From 53428f0a21cea2d6257a6b40eb6bc5e32731b7f9 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Thu, 11 Aug 2011 13:13:46 +0000
Subject: [PATCH] Fixed random black screen bug

git-svn-id: http://svn.net-core.org/repos/t-engine4@4104 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engines/default/engine/Entity.lua |  3 ++-
 game/engines/default/engine/Map.lua    |  5 +++--
 src/map.c                              |  3 +++
 src/particles.c                        | 12 +++++++++---
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/game/engines/default/engine/Entity.lua b/game/engines/default/engine/Entity.lua
index 72172816fe..fa7f1d4094 100644
--- a/game/engines/default/engine/Entity.lua
+++ b/game/engines/default/engine/Entity.lua
@@ -212,7 +212,8 @@ function _M:defineDisplayCallback()
 		for i = 1, #ps do
 			e = ps[i]
 			e:checkDisplay()
-			if e.ps:isAlive() then e.ps:toScreen(x + w / 2, y + h / 2, true, w / game.level.map.tile_w)
+			if e.ps:isAlive() then
+				e.ps:toScreen(x + w / 2, y + h / 2, true, w / game.level.map.tile_w)
 			else
 			end
 		end
diff --git a/game/engines/default/engine/Map.lua b/game/engines/default/engine/Map.lua
index a444872d73..a83ae392ee 100644
--- a/game/engines/default/engine/Map.lua
+++ b/game/engines/default/engine/Map.lua
@@ -1014,6 +1014,7 @@ function _M:displayParticles(nb_keyframes)
 	local alive
 	local del = {}
 	local e = next(self.particles)
+	local dx, dy = self.display_x, self.display_y
 	while e do
 		if e.ps then
 			adx, ady = 0, 0
@@ -1030,14 +1031,14 @@ function _M:displayParticles(nb_keyframes)
 			if nb_keyframes == 0 and e.x and e.y then
 				-- Just display it, not updating, no emitting
 				if e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
-					e.ps:toScreen(self.display_x + (adx + e.x - self.mx + 0.5) * self.tile_w * self.zoom, self.display_y + (ady + e.y - self.my + 0.5) * self.tile_h * self.zoom, self.seens(e.x, e.y) or e.always_seen, e.zoom * self.zoom)
+					e.ps:toScreen(dx + (adx + e.x - self.mx + 0.5) * self.tile_w * self.zoom, dy + (ady + e.y - self.my + 0.5) * self.tile_h * self.zoom, self.seens(e.x, e.y) or e.always_seen, e.zoom * self.zoom)
 				end
 			elseif e.x and e.y then
 				alive = e.ps:isAlive()
 
 				-- Update more, if needed
 				if alive and e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
-					e.ps:toScreen(self.display_x + (adx + e.x - self.mx + 0.5) * self.tile_w * self.zoom, self.display_y + (ady + e.y - self.my + 0.5) * self.tile_h * self.zoom, self.seens(e.x, e.y) or e.always_seen)
+					e.ps:toScreen(dx + (adx + e.x - self.mx + 0.5) * self.tile_w * self.zoom, dy + (ady + e.y - self.my + 0.5) * self.tile_h * self.zoom, self.seens(e.x, e.y) or e.always_seen)
 				end
 
 				if not alive then
diff --git a/src/map.c b/src/map.c
index 86bb3903e1..0a5d9ea398 100644
--- a/src/map.c
+++ b/src/map.c
@@ -276,11 +276,13 @@ static int map_object_get_move_anim(lua_State *L)
 
 	if (!obj->move_max || obj->display_last == DL_NONE)
 	{
+//		printf("==== GET %f x %f\n", mapdx, mapdy);
 		lua_pushnumber(L, mapdx);
 		lua_pushnumber(L, mapdy);
 	}
 	else
 	{
+//		printf("==== GET %f x %f :: %f x %f\n", mapdx, mapdy,obj->animdx,obj->animdy);
 		lua_pushnumber(L, mapdx + obj->animdx);
 		lua_pushnumber(L, mapdy + obj->animdy);
 	}
@@ -1195,6 +1197,7 @@ void display_map_quad(GLuint *cur_tex, int *vert_idx, int *col_idx, map_type *ma
 			// Final step
 			animdx = adx * m->move_step / (float)m->move_max - adx;
 			animdy = ady * m->move_step / (float)m->move_max - ady;
+//			printf("==computing %f x %f : %f x %f // %d/%d\n", animdx, animdy, adx, ady, m->move_step, m->move_max);
 		}
 	}
 
diff --git a/src/particles.c b/src/particles.c
index 08e9913e9f..c44fcf19b5 100644
--- a/src/particles.c
+++ b/src/particles.c
@@ -162,15 +162,21 @@ static int particles_to_screen(lua_State *L)
 	GLfloat *colors = ps->colors;
 	GLshort *texcoords = ps->texcoords;
 
-	SDL_mutexP(ps->lock);
+	if (x < -10000) x = -10000;
+	if (x > 10000) x = 10000;
+	if (y < -10000) y = -10000;
+	if (y > 10000) y = 10000;
 
 	// No texture? abord
 	if (!ps->texture) return 0;
 
+	SDL_mutexP(ps->lock);
+
 	glBindTexture(GL_TEXTURE_2D, ps->texture);
 	glTexCoordPointer(2, GL_SHORT, 0, texcoords);
 	glColorPointer(4, GL_FLOAT, 0, colors);
 	glVertexPointer(2, GL_FLOAT, 0, vertices);
+
 	glTranslatef(x, y, 0);
 	glPushMatrix();
 	glScalef(ps->zoom * zoom, ps->zoom * zoom, ps->zoom * zoom);
@@ -184,12 +190,12 @@ static int particles_to_screen(lua_State *L)
 	}
 	if (remaining) glDrawArrays(GL_QUADS, 0, remaining);
 
-	SDL_mutexV(ps->lock);
-
 	glRotatef(-ps->rotate, 0, 0, 1);
 	glPopMatrix();
 	glTranslatef(-x, -y, 0);
 
+	SDL_mutexV(ps->lock);
+
 	return 0;
 }
 
-- 
GitLab