mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 11:10:47 +00:00
Use LZF for undo/redo snapshots
git-svn-id: https://svn.eduke32.com/eduke32@1362 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
f3d93e8406
commit
024edae792
2 changed files with 55 additions and 85 deletions
|
@ -217,6 +217,7 @@ int32_t menuselect_pk(int32_t); //PK
|
||||||
int32_t getfilenames(char *path, char *kind);
|
int32_t getfilenames(char *path, char *kind);
|
||||||
void clearfilenames(void);
|
void clearfilenames(void);
|
||||||
void loadmhk();
|
void loadmhk();
|
||||||
|
extern int32_t map_revision;
|
||||||
|
|
||||||
void clearkeys(void) { memset(keystatus,0,sizeof(keystatus)); }
|
void clearkeys(void) { memset(keystatus,0,sizeof(keystatus)); }
|
||||||
|
|
||||||
|
@ -5733,58 +5734,6 @@ int16_t whitelinescan(int16_t dalinehighlight)
|
||||||
else
|
else
|
||||||
return(newnumwalls);
|
return(newnumwalls);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
#define loadbyte(fil,tempbuf,bufplc,dat) \
|
|
||||||
{ \
|
|
||||||
if (bufplc == 0) \
|
|
||||||
{ \
|
|
||||||
for(bufplc=0;bufplc<4096;bufplc++) \
|
|
||||||
tempbuf[bufplc] = 0; \
|
|
||||||
bufplc = 0; \
|
|
||||||
read(fil,tempbuf,4096); \
|
|
||||||
} \
|
|
||||||
dat = tempbuf[bufplc]; \
|
|
||||||
bufplc = ((bufplc+1)&4095); \
|
|
||||||
} \
|
|
||||||
|
|
||||||
int32_t loadnames(void)
|
|
||||||
{
|
|
||||||
char buffer[80], firstch, ch;
|
|
||||||
int32_t fil, i, num, buffercnt, bufplc;
|
|
||||||
|
|
||||||
if ((fil = open("names.h",O_BINARY|O_RDWR,S_IREAD)) == -1) return(-1);
|
|
||||||
bufplc = 0;
|
|
||||||
do { loadbyte(fil,tempbuf,bufplc,firstch); } while (firstch != '#');
|
|
||||||
|
|
||||||
while ((firstch == '#') || (firstch == '/'))
|
|
||||||
{
|
|
||||||
do { loadbyte(fil,tempbuf,bufplc,ch); } while (ch > 32);
|
|
||||||
|
|
||||||
buffercnt = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
loadbyte(fil,tempbuf,bufplc,ch);
|
|
||||||
if (ch > 32) buffer[buffercnt++] = ch;
|
|
||||||
}
|
|
||||||
while (ch > 32);
|
|
||||||
|
|
||||||
num = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
loadbyte(fil,tempbuf,bufplc,ch);
|
|
||||||
if ((ch >= 48) && (ch <= 57)) num = num*10+(ch-48);
|
|
||||||
}
|
|
||||||
while (ch != 13);
|
|
||||||
for(i=0;i<buffercnt;i++) names[num][i] = buffer[i];
|
|
||||||
names[num][buffercnt] = 0;
|
|
||||||
|
|
||||||
loadbyte(fil,tempbuf,bufplc,firstch);
|
|
||||||
if (firstch == 10) loadbyte(fil,tempbuf,bufplc,firstch);
|
|
||||||
}
|
|
||||||
close(fil);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
int32_t loadnames(void)
|
int32_t loadnames(void)
|
||||||
{
|
{
|
||||||
|
@ -5912,16 +5861,16 @@ void printcoords16(int32_t posxe, int32_t posye, int16_t ange)
|
||||||
char snotbuf[80];
|
char snotbuf[80];
|
||||||
int32_t i,m;
|
int32_t i,m;
|
||||||
|
|
||||||
Bsprintf(snotbuf,"x:%d y:%d ang:%d",posxe,posye,ange);
|
Bsprintf(snotbuf,"x:%d y:%d ang:%d r%d",posxe,posye,ange,map_revision-1);
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((snotbuf[i] != 0) && (i < 30))
|
while ((snotbuf[i] != 0) && (i < 33))
|
||||||
i++;
|
i++;
|
||||||
while (i < 30)
|
while (i < 33)
|
||||||
{
|
{
|
||||||
snotbuf[i] = 32;
|
snotbuf[i] = 32;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
snotbuf[30] = 0;
|
snotbuf[33] = 0;
|
||||||
|
|
||||||
clearministatbar16();
|
clearministatbar16();
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "fx_man.h"
|
#include "fx_man.h"
|
||||||
|
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
#include "lzf.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
@ -114,7 +115,7 @@ void message(const char *fmt, ...)
|
||||||
|
|
||||||
Bstrcpy(getmessage,tmpstr);
|
Bstrcpy(getmessage,tmpstr);
|
||||||
getmessageleng = strlen(getmessage);
|
getmessageleng = strlen(getmessage);
|
||||||
getmessagetimeoff = totalclock+120*3;
|
getmessagetimeoff = totalclock+120*2;
|
||||||
lastmessagetime = totalclock;
|
lastmessagetime = totalclock;
|
||||||
if (!mouseaction)
|
if (!mouseaction)
|
||||||
{
|
{
|
||||||
|
@ -123,8 +124,6 @@ void message(const char *fmt, ...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UNDODEPTH 96
|
|
||||||
|
|
||||||
typedef struct _mapundo
|
typedef struct _mapundo
|
||||||
{
|
{
|
||||||
int32_t numsectors;
|
int32_t numsectors;
|
||||||
|
@ -137,9 +136,8 @@ typedef struct _mapundo
|
||||||
|
|
||||||
int32_t revision;
|
int32_t revision;
|
||||||
|
|
||||||
uint32_t sectcrc;
|
uint32_t sectcrc, wallcrc, spritecrc;
|
||||||
uint32_t wallcrc;
|
uint32_t sectsiz, wallsiz, spritesiz;
|
||||||
uint32_t spritecrc;
|
|
||||||
|
|
||||||
struct _mapundo *next; // 'redo' loads this
|
struct _mapundo *next; // 'redo' loads this
|
||||||
struct _mapundo *prev; // 'undo' loads this
|
struct _mapundo *prev; // 'undo' loads this
|
||||||
|
@ -152,6 +150,7 @@ int32_t map_revision = 0;
|
||||||
void create_map_snapshot(void)
|
void create_map_snapshot(void)
|
||||||
{
|
{
|
||||||
int32_t j;
|
int32_t j;
|
||||||
|
uint32_t tempcrc;
|
||||||
|
|
||||||
// if (mapstate == NULL) mapstate = (mapundo_t *)Bcalloc(1, sizeof(mapundo_t));
|
// if (mapstate == NULL) mapstate = (mapundo_t *)Bcalloc(1, sizeof(mapundo_t));
|
||||||
|
|
||||||
|
@ -192,8 +191,9 @@ void create_map_snapshot(void)
|
||||||
mapstate->numwalls = numwalls;
|
mapstate->numwalls = numwalls;
|
||||||
mapstate->numsprites = numsprites;
|
mapstate->numsprites = numsprites;
|
||||||
|
|
||||||
if (mapstate->prev && mapstate->prev->numsectors == numsectors &&
|
tempcrc = crc32once((uint8_t *)§or[0],sizeof(sectortype) * numsectors);
|
||||||
mapstate->prev->sectcrc == crc32once((uint8_t *)§or[0],sizeof(sectortype) * numsectors))
|
|
||||||
|
if (mapstate->prev && mapstate->prev->numsectors == numsectors && mapstate->prev->sectcrc == tempcrc)
|
||||||
{
|
{
|
||||||
mapstate->sectors = mapstate->prev->sectors;
|
mapstate->sectors = mapstate->prev->sectors;
|
||||||
/*OSD_Printf("found a match between undo sectors\n");*/
|
/*OSD_Printf("found a match between undo sectors\n");*/
|
||||||
|
@ -201,12 +201,15 @@ void create_map_snapshot(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mapstate->sectors = (sectortype *)Bcalloc(1, sizeof(sectortype) * numsectors);
|
mapstate->sectors = (sectortype *)Bcalloc(1, sizeof(sectortype) * numsectors);
|
||||||
Bmemcpy(&mapstate->sectors[0], §or[0], sizeof(sectortype) * numsectors);
|
mapstate->sectsiz = j = lzf_compress(§or[0], sizeof(sectortype) * numsectors,
|
||||||
mapstate->sectcrc = crc32once((uint8_t *)&mapstate->sectors[0],sizeof(sectortype) * numsectors);
|
&mapstate->sectors[0], sizeof(sectortype) * numsectors);
|
||||||
|
mapstate->sectors = (sectortype *)Brealloc(mapstate->sectors, j);
|
||||||
|
mapstate->sectcrc = tempcrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapstate->prev && mapstate->prev->numwalls == numwalls &&
|
tempcrc = crc32once((uint8_t *)&wall[0],sizeof(walltype) * numwalls);
|
||||||
mapstate->prev->wallcrc == crc32once((uint8_t *)&wall[0],sizeof(walltype) * numwalls))
|
|
||||||
|
if (mapstate->prev && mapstate->prev->numwalls == numwalls && mapstate->prev->wallcrc == tempcrc)
|
||||||
{
|
{
|
||||||
mapstate->walls = mapstate->prev->walls;
|
mapstate->walls = mapstate->prev->walls;
|
||||||
/*OSD_Printf("found a match between undo walls\n");*/
|
/*OSD_Printf("found a match between undo walls\n");*/
|
||||||
|
@ -214,28 +217,36 @@ void create_map_snapshot(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mapstate->walls = (walltype *)Bcalloc(1, sizeof(walltype) * numwalls);
|
mapstate->walls = (walltype *)Bcalloc(1, sizeof(walltype) * numwalls);
|
||||||
Bmemcpy(&mapstate->walls[0], &wall[0], sizeof(walltype) * numwalls);
|
mapstate->wallsiz = j = lzf_compress(&wall[0], sizeof(walltype) * numwalls,
|
||||||
mapstate->wallcrc = crc32once((uint8_t *)&mapstate->walls[0],sizeof(walltype) * numwalls);
|
&mapstate->walls[0], sizeof(walltype) * numwalls);
|
||||||
|
mapstate->walls = (walltype *)Brealloc(mapstate->walls, j);
|
||||||
|
mapstate->wallcrc = tempcrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapstate->prev && mapstate->prev->numsprites == numsprites &&
|
tempcrc = crc32once((uint8_t *)&sprite[0],sizeof(spritetype) * numsprites);
|
||||||
mapstate->prev->spritecrc == crc32once((uint8_t *)&sprite[0],sizeof(spritetype) * numsprites))
|
|
||||||
|
if (mapstate->prev && mapstate->prev->numsprites == numsprites && mapstate->prev->spritecrc == tempcrc)
|
||||||
{
|
{
|
||||||
mapstate->sprites = mapstate->prev->sprites;
|
mapstate->sprites = mapstate->prev->sprites;
|
||||||
/*OSD_Printf("found a match between undo sprites\n");*/
|
/*OSD_Printf("found a match between undo sprites\n");*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
spritetype *spri;
|
spritetype *spri, *tspri = (spritetype *)Bcalloc(1, sizeof(spritetype) * numsprites);
|
||||||
mapstate->sprites = (spritetype *)Bcalloc(1, sizeof(spritetype) * numsprites);
|
mapstate->sprites = (spritetype *)Bcalloc(1, sizeof(spritetype) * numsprites);
|
||||||
spri=&mapstate->sprites[0];
|
|
||||||
|
spri = &tspri[0];
|
||||||
|
|
||||||
for (j=0; j<MAXSPRITES; j++)
|
for (j=0; j<MAXSPRITES; j++)
|
||||||
{
|
{
|
||||||
if (sprite[j].statnum != MAXSTATUS)
|
if (sprite[j].statnum != MAXSTATUS)
|
||||||
Bmemcpy(spri++,&sprite[j],sizeof(spritetype));
|
Bmemcpy(spri++,&sprite[j],sizeof(spritetype));
|
||||||
}
|
}
|
||||||
mapstate->spritecrc = crc32once((uint8_t *)&mapstate->sprites[0],sizeof(spritetype) * numsprites);
|
mapstate->spritesiz = j = lzf_compress(&tspri[0], sizeof(spritetype) * numsprites,
|
||||||
|
&mapstate->sprites[0], sizeof(spritetype) * numsprites);
|
||||||
|
mapstate->sprites = (spritetype *)Brealloc(mapstate->sprites, j);
|
||||||
|
mapstate->spritecrc = tempcrc;
|
||||||
|
Bfree(tspri);
|
||||||
}
|
}
|
||||||
|
|
||||||
mapstate->revision = ++map_revision;
|
mapstate->revision = ++map_revision;
|
||||||
|
@ -246,7 +257,7 @@ int32_t map_undo(void)
|
||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
if (mapstate == NULL || mapstate->prev == NULL) return 1;
|
if (mapstate == NULL || mapstate->prev == NULL || !mapstate->prev->numsectors) return 1;
|
||||||
|
|
||||||
mapstate = mapstate->prev;
|
mapstate = mapstate->prev;
|
||||||
|
|
||||||
|
@ -256,9 +267,9 @@ int32_t map_undo(void)
|
||||||
|
|
||||||
initspritelists();
|
initspritelists();
|
||||||
|
|
||||||
Bmemcpy(§or[0], &mapstate->sectors[0], sizeof(sectortype) * numsectors);
|
lzf_decompress(&mapstate->sectors[0], mapstate->sectsiz, §or[0], sizeof(sectortype) * numsectors);
|
||||||
Bmemcpy(&wall[0], &mapstate->walls[0], sizeof(walltype) * numwalls);
|
lzf_decompress(&mapstate->walls[0], mapstate->wallsiz, &wall[0], sizeof(walltype) * numwalls);
|
||||||
Bmemcpy(&sprite[0], &mapstate->sprites[0], sizeof(spritetype) * numsprites);
|
lzf_decompress(&mapstate->sprites[0], mapstate->spritesiz, &sprite[0], sizeof(spritetype) * numsprites);
|
||||||
|
|
||||||
updatenumsprites();
|
updatenumsprites();
|
||||||
|
|
||||||
|
@ -270,6 +281,10 @@ int32_t map_undo(void)
|
||||||
|
|
||||||
map_revision = mapstate->revision;
|
map_revision = mapstate->revision;
|
||||||
|
|
||||||
|
#ifdef POLYMER
|
||||||
|
if (qsetmode == 200 && rendmode == 4)
|
||||||
|
polymer_loadboard();
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,9 +302,9 @@ int32_t map_redo(void)
|
||||||
|
|
||||||
initspritelists();
|
initspritelists();
|
||||||
|
|
||||||
Bmemcpy(§or[0], &mapstate->sectors[0], sizeof(sectortype) * numsectors);
|
lzf_decompress(&mapstate->sectors[0], mapstate->sectsiz, §or[0], sizeof(sectortype) * numsectors);
|
||||||
Bmemcpy(&wall[0], &mapstate->walls[0], sizeof(walltype) * numwalls);
|
lzf_decompress(&mapstate->walls[0], mapstate->wallsiz, &wall[0], sizeof(walltype) * numwalls);
|
||||||
Bmemcpy(&sprite[0], &mapstate->sprites[0], sizeof(spritetype) * numsprites);
|
lzf_decompress(&mapstate->sprites[0], mapstate->spritesiz, &sprite[0], sizeof(spritetype) * numsprites);
|
||||||
|
|
||||||
updatenumsprites();
|
updatenumsprites();
|
||||||
|
|
||||||
|
@ -301,6 +316,10 @@ int32_t map_redo(void)
|
||||||
|
|
||||||
map_revision = mapstate->revision;
|
map_revision = mapstate->revision;
|
||||||
|
|
||||||
|
#ifdef POLYMER
|
||||||
|
if (qsetmode == 200 && rendmode == 4)
|
||||||
|
polymer_loadboard();
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7474,7 +7493,7 @@ static void Keys2d(void)
|
||||||
{
|
{
|
||||||
showsectordata((int16_t)cursectornum+16384);
|
showsectordata((int16_t)cursectornum+16384);
|
||||||
}
|
}
|
||||||
if (totalclock < (lastpm16time + 120*3))
|
if (totalclock < (lastpm16time + 120*2))
|
||||||
_printmessage16(lastpm16buf);
|
_printmessage16(lastpm16buf);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -10260,6 +10279,8 @@ static void Keys2d3d(void)
|
||||||
{
|
{
|
||||||
mapstate = (mapundo_t *)Bcalloc(1, sizeof(mapundo_t));
|
mapstate = (mapundo_t *)Bcalloc(1, sizeof(mapundo_t));
|
||||||
create_map_snapshot(); // initial map state
|
create_map_snapshot(); // initial map state
|
||||||
|
Bfree(mapstate->next);
|
||||||
|
mapstate = mapstate->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_A]) // ' a
|
if (keystatus[KEYSC_QUOTE] && keystatus[KEYSC_A]) // ' a
|
||||||
|
@ -10295,12 +10316,12 @@ static void Keys2d3d(void)
|
||||||
if (eitherSHIFT)
|
if (eitherSHIFT)
|
||||||
{
|
{
|
||||||
if (map_redo()) message("Nothing to redo!");
|
if (map_redo()) message("Nothing to redo!");
|
||||||
else message("Restored undo rev %d",map_revision);
|
else message("Restored undo rev %d",map_revision-1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (map_undo()) message("Nothing to undo!");
|
if (map_undo()) message("Nothing to undo!");
|
||||||
else message("Restored undo rev %d",map_revision);
|
else message("Restored undo rev %d",map_revision-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue