From 353b4946177e6b55f818bfe6202860fd810c7c39 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 22 Jan 2018 20:59:49 +0100 Subject: [PATCH] move tilemap data to T_Document. Also merge Disable_main_tilemap + Disable_spare_tilemap => Disable_tilemap() --- src/buttons.c | 4 +- src/buttons_effects.c | 2 +- src/struct.h | 6 ++ src/tiles.c | 167 +++++++++++++++++------------------------- src/tiles.h | 23 +----- 5 files changed, 79 insertions(+), 123 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index bbb0cbe4..ea6b5610 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -1762,7 +1762,7 @@ void Button_Copy_page(void) Redraw_spare_image(); Spare.image_is_modified=1; if (Spare.tilemap_mode) - Disable_spare_tilemap(); + Disable_tilemap(&Spare); break; case 2: // Pixels only @@ -1773,7 +1773,7 @@ void Button_Copy_page(void) Redraw_spare_image(); Spare.image_is_modified=1; if (Spare.tilemap_mode) - Disable_spare_tilemap(); + Disable_tilemap(&Spare); break; case 3: // Palette only diff --git a/src/buttons_effects.c b/src/buttons_effects.c index 0b4a98d9..b871cd38 100644 --- a/src/buttons_effects.c +++ b/src/buttons_effects.c @@ -543,7 +543,7 @@ void Button_Grid_menu(void) if (modified) { Tilemap_update(); - Disable_spare_tilemap(); + Disable_tilemap(&Spare); } } diff --git a/src/struct.h b/src/struct.h index 24f78cb2..e85d4f81 100644 --- a/src/struct.h +++ b/src/struct.h @@ -606,6 +606,12 @@ typedef struct byte safety_backup_prefix; /// Tilemap mode byte tilemap_mode; + /// Tilemap + T_Tile * tilemap; + /// Number of tiles (horizontally) for the tilemap + short tilemap_width; + /// Number of tiles (vertically) for the tilemap + short tilemap_height; /// The pixels of visible layers, flattened copy. T_Bitmap visible_image; /// List of backup pages for the main image. diff --git a/src/tiles.c b/src/tiles.c index 056ecceb..4b110ebd 100644 --- a/src/tiles.c +++ b/src/tiles.c @@ -30,10 +30,10 @@ #include "tiles.h" // These helpers are only needed internally at the moment -#define TILE_FOR_COORDS(x,y) (((y)-Snap_offset_Y)/Snap_height*Main_tilemap_width+((x)-Snap_offset_X)/Snap_width) -#define TILE_AT(x,y) (y)*Main_tilemap_width+(x) -#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) +#define TILE_FOR_COORDS(x,y) (((y)-Snap_offset_Y)/Snap_height*Main.tilemap_width+((x)-Snap_offset_X)/Snap_width) +#define TILE_AT(x,y) (y)*Main.tilemap_width+(x) +#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 { @@ -45,21 +45,6 @@ enum TILE_FLIPPED // globals -/// Tilemap for the main screen -T_Tile * Main_tilemap; -/// Number of tiles (horizontally) for the main page's tilemap -short Main_tilemap_width; -/// Number of tiles (vertically) for the main page's tilemap -short Main_tilemap_height; - -/// Tilemap for the spare -T_Tile * Spare_tilemap; -/// Number of tiles (horizontally) for the spare page's tilemap -short Spare_tilemap_width; -/// Number of tiles (vertically) for the spare page's tilemap -short Spare_tilemap_height; - - /// /// Draw a pixel while Tilemap mode is active : This will paint on all /// similar tiles of the layer, visible on the screen or not. @@ -70,8 +55,8 @@ void Tilemap_draw(word x, word y, byte color) if (x < Snap_offset_X || y < Snap_offset_Y - || x >= Snap_offset_X + Main_tilemap_width*Snap_width - || y >= Snap_offset_Y + Main_tilemap_height*Snap_height) + || x >= Snap_offset_X + Main.tilemap_width*Snap_width + || y >= Snap_offset_Y + Main.tilemap_height*Snap_height) return; tile = first_tile = TILE_FOR_COORDS(x,y); @@ -81,24 +66,24 @@ void Tilemap_draw(word x, word y, byte color) do { int xx,yy; - switch(Main_tilemap[tile].Flipped ^ Main_tilemap[first_tile].Flipped) + switch(Main.tilemap[tile].Flipped ^ Main.tilemap[first_tile].Flipped) { case 0: // no default: - xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + rel_x; - yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + rel_y; + xx = (tile % Main.tilemap_width)*Snap_width+Snap_offset_X + rel_x; + yy = (tile / Main.tilemap_width)*Snap_height+Snap_offset_Y + rel_y; break; case 1: // horizontal - xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + Snap_width-rel_x-1; - yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + rel_y; + xx = (tile % Main.tilemap_width)*Snap_width+Snap_offset_X + Snap_width-rel_x-1; + yy = (tile / Main.tilemap_width)*Snap_height+Snap_offset_Y + rel_y; break; case 2: // vertical - xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + rel_x; - yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + Snap_height - rel_y - 1; + xx = (tile % Main.tilemap_width)*Snap_width+Snap_offset_X + rel_x; + yy = (tile / Main.tilemap_width)*Snap_height+Snap_offset_Y + Snap_height - rel_y - 1; break; case 3: // both - xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + Snap_width-rel_x-1; - yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + Snap_height - rel_y - 1; + xx = (tile % Main.tilemap_width)*Snap_width+Snap_offset_X + Snap_width-rel_x-1; + yy = (tile / Main.tilemap_width)*Snap_height+Snap_offset_Y + Snap_height - rel_y - 1; break; } if (yy>=Limit_top&&yy<=Limit_bottom&&xx>=Limit_left&&xx<=Limit_right) @@ -106,7 +91,7 @@ void Tilemap_draw(word x, word y, byte color) else Pixel_in_current_screen(xx,yy,color); - tile = Main_tilemap[tile].Next; + tile = Main.tilemap[tile].Next; } while (tile != first_tile); Update_rect(0,0,0,0); @@ -209,20 +194,20 @@ void Tilemap_update(void) // Or the number of tiles seems unreasonable (one million) : This can // happen if you set grid 1x1 for example. - Disable_main_tilemap(); + Disable_tilemap(&Main); return; } - if (Main_tilemap) + if (Main.tilemap) { // Recycle existing tilemap - free(Main_tilemap); - Main_tilemap=NULL; + free(Main.tilemap); + Main.tilemap=NULL; } - Main_tilemap=tile_ptr; + Main.tilemap=tile_ptr; - Main_tilemap_width=width; - Main_tilemap_height=height; + Main.tilemap_width=width; + Main.tilemap_height=height; if (width*height > 1000 || Config.Tilemap_show_count) { @@ -239,9 +224,9 @@ void Tilemap_update(void) // Initialize array with all tiles unique by default for (tile=0; tiletilemap) { // Recycle existing tilemap - free(Main_tilemap); - Main_tilemap=NULL; + free(doc->tilemap); + doc->tilemap=NULL; } - Main_tilemap_width=0; - Main_tilemap_height=0; - Main.tilemap_mode=0; -} - -/// -/// Clears all tilemap data and settings for the spare. -/// Safe to call again. -void Disable_spare_tilemap(void) -{ - if (Spare_tilemap) - { - // Recycle existing tilemap - free(Spare_tilemap); - Spare_tilemap=NULL; - } - Spare_tilemap_width=0; - Spare_tilemap_height=0; - Spare.tilemap_mode=0; + doc->tilemap_width=0; + doc->tilemap_height=0; + doc->tilemap_mode=0; } diff --git a/src/tiles.h b/src/tiles.h index 3e5c32ff..cad048ec 100644 --- a/src/tiles.h +++ b/src/tiles.h @@ -38,26 +38,7 @@ void Tilemap_draw(word x, word y, byte color); void Swap_tilemap(void); /// -/// Clears all tilemap data and settings for the main page. +/// Clears all tilemap data and settings /// Safe to call again. -void Disable_main_tilemap(void); +void Disable_tilemap(T_Document * doc); -/// -/// Clears all tilemap data and settings for the spare. -/// Safe to call again. -void Disable_spare_tilemap(void); - - -/// Tilemap for the main screen -extern T_Tile * Main_tilemap; -/// Number of tiles (horizontally) for the main page's tilemap -extern short Main_tilemap_width; -/// Number of tiles (vertically) for the main page's tilemap -extern short Main_tilemap_height; - -/// Tilemap for the spare -extern T_Tile * Spare_tilemap; -/// Number of tiles (horizontally) for the spare page's tilemap -extern short Spare_tilemap_width; -/// Number of tiles (vertically) for the spare page's tilemap -extern short Spare_tilemap_height;