From a33870845628fea75c96e4b3acebca0a2cd10f7a Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sun, 28 Oct 2007 23:14:18 +0000 Subject: fixed support for flipped tiles --- src/editor/editor.cpp | 62 +++++++++++++++++++++++++++++++++++--- src/game/client/mapres_tilemap.cpp | 34 +++++++++++++-------- src/game/game.h | 2 +- 3 files changed, 79 insertions(+), 19 deletions(-) (limited to 'src') 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 -- cgit 1.4.1