Tilemap: now separate for main and spare. Safeties added in most places necessary (auto-recompute tilemap after load, undo, etc)
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1866 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
83fff59f66
commit
e7d37cf367
@ -70,6 +70,7 @@
|
||||
#include "brush.h"
|
||||
#include "input.h"
|
||||
#include "special.h"
|
||||
#include "tiles.h"
|
||||
#include "setup.h"
|
||||
|
||||
#ifdef __VBCC__
|
||||
@ -210,7 +211,7 @@ void Button_Undo(void)
|
||||
{
|
||||
Hide_cursor();
|
||||
Undo();
|
||||
|
||||
Tilemap_update();
|
||||
Set_palette(Main_palette);
|
||||
Compute_optimal_menu_colors(Main_palette);
|
||||
|
||||
@ -225,7 +226,7 @@ void Button_Redo(void)
|
||||
{
|
||||
Hide_cursor();
|
||||
Redo();
|
||||
|
||||
Tilemap_update();
|
||||
Set_palette(Main_palette);
|
||||
Compute_optimal_menu_colors(Main_palette);
|
||||
|
||||
@ -1529,6 +1530,9 @@ void Button_Page(void)
|
||||
// On dégrossit le travail avec les infos des listes de pages
|
||||
Exchange_main_and_spare();
|
||||
|
||||
// Tilemap info
|
||||
Swap_tilemap();
|
||||
|
||||
// On fait le reste du travail "ŕ la main":
|
||||
#ifndef NOLAYERS
|
||||
SWAP_PBYTES(Main_visible_image.Image,Spare_visible_image.Image)
|
||||
@ -1724,6 +1728,8 @@ void Button_Copy_page(void)
|
||||
Update_spare_buffers(Spare_image_width,Spare_image_height);
|
||||
Redraw_spare_image();
|
||||
Spare_image_is_modified=1;
|
||||
if (Spare_tilemap_mode)
|
||||
Disable_spare_tilemap();
|
||||
break;
|
||||
|
||||
case 2: // Pixels only
|
||||
@ -1733,6 +1739,8 @@ void Button_Copy_page(void)
|
||||
Update_spare_buffers(Spare_image_width,Spare_image_height);
|
||||
Redraw_spare_image();
|
||||
Spare_image_is_modified=1;
|
||||
if (Spare_tilemap_mode)
|
||||
Disable_spare_tilemap();
|
||||
break;
|
||||
|
||||
case 3: // Palette only
|
||||
@ -2185,7 +2193,8 @@ void Button_Resolution(void)
|
||||
|| (chosen_height!=Main_image_height) )
|
||||
{
|
||||
Resize_image(chosen_width,chosen_height);
|
||||
End_of_modification();
|
||||
End_of_modification();
|
||||
Tilemap_update();
|
||||
}
|
||||
|
||||
if ((Video_mode[selected_mode].State & 3) == 3 ||
|
||||
@ -3275,6 +3284,7 @@ void Button_Load(void)
|
||||
Upload_infos_page_main(Main_backups->Pages);
|
||||
|
||||
Load_picture(1);
|
||||
Tilemap_update();
|
||||
}
|
||||
|
||||
|
||||
@ -3346,6 +3356,7 @@ void Button_Reload(void)
|
||||
Compute_limits();
|
||||
Compute_paintbrush_coordinates();
|
||||
}
|
||||
Tilemap_update();
|
||||
Redraw_layered_image();
|
||||
End_of_modification();
|
||||
Display_all_screen();
|
||||
@ -4494,7 +4505,7 @@ void Display_effect_states(void)
|
||||
Display_effect_state(C2+23,100, "Tiling" ,Tiling_mode);
|
||||
|
||||
Display_effect_state(177+23,24, "8 bit" ,Constraint_mode);
|
||||
Display_effect_state(177+23,43, "Tilemap",Tilemap_mode);
|
||||
Display_effect_state(177+23,43, "Tilemap",Main_tilemap_mode);
|
||||
}
|
||||
|
||||
|
||||
@ -4791,7 +4802,7 @@ void Button_Effects(void)
|
||||
case 15: // Tilemap
|
||||
Button_Tilemap_mode();
|
||||
Hide_cursor();
|
||||
Display_effect_state(177+23,43, "Tilemap" ,Tilemap_mode);
|
||||
Display_effect_state(177+23,43, "Tilemap" ,Main_tilemap_mode);
|
||||
Display_cursor();
|
||||
break;
|
||||
}
|
||||
@ -4803,7 +4814,7 @@ void Button_Effects(void)
|
||||
else
|
||||
Hide_cursor();
|
||||
|
||||
if (!(Shade_mode||Quick_shade_mode||Colorize_mode||Smooth_mode||Tiling_mode||Smear_mode||Stencil_mode||Mask_mode||Sieve_mode||Snap_mode||Constraint_mode||Tilemap_mode))
|
||||
if (!(Shade_mode||Quick_shade_mode||Colorize_mode||Smooth_mode||Tiling_mode||Smear_mode||Stencil_mode||Mask_mode||Sieve_mode||Snap_mode||Constraint_mode||Main_tilemap_mode))
|
||||
Unselect_button(BUTTON_EFFECTS);
|
||||
|
||||
Display_cursor();
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
#include "sdlscreen.h"
|
||||
#include "struct.h"
|
||||
#include "windows.h"
|
||||
#include "tiles.h"
|
||||
|
||||
//---------- Menu dans lequel on tagge des couleurs (genre Stencil) ----------
|
||||
void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section, word close_shortcut)
|
||||
@ -192,9 +193,8 @@ void Button_Constraint_menu(void)
|
||||
// Tilemap mode
|
||||
void Button_Tilemap_mode(void)
|
||||
{
|
||||
Tilemap_mode=!Tilemap_mode;
|
||||
if (Tilemap_mode)
|
||||
Tilemap_create();
|
||||
Main_tilemap_mode=!Main_tilemap_mode;
|
||||
Tilemap_update();
|
||||
}
|
||||
|
||||
void Button_Tilemap_menu(void)
|
||||
@ -413,12 +413,25 @@ void Button_Grid_menu(void)
|
||||
|
||||
if (clicked_button==2) // OK
|
||||
{
|
||||
byte modified;
|
||||
|
||||
modified = Snap_width!=chosen_X
|
||||
|| Snap_height!=chosen_Y
|
||||
|| Snap_offset_X!=dx_selected
|
||||
|| Snap_offset_Y!=dy_selected;
|
||||
|
||||
Snap_width=chosen_X;
|
||||
Snap_height=chosen_Y;
|
||||
Snap_offset_X=dx_selected;
|
||||
Snap_offset_Y=dy_selected;
|
||||
Snap_mode=snapgrid;
|
||||
Show_grid=showgrid;
|
||||
|
||||
if (modified)
|
||||
{
|
||||
Tilemap_update();
|
||||
Disable_spare_tilemap();
|
||||
}
|
||||
}
|
||||
|
||||
Close_window();
|
||||
@ -834,7 +847,7 @@ void Effects_off(void)
|
||||
Sieve_mode=0;
|
||||
Snap_mode=0;
|
||||
Constraint_mode=0;
|
||||
Tilemap_mode=0;
|
||||
Main_tilemap_mode=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
15
src/global.h
15
src/global.h
@ -348,13 +348,6 @@ GFX2_GLOBAL Uint32 Main_time_of_safety_backup;
|
||||
/// Letter prefix for the filenames of safety backups. a or b
|
||||
GFX2_GLOBAL byte Main_safety_backup_prefix;
|
||||
|
||||
/// Tilemap for the main screen
|
||||
GFX2_GLOBAL T_Tile * Main_tilemap;
|
||||
|
||||
GFX2_GLOBAL short Main_tilemap_width;
|
||||
GFX2_GLOBAL short Main_tilemap_height;
|
||||
GFX2_GLOBAL byte Main_tilemap_allow_flip; ///< 0:no, 1:horizontally, 2:vertically, 3:both
|
||||
|
||||
// -- Spare page data
|
||||
|
||||
/// Palette of the spare page
|
||||
@ -740,11 +733,11 @@ GFX2_GLOBAL byte Constraint_mode;
|
||||
|
||||
// -- Tilemap mode
|
||||
|
||||
/// Tilemap mode
|
||||
GFX2_GLOBAL byte Tilemap_mode;
|
||||
/// Tilemap mode for main page
|
||||
GFX2_GLOBAL byte Main_tilemap_mode;
|
||||
|
||||
/// Tilemap allows swapped tiles : 0:No 1:Horizontal 2:Vertical 3:Both
|
||||
GFX2_GLOBAL byte Tilemap_allow_swap;
|
||||
/// Tilemap mode for spare page
|
||||
GFX2_GLOBAL byte Spare_tilemap_mode;
|
||||
|
||||
// -- Magnifier data
|
||||
|
||||
|
||||
@ -2747,7 +2747,7 @@ void Display_pixel(word x,word y,byte color)
|
||||
&& (!((Mask_mode) && (Mask_table[Read_pixel_from_spare_screen(x,y)]))) )
|
||||
{
|
||||
color=Effect_function(x,y,color);
|
||||
if (Tilemap_mode)
|
||||
if (Main_tilemap_mode)
|
||||
{
|
||||
Tilemap_draw(x,y, color);
|
||||
}
|
||||
|
||||
182
src/tiles.c
182
src/tiles.c
@ -29,6 +29,26 @@
|
||||
#include "misc.h"
|
||||
#include "tiles.h"
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
// globals
|
||||
T_Tile * Main_tilemap;
|
||||
short Main_tilemap_width;
|
||||
short Main_tilemap_height;
|
||||
|
||||
T_Tile * Spare_tilemap;
|
||||
short Spare_tilemap_width;
|
||||
short Spare_tilemap_height;
|
||||
|
||||
T_Tilemap_settings Tilemap_settings = { 0, 0, 0, 0};
|
||||
|
||||
//
|
||||
|
||||
/// Build the tile-area from the current picture
|
||||
void build_tile_area()
|
||||
@ -253,7 +273,7 @@ int Tile_is_same_flipped_xy(int t1, int t2)
|
||||
}
|
||||
|
||||
/// Create or update a tilemap based on current screen (layer)'s pixels.
|
||||
void Tilemap_create(void)
|
||||
void Tilemap_update(void)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
@ -262,8 +282,11 @@ void Tilemap_create(void)
|
||||
T_Tile * tile_ptr;
|
||||
|
||||
int wait_window=0;
|
||||
byte old_cursor;
|
||||
byte old_cursor=0;
|
||||
|
||||
if (!Main_tilemap_mode)
|
||||
return;
|
||||
|
||||
width=(Main_image_width-Snap_offset_X)/Snap_width;
|
||||
height=(Main_image_height-Snap_offset_Y)/Snap_height;
|
||||
|
||||
@ -275,15 +298,7 @@ void Tilemap_create(void)
|
||||
// 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;
|
||||
}
|
||||
Main_tilemap_width=0;
|
||||
Main_tilemap_height=0;
|
||||
Tilemap_mode=0;
|
||||
Disable_main_tilemap();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -298,7 +313,7 @@ void Tilemap_create(void)
|
||||
Main_tilemap_width=width;
|
||||
Main_tilemap_height=height;
|
||||
|
||||
if (width*height > 1000 || 1)
|
||||
if (width*height > 1000 || Tilemap_settings.Show_tile_count)
|
||||
{
|
||||
wait_window=1;
|
||||
Open_window(180,36,"Creating tileset");
|
||||
@ -347,69 +362,75 @@ void Tilemap_create(void)
|
||||
}
|
||||
|
||||
// Try flipped-y comparison
|
||||
|
||||
for (ref_tile=0; ref_tile<tile; ref_tile++)
|
||||
if (Tilemap_settings.Allow_flipped_y)
|
||||
{
|
||||
if (Main_tilemap[ref_tile].Previous<=ref_tile && Tile_is_same_flipped_y(ref_tile, tile))
|
||||
for (ref_tile=0; ref_tile<tile; ref_tile++)
|
||||
{
|
||||
break; // stop loop on ref_tile
|
||||
if (Main_tilemap[ref_tile].Previous<=ref_tile && Tile_is_same_flipped_y(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_Y;
|
||||
Main_tilemap[ref_tile].Previous=tile;
|
||||
Main_tilemap[last_tile].Next=tile;
|
||||
continue; // next 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_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 (Tilemap_settings.Allow_flipped_x)
|
||||
{
|
||||
if (Main_tilemap[ref_tile].Previous<=ref_tile && Tile_is_same_flipped_x(ref_tile, tile))
|
||||
for (ref_tile=0; ref_tile<tile; ref_tile++)
|
||||
{
|
||||
break; // stop loop on 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
|
||||
}
|
||||
}
|
||||
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 (Tilemap_settings.Allow_flipped_xy)
|
||||
{
|
||||
if (Main_tilemap[ref_tile].Previous<=ref_tile && Tile_is_same_flipped_xy(ref_tile, tile))
|
||||
for (ref_tile=0; ref_tile<tile; ref_tile++)
|
||||
{
|
||||
break; // stop loop on 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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
// This tile is really unique.
|
||||
@ -440,4 +461,43 @@ void Tilemap_create(void)
|
||||
Cursor_shape=old_cursor;
|
||||
Display_cursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Swap_tilemap(void)
|
||||
{
|
||||
SWAP_BYTES(Main_tilemap_mode, Spare_tilemap_mode)
|
||||
{
|
||||
T_Tile * a;
|
||||
a=Main_tilemap;
|
||||
Main_tilemap=Spare_tilemap;
|
||||
Spare_tilemap=a;
|
||||
}
|
||||
SWAP_SHORTS(Main_tilemap_width, Spare_tilemap_width)
|
||||
SWAP_SHORTS(Main_tilemap_height, Spare_tilemap_height)
|
||||
}
|
||||
|
||||
void Disable_main_tilemap(void)
|
||||
{
|
||||
if (Main_tilemap)
|
||||
{
|
||||
// Recycle existing tilemap
|
||||
free(Main_tilemap);
|
||||
Main_tilemap=NULL;
|
||||
}
|
||||
Main_tilemap_width=0;
|
||||
Main_tilemap_height=0;
|
||||
Main_tilemap_mode=0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
37
src/tiles.h
37
src/tiles.h
@ -27,19 +27,42 @@
|
||||
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_update(void);
|
||||
|
||||
void Tilemap_draw(word x, word y, byte color);
|
||||
|
||||
void Swap_tilemap(void);
|
||||
|
||||
void Disable_main_tilemap(void);
|
||||
|
||||
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)
|
||||
|
||||
enum TILE_FLIPPED
|
||||
typedef struct
|
||||
{
|
||||
TILE_FLIPPED_NONE = 0,
|
||||
TILE_FLIPPED_X = 1,
|
||||
TILE_FLIPPED_Y = 2,
|
||||
TILE_FLIPPED_XY = 3, // needs be TILE_FLIPPED_X|TILE_FLIPPED_Y
|
||||
};
|
||||
byte Allow_flipped_x;
|
||||
byte Allow_flipped_y;
|
||||
byte Allow_flipped_xy;
|
||||
byte Show_tile_count;
|
||||
|
||||
} T_Tilemap_settings;
|
||||
|
||||
|
||||
|
||||
extern T_Tilemap_settings Tilemap_settings;
|
||||
|
||||
/// Tilemap for the main screen
|
||||
|
||||
extern T_Tile * Main_tilemap;
|
||||
|
||||
extern short Main_tilemap_width;
|
||||
extern short Main_tilemap_height;
|
||||
|
||||
extern T_Tile * Spare_tilemap;
|
||||
|
||||
extern short Spare_tilemap_width;
|
||||
extern short Spare_tilemap_height;
|
||||
|
||||
@ -434,6 +434,7 @@ void Button_Transform_menu(void)
|
||||
Redraw_layered_image();
|
||||
Display_all_screen();
|
||||
End_of_modification();
|
||||
Tilemap_update();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user