More undo fixes

git-svn-id: https://svn.eduke32.com/eduke32@1447 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2009-06-28 23:47:38 +00:00
parent 5cdc55591b
commit ad3b34c49b

View file

@ -210,6 +210,8 @@ void create_map_snapshot(void)
tempcrc = crc32once((uint8_t *)&sector[0],sizeof(sectortype) * numsectors); tempcrc = crc32once((uint8_t *)&sector[0],sizeof(sectortype) * numsectors);
if (numsectors)
{
if (mapstate->prev && mapstate->prev->sectcrc == tempcrc) if (mapstate->prev && mapstate->prev->sectcrc == tempcrc)
{ {
mapstate->sectors = mapstate->prev->sectors; mapstate->sectors = mapstate->prev->sectors;
@ -226,6 +228,8 @@ void create_map_snapshot(void)
mapstate->sectcrc = tempcrc; mapstate->sectcrc = tempcrc;
} }
if (numwalls)
{
tempcrc = crc32once((uint8_t *)&wall[0],sizeof(walltype) * numwalls); tempcrc = crc32once((uint8_t *)&wall[0],sizeof(walltype) * numwalls);
@ -244,7 +248,10 @@ void create_map_snapshot(void)
mapstate->walls = (walltype *)Brealloc(mapstate->walls, j); mapstate->walls = (walltype *)Brealloc(mapstate->walls, j);
mapstate->wallcrc = tempcrc; mapstate->wallcrc = tempcrc;
} }
}
if (numsprites)
{
tempcrc = crc32once((uint8_t *)&sprite[0],sizeof(spritetype) * MAXSPRITES); tempcrc = crc32once((uint8_t *)&sprite[0],sizeof(spritetype) * MAXSPRITES);
if (mapstate->prev && mapstate->prev->spritecrc == tempcrc) if (mapstate->prev && mapstate->prev->spritecrc == tempcrc)
@ -277,38 +284,35 @@ void create_map_snapshot(void)
Bfree(tspri); Bfree(tspri);
} }
} }
}
}
void map_undoredo_free(void) void map_undoredo_free(void)
{ {
if (mapstate) if (mapstate)
{ {
if (mapstate->next != NULL) while (mapstate->next)
{ mapstate = mapstate->next;
mapundo_t *next = mapstate->next;
while (next->next) while (mapstate->prev)
next = next->next;
while (next->prev)
{ {
next = next->prev; mapundo_t *state = mapstate->prev;
if (next->next->sectors && (next->next->sectors != next->sectors)) Bfree(next->next->sectors); if (mapstate->sectors && (mapstate->sectcrc != mapstate->prev->sectcrc)) Bfree(mapstate->sectors);
if (next->next->walls && (next->next->walls != next->walls)) Bfree(next->next->walls); if (mapstate->walls && (mapstate->wallcrc != mapstate->prev->wallcrc)) Bfree(mapstate->walls);
if (next->next->sprites && (next->next->sprites != next->sprites)) Bfree(next->next->sprites); if (mapstate->sprites && (mapstate->spritecrc != mapstate->prev->spritecrc)) Bfree(mapstate->sprites);
if (next->next == mapstate) Bfree(mapstate);
mapstate = NULL; mapstate = state;
Bfree(next->next);
next->next = NULL;
}
} }
if (mapstate) if (mapstate->sectors) Bfree(mapstate->sectors);
if (mapstate->walls) Bfree(mapstate->walls);
if (mapstate->sprites) Bfree(mapstate->sprites);
Bfree(mapstate); Bfree(mapstate);
mapstate = NULL; mapstate = NULL;
} }
map_revision = 1; map_revision = 1;
} }
int32_t map_undoredo(int32_t dir) int32_t map_undoredo(int32_t dir)
@ -343,9 +347,16 @@ int32_t map_undoredo(int32_t dir)
clearbuf(&show2dsprite[0],(int32_t)((MAXSPRITES+3)>>5),0L); clearbuf(&show2dsprite[0],(int32_t)((MAXSPRITES+3)>>5),0L);
clearbuf(&show2dwall[0],(int32_t)((MAXWALLS+3)>>5),0L); clearbuf(&show2dwall[0],(int32_t)((MAXWALLS+3)>>5),0L);
if (mapstate->numsectors)
{
lzf_decompress(&mapstate->sectors[0], mapstate->sectsiz, &sector[0], sizeof(sectortype) * numsectors); lzf_decompress(&mapstate->sectors[0], mapstate->sectsiz, &sector[0], sizeof(sectortype) * numsectors);
if (mapstate->numwalls)
lzf_decompress(&mapstate->walls[0], mapstate->wallsiz, &wall[0], sizeof(walltype) * numwalls); lzf_decompress(&mapstate->walls[0], mapstate->wallsiz, &wall[0], sizeof(walltype) * numwalls);
if (mapstate->numsprites)
lzf_decompress(&mapstate->sprites[0], mapstate->spritesiz, &sprite[0], sizeof(spritetype) * numsprites); lzf_decompress(&mapstate->sprites[0], mapstate->spritesiz, &sprite[0], sizeof(spritetype) * numsprites);
}
updatenumsprites(); updatenumsprites();