Tilemap: Support for x-flipped and xy-flipped (180°) tiles
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1864 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
3b989f3eb3
commit
e9a2ad8e81
87
src/tiles.c
87
src/tiles.c
@ -195,7 +195,25 @@ int Tile_is_same(int t1, int t2)
|
||||
}
|
||||
|
||||
///
|
||||
int Tile_is_same_y(int t1, int t2)
|
||||
int Tile_is_same_flipped_x(int t1, int t2)
|
||||
{
|
||||
byte *bmp1,*bmp2;
|
||||
int y, x;
|
||||
|
||||
bmp1 = Main_backups->Pages->Image[Main_current_layer].Pixels+(TILE_Y(t1))*Main_image_width+(TILE_X(t1));
|
||||
bmp2 = Main_backups->Pages->Image[Main_current_layer].Pixels+(TILE_Y(t2))*Main_image_width+(TILE_X(t2)+Snap_width-1);
|
||||
|
||||
for (y=0; y < Snap_height; y++)
|
||||
{
|
||||
for (x=0; x < Snap_width; x++)
|
||||
if (*(bmp1+y*Main_image_width+x) != *(bmp2+y*Main_image_width-x))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
///
|
||||
int Tile_is_same_flipped_y(int t1, int t2)
|
||||
{
|
||||
byte *bmp1,*bmp2;
|
||||
int y;
|
||||
@ -211,6 +229,25 @@ int Tile_is_same_y(int t1, int t2)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
int Tile_is_same_flipped_xy(int t1, int t2)
|
||||
{
|
||||
byte *bmp1,*bmp2;
|
||||
int y, x;
|
||||
|
||||
bmp1 = Main_backups->Pages->Image[Main_current_layer].Pixels+(TILE_Y(t1))*Main_image_width+(TILE_X(t1));
|
||||
bmp2 = Main_backups->Pages->Image[Main_current_layer].Pixels+(TILE_Y(t2)+Snap_height-1)*Main_image_width+(TILE_X(t2)+Snap_width-1);
|
||||
|
||||
for (y=0; y < Snap_height; y++)
|
||||
{
|
||||
for (x=0; x < Snap_width; x++)
|
||||
if (*(bmp1+y*Main_image_width+x) != *(bmp2-y*Main_image_width-x))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// Create or update a tilemap based on current screen pixels.
|
||||
void Tilemap_create(void)
|
||||
{
|
||||
@ -293,7 +330,7 @@ void Tilemap_create(void)
|
||||
|
||||
for (ref_tile=0; ref_tile<tile; ref_tile++)
|
||||
{
|
||||
if (Main_tilemap[ref_tile].Previous<=ref_tile && Tile_is_same_y(ref_tile, tile))
|
||||
if (Main_tilemap[ref_tile].Previous<=ref_tile && Tile_is_same_flipped_y(ref_tile, tile))
|
||||
{
|
||||
break; // stop loop on ref_tile
|
||||
}
|
||||
@ -305,7 +342,51 @@ void Tilemap_create(void)
|
||||
int last_tile=Main_tilemap[ref_tile].Previous;
|
||||
Main_tilemap[tile].Previous=last_tile;
|
||||
Main_tilemap[tile].Next=ref_tile;
|
||||
Main_tilemap[tile].Flipped=Main_tilemap[ref_tile].Flipped ^ 2;
|
||||
Main_tilemap[tile].Flipped=Main_tilemap[ref_tile].Flipped ^ TILE_FLIPPED_Y;
|
||||
Main_tilemap[ref_tile].Previous=tile;
|
||||
Main_tilemap[last_tile].Next=tile;
|
||||
continue; // next tile
|
||||
}
|
||||
|
||||
// Try flipped-x comparison
|
||||
|
||||
for (ref_tile=0; ref_tile<tile; ref_tile++)
|
||||
{
|
||||
if (Main_tilemap[ref_tile].Previous<=ref_tile && Tile_is_same_flipped_x(ref_tile, tile))
|
||||
{
|
||||
break; // stop loop on ref_tile
|
||||
}
|
||||
}
|
||||
if (ref_tile<tile)
|
||||
{
|
||||
// New occurence of a known tile
|
||||
// Insert at the end. classic doubly-linked-list.
|
||||
int last_tile=Main_tilemap[ref_tile].Previous;
|
||||
Main_tilemap[tile].Previous=last_tile;
|
||||
Main_tilemap[tile].Next=ref_tile;
|
||||
Main_tilemap[tile].Flipped=Main_tilemap[ref_tile].Flipped ^ TILE_FLIPPED_X;
|
||||
Main_tilemap[ref_tile].Previous=tile;
|
||||
Main_tilemap[last_tile].Next=tile;
|
||||
continue; // next tile
|
||||
}
|
||||
|
||||
// Try flipped-xy comparison
|
||||
|
||||
for (ref_tile=0; ref_tile<tile; ref_tile++)
|
||||
{
|
||||
if (Main_tilemap[ref_tile].Previous<=ref_tile && Tile_is_same_flipped_xy(ref_tile, tile))
|
||||
{
|
||||
break; // stop loop on ref_tile
|
||||
}
|
||||
}
|
||||
if (ref_tile<tile)
|
||||
{
|
||||
// New occurence of a known tile
|
||||
// Insert at the end. classic doubly-linked-list.
|
||||
int last_tile=Main_tilemap[ref_tile].Previous;
|
||||
Main_tilemap[tile].Previous=last_tile;
|
||||
Main_tilemap[tile].Next=ref_tile;
|
||||
Main_tilemap[tile].Flipped=Main_tilemap[ref_tile].Flipped ^ TILE_FLIPPED_XY;
|
||||
Main_tilemap[ref_tile].Previous=tile;
|
||||
Main_tilemap[last_tile].Next=tile;
|
||||
continue; // next tile
|
||||
|
||||
@ -36,3 +36,10 @@ void Tilemap_draw(word x, word y, byte color);
|
||||
#define TILE_X(t) (((t)%Main_tilemap_width)*Snap_width+Snap_offset_X)
|
||||
#define TILE_Y(t) (((t)/Main_tilemap_width)*Snap_height+Snap_offset_Y)
|
||||
|
||||
enum TILE_FLIPPED
|
||||
{
|
||||
TILE_FLIPPED_NONE = 0,
|
||||
TILE_FLIPPED_X = 1,
|
||||
TILE_FLIPPED_Y = 2,
|
||||
TILE_FLIPPED_XY = 3, // needs be TILE_FLIPPED_X|TILE_FLIPPED_Y
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user