about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-28 23:14:18 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-28 23:14:18 +0000
commita33870845628fea75c96e4b3acebca0a2cd10f7a (patch)
treea34ed282e9acc39091aec7fe2af4adef93aa8fa5 /src
parentdab34697e79f5d6a97462b24249ef7c5b0f1813a (diff)
downloadzcatch-a33870845628fea75c96e4b3acebca0a2cd10f7a.tar.gz
zcatch-a33870845628fea75c96e4b3acebca0a2cd10f7a.zip
fixed support for flipped tiles
Diffstat (limited to 'src')
-rw-r--r--src/editor/editor.cpp62
-rw-r--r--src/game/client/mapres_tilemap.cpp34
-rw-r--r--src/game/game.h2
3 files changed, 79 insertions, 19 deletions
diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp
index 6d6cea57..c35bb08c 100644
--- a/src/editor/editor.cpp
+++ b/src/editor/editor.cpp
@@ -154,6 +154,37 @@ static void tilemap_destroy(tilemap *tm)
 	tm->height = 0;
 }
 
+static void tilemap_vflip(tilemap *tm)
+{
+	for(int iy = 0; iy < tm->height; iy++)
+		for(int ix = 0; ix < tm->width/2; ix++)
+		{
+			tile tmp = tm->tiles[iy*tm->width+ix];
+			tm->tiles[iy*tm->width+ix] = tm->tiles[iy*tm->width+tm->width-ix-1];
+			tm->tiles[iy*tm->width+tm->width-ix-1] = tmp;
+		}
+		
+	for(int iy = 0; iy < tm->height; iy++)
+		for(int ix = 0; ix < tm->width; ix++)
+			tm->tiles[iy*tm->width+ix].flags ^= TILEFLAG_VFLIP;
+
+}
+
+static void tilemap_hflip(tilemap *tm)
+{
+	for(int iy = 0; iy < tm->height/2; iy++)
+		for(int ix = 0; ix < tm->width; ix++)
+		{
+			tile tmp = tm->tiles[iy*tm->width+ix];
+			tm->tiles[iy*tm->width+ix] = tm->tiles[tm->height*tm->width-tm->width-tm->width*iy+ix];
+			tm->tiles[tm->height*tm->width-tm->width-tm->width*iy+ix] = tmp;
+		}
+
+	for(int iy = 0; iy < tm->height; iy++)
+		for(int ix = 0; ix < tm->width; ix++)
+			tm->tiles[iy*tm->width+ix].flags ^= TILEFLAG_HFLIP;
+}
+
 static int tilemap_blit(tilemap *dst, tilemap *src, int x, int y)
 {
 	int count = 0;
@@ -353,13 +384,28 @@ static void render_tilemap(tilemap *tm, float sx, float sy, float scale)
 		for(int x = 0; x < tm->width; x++)
 		{
 			unsigned char d = tm->tiles[y*tm->width+x].index;
+			unsigned char f = tm->tiles[y*tm->width+x].flags;
 			if(d)
 			{
-				gfx_quads_setsubset(
-					(d%16)/16.0f+frac,
-					(d/16)/16.0f+frac,
-					(d%16)/16.0f+1.0f/16.0f-frac,
-					(d/16)/16.0f+1.0f/16.0f-frac);
+				float u0 = (d%16)/16.0f+frac;
+				float v0 = (d/16)/16.0f+frac;
+				float u1 = (d%16)/16.0f+1.0f/16.0f-frac;
+				float v1 = (d/16)/16.0f+1.0f/16.0f-frac;
+				if(f&TILEFLAG_VFLIP)
+				{
+					float tmp = u0;
+					u0 = u1;
+					u1 = tmp;
+				}
+
+				if(f&TILEFLAG_HFLIP)
+				{
+					float tmp = v0;
+					v0 = v1;
+					v1 = tmp;
+				}
+				
+				gfx_quads_setsubset(u0,v0,u1,v1);
 				gfx_quads_drawTL(sx+x*scale, sy+y*scale, scale, scale);
 			}
 
@@ -861,6 +907,12 @@ static void editor_render()
 			if(ui_mouse_button(1) || inp_key_pressed('C'))
 				tilemap_destroy(&brush);
 		}
+
+		// flip buttons
+		if(inp_key_down('N') && brush.tiles)
+			tilemap_vflip(&brush);
+		if(inp_key_down('M') && brush.tiles)
+			tilemap_hflip(&brush);
 		
 		if(inp_key_pressed(KEY_SPACE))
 		{
diff --git a/src/game/client/mapres_tilemap.cpp b/src/game/client/mapres_tilemap.cpp
index 961fe7fc..822e2d8c 100644
--- a/src/game/client/mapres_tilemap.cpp
+++ b/src/game/client/mapres_tilemap.cpp
@@ -60,28 +60,36 @@ void tilemap_render(float scale, int fg)
 					int c = mx + my*tmap->width;
 						
 					unsigned char d = data[c*2];
+					unsigned char f = data[c*2+1];
 					if(d)
 					{
-						/*
-						gfx_quads_setsubset(
-							(d%16)/16.0f*s+frac,
-							(d/16)/16.0f*s+frac,
-							((d%16)/16.0f+1.0f/16.0f)*s-frac,
-							((d/16)/16.0f+1.0f/16.0f)*s-frac);
-							*/
-						
 						int tx = d%16;
 						int ty = d/16;
 						int px0 = tx*(1024/16);
 						int py0 = ty*(1024/16);
 						int px1 = (tx+1)*(1024/16)-1;
 						int py1 = (ty+1)*(1024/16)-1;
+						
+						float u0 = nudge + px0/texsize+frac;
+						float v0 = nudge + py0/texsize+frac;
+						float u1 = nudge + px1/texsize+frac;
+						float v1 = nudge + py1/texsize+frac;
+						
+						if(f&TILEFLAG_VFLIP)
+						{
+							float tmp = u0;
+							u0 = u1;
+							u1 = tmp;
+						}
 
-						gfx_quads_setsubset(
-							nudge + px0/texsize+frac,
-							nudge + py0/texsize+frac,
-							nudge + px1/texsize-frac,
-							nudge + py1/texsize-frac);
+						if(f&TILEFLAG_HFLIP)
+						{
+							float tmp = v0;
+							v0 = v1;
+							v1 = tmp;
+						}
+						
+						gfx_quads_setsubset(u0,v0,u1,v1);
 
 						gfx_quads_drawTL(x*scale, y*scale, scale, scale);
 					}
diff --git a/src/game/game.h b/src/game/game.h
index 4fa22c08..62d67cb7 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -109,7 +109,7 @@ inline bool col_check_point(vec2 p) { return col_check_point(p.x, p.y); }
 struct mapres_entity
 {
 	int x, y;
-	int *data;
+	int data[1];
 };
 
 struct mapres_spawnpoint