undo improvements

git-svn-id: https://svn.eduke32.com/eduke32@1363 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2009-05-05 21:25:06 +00:00
parent 024edae792
commit e47b890189
2 changed files with 32 additions and 43 deletions

View file

@ -218,6 +218,7 @@ int32_t getfilenames(char *path, char *kind);
void clearfilenames(void); void clearfilenames(void);
void loadmhk(); void loadmhk();
extern int32_t map_revision; extern int32_t map_revision;
extern int32_t map_undoredo(int32_t dir);
void clearkeys(void) { memset(keystatus,0,sizeof(keystatus)); } void clearkeys(void) { memset(keystatus,0,sizeof(keystatus)); }
@ -4148,8 +4149,7 @@ CANCEL:
if (keystatus[1]) if (keystatus[1])
{ {
keystatus[1] = 0; keystatus[1] = 0;
_printmessage16("(N)ew, (L)oad, (S)ave, save (A)s, (T)est map, (Q)uit"); _printmessage16("(N)ew, (L)oad, (S)ave, save (A)s, (T)est map, (U)ndo, (R)edo, (Q)uit");
// printext16(200L+248, ydim-STATUS2DSIZ+20L, 9, 0, "(U)ndo, (R)edo", 0);
showframe(1); showframe(1);
bflushchars(); bflushchars();
bad = 1; bad = 1;
@ -4511,6 +4511,18 @@ CANCEL:
{ {
test_map(0); test_map(0);
} }
else if (ch == 'u' || ch == 'U')
{
bad = 0;
if (map_undoredo(0)) printmessage16("Nothing to undo!");
else printmessage16("Revision %d undone",map_revision);
}
else if (ch == 'r' || ch == 'R')
{
bad = 0;
if (map_undoredo(1)) printmessage16("Nothing to redo!");
else printmessage16("Restored revision %d",map_revision-1);
}
else if (ch == 'q' || ch == 'Q') //Q else if (ch == 'q' || ch == 'Q') //Q
{ {
bad = 0; bad = 0;

View file

@ -253,48 +253,24 @@ void create_map_snapshot(void)
mapstate = mapstate->next; mapstate = mapstate->next;
} }
int32_t map_undo(void) int32_t map_undoredo(int32_t dir)
{ {
int32_t i; int32_t i;
if (mapstate == NULL || mapstate->prev == NULL || !mapstate->prev->numsectors) return 1; if (dir)
mapstate = mapstate->prev;
numsectors = mapstate->numsectors;
numwalls = mapstate->numwalls;
numsprites = mapstate->numsprites;
initspritelists();
lzf_decompress(&mapstate->sectors[0], mapstate->sectsiz, &sector[0], sizeof(sectortype) * numsectors);
lzf_decompress(&mapstate->walls[0], mapstate->wallsiz, &wall[0], sizeof(walltype) * numwalls);
lzf_decompress(&mapstate->sprites[0], mapstate->spritesiz, &sprite[0], sizeof(spritetype) * numsprites);
updatenumsprites();
for (i=0; i<numsprites; i++)
{ {
if ((sprite[i].cstat & 48) == 48) sprite[i].cstat &= ~48; if (mapstate == NULL || mapstate->next == NULL || !mapstate->next->numsectors) return 1;
insertsprite(sprite[i].sectnum,sprite[i].statnum);
while (map_revision+1 != mapstate->revision)
mapstate = mapstate->next;
} }
else
{
if (mapstate == NULL || mapstate->prev == NULL || !mapstate->prev->numsectors) return 1;
map_revision = mapstate->revision; while (map_revision-1 != mapstate->revision)
mapstate = mapstate->prev;
#ifdef POLYMER }
if (qsetmode == 200 && rendmode == 4)
polymer_loadboard();
#endif
return 0;
}
int32_t map_redo(void)
{
int32_t i;
if (mapstate == NULL || mapstate->next == NULL || !mapstate->next->numsectors) return 1;
mapstate = mapstate->next;
numsectors = mapstate->numsectors; numsectors = mapstate->numsectors;
numwalls = mapstate->numwalls; numwalls = mapstate->numwalls;
@ -9845,7 +9821,6 @@ void ExtPreCheckKeys(void) // just before drawrooms
if (qsetmode == 200) //In 3D mode if (qsetmode == 200) //In 3D mode
{ {
if (shadepreview) if (shadepreview)
{ {
int32_t i = 0; int32_t i = 0;
@ -10023,6 +9998,8 @@ void ExtPreCheckKeys(void) // just before drawrooms
xp1 += halfxdim16; xp1 += halfxdim16;
yp1 += midydim16; yp1 += midydim16;
ydim16 = ydim-STATUS2DSIZ2;
if (xp1 < 4 || xp1 > xdim-6 || yp1 < 4 || yp1 > ydim16-6) if (xp1 < 4 || xp1 > xdim-6 || yp1 < 4 || yp1 > ydim16-6)
continue; continue;
rotatesprite(xp1<<16,yp1<<16,zoom<<5,ang,picnum, rotatesprite(xp1<<16,yp1<<16,zoom<<5,ang,picnum,
@ -10315,13 +10292,13 @@ static void Keys2d3d(void)
keystatus[KEYSC_Z] = 0; keystatus[KEYSC_Z] = 0;
if (eitherSHIFT) if (eitherSHIFT)
{ {
if (map_redo()) message("Nothing to redo!"); if (map_undoredo(1)) message("Nothing to redo!");
else message("Restored undo rev %d",map_revision-1); else message("Restored revision %d",map_revision-1);
} }
else else
{ {
if (map_undo()) message("Nothing to undo!"); if (map_undoredo(0)) printmessage16("Nothing to undo!");
else message("Restored undo rev %d",map_revision-1); else message("Revision %d undone",map_revision);
} }
} }