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
This commit is contained in:
		
							parent
							
								
									ef030fec3f
								
							
						
					
					
						commit
						82860387bc
					
				@ -49,6 +49,7 @@
 | 
			
		||||
#include "windows.h"
 | 
			
		||||
#include "input.h"
 | 
			
		||||
#include "brush.h"
 | 
			
		||||
#include "tiles.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __VBCC__
 | 
			
		||||
    #define __attribute__(x)
 | 
			
		||||
 | 
			
		||||
@ -545,9 +545,8 @@ typedef enum {
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  int Previous_occurence;
 | 
			
		||||
  int Next_occurence;
 | 
			
		||||
  int First_occurence;
 | 
			
		||||
  int Previous;
 | 
			
		||||
  int Next;
 | 
			
		||||
} T_Tile;
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										56
									
								
								src/tiles.c
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								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<width*height; tile++)
 | 
			
		||||
  {
 | 
			
		||||
    Main_tilemap[tile].Previous_occurence = tile;
 | 
			
		||||
    Main_tilemap[tile].Next_occurence = tile;
 | 
			
		||||
    //Main_tilemap[tile].First_occurence = 1;
 | 
			
		||||
    Main_tilemap[tile].Previous = tile;
 | 
			
		||||
    Main_tilemap[tile].Next = tile;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  // Now find similar tiles and link them in circular linked list
 | 
			
		||||
  //It will be used to modify all tiles whenever you draw on one.
 | 
			
		||||
  for (tile=1; tile<width*height; tile++)
 | 
			
		||||
  {
 | 
			
		||||
    int ref_tile=0;
 | 
			
		||||
    while(1)
 | 
			
		||||
    {
 | 
			
		||||
      if (Main_tilemap[ref_tile].Previous_occurence<=ref_tile && Tile_is_same(ref_tile, tile))
 | 
			
		||||
      if (Main_tilemap[ref_tile].Previous<=ref_tile && Tile_is_same(ref_tile, tile))
 | 
			
		||||
      {
 | 
			
		||||
        // Insert at end
 | 
			
		||||
        int last_tile=Main_tilemap[ref_tile].Previous_occurence;
 | 
			
		||||
        Main_tilemap[tile].Previous_occurence=last_tile;
 | 
			
		||||
        Main_tilemap[tile].Next_occurence=ref_tile;
 | 
			
		||||
        //Main_tilemap[tile].First_occurence=0;
 | 
			
		||||
        
 | 
			
		||||
        Main_tilemap[ref_tile].Previous_occurence=tile;
 | 
			
		||||
        Main_tilemap[last_tile].Next_occurence=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[ref_tile].Previous=tile;
 | 
			
		||||
        Main_tilemap[last_tile].Next=tile;
 | 
			
		||||
        
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // next
 | 
			
		||||
      ref_tile++;
 | 
			
		||||
 | 
			
		||||
      // end of loop without finding a match
 | 
			
		||||
      if (ref_tile>=tile)
 | 
			
		||||
      {
 | 
			
		||||
        // New unique tile
 | 
			
		||||
        //Main_tilemap[tile].First_occurence=1;
 | 
			
		||||
        // This tile is really unique.
 | 
			
		||||
        // Nothing to do at the moment
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										38
									
								
								src/tiles.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/tiles.h
									
									
									
									
									
										Normal file
									
								
							@ -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 <http://www.gnu.org/licenses/>
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
//////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
///@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)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user