From 191a6ca76fc825f0e7479f6ee2e6d175d2498a5d Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 12:42:29 +0200 Subject: [PATCH] unglobalize savebuffer needs some cleanup --- src/d_clisrv.c | 83 +- src/d_netcmd.c | 23 +- src/g_game.c | 157 ++-- src/lua_script.c | 613 +++---------- src/lua_script.h | 8 +- src/p_saveg.c | 2275 ++++++++++++++++++++++++---------------------- src/p_saveg.h | 24 +- src/p_setup.c | 24 +- 8 files changed, 1492 insertions(+), 1715 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index a5899796a..474d3f19a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1793,28 +1793,28 @@ static boolean SV_SendServerConfig(INT32 node) static void SV_SendSaveGame(INT32 node, boolean resending) { size_t length, compressedlen; - UINT8 *savebuffer; + savebuffer_t save; UINT8 *compressedsave; UINT8 *buffertosend; // first save it in a malloced buffer - savebuffer = (UINT8 *)malloc(SAVEGAMESIZE); - if (!savebuffer) + save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); + if (!save.buffer) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); return; } // Leave room for the uncompressed length. - save_p = savebuffer + sizeof(UINT32); + save.p = save.buffer + sizeof(UINT32); - P_SaveNetGame(resending); + P_SaveNetGame(&save, resending); - length = save_p - savebuffer; + length = save.p - save.buffer; if (length > SAVEGAMESIZE) { - free(savebuffer); - save_p = NULL; + free(save.buffer); + save.p = NULL; I_Error("Savegame buffer overrun"); } @@ -1828,11 +1828,11 @@ static void SV_SendSaveGame(INT32 node, boolean resending) } // Attempt to compress it. - if((compressedlen = lzf_compress(savebuffer + sizeof(UINT32), length - sizeof(UINT32), compressedsave + sizeof(UINT32), length - sizeof(UINT32) - 1))) + if ((compressedlen = lzf_compress(save.buffer + sizeof(UINT32), length - sizeof(UINT32), compressedsave + sizeof(UINT32), length - sizeof(UINT32) - 1))) { // Compressing succeeded; send compressed data - free(savebuffer); + free(save.buffer); // State that we're compressed. buffertosend = compressedsave; @@ -1846,12 +1846,12 @@ static void SV_SendSaveGame(INT32 node, boolean resending) free(compressedsave); // State that we're not compressed - buffertosend = savebuffer; - WRITEUINT32(savebuffer, 0); + buffertosend = save.buffer; + WRITEUINT32(save.buffer, 0); } SV_SendRam(node, buffertosend, length, SF_RAM, 0); - save_p = NULL; + save.p = NULL; // Remember when we started sending the savegame so we can handle timeouts sendingsavegame[node] = true; @@ -1865,7 +1865,7 @@ static consvar_t cv_dumpconsistency = {"dumpconsistency", "Off", CV_NETVAR, CV_O static void SV_SavedGame(void) { size_t length; - UINT8 *savebuffer; + savebuffer_t save; char tmpsave[264]; if (!cv_dumpconsistency.value) @@ -1874,29 +1874,31 @@ static void SV_SavedGame(void) sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); // first save it in a malloced buffer - save_p = savebuffer = (UINT8 *)malloc(SAVEGAMESIZE); - if (!save_p) + save.p = save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); + if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); + free(save.buffer); + save.p = NULL; return; } - P_SaveNetGame(false); + P_SaveNetGame(&save); - length = save_p - savebuffer; + length = save.p - save.buffer; if (length > SAVEGAMESIZE) { - free(savebuffer); - save_p = NULL; + free(save.buffer); + save.p = NULL; I_Error("Savegame buffer overrun"); } // then save it! - if (!FIL_WriteFile(tmpsave, savebuffer, length)) + if (!FIL_WriteFile(tmpsave, save.buffer, length)) CONS_Printf(M_GetText("Didn't save %s for netgame"), tmpsave); - free(savebuffer); - save_p = NULL; + free(save.buffer); + save.p = NULL; } #undef TMPSAVENAME @@ -1905,13 +1907,13 @@ static void SV_SavedGame(void) static void CL_LoadReceivedSavegame(boolean reloading) { - UINT8 *savebuffer = NULL; + savebuffer_t save; size_t length, decompressedlen; char tmpsave[264]; sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); - length = FIL_ReadFile(tmpsave, &savebuffer); + length = FIL_ReadFile(tmpsave, &save.buffer); CONS_Printf(M_GetText("Loading savegame length %s\n"), sizeu1(length)); if (!length) @@ -1920,16 +1922,17 @@ static void CL_LoadReceivedSavegame(boolean reloading) return; } - save_p = savebuffer; + save.p = save.buffer; // Decompress saved game if necessary. - decompressedlen = READUINT32(save_p); - if(decompressedlen > 0) + decompressedlen = READUINT32(save.p); + + if (decompressedlen > 0) { UINT8 *decompressedbuffer = Z_Malloc(decompressedlen, PU_STATIC, NULL); - lzf_decompress(save_p, length - sizeof(UINT32), decompressedbuffer, decompressedlen); - Z_Free(savebuffer); - save_p = savebuffer = decompressedbuffer; + lzf_decompress(save.p, length - sizeof(UINT32), decompressedbuffer, decompressedlen); + Z_Free(save.buffer); + save.p = save.buffer = decompressedbuffer; } paused = false; @@ -1938,7 +1941,7 @@ static void CL_LoadReceivedSavegame(boolean reloading) automapactive = false; // load a base level - if (P_LoadNetGame(reloading)) + if (P_LoadNetGame(&save, reloading)) { if (!reloading) { @@ -1958,8 +1961,8 @@ static void CL_LoadReceivedSavegame(boolean reloading) } // done - Z_Free(savebuffer); - save_p = NULL; + Z_Free(save.buffer); + save.p = NULL; if (unlink(tmpsave) == -1) CONS_Alert(CONS_ERROR, M_GetText("Can't delete %s\n"), tmpsave); consistancy[gametic%TICQUEUE] = Consistancy(); @@ -6842,6 +6845,7 @@ void CL_ClearRewinds(void) rewind_t *CL_SaveRewindPoint(size_t demopos) { + savebuffer_t save; rewind_t *rewind; if (rewindhead && rewindhead->leveltime + REWIND_POINT_INTERVAL > leveltime) @@ -6851,8 +6855,9 @@ rewind_t *CL_SaveRewindPoint(size_t demopos) if (!rewind) return NULL; - save_p = rewind->savebuffer; - P_SaveNetGame(false); + save.buffer = save.p = rewind->savebuffer; + + P_SaveNetGame(&save, false); rewind->leveltime = leveltime; rewind->next = rewindhead; rewind->demopos = demopos; @@ -6863,6 +6868,7 @@ rewind_t *CL_SaveRewindPoint(size_t demopos) rewind_t *CL_RewindToTime(tic_t time) { + savebuffer_t save; rewind_t *rewind; while (rewindhead && rewindhead->leveltime > time) @@ -6875,8 +6881,9 @@ rewind_t *CL_RewindToTime(tic_t time) if (!rewindhead) return NULL; - save_p = rewindhead->savebuffer; - P_LoadNetGame(false); + save.buffer = save.p = rewindhead->savebuffer; + + P_LoadNetGame(&save, false); wipegamestate = gamestate; // No fading back in! timeinmap = leveltime; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3cd815dee..d85280f08 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5819,10 +5819,9 @@ static void Command_Togglemodified_f(void) modifiedgame = !modifiedgame; } -extern UINT8 *save_p; static void Command_Archivetest_f(void) { - UINT8 *buf; + savebuffer_t save; UINT32 i, wrote; thinker_t *th; if (gamestate != GS_LEVEL) @@ -5838,28 +5837,28 @@ static void Command_Archivetest_f(void) ((mobj_t *)th)->mobjnum = i++; // allocate buffer - buf = save_p = ZZ_Alloc(1024); + save.buffer = save.p = ZZ_Alloc(1024); // test archive CONS_Printf("LUA_Archive...\n"); - LUA_Archive(); - WRITEUINT8(save_p, 0x7F); - wrote = (UINT32)(save_p-buf); + LUA_Archive(&save.p, true); + WRITEUINT8(save.p, 0x7F); + wrote = (UINT32)(save.p - save.buffer); // clear Lua state, so we can really see what happens! CONS_Printf("Clearing state!\n"); LUA_ClearExtVars(); // test unarchive - save_p = buf; + save.p = save.buffer; CONS_Printf("LUA_UnArchive...\n"); - LUA_UnArchive(); - i = READUINT8(save_p); - if (i != 0x7F || wrote != (UINT32)(save_p-buf)) - CONS_Printf("Savegame corrupted. (write %u, read %u)\n", wrote, (UINT32)(save_p-buf)); + LUA_UnArchive(&save.p, true); + i = READUINT8(save.p); + if (i != 0x7F || wrote != (UINT32)(save.p - save.buffer)) + CONS_Printf("Savegame corrupted. (write %u, read %u)\n", wrote, (UINT32)(save.p - save.buffer)); // free buffer - Z_Free(buf); + Z_Free(save.buffer); CONS_Printf("Done. No crash.\n"); } #endif diff --git a/src/g_game.c b/src/g_game.c index 27758119b..5f5cce736 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -354,8 +354,6 @@ consvar_t cv_maxdemosize = {"maxdemosize", "10", CV_SAVE, maxdemosize_cons_t, NU static CV_PossibleValue_t demochangemap_cons_t[] = {{0, "Disabled"}, {1, "Diff Map"}, {2, "Always"}, {0, NULL}}; consvar_t cv_demochangemap = {"netdemo_savemapchange", "Disabled", CV_SAVE, demochangemap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -static UINT8 *savebuffer; - // Analog Control static void UserAnalog_OnChange(void); static void UserAnalog2_OnChange(void); @@ -3918,6 +3916,7 @@ void G_LoadGameData(void) INT32 i, j; UINT8 modded = false; UINT8 rtemp; + savebuffer_t save; //For records tic_t rectime; @@ -3939,28 +3938,28 @@ void G_LoadGameData(void) if (M_CheckParm("-resetdata")) return; // Don't load (essentially, reset). - length = FIL_ReadFile(va(pandf, srb2home, gamedatafilename), &savebuffer); + length = FIL_ReadFile(va(pandf, srb2home, gamedatafilename), &save.buffer); if (!length) // Aw, no game data. Their loss! return; - save_p = savebuffer; + save.p = save.buffer; // Version check - if (READUINT32(save_p) != 0xFCAFE211) + if (READUINT32(save.p) != 0xFCAFE211) { const char *gdfolder = "the SRB2Kart folder"; if (strcmp(srb2home,".")) gdfolder = srb2home; - Z_Free(savebuffer); - save_p = NULL; + Z_Free(save.buffer); + save.p = NULL; I_Error("Game data is from another version of SRB2.\nDelete %s(maybe in %s) and try again.", gamedatafilename, gdfolder); } - totalplaytime = READUINT32(save_p); - matchesplayed = READUINT32(save_p); + totalplaytime = READUINT32(save.p); + matchesplayed = READUINT32(save.p); - modded = READUINT8(save_p); + modded = READUINT8(save.p); // Aha! Someone's been screwing with the save file! if ((modded && !savemoddata)) @@ -3970,48 +3969,47 @@ void G_LoadGameData(void) // TODO put another cipher on these things? meh, I don't care... for (i = 0; i < NUMMAPS; i++) - if ((mapvisited[i] = READUINT8(save_p)) > MV_MAX) + if ((mapvisited[i] = READUINT8(save.p)) > MV_MAX) goto datacorrupt; // To save space, use one bit per collected/achieved/unlocked flag for (i = 0; i < MAXEMBLEMS;) { - rtemp = READUINT8(save_p); + rtemp = READUINT8(save.p); for (j = 0; j < 8 && j+i < MAXEMBLEMS; ++j) emblemlocations[j+i].collected = ((rtemp >> j) & 1); i += j; } for (i = 0; i < MAXEXTRAEMBLEMS;) { - rtemp = READUINT8(save_p); + rtemp = READUINT8(save.p); for (j = 0; j < 8 && j+i < MAXEXTRAEMBLEMS; ++j) extraemblems[j+i].collected = ((rtemp >> j) & 1); i += j; } for (i = 0; i < MAXUNLOCKABLES;) { - rtemp = READUINT8(save_p); + rtemp = READUINT8(save.p); for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j) unlockables[j+i].unlocked = ((rtemp >> j) & 1); i += j; } for (i = 0; i < MAXCONDITIONSETS;) { - rtemp = READUINT8(save_p); + rtemp = READUINT8(save.p); for (j = 0; j < 8 && j+i < MAXCONDITIONSETS; ++j) conditionSets[j+i].achieved = ((rtemp >> j) & 1); i += j; } - timesBeaten = READUINT32(save_p); - timesBeatenWithEmeralds = READUINT32(save_p); - //timesBeatenUltimate = READUINT32(save_p); + timesBeaten = READUINT32(save.p); + timesBeatenWithEmeralds = READUINT32(save.p); // Main records for (i = 0; i < NUMMAPS; ++i) { - rectime = (tic_t)READUINT32(save_p); - reclap = (tic_t)READUINT32(save_p); + rectime = (tic_t)READUINT32(save.p); + reclap = (tic_t)READUINT32(save.p); if (rectime || reclap) { @@ -4022,8 +4020,8 @@ void G_LoadGameData(void) } // done - Z_Free(savebuffer); - save_p = NULL; + Z_Free(save.buffer); + save.p = NULL; // Silent update unlockables in case they're out of sync with conditions M_SilentUpdateUnlockablesAndEmblems(); @@ -4037,8 +4035,8 @@ void G_LoadGameData(void) if (strcmp(srb2home,".")) gdfolder = srb2home; - Z_Free(savebuffer); - save_p = NULL; + Z_Free(save.buffer); + save.p = NULL; I_Error("Corrupt game data file.\nDelete %s(maybe in %s) and try again.", gamedatafilename, gdfolder); } @@ -4051,14 +4049,13 @@ void G_SaveGameData(boolean force) size_t length; INT32 i, j; UINT8 btemp; - - //INT32 curmare; + savebuffer_t save; if (!gamedataloaded) return; // If never loaded (-nodata), don't save - save_p = savebuffer = (UINT8 *)malloc(GAMEDATASIZE); - if (!save_p) + save.p = save.buffer = (UINT8 *)malloc(GAMEDATASIZE); + if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); return; @@ -4066,23 +4063,23 @@ void G_SaveGameData(boolean force) if (majormods && !force) { - free(savebuffer); - save_p = savebuffer = NULL; + free(save.buffer); + save.p = save.buffer = NULL; return; } // Version test - WRITEUINT32(save_p, 0xFCAFE211); + WRITEUINT32(save.p, 0xFCAFE211); - WRITEUINT32(save_p, totalplaytime); - WRITEUINT32(save_p, matchesplayed); + WRITEUINT32(save.p, totalplaytime); + WRITEUINT32(save.p, matchesplayed); btemp = (UINT8)(savemoddata); // what used to be here was profoundly dunderheaded - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); // TODO put another cipher on these things? meh, I don't care... for (i = 0; i < NUMMAPS; i++) - WRITEUINT8(save_p, mapvisited[i]); + WRITEUINT8(save.p, mapvisited[i]); // To save space, use one bit per collected/achieved/unlocked flag for (i = 0; i < MAXEMBLEMS;) @@ -4090,7 +4087,7 @@ void G_SaveGameData(boolean force) btemp = 0; for (j = 0; j < 8 && j+i < MAXEMBLEMS; ++j) btemp |= (emblemlocations[j+i].collected << j); - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); i += j; } for (i = 0; i < MAXEXTRAEMBLEMS;) @@ -4098,7 +4095,7 @@ void G_SaveGameData(boolean force) btemp = 0; for (j = 0; j < 8 && j+i < MAXEXTRAEMBLEMS; ++j) btemp |= (extraemblems[j+i].collected << j); - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); i += j; } for (i = 0; i < MAXUNLOCKABLES;) @@ -4106,7 +4103,7 @@ void G_SaveGameData(boolean force) btemp = 0; for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j) btemp |= (unlockables[j+i].unlocked << j); - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); i += j; } for (i = 0; i < MAXCONDITIONSETS;) @@ -4114,33 +4111,33 @@ void G_SaveGameData(boolean force) btemp = 0; for (j = 0; j < 8 && j+i < MAXCONDITIONSETS; ++j) btemp |= (conditionSets[j+i].achieved << j); - WRITEUINT8(save_p, btemp); + WRITEUINT8(save.p, btemp); i += j; } - WRITEUINT32(save_p, timesBeaten); - WRITEUINT32(save_p, timesBeatenWithEmeralds); + WRITEUINT32(save.p, timesBeaten); + WRITEUINT32(save.p, timesBeatenWithEmeralds); // Main records for (i = 0; i < NUMMAPS; i++) { if (mainrecords[i]) { - WRITEUINT32(save_p, mainrecords[i]->time); - WRITEUINT32(save_p, mainrecords[i]->lap); + WRITEUINT32(save.p, mainrecords[i]->time); + WRITEUINT32(save.p, mainrecords[i]->lap); } else { - WRITEUINT32(save_p, 0); - WRITEUINT32(save_p, 0); + WRITEUINT32(save.p, 0); + WRITEUINT32(save.p, 0); } } - length = save_p - savebuffer; + length = save.p - save.buffer; - FIL_WriteFile(va(pandf, srb2home, gamedatafilename), savebuffer, length); - free(savebuffer); - save_p = savebuffer = NULL; + FIL_WriteFile(va(pandf, srb2home, gamedatafilename), save.buffer, length); + free(save.buffer); + save.p = save.buffer = NULL; } #define VERSIONSIZE 16 @@ -4156,22 +4153,23 @@ static void M_ForceLoadGameResponse(INT32 ch) if (ch != 'y' && ch != KEY_ENTER) { //refused - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; startonmapnum = 0; M_SetupNextMenu(&SP_LoadDef); return; } // pick up where we left off. - save_p += VERSIONSIZE; + save.p += VERSIONSIZE; + if (!P_LoadGame(startonmapnum)) { M_ClearMenus(true); // so ESC backs out to title M_StartMessage(M_GetText("Savegame file corrupted\n\nPress ESC\n"), NULL, MM_NOTHING); Command_ExitGame_f(); - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; startonmapnum = 0; // no cheating! @@ -4180,8 +4178,8 @@ static void M_ForceLoadGameResponse(INT32 ch) } // done - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; startonmapnum = 0; //set cursaveslot to -1 so nothing gets saved. @@ -4209,6 +4207,7 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) size_t length; char vcheck[VERSIONSIZE]; char savename[255]; + savebuffer_t save; // memset savedata to all 0, fixes calling perfectly valid saves corrupt because of bots memset(&savedata, 0, sizeof(savedata)); @@ -4220,18 +4219,18 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) sprintf(savename, savegamename, slot); - length = FIL_ReadFile(savename, &savebuffer); + length = FIL_ReadFile(savename, &save.buffer); if (!length) { CONS_Printf(M_GetText("Couldn't read file %s\n"), savename); return; } - save_p = savebuffer; + save.p = save.buffer; memset(vcheck, 0, sizeof (vcheck)); sprintf(vcheck, "version %d", VERSION); - if (strcmp((const char *)save_p, (const char *)vcheck)) + if (strcmp((const char *)save.p, (const char *)vcheck)) { #ifdef SAVEGAME_OTHERVERSIONS M_StartMessage(M_GetText("Save game from different version.\nYou can load this savegame, but\nsaving afterwards will be disabled.\n\nDo you want to continue anyway?\n\n(Press 'Y' to confirm)\n"), @@ -4241,15 +4240,15 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) M_ClearMenus(true); // so ESC backs out to title M_StartMessage(M_GetText("Save game from different version\n\nPress ESC\n"), NULL, MM_NOTHING); Command_ExitGame_f(); - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; // no cheating! memset(&savedata, 0, sizeof(savedata)); #endif return; // bad version } - save_p += VERSIONSIZE; + save.p += VERSIONSIZE; if (demo.playback) // reset game engine G_StopDemo(); @@ -4258,13 +4257,13 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) // automapactive = false; // dearchive all the modifications - if (!P_LoadGame(mapoverride)) + if (!P_LoadGame(&save, mapoverride)) { M_ClearMenus(true); // so ESC backs out to title M_StartMessage(M_GetText("Savegame file corrupted\n\nPress ESC\n"), NULL, MM_NOTHING); Command_ExitGame_f(); - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; // no cheating! memset(&savedata, 0, sizeof(savedata)); @@ -4272,17 +4271,14 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) } // done - Z_Free(savebuffer); - save_p = savebuffer = NULL; + Z_Free(save.buffer); + save.p = save.buffer = NULL; -// gameaction = ga_nothing; -// G_SetGamestate(GS_LEVEL); displayplayers[0] = consoleplayer; multiplayer = false; splitscreen = 0; SplitScreen_OnChange(); // not needed? -// G_DeferedInitNew(sk_medium, G_BuildMapName(1), 0, 0, 1); if (setsizeneeded) R_ExecuteSetViewSize(); @@ -4299,6 +4295,7 @@ void G_SaveGame(UINT32 savegameslot) boolean saved; char savename[256] = ""; const char *backup; + savebuffer_t save; sprintf(savename, savegamename, savegameslot); backup = va("%s",savename); @@ -4312,8 +4309,8 @@ void G_SaveGame(UINT32 savegameslot) char name[VERSIONSIZE]; size_t length; - save_p = savebuffer = (UINT8 *)malloc(SAVEGAMESIZE); - if (!save_p) + save.p = save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); + if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); return; @@ -4321,14 +4318,14 @@ void G_SaveGame(UINT32 savegameslot) memset(name, 0, sizeof (name)); sprintf(name, "version %d", VERSION); - WRITEMEM(save_p, name, VERSIONSIZE); + WRITEMEM(save.p, name, VERSIONSIZE); - P_SaveGame(); + P_SaveGame(&save); - length = save_p - savebuffer; - saved = FIL_WriteFile(backup, savebuffer, length); - free(savebuffer); - save_p = savebuffer = NULL; + length = save.p - save.buffer; + saved = FIL_WriteFile(backup, save.buffer, length); + free(save.buffer); + save.p = save.buffer = NULL; } gameaction = ga_nothing; @@ -6585,7 +6582,7 @@ void G_BeginRecording(void) // player lua vars, always saved even if empty... Unless it's record attack. if (demoflags & DF_LUAVARS) - LUA_ArchiveDemo(); + LUA_Archive(&demo_p, false); memset(&oldcmd,0,sizeof(oldcmd)); memset(&oldghost,0,sizeof(oldghost)); @@ -7689,7 +7686,7 @@ void G_DoPlayDemo(char *defdemoname) LUA_ClearState(); // No modeattacking check, DF_LUAVARS won't be present here. - LUA_UnArchiveDemo(); + LUA_UnArchiveDemo(&demo_p); } splitscreen = 0; diff --git a/src/lua_script.c b/src/lua_script.c index 9d5bef4a7..5e8b4315f 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -40,6 +40,8 @@ static lua_State *mL = NULL; int hook_defrosting; +static UINT8 **lua_save_p = NULL; // FIXME: Remove this horrible hack + // List of internal libraries to load from SRB2 static lua_CFunction liblist[] = { LUA_EnumLib, // global metatable for enums @@ -608,7 +610,7 @@ static UINT8 GetUserdataArchType(int index) return ARCH_NULL; } -static UINT8 ArchiveValue(int TABLESINDEX, int myindex) +static UINT8 ArchiveValue(UINT8 **p, int TABLESINDEX, int myindex) { if (myindex < 0) myindex = lua_gettop(gL)+1+myindex; @@ -616,23 +618,23 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { case LUA_TNONE: case LUA_TNIL: - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); break; // This might be a problem. D: case LUA_TLIGHTUSERDATA: case LUA_TTHREAD: case LUA_TFUNCTION: - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); return 2; case LUA_TBOOLEAN: - WRITEUINT8(save_p, ARCH_BOOLEAN); - WRITEUINT8(save_p, lua_toboolean(gL, myindex)); + WRITEUINT8(*p, ARCH_BOOLEAN); + WRITEUINT8(*p, lua_toboolean(gL, myindex)); break; case LUA_TNUMBER: { lua_Integer number = lua_tointeger(gL, myindex); - WRITEUINT8(save_p, ARCH_SIGNED); - WRITEFIXED(save_p, number); + WRITEUINT8(*p, ARCH_SIGNED); + WRITEFIXED(*p, number); break; } case LUA_TSTRING: @@ -640,7 +642,7 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) UINT16 len = (UINT16)lua_objlen(gL, myindex); // get length of string, including embedded zeros const char *s = lua_tostring(gL, myindex); UINT16 i = 0; - WRITEUINT8(save_p, ARCH_STRING); + WRITEUINT8(*p, ARCH_STRING); // if you're wondering why we're writing a string to save_p this way, // it turns out that Lua can have embedded zeros ('\0') in the strings, // so we can't use WRITESTRING as that cuts off when it finds a '\0'. @@ -648,9 +650,9 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) // fixing the awful crashes previously encountered for reading strings longer than 1024 // (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?) // -- Monster Iestyn 05/08/18 - WRITEUINT16(save_p, len); // save size of string + WRITEUINT16(*p, len); // save size of string while (i < len) - WRITECHAR(save_p, s[i++]); // write chars individually, including the embedded zeros + WRITECHAR(*p, s[i++]); // write chars individually, including the embedded zeros break; } case LUA_TTABLE: @@ -676,13 +678,13 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) if (t == 0) { CONS_Alert(CONS_ERROR, "Too many tables to archive!\n"); - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); return 0; } } - WRITEUINT8(save_p, ARCH_TABLE); - WRITEUINT16(save_p, t); + WRITEUINT8(*p, ARCH_TABLE); + WRITEUINT16(*p, t); if (!found) { @@ -698,25 +700,25 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) case ARCH_MOBJINFO: { mobjinfo_t *info = *((mobjinfo_t **)lua_touserdata(gL, myindex)); - WRITEUINT8(save_p, ARCH_MOBJINFO); - WRITEUINT16(save_p, info - mobjinfo); + WRITEUINT8(*p, ARCH_MOBJINFO); + WRITEUINT16(*p, info - mobjinfo); break; } case ARCH_STATE: { state_t *state = *((state_t **)lua_touserdata(gL, myindex)); - WRITEUINT8(save_p, ARCH_STATE); - WRITEUINT16(save_p, state - states); + WRITEUINT8(*p, ARCH_STATE); + WRITEUINT16(*p, state - states); break; } case ARCH_MOBJ: { mobj_t *mobj = *((mobj_t **)lua_touserdata(gL, myindex)); if (!mobj) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_MOBJ); - WRITEUINT32(save_p, mobj->mobjnum); + WRITEUINT8(*p, ARCH_MOBJ); + WRITEUINT32(*p, mobj->mobjnum); } break; } @@ -724,10 +726,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { player_t *player = *((player_t **)lua_touserdata(gL, myindex)); if (!player) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_PLAYER); - WRITEUINT8(save_p, player - players); + WRITEUINT8(*p, ARCH_PLAYER); + WRITEUINT8(*p, player - players); } break; } @@ -735,10 +737,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { mapthing_t *mapthing = *((mapthing_t **)lua_touserdata(gL, myindex)); if (!mapthing) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_MAPTHING); - WRITEUINT16(save_p, mapthing - mapthings); + WRITEUINT8(*p, ARCH_MAPTHING); + WRITEUINT16(*p, mapthing - mapthings); } break; } @@ -746,10 +748,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { vertex_t *vertex = *((vertex_t **)lua_touserdata(gL, myindex)); if (!vertex) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_VERTEX); - WRITEUINT16(save_p, vertex - vertexes); + WRITEUINT8(*p, ARCH_VERTEX); + WRITEUINT16(*p, vertex - vertexes); } break; } @@ -757,10 +759,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { line_t *line = *((line_t **)lua_touserdata(gL, myindex)); if (!line) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_LINE); - WRITEUINT16(save_p, line - lines); + WRITEUINT8(*p, ARCH_LINE); + WRITEUINT16(*p, line - lines); } break; } @@ -768,10 +770,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { side_t *side = *((side_t **)lua_touserdata(gL, myindex)); if (!side) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_SIDE); - WRITEUINT16(save_p, side - sides); + WRITEUINT8(*p, ARCH_SIDE); + WRITEUINT16(*p, side - sides); } break; } @@ -779,10 +781,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { subsector_t *subsector = *((subsector_t **)lua_touserdata(gL, myindex)); if (!subsector) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_SUBSECTOR); - WRITEUINT16(save_p, subsector - subsectors); + WRITEUINT8(*p, ARCH_SUBSECTOR); + WRITEUINT16(*p, subsector - subsectors); } break; } @@ -790,10 +792,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { sector_t *sector = *((sector_t **)lua_touserdata(gL, myindex)); if (!sector) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_SECTOR); - WRITEUINT16(save_p, sector - sectors); + WRITEUINT8(*p, ARCH_SECTOR); + WRITEUINT16(*p, sector - sectors); } break; } @@ -801,10 +803,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { pslope_t *slope = *((pslope_t **)lua_touserdata(gL, myindex)); if (!slope) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_SLOPE); - WRITEUINT16(save_p, slope->id); + WRITEUINT8(*p, ARCH_SLOPE); + WRITEUINT16(*p, slope->id); } break; } @@ -812,15 +814,15 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) { mapheader_t *header = *((mapheader_t **)lua_touserdata(gL, myindex)); if (!header) - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); else { - WRITEUINT8(save_p, ARCH_MAPHEADER); - WRITEUINT16(save_p, header - *mapheaderinfo); + WRITEUINT8(*p, ARCH_MAPHEADER); + WRITEUINT16(*p, header - *mapheaderinfo); } break; } default: - WRITEUINT8(save_p, ARCH_NULL); + WRITEUINT8(*p, ARCH_NULL); return 2; } break; @@ -828,226 +830,14 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) return 0; } -// because of how this function works it has to be pasted allll over again just to save to demo_p since it returns an uint8 to begin with -static UINT8 ArchiveValueDemo(int TABLESINDEX, int myindex) -{ - if (myindex < 0) - myindex = lua_gettop(gL)+1+myindex; - switch (lua_type(gL, myindex)) - { - case LUA_TNONE: - case LUA_TNIL: - WRITEUINT8(demo_p, ARCH_NULL); - break; - // This might be a problem. D: - case LUA_TLIGHTUSERDATA: - case LUA_TTHREAD: - case LUA_TFUNCTION: - WRITEUINT8(demo_p, ARCH_NULL); - return 2; - case LUA_TBOOLEAN: - WRITEUINT8(demo_p, ARCH_BOOLEAN); - WRITEUINT8(demo_p, lua_toboolean(gL, myindex)); - break; - case LUA_TNUMBER: - { - lua_Integer number = lua_tointeger(gL, myindex); - WRITEUINT8(demo_p, ARCH_SIGNED); - WRITEFIXED(demo_p, number); - break; - } - case LUA_TSTRING: - { - UINT16 len = (UINT16)lua_objlen(gL, myindex); // get length of string, including embedded zeros - const char *s = lua_tostring(gL, myindex); - UINT16 i = 0; - WRITEUINT8(demo_p, ARCH_STRING); - // if you're wondering why we're writing a string to demo_p this way, - // it turns out that Lua can have embedded zeros ('\0') in the strings, - // so we can't use WRITESTRING as that cuts off when it finds a '\0'. - // Saving the size of the string also allows us to get the size of the string on the other end, - // fixing the awful crashes previously encountered for reading strings longer than 1024 - // (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?) - // -- Monster Iestyn 05/08/18 - WRITEUINT16(demo_p, len); // save size of string - while (i < len) - WRITECHAR(demo_p, s[i++]); // write chars individually, including the embedded zeros - break; - } - case LUA_TTABLE: - { - boolean found = false; - INT32 i; - UINT16 t = (UINT16)lua_objlen(gL, TABLESINDEX); - - for (i = 1; i <= t && !found; i++) - { - lua_rawgeti(gL, TABLESINDEX, i); - if (lua_rawequal(gL, myindex, -1)) - { - t = i; - found = true; - } - lua_pop(gL, 1); - } - if (!found) - t++; - - WRITEUINT8(demo_p, ARCH_TABLE); - WRITEUINT16(demo_p, t); - - if (!found) - { - lua_pushvalue(gL, myindex); - lua_rawseti(gL, TABLESINDEX, t); - return 1; - } - break; - } - case LUA_TUSERDATA: - switch (GetUserdataArchType(myindex)) - { - case ARCH_MOBJINFO: - { - mobjinfo_t *info = *((mobjinfo_t **)lua_touserdata(gL, myindex)); - WRITEUINT8(demo_p, ARCH_MOBJINFO); - WRITEUINT16(demo_p, info - mobjinfo); - break; - } - case ARCH_STATE: - { - state_t *state = *((state_t **)lua_touserdata(gL, myindex)); - WRITEUINT8(demo_p, ARCH_STATE); - WRITEUINT16(demo_p, state - states); - break; - } - case ARCH_MOBJ: - { - mobj_t *mobj = *((mobj_t **)lua_touserdata(gL, myindex)); - if (!mobj) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_MOBJ); - WRITEUINT32(demo_p, mobj->mobjnum); - } - break; - } - case ARCH_PLAYER: - { - player_t *player = *((player_t **)lua_touserdata(gL, myindex)); - if (!player) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_PLAYER); - WRITEUINT8(demo_p, player - players); - } - break; - } - case ARCH_MAPTHING: - { - mapthing_t *mapthing = *((mapthing_t **)lua_touserdata(gL, myindex)); - if (!mapthing) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_MAPTHING); - WRITEUINT16(demo_p, mapthing - mapthings); - } - break; - } - case ARCH_VERTEX: - { - vertex_t *vertex = *((vertex_t **)lua_touserdata(gL, myindex)); - if (!vertex) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_VERTEX); - WRITEUINT16(demo_p, vertex - vertexes); - } - break; - } - case ARCH_LINE: - { - line_t *line = *((line_t **)lua_touserdata(gL, myindex)); - if (!line) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_LINE); - WRITEUINT16(demo_p, line - lines); - } - break; - } - case ARCH_SIDE: - { - side_t *side = *((side_t **)lua_touserdata(gL, myindex)); - if (!side) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_SIDE); - WRITEUINT16(demo_p, side - sides); - } - break; - } - case ARCH_SUBSECTOR: - { - subsector_t *subsector = *((subsector_t **)lua_touserdata(gL, myindex)); - if (!subsector) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_SUBSECTOR); - WRITEUINT16(demo_p, subsector - subsectors); - } - break; - } - case ARCH_SECTOR: - { - sector_t *sector = *((sector_t **)lua_touserdata(gL, myindex)); - if (!sector) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_SECTOR); - WRITEUINT16(demo_p, sector - sectors); - } - break; - } - case ARCH_SLOPE: - { - pslope_t *slope = *((pslope_t **)lua_touserdata(gL, myindex)); - if (!slope) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_SLOPE); - WRITEUINT16(demo_p, slope->id); - } - break; - } - case ARCH_MAPHEADER: - { - mapheader_t *header = *((mapheader_t **)lua_touserdata(gL, myindex)); - if (!header) - WRITEUINT8(demo_p, ARCH_NULL); - else { - WRITEUINT8(demo_p, ARCH_MAPHEADER); - WRITEUINT16(demo_p, header - *mapheaderinfo); - } - break; - } - default: - WRITEUINT8(demo_p, ARCH_NULL); - return 2; - } - break; - } - return 0; -} - -static void ArchiveExtVars(void *pointer, const char *ptype) +static void ArchiveExtVars(UINT8 **p, void *pointer, const char *ptype) { int TABLESINDEX; UINT16 i; if (!gL) { if (fastcmp(ptype,"player")) // players must always be included, even if no vars - WRITEUINT16(save_p, 0); + WRITEUINT16(*p, 0); return; } @@ -1063,7 +853,7 @@ static void ArchiveExtVars(void *pointer, const char *ptype) { // no extra values table lua_pop(gL, 1); if (fastcmp(ptype,"player")) // players must always be included, even if no vars - WRITEUINT16(save_p, 0); + WRITEUINT16(*p, 0); return; } @@ -1075,77 +865,20 @@ static void ArchiveExtVars(void *pointer, const char *ptype) if (i == 0) { if (fastcmp(ptype,"player")) // always include players even if they have no extra variables - WRITEUINT16(save_p, 0); + WRITEUINT16(*p, 0); lua_pop(gL, 1); return; } if (fastcmp(ptype,"mobj")) // mobjs must write their mobjnum as a header - WRITEUINT32(save_p, ((mobj_t *)pointer)->mobjnum); - WRITEUINT16(save_p, i); + WRITEUINT32(*p, ((mobj_t *)pointer)->mobjnum); + WRITEUINT16(*p, i); lua_pushnil(gL); while (lua_next(gL, -2)) { I_Assert(lua_type(gL, -2) == LUA_TSTRING); - WRITESTRING(save_p, lua_tostring(gL, -2)); - if (ArchiveValue(TABLESINDEX, -1) == 2) - CONS_Alert(CONS_ERROR, "Type of value for %s entry '%s' (%s) could not be archived!\n", ptype, lua_tostring(gL, -2), luaL_typename(gL, -1)); - lua_pop(gL, 1); - } - - lua_pop(gL, 1); -} - -// simplified for demos -static void ArchiveExtVarsDemo(void *pointer, const char *ptype) -{ - int TABLESINDEX; - UINT16 i; - - if (!gL) { - if (fastcmp(ptype,"player")) // players must always be included, even if no vars - WRITEUINT16(demo_p, 0); - return; - } - - TABLESINDEX = lua_gettop(gL); - - lua_getfield(gL, LUA_REGISTRYINDEX, LREG_EXTVARS); - I_Assert(lua_istable(gL, -1)); - lua_pushlightuserdata(gL, pointer); - lua_rawget(gL, -2); - lua_remove(gL, -2); // pop LREG_EXTVARS - - if (!lua_istable(gL, -1)) - { // no extra values table - lua_pop(gL, 1); - if (fastcmp(ptype,"player")) // players must always be included, even if no vars - WRITEUINT16(demo_p, 0); - return; - } - - lua_pushnil(gL); - for (i = 0; lua_next(gL, -2); i++) - lua_pop(gL, 1); - - // skip anything that has an empty table and isn't a player. - if (i == 0) - { - if (fastcmp(ptype,"player")) // always include players even if they have no extra variables - WRITEUINT16(demo_p, 0); - lua_pop(gL, 1); - return; - } - - if (fastcmp(ptype,"mobj")) // mobjs must write their mobjnum as a header - WRITEUINT32(demo_p, ((mobj_t *)pointer)->mobjnum); - WRITEUINT16(demo_p, i); - lua_pushnil(gL); - while (lua_next(gL, -2)) - { - I_Assert(lua_type(gL, -2) == LUA_TSTRING); - WRITESTRING(demo_p, lua_tostring(gL, -2)); - if (ArchiveValueDemo(TABLESINDEX, -1) == 2) + WRITESTRING(*p, lua_tostring(gL, -2)); + if (ArchiveValue(p, TABLESINDEX, -1) == 2) CONS_Alert(CONS_ERROR, "Type of value for %s entry '%s' (%s) could not be archived!\n", ptype, lua_tostring(gL, -2), luaL_typename(gL, -1)); lua_pop(gL, 1); } @@ -1158,11 +891,11 @@ static int NetArchive(lua_State *L) int TABLESINDEX = lua_upvalueindex(1); int i, n = lua_gettop(L); for (i = 1; i <= n; i++) - ArchiveValue(TABLESINDEX, i); + ArchiveValue(lua_save_p, TABLESINDEX, i); return n; } -static void ArchiveTables(void) +static void ArchiveTables(UINT8 **p) { int TABLESINDEX; UINT16 i, n; @@ -1181,7 +914,7 @@ static void ArchiveTables(void) while (lua_next(gL, -2)) { // Write key - e = ArchiveValue(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. + e = ArchiveValue(p, TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) { lua_pushvalue(gL, -2); @@ -1189,7 +922,7 @@ static void ArchiveTables(void) lua_pop(gL, 1); } // Write value - e = ArchiveValue(TABLESINDEX, -1); + e = ArchiveValue(p, TABLESINDEX, -1); if (e == 1) n++; // the table contained a new table we'll have to archive. :( else if (e == 2) // invalid value type @@ -1202,57 +935,13 @@ static void ArchiveTables(void) lua_pop(gL, 1); } lua_pop(gL, 1); - WRITEUINT8(save_p, ARCH_TEND); + WRITEUINT8(*p, ARCH_TEND); } } -static void ArchiveTablesDemo(void) +static UINT8 UnArchiveValue(UINT8 **p, int TABLESINDEX) { - int TABLESINDEX; - UINT16 i, n; - UINT8 e; - - if (!gL) - return; - - TABLESINDEX = lua_gettop(gL); - - n = (UINT16)lua_objlen(gL, TABLESINDEX); - for (i = 1; i <= n; i++) - { - lua_rawgeti(gL, TABLESINDEX, i); - lua_pushnil(gL); - while (lua_next(gL, -2)) - { - // Write key - e = ArchiveValueDemo(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. - if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) - { - lua_pushvalue(gL, -2); - CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -1), luaL_typename(gL, -1), i); - lua_pop(gL, 1); - } - // Write value - e = ArchiveValueDemo(TABLESINDEX, -1); - if (e == 1) - n++; // the table contained a new table we'll have to archive. :( - else if (e == 2) // invalid value type - { - lua_pushvalue(gL, -2); - CONS_Alert(CONS_ERROR, "Type of value for table %d entry '%s' (%s) could not be archived!\n", i, lua_tostring(gL, -1), luaL_typename(gL, -1)); - lua_pop(gL, 1); - } - - lua_pop(gL, 1); - } - lua_pop(gL, 1); - WRITEUINT8(demo_p, ARCH_TEND); - } -} - -static UINT8 UnArchiveValue(int TABLESINDEX) -{ - UINT8 type = READUINT8(save_p); + UINT8 type = READUINT8(*p); switch (type) { case ARCH_NULL: @@ -1262,11 +951,11 @@ static UINT8 UnArchiveValue(int TABLESINDEX) lua_pushboolean(gL, READUINT8(save_p)); break; case ARCH_SIGNED: - lua_pushinteger(gL, READFIXED(save_p)); + lua_pushinteger(gL, READFIXED(*p)); break; case ARCH_STRING: { - UINT16 len = READUINT16(save_p); // length of string, including embedded zeros + UINT16 len = READUINT16(*p); // length of string, including embedded zeros char *value; UINT16 i = 0; // See my comments in the ArchiveValue function; @@ -1276,14 +965,14 @@ static UINT8 UnArchiveValue(int TABLESINDEX) value = malloc(len); // make temp buffer of size len // now read the actual string while (i < len) - value[i++] = READCHAR(save_p); // read chars individually, including the embedded zeros + value[i++] = READCHAR(*p); // read chars individually, including the embedded zeros lua_pushlstring(gL, value, len); // push the string (note: this function supports embedded zeros) free(value); // free the buffer break; } case ARCH_TABLE: { - UINT16 tid = READUINT16(save_p); + UINT16 tid = READUINT16(*p); lua_rawgeti(gL, TABLESINDEX, tid); if (lua_isnil(gL, -1)) { @@ -1296,40 +985,40 @@ static UINT8 UnArchiveValue(int TABLESINDEX) break; } case ARCH_MOBJINFO: - LUA_PushUserdata(gL, &mobjinfo[READUINT16(save_p)], META_MOBJINFO); + LUA_PushUserdata(gL, &mobjinfo[READUINT16(*p)], META_MOBJINFO); break; case ARCH_STATE: - LUA_PushUserdata(gL, &states[READUINT16(save_p)], META_STATE); + LUA_PushUserdata(gL, &states[READUINT16(*p)], META_STATE); break; case ARCH_MOBJ: - LUA_PushUserdata(gL, P_FindNewPosition(READUINT32(save_p)), META_MOBJ); + LUA_PushUserdata(gL, P_FindNewPosition(READUINT32(*p)), META_MOBJ); break; case ARCH_PLAYER: - LUA_PushUserdata(gL, &players[READUINT8(save_p)], META_PLAYER); + LUA_PushUserdata(gL, &players[READUINT8(*p)], META_PLAYER); break; case ARCH_MAPTHING: - LUA_PushUserdata(gL, &mapthings[READUINT16(save_p)], META_MAPTHING); + LUA_PushUserdata(gL, &mapthings[READUINT16(*p)], META_MAPTHING); break; case ARCH_VERTEX: - LUA_PushUserdata(gL, &vertexes[READUINT16(save_p)], META_VERTEX); + LUA_PushUserdata(gL, &vertexes[READUINT16(*p)], META_VERTEX); break; case ARCH_LINE: - LUA_PushUserdata(gL, &lines[READUINT16(save_p)], META_LINE); + LUA_PushUserdata(gL, &lines[READUINT16(*p)], META_LINE); break; case ARCH_SIDE: - LUA_PushUserdata(gL, &sides[READUINT16(save_p)], META_SIDE); + LUA_PushUserdata(gL, &sides[READUINT16(*p)], META_SIDE); break; case ARCH_SUBSECTOR: - LUA_PushUserdata(gL, &subsectors[READUINT16(save_p)], META_SUBSECTOR); + LUA_PushUserdata(gL, &subsectors[READUINT16(*p)], META_SUBSECTOR); break; case ARCH_SECTOR: - LUA_PushUserdata(gL, §ors[READUINT16(save_p)], META_SECTOR); + LUA_PushUserdata(gL, §ors[READUINT16(*p)], META_SECTOR); break; case ARCH_SLOPE: - LUA_PushUserdata(gL, P_SlopeById(READUINT16(save_p)), META_SLOPE); + LUA_PushUserdata(gL, P_SlopeById(READUINT16(*p)), META_SLOPE); break; case ARCH_MAPHEADER: - LUA_PushUserdata(gL, mapheaderinfo[READUINT16(save_p)], META_MAPHEADER); + LUA_PushUserdata(gL, mapheaderinfo[READUINT16(*p)], META_MAPHEADER); break; case ARCH_TEND: return 1; @@ -1345,23 +1034,23 @@ static UINT8 UnArchiveValue(int TABLESINDEX) // 2: Read table value // 3: Don't use setfield -static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) +static UINT8 UnArchiveValueDemo(UINT8 **p, int TABLESINDEX, char field[1024]) { - UINT8 type = READUINT8(demo_p); + UINT8 type = READUINT8(*p); switch (type) { case ARCH_NULL: lua_pushnil(gL); break; case ARCH_BOOLEAN: - lua_pushboolean(gL, READUINT8(demo_p)); + lua_pushboolean(gL, READUINT8(*p)); break; case ARCH_SIGNED: - lua_pushinteger(gL, READFIXED(demo_p)); + lua_pushinteger(gL, READFIXED(*p)); break; case ARCH_STRING: { - UINT16 len = READUINT16(demo_p); // length of string, including embedded zeros + UINT16 len = READUINT16(*p); // length of string, including embedded zeros char *value; UINT16 i = 0; // See my comments in the ArchiveValue function; @@ -1371,14 +1060,14 @@ static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) value = malloc(len); // make temp buffer of size len // now read the actual string while (i < len) - value[i++] = READCHAR(demo_p); // read chars individually, including the embedded zeros + value[i++] = READCHAR(*p); // read chars individually, including the embedded zeros lua_pushlstring(gL, value, len); // push the string (note: this function supports embedded zeros) free(value); // free the buffer break; } case ARCH_TABLE: { - UINT16 tid = READUINT16(demo_p); + UINT16 tid = READUINT16(*p); lua_rawgeti(gL, TABLESINDEX, tid); if (lua_isnil(gL, -1)) { @@ -1391,13 +1080,13 @@ static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) break; } case ARCH_MOBJINFO: - LUA_PushUserdata(gL, &mobjinfo[READUINT16(demo_p)], META_MOBJINFO); + LUA_PushUserdata(gL, &mobjinfo[READUINT16(*p)], META_MOBJINFO); break; case ARCH_STATE: - LUA_PushUserdata(gL, &states[READUINT16(demo_p)], META_STATE); + LUA_PushUserdata(gL, &states[READUINT16(*p)], META_STATE); break; case ARCH_MOBJ: - demo_p += sizeof(UINT32); // Skip this data, we can't read a mobj here, it'd point to garbage and crash the game. + *p += sizeof(UINT32); // Skip this data, we can't read a mobj here, it'd point to garbage and crash the game. if (field) CONS_Alert(CONS_WARNING,"Cannot read mobj_t stored in player variable \'%s\'. Desyncs may occur.\n", field); else @@ -1406,31 +1095,31 @@ static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) return 3; // Don't set the field case ARCH_PLAYER: - LUA_PushUserdata(gL, &players[READUINT8(demo_p)], META_PLAYER); + LUA_PushUserdata(gL, &players[READUINT8(*p)], META_PLAYER); break; case ARCH_MAPTHING: - LUA_PushUserdata(gL, &mapthings[READUINT16(demo_p)], META_MAPTHING); + LUA_PushUserdata(gL, &mapthings[READUINT16(*p)], META_MAPTHING); break; case ARCH_VERTEX: - LUA_PushUserdata(gL, &vertexes[READUINT16(demo_p)], META_VERTEX); + LUA_PushUserdata(gL, &vertexes[READUINT16(*p)], META_VERTEX); break; case ARCH_LINE: - LUA_PushUserdata(gL, &lines[READUINT16(demo_p)], META_LINE); + LUA_PushUserdata(gL, &lines[READUINT16(*p)], META_LINE); break; case ARCH_SIDE: - LUA_PushUserdata(gL, &sides[READUINT16(demo_p)], META_SIDE); + LUA_PushUserdata(gL, &sides[READUINT16(*p)], META_SIDE); break; case ARCH_SUBSECTOR: - LUA_PushUserdata(gL, &subsectors[READUINT16(demo_p)], META_SUBSECTOR); + LUA_PushUserdata(gL, &subsectors[READUINT16(*p)], META_SUBSECTOR); break; case ARCH_SECTOR: - LUA_PushUserdata(gL, §ors[READUINT16(demo_p)], META_SECTOR); + LUA_PushUserdata(gL, §ors[READUINT16(*p)], META_SECTOR); break; case ARCH_SLOPE: - LUA_PushUserdata(gL, P_SlopeById(READUINT16(demo_p)), META_SLOPE); + LUA_PushUserdata(gL, P_SlopeById(READUINT16(*p)), META_SLOPE); break; case ARCH_MAPHEADER: - LUA_PushUserdata(gL, mapheaderinfo[READUINT16(demo_p)], META_MAPHEADER); + LUA_PushUserdata(gL, mapheaderinfo[READUINT16(*p)], META_MAPHEADER); break; case ARCH_TEND: return 1; @@ -1438,10 +1127,10 @@ static UINT8 UnArchiveValueDemo(int TABLESINDEX, char field[1024]) return 0; } -static void UnArchiveExtVars(void *pointer) +static void UnArchiveExtVars(UINT8 **p, void *pointer) { int TABLESINDEX; - UINT16 field_count = READUINT16(save_p); + UINT16 field_count = READUINT16(*p); UINT16 i; char field[1024]; @@ -1459,8 +1148,8 @@ static void UnArchiveExtVars(void *pointer) for (i = 0; i < field_count; i++) { - READSTRING(save_p, field); - UnArchiveValue(TABLESINDEX); + READSTRING(*p, field); + UnArchiveValue(p, TABLESINDEX); lua_setfield(gL, -2, field); } @@ -1472,10 +1161,10 @@ static void UnArchiveExtVars(void *pointer) lua_pop(gL, 2); // pop LREG_EXTVARS and pointer's subtable } -static void UnArchiveExtVarsDemo(void *pointer) +static void UnArchiveExtVarsDemo(UINT8 **p, void *pointer) { int TABLESINDEX; - UINT16 field_count = READUINT16(demo_p); + UINT16 field_count = READUINT16(*p); UINT16 i; char field[1024]; @@ -1488,8 +1177,8 @@ static void UnArchiveExtVarsDemo(void *pointer) for (i = 0; i < field_count; i++) { - READSTRING(demo_p, field); - if (UnArchiveValueDemo(TABLESINDEX, field) != 3) // This will return 3 if we shouldn't set this field. + READSTRING(*p, field); + if (UnArchiveValueDemo(p, TABLESINDEX, field) != 3) // This will return 3 if we shouldn't set this field. lua_setfield(gL, -2, field); } @@ -1506,11 +1195,11 @@ static int NetUnArchive(lua_State *L) int TABLESINDEX = lua_upvalueindex(1); int i, n = lua_gettop(L); for (i = 1; i <= n; i++) - UnArchiveValue(TABLESINDEX); + UnArchiveValue(lua_save_p, TABLESINDEX); return n; } -static void UnArchiveTables(void) +static void UnArchiveTables(UINT8 **p) { int TABLESINDEX; UINT16 i, n; @@ -1526,9 +1215,9 @@ static void UnArchiveTables(void) lua_rawgeti(gL, TABLESINDEX, i); while (true) { - if (UnArchiveValue(TABLESINDEX) == 1) // read key + if (UnArchiveValue(p, TABLESINDEX) == 1) // read key break; - if (UnArchiveValue(TABLESINDEX) == 2) // read value + if (UnArchiveValue(p, TABLESINDEX) == 2) // read value n++; if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) { @@ -1542,7 +1231,7 @@ static void UnArchiveTables(void) } } -static void UnArchiveTablesDemo(void) +static void UnArchiveTablesDemo(UINT8 **p) { int TABLESINDEX; UINT16 i, n; @@ -1560,13 +1249,13 @@ static void UnArchiveTablesDemo(void) { UINT8 ret; - ret = UnArchiveValueDemo(TABLESINDEX, NULL); + ret = UnArchiveValueDemo(p, TABLESINDEX, NULL); if (ret == 3) lua_pushnil(gL); else if (ret == 1) // read key break; - ret = UnArchiveValueDemo(TABLESINDEX, NULL); + ret = UnArchiveValueDemo(p, TABLESINDEX, NULL); if (ret == 3) lua_pushnil(gL); @@ -1593,7 +1282,7 @@ void LUA_Step(void) lua_gc(gL, LUA_GCSTEP, 1); } -void LUA_Archive(void) +void LUA_Archive(UINT8 **p, boolean network) { INT32 i; thinker_t *th; @@ -1606,31 +1295,36 @@ void LUA_Archive(void) if (!playeringame[i] && i > 0) // NEVER skip player 0, this is for dedi servs. continue; // all players in game will be archived, even if they just add a 0. - ArchiveExtVars(&players[i], "player"); + ArchiveExtVars(p, &players[i], "player"); } - if (gamestate == GS_LEVEL) + if (network == true) { - for (th = thinkercap.next; th != &thinkercap; th = th->next) + if (gamestate == GS_LEVEL) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; - // archive function will determine when to skip mobjs, - // and write mobjnum in otherwise. - ArchiveExtVars(th, "mobj"); + // archive function will determine when to skip mobjs, + // and write mobjnum in otherwise. + ArchiveExtVars(p, th, "mobj"); + } } - } - WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. + WRITEUINT32(*p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. - LUAh_NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode - ArchiveTables(); + lua_save_p = p; + LUAh_NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode + } + + ArchiveTables(p); if (gL) lua_pop(gL, 1); // pop tables } -void LUA_UnArchive(void) +void LUA_UnArchive(UINT8 **p) { UINT32 mobjnum; INT32 i; @@ -1643,52 +1337,33 @@ void LUA_UnArchive(void) { if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. continue; - UnArchiveExtVars(&players[i]); + UnArchiveExtVars(p, &players[i]); } do { - mobjnum = READUINT32(save_p); // read a mobjnum + mobjnum = READUINT32(*p); // read a mobjnum for (th = thinkercap.next; th != &thinkercap; th = th->next) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; + if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj continue; - UnArchiveExtVars(th); // apply variables + + UnArchiveExtVars(p, th); // apply variables } } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. + lua_save_p = p; LUAh_NetArchiveHook(NetUnArchive); // call the NetArchive hook in unarchive mode - UnArchiveTables(); - - if (gL) - lua_pop(gL, 1); // pop tables -} - -// simplified versions of LUA_Archive for demos -void LUA_ArchiveDemo(void) -{ - INT32 i; - - if (gL) - lua_newtable(gL); // tables to be archived. - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] && i > 0) // NEVER skip player 0, this is for dedi servs. - continue; - // all players in game will be archived, even if they just add a 0. - ArchiveExtVarsDemo(&players[i], "player"); - } - - ArchiveTablesDemo(); + UnArchiveTables(p); if (gL) lua_pop(gL, 1); // pop tables } // this time make sure we read from demo_p -void LUA_UnArchiveDemo(void) +void LUA_UnArchiveDemo(UINT8 **p) { INT32 i; @@ -1699,10 +1374,10 @@ void LUA_UnArchiveDemo(void) { if (!playeringame[i] && i > 0) // same here, this is to synch dediservs properly. continue; - UnArchiveExtVarsDemo(&players[i]); + UnArchiveExtVarsDemo(p, &players[i]); } - UnArchiveTablesDemo(); + UnArchiveTablesDemo(p); if (gL) lua_pop(gL, 1); // pop tables diff --git a/src/lua_script.h b/src/lua_script.h index 9903315c2..7039603a5 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -55,11 +55,11 @@ void LUA_InvalidateLevel(void); void LUA_InvalidateMapthings(void); void LUA_InvalidatePlayer(player_t *player); void LUA_Step(void); -void LUA_Archive(void); -void LUA_UnArchive(void); +void LUA_Archive(UINT8 **p, boolean network); +void LUA_UnArchive(UINT8 **p); -void LUA_ArchiveDemo(void); -void LUA_UnArchiveDemo(void); +// keeping this around since demos are kinda ass +void LUA_UnArchiveDemo(UINT8 **p); void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c void LUA_CVarChanged(const char *name); // lua_consolelib.c diff --git a/src/p_saveg.c b/src/p_saveg.c index b8a517f0e..695ecac76 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -34,7 +34,6 @@ #include "p_slopes.h" savedata_t savedata; -UINT8 *save_p; // Block UINT32s to attempt to ensure that the correct data is // being sent and received @@ -60,45 +59,45 @@ typedef enum // // P_ArchivePlayer // -static inline void P_ArchivePlayer(void) +static inline void P_ArchivePlayer(savebuffer_t *save) { const player_t *player = &players[consoleplayer]; INT32 pllives = player->lives; if (pllives < 3) // Bump up to 3 lives if the player pllives = 3; // has less than that. - WRITEUINT8(save_p, player->skincolor); - WRITEUINT8(save_p, player->skin); + WRITEUINT8(save->p, player->skincolor); + WRITEUINT16(save->p, player->skin); - WRITEUINT32(save_p, player->score); - WRITEINT32(save_p, pllives); - WRITEINT32(save_p, player->continues); + WRITEUINT32(save->p, player->score); + WRITEINT32(save->p, pllives); + WRITEINT32(save->p, player->continues); if (botskin) { - WRITEUINT8(save_p, botskin); - WRITEUINT8(save_p, botcolor); + WRITEUINT16(save->p, botskin); + WRITEUINT8(save->p, botcolor); } } // // P_UnArchivePlayer // -static inline void P_UnArchivePlayer(void) +static inline void P_UnArchivePlayer(savebuffer_t *save) { - savedata.skincolor = READUINT8(save_p); - savedata.skin = READUINT8(save_p); + savedata.skincolor = READUINT8(save->p); + savedata.skin = READUINT16(save->p); - savedata.score = READINT32(save_p); - savedata.lives = READINT32(save_p); - savedata.continues = READINT32(save_p); + savedata.score = READINT32(save->p); + savedata.lives = READINT32(save->p); + savedata.continues = READINT32(save->p); if (savedata.botcolor) { - savedata.botskin = READUINT8(save_p); + savedata.botskin = READUINT16(save->p); if (savedata.botskin-1 >= numskins) savedata.botskin = 0; - savedata.botcolor = READUINT8(save_p); + savedata.botcolor = READUINT8(save->p); } else savedata.botskin = 0; @@ -107,136 +106,128 @@ static inline void P_UnArchivePlayer(void) // // P_NetArchivePlayers // -static void P_NetArchivePlayers(boolean resending) +static void P_NetArchivePlayers(savebuffer_t *save) { INT32 i, j; UINT16 flags; // size_t q; - WRITEUINT32(save_p, ARCHIVEBLOCK_PLAYERS); + WRITEUINT32(save->p, ARCHIVEBLOCK_PLAYERS); for (i = 0; i < MAXPLAYERS; i++) { - if (resending) - WRITESINT8(save_p, (SINT8)adminplayers[i]); + WRITESINT8(save->p, (SINT8)adminplayers[i]); if (!playeringame[i]) continue; flags = 0; - // no longer send ticcmds, player name, skin, or color + // no longer send ticcmds - if (resending) - WRITESTRINGN(save_p, player_names[i], MAXPLAYERNAME); + WRITESTRINGN(save->p, player_names[i], MAXPLAYERNAME); + WRITEANGLE(save->p, players[i].aiming); + WRITEANGLE(save->p, players[i].awayviewaiming); + WRITEINT32(save->p, players[i].awayviewtics); + WRITEINT32(save->p, players[i].health); - WRITEANGLE(save_p, players[i].aiming); - WRITEANGLE(save_p, players[i].awayviewaiming); - WRITEINT32(save_p, players[i].awayviewtics); - WRITEINT32(save_p, players[i].health); - - WRITESINT8(save_p, players[i].pity); - WRITEINT32(save_p, players[i].currentweapon); - WRITEINT32(save_p, players[i].ringweapons); + WRITESINT8(save->p, players[i].pity); + WRITEINT32(save->p, players[i].currentweapon); + WRITEINT32(save->p, players[i].ringweapons); for (j = 0; j < NUMPOWERS; j++) - WRITEUINT16(save_p, players[i].powers[j]); + WRITEUINT16(save->p, players[i].powers[j]); for (j = 0; j < NUMKARTSTUFF; j++) - WRITEINT32(save_p, players[i].kartstuff[j]); + WRITEINT32(save->p, players[i].kartstuff[j]); - WRITEANGLE(save_p, players[i].frameangle); + WRITEANGLE(save->p, players[i].frameangle); - WRITEUINT8(save_p, players[i].playerstate); - WRITEUINT32(save_p, players[i].pflags); - WRITEUINT8(save_p, players[i].panim); - WRITEUINT8(save_p, players[i].spectator); + WRITEUINT8(save->p, players[i].playerstate); + WRITEUINT32(save->p, players[i].pflags); + WRITEUINT8(save->p, players[i].panim); + WRITEUINT8(save->p, players[i].spectator); - WRITEUINT16(save_p, players[i].flashpal); - WRITEUINT16(save_p, players[i].flashcount); + WRITEUINT16(save->p, players[i].flashpal); + WRITEUINT16(save->p, players[i].flashcount); - if (resending) - { - WRITEUINT8(save_p, players[i].skincolor); - WRITEINT32(save_p, players[i].skin); - } - - - WRITEUINT32(save_p, players[i].score); - WRITEFIXED(save_p, players[i].dashspeed); - WRITEINT32(save_p, players[i].dashtime); - WRITESINT8(save_p, players[i].lives); - WRITESINT8(save_p, players[i].continues); - WRITESINT8(save_p, players[i].xtralife); - WRITEUINT8(save_p, players[i].gotcontinue); - WRITEFIXED(save_p, players[i].speed); - WRITEUINT8(save_p, players[i].jumping); - WRITEUINT8(save_p, players[i].secondjump); - WRITEUINT8(save_p, players[i].fly1); - WRITEUINT8(save_p, players[i].scoreadd); - WRITEUINT32(save_p, players[i].glidetime); - WRITEUINT8(save_p, players[i].climbing); - WRITEINT32(save_p, players[i].deadtimer); - WRITEUINT32(save_p, players[i].exiting); - WRITEUINT8(save_p, players[i].homing); - WRITEUINT32(save_p, players[i].skidtime); + WRITEUINT8(save->p, players[i].skincolor); + WRITEINT32(save->p, players[i].skin); + WRITEUINT32(save->p, players[i].score); + WRITEFIXED(save->p, players[i].dashspeed); + WRITEINT32(save->p, players[i].dashtime); + WRITESINT8(save->p, players[i].lives); + WRITESINT8(save->p, players[i].continues); + WRITESINT8(save->p, players[i].xtralife); + WRITEUINT8(save->p, players[i].gotcontinue); + WRITEFIXED(save->p, players[i].speed); + WRITEUINT8(save->p, players[i].jumping); + WRITEUINT8(save->p, players[i].secondjump); + WRITEUINT8(save->p, players[i].fly1); + WRITEUINT8(save->p, players[i].scoreadd); + WRITEUINT32(save->p, players[i].glidetime); + WRITEUINT8(save->p, players[i].climbing); + WRITEINT32(save->p, players[i].deadtimer); + WRITEUINT32(save->p, players[i].exiting); + WRITEUINT8(save->p, players[i].homing); + WRITEUINT32(save->p, players[i].skidtime); //////////////////////////// // Conveyor Belt Movement // //////////////////////////// - WRITEFIXED(save_p, players[i].cmomx); // Conveyor momx - WRITEFIXED(save_p, players[i].cmomy); // Conveyor momy - WRITEFIXED(save_p, players[i].rmomx); // "Real" momx (momx - cmomx) - WRITEFIXED(save_p, players[i].rmomy); // "Real" momy (momy - cmomy) + WRITEFIXED(save->p, players[i].cmomx); // Conveyor momx + WRITEFIXED(save->p, players[i].cmomy); // Conveyor momy + WRITEFIXED(save->p, players[i].rmomx); // "Real" momx (momx - cmomx) + WRITEFIXED(save->p, players[i].rmomy); // "Real" momy (momy - cmomy) ///////////////////// // Race Mode Stuff // ///////////////////// - WRITEINT16(save_p, players[i].numboxes); - WRITEINT16(save_p, players[i].totalring); - WRITEUINT32(save_p, players[i].realtime); - WRITEUINT8(save_p, players[i].laps); + WRITEINT16(save->p, players[i].numboxes); + WRITEINT16(save->p, players[i].totalring); + WRITEUINT32(save->p, players[i].realtime); + WRITEUINT8(save->p, players[i].laps); //////////////////// // CTF Mode Stuff // //////////////////// - WRITEINT32(save_p, players[i].ctfteam); - WRITEUINT16(save_p, players[i].gotflag); + WRITEINT32(save->p, players[i].ctfteam); + WRITEUINT16(save->p, players[i].gotflag); - WRITEINT32(save_p, players[i].weapondelay); - WRITEINT32(save_p, players[i].tossdelay); + WRITEINT32(save->p, players[i].weapondelay); + WRITEINT32(save->p, players[i].tossdelay); - WRITEUINT32(save_p, players[i].starposttime); - WRITEINT16(save_p, players[i].starpostx); - WRITEINT16(save_p, players[i].starposty); - WRITEINT16(save_p, players[i].starpostz); - WRITEINT32(save_p, players[i].starpostnum); - WRITEANGLE(save_p, players[i].starpostangle); + WRITEUINT32(save->p, players[i].starposttime); + WRITEINT16(save->p, players[i].starpostx); + WRITEINT16(save->p, players[i].starposty); + WRITEINT16(save->p, players[i].starpostz); + WRITEINT32(save->p, players[i].starpostnum); + WRITEANGLE(save->p, players[i].starpostangle); - WRITEANGLE(save_p, players[i].angle_pos); - WRITEANGLE(save_p, players[i].old_angle_pos); + WRITEANGLE(save->p, players[i].angle_pos); + WRITEANGLE(save->p, players[i].old_angle_pos); - WRITEINT32(save_p, players[i].flyangle); - WRITEUINT32(save_p, players[i].drilltimer); - WRITEINT32(save_p, players[i].linkcount); - WRITEUINT32(save_p, players[i].linktimer); - WRITEINT32(save_p, players[i].anotherflyangle); - WRITEUINT32(save_p, players[i].nightstime); - WRITEUINT32(save_p, players[i].bumpertime); - WRITEINT32(save_p, players[i].drillmeter); - WRITEUINT8(save_p, players[i].drilldelay); - WRITEUINT8(save_p, players[i].bonustime); - WRITEUINT8(save_p, players[i].mare); + WRITEINT32(save->p, players[i].flyangle); + WRITEUINT32(save->p, players[i].drilltimer); + WRITEINT32(save->p, players[i].linkcount); + WRITEUINT32(save->p, players[i].linktimer); + WRITEINT32(save->p, players[i].anotherflyangle); + WRITEUINT32(save->p, players[i].nightstime); + WRITEUINT32(save->p, players[i].bumpertime); + WRITEINT32(save->p, players[i].drillmeter); + WRITEUINT8(save->p, players[i].drilldelay); + WRITEUINT8(save->p, players[i].bonustime); + WRITEUINT8(save->p, players[i].mare); - WRITEUINT32(save_p, players[i].marebegunat); - WRITEUINT32(save_p, players[i].startedtime); - WRITEUINT32(save_p, players[i].finishedtime); - WRITEINT16(save_p, players[i].finishedrings); - WRITEUINT32(save_p, players[i].marescore); - WRITEUINT32(save_p, players[i].lastmarescore); - WRITEUINT8(save_p, players[i].lastmare); - WRITEINT32(save_p, players[i].maxlink); - WRITEUINT8(save_p, players[i].texttimer); - WRITEUINT8(save_p, players[i].textvar); + WRITEUINT32(save->p, players[i].marebegunat); + WRITEUINT32(save->p, players[i].startedtime); + WRITEUINT32(save->p, players[i].finishedtime); + WRITEINT16(save->p, players[i].finishedrings); + WRITEUINT32(save->p, players[i].marescore); + WRITEUINT32(save->p, players[i].lastmarescore); + WRITEUINT8(save->p, players[i].lastmare); + WRITEINT32(save->p, players[i].maxlink); + WRITEUINT8(save->p, players[i].texttimer); + WRITEUINT8(save->p, players[i].textvar); if (players[i].capsule) flags |= CAPSULE; @@ -250,47 +241,47 @@ static void P_NetArchivePlayers(boolean resending) if (players[i].axis2) flags |= SECONDAXIS; - WRITEINT16(save_p, players[i].lastsidehit); - WRITEINT16(save_p, players[i].lastlinehit); + WRITEINT16(save->p, players[i].lastsidehit); + WRITEINT16(save->p, players[i].lastlinehit); - WRITEUINT32(save_p, players[i].losstime); + WRITEUINT32(save->p, players[i].losstime); - WRITEUINT8(save_p, players[i].timeshit); + WRITEUINT8(save->p, players[i].timeshit); - WRITEINT32(save_p, players[i].onconveyor); + WRITEINT32(save->p, players[i].onconveyor); - WRITEUINT32(save_p, players[i].jointime); - WRITEUINT32(save_p, players[i].spectatorreentry); + WRITEUINT32(save->p, players[i].jointime); + WRITEUINT32(save->p, players[i].spectatorreentry); - WRITEUINT32(save_p, players[i].grieftime); - WRITEUINT8(save_p, players[i].griefstrikes); + WRITEUINT32(save->p, players[i].grieftime); + WRITEUINT8(save->p, players[i].griefstrikes); - WRITEUINT8(save_p, players[i].splitscreenindex); + WRITEUINT8(save->p, players[i].splitscreenindex); - WRITEUINT16(save_p, flags); + WRITEUINT16(save->p, flags); if (flags & CAPSULE) - WRITEUINT32(save_p, players[i].capsule->mobjnum); + WRITEUINT32(save->p, players[i].capsule->mobjnum); if (flags & FIRSTAXIS) - WRITEUINT32(save_p, players[i].axis1->mobjnum); + WRITEUINT32(save->p, players[i].axis1->mobjnum); if (flags & SECONDAXIS) - WRITEUINT32(save_p, players[i].axis2->mobjnum); + WRITEUINT32(save->p, players[i].axis2->mobjnum); if (flags & AWAYVIEW) - WRITEUINT32(save_p, players[i].awayviewmobj->mobjnum); + WRITEUINT32(save->p, players[i].awayviewmobj->mobjnum); - WRITEUINT32(save_p, players[i].charflags); + WRITEUINT32(save->p, players[i].charflags); // SRB2kart - WRITEUINT8(save_p, players[i].kartspeed); - WRITEUINT8(save_p, players[i].kartweight); + WRITEUINT8(save->p, players[i].kartspeed); + WRITEUINT8(save->p, players[i].kartweight); // for (j = 0; j < MAXPREDICTTICS; j++) { - WRITEINT16(save_p, players[i].lturn_max[j]); - WRITEINT16(save_p, players[i].rturn_max[j]); + WRITEINT16(save->p, players[i].lturn_max[j]); + WRITEINT16(save->p, players[i].rturn_max[j]); } } } @@ -298,18 +289,18 @@ static void P_NetArchivePlayers(boolean resending) // // P_NetUnArchivePlayers // -static void P_NetUnArchivePlayers(boolean resending) +static void P_NetUnArchivePlayers(savebuffer_t *save) { INT32 i, j; UINT16 flags; - if (READUINT32(save_p) != ARCHIVEBLOCK_PLAYERS) + if (READUINT32(save->p) != ARCHIVEBLOCK_PLAYERS) I_Error("Bad $$$.sav at archive block Players"); for (i = 0; i < MAXPLAYERS; i++) { - if (resending) - adminplayers[i] = (INT32)READSINT8(save_p); + adminplayers[i] = (INT32)READSINT8(save->p); + // Do NOT memset player struct to 0 // other areas may initialize data elsewhere //memset(&players[i], 0, sizeof (player_t)); @@ -317,167 +308,191 @@ static void P_NetUnArchivePlayers(boolean resending) continue; // NOTE: sending tics should (hopefully) no longer be necessary - // sending player names, skin and color should not be necessary at all! - // (that data is handled in the server config now) - if (resending) - READSTRINGN(save_p, player_names[i], MAXPLAYERNAME); + READSTRINGN(save->p, player_names[i], MAXPLAYERNAME); + players[i].aiming = READANGLE(save->p); + players[i].awayviewaiming = READANGLE(save->p); + players[i].awayviewtics = READINT32(save->p); + players[i].health = READINT32(save->p); - players[i].aiming = READANGLE(save_p); - players[i].awayviewaiming = READANGLE(save_p); - players[i].awayviewtics = READINT32(save_p); - players[i].health = READINT32(save_p); - - players[i].pity = READSINT8(save_p); - players[i].currentweapon = READINT32(save_p); - players[i].ringweapons = READINT32(save_p); + players[i].pity = READSINT8(save->p); + players[i].currentweapon = READINT32(save->p); + players[i].ringweapons = READINT32(save->p); for (j = 0; j < NUMPOWERS; j++) - players[i].powers[j] = READUINT16(save_p); + players[i].powers[j] = READUINT16(save->p); for (j = 0; j < NUMKARTSTUFF; j++) - players[i].kartstuff[j] = READINT32(save_p); + players[i].kartstuff[j] = READINT32(save->p); - players[i].frameangle = READANGLE(save_p); + players[i].frameangle = READANGLE(save->p); - players[i].playerstate = READUINT8(save_p); - players[i].pflags = READUINT32(save_p); - players[i].panim = READUINT8(save_p); - players[i].spectator = READUINT8(save_p); + players[i].playerstate = READUINT8(save->p); + players[i].pflags = READUINT32(save->p); + players[i].panim = READUINT8(save->p); + players[i].spectator = READUINT8(save->p); - players[i].flashpal = READUINT16(save_p); - players[i].flashcount = READUINT16(save_p); + players[i].flashpal = READUINT16(save->p); + players[i].flashcount = READUINT16(save->p); - if (resending) - { - players[i].skincolor = READUINT8(save_p); - players[i].skin = READINT32(save_p); - } - - players[i].score = READUINT32(save_p); - players[i].dashspeed = READFIXED(save_p); // dashing speed - players[i].dashtime = READINT32(save_p); // dashing speed - players[i].lives = READSINT8(save_p); - players[i].continues = READSINT8(save_p); // continues that player has acquired - players[i].xtralife = READSINT8(save_p); // Ring Extra Life counter - players[i].gotcontinue = READUINT8(save_p); // got continue from stage - players[i].speed = READFIXED(save_p); // Player's speed (distance formula of MOMX and MOMY values) - players[i].jumping = READUINT8(save_p); // Jump counter - players[i].secondjump = READUINT8(save_p); - players[i].fly1 = READUINT8(save_p); // Tails flying - players[i].scoreadd = READUINT8(save_p); // Used for multiple enemy attack bonus - players[i].glidetime = READUINT32(save_p); // Glide counter for thrust - players[i].climbing = READUINT8(save_p); // Climbing on the wall - players[i].deadtimer = READINT32(save_p); // End game if game over lasts too long - players[i].exiting = READUINT32(save_p); // Exitlevel timer - players[i].homing = READUINT8(save_p); // Are you homing? - players[i].skidtime = READUINT32(save_p); // Skid timer + players[i].skincolor = READUINT8(save->p); + players[i].skin = READINT32(save->p); + players[i].score = READUINT32(save->p); + players[i].dashspeed = READFIXED(save->p); // dashing speed + players[i].dashtime = READINT32(save->p); // dashing speed + players[i].lives = READSINT8(save->p); + players[i].continues = READSINT8(save->p); // continues that player has acquired + players[i].xtralife = READSINT8(save->p); // Ring Extra Life counter + players[i].gotcontinue = READUINT8(save->p); // got continue from stage + players[i].speed = READFIXED(save->p); // Player's speed (distance formula of MOMX and MOMY values) + players[i].jumping = READUINT8(save->p); // Jump counter + players[i].secondjump = READUINT8(save->p); + players[i].fly1 = READUINT8(save->p); // Tails flying + players[i].scoreadd = READUINT8(save->p); // Used for multiple enemy attack bonus + players[i].glidetime = READUINT32(save->p); // Glide counter for thrust + players[i].climbing = READUINT8(save->p); // Climbing on the wall + players[i].deadtimer = READINT32(save->p); // End game if game over lasts too long + players[i].exiting = READUINT32(save->p); // Exitlevel timer + players[i].homing = READUINT8(save->p); // Are you homing? + players[i].skidtime = READUINT32(save->p); // Skid timer //////////////////////////// // Conveyor Belt Movement // //////////////////////////// - players[i].cmomx = READFIXED(save_p); // Conveyor momx - players[i].cmomy = READFIXED(save_p); // Conveyor momy - players[i].rmomx = READFIXED(save_p); // "Real" momx (momx - cmomx) - players[i].rmomy = READFIXED(save_p); // "Real" momy (momy - cmomy) + players[i].cmomx = READFIXED(save->p); // Conveyor momx + players[i].cmomy = READFIXED(save->p); // Conveyor momy + players[i].rmomx = READFIXED(save->p); // "Real" momx (momx - cmomx) + players[i].rmomy = READFIXED(save->p); // "Real" momy (momy - cmomy) ///////////////////// // Race Mode Stuff // ///////////////////// - players[i].numboxes = READINT16(save_p); // Number of item boxes obtained for Race Mode - players[i].totalring = READINT16(save_p); // Total number of rings obtained for Race Mode - players[i].realtime = READUINT32(save_p); // integer replacement for leveltime - players[i].laps = READUINT8(save_p); // Number of laps (optional) + players[i].numboxes = READINT16(save->p); // Number of item boxes obtained for Race Mode + players[i].totalring = READINT16(save->p); // Total number of rings obtained for Race Mode + players[i].realtime = READUINT32(save->p); // integer replacement for leveltime + players[i].laps = READUINT8(save->p); // Number of laps (optional) //////////////////// // CTF Mode Stuff // //////////////////// - players[i].ctfteam = READINT32(save_p); // 1 == Red, 2 == Blue - players[i].gotflag = READUINT16(save_p); // 1 == Red, 2 == Blue Do you have the flag? + players[i].ctfteam = READINT32(save->p); // 1 == Red, 2 == Blue + players[i].gotflag = READUINT16(save->p); // 1 == Red, 2 == Blue Do you have the flag? - players[i].weapondelay = READINT32(save_p); - players[i].tossdelay = READINT32(save_p); + players[i].weapondelay = READINT32(save->p); + players[i].tossdelay = READINT32(save->p); - players[i].starposttime = READUINT32(save_p); - players[i].starpostx = READINT16(save_p); - players[i].starposty = READINT16(save_p); - players[i].starpostz = READINT16(save_p); - players[i].starpostnum = READINT32(save_p); - players[i].starpostangle = READANGLE(save_p); + players[i].starposttime = READUINT32(save->p); + players[i].starpostx = READINT16(save->p); + players[i].starposty = READINT16(save->p); + players[i].starpostz = READINT16(save->p); + players[i].starpostnum = READINT32(save->p); + players[i].starpostangle = READANGLE(save->p); - players[i].angle_pos = READANGLE(save_p); - players[i].old_angle_pos = READANGLE(save_p); + players[i].angle_pos = READANGLE(save->p); + players[i].old_angle_pos = READANGLE(save->p); - players[i].flyangle = READINT32(save_p); - players[i].drilltimer = READUINT32(save_p); - players[i].linkcount = READINT32(save_p); - players[i].linktimer = READUINT32(save_p); - players[i].anotherflyangle = READINT32(save_p); - players[i].nightstime = READUINT32(save_p); - players[i].bumpertime = READUINT32(save_p); - players[i].drillmeter = READINT32(save_p); - players[i].drilldelay = READUINT8(save_p); - players[i].bonustime = (boolean)READUINT8(save_p); - players[i].mare = READUINT8(save_p); + players[i].flyangle = READINT32(save->p); + players[i].drilltimer = READUINT32(save->p); + players[i].linkcount = READINT32(save->p); + players[i].linktimer = READUINT32(save->p); + players[i].anotherflyangle = READINT32(save->p); + players[i].nightstime = READUINT32(save->p); + players[i].bumpertime = READUINT32(save->p); + players[i].drillmeter = READINT32(save->p); + players[i].drilldelay = READUINT8(save->p); + players[i].bonustime = (boolean)READUINT8(save->p); + players[i].mare = READUINT8(save->p); - players[i].marebegunat = READUINT32(save_p); - players[i].startedtime = READUINT32(save_p); - players[i].finishedtime = READUINT32(save_p); - players[i].finishedrings = READINT16(save_p); - players[i].marescore = READUINT32(save_p); - players[i].lastmarescore = READUINT32(save_p); - players[i].lastmare = READUINT8(save_p); - players[i].maxlink = READINT32(save_p); - players[i].texttimer = READUINT8(save_p); - players[i].textvar = READUINT8(save_p); + players[i].marebegunat = READUINT32(save->p); + players[i].startedtime = READUINT32(save->p); + players[i].finishedtime = READUINT32(save->p); + players[i].finishedrings = READINT16(save->p); + players[i].marescore = READUINT32(save->p); + players[i].lastmarescore = READUINT32(save->p); + players[i].lastmare = READUINT8(save->p); + players[i].maxlink = READINT32(save->p); + players[i].texttimer = READUINT8(save->p); + players[i].textvar = READUINT8(save->p); - players[i].lastsidehit = READINT16(save_p); - players[i].lastlinehit = READINT16(save_p); + players[i].lastsidehit = READINT16(save->p); + players[i].lastlinehit = READINT16(save->p); - players[i].losstime = READUINT32(save_p); + players[i].losstime = READUINT32(save->p); - players[i].timeshit = READUINT8(save_p); + players[i].timeshit = READUINT8(save->p); - players[i].onconveyor = READINT32(save_p); + players[i].onconveyor = READINT32(save->p); - players[i].jointime = READUINT32(save_p); - players[i].spectatorreentry = READUINT32(save_p); + players[i].jointime = READUINT32(save->p); + players[i].spectatorreentry = READUINT32(save->p); - players[i].grieftime = READUINT32(save_p); - players[i].griefstrikes = READUINT8(save_p); + players[i].grieftime = READUINT32(save->p); + players[i].griefstrikes = READUINT8(save->p); - players[i].splitscreenindex = READUINT8(save_p); + players[i].splitscreenindex = READUINT8(save->p); - flags = READUINT16(save_p); + flags = READUINT16(save->p); if (flags & CAPSULE) - players[i].capsule = (mobj_t *)(size_t)READUINT32(save_p); + players[i].capsule = (mobj_t *)(size_t)READUINT32(save->p); if (flags & FIRSTAXIS) - players[i].axis1 = (mobj_t *)(size_t)READUINT32(save_p); + players[i].axis1 = (mobj_t *)(size_t)READUINT32(save->p); if (flags & SECONDAXIS) - players[i].axis2 = (mobj_t *)(size_t)READUINT32(save_p); + players[i].axis2 = (mobj_t *)(size_t)READUINT32(save->p); if (flags & AWAYVIEW) - players[i].awayviewmobj = (mobj_t *)(size_t)READUINT32(save_p); + players[i].awayviewmobj = (mobj_t *)(size_t)READUINT32(save->p); players[i].viewheight = 32<p); // SRB2kart - players[i].kartspeed = READUINT8(save_p); - players[i].kartweight = READUINT8(save_p); + players[i].kartspeed = READUINT8(save->p); + players[i].kartweight = READUINT8(save->p); // for (j = 0; j < MAXPREDICTTICS; j++) { - players[i].lturn_max[j] = READINT16(save_p); - players[i].rturn_max[j] = READINT16(save_p); + players[i].lturn_max[j] = READINT16(save->p); + players[i].rturn_max[j] = READINT16(save->p); } } } +static void P_NetArchiveWaypoints(savebuffer_t *save) +{ + INT32 i, j; + + for (i = 0; i < NUMWAYPOINTSEQUENCES; i++) + { + WRITEUINT16(save->p, numwaypoints[i]); + for (j = 0; j < numwaypoints[i]; j++) + WRITEUINT32(save->p, waypoints[i][j] ? waypoints[i][j]->mobjnum : 0); + } +} + +static void P_NetUnArchiveWaypoints(savebuffer_t *save) +{ + INT32 i, j; + UINT32 mobjnum; + + for (i = 0; i < NUMWAYPOINTSEQUENCES; i++) + { + numwaypoints[i] = READUINT16(save->p); + for (j = 0; j < numwaypoints[i]; j++) + { + mobjnum = READUINT32(save->p); + waypoints[i][j] = (mobjnum == 0) ? NULL : P_FindNewPosition(mobjnum); + } + } +} + +/// +/// World Archiving +/// + #define SD_FLOORHT 0x01 #define SD_CEILHT 0x02 #define SD_FLOORPIC 0x04 @@ -515,7 +530,7 @@ static void P_NetUnArchivePlayers(boolean resending) // // P_NetArchiveWorld // -static void P_NetArchiveWorld(void) +static void P_NetArchiveWorld(savebuffer_t *save) { size_t i; const line_t *li = lines; @@ -530,8 +545,8 @@ static void P_NetArchiveWorld(void) const sector_t *ss = sectors; UINT8 diff, diff2; - WRITEUINT32(save_p, ARCHIVEBLOCK_WORLD); - put = save_p; + WRITEUINT32(save->p, ARCHIVEBLOCK_WORLD); + put = save->p; for (i = 0; i < numsectors; i++, ss++, ms++) { @@ -743,13 +758,13 @@ static void P_NetArchiveWorld(void) R_ClearTextureNumCache(false); vres_Free(virt); - save_p = put; + save->p = put; } // // P_NetUnArchiveWorld // -static void P_NetUnArchiveWorld(void) +static void P_NetUnArchiveWorld(savebuffer_t *save) { UINT16 i; line_t *li; @@ -757,10 +772,10 @@ static void P_NetUnArchiveWorld(void) UINT8 *get; UINT8 diff, diff2; - if (READUINT32(save_p) != ARCHIVEBLOCK_WORLD) + if (READUINT32(save->p) != ARCHIVEBLOCK_WORLD) I_Error("Bad $$$.sav at archive block World"); - get = save_p; + get = save->p; for (;;) { @@ -902,7 +917,7 @@ static void P_NetUnArchiveWorld(void) si->midtexture = READINT32(get); } - save_p = get; + save->p = get; } // @@ -992,6 +1007,8 @@ typedef enum tc_noenemies, tc_eachtime, tc_disappear, + tc_dynslopeline, + tc_dynslopevert, tc_polyrotate, // haleyjd 03/26/06: polyobjects tc_polymove, tc_polywaypoint, @@ -1026,12 +1043,18 @@ static inline UINT32 SavePlayer(const player_t *player) return 0xFFFFFFFF; } +static UINT32 SaveSlope(const pslope_t *slope) +{ + if (slope) return (UINT32)(slope->id); + return 0xFFFFFFFF; +} + // // SaveMobjThinker // // Saves a mobj_t thinker // -static void SaveMobjThinker(const thinker_t *th, const UINT8 type) +static void SaveMobjThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const mobj_t *mobj = (const mobj_t *)th; UINT32 diff; @@ -1068,7 +1091,7 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) diff2 = 0; // not the default but the most probable - if (mobj->momx != 0 || mobj->momy != 0 || mobj->momz != 0) + if (mobj->momx != 0 || mobj->momy != 0 || mobj->momz != 0 || mobj->pmomz !=0) diff |= MD_MOM; if (mobj->radius != mobj->info->radius) diff |= MD_RADIUS; @@ -1160,17 +1183,17 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) if (mobj->type == MT_HOOPCENTER) diff = MD_SPAWNPOINT; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, diff); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, diff); if (diff & MD_MORE) - WRITEUINT16(save_p, diff2); + WRITEUINT16(save->p, diff2); // save pointer, at load time we will search this pointer to reinitilize pointers - WRITEUINT32(save_p, (size_t)mobj); + WRITEUINT32(save->p, (size_t)mobj); - WRITEFIXED(save_p, mobj->z); // Force this so 3dfloor problems don't arise. - WRITEFIXED(save_p, mobj->floorz); - WRITEFIXED(save_p, mobj->ceilingz); + WRITEFIXED(save->p, mobj->z); // Force this so 3dfloor problems don't arise. + WRITEFIXED(save->p, mobj->floorz); + WRITEFIXED(save->p, mobj->ceilingz); if (diff & MD_SPAWNPOINT) { @@ -1178,102 +1201,103 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) for (z = 0; z < nummapthings; z++) if (&mapthings[z] == mobj->spawnpoint) - WRITEUINT16(save_p, z); + WRITEUINT16(save->p, z); if (mobj->type == MT_HOOPCENTER) return; } if (diff & MD_TYPE) - WRITEUINT32(save_p, mobj->type); + WRITEUINT32(save->p, mobj->type); if (diff & MD_POS) { - WRITEFIXED(save_p, mobj->x); - WRITEFIXED(save_p, mobj->y); - WRITEANGLE(save_p, mobj->angle); + WRITEFIXED(save->p, mobj->x); + WRITEFIXED(save->p, mobj->y); + WRITEANGLE(save->p, mobj->angle); } if (diff & MD_MOM) { - WRITEFIXED(save_p, mobj->momx); - WRITEFIXED(save_p, mobj->momy); - WRITEFIXED(save_p, mobj->momz); + WRITEFIXED(save->p, mobj->momx); + WRITEFIXED(save->p, mobj->momy); + WRITEFIXED(save->p, mobj->momz); + WRITEFIXED(save->p, mobj->pmomz); } if (diff & MD_RADIUS) - WRITEFIXED(save_p, mobj->radius); + WRITEFIXED(save->p, mobj->radius); if (diff & MD_HEIGHT) - WRITEFIXED(save_p, mobj->height); + WRITEFIXED(save->p, mobj->height); if (diff & MD_FLAGS) - WRITEUINT32(save_p, mobj->flags); + WRITEUINT32(save->p, mobj->flags); if (diff & MD_FLAGS2) - WRITEUINT32(save_p, mobj->flags2); + WRITEUINT32(save->p, mobj->flags2); if (diff & MD_HEALTH) - WRITEINT32(save_p, mobj->health); + WRITEINT32(save->p, mobj->health); if (diff & MD_RTIME) - WRITEINT32(save_p, mobj->reactiontime); + WRITEINT32(save->p, mobj->reactiontime); if (diff & MD_STATE) - WRITEUINT16(save_p, mobj->state-states); + WRITEUINT16(save->p, mobj->state-states); if (diff & MD_TICS) - WRITEINT32(save_p, mobj->tics); + WRITEINT32(save->p, mobj->tics); if (diff & MD_SPRITE) - WRITEUINT16(save_p, mobj->sprite); + WRITEUINT16(save->p, mobj->sprite); if (diff & MD_FRAME) { - WRITEUINT32(save_p, mobj->frame); - WRITEUINT16(save_p, mobj->anim_duration); + WRITEUINT32(save->p, mobj->frame); + WRITEUINT16(save->p, mobj->anim_duration); } if (diff & MD_EFLAGS) - WRITEUINT16(save_p, mobj->eflags); + WRITEUINT16(save->p, mobj->eflags); if (diff & MD_PLAYER) - WRITEUINT8(save_p, mobj->player-players); + WRITEUINT8(save->p, mobj->player-players); if (diff & MD_MOVEDIR) - WRITEANGLE(save_p, mobj->movedir); + WRITEANGLE(save->p, mobj->movedir); if (diff & MD_MOVECOUNT) - WRITEINT32(save_p, mobj->movecount); + WRITEINT32(save->p, mobj->movecount); if (diff & MD_THRESHOLD) - WRITEINT32(save_p, mobj->threshold); + WRITEINT32(save->p, mobj->threshold); if (diff & MD_LASTLOOK) - WRITEINT32(save_p, mobj->lastlook); + WRITEINT32(save->p, mobj->lastlook); if (diff & MD_TARGET) - WRITEUINT32(save_p, mobj->target->mobjnum); + WRITEUINT32(save->p, mobj->target->mobjnum); if (diff & MD_TRACER) - WRITEUINT32(save_p, mobj->tracer->mobjnum); + WRITEUINT32(save->p, mobj->tracer->mobjnum); if (diff & MD_FRICTION) - WRITEFIXED(save_p, mobj->friction); + WRITEFIXED(save->p, mobj->friction); if (diff & MD_MOVEFACTOR) - WRITEFIXED(save_p, mobj->movefactor); + WRITEFIXED(save->p, mobj->movefactor); if (diff & MD_FUSE) - WRITEINT32(save_p, mobj->fuse); + WRITEINT32(save->p, mobj->fuse); if (diff & MD_WATERTOP) - WRITEFIXED(save_p, mobj->watertop); + WRITEFIXED(save->p, mobj->watertop); if (diff & MD_WATERBOTTOM) - WRITEFIXED(save_p, mobj->waterbottom); + WRITEFIXED(save->p, mobj->waterbottom); if (diff & MD_SCALE) - WRITEFIXED(save_p, mobj->scale); + WRITEFIXED(save->p, mobj->scale); if (diff & MD_DSCALE) - WRITEFIXED(save_p, mobj->destscale); + WRITEFIXED(save->p, mobj->destscale); if (diff2 & MD2_SCALESPEED) - WRITEFIXED(save_p, mobj->scalespeed); + WRITEFIXED(save->p, mobj->scalespeed); if (diff2 & MD2_CUSVAL) - WRITEINT32(save_p, mobj->cusval); + WRITEINT32(save->p, mobj->cusval); if (diff2 & MD2_CVMEM) - WRITEINT32(save_p, mobj->cvmem); + WRITEINT32(save->p, mobj->cvmem); if (diff2 & MD2_SKIN) - WRITEUINT8(save_p, (UINT8)((skin_t *)mobj->skin - skins)); + WRITEUINT16(save->p, (UINT16)((skin_t *)mobj->skin - skins)); if (diff2 & MD2_COLOR) - WRITEUINT8(save_p, mobj->color); + WRITEUINT8(save->p, mobj->color); if (diff2 & MD2_EXTVAL1) - WRITEINT32(save_p, mobj->extravalue1); + WRITEINT32(save->p, mobj->extravalue1); if (diff2 & MD2_EXTVAL2) - WRITEINT32(save_p, mobj->extravalue2); + WRITEINT32(save->p, mobj->extravalue2); if (diff2 & MD2_HNEXT) - WRITEUINT32(save_p, mobj->hnext->mobjnum); + WRITEUINT32(save->p, mobj->hnext->mobjnum); if (diff2 & MD2_HPREV) - WRITEUINT32(save_p, mobj->hprev->mobjnum); + WRITEUINT32(save->p, mobj->hprev->mobjnum); if (diff2 & MD2_SLOPE) - WRITEUINT16(save_p, mobj->standingslope->id); + WRITEUINT16(save->p, mobj->standingslope->id); if (diff2 & MD2_COLORIZED) - WRITEUINT8(save_p, mobj->colorized); + WRITEUINT8(save->p, mobj->colorized); - WRITEUINT32(save_p, mobj->mobjnum); + WRITEUINT32(save->p, mobj->mobjnum); } // @@ -1281,18 +1305,18 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) // // Saves a levelspecthink_t thinker // -static void SaveSpecialLevelThinker(const thinker_t *th, const UINT8 type) +static void SaveSpecialLevelThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const levelspecthink_t *ht = (const void *)th; size_t i; - WRITEUINT8(save_p, type); + WRITEUINT8(save->p, type); for (i = 0; i < 16; i++) { - WRITEFIXED(save_p, ht->vars[i]); //var[16] - WRITEFIXED(save_p, ht->var2s[i]); //var[16] + WRITEFIXED(save->p, ht->vars[i]); //var[16] + WRITEFIXED(save->p, ht->var2s[i]); //var[16] } - WRITEUINT32(save_p, SaveLine(ht->sourceline)); - WRITEUINT32(save_p, SaveSector(ht->sector)); + WRITEUINT32(save->p, SaveLine(ht->sourceline)); + WRITEUINT32(save->p, SaveSector(ht->sector)); } // @@ -1300,25 +1324,25 @@ static void SaveSpecialLevelThinker(const thinker_t *th, const UINT8 type) // // Saves a ceiling_t thinker // -static void SaveCeilingThinker(const thinker_t *th, const UINT8 type) +static void SaveCeilingThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const ceiling_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT8(save_p, ht->type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEFIXED(save_p, ht->bottomheight); - WRITEFIXED(save_p, ht->topheight); - WRITEFIXED(save_p, ht->speed); - WRITEFIXED(save_p, ht->oldspeed); - WRITEFIXED(save_p, ht->delay); - WRITEFIXED(save_p, ht->delaytimer); - WRITEUINT8(save_p, ht->crush); - WRITEINT32(save_p, ht->texture); - WRITEINT32(save_p, ht->direction); - WRITEINT32(save_p, ht->tag); - WRITEINT32(save_p, ht->olddirection); - WRITEFIXED(save_p, ht->origspeed); - WRITEFIXED(save_p, ht->sourceline); + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEFIXED(save->p, ht->bottomheight); + WRITEFIXED(save->p, ht->topheight); + WRITEFIXED(save->p, ht->speed); + WRITEFIXED(save->p, ht->oldspeed); + WRITEFIXED(save->p, ht->delay); + WRITEFIXED(save->p, ht->delaytimer); + WRITEUINT8(save->p, ht->crush); + WRITEINT32(save->p, ht->texture); + WRITEINT32(save->p, ht->direction); + WRITEINT32(save->p, ht->tag); + WRITEINT32(save->p, ht->olddirection); + WRITEFIXED(save->p, ht->origspeed); + WRITEFIXED(save->p, ht->sourceline); } // @@ -1326,20 +1350,20 @@ static void SaveCeilingThinker(const thinker_t *th, const UINT8 type) // // Saves a floormove_t thinker // -static void SaveFloormoveThinker(const thinker_t *th, const UINT8 type) +static void SaveFloormoveThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const floormove_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT8(save_p, ht->type); - WRITEUINT8(save_p, ht->crush); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->direction); - WRITEINT32(save_p, ht->texture); - WRITEFIXED(save_p, ht->floordestheight); - WRITEFIXED(save_p, ht->speed); - WRITEFIXED(save_p, ht->origspeed); - WRITEFIXED(save_p, ht->delay); - WRITEFIXED(save_p, ht->delaytimer); + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEUINT8(save->p, ht->crush); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->direction); + WRITEINT32(save->p, ht->texture); + WRITEFIXED(save->p, ht->floordestheight); + WRITEFIXED(save->p, ht->speed); + WRITEFIXED(save->p, ht->origspeed); + WRITEFIXED(save->p, ht->delay); + WRITEFIXED(save->p, ht->delaytimer); } // @@ -1347,13 +1371,13 @@ static void SaveFloormoveThinker(const thinker_t *th, const UINT8 type) // // Saves a lightflash_t thinker // -static void SaveLightflashThinker(const thinker_t *th, const UINT8 type) +static void SaveLightflashThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const lightflash_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->maxlight); - WRITEINT32(save_p, ht->minlight); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->maxlight); + WRITEINT32(save->p, ht->minlight); } // @@ -1361,16 +1385,16 @@ static void SaveLightflashThinker(const thinker_t *th, const UINT8 type) // // Saves a strobe_t thinker // -static void SaveStrobeThinker(const thinker_t *th, const UINT8 type) +static void SaveStrobeThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const strobe_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->count); - WRITEINT32(save_p, ht->minlight); - WRITEINT32(save_p, ht->maxlight); - WRITEINT32(save_p, ht->darktime); - WRITEINT32(save_p, ht->brighttime); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->count); + WRITEINT32(save->p, ht->minlight); + WRITEINT32(save->p, ht->maxlight); + WRITEINT32(save->p, ht->darktime); + WRITEINT32(save->p, ht->brighttime); } // @@ -1378,15 +1402,15 @@ static void SaveStrobeThinker(const thinker_t *th, const UINT8 type) // // Saves a glow_t thinker // -static void SaveGlowThinker(const thinker_t *th, const UINT8 type) +static void SaveGlowThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const glow_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->minlight); - WRITEINT32(save_p, ht->maxlight); - WRITEINT32(save_p, ht->direction); - WRITEINT32(save_p, ht->speed); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->minlight); + WRITEINT32(save->p, ht->maxlight); + WRITEINT32(save->p, ht->direction); + WRITEINT32(save->p, ht->speed); } // @@ -1394,15 +1418,15 @@ static void SaveGlowThinker(const thinker_t *th, const UINT8 type) // // Saves a fireflicker_t thinker // -static inline void SaveFireflickerThinker(const thinker_t *th, const UINT8 type) +static inline void SaveFireflickerThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const fireflicker_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->count); - WRITEINT32(save_p, ht->resetcount); - WRITEINT32(save_p, ht->maxlight); - WRITEINT32(save_p, ht->minlight); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->count); + WRITEINT32(save->p, ht->resetcount); + WRITEINT32(save->p, ht->maxlight); + WRITEINT32(save->p, ht->minlight); } // @@ -1410,27 +1434,27 @@ static inline void SaveFireflickerThinker(const thinker_t *th, const UINT8 type) // // Saves a elevator_t thinker // -static void SaveElevatorThinker(const thinker_t *th, const UINT8 type) +static void SaveElevatorThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const elevator_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT8(save_p, ht->type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEUINT32(save_p, SaveSector(ht->actionsector)); - WRITEINT32(save_p, ht->direction); - WRITEFIXED(save_p, ht->floordestheight); - WRITEFIXED(save_p, ht->ceilingdestheight); - WRITEFIXED(save_p, ht->speed); - WRITEFIXED(save_p, ht->origspeed); - WRITEFIXED(save_p, ht->low); - WRITEFIXED(save_p, ht->high); - WRITEFIXED(save_p, ht->distance); - WRITEFIXED(save_p, ht->delay); - WRITEFIXED(save_p, ht->delaytimer); - WRITEFIXED(save_p, ht->floorwasheight); - WRITEFIXED(save_p, ht->ceilingwasheight); - WRITEUINT32(save_p, SavePlayer(ht->player)); // was dummy - WRITEUINT32(save_p, SaveLine(ht->sourceline)); + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEUINT32(save->p, SaveSector(ht->actionsector)); + WRITEINT32(save->p, ht->direction); + WRITEFIXED(save->p, ht->floordestheight); + WRITEFIXED(save->p, ht->ceilingdestheight); + WRITEFIXED(save->p, ht->speed); + WRITEFIXED(save->p, ht->origspeed); + WRITEFIXED(save->p, ht->low); + WRITEFIXED(save->p, ht->high); + WRITEFIXED(save->p, ht->distance); + WRITEFIXED(save->p, ht->delay); + WRITEFIXED(save->p, ht->delaytimer); + WRITEFIXED(save->p, ht->floorwasheight); + WRITEFIXED(save->p, ht->ceilingwasheight); + WRITEUINT32(save->p, SavePlayer(ht->player)); // was dummy + WRITEUINT32(save->p, SaveLine(ht->sourceline)); } // @@ -1438,20 +1462,20 @@ static void SaveElevatorThinker(const thinker_t *th, const UINT8 type) // // Saves a scroll_t thinker // -static inline void SaveScrollThinker(const thinker_t *th, const UINT8 type) +static inline void SaveScrollThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const scroll_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEFIXED(save_p, ht->dx); - WRITEFIXED(save_p, ht->dy); - WRITEINT32(save_p, ht->affectee); - WRITEINT32(save_p, ht->control); - WRITEFIXED(save_p, ht->last_height); - WRITEFIXED(save_p, ht->vdx); - WRITEFIXED(save_p, ht->vdy); - WRITEINT32(save_p, ht->accel); - WRITEINT32(save_p, ht->exclusive); - WRITEUINT8(save_p, ht->type); + WRITEUINT8(save->p, type); + WRITEFIXED(save->p, ht->dx); + WRITEFIXED(save->p, ht->dy); + WRITEINT32(save->p, ht->affectee); + WRITEINT32(save->p, ht->control); + WRITEFIXED(save->p, ht->last_height); + WRITEFIXED(save->p, ht->vdx); + WRITEFIXED(save->p, ht->vdy); + WRITEINT32(save->p, ht->accel); + WRITEINT32(save->p, ht->exclusive); + WRITEUINT8(save->p, ht->type); } // @@ -1459,15 +1483,15 @@ static inline void SaveScrollThinker(const thinker_t *th, const UINT8 type) // // Saves a friction_t thinker // -static inline void SaveFrictionThinker(const thinker_t *th, const UINT8 type) +static inline void SaveFrictionThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const friction_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->friction); - WRITEINT32(save_p, ht->movefactor); - WRITEINT32(save_p, ht->affectee); - WRITEINT32(save_p, ht->referrer); - WRITEUINT8(save_p, ht->roverfriction); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->friction); + WRITEINT32(save->p, ht->movefactor); + WRITEINT32(save->p, ht->affectee); + WRITEINT32(save->p, ht->referrer); + WRITEUINT8(save->p, ht->roverfriction); } // @@ -1475,23 +1499,23 @@ static inline void SaveFrictionThinker(const thinker_t *th, const UINT8 type) // // Saves a pusher_t thinker // -static inline void SavePusherThinker(const thinker_t *th, const UINT8 type) +static inline void SavePusherThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const pusher_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT8(save_p, ht->type); - WRITEINT32(save_p, ht->x_mag); - WRITEINT32(save_p, ht->y_mag); - WRITEINT32(save_p, ht->magnitude); - WRITEINT32(save_p, ht->radius); - WRITEINT32(save_p, ht->x); - WRITEINT32(save_p, ht->y); - WRITEINT32(save_p, ht->z); - WRITEINT32(save_p, ht->affectee); - WRITEUINT8(save_p, ht->roverpusher); - WRITEINT32(save_p, ht->referrer); - WRITEINT32(save_p, ht->exclusive); - WRITEINT32(save_p, ht->slider); + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEINT32(save->p, ht->x_mag); + WRITEINT32(save->p, ht->y_mag); + WRITEINT32(save->p, ht->magnitude); + WRITEINT32(save->p, ht->radius); + WRITEINT32(save->p, ht->x); + WRITEINT32(save->p, ht->y); + WRITEINT32(save->p, ht->z); + WRITEINT32(save->p, ht->affectee); + WRITEUINT8(save->p, ht->roverpusher); + WRITEINT32(save->p, ht->referrer); + WRITEINT32(save->p, ht->exclusive); + WRITEINT32(save->p, ht->slider); } // @@ -1499,13 +1523,13 @@ static inline void SavePusherThinker(const thinker_t *th, const UINT8 type) // // Saves a laserthink_t thinker // -static void SaveLaserThinker(const thinker_t *th, const UINT8 type) +static void SaveLaserThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const laserthink_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEUINT32(save_p, SaveSector(ht->sec)); - WRITEUINT32(save_p, SaveLine(ht->sourceline)); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEUINT32(save->p, SaveSector(ht->sec)); + WRITEUINT32(save->p, SaveLine(ht->sourceline)); } // @@ -1513,13 +1537,13 @@ static void SaveLaserThinker(const thinker_t *th, const UINT8 type) // // Saves a lightlevel_t thinker // -static void SaveLightlevelThinker(const thinker_t *th, const UINT8 type) +static void SaveLightlevelThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const lightlevel_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->destlevel); - WRITEINT32(save_p, ht->speed); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->destlevel); + WRITEINT32(save->p, ht->speed); } // @@ -1527,14 +1551,14 @@ static void SaveLightlevelThinker(const thinker_t *th, const UINT8 type) // // Saves a executor_t thinker // -static void SaveExecutorThinker(const thinker_t *th, const UINT8 type) +static void SaveExecutorThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const executor_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, SaveLine(ht->line)); - WRITEUINT32(save_p, SaveMobjnum(ht->caller)); - WRITEUINT32(save_p, SaveSector(ht->sector)); - WRITEINT32(save_p, ht->timer); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, SaveLine(ht->line)); + WRITEUINT32(save->p, SaveMobjnum(ht->caller)); + WRITEUINT32(save->p, SaveSector(ht->sector)); + WRITEINT32(save->p, ht->timer); } // @@ -1542,33 +1566,47 @@ static void SaveExecutorThinker(const thinker_t *th, const UINT8 type) // // Saves a disappear_t thinker // -static void SaveDisappearThinker(const thinker_t *th, const UINT8 type) +static void SaveDisappearThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const disappear_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEUINT32(save_p, ht->appeartime); - WRITEUINT32(save_p, ht->disappeartime); - WRITEUINT32(save_p, ht->offset); - WRITEUINT32(save_p, ht->timer); - WRITEINT32(save_p, ht->affectee); - WRITEINT32(save_p, ht->sourceline); - WRITEINT32(save_p, ht->exists); + WRITEUINT8(save->p, type); + WRITEUINT32(save->p, ht->appeartime); + WRITEUINT32(save->p, ht->disappeartime); + WRITEUINT32(save->p, ht->offset); + WRITEUINT32(save->p, ht->timer); + WRITEINT32(save->p, ht->affectee); + WRITEINT32(save->p, ht->sourceline); + WRITEINT32(save->p, ht->exists); } +/// Save a dynamic slope thinker. +static inline void SaveDynamicSlopeThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) +{ + const dynplanethink_t* ht = (const void*)th; + + WRITEUINT8(save->p, type); + WRITEUINT8(save->p, ht->type); + WRITEUINT32(save->p, SaveSlope(ht->slope)); + WRITEUINT32(save->p, SaveLine(ht->sourceline)); + WRITEFIXED(save->p, ht->extent); + + WRITEMEM(save->p, ht->tags, sizeof(ht->tags)); + WRITEMEM(save->p, ht->vex, sizeof(ht->vex)); +} // // SavePolyrotateThinker // // Saves a polyrotate_t thinker // -static inline void SavePolyrotatetThinker(const thinker_t *th, const UINT8 type) +static inline void SavePolyrotatetThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polyrotate_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->speed); - WRITEINT32(save_p, ht->distance); - WRITEUINT8(save_p, ht->turnobjs); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->speed); + WRITEINT32(save->p, ht->distance); + WRITEUINT8(save->p, ht->turnobjs); } // @@ -1576,16 +1614,16 @@ static inline void SavePolyrotatetThinker(const thinker_t *th, const UINT8 type) // // Saves a polymovet_t thinker // -static void SavePolymoveThinker(const thinker_t *th, const UINT8 type) +static void SavePolymoveThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polymove_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->speed); - WRITEFIXED(save_p, ht->momx); - WRITEFIXED(save_p, ht->momy); - WRITEINT32(save_p, ht->distance); - WRITEANGLE(save_p, ht->angle); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->speed); + WRITEFIXED(save->p, ht->momx); + WRITEFIXED(save->p, ht->momy); + WRITEINT32(save->p, ht->distance); + WRITEANGLE(save->p, ht->angle); } // @@ -1593,22 +1631,23 @@ static void SavePolymoveThinker(const thinker_t *th, const UINT8 type) // // Saves a polywaypoint_t thinker // -static void SavePolywaypointThinker(const thinker_t *th, UINT8 type) +static void SavePolywaypointThinker(savebuffer_t *save, const thinker_t *th, UINT8 type) { const polywaypoint_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->speed); - WRITEINT32(save_p, ht->sequence); - WRITEINT32(save_p, ht->pointnum); - WRITEINT32(save_p, ht->direction); - WRITEUINT8(save_p, ht->comeback); - WRITEUINT8(save_p, ht->wrap); - WRITEUINT8(save_p, ht->continuous); - WRITEUINT8(save_p, ht->stophere); - WRITEFIXED(save_p, ht->diffx); - WRITEFIXED(save_p, ht->diffy); - WRITEFIXED(save_p, ht->diffz); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->speed); + WRITEINT32(save->p, ht->sequence); + WRITEINT32(save->p, ht->pointnum); + WRITEINT32(save->p, ht->direction); + WRITEUINT8(save->p, ht->comeback); + WRITEUINT8(save->p, ht->wrap); + WRITEUINT8(save->p, ht->continuous); + WRITEUINT8(save->p, ht->stophere); + WRITEFIXED(save->p, ht->diffx); + WRITEFIXED(save->p, ht->diffy); + WRITEFIXED(save->p, ht->diffz); + WRITEUINT32(save->p, SaveMobjnum(ht->target)); } // @@ -1616,23 +1655,23 @@ static void SavePolywaypointThinker(const thinker_t *th, UINT8 type) // // Saves a polyslidedoor_t thinker // -static void SavePolyslidedoorThinker(const thinker_t *th, const UINT8 type) +static void SavePolyslidedoorThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polyslidedoor_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->delay); - WRITEINT32(save_p, ht->delayCount); - WRITEINT32(save_p, ht->initSpeed); - WRITEINT32(save_p, ht->speed); - WRITEINT32(save_p, ht->initDistance); - WRITEINT32(save_p, ht->distance); - WRITEUINT32(save_p, ht->initAngle); - WRITEUINT32(save_p, ht->angle); - WRITEUINT32(save_p, ht->revAngle); - WRITEFIXED(save_p, ht->momx); - WRITEFIXED(save_p, ht->momy); - WRITEUINT8(save_p, ht->closing); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->delay); + WRITEINT32(save->p, ht->delayCount); + WRITEINT32(save->p, ht->initSpeed); + WRITEINT32(save->p, ht->speed); + WRITEINT32(save->p, ht->initDistance); + WRITEINT32(save->p, ht->distance); + WRITEUINT32(save->p, ht->initAngle); + WRITEUINT32(save->p, ht->angle); + WRITEUINT32(save->p, ht->revAngle); + WRITEFIXED(save->p, ht->momx); + WRITEFIXED(save->p, ht->momy); + WRITEUINT8(save->p, ht->closing); } // @@ -1640,29 +1679,29 @@ static void SavePolyslidedoorThinker(const thinker_t *th, const UINT8 type) // // Saves a polyswingdoor_t thinker // -static void SavePolyswingdoorThinker(const thinker_t *th, const UINT8 type) +static void SavePolyswingdoorThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polyswingdoor_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEINT32(save_p, ht->delay); - WRITEINT32(save_p, ht->delayCount); - WRITEINT32(save_p, ht->initSpeed); - WRITEINT32(save_p, ht->speed); - WRITEINT32(save_p, ht->initDistance); - WRITEINT32(save_p, ht->distance); - WRITEUINT8(save_p, ht->closing); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEINT32(save->p, ht->delay); + WRITEINT32(save->p, ht->delayCount); + WRITEINT32(save->p, ht->initSpeed); + WRITEINT32(save->p, ht->speed); + WRITEINT32(save->p, ht->initDistance); + WRITEINT32(save->p, ht->distance); + WRITEUINT8(save->p, ht->closing); } -static void SavePolydisplaceThinker(const thinker_t *th, const UINT8 type) +static void SavePolydisplaceThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const polydisplace_t *ht = (const void *)th; - WRITEUINT8(save_p, type); - WRITEINT32(save_p, ht->polyObjNum); - WRITEUINT32(save_p, SaveSector(ht->controlSector)); - WRITEFIXED(save_p, ht->dx); - WRITEFIXED(save_p, ht->dy); - WRITEFIXED(save_p, ht->oldHeights); + WRITEUINT8(save->p, type); + WRITEINT32(save->p, ht->polyObjNum); + WRITEUINT32(save->p, SaveSector(ht->controlSector)); + WRITEFIXED(save->p, ht->dx); + WRITEFIXED(save->p, ht->dy); + WRITEFIXED(save->p, ht->oldHeights); } /* @@ -1671,10 +1710,10 @@ static void SavePolydisplaceThinker(const thinker_t *th, const UINT8 type) // // Saves a what_t thinker // -static inline void SaveWhatThinker(const thinker_t *th, const UINT8 type) +static inline void SaveWhatThinker(savebuffer_t *save, const thinker_t *th, const UINT8 type) { const what_t *ht = (const void *)th; - WRITEUINT8(save_p, type); + WRITEUINT8(save->p, type); } */ @@ -1682,12 +1721,12 @@ static inline void SaveWhatThinker(const thinker_t *th, const UINT8 type) // P_NetArchiveThinkers // // -static void P_NetArchiveThinkers(void) +static void P_NetArchiveThinkers(savebuffer_t *save) { const thinker_t *th; UINT32 numsaved = 0; - WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS); + WRITEUINT32(save->p, ARCHIVEBLOCK_THINKERS); // save off the current thinkers for (th = thinkercap.next; th != &thinkercap; th = th->next) @@ -1698,7 +1737,7 @@ static void P_NetArchiveThinkers(void) if (th->function.acp1 == (actionf_p1)P_MobjThinker) { - SaveMobjThinker(th, tc_mobj); + SaveMobjThinker(save, th, tc_mobj); continue; } #ifdef PARANOIA @@ -1706,188 +1745,198 @@ static void P_NetArchiveThinkers(void) #endif else if (th->function.acp1 == (actionf_p1)T_MoveCeiling) { - SaveCeilingThinker(th, tc_ceiling); + SaveCeilingThinker(save, th, tc_ceiling); continue; } else if (th->function.acp1 == (actionf_p1)T_CrushCeiling) { - SaveCeilingThinker(th, tc_crushceiling); + SaveCeilingThinker(save, th, tc_crushceiling); continue; } else if (th->function.acp1 == (actionf_p1)T_MoveFloor) { - SaveFloormoveThinker(th, tc_floor); + SaveFloormoveThinker(save, th, tc_floor); continue; } else if (th->function.acp1 == (actionf_p1)T_LightningFlash) { - SaveLightflashThinker(th, tc_flash); + SaveLightflashThinker(save, th, tc_flash); continue; } else if (th->function.acp1 == (actionf_p1)T_StrobeFlash) { - SaveStrobeThinker(th, tc_strobe); + SaveStrobeThinker(save, th, tc_strobe); continue; } else if (th->function.acp1 == (actionf_p1)T_Glow) { - SaveGlowThinker(th, tc_glow); + SaveGlowThinker(save, th, tc_glow); continue; } else if (th->function.acp1 == (actionf_p1)T_FireFlicker) { - SaveFireflickerThinker(th, tc_fireflicker); + SaveFireflickerThinker(save, th, tc_fireflicker); continue; } else if (th->function.acp1 == (actionf_p1)T_MoveElevator) { - SaveElevatorThinker(th, tc_elevator); + SaveElevatorThinker(save, th, tc_elevator); continue; } else if (th->function.acp1 == (actionf_p1)T_ContinuousFalling) { - SaveSpecialLevelThinker(th, tc_continuousfalling); + SaveSpecialLevelThinker(save, th, tc_continuousfalling); continue; } else if (th->function.acp1 == (actionf_p1)T_ThwompSector) { - SaveSpecialLevelThinker(th, tc_thwomp); + SaveSpecialLevelThinker(save, th, tc_thwomp); continue; } else if (th->function.acp1 == (actionf_p1)T_NoEnemiesSector) { - SaveSpecialLevelThinker(th, tc_noenemies); + SaveSpecialLevelThinker(save, th, tc_noenemies); continue; } else if (th->function.acp1 == (actionf_p1)T_EachTimeThinker) { - SaveSpecialLevelThinker(th, tc_eachtime); + SaveSpecialLevelThinker(save, th, tc_eachtime); continue; } else if (th->function.acp1 == (actionf_p1)T_RaiseSector) { - SaveSpecialLevelThinker(th, tc_raisesector); + SaveSpecialLevelThinker(save, th, tc_raisesector); continue; } else if (th->function.acp1 == (actionf_p1)T_CameraScanner) { - SaveElevatorThinker(th, tc_camerascanner); + SaveElevatorThinker(save, th, tc_camerascanner); continue; } else if (th->function.acp1 == (actionf_p1)T_Scroll) { - SaveScrollThinker(th, tc_scroll); + SaveScrollThinker(save, th, tc_scroll); continue; } else if (th->function.acp1 == (actionf_p1)T_Friction) { - SaveFrictionThinker(th, tc_friction); + SaveFrictionThinker(save, th, tc_friction); continue; } else if (th->function.acp1 == (actionf_p1)T_Pusher) { - SavePusherThinker(th, tc_pusher); + SavePusherThinker(save, th, tc_pusher); continue; } else if (th->function.acp1 == (actionf_p1)T_BounceCheese) { - SaveSpecialLevelThinker(th, tc_bouncecheese); + SaveSpecialLevelThinker(save, th, tc_bouncecheese); continue; } else if (th->function.acp1 == (actionf_p1)T_StartCrumble) { - SaveElevatorThinker(th, tc_startcrumble); + SaveElevatorThinker(save, th, tc_startcrumble); continue; } else if (th->function.acp1 == (actionf_p1)T_MarioBlock) { - SaveSpecialLevelThinker(th, tc_marioblock); + SaveSpecialLevelThinker(save, th, tc_marioblock); continue; } else if (th->function.acp1 == (actionf_p1)T_MarioBlockChecker) { - SaveSpecialLevelThinker(th, tc_marioblockchecker); + SaveSpecialLevelThinker(save, th, tc_marioblockchecker); continue; } else if (th->function.acp1 == (actionf_p1)T_SpikeSector) { - SaveSpecialLevelThinker(th, tc_spikesector); + SaveSpecialLevelThinker(save, th, tc_spikesector); continue; } else if (th->function.acp1 == (actionf_p1)T_FloatSector) { - SaveSpecialLevelThinker(th, tc_floatsector); + SaveSpecialLevelThinker(save, th, tc_floatsector); continue; } else if (th->function.acp1 == (actionf_p1)T_BridgeThinker) { - SaveSpecialLevelThinker(th, tc_bridgethinker); + SaveSpecialLevelThinker(save, th, tc_bridgethinker); continue; } else if (th->function.acp1 == (actionf_p1)T_LaserFlash) { - SaveLaserThinker(th, tc_laserflash); + SaveLaserThinker(save, th, tc_laserflash); continue; } else if (th->function.acp1 == (actionf_p1)T_LightFade) { - SaveLightlevelThinker(th, tc_lightfade); + SaveLightlevelThinker(save, th, tc_lightfade); continue; } else if (th->function.acp1 == (actionf_p1)T_ExecutorDelay) { - SaveExecutorThinker(th, tc_executor); + SaveExecutorThinker(save, th, tc_executor); continue; } else if (th->function.acp1 == (actionf_p1)T_Disappear) { - SaveDisappearThinker(th, tc_disappear); + SaveDisappearThinker(save, th, tc_disappear); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_DynamicSlopeLine) + { + SaveDynamicSlopeThinker(save, th, tc_dynslopeline); + continue; + } + else if (th->function.acp1 == (actionf_p1)T_DynamicSlopeVert) + { + SaveDynamicSlopeThinker(save, th, tc_dynslopevert); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjRotate) { - SavePolyrotatetThinker(th, tc_polyrotate); + SavePolyrotatetThinker(save, th, tc_polyrotate); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjMove) { - SavePolymoveThinker(th, tc_polymove); + SavePolymoveThinker(save, th, tc_polymove); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjWaypoint) { - SavePolywaypointThinker(th, tc_polywaypoint); + SavePolywaypointThinker(save, th, tc_polywaypoint); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyDoorSlide) { - SavePolyslidedoorThinker(th, tc_polyslidedoor); + SavePolyslidedoorThinker(save, th, tc_polyslidedoor); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyDoorSwing) { - SavePolyswingdoorThinker(th, tc_polyswingdoor); + SavePolyswingdoorThinker(save, th, tc_polyswingdoor); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjFlag) { - SavePolymoveThinker(th, tc_polyflag); + SavePolymoveThinker(save, th, tc_polyflag); continue; } else if (th->function.acp1 == (actionf_p1)T_PolyObjDisplace) { - SavePolydisplaceThinker(th, tc_polydisplace); + SavePolydisplaceThinker(save, th, tc_polydisplace); continue; } #ifdef PARANOIA - else if (th->function.acp1 != P_RemoveThinkerDelayed) // wait garbage collection + else if (th->function.acv != P_RemoveThinkerDelayed) // wait garbage collection I_Error("unknown thinker type %p", th->function.acp1); #endif } CONS_Debug(DBG_NETPLAY, "%u thinkers saved\n", numsaved); - WRITEUINT8(save_p, tc_end); + WRITEUINT8(save->p, tc_end); } // Now save the pointers, tracer and target, but at load time we must @@ -1905,11 +1954,8 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) continue; mobj = (mobj_t *)th; - - if (mobj->mobjnum != oldposition) - continue; - - return mobj; + if (mobj->mobjnum == oldposition) + return mobj; } CONS_Debug(DBG_GAMELOGIC, "mobj not found\n"); return NULL; @@ -1939,12 +1985,25 @@ static inline player_t *LoadPlayer(UINT32 player) return &players[player]; } +static inline pslope_t *LoadSlope(UINT32 slopeid) +{ + pslope_t *p = slopelist; + if (slopeid > slopecount) return NULL; + do + { + if (p->id == slopeid) + return p; + } while ((p = p->next)); + return NULL; +} + + // // LoadMobjThinker // // Loads a mobj_t from a save game // -static void LoadMobjThinker(actionf_p1 thinker) +static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) { thinker_t *next; mobj_t *mobj; @@ -1953,21 +2012,21 @@ static void LoadMobjThinker(actionf_p1 thinker) INT32 i; fixed_t z, floorz, ceilingz; - diff = READUINT32(save_p); + diff = READUINT32(save->p); if (diff & MD_MORE) - diff2 = READUINT16(save_p); + diff2 = READUINT16(save->p); else diff2 = 0; - next = (void *)(size_t)READUINT32(save_p); + next = (void *)(size_t)READUINT32(save->p); - z = READFIXED(save_p); // Force this so 3dfloor problems don't arise. - floorz = READFIXED(save_p); - ceilingz = READFIXED(save_p); + z = READFIXED(save->p); // Force this so 3dfloor problems don't arise. + floorz = READFIXED(save->p); + ceilingz = READFIXED(save->p); if (diff & MD_SPAWNPOINT) { - UINT16 spawnpointnum = READUINT16(save_p); + UINT16 spawnpointnum = READUINT16(save->p); if (mapthings[spawnpointnum].type == 1705 || mapthings[spawnpointnum].type == 1713) // NiGHTS Hoop special case { @@ -1991,7 +2050,7 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->ceilingz = ceilingz; if (diff & MD_TYPE) - mobj->type = READUINT32(save_p); + mobj->type = READUINT32(save->p); else { for (i = 0; i < NUMMOBJTYPES; i++) @@ -2010,9 +2069,9 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->info = &mobjinfo[mobj->type]; if (diff & MD_POS) { - mobj->x = READFIXED(save_p); - mobj->y = READFIXED(save_p); - mobj->angle = READANGLE(save_p); + mobj->x = READFIXED(save->p); + mobj->y = READFIXED(save->p); + mobj->angle = READANGLE(save->p); } else { @@ -2022,50 +2081,51 @@ static void LoadMobjThinker(actionf_p1 thinker) } if (diff & MD_MOM) { - mobj->momx = READFIXED(save_p); - mobj->momy = READFIXED(save_p); - mobj->momz = READFIXED(save_p); + mobj->momx = READFIXED(save->p); + mobj->momy = READFIXED(save->p); + mobj->momz = READFIXED(save->p); + mobj->pmomz = READFIXED(save->p); } // otherwise they're zero, and the memset took care of it if (diff & MD_RADIUS) - mobj->radius = READFIXED(save_p); + mobj->radius = READFIXED(save->p); else mobj->radius = mobj->info->radius; if (diff & MD_HEIGHT) - mobj->height = READFIXED(save_p); + mobj->height = READFIXED(save->p); else mobj->height = mobj->info->height; if (diff & MD_FLAGS) - mobj->flags = READUINT32(save_p); + mobj->flags = READUINT32(save->p); else mobj->flags = mobj->info->flags; if (diff & MD_FLAGS2) - mobj->flags2 = READUINT32(save_p); + mobj->flags2 = READUINT32(save->p); if (diff & MD_HEALTH) - mobj->health = READINT32(save_p); + mobj->health = READINT32(save->p); else mobj->health = mobj->info->spawnhealth; if (diff & MD_RTIME) - mobj->reactiontime = READINT32(save_p); + mobj->reactiontime = READINT32(save->p); else mobj->reactiontime = mobj->info->reactiontime; if (diff & MD_STATE) - mobj->state = &states[READUINT16(save_p)]; + mobj->state = &states[READUINT16(save->p)]; else mobj->state = &states[mobj->info->spawnstate]; if (diff & MD_TICS) - mobj->tics = READINT32(save_p); + mobj->tics = READINT32(save->p); else mobj->tics = mobj->state->tics; if (diff & MD_SPRITE) - mobj->sprite = READUINT16(save_p); + mobj->sprite = READUINT16(save->p); else mobj->sprite = mobj->state->sprite; if (diff & MD_FRAME) { - mobj->frame = READUINT32(save_p); - mobj->anim_duration = READUINT16(save_p); + mobj->frame = READUINT32(save->p); + mobj->anim_duration = READUINT16(save->p); } else { @@ -2073,10 +2133,10 @@ static void LoadMobjThinker(actionf_p1 thinker) mobj->anim_duration = (UINT16)mobj->state->var2; } if (diff & MD_EFLAGS) - mobj->eflags = READUINT16(save_p); + mobj->eflags = READUINT16(save->p); if (diff & MD_PLAYER) { - i = READUINT8(save_p); + i = READUINT8(save->p); mobj->player = &players[i]; mobj->player->mo = mobj; // added for angle prediction @@ -2090,65 +2150,65 @@ static void LoadMobjThinker(actionf_p1 thinker) localangle[3] = mobj->angle; } if (diff & MD_MOVEDIR) - mobj->movedir = READANGLE(save_p); + mobj->movedir = READANGLE(save->p); if (diff & MD_MOVECOUNT) - mobj->movecount = READINT32(save_p); + mobj->movecount = READINT32(save->p); if (diff & MD_THRESHOLD) - mobj->threshold = READINT32(save_p); + mobj->threshold = READINT32(save->p); if (diff & MD_LASTLOOK) - mobj->lastlook = READINT32(save_p); + mobj->lastlook = READINT32(save->p); else mobj->lastlook = -1; if (diff & MD_TARGET) - mobj->target = (mobj_t *)(size_t)READUINT32(save_p); + mobj->target = (mobj_t *)(size_t)READUINT32(save->p); if (diff & MD_TRACER) - mobj->tracer = (mobj_t *)(size_t)READUINT32(save_p); + mobj->tracer = (mobj_t *)(size_t)READUINT32(save->p); if (diff & MD_FRICTION) - mobj->friction = READFIXED(save_p); + mobj->friction = READFIXED(save->p); else mobj->friction = ORIG_FRICTION; if (diff & MD_MOVEFACTOR) - mobj->movefactor = READFIXED(save_p); + mobj->movefactor = READFIXED(save->p); else mobj->movefactor = FRACUNIT; //mobj->movefactor = ORIG_FRICTION_FACTOR; if (diff & MD_FUSE) - mobj->fuse = READINT32(save_p); + mobj->fuse = READINT32(save->p); if (diff & MD_WATERTOP) - mobj->watertop = READFIXED(save_p); + mobj->watertop = READFIXED(save->p); if (diff & MD_WATERBOTTOM) - mobj->waterbottom = READFIXED(save_p); + mobj->waterbottom = READFIXED(save->p); if (diff & MD_SCALE) - mobj->scale = READFIXED(save_p); + mobj->scale = READFIXED(save->p); else mobj->scale = FRACUNIT; if (diff & MD_DSCALE) - mobj->destscale = READFIXED(save_p); + mobj->destscale = READFIXED(save->p); else mobj->destscale = mobj->scale; if (diff2 & MD2_SCALESPEED) - mobj->scalespeed = READFIXED(save_p); + mobj->scalespeed = READFIXED(save->p); else mobj->scalespeed = mapobjectscale/12; if (diff2 & MD2_CUSVAL) - mobj->cusval = READINT32(save_p); + mobj->cusval = READINT32(save->p); if (diff2 & MD2_CVMEM) - mobj->cvmem = READINT32(save_p); + mobj->cvmem = READINT32(save->p); if (diff2 & MD2_SKIN) - mobj->skin = &skins[READUINT8(save_p)]; + mobj->skin = &skins[READUINT16(save->p)]; if (diff2 & MD2_COLOR) - mobj->color = READUINT8(save_p); + mobj->color = READUINT8(save->p); if (diff2 & MD2_EXTVAL1) - mobj->extravalue1 = READINT32(save_p); + mobj->extravalue1 = READINT32(save->p); if (diff2 & MD2_EXTVAL2) - mobj->extravalue2 = READINT32(save_p); + mobj->extravalue2 = READINT32(save->p); if (diff2 & MD2_HNEXT) - mobj->hnext = (mobj_t *)(size_t)READUINT32(save_p); + mobj->hnext = (mobj_t *)(size_t)READUINT32(save->p); if (diff2 & MD2_HPREV) - mobj->hprev = (mobj_t *)(size_t)READUINT32(save_p); + mobj->hprev = (mobj_t *)(size_t)READUINT32(save->p); if (diff2 & MD2_SLOPE) - mobj->standingslope = P_SlopeById(READUINT16(save_p)); + mobj->standingslope = P_SlopeById(READUINT16(save->p)); if (diff2 & MD2_COLORIZED) - mobj->colorized = READUINT8(save_p); + mobj->colorized = READUINT8(save->p); //{ Saturn stuff, needs to be set, but shouldnt be synched @@ -2197,7 +2257,7 @@ static void LoadMobjThinker(actionf_p1 thinker) // set sprev, snext, bprev, bnext, subsector P_SetThingPosition(mobj); - mobj->mobjnum = READUINT32(save_p); + mobj->mobjnum = READUINT32(save->p); if (mobj->player) { @@ -2236,18 +2296,18 @@ static void LoadMobjThinker(actionf_p1 thinker) // 2 - Ceiling Only // 3 - Both // -static void LoadSpecialLevelThinker(actionf_p1 thinker, UINT8 floorOrCeiling) +static void LoadSpecialLevelThinker(savebuffer_t *save, actionf_p1 thinker, UINT8 floorOrCeiling) { levelspecthink_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); size_t i; ht->thinker.function.acp1 = thinker; for (i = 0; i < 16; i++) { - ht->vars[i] = READFIXED(save_p); //var[16] - ht->var2s[i] = READFIXED(save_p); //var[16] + ht->vars[i] = READFIXED(save->p); //var[16] + ht->var2s[i] = READFIXED(save->p); //var[16] } - ht->sourceline = LoadLine(READUINT32(save_p)); - ht->sector = LoadSector(READUINT32(save_p)); + ht->sourceline = LoadLine(READUINT32(save->p)); + ht->sector = LoadSector(READUINT32(save->p)); if (ht->sector) { @@ -2265,25 +2325,25 @@ static void LoadSpecialLevelThinker(actionf_p1 thinker, UINT8 floorOrCeiling) // // Loads a ceiling_t from a save game // -static void LoadCeilingThinker(actionf_p1 thinker) +static void LoadCeilingThinker(savebuffer_t *save, actionf_p1 thinker) { ceiling_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->type = READUINT8(save_p); - ht->sector = LoadSector(READUINT32(save_p)); - ht->bottomheight = READFIXED(save_p); - ht->topheight = READFIXED(save_p); - ht->speed = READFIXED(save_p); - ht->oldspeed = READFIXED(save_p); - ht->delay = READFIXED(save_p); - ht->delaytimer = READFIXED(save_p); - ht->crush = READUINT8(save_p); - ht->texture = READINT32(save_p); - ht->direction = READINT32(save_p); - ht->tag = READINT32(save_p); - ht->olddirection = READINT32(save_p); - ht->origspeed = READFIXED(save_p); - ht->sourceline = READFIXED(save_p); + ht->type = READUINT8(save->p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->bottomheight = READFIXED(save->p); + ht->topheight = READFIXED(save->p); + ht->speed = READFIXED(save->p); + ht->oldspeed = READFIXED(save->p); + ht->delay = READFIXED(save->p); + ht->delaytimer = READFIXED(save->p); + ht->crush = READUINT8(save->p); + ht->texture = READINT32(save->p); + ht->direction = READINT32(save->p); + ht->tag = READINT32(save->p); + ht->olddirection = READINT32(save->p); + ht->origspeed = READFIXED(save->p); + ht->sourceline = READFIXED(save->p); if (ht->sector) ht->sector->ceilingdata = ht; P_AddThinker(&ht->thinker); @@ -2294,20 +2354,20 @@ static void LoadCeilingThinker(actionf_p1 thinker) // // Loads a floormove_t from a save game // -static void LoadFloormoveThinker(actionf_p1 thinker) +static void LoadFloormoveThinker(savebuffer_t *save, actionf_p1 thinker) { floormove_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->type = READUINT8(save_p); - ht->crush = READUINT8(save_p); - ht->sector = LoadSector(READUINT32(save_p)); - ht->direction = READINT32(save_p); - ht->texture = READINT32(save_p); - ht->floordestheight = READFIXED(save_p); - ht->speed = READFIXED(save_p); - ht->origspeed = READFIXED(save_p); - ht->delay = READFIXED(save_p); - ht->delaytimer = READFIXED(save_p); + ht->type = READUINT8(save->p); + ht->crush = READUINT8(save->p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->direction = READINT32(save->p); + ht->texture = READINT32(save->p); + ht->floordestheight = READFIXED(save->p); + ht->speed = READFIXED(save->p); + ht->origspeed = READFIXED(save->p); + ht->delay = READFIXED(save->p); + ht->delaytimer = READFIXED(save->p); if (ht->sector) ht->sector->floordata = ht; P_AddThinker(&ht->thinker); @@ -2318,13 +2378,13 @@ static void LoadFloormoveThinker(actionf_p1 thinker) // // Loads a lightflash_t from a save game // -static void LoadLightflashThinker(actionf_p1 thinker) +static void LoadLightflashThinker(savebuffer_t *save, actionf_p1 thinker) { lightflash_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->maxlight = READINT32(save_p); - ht->minlight = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->maxlight = READINT32(save->p); + ht->minlight = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2335,16 +2395,16 @@ static void LoadLightflashThinker(actionf_p1 thinker) // // Loads a strobe_t from a save game // -static void LoadStrobeThinker(actionf_p1 thinker) +static void LoadStrobeThinker(savebuffer_t *save, actionf_p1 thinker) { strobe_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->count = READINT32(save_p); - ht->minlight = READINT32(save_p); - ht->maxlight = READINT32(save_p); - ht->darktime = READINT32(save_p); - ht->brighttime = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->count = READINT32(save->p); + ht->minlight = READINT32(save->p); + ht->maxlight = READINT32(save->p); + ht->darktime = READINT32(save->p); + ht->brighttime = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2355,15 +2415,15 @@ static void LoadStrobeThinker(actionf_p1 thinker) // // Loads a glow_t from a save game // -static void LoadGlowThinker(actionf_p1 thinker) +static void LoadGlowThinker(savebuffer_t *save, actionf_p1 thinker) { glow_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->minlight = READINT32(save_p); - ht->maxlight = READINT32(save_p); - ht->direction = READINT32(save_p); - ht->speed = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->minlight = READINT32(save->p); + ht->maxlight = READINT32(save->p); + ht->direction = READINT32(save->p); + ht->speed = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2374,15 +2434,15 @@ static void LoadGlowThinker(actionf_p1 thinker) // // Loads a fireflicker_t from a save game // -static void LoadFireflickerThinker(actionf_p1 thinker) +static void LoadFireflickerThinker(savebuffer_t *save, actionf_p1 thinker) { fireflicker_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->count = READINT32(save_p); - ht->resetcount = READINT32(save_p); - ht->maxlight = READINT32(save_p); - ht->minlight = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->count = READINT32(save->p); + ht->resetcount = READINT32(save->p); + ht->maxlight = READINT32(save->p); + ht->minlight = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2393,27 +2453,27 @@ static void LoadFireflickerThinker(actionf_p1 thinker) // // Loads a elevator_t from a save game // -static void LoadElevatorThinker(actionf_p1 thinker, UINT8 floorOrCeiling) +static void LoadElevatorThinker(savebuffer_t *save, actionf_p1 thinker, UINT8 floorOrCeiling) { elevator_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->type = READUINT8(save_p); - ht->sector = LoadSector(READUINT32(save_p)); - ht->actionsector = LoadSector(READUINT32(save_p)); - ht->direction = READINT32(save_p); - ht->floordestheight = READFIXED(save_p); - ht->ceilingdestheight = READFIXED(save_p); - ht->speed = READFIXED(save_p); - ht->origspeed = READFIXED(save_p); - ht->low = READFIXED(save_p); - ht->high = READFIXED(save_p); - ht->distance = READFIXED(save_p); - ht->delay = READFIXED(save_p); - ht->delaytimer = READFIXED(save_p); - ht->floorwasheight = READFIXED(save_p); - ht->ceilingwasheight = READFIXED(save_p); - ht->player = LoadPlayer(READUINT32(save_p)); // was dummy - ht->sourceline = LoadLine(READUINT32(save_p)); + ht->type = READUINT8(save->p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->actionsector = LoadSector(READUINT32(save->p)); + ht->direction = READINT32(save->p); + ht->floordestheight = READFIXED(save->p); + ht->ceilingdestheight = READFIXED(save->p); + ht->speed = READFIXED(save->p); + ht->origspeed = READFIXED(save->p); + ht->low = READFIXED(save->p); + ht->high = READFIXED(save->p); + ht->distance = READFIXED(save->p); + ht->delay = READFIXED(save->p); + ht->delaytimer = READFIXED(save->p); + ht->floorwasheight = READFIXED(save->p); + ht->ceilingwasheight = READFIXED(save->p); + ht->player = LoadPlayer(READUINT32(save->p)); // was dummy + ht->sourceline = LoadLine(READUINT32(save->p)); if (ht->sector) { @@ -2431,20 +2491,20 @@ static void LoadElevatorThinker(actionf_p1 thinker, UINT8 floorOrCeiling) // // Loads a scroll_t from a save game // -static void LoadScrollThinker(actionf_p1 thinker) +static void LoadScrollThinker(savebuffer_t *save, actionf_p1 thinker) { scroll_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->dx = READFIXED(save_p); - ht->dy = READFIXED(save_p); - ht->affectee = READINT32(save_p); - ht->control = READINT32(save_p); - ht->last_height = READFIXED(save_p); - ht->vdx = READFIXED(save_p); - ht->vdy = READFIXED(save_p); - ht->accel = READINT32(save_p); - ht->exclusive = READINT32(save_p); - ht->type = READUINT8(save_p); + ht->dx = READFIXED(save->p); + ht->dy = READFIXED(save->p); + ht->affectee = READINT32(save->p); + ht->control = READINT32(save->p); + ht->last_height = READFIXED(save->p); + ht->vdx = READFIXED(save->p); + ht->vdy = READFIXED(save->p); + ht->accel = READINT32(save->p); + ht->exclusive = READINT32(save->p); + ht->type = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2453,15 +2513,15 @@ static void LoadScrollThinker(actionf_p1 thinker) // // Loads a friction_t from a save game // -static inline void LoadFrictionThinker(actionf_p1 thinker) +static inline void LoadFrictionThinker(savebuffer_t *save, actionf_p1 thinker) { friction_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->friction = READINT32(save_p); - ht->movefactor = READINT32(save_p); - ht->affectee = READINT32(save_p); - ht->referrer = READINT32(save_p); - ht->roverfriction = READUINT8(save_p); + ht->friction = READINT32(save->p); + ht->movefactor = READINT32(save->p); + ht->affectee = READINT32(save->p); + ht->referrer = READINT32(save->p); + ht->roverfriction = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2470,23 +2530,23 @@ static inline void LoadFrictionThinker(actionf_p1 thinker) // // Loads a pusher_t from a save game // -static void LoadPusherThinker(actionf_p1 thinker) +static void LoadPusherThinker(savebuffer_t *save, actionf_p1 thinker) { pusher_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->type = READUINT8(save_p); - ht->x_mag = READINT32(save_p); - ht->y_mag = READINT32(save_p); - ht->magnitude = READINT32(save_p); - ht->radius = READINT32(save_p); - ht->x = READINT32(save_p); - ht->y = READINT32(save_p); - ht->z = READINT32(save_p); - ht->affectee = READINT32(save_p); - ht->roverpusher = READUINT8(save_p); - ht->referrer = READINT32(save_p); - ht->exclusive = READINT32(save_p); - ht->slider = READINT32(save_p); + ht->type = READUINT8(save->p); + ht->x_mag = READINT32(save->p); + ht->y_mag = READINT32(save->p); + ht->magnitude = READINT32(save->p); + ht->radius = READINT32(save->p); + ht->x = READINT32(save->p); + ht->y = READINT32(save->p); + ht->z = READINT32(save->p); + ht->affectee = READINT32(save->p); + ht->roverpusher = READUINT8(save->p); + ht->referrer = READINT32(save->p); + ht->exclusive = READINT32(save->p); + ht->slider = READINT32(save->p); ht->source = P_GetPushThing(ht->affectee); P_AddThinker(&ht->thinker); } @@ -2496,14 +2556,14 @@ static void LoadPusherThinker(actionf_p1 thinker) // // Loads a laserthink_t from a save game // -static inline void LoadLaserThinker(actionf_p1 thinker) +static inline void LoadLaserThinker(savebuffer_t *save, actionf_p1 thinker) { laserthink_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ffloor_t *rover = NULL; ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->sec = LoadSector(READUINT32(save_p)); - ht->sourceline = LoadLine(READUINT32(save_p)); + ht->sector = LoadSector(READUINT32(save->p)); + ht->sec = LoadSector(READUINT32(save->p)); + ht->sourceline = LoadLine(READUINT32(save->p)); for (rover = ht->sector->ffloors; rover; rover = rover->next) if (rover->secnum == (size_t)(ht->sec - sectors) && rover->master == ht->sourceline) @@ -2516,13 +2576,13 @@ static inline void LoadLaserThinker(actionf_p1 thinker) // // Loads a lightlevel_t from a save game // -FUNCINLINE static ATTRINLINE void LoadLightlevelThinker(actionf_p1 thinker) +FUNCINLINE static ATTRINLINE void LoadLightlevelThinker(savebuffer_t *save, actionf_p1 thinker) { lightlevel_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->sector = LoadSector(READUINT32(save_p)); - ht->destlevel = READINT32(save_p); - ht->speed = READINT32(save_p); + ht->sector = LoadSector(READUINT32(save->p)); + ht->destlevel = READINT32(save->p); + ht->speed = READINT32(save->p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); @@ -2533,14 +2593,14 @@ FUNCINLINE static ATTRINLINE void LoadLightlevelThinker(actionf_p1 thinker) // // Loads a executor_t from a save game // -static inline void LoadExecutorThinker(actionf_p1 thinker) +static inline void LoadExecutorThinker(savebuffer_t *save, actionf_p1 thinker) { executor_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->line = LoadLine(READUINT32(save_p)); - ht->caller = LoadMobj(READUINT32(save_p)); - ht->sector = LoadSector(READUINT32(save_p)); - ht->timer = READINT32(save_p); + ht->line = LoadLine(READUINT32(save->p)); + ht->caller = LoadMobj(READUINT32(save->p)); + ht->sector = LoadSector(READUINT32(save->p)); + ht->timer = READINT32(save->p); P_AddThinker(&ht->thinker); } @@ -2549,17 +2609,33 @@ static inline void LoadExecutorThinker(actionf_p1 thinker) // // Loads a disappear_t thinker // -static inline void LoadDisappearThinker(actionf_p1 thinker) +static inline void LoadDisappearThinker(savebuffer_t *save, actionf_p1 thinker) { disappear_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->appeartime = READUINT32(save_p); - ht->disappeartime = READUINT32(save_p); - ht->offset = READUINT32(save_p); - ht->timer = READUINT32(save_p); - ht->affectee = READINT32(save_p); - ht->sourceline = READINT32(save_p); - ht->exists = READINT32(save_p); + ht->appeartime = READUINT32(save->p); + ht->disappeartime = READUINT32(save->p); + ht->offset = READUINT32(save->p); + ht->timer = READUINT32(save->p); + ht->affectee = READINT32(save->p); + ht->sourceline = READINT32(save->p); + ht->exists = READINT32(save->p); + P_AddThinker(&ht->thinker); +} + +/// Save a dynamic slope thinker. +static inline void LoadDynamicSlopeThinker(savebuffer_t *save, actionf_p1 thinker) +{ + dynplanethink_t* ht = Z_Malloc(sizeof(*ht), PU_LEVSPEC, NULL); + ht->thinker.function.acp1 = thinker; + + ht->type = READUINT8(save->p); + ht->slope = LoadSlope(READUINT32(save->p)); + ht->sourceline = LoadLine(READUINT32(save->p)); + ht->extent = READFIXED(save->p); + READMEM(save->p, ht->tags, sizeof(ht->tags)); + READMEM(save->p, ht->vex, sizeof(ht->vex)); + P_AddThinker(&ht->thinker); } @@ -2569,14 +2645,14 @@ static inline void LoadDisappearThinker(actionf_p1 thinker) // // Loads a polyrotate_t thinker // -static inline void LoadPolyrotatetThinker(actionf_p1 thinker) +static inline void LoadPolyrotatetThinker(savebuffer_t *save, actionf_p1 thinker) { polyrotate_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->distance = READINT32(save_p); - ht->turnobjs = READUINT8(save_p); + ht->polyObjNum = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->distance = READINT32(save->p); + ht->turnobjs = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2585,16 +2661,16 @@ static inline void LoadPolyrotatetThinker(actionf_p1 thinker) // // Loads a polymovet_t thinker // -static void LoadPolymoveThinker(actionf_p1 thinker) +static void LoadPolymoveThinker(savebuffer_t *save, actionf_p1 thinker) { polymove_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->momx = READFIXED(save_p); - ht->momy = READFIXED(save_p); - ht->distance = READINT32(save_p); - ht->angle = READANGLE(save_p); + ht->polyObjNum = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->momx = READFIXED(save->p); + ht->momy = READFIXED(save->p); + ht->distance = READINT32(save->p); + ht->angle = READANGLE(save->p); P_AddThinker(&ht->thinker); } @@ -2603,22 +2679,23 @@ static void LoadPolymoveThinker(actionf_p1 thinker) // // Loads a polywaypoint_t thinker // -static inline void LoadPolywaypointThinker(actionf_p1 thinker) +static inline void LoadPolywaypointThinker(savebuffer_t *save, actionf_p1 thinker) { polywaypoint_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->sequence = READINT32(save_p); - ht->pointnum = READINT32(save_p); - ht->direction = READINT32(save_p); - ht->comeback = READUINT8(save_p); - ht->wrap = READUINT8(save_p); - ht->continuous = READUINT8(save_p); - ht->stophere = READUINT8(save_p); - ht->diffx = READFIXED(save_p); - ht->diffy = READFIXED(save_p); - ht->diffz = READFIXED(save_p); + ht->polyObjNum = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->sequence = READINT32(save->p); + ht->pointnum = READINT32(save->p); + ht->direction = READINT32(save->p); + ht->comeback = READUINT8(save->p); + ht->wrap = READUINT8(save->p); + ht->continuous = READUINT8(save->p); + ht->stophere = READUINT8(save->p); + ht->diffx = READFIXED(save->p); + ht->diffy = READFIXED(save->p); + ht->diffz = READFIXED(save->p); + ht->target = LoadMobj(READUINT32(save->p)); P_AddThinker(&ht->thinker); } @@ -2627,23 +2704,23 @@ static inline void LoadPolywaypointThinker(actionf_p1 thinker) // // loads a polyslidedoor_t thinker // -static inline void LoadPolyslidedoorThinker(actionf_p1 thinker) +static inline void LoadPolyslidedoorThinker(savebuffer_t *save, actionf_p1 thinker) { polyslidedoor_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->delay = READINT32(save_p); - ht->delayCount = READINT32(save_p); - ht->initSpeed = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->initDistance = READINT32(save_p); - ht->distance = READINT32(save_p); - ht->initAngle = READUINT32(save_p); - ht->angle = READUINT32(save_p); - ht->revAngle = READUINT32(save_p); - ht->momx = READFIXED(save_p); - ht->momy = READFIXED(save_p); - ht->closing = READUINT8(save_p); + ht->polyObjNum = READINT32(save->p); + ht->delay = READINT32(save->p); + ht->delayCount = READINT32(save->p); + ht->initSpeed = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->initDistance = READINT32(save->p); + ht->distance = READINT32(save->p); + ht->initAngle = READUINT32(save->p); + ht->angle = READUINT32(save->p); + ht->revAngle = READUINT32(save->p); + ht->momx = READFIXED(save->p); + ht->momy = READFIXED(save->p); + ht->closing = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2652,18 +2729,18 @@ static inline void LoadPolyslidedoorThinker(actionf_p1 thinker) // // Loads a polyswingdoor_t thinker // -static inline void LoadPolyswingdoorThinker(actionf_p1 thinker) +static inline void LoadPolyswingdoorThinker(savebuffer_t *save, actionf_p1 thinker) { polyswingdoor_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->delay = READINT32(save_p); - ht->delayCount = READINT32(save_p); - ht->initSpeed = READINT32(save_p); - ht->speed = READINT32(save_p); - ht->initDistance = READINT32(save_p); - ht->distance = READINT32(save_p); - ht->closing = READUINT8(save_p); + ht->polyObjNum = READINT32(save->p); + ht->delay = READINT32(save->p); + ht->delayCount = READINT32(save->p); + ht->initSpeed = READINT32(save->p); + ht->speed = READINT32(save->p); + ht->initDistance = READINT32(save->p); + ht->distance = READINT32(save->p); + ht->closing = READUINT8(save->p); P_AddThinker(&ht->thinker); } @@ -2672,15 +2749,15 @@ static inline void LoadPolyswingdoorThinker(actionf_p1 thinker) // // Loads a polydisplace_t thinker // -static inline void LoadPolydisplaceThinker(actionf_p1 thinker) +static inline void LoadPolydisplaceThinker(savebuffer_t *save, actionf_p1 thinker) { polydisplace_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; - ht->polyObjNum = READINT32(save_p); - ht->controlSector = LoadSector(READUINT32(save_p)); - ht->dx = READFIXED(save_p); - ht->dy = READFIXED(save_p); - ht->oldHeights = READFIXED(save_p); + ht->polyObjNum = READINT32(save->p); + ht->controlSector = LoadSector(READUINT32(save->p)); + ht->dx = READFIXED(save->p); + ht->dy = READFIXED(save->p); + ht->oldHeights = READFIXED(save->p); P_AddThinker(&ht->thinker); } @@ -2690,7 +2767,7 @@ static inline void LoadPolydisplaceThinker(actionf_p1 thinker) // // load a what_t thinker // -static inline void LoadWhatThinker(actionf_p1 thinker) +static inline void LoadWhatThinker(savebuffer_t *save, actionf_p1 thinker) { what_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); ht->thinker.function.acp1 = thinker; @@ -2700,7 +2777,7 @@ static inline void LoadWhatThinker(actionf_p1 thinker) // // P_NetUnArchiveThinkers // -static void P_NetUnArchiveThinkers(void) +static void P_NetUnArchiveThinkers(savebuffer_t *save) { thinker_t *currentthinker; thinker_t *next; @@ -2709,7 +2786,7 @@ static void P_NetUnArchiveThinkers(void) UINT32 i; UINT32 numloaded = 0; - if (READUINT32(save_p) != ARCHIVEBLOCK_THINKERS) + if (READUINT32(save->p) != ARCHIVEBLOCK_THINKERS) I_Error("Bad $$$.sav at archive block Thinkers"); // remove all the current thinkers @@ -2741,7 +2818,7 @@ static void P_NetUnArchiveThinkers(void) // read in saved thinkers for (;;) { - tclass = READUINT8(save_p); + tclass = READUINT8(save->p); if (tclass == tc_end) break; // leave the saved thinker reading loop @@ -2750,148 +2827,158 @@ static void P_NetUnArchiveThinkers(void) switch (tclass) { case tc_mobj: - LoadMobjThinker((actionf_p1)P_MobjThinker); + LoadMobjThinker(save, (actionf_p1)P_MobjThinker); break; case tc_ceiling: - LoadCeilingThinker((actionf_p1)T_MoveCeiling); + LoadCeilingThinker(save, (actionf_p1)T_MoveCeiling); break; case tc_crushceiling: - LoadCeilingThinker((actionf_p1)T_CrushCeiling); + LoadCeilingThinker(save, (actionf_p1)T_CrushCeiling); break; case tc_floor: - LoadFloormoveThinker((actionf_p1)T_MoveFloor); + LoadFloormoveThinker(save, (actionf_p1)T_MoveFloor); break; case tc_flash: - LoadLightflashThinker((actionf_p1)T_LightningFlash); + LoadLightflashThinker(save, (actionf_p1)T_LightningFlash); break; case tc_strobe: - LoadStrobeThinker((actionf_p1)T_StrobeFlash); + LoadStrobeThinker(save, (actionf_p1)T_StrobeFlash); break; case tc_glow: - LoadGlowThinker((actionf_p1)T_Glow); + LoadGlowThinker(save, (actionf_p1)T_Glow); break; case tc_fireflicker: - LoadFireflickerThinker((actionf_p1)T_FireFlicker); + LoadFireflickerThinker(save, (actionf_p1)T_FireFlicker); break; case tc_elevator: - LoadElevatorThinker((actionf_p1)T_MoveElevator, 3); + LoadElevatorThinker(save, (actionf_p1)T_MoveElevator, 3); break; case tc_continuousfalling: - LoadSpecialLevelThinker((actionf_p1)T_ContinuousFalling, 3); + LoadSpecialLevelThinker(save, (actionf_p1)T_ContinuousFalling, 3); break; case tc_thwomp: - LoadSpecialLevelThinker((actionf_p1)T_ThwompSector, 3); + LoadSpecialLevelThinker(save, (actionf_p1)T_ThwompSector, 3); break; case tc_noenemies: - LoadSpecialLevelThinker((actionf_p1)T_NoEnemiesSector, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_NoEnemiesSector, 0); break; case tc_eachtime: - LoadSpecialLevelThinker((actionf_p1)T_EachTimeThinker, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_EachTimeThinker, 0); break; case tc_raisesector: - LoadSpecialLevelThinker((actionf_p1)T_RaiseSector, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_RaiseSector, 0); break; /// \todo rewrite all the code that uses an elevator_t but isn't an elevator /// \note working on it! case tc_camerascanner: - LoadElevatorThinker((actionf_p1)T_CameraScanner, 0); + LoadElevatorThinker(save, (actionf_p1)T_CameraScanner, 0); break; case tc_bouncecheese: - LoadSpecialLevelThinker((actionf_p1)T_BounceCheese, 2); + LoadSpecialLevelThinker(save, (actionf_p1)T_BounceCheese, 2); break; case tc_startcrumble: - LoadElevatorThinker((actionf_p1)T_StartCrumble, 1); + LoadElevatorThinker(save, (actionf_p1)T_StartCrumble, 1); break; case tc_marioblock: - LoadSpecialLevelThinker((actionf_p1)T_MarioBlock, 3); + LoadSpecialLevelThinker(save, (actionf_p1)T_MarioBlock, 3); break; case tc_marioblockchecker: - LoadSpecialLevelThinker((actionf_p1)T_MarioBlockChecker, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_MarioBlockChecker, 0); break; case tc_spikesector: - LoadSpecialLevelThinker((actionf_p1)T_SpikeSector, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_SpikeSector, 0); break; case tc_floatsector: - LoadSpecialLevelThinker((actionf_p1)T_FloatSector, 0); + LoadSpecialLevelThinker(save, (actionf_p1)T_FloatSector, 0); break; case tc_bridgethinker: - LoadSpecialLevelThinker((actionf_p1)T_BridgeThinker, 3); + LoadSpecialLevelThinker(save, (actionf_p1)T_BridgeThinker, 3); break; case tc_laserflash: - LoadLaserThinker((actionf_p1)T_LaserFlash); + LoadLaserThinker(save, (actionf_p1)T_LaserFlash); break; case tc_lightfade: - LoadLightlevelThinker((actionf_p1)T_LightFade); + LoadLightlevelThinker(save, (actionf_p1)T_LightFade); break; case tc_executor: - LoadExecutorThinker((actionf_p1)T_ExecutorDelay); + LoadExecutorThinker(save, (actionf_p1)T_ExecutorDelay); restoreNum = true; break; case tc_disappear: - LoadDisappearThinker((actionf_p1)T_Disappear); + LoadDisappearThinker(save, (actionf_p1)T_Disappear); break; + + case tc_dynslopeline: + LoadDynamicSlopeThinker(save, (actionf_p1)T_DynamicSlopeLine); + break; + + case tc_dynslopevert: + LoadDynamicSlopeThinker(save, (actionf_p1)T_DynamicSlopeVert); + break; + case tc_polyrotate: - LoadPolyrotatetThinker((actionf_p1)T_PolyObjRotate); + LoadPolyrotatetThinker(save, (actionf_p1)T_PolyObjRotate); break; case tc_polymove: - LoadPolymoveThinker((actionf_p1)T_PolyObjMove); + LoadPolymoveThinker(save, (actionf_p1)T_PolyObjMove); break; case tc_polywaypoint: - LoadPolywaypointThinker((actionf_p1)T_PolyObjWaypoint); + LoadPolywaypointThinker(save, (actionf_p1)T_PolyObjWaypoint); + restoreNum = true; break; case tc_polyslidedoor: - LoadPolyslidedoorThinker((actionf_p1)T_PolyDoorSlide); + LoadPolyslidedoorThinker(save, (actionf_p1)T_PolyDoorSlide); break; case tc_polyswingdoor: - LoadPolyswingdoorThinker((actionf_p1)T_PolyDoorSwing); + LoadPolyswingdoorThinker(save, (actionf_p1)T_PolyDoorSwing); break; case tc_polyflag: - LoadPolymoveThinker((actionf_p1)T_PolyObjFlag); + LoadPolymoveThinker(save, (actionf_p1)T_PolyObjFlag); break; case tc_polydisplace: - LoadPolydisplaceThinker((actionf_p1)T_PolyObjDisplace); + LoadPolydisplaceThinker(save, (actionf_p1)T_PolyObjDisplace); break; case tc_scroll: - LoadScrollThinker((actionf_p1)T_Scroll); + LoadScrollThinker(save, (actionf_p1)T_Scroll); break; case tc_friction: - LoadFrictionThinker((actionf_p1)T_Friction); + LoadFrictionThinker(save, (actionf_p1)T_Friction); break; case tc_pusher: - LoadPusherThinker((actionf_p1)T_Pusher); + LoadPusherThinker(save, (actionf_p1)T_Pusher); break; default: @@ -2904,17 +2991,27 @@ static void P_NetUnArchiveThinkers(void) if (restoreNum) { executor_t *delay = NULL; + polywaypoint_t *polywp = NULL; UINT32 mobjnum; for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay) + if (currentthinker->function.acp1 == (actionf_p1)T_ExecutorDelay) + { + delay = (void *)currentthinker; + if ((mobjnum = (UINT32)(size_t)delay->caller)) + delay->caller = P_FindNewPosition(mobjnum); + } + } + for (currentthinker = thinkercap.next; currentthinker != &thinkercap; + currentthinker = currentthinker->next) + { + if (currentthinker->function.acp1 != (actionf_p1)T_PolyObjWaypoint) continue; - - delay = (void *)currentthinker; - - if ((mobjnum = (UINT32)(size_t)delay->caller)) - delay->caller = P_FindNewPosition(mobjnum); + polywp = (void *)currentthinker; + if (!(mobjnum = (UINT32)(size_t)polywp->target)) + continue; + polywp->target = P_FindNewPosition(mobjnum); } } } @@ -2926,29 +3023,29 @@ static void P_NetUnArchiveThinkers(void) #define PD_FLAGS 0x01 #define PD_TRANS 0x02 -static inline void P_ArchivePolyObj(polyobj_t *po) +static inline void P_ArchivePolyObj(savebuffer_t *save, polyobj_t *po) { UINT8 diff = 0; - WRITEINT32(save_p, po->id); - WRITEANGLE(save_p, po->angle); + WRITEINT32(save->p, po->id); + WRITEANGLE(save->p, po->angle); - WRITEFIXED(save_p, po->spawnSpot.x); - WRITEFIXED(save_p, po->spawnSpot.y); + WRITEFIXED(save->p, po->spawnSpot.x); + WRITEFIXED(save->p, po->spawnSpot.y); if (po->flags != po->spawnflags) diff |= PD_FLAGS; if (po->translucency != 0) diff |= PD_TRANS; - WRITEUINT8(save_p, diff); + WRITEUINT8(save->p, diff); if (diff & PD_FLAGS) - WRITEINT32(save_p, po->flags); + WRITEINT32(save->p, po->flags); if (diff & PD_TRANS) - WRITEINT32(save_p, po->translucency); + WRITEINT32(save->p, po->translucency); } -static inline void P_UnArchivePolyObj(polyobj_t *po) +static inline void P_UnArchivePolyObj(savebuffer_t *save, polyobj_t *po) { INT32 id; UINT32 angle; @@ -2960,19 +3057,19 @@ static inline void P_UnArchivePolyObj(polyobj_t *po) // when they first start to run. po->thinker = NULL; - id = READINT32(save_p); + id = READINT32(save->p); - angle = READANGLE(save_p); + angle = READANGLE(save->p); - x = READFIXED(save_p); - y = READFIXED(save_p); + x = READFIXED(save->p); + y = READFIXED(save->p); - diff = READUINT8(save_p); + diff = READUINT8(save->p); if (diff & PD_FLAGS) - po->flags = READINT32(save_p); + po->flags = READINT32(save->p); if (diff & PD_TRANS) - po->translucency = READINT32(save_p); + po->translucency = READINT32(save->p); // if the object is bad or isn't in the id hash, we can do nothing more // with it, so return now @@ -2983,33 +3080,33 @@ static inline void P_UnArchivePolyObj(polyobj_t *po) Polyobj_MoveOnLoad(po, angle, x, y); } -static inline void P_ArchivePolyObjects(void) +static inline void P_ArchivePolyObjects(savebuffer_t *save) { INT32 i; - WRITEUINT32(save_p, ARCHIVEBLOCK_POBJS); + WRITEUINT32(save->p, ARCHIVEBLOCK_POBJS); // save number of polyobjects - WRITEINT32(save_p, numPolyObjects); + WRITEINT32(save->p, numPolyObjects); for (i = 0; i < numPolyObjects; ++i) - P_ArchivePolyObj(&PolyObjects[i]); + P_ArchivePolyObj(save, &PolyObjects[i]); } -static inline void P_UnArchivePolyObjects(void) +static inline void P_UnArchivePolyObjects(savebuffer_t *save) { INT32 i, numSavedPolys; - if (READUINT32(save_p) != ARCHIVEBLOCK_POBJS) + if (READUINT32(save->p) != ARCHIVEBLOCK_POBJS) I_Error("Bad $$$.sav at archive block Pobjs"); - numSavedPolys = READINT32(save_p); + numSavedPolys = READINT32(save->p); if (numSavedPolys != numPolyObjects) I_Error("P_UnArchivePolyObjects: polyobj count inconsistency\n"); for (i = 0; i < numSavedPolys; ++i) - P_UnArchivePolyObj(&PolyObjects[i]); + P_UnArchivePolyObj(save, &PolyObjects[i]); } // // P_FinishMobjs @@ -3023,11 +3120,11 @@ static inline void P_FinishMobjs(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mobj = (mobj_t *)currentthinker; - mobj->info = &mobjinfo[mobj->type]; + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)currentthinker; + mobj->info = &mobjinfo[mobj->type]; + } } } @@ -3041,69 +3138,69 @@ static void P_RelinkPointers(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) - continue; + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)currentthinker; - mobj = (mobj_t *)currentthinker; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - - if (mobj->tracer) - { - temp = (UINT32)(size_t)mobj->tracer; - mobj->tracer = NULL; - if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); - } - if (mobj->target) - { - temp = (UINT32)(size_t)mobj->target; - mobj->target = NULL; - if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); - } - if (mobj->hnext) - { - temp = (UINT32)(size_t)mobj->hnext; - mobj->hnext = NULL; - if (!P_SetTarget(&mobj->hnext, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); - } - if (mobj->hprev) - { - temp = (UINT32)(size_t)mobj->hprev; - mobj->hprev = NULL; - if (!P_SetTarget(&mobj->hprev, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->capsule) - { - temp = (UINT32)(size_t)mobj->player->capsule; - mobj->player->capsule = NULL; - if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis1) - { - temp = (UINT32)(size_t)mobj->player->axis1; - mobj->player->axis1 = NULL; - if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis2) - { - temp = (UINT32)(size_t)mobj->player->axis2; - mobj->player->axis2 = NULL; - if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->awayviewmobj) - { - temp = (UINT32)(size_t)mobj->player->awayviewmobj; - mobj->player->awayviewmobj = NULL; - if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); + if (mobj->tracer) + { + temp = (UINT32)(size_t)mobj->tracer; + mobj->tracer = NULL; + if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); + } + if (mobj->target) + { + temp = (UINT32)(size_t)mobj->target; + mobj->target = NULL; + if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); + } + if (mobj->hnext) + { + temp = (UINT32)(size_t)mobj->hnext; + mobj->hnext = NULL; + if (!P_SetTarget(&mobj->hnext, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); + } + if (mobj->hprev) + { + temp = (UINT32)(size_t)mobj->hprev; + mobj->hprev = NULL; + if (!P_SetTarget(&mobj->hprev, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->capsule) + { + temp = (UINT32)(size_t)mobj->player->capsule; + mobj->player->capsule = NULL; + if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis1) + { + temp = (UINT32)(size_t)mobj->player->axis1; + mobj->player->axis1 = NULL; + if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis2) + { + temp = (UINT32)(size_t)mobj->player->axis2; + mobj->player->axis2 = NULL; + if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->awayviewmobj) + { + temp = (UINT32)(size_t)mobj->player->awayviewmobj; + mobj->player->awayviewmobj = NULL; + if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); + } } } } @@ -3111,11 +3208,11 @@ static void P_RelinkPointers(void) // // P_NetArchiveSpecials // -static inline void P_NetArchiveSpecials(void) +static inline void P_NetArchiveSpecials(savebuffer_t *save) { size_t i, z; - WRITEUINT32(save_p, ARCHIVEBLOCK_SPECIALS); + WRITEUINT32(save->p, ARCHIVEBLOCK_SPECIALS); // itemrespawn queue for deathmatch i = iquetail; @@ -3125,56 +3222,56 @@ static inline void P_NetArchiveSpecials(void) { if (&mapthings[z] == itemrespawnque[i]) { - WRITEUINT32(save_p, z); + WRITEUINT32(save->p, z); break; } } - WRITEUINT32(save_p, itemrespawntime[i]); + WRITEUINT32(save->p, itemrespawntime[i]); i = (i + 1) & (ITEMQUESIZE-1); } // end delimiter - WRITEUINT32(save_p, 0xffffffff); + WRITEUINT32(save->p, 0xffffffff); // Sky number - WRITEINT32(save_p, globallevelskynum); + WRITEINT32(save->p, globallevelskynum); // Current global weather type - WRITEUINT8(save_p, globalweather); + WRITEUINT8(save->p, globalweather); if (metalplayback) // Is metal sonic running? { - WRITEUINT8(save_p, 0x01); - G_SaveMetal(&save_p); + WRITEUINT8(save->p, 0x01); + G_SaveMetal(&save->p); } else - WRITEUINT8(save_p, 0x00); + WRITEUINT8(save->p, 0x00); } // // P_NetUnArchiveSpecials // -static void P_NetUnArchiveSpecials(void) +static void P_NetUnArchiveSpecials(savebuffer_t *save) { size_t i; INT32 j; - if (READUINT32(save_p) != ARCHIVEBLOCK_SPECIALS) + if (READUINT32(save->p) != ARCHIVEBLOCK_SPECIALS) I_Error("Bad $$$.sav at archive block Specials"); // BP: added save itemrespawn queue for deathmatch iquetail = iquehead = 0; - while ((i = READUINT32(save_p)) != 0xffffffff) + while ((i = READUINT32(save->p)) != 0xffffffff) { itemrespawnque[iquehead] = &mapthings[i]; - itemrespawntime[iquehead++] = READINT32(save_p); + itemrespawntime[iquehead++] = READINT32(save->p); } - j = READINT32(save_p); + j = READINT32(save->p); if (j != globallevelskynum) P_SetupLevelSky(j, true); - globalweather = READUINT8(save_p); + globalweather = READUINT8(save->p); if (globalweather) { @@ -3189,31 +3286,31 @@ static void P_NetUnArchiveSpecials(void) P_SwitchWeather(globalweather); } - if (READUINT8(save_p) == 0x01) // metal sonic - G_LoadMetal(&save_p); + if (READUINT8(save->p) == 0x01) // metal sonic + G_LoadMetal(&save->p); } // ======================================================================= // Misc // ======================================================================= -static inline void P_ArchiveMisc(void) +static inline void P_ArchiveMisc(savebuffer_t *save) { if (gamecomplete) - WRITEINT16(save_p, gamemap | 8192); + WRITEINT16(save->p, gamemap | 8192); else - WRITEINT16(save_p, gamemap); + WRITEINT16(save->p, gamemap); lastmapsaved = gamemap; - WRITEUINT16(save_p, (botskin ? (emeralds|(1<<10)) : emeralds)+357); - WRITESTRINGN(save_p, timeattackfolder, sizeof(timeattackfolder)); + WRITEUINT16(save->p, (botskin ? (emeralds|(1<<10)) : emeralds)+357); + WRITESTRINGN(save->p, timeattackfolder, sizeof(timeattackfolder)); } -static inline void P_UnArchiveSPGame(INT16 mapoverride) +static inline void P_UnArchiveSPGame(savebuffer_t *save, INT16 mapoverride) { char testname[sizeof(timeattackfolder)]; - gamemap = READINT16(save_p); + gamemap = READINT16(save->p); if (mapoverride != 0) { @@ -3233,12 +3330,12 @@ static inline void P_UnArchiveSPGame(INT16 mapoverride) tokenlist = 0; token = 0; - savedata.emeralds = READUINT16(save_p)-357; + savedata.emeralds = READUINT16(save->p)-357; if (savedata.emeralds & (1<<10)) savedata.botcolor = 0xFF; savedata.emeralds &= 0xff; - READSTRINGN(save_p, testname, sizeof(testname)); + READSTRINGN(save->p, testname, sizeof(testname)); if (strcmp(testname, timeattackfolder)) { @@ -3252,120 +3349,117 @@ static inline void P_UnArchiveSPGame(INT16 mapoverride) playeringame[consoleplayer] = true; } -static void P_NetArchiveMisc(boolean resending) +static void P_NetArchiveMisc(savebuffer_t *save, boolean resending) { UINT32 pig = 0; INT32 i; - WRITEUINT32(save_p, ARCHIVEBLOCK_MISC); + WRITEUINT32(save->p, ARCHIVEBLOCK_MISC); if (resending) - WRITEUINT32(save_p, gametic); - - WRITEINT16(save_p, gamemap); + WRITEUINT32(save->p, gametic); + WRITEINT16(save->p, gamemap); if (gamestate != GS_LEVEL) - WRITEINT16(save_p, GS_WAITINGPLAYERS); // nice hack to put people back into waitingplayers + WRITEINT16(save->p, GS_WAITINGPLAYERS); // nice hack to put people back into waitingplayers else - WRITEINT16(save_p, gamestate); + WRITEINT16(save->p, gamestate); - if (resending) - WRITEINT16(save_p, gametype); + WRITEINT16(save->p, gametype); for (i = 0; i < MAXPLAYERS; i++) pig |= (playeringame[i] != 0)<p, pig); - WRITEUINT32(save_p, P_GetRandSeed()); + WRITEUINT32(save->p, P_GetRandSeed()); - WRITEUINT32(save_p, tokenlist); + WRITEUINT32(save->p, tokenlist); - WRITEUINT8(save_p, encoremode); + WRITEUINT8(save->p, encoremode); - WRITEUINT32(save_p, leveltime); - WRITEUINT32(save_p, totalrings); - WRITEINT16(save_p, lastmap); + WRITEUINT32(save->p, leveltime); + WRITEUINT32(save->p, totalrings); + WRITEINT16(save->p, lastmap); - for (i = 0; i < 4; i++) + for (i = 0; i < 12; i++) { - WRITEINT16(save_p, votelevels[i][0]); - WRITEINT16(save_p, votelevels[i][1]); + WRITEINT16(save->p, votelevels[i][0]); + WRITEINT16(save->p, votelevels[i][1]); } for (i = 0; i < MAXPLAYERS; i++) - WRITESINT8(save_p, votes[i]); + WRITESINT8(save->p, votes[i]); - WRITESINT8(save_p, pickedvote); + WRITESINT8(save->p, pickedvote); - WRITEUINT16(save_p, emeralds); - WRITEUINT8(save_p, stagefailed); + WRITEUINT16(save->p, emeralds); + WRITEUINT8(save->p, stagefailed); - WRITEUINT32(save_p, token); - WRITEINT32(save_p, sstimer); - WRITEUINT32(save_p, bluescore); - WRITEUINT32(save_p, redscore); + WRITEUINT32(save->p, token); + WRITEINT32(save->p, sstimer); + WRITEUINT32(save->p, bluescore); + WRITEUINT32(save->p, redscore); - WRITEINT16(save_p, autobalance); - WRITEINT16(save_p, teamscramble); + WRITEINT16(save->p, autobalance); + WRITEINT16(save->p, teamscramble); for (i = 0; i < MAXPLAYERS; i++) - WRITEINT16(save_p, scrambleplayers[i]); + WRITEINT16(save->p, scrambleplayers[i]); for (i = 0; i < MAXPLAYERS; i++) - WRITEINT16(save_p, scrambleteams[i]); + WRITEINT16(save->p, scrambleteams[i]); - WRITEINT16(save_p, scrambletotal); - WRITEINT16(save_p, scramblecount); + WRITEINT16(save->p, scrambletotal); + WRITEINT16(save->p, scramblecount); - WRITEUINT32(save_p, racecountdown); - WRITEUINT32(save_p, exitcountdown); + WRITEUINT32(save->p, racecountdown); + WRITEUINT32(save->p, exitcountdown); - WRITEFIXED(save_p, gravity); - WRITEFIXED(save_p, mapobjectscale); + WRITEFIXED(save->p, gravity); + WRITEFIXED(save->p, mapobjectscale); - WRITEUINT32(save_p, countdowntimer); - WRITEUINT8(save_p, countdowntimeup); + WRITEUINT32(save->p, countdowntimer); + WRITEUINT8(save->p, countdowntimeup); - WRITEUINT32(save_p, hidetime); + WRITEUINT32(save->p, hidetime); // SRB2kart - WRITEINT32(save_p, numgotboxes); + WRITEINT32(save->p, numgotboxes); - WRITEUINT8(save_p, gamespeed); - WRITEUINT8(save_p, franticitems); - WRITEUINT8(save_p, comeback); + WRITEUINT8(save->p, gamespeed); + WRITEUINT8(save->p, franticitems); + WRITEUINT8(save->p, comeback); for (i = 0; i < 4; i++) - WRITESINT8(save_p, battlewanted[i]); + WRITESINT8(save->p, battlewanted[i]); - WRITEUINT32(save_p, wantedcalcdelay); - WRITEUINT32(save_p, indirectitemcooldown); - WRITEUINT32(save_p, hyubgone); - WRITEUINT32(save_p, mapreset); - WRITEUINT8(save_p, nospectategrief); - WRITEUINT8(save_p, thwompsactive); - WRITESINT8(save_p, spbplace); - WRITEUINT8(save_p, startedInFreePlay); + WRITEUINT32(save->p, wantedcalcdelay); + WRITEUINT32(save->p, indirectitemcooldown); + WRITEUINT32(save->p, hyubgone); + WRITEUINT32(save->p, mapreset); + WRITEUINT8(save->p, nospectategrief); + WRITEUINT8(save->p, thwompsactive); + WRITESINT8(save->p, spbplace); + WRITEUINT8(save->p, startedInFreePlay); // Is it paused? if (paused) - WRITEUINT8(save_p, 0x2f); + WRITEUINT8(save->p, 0x2f); else - WRITEUINT8(save_p, 0x2e); + WRITEUINT8(save->p, 0x2e); } -FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(boolean reloading) +FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(savebuffer_t *save, boolean reloading) { UINT32 pig; INT32 i; - UINT8 *old_save_p; - if (READUINT32(save_p) != ARCHIVEBLOCK_MISC) + if (READUINT32(save->p) != ARCHIVEBLOCK_MISC) I_Error("Bad $$$.sav at archive block Misc"); if (reloading) - gametic = READUINT32(save_p); + gametic = READUINT32(save->p); - gamemap = READINT16(save_p); + gamemap = READINT16(save->p); // gamemap changed; we assume that its map header is always valid, // so make it so @@ -3377,26 +3471,22 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(boolean reloading) if (!reloading) mapmusflags |= MUSIC_RELOADRESET; - G_SetGamestate(READINT16(save_p)); + G_SetGamestate(READINT16(save->p)); - if (reloading) - gametype = READINT16(save_p); + gametype = READINT16(save->p); - pig = READUINT32(save_p); + pig = READUINT32(save->p); for (i = 0; i < MAXPLAYERS; i++) { playeringame[i] = (pig & (1<p)); - tokenlist = READUINT32(save_p); + tokenlist = READUINT32(save->p); - encoremode = (boolean)READUINT8(save_p); - - // FIXME: save_p should not be global!!! - old_save_p = save_p; + encoremode = (boolean)READUINT8(save->p); if (!P_SetupLevel(true, reloading)) { @@ -3404,129 +3494,126 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(boolean reloading) return false; } - save_p = old_save_p; - // get the time - leveltime = READUINT32(save_p); - totalrings = READUINT32(save_p); - lastmap = READINT16(save_p); + leveltime = READUINT32(save->p); + totalrings = READUINT32(save->p); + lastmap = READINT16(save->p); - for (i = 0; i < 4; i++) + for (i = 0; i < 12; i++) { - votelevels[i][0] = READINT16(save_p); - votelevels[i][1] = READINT16(save_p); + votelevels[i][0] = READINT16(save->p); + votelevels[i][1] = READINT16(save->p); } for (i = 0; i < MAXPLAYERS; i++) - votes[i] = READSINT8(save_p); + votes[i] = READSINT8(save->p); - pickedvote = READSINT8(save_p); + pickedvote = READSINT8(save->p); - emeralds = READUINT16(save_p); - stagefailed = READUINT8(save_p); + emeralds = READUINT16(save->p); + stagefailed = READUINT8(save->p); - token = READUINT32(save_p); - sstimer = READINT32(save_p); - bluescore = READUINT32(save_p); - redscore = READUINT32(save_p); + token = READUINT32(save->p); + sstimer = READINT32(save->p); + bluescore = READUINT32(save->p); + redscore = READUINT32(save->p); - autobalance = READINT16(save_p); - teamscramble = READINT16(save_p); + autobalance = READINT16(save->p); + teamscramble = READINT16(save->p); for (i = 0; i < MAXPLAYERS; i++) - scrambleplayers[i] = READINT16(save_p); + scrambleplayers[i] = READINT16(save->p); for (i = 0; i < MAXPLAYERS; i++) - scrambleteams[i] = READINT16(save_p); + scrambleteams[i] = READINT16(save->p); - scrambletotal = READINT16(save_p); - scramblecount = READINT16(save_p); + scrambletotal = READINT16(save->p); + scramblecount = READINT16(save->p); - racecountdown = READUINT32(save_p); - exitcountdown = READUINT32(save_p); + racecountdown = READUINT32(save->p); + exitcountdown = READUINT32(save->p); - gravity = READFIXED(save_p); - mapobjectscale = READFIXED(save_p); + gravity = READFIXED(save->p); + mapobjectscale = READFIXED(save->p); - countdowntimer = (tic_t)READUINT32(save_p); - countdowntimeup = (boolean)READUINT8(save_p); + countdowntimer = (tic_t)READUINT32(save->p); + countdowntimeup = (boolean)READUINT8(save->p); - hidetime = READUINT32(save_p); + hidetime = READUINT32(save->p); // SRB2kart - numgotboxes = READINT32(save_p); + numgotboxes = READINT32(save->p); - gamespeed = READUINT8(save_p); - franticitems = (boolean)READUINT8(save_p); - comeback = (boolean)READUINT8(save_p); + gamespeed = READUINT8(save->p); + franticitems = (boolean)READUINT8(save->p); + comeback = (boolean)READUINT8(save->p); for (i = 0; i < 4; i++) - battlewanted[i] = READSINT8(save_p); + battlewanted[i] = READSINT8(save->p); - wantedcalcdelay = READUINT32(save_p); - indirectitemcooldown = READUINT32(save_p); - hyubgone = READUINT32(save_p); - mapreset = READUINT32(save_p); - nospectategrief = READUINT8(save_p); - thwompsactive = (boolean)READUINT8(save_p); - spbplace = READSINT8(save_p); - startedInFreePlay = READUINT8(save_p); + wantedcalcdelay = READUINT32(save->p); + indirectitemcooldown = READUINT32(save->p); + hyubgone = READUINT32(save->p); + mapreset = READUINT32(save->p); + nospectategrief = READUINT8(save->p); + thwompsactive = (boolean)READUINT8(save->p); + spbplace = READSINT8(save->p); + startedInFreePlay = READUINT8(save->p); // Is it paused? - if (READUINT8(save_p) == 0x2f) + if (READUINT8(save->p) == 0x2f) paused = true; return true; } -void P_SaveGame(void) +void P_SaveGame(savebuffer_t *save) { - P_ArchiveMisc(); - P_ArchivePlayer(); + P_ArchiveMisc(save); + P_ArchivePlayer(save); - WRITEUINT8(save_p, 0x1d); // consistency marker + WRITEUINT8(save->p, 0x1d); // consistency marker } -void P_SaveNetGame(boolean resending) +void P_SaveNetGame(savebuffer_t *save, boolean resending) { thinker_t *th; mobj_t *mobj; INT32 i = 1; // don't start from 0, it'd be confused with a blank pointer otherwise - CV_SaveNetVars(&save_p, false); - P_NetArchiveMisc(resending); + CV_SaveNetVars(&save->p, false); + P_NetArchiveMisc(save, resending); // Assign the mobjnumber for pointer tracking if (gamestate == GS_LEVEL) { for (th = thinkercap.next; th != &thinkercap; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mobj = (mobj_t *)th; - - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - - mobj->mobjnum = i++; + if (th->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)th; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; + mobj->mobjnum = i++; + } } } - P_NetArchivePlayers(resending); + P_NetArchivePlayers(save); if (gamestate == GS_LEVEL) { - P_NetArchiveWorld(); - P_ArchivePolyObjects(); - P_NetArchiveThinkers(); - P_NetArchiveSpecials(); + P_NetArchiveWorld(save); + P_ArchivePolyObjects(save); + P_NetArchiveThinkers(save); + P_NetArchiveSpecials(save); + P_NetArchiveWaypoints(save); } - LUA_Archive(); - WRITEUINT8(save_p, 0x1d); // consistency marker + LUA_Archive(&save->p, true); + WRITEUINT8(save->p, 0x1d); // consistency marker } -boolean P_LoadGame(INT16 mapoverride) +boolean P_LoadGame(savebuffer_t *save, INT16 mapoverride) { if (gamestate == GS_INTERMISSION) Y_EndIntermission(); @@ -3534,11 +3621,11 @@ boolean P_LoadGame(INT16 mapoverride) Y_EndVote(); G_SetGamestate(GS_NULL); // should be changed in P_UnArchiveMisc - P_UnArchiveSPGame(mapoverride); - P_UnArchivePlayer(); + P_UnArchiveSPGame(save, mapoverride); + P_UnArchivePlayer(save); // Savegame end marker - if (READUINT8(save_p) != 0x1d) + if (READUINT8(save->p) != 0x1d) return false; // Only do this after confirming savegame is ok @@ -3548,23 +3635,27 @@ boolean P_LoadGame(INT16 mapoverride) return true; } -boolean P_LoadNetGame(boolean resending) +boolean P_LoadNetGame(savebuffer_t *save, boolean reloading) { - CV_LoadNetVars(&save_p); - if (!P_NetUnArchiveMisc(resending)) + CV_LoadNetVars(&save->p); + + if (!P_NetUnArchiveMisc(save, reloading)) return false; - P_NetUnArchivePlayers(resending); + + P_NetUnArchivePlayers(save); + if (gamestate == GS_LEVEL) { - P_NetUnArchiveWorld(); - P_UnArchivePolyObjects(); - P_NetUnArchiveThinkers(); - P_NetUnArchiveSpecials(); + P_NetUnArchiveWorld(save); + P_UnArchivePolyObjects(save); + P_NetUnArchiveThinkers(save); + P_NetUnArchiveSpecials(save); + P_NetUnArchiveWaypoints(save); P_RelinkPointers(); P_FinishMobjs(); } - LUA_UnArchive(); + LUA_UnArchive(&save->p, true); // This is stupid and hacky, but maybe it'll work! P_SetRandSeed(P_GetInitSeed()); @@ -3575,5 +3666,5 @@ boolean P_LoadNetGame(boolean resending) // precipitation when loading a netgame save. Instead, precip has to be spawned here. // This is done in P_NetUnArchiveSpecials now. - return READUINT8(save_p) == 0x1d; + return READUINT8(save->p) == 0x1d; } diff --git a/src/p_saveg.h b/src/p_saveg.h index 9e73ad8fc..9a0e26c39 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -21,13 +21,6 @@ // Persistent storage/archiving. // These are the load / save game routines. -void P_SaveGame(void); -void P_SaveNetGame(boolean resending); -boolean P_LoadGame(INT16 mapoverride); -boolean P_LoadNetGame(boolean resending); - -mobj_t *P_FindNewPosition(UINT32 oldposition); - typedef struct { UINT8 skincolor; @@ -41,6 +34,21 @@ typedef struct } savedata_t; extern savedata_t savedata; -extern UINT8 *save_p; + +typedef struct +{ + UINT8 *buffer; + UINT8 *p; +} savebuffer_t; + +// Persistent storage/archiving. +// These are the load / save game routines. + +void P_SaveGame(savebuffer_t *save); +void P_SaveNetGame(savebuffer_t *save, boolean resending); +boolean P_LoadGame(savebuffer_t *save, INT16 mapoverride); +boolean P_LoadNetGame(savebuffer_t *save, boolean reloading); + +mobj_t *P_FindNewPosition(UINT32 oldposition); #endif diff --git a/src/p_setup.c b/src/p_setup.c index 671ba92ac..3ad668cd2 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -997,14 +997,14 @@ void P_WriteThings(lumpnum_t lumpnum) size_t i, length; mapthing_t *mt; UINT8 *data; - UINT8 *savebuffer, *savebuf_p; + savebuffer_t save; INT16 temp; data = W_CacheLumpNum(lumpnum, PU_LEVEL); - savebuf_p = savebuffer = (UINT8 *)malloc(nummapthings * sizeof (mapthing_t)); + save.p = save.buffer = (UINT8 *)malloc(nummapthings * sizeof (mapthing_t)); - if (!savebuf_p) + if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for thing writing!\n")); return; @@ -1013,23 +1013,23 @@ void P_WriteThings(lumpnum_t lumpnum) mt = mapthings; for (i = 0; i < nummapthings; i++, mt++) { - WRITEINT16(savebuf_p, mt->x); - WRITEINT16(savebuf_p, mt->y); + WRITEINT16(save.p, mt->x); + WRITEINT16(save.p, mt->y); - WRITEINT16(savebuf_p, mt->angle); + WRITEINT16(save.p, mt->angle); temp = (INT16)(mt->type + ((INT16)mt->extrainfo << 12)); - WRITEINT16(savebuf_p, temp); - WRITEUINT16(savebuf_p, mt->options); + WRITEINT16(save.p, temp); + WRITEUINT16(save.p, mt->options); } Z_Free(data); - length = savebuf_p - savebuffer; + length = save.p - save.buffer; - FIL_WriteFile(va("newthings%d.lmp", gamemap), savebuffer, length); - free(savebuffer); - savebuf_p = NULL; + FIL_WriteFile(va("newthings%d.lmp", gamemap), save.buffer, length); + free(save.buffer); + save.p = NULL; CONS_Printf(M_GetText("newthings%d.lmp saved.\n"), gamemap); }