mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
fixed support for flipped tiles
This commit is contained in:
parent
dab34697e7
commit
a338708456
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue