From c5f9bb354d87cb876c2b27e4d7cf69fca261dfa0 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Fri, 30 Mar 2012 21:46:54 +0000 Subject: [PATCH] Tilemap mode: added a missing tile refresh after using the scroll(pan) tool. Added a few Doxygen comments. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1939 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/operatio.c | 28 ++++++----- src/tiles.c | 132 ++++++++++--------------------------------------- src/tiles.h | 26 ++++++---- 3 files changed, 58 insertions(+), 128 deletions(-) diff --git a/src/operatio.c b/src/operatio.c index e9f2bf51..620c4036 100644 --- a/src/operatio.c +++ b/src/operatio.c @@ -37,6 +37,8 @@ #include "brush.h" #include "windows.h" #include "input.h" +#include "special.h" +#include "tiles.h" // PI is NOT part of math.h according to C standards... #if defined(__GP2X__) || defined(__VBCC__) @@ -2826,7 +2828,7 @@ void Scroll_12_5(void) Operation_pop(&x_pos); Operation_pop(¢er_y); Operation_pop(¢er_x); - + if ( (Paintbrush_X!=x_pos) || (Paintbrush_Y!=y_pos) ) { // L'utilisateur a bougé, il faut scroller l'image @@ -2890,21 +2892,21 @@ void Scroll_0_5(void) Operation_pop(&x_pos); Operation_pop(¢er_y); Operation_pop(¢er_x); - + if (side == RIGHT_SIDE) { - // All layers at once - if (x_pos>=center_x) - x_offset=(x_pos-center_x)%Main_image_width; - else - x_offset=Main_image_width-((center_x-x_pos)%Main_image_width); + // All layers at once + if (x_pos>=center_x) + x_offset=(x_pos-center_x)%Main_image_width; + else + x_offset=Main_image_width-((center_x-x_pos)%Main_image_width); - if (y_pos>=center_y) - y_offset=(y_pos-center_y)%Main_image_height; - else - y_offset=Main_image_height-((center_y-y_pos)%Main_image_height); - + if (y_pos>=center_y) + y_offset=(y_pos-center_y)%Main_image_height; + else + y_offset=Main_image_height-((center_y-y_pos)%Main_image_height); + // Do the actual scroll operation on all layers. for (i=0; iPages->Nb_layers; i++) //if ((1<= 0; ctx--) - if(compare_tiles(tile_x*Snap_width, tile_y*Snap_height, ctx*Snap_width, tile_y*Snap_height)) - { - // We found a match ! - tileArea[tile_y*tileAreaWidth+tile_x] = tile_y*tileAreaWidth+ctx; - goto found; - } - - // Then we look at all the lines above - for(cty = tile_y - 1; cty >= 0; cty--) - for(ctx = tileAreaWidth - 1; ctx >= 0; ctx--) - if(compare_tiles(tile_x*Snap_width, tile_y*Snap_height, ctx*Snap_width, cty*Snap_height)) - { - // We found a match ! - tileArea[tile_y*tileAreaWidth+tile_x] = cty*tileAreaWidth+ctx; - goto found; - } - - // Then we look at all the lines below - for(cty = tileAreaHeight - 1; cty >= tile_y; cty--) - for(ctx = tileAreaWidth - 1; ctx >= 0; ctx--) - if(compare_tiles(tile_x*Snap_width, tile_y*Snap_height, ctx*Snap_width, cty*Snap_height)) - { - // We found a match ! - tileArea[tile_y*tileAreaWidth+tile_x] = cty*tileAreaWidth+ctx; - goto found; - } - - // Then we look at the tiles at the right of this one - // (including the tile itself, so we are sure we match something this time) - for(ctx = tileAreaHeight; ctx >= tile_x; ctx--) - if(compare_tiles(tile_x*Snap_width, tile_y*Snap_height, ctx*Snap_width, tile_y*Snap_height)) - { - // We found a match ! - tileArea[tile_y*tileAreaWidth+tile_x] = tile_y*tileAreaWidth+ctx; - } - - found: - ; - } -} - - -// Compare tiles -// The parameters are in pixel-space. -int compare_tiles(word x1, word y1, word x2, word y2) -{ - word pixel_x, pixel_y; - byte c1, c2; - - for (pixel_y = 0; pixel_y < Snap_width; pixel_y++) - for (pixel_x = 0; pixel_x < Snap_height; pixel_x++) - { - c1 = *(Main_screen + (y1+pixel_y) * Main_image_width + (x1+pixel_x)); - c2 = *(Main_screen + (y2+pixel_y) * Main_image_width + (x2+pixel_x)); - if (c1 != c2) return 0; - } - - return 1; -} -/* -/// Copy a tile pixeldata to all the identical ones -// Call this after the end of an operation -void update_tile(word pixel_x, word pixel_y) -{ - int tileOffset = (pixel_y/Snap_height)*tileAreaHeight + pixel_x/Snap_width; - int firstTileOffset = tileOffset + 1; // to make sure they are not equal - - while(firstTileOffset != tileOffset) - { - tileOffset = tileArea[tileOffset]; - - //do the copy of a block starting at (pixel_x, pixel_y) - } -} -*/ - -/* Basic repeat-all -void Tilemap_draw(word x, word y, byte color) -{ - int xx,yy; - for (yy=(y+Snap_height-Snap_offset_Y)%Snap_height+Snap_offset_Y;yy=Limit_top&&yy<=Limit_bottom&&xx>=Limit_left&&xx<=Limit_right); - Update_rect(0,0,0,0); -} -*/ +/// +/// Draw a pixel while Tilemap mode is active : This will paint on all +/// similar tiles of the layer, visible on the screen or not. void Tilemap_draw(word x, word y, byte color) { int tile, first_tile; @@ -468,6 +377,9 @@ void Tilemap_update(void) } } +/// +/// This exchanges the tilemap settings of the main and spare, it should +/// be called when swapping pages. void Swap_tilemap(void) { SWAP_BYTES(Main_tilemap_mode, Spare_tilemap_mode) @@ -481,6 +393,9 @@ void Swap_tilemap(void) SWAP_SHORTS(Main_tilemap_height, Spare_tilemap_height) } +/// +/// Clears all tilemap data and settings for the main page. +/// Safe to call again. void Disable_main_tilemap(void) { if (Main_tilemap) @@ -494,6 +409,9 @@ void Disable_main_tilemap(void) 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) diff --git a/src/tiles.h b/src/tiles.h index 8b9b54b3..8e4233ec 100644 --- a/src/tiles.h +++ b/src/tiles.h @@ -24,32 +24,40 @@ /// Functions for tilemap effect ////////////////////////////////////////////////////////////////////////////// -int compare_tiles(word x1, word y1, word x2, word y2); - /// Create or update a tilemap based on current screen pixels. void Tilemap_update(void); +/// +/// Draw a pixel while Tilemap mode is active : This will paint on all +/// similar tiles of the layer, visible on the screen or not. void Tilemap_draw(word x, word y, byte color); +/// +/// This exchanges the tilemap settings of the main and spare, it should +/// be called when swapping pages. void Swap_tilemap(void); +/// +/// Clears all tilemap data and settings for the main page. +/// Safe to call again. void Disable_main_tilemap(void); +/// +/// Clears all tilemap data and settings for the spare. +/// Safe to call again. void Disable_spare_tilemap(void); -#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) /// 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;