From 82860387bc3d2958aeac522e77cef90c0af2deaa Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Tue, 8 Nov 2011 23:38:14 +0000 Subject: [PATCH] Added missing source file, and make the tilemap depend on current layer instead of the sum of layers git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1860 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/graph.c | 1 + src/struct.h | 5 ++--- src/tiles.c | 56 ++++++++++++++++++++++++++++++++-------------------- src/tiles.h | 38 +++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 24 deletions(-) create mode 100644 src/tiles.h diff --git a/src/graph.c b/src/graph.c index 682eb302..9a761c37 100644 --- a/src/graph.c +++ b/src/graph.c @@ -49,6 +49,7 @@ #include "windows.h" #include "input.h" #include "brush.h" +#include "tiles.h" #ifdef __VBCC__ #define __attribute__(x) diff --git a/src/struct.h b/src/struct.h index 4042ff00..78b3e7d5 100644 --- a/src/struct.h +++ b/src/struct.h @@ -545,9 +545,8 @@ typedef enum { typedef struct { - int Previous_occurence; - int Next_occurence; - int First_occurence; + int Previous; + int Next; } T_Tile; #endif diff --git a/src/tiles.c b/src/tiles.c index 5049350e..4f867c9f 100644 --- a/src/tiles.c +++ b/src/tiles.c @@ -152,7 +152,7 @@ void Tilemap_draw(word x, word y, byte color) xx = (tile % Main_tilemap_width)*Snap_width+Snap_offset_X + rel_x; yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + rel_y; Pixel_in_current_screen(xx,yy,color,yy>=Limit_top&&yy<=Limit_bottom&&xx>=Limit_left&&xx<=Limit_right); - tile = Main_tilemap[tile].Next_occurence; + tile = Main_tilemap[tile].Next; } while (tile != first_tile); Update_rect(0,0,0,0); @@ -164,8 +164,8 @@ int Tile_is_same(int t1, int t2) byte *bmp1,*bmp2; int y; - bmp1 = Main_screen+(TILE_Y(t1))*Main_image_width+(TILE_X(t1)); - bmp2 = Main_screen+(TILE_Y(t2))*Main_image_width+(TILE_X(t2)); + 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)); for (y=0; y < Snap_height; y++) { @@ -189,8 +189,14 @@ void Tilemap_create(void) if (width<1 || height<1 || width*height>1000000l || (tile_ptr=(T_Tile *)malloc(width*height*sizeof(T_Tile))) == NULL) { + // Cannot enable tilemap because either the image is too small + // for the grid settings (and I don't want to implement partial tiles) + // Or the number of tiles seems unreasonable (one million) : This can + // happen if you set grid 1x1 for example. + if (Main_tilemap) { + // Recycle existing tilemap free(Main_tilemap); Main_tilemap=NULL; } @@ -199,43 +205,51 @@ void Tilemap_create(void) Tilemap_mode=0; return; } - Main_tilemap_width=width; - Main_tilemap_height=height; + + if (Main_tilemap) + { + // Recycle existing tilemap + free(Main_tilemap); + Main_tilemap=NULL; + } Main_tilemap=tile_ptr; - // Init array + Main_tilemap_width=width; + Main_tilemap_height=height; + + // Init array with all tiles unique by default for (tile=0; tile=tile) { - // New unique tile - //Main_tilemap[tile].First_occurence=1; + // This tile is really unique. + // Nothing to do at the moment break; } } diff --git a/src/tiles.h b/src/tiles.h new file mode 100644 index 00000000..b718646e --- /dev/null +++ b/src/tiles.h @@ -0,0 +1,38 @@ +/* vim:expandtab:ts=2 sw=2: +*/ +/* Grafx2 - The Ultimate 256-color bitmap paint program + + Copyright 2011 Yves Rizoud + Copyright 2011 Adrien Destugues + + Grafx2 is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; version 2 + of the License. + + Grafx2 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grafx2; if not, see +*/ + +////////////////////////////////////////////////////////////////////////////// +///@file tiles.h +/// 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_create(void); + +void Tilemap_draw(word x, word y, byte color); + +#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) +