From 8f19dc12d824efe540554423c6703dc4e916b491 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers <coelckers@users.noreply.github.com> Date: Thu, 11 Nov 2021 23:28:28 +0100 Subject: [PATCH] - SW: code/data pointer saving cleanup. * a large number of code pointer records were removed because none of these functions ever gets assigned to a pointer * instead of looking up entries by index, do it by name. This is far less fragile and will survive deeper refactoring. The old storage by table index will break as soon as a single entry gets removed. Since the old savegames got broken due to this problem recently it was a good time to change the setup. --- source/core/version.h | 4 +- source/games/sw/src/actor.cpp | 16 ----- source/games/sw/src/ai.cpp | 17 ----- source/games/sw/src/bunny.cpp | 5 -- source/games/sw/src/coolg.cpp | 4 -- source/games/sw/src/coolie.cpp | 2 - source/games/sw/src/eel.cpp | 3 - source/games/sw/src/girlninj.cpp | 1 - source/games/sw/src/goro.cpp | 1 - source/games/sw/src/hornet.cpp | 1 - source/games/sw/src/lava.cpp | 1 - source/games/sw/src/miscactr.cpp | 12 ---- source/games/sw/src/morph.cpp | 6 -- source/games/sw/src/ninja.cpp | 2 - source/games/sw/src/player.cpp | 5 -- source/games/sw/src/quake.cpp | 29 -------- source/games/sw/src/ripper.cpp | 5 -- source/games/sw/src/ripper2.cpp | 2 - source/games/sw/src/rotator.cpp | 10 --- source/games/sw/src/save.cpp | 30 ++------ source/games/sw/src/saveable.cpp | 72 ++++++++----------- source/games/sw/src/saveable.h | 21 +++--- source/games/sw/src/sector.cpp | 42 ------------ source/games/sw/src/serp.cpp | 1 - source/games/sw/src/skel.cpp | 1 - source/games/sw/src/skull.cpp | 2 - source/games/sw/src/slidor.cpp | 11 --- source/games/sw/src/spike.cpp | 10 --- source/games/sw/src/sprite.cpp | 14 ---- source/games/sw/src/sumo.cpp | 2 - source/games/sw/src/track.cpp | 3 - source/games/sw/src/vator.cpp | 10 --- source/games/sw/src/weapon.cpp | 114 ------------------------------- source/games/sw/src/zilla.cpp | 1 - source/games/sw/src/zombie.cpp | 3 - 35 files changed, 50 insertions(+), 413 deletions(-) diff --git a/source/core/version.h b/source/core/version.h index 3f5abfddf..1ab4f4fcc 100644 --- a/source/core/version.h +++ b/source/core/version.h @@ -71,12 +71,12 @@ const char *GetVersionString(); #define MINSAVEVER_DN3D 10 #define MINSAVEVER_BLD 11 -#define MINSAVEVER_SW 12 +#define MINSAVEVER_SW 13 #define MINSAVEVER_PS 15 #define SAVEVER_DN3D 11 #define SAVEVER_BLD 11 -#define SAVEVER_SW 12 +#define SAVEVER_SW 13 #define SAVEVER_PS 15 #define OLD_SAVEGAME 1 // this is to keep writing out the old format in Blood, even when data has been refactored. diff --git a/source/games/sw/src/actor.cpp b/source/games/sw/src/actor.cpp index 732a7568a..124b908c5 100644 --- a/source/games/sw/src/actor.cpp +++ b/source/games/sw/src/actor.cpp @@ -1003,26 +1003,10 @@ DoFall(short SpriteNum) static saveable_code saveable_actor_code[] = { - SAVE_CODE(DoScaleSprite), - SAVE_CODE(DoActorDie), - SAVE_CODE(DoDebrisCurrent), - SAVE_CODE(DoActorSectorDamage), SAVE_CODE(DoActorDebris), SAVE_CODE(DoFireFly), SAVE_CODE(DoGenerateSewerDebris), - SAVE_CODE(KeepActorOnFloor), - SAVE_CODE(DoActorBeginSlide), - SAVE_CODE(DoActorSlide), - SAVE_CODE(DoActorBeginJump), - SAVE_CODE(DoActorJump), - SAVE_CODE(DoActorBeginFall), - SAVE_CODE(DoActorFall), - SAVE_CODE(DoActorStopFall), SAVE_CODE(DoActorDeathMove), - SAVE_CODE(DoBeginJump), - SAVE_CODE(DoJump), - SAVE_CODE(DoBeginFall), - SAVE_CODE(DoFall) }; saveable_module saveable_actor = diff --git a/source/games/sw/src/ai.cpp b/source/games/sw/src/ai.cpp index 362692bc6..fcd5121e9 100644 --- a/source/games/sw/src/ai.cpp +++ b/source/games/sw/src/ai.cpp @@ -2129,20 +2129,6 @@ DoActorPause(DSWActor* actor) static saveable_code saveable_ai_code[] = { - SAVE_CODE(DebugMoveHit), - SAVE_CODE(ActorMoveHitReact), - SAVE_CODE(ActorFlaming), - SAVE_CODE(DoActorSetSpeed), - SAVE_CODE(ChooseAction), - SAVE_CODE(ChooseActionNumber), - SAVE_CODE(DoActorNoise), - SAVE_CODE(CanSeePlayer), - SAVE_CODE(CanHitPlayer), - SAVE_CODE(DoActorPickClosePlayer), - SAVE_CODE(GetPlayerSpriteNum), - SAVE_CODE(CloseRangeDist), - SAVE_CODE(DoActorOperate), - SAVE_CODE(DoActorActionDecide), SAVE_CODE(InitActorDecide), SAVE_CODE(DoActorDecide), SAVE_CODE(InitActorAlertNoise), @@ -2157,7 +2143,6 @@ static saveable_code saveable_ai_code[] = SAVE_CODE(InitActorExtra5Noise), SAVE_CODE(InitActorExtra6Noise), SAVE_CODE(InitActorMoveCloser), - SAVE_CODE(DoActorCantMoveCloser), SAVE_CODE(DoActorMoveCloser), SAVE_CODE(FindTrackToPlayer), SAVE_CODE(FindTrackAwayFromPlayer), @@ -2172,10 +2157,8 @@ static saveable_code saveable_ai_code[] = SAVE_CODE(InitActorDuck), SAVE_CODE(DoActorDuck), SAVE_CODE(DoActorMoveJump), - SAVE_CODE(FindNewAngle), SAVE_CODE(InitActorReposition), SAVE_CODE(DoActorReposition), - SAVE_CODE(InitActorPause), SAVE_CODE(DoActorPause) }; diff --git a/source/games/sw/src/bunny.cpp b/source/games/sw/src/bunny.cpp index dc5988ae3..a729c60a7 100644 --- a/source/games/sw/src/bunny.cpp +++ b/source/games/sw/src/bunny.cpp @@ -1549,9 +1549,6 @@ DoBunnyGrowUp(DSWActor* actor) static saveable_code saveable_bunny_code[] = { - SAVE_CODE(SetupBunny), - SAVE_CODE(GetBunnyJumpHeight), - SAVE_CODE(PickBunnyJumpSpeed), SAVE_CODE(DoBunnyBeginJumpAttack), SAVE_CODE(DoBunnyMoveJump), SAVE_CODE(DoPickCloseBunny), @@ -1560,8 +1557,6 @@ static saveable_code saveable_bunny_code[] = SAVE_CODE(DoBunnyPain), SAVE_CODE(DoBunnyRipHeart), SAVE_CODE(DoBunnyStandKill), - SAVE_CODE(BunnyHatch), - SAVE_CODE(BunnyHatch2), SAVE_CODE(DoBunnyMove), SAVE_CODE(BunnySpew), SAVE_CODE(DoBunnyEat), diff --git a/source/games/sw/src/coolg.cpp b/source/games/sw/src/coolg.cpp index 6a0a35913..8b9c36d84 100644 --- a/source/games/sw/src/coolg.cpp +++ b/source/games/sw/src/coolg.cpp @@ -935,12 +935,8 @@ int DoCoolgPain(DSWActor* actor) static saveable_code saveable_coolg_code[] = { - SAVE_CODE(CoolgCommon), - SAVE_CODE(SetupCoolg), - SAVE_CODE(NewCoolg), SAVE_CODE(DoCoolgBirth), SAVE_CODE(NullCoolg), - SAVE_CODE(DoCoolgMatchPlayerZ), SAVE_CODE(InitCoolgCircle), SAVE_CODE(DoCoolgCircle), SAVE_CODE(DoCoolgDeath), diff --git a/source/games/sw/src/coolie.cpp b/source/games/sw/src/coolie.cpp index a5ff9cc12..9c3dec0d7 100644 --- a/source/games/sw/src/coolie.cpp +++ b/source/games/sw/src/coolie.cpp @@ -681,8 +681,6 @@ DoCoolieWaitBirth(DSWActor* actor) static saveable_code saveable_coolie_code[] = { - SAVE_CODE(EnemyDefaults), - SAVE_CODE(SetupCoolie), SAVE_CODE(SpawnCoolg), SAVE_CODE(CooliePain), SAVE_CODE(NullCoolie), diff --git a/source/games/sw/src/eel.cpp b/source/games/sw/src/eel.cpp index 7cb09a75f..5f6d73e03 100644 --- a/source/games/sw/src/eel.cpp +++ b/source/games/sw/src/eel.cpp @@ -602,9 +602,6 @@ int DoEelMove(DSWActor* actor) static saveable_code saveable_eel_code[] = { - SAVE_CODE(EelCommon), - SAVE_CODE(SetupEel), - //SAVE_CODE(NewEel), SAVE_CODE(DoEelMatchPlayerZ), SAVE_CODE(DoEelDeath), SAVE_CODE(DoEelMove) diff --git a/source/games/sw/src/girlninj.cpp b/source/games/sw/src/girlninj.cpp index 2890277e7..402d09460 100644 --- a/source/games/sw/src/girlninj.cpp +++ b/source/games/sw/src/girlninj.cpp @@ -868,7 +868,6 @@ int DoGirlNinjaSpecial(DSWActor* actor) static saveable_code saveable_girlninj_code[] = { - SAVE_CODE(SetupGirlNinja), SAVE_CODE(DoGirlNinjaMove), SAVE_CODE(GirlNinjaJumpActionFunc), SAVE_CODE(NullGirlNinja), diff --git a/source/games/sw/src/goro.cpp b/source/games/sw/src/goro.cpp index be9fcfb04..61a4f4d31 100644 --- a/source/games/sw/src/goro.cpp +++ b/source/games/sw/src/goro.cpp @@ -564,7 +564,6 @@ int DoGoroMove(DSWActor* actor) static saveable_code saveable_goro_code[] = { - SAVE_CODE(SetupGoro), SAVE_CODE(NullGoro), SAVE_CODE(DoGoroPain), SAVE_CODE(DoGoroMove), diff --git a/source/games/sw/src/hornet.cpp b/source/games/sw/src/hornet.cpp index 39fc0798a..69bca3a19 100644 --- a/source/games/sw/src/hornet.cpp +++ b/source/games/sw/src/hornet.cpp @@ -634,7 +634,6 @@ int DoHornetMove(DSWActor* actor) static saveable_code saveable_hornet_code[] = { - SAVE_CODE(SetupHornet), SAVE_CODE(NullHornet), SAVE_CODE(DoHornetMatchPlayerZ), SAVE_CODE(InitHornetCircle), diff --git a/source/games/sw/src/lava.cpp b/source/games/sw/src/lava.cpp index 3eed80540..d6651a87a 100644 --- a/source/games/sw/src/lava.cpp +++ b/source/games/sw/src/lava.cpp @@ -523,7 +523,6 @@ int DoLavaMove(DSWActor* actor) static saveable_code saveable_lava_code[] = { - SAVE_CODE(SetupLava), SAVE_CODE(NullLava), SAVE_CODE(DoLavaMove), }; diff --git a/source/games/sw/src/miscactr.cpp b/source/games/sw/src/miscactr.cpp index 4424bf52d..8d694f070 100644 --- a/source/games/sw/src/miscactr.cpp +++ b/source/games/sw/src/miscactr.cpp @@ -2073,51 +2073,39 @@ int PruneGirlPain(DSWActor* actor) static saveable_code saveable_miscactr_code[] = { - SAVE_CODE(SetupToiletGirl), SAVE_CODE(DoToiletGirl), SAVE_CODE(NullToiletGirl), SAVE_CODE(ToiletGirlUzi), SAVE_CODE(ToiletGirlPain), - SAVE_CODE(SetupWashGirl), SAVE_CODE(DoWashGirl), SAVE_CODE(NullWashGirl), SAVE_CODE(WashGirlUzi), SAVE_CODE(WashGirlPain), - SAVE_CODE(SetupTrashCan), SAVE_CODE(DoTrashCan), SAVE_CODE(TrashCanPain), - SAVE_CODE(SetupPachinkoLight), SAVE_CODE(PachinkoLightOperate), - SAVE_CODE(SetupPachinko1), - SAVE_CODE(SetupPachinko2), - SAVE_CODE(SetupPachinko3), - SAVE_CODE(SetupPachinko4), SAVE_CODE(PachinkoCheckWin), SAVE_CODE(Pachinko1Operate), - SAVE_CODE(SetupCarGirl), SAVE_CODE(DoCarGirl), SAVE_CODE(NullCarGirl), SAVE_CODE(CarGirlUzi), SAVE_CODE(CarGirlPain), - SAVE_CODE(SetupMechanicGirl), SAVE_CODE(DoMechanicGirl), SAVE_CODE(NullMechanicGirl), SAVE_CODE(MechanicGirlDrill), SAVE_CODE(MechanicGirlPain), - SAVE_CODE(SetupSailorGirl), SAVE_CODE(DoSailorGirl), SAVE_CODE(NullSailorGirl), SAVE_CODE(SailorGirlThrow), SAVE_CODE(SailorGirlPain), - SAVE_CODE(SetupPruneGirl), SAVE_CODE(DoPruneGirl), SAVE_CODE(NullPruneGirl), SAVE_CODE(PruneGirlUzi), diff --git a/source/games/sw/src/morph.cpp b/source/games/sw/src/morph.cpp index 4a6ab5585..f24265855 100644 --- a/source/games/sw/src/morph.cpp +++ b/source/games/sw/src/morph.cpp @@ -568,15 +568,9 @@ SpikeFloor(SECTOR_OBJECTp sop) static saveable_code saveable_morph_code[] = { - SAVE_CODE(DoSectorObjectSetScale), - SAVE_CODE(DoSOevent), SAVE_CODE(ScaleSectorObject), - SAVE_CODE(ScaleRandomPoint), SAVE_CODE(MorphTornado), SAVE_CODE(MorphFloor), - SAVE_CODE(SOBJ_AlignFloorToPoint), - SAVE_CODE(SOBJ_AlignCeilingToPoint), - SAVE_CODE(SOBJ_AlignFloorCeilingToPoint), SAVE_CODE(SpikeFloor), }; diff --git a/source/games/sw/src/ninja.cpp b/source/games/sw/src/ninja.cpp index 7f995e632..4e6ce93ed 100644 --- a/source/games/sw/src/ninja.cpp +++ b/source/games/sw/src/ninja.cpp @@ -2511,8 +2511,6 @@ SpawnPlayerUnderSprite(PLAYERp pp) static saveable_code saveable_ninja_code[] = { - SAVE_CODE(SetupNinja), - SAVE_CODE(SetupNinja), SAVE_CODE(DoNinjaHariKari), SAVE_CODE(DoNinjaGrabThroat), SAVE_CODE(DoNinjaMove), diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 62a781f4c..6aebb6688 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -7532,8 +7532,6 @@ void CheckFootPrints(PLAYERp pp) static saveable_code saveable_player_code[] = { SAVE_CODE(DoPlayerSlide), - //SAVE_CODE(DoPlayerBeginSwim), - //SAVE_CODE(DoPlayerSwim), SAVE_CODE(DoPlayerWade), SAVE_CODE(DoPlayerBeginWade), SAVE_CODE(DoPlayerBeginCrawl), @@ -7550,11 +7548,8 @@ static saveable_code saveable_player_code[] = SAVE_CODE(DoPlayerBeginClimb), SAVE_CODE(DoPlayerClimb), SAVE_CODE(DoPlayerBeginDie), - //SAVE_CODE(DoPlayerDie), - //SAVE_CODE(DoPlayerBeginOperateBoat), SAVE_CODE(DoPlayerBeginOperateVehicle), SAVE_CODE(DoPlayerBeginOperate), - //SAVE_CODE(DoPlayerOperateBoat), SAVE_CODE(DoPlayerOperateVehicle), SAVE_CODE(DoPlayerOperateTurret), SAVE_CODE(DoPlayerBeginDive), diff --git a/source/games/sw/src/quake.cpp b/source/games/sw/src/quake.cpp index a6561147a..c7e631d6e 100644 --- a/source/games/sw/src/quake.cpp +++ b/source/games/sw/src/quake.cpp @@ -342,33 +342,4 @@ SetSumoFartQuake(int16_t SpriteNum) } -#include "saveable.h" - -static saveable_code saveable_quake_code[] = -{ - SAVE_CODE(CopyQuakeSpotToOn), - SAVE_CODE(DoQuakeMatch), - SAVE_CODE(ProcessQuakeOn), - SAVE_CODE(ProcessQuakeSpot), - SAVE_CODE(QuakeViewChange), - SAVE_CODE(SpawnQuake), - SAVE_CODE(SetQuake), - SAVE_CODE(SetExpQuake), - SAVE_CODE(SetGunQuake), - SAVE_CODE(SetPlayerQuake), - SAVE_CODE(SetNuclearQuake), - SAVE_CODE(SetSumoQuake), - SAVE_CODE(SetSumoFartQuake), -}; - -saveable_module saveable_quake = -{ - // code - saveable_quake_code, - SIZ(saveable_quake_code), - - // data - nullptr,0 -}; - END_SW_NS diff --git a/source/games/sw/src/ripper.cpp b/source/games/sw/src/ripper.cpp index 59238382f..684eacb4a 100644 --- a/source/games/sw/src/ripper.cpp +++ b/source/games/sw/src/ripper.cpp @@ -1333,10 +1333,6 @@ DoRipperMove(DSWActor* actor) static saveable_code saveable_ripper_code[] = { - SAVE_CODE(SetupRipper), - SAVE_CODE(GetJumpHeight), - SAVE_CODE(PickJumpSpeed), - SAVE_CODE(PickJumpMaxSpeed), SAVE_CODE(InitRipperHang), SAVE_CODE(DoRipperHang), @@ -1351,7 +1347,6 @@ static saveable_code saveable_ripper_code[] = SAVE_CODE(DoRipperPain), SAVE_CODE(DoRipperRipHeart), SAVE_CODE(DoRipperStandHeart), - SAVE_CODE(RipperHatch), SAVE_CODE(DoRipperMove), }; diff --git a/source/games/sw/src/ripper2.cpp b/source/games/sw/src/ripper2.cpp index 159a00ab6..25740829d 100644 --- a/source/games/sw/src/ripper2.cpp +++ b/source/games/sw/src/ripper2.cpp @@ -1377,8 +1377,6 @@ int ChestRipper2(DSWActor* actor) static saveable_code saveable_ripper2_code[] = { - SAVE_CODE(SetupRipper2), - SAVE_CODE(InitRipper2Hang), SAVE_CODE(DoRipper2Hang), SAVE_CODE(DoRipper2MoveHang), diff --git a/source/games/sw/src/rotator.cpp b/source/games/sw/src/rotator.cpp index 4cefdab2a..407d56701 100644 --- a/source/games/sw/src/rotator.cpp +++ b/source/games/sw/src/rotator.cpp @@ -448,16 +448,6 @@ int DoRotator(DSWActor* actor) static saveable_code saveable_rotator_code[] = { - SAVE_CODE(ReverseRotator), - SAVE_CODE(RotatorSwitch), - SAVE_CODE(SetRotatorActive), - SAVE_CODE(SetRotatorInactive), - SAVE_CODE(DoRotatorOperate), - SAVE_CODE(DoRotatorMatch), - SAVE_CODE(TestRotatorMatchActive), - SAVE_CODE(DoRotatorSetInterp), - SAVE_CODE(DoRotatorStopInterp), - SAVE_CODE(DoRotatorMove), SAVE_CODE(DoRotator) }; diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index 0b2b1b5be..7ff3308de 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -96,19 +96,8 @@ extern STATE s_NotRestored[]; FSerializer& Serialize(FSerializer& arc, const char* keyname, savedcodesym& w, savedcodesym* def) { - static savedcodesym nul; - if (!def) - { - def = &nul; - if (arc.isReading()) w = {}; - } - - if (arc.BeginObject(keyname)) - { - arc("module", w.module, def->module) - ("index", w.index, def->index) - .EndObject(); - } + if (arc.isWriting() && w.name.IsEmpty()) return arc; + arc(keyname, w.name); return arc; } @@ -120,18 +109,11 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, savedcodesym& w, s FSerializer& Serialize(FSerializer& arc, const char* keyname, saveddatasym& w, saveddatasym* def) { - static saveddatasym nul; - if (!def) + if (arc.isWriting() && w.name.IsEmpty()) return arc; + if (arc.BeginObject(keyname)) { - def = &nul; - if (arc.isReading()) w = {}; - } - - if (arc.BeginObject(keyname)) - { - arc("module", w.module, def->module) - ("index", w.index, def->index) - ("offset", w.offset, def->offset) + arc("name", w.name) + ("offset", w.offset) .EndObject(); } return arc; diff --git a/source/games/sw/src/saveable.cpp b/source/games/sw/src/saveable.cpp index f1fd29147..f2284a054 100644 --- a/source/games/sw/src/saveable.cpp +++ b/source/games/sw/src/saveable.cpp @@ -58,7 +58,6 @@ void Saveable_Init(void) MODULE(ninja) MODULE(panel) MODULE(player) - MODULE(quake) MODULE(ripper) MODULE(ripper2) MODULE(rotator) @@ -85,8 +84,7 @@ int Saveable_FindCodeSym(void *ptr, savedcodesym *sym) if (!ptr) { - sym->module = 0; // module 0 is the "null module" for null pointers - sym->index = 0; + sym->name = ""; return 0; } @@ -94,11 +92,9 @@ int Saveable_FindCodeSym(void *ptr, savedcodesym *sym) { for (i=0; i<saveablemodules[m]->numcode; i++) { - if (ptr != saveablemodules[m]->code[i]) continue; - - sym->module = 1+m; - sym->index = i; + if (ptr != saveablemodules[m]->code[i].base) continue; + sym->name = saveablemodules[m]->code[i].name; return 0; } } @@ -113,8 +109,7 @@ int Saveable_FindDataSym(void *ptr, saveddatasym *sym) if (!ptr) { - sym->module = 0; - sym->index = 0; + sym->name = ""; sym->offset = 0; return 0; } @@ -127,8 +122,7 @@ int Saveable_FindDataSym(void *ptr, saveddatasym *sym) if (ptr >= (void *)((intptr_t)saveablemodules[m]->data[i].base + saveablemodules[m]->data[i].size)) continue; - sym->module = 1+m; - sym->index = i; + sym->name = saveablemodules[m]->data[i].name; sym->offset = unsigned((intptr_t)ptr - (intptr_t)saveablemodules[m]->data[i].base); return 0; @@ -141,54 +135,48 @@ int Saveable_FindDataSym(void *ptr, saveddatasym *sym) int Saveable_RestoreCodeSym(savedcodesym *sym, void **ptr) { - if (sym->module == 0) + if (sym->name.IsEmpty()) { *ptr = nullptr; return 0; } - if (sym->module > saveablemodules.Size()) + for (auto module : saveablemodules) { - debug_break(); - return -1; + for (unsigned i = 0; i < module->numcode; i++) + { + if (sym->name.Compare(module->code[i].name) == 0) + { + *ptr = module->code[i].base; + return 0; + } + } } - if (sym->index >= saveablemodules[sym->module-1]->numcode) - { - debug_break(); - return -1; - } - - *ptr = saveablemodules[sym->module-1]->code[sym->index]; - - return 0; + I_Error("Unknown code reference '%s' in savegame\n", sym->name.GetChars()); + return -1; } int Saveable_RestoreDataSym(saveddatasym *sym, void **ptr) { - if (sym->module == 0) + if (sym->name.IsEmpty()) { *ptr = nullptr; return 0; } - if (sym->module > saveablemodules.Size()) + for (auto module : saveablemodules) { - debug_break(); - return -1; + for (unsigned i = 0; i < module->numdata; i++) + { + if (sym->name.Compare(module->data[i].name) == 0) + { + *ptr = ((uint8_t*)module->data[i].base) + sym->offset; + return 0; + } + } } - if (sym->index >= saveablemodules[sym->module-1]->numdata) - { - debug_break(); - return -1; - } - if (sym->offset >= saveablemodules[sym->module-1]->data[sym->index].size) - { - debug_break(); - return -1; - } - - *ptr = (void *)((intptr_t)saveablemodules[sym->module-1]->data[sym->index].base + sym->offset); - - return 0; + I_Error("Unknown data reference '%s' in savegame\n", sym->name.GetChars()); + return -1; } + END_SW_NS diff --git a/source/games/sw/src/saveable.h b/source/games/sw/src/saveable.h index 8d5940fad..18f5b9643 100644 --- a/source/games/sw/src/saveable.h +++ b/source/games/sw/src/saveable.h @@ -26,13 +26,18 @@ #include "compat.h" -typedef void *saveable_code; +struct saveable_code +{ + void* base; + const char* name; +}; -typedef struct +struct saveable_data { void *base; + const char* name; unsigned int size; -} saveable_data; +}; typedef struct { @@ -49,21 +54,19 @@ constexpr std::enable_if_t<!std::is_pointer<T>::value, size_t> SAVE_SIZEOF(T con return sizeof(obj); } -#define SAVE_CODE(s) (void*)(s) -#define SAVE_DATA(s) { (void*)&(s), (int)SAVE_SIZEOF(s) } +#define SAVE_CODE(s) { (void*)(s), #s } +#define SAVE_DATA(s) { (void*)&(s), #s, (int)SAVE_SIZEOF(s) } #define NUM_SAVEABLE_ITEMS(x) countof(x) typedef struct { - unsigned int module; - unsigned int index; + FString name; } savedcodesym; typedef struct { - unsigned int module; - unsigned int index; + FString name; unsigned int offset; } saveddatasym; diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 3e4b261b2..6d3f29fef 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -3334,49 +3334,7 @@ int inside(int x, int y, short sectnum) static saveable_code saveable_sector_code[] = { - SAVE_CODE(WallSetupDontMove), - SAVE_CODE(WallSetup), - SAVE_CODE(SectorLiquidSet), - SAVE_CODE(SectorSetup), - SAVE_CODE(DoSpringBoard), - SAVE_CODE(DoSpringBoardDown), - SAVE_CODE(DoSpawnActorTrigger), - SAVE_CODE(OperateSector), - SAVE_CODE(OperateWall), - SAVE_CODE(AnimateSwitch), - SAVE_CODE(SectorExp), - SAVE_CODE(DoExplodeSector), SAVE_CODE(DoSpawnSpot), - SAVE_CODE(DoSpawnSpotsForKill), - SAVE_CODE(DoSpawnSpotsForDamage), - SAVE_CODE(DoSoundSpotMatch), - SAVE_CODE(DoSoundSpotStopSound), - SAVE_CODE(DoStopSoundSpotMatch), - SAVE_CODE(DoSectorObjectKillMatch), - SAVE_CODE(DoDeleteSpriteMatch), - SAVE_CODE(DoChangorMatch), - SAVE_CODE(DoMatchEverything), - SAVE_CODE(DoTrapReset), - SAVE_CODE(DoTrapMatch), - SAVE_CODE(OperateTripTrigger), - SAVE_CODE(OperateContinuousTrigger), - SAVE_CODE(PlayerTakeSectorDamage), - SAVE_CODE(NearThings), - SAVE_CODE(NearTagList), - SAVE_CODE(BuildNearTagList), - SAVE_CODE(DoPlayerGrabStar), - SAVE_CODE(PlayerOperateEnv), - SAVE_CODE(DoSineWaveFloor), - SAVE_CODE(DoSineWaveWall), - SAVE_CODE(DoAnim), - SAVE_CODE(AnimClear), - SAVE_CODE(AnimGetGoal), - SAVE_CODE(AnimDelete), - SAVE_CODE(AnimSet), - SAVE_CODE(AnimSetCallback), - SAVE_CODE(AnimSetVelAdj), - SAVE_CODE(DoPanning), - SAVE_CODE(DoSector), }; saveable_module saveable_sector = diff --git a/source/games/sw/src/serp.cpp b/source/games/sw/src/serp.cpp index e91222013..017fbe382 100644 --- a/source/games/sw/src/serp.cpp +++ b/source/games/sw/src/serp.cpp @@ -833,7 +833,6 @@ int DoDeathSpecial(DSWActor* actor) static saveable_code saveable_serp_code[] = { - SAVE_CODE(SetupSerp), SAVE_CODE(NullSerp), SAVE_CODE(DoSerpMove), SAVE_CODE(DoDeathSpecial), diff --git a/source/games/sw/src/skel.cpp b/source/games/sw/src/skel.cpp index 5cfc04b76..283df6d72 100644 --- a/source/games/sw/src/skel.cpp +++ b/source/games/sw/src/skel.cpp @@ -643,7 +643,6 @@ int DoSkelMove(DSWActor* actor) static saveable_code saveable_skel_code[] = { - SAVE_CODE(SetupSkel), SAVE_CODE(DoSkelInitTeleport), SAVE_CODE(DoSkelTeleport), SAVE_CODE(DoSkelTermTeleport), diff --git a/source/games/sw/src/skull.cpp b/source/games/sw/src/skull.cpp index b16f017ae..98965fe15 100644 --- a/source/games/sw/src/skull.cpp +++ b/source/games/sw/src/skull.cpp @@ -930,7 +930,6 @@ int DoBettyWait(DSWActor* actor) static saveable_code saveable_skull_code[] = { - SAVE_CODE(SetupSkull), SAVE_CODE(DoSkullMove), SAVE_CODE(DoSkullBeginDeath), SAVE_CODE(DoSkullJump), @@ -938,7 +937,6 @@ static saveable_code saveable_skull_code[] = SAVE_CODE(DoSkullSpawnShrap), SAVE_CODE(DoSkullWait), - SAVE_CODE(SetupBetty), SAVE_CODE(DoBettyMove), SAVE_CODE(DoBettyBeginDeath), SAVE_CODE(DoBettyJump), diff --git a/source/games/sw/src/slidor.cpp b/source/games/sw/src/slidor.cpp index 331950e00..56f5759fa 100644 --- a/source/games/sw/src/slidor.cpp +++ b/source/games/sw/src/slidor.cpp @@ -696,17 +696,6 @@ int DoSlidor(DSWActor* actor) static saveable_code saveable_slidor_code[] = { - SAVE_CODE(ReverseSlidor), - SAVE_CODE(SlidorSwitch), - SAVE_CODE(SetSlidorActive), - SAVE_CODE(SetSlidorInactive), - SAVE_CODE(DoSlidorOperate), - SAVE_CODE(DoSlidorMatch), - SAVE_CODE(TestSlidorMatchActive), - SAVE_CODE(DoSlidorInterp), - SAVE_CODE(DoSlidorMoveWalls), - SAVE_CODE(DoSlidorInstantClose), - SAVE_CODE(DoSlidorMove), SAVE_CODE(DoSlidor), }; diff --git a/source/games/sw/src/spike.cpp b/source/games/sw/src/spike.cpp index f6b00bbd8..50f24e3b5 100644 --- a/source/games/sw/src/spike.cpp +++ b/source/games/sw/src/spike.cpp @@ -493,16 +493,6 @@ int DoSpikeAuto(DSWActor* actor) static saveable_code saveable_spike_code[] = { - SAVE_CODE(ReverseSpike), - SAVE_CODE(SpikeSwitch), - SAVE_CODE(SetSpikeActive), - SAVE_CODE(SetSpikeInactive), - SAVE_CODE(DoSpikeOperate), - SAVE_CODE(DoSpikeMatch), - SAVE_CODE(TestSpikeMatchActive), - SAVE_CODE(DoSpikeMove), - SAVE_CODE(SpikeAlign), - SAVE_CODE(MoveSpritesWithSpike), SAVE_CODE(DoSpike), SAVE_CODE(DoSpikeAuto), }; diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index f5ee95c23..724240f77 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -7400,24 +7400,10 @@ move_ground_missile(short spritenum, int xchange, int ychange, int ceildist, int static saveable_code saveable_sprite_code[] = { - SAVE_CODE(DoActorZrange), - SAVE_CODE(DoActorGlobZ), - SAVE_CODE(DoStayOnFloor), SAVE_CODE(DoGrating), - SAVE_CODE(move_ground_missile), // dead entries, kept for savegame compatibility. - SAVE_CODE(move_ground_missile), SAVE_CODE(DoKey), SAVE_CODE(DoCoin), - SAVE_CODE(KillGet), - SAVE_CODE(KillGetAmmo), - SAVE_CODE(KillGetWeapon), - SAVE_CODE(DoSpawnItemTeleporterEffect), SAVE_CODE(DoGet), - SAVE_CODE(SetEnemyActive), - SAVE_CODE(SetEnemyInactive), - SAVE_CODE(ProcessActiveVars), - SAVE_CODE(StateControl), - SAVE_CODE(SpriteControl), }; static saveable_data saveable_sprite_data[] = diff --git a/source/games/sw/src/sumo.cpp b/source/games/sw/src/sumo.cpp index fff81c6e1..da5e20cd4 100644 --- a/source/games/sw/src/sumo.cpp +++ b/source/games/sw/src/sumo.cpp @@ -972,10 +972,8 @@ BossHealthMeter(void) static saveable_code saveable_sumo_code[] = { - SAVE_CODE(SetupSumo), SAVE_CODE(NullSumo), SAVE_CODE(DoSumoMove), - //SAVE_CODE(InitSumoCharge), SAVE_CODE(DoSumoRumble), SAVE_CODE(InitSumoFart), SAVE_CODE(InitSumoStomp), diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index bd86d993c..4acba88e3 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -3799,11 +3799,8 @@ ActorFollowTrack(short SpriteNum, short locktics) static saveable_code saveable_track_code[] = { - SAVE_CODE(DoTrack), SAVE_CODE(DoTornadoObject), SAVE_CODE(DoAutoTurretObject), - SAVE_CODE(DoActorHitTrackEndPoint), - SAVE_CODE(CallbackSOsink), }; saveable_module saveable_track = diff --git a/source/games/sw/src/vator.cpp b/source/games/sw/src/vator.cpp index 2ee3b88ff..75bf26cf4 100644 --- a/source/games/sw/src/vator.cpp +++ b/source/games/sw/src/vator.cpp @@ -682,16 +682,6 @@ int DoVatorAuto(DSWActor* actor) static saveable_code saveable_vator_code[] = { - SAVE_CODE(ReverseVator), - SAVE_CODE(VatorSwitch), - SAVE_CODE(SetVatorActive), - SAVE_CODE(SetVatorInactive), - SAVE_CODE(DoVatorOperate), - SAVE_CODE(DoVatorMatch), - SAVE_CODE(TestVatorMatchActive), - SAVE_CODE(InterpSectorSprites), - SAVE_CODE(MoveSpritesWithSector), - SAVE_CODE(DoVatorMove), SAVE_CODE(DoVator), SAVE_CODE(DoVatorAuto), }; diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 9071ef089..640a1cb14 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -21362,67 +21362,32 @@ int QueueLoWangs(short SpriteNum) static saveable_code saveable_weapon_code[] = { - SAVE_CODE(MissileHitMatch), SAVE_CODE(SpawnShrapX), SAVE_CODE(DoLavaErupt), - SAVE_CODE(QueueLoWangs), // dead entry, for savegame compatibility. - SAVE_CODE(SpawnShrap), - SAVE_CODE(DoShrapMove), - SAVE_CODE(DoVomit), SAVE_CODE(DoVomit), SAVE_CODE(DoVomitSplash), SAVE_CODE(DoFastShrapJumpFall), SAVE_CODE(DoTracerShrap), SAVE_CODE(DoShrapJumpFall), SAVE_CODE(DoShrapDamage), - SAVE_CODE(SpawnBlood), - SAVE_CODE(VehicleMoveHit), - SAVE_CODE(WeaponMoveHit), SAVE_CODE(DoUziSmoke), SAVE_CODE(DoShotgunSmoke), SAVE_CODE(DoMineSpark), SAVE_CODE(DoFireballFlames), SAVE_CODE(DoBreakFlames), - SAVE_CODE(SetSuicide), SAVE_CODE(DoActorScale), SAVE_CODE(DoRipperGrow), - SAVE_CODE(ActorChooseDeath), - SAVE_CODE(ActorHealth), - SAVE_CODE(SopDamage), - SAVE_CODE(SopCheckKill), - SAVE_CODE(ActorPain), - SAVE_CODE(ActorPainPlasma), - SAVE_CODE(ActorStdMissile), - SAVE_CODE(ActorDamageSlide), - SAVE_CODE(PlayerDamageSlide), - SAVE_CODE(GetDamage), - SAVE_CODE(RadiusGetDamage), - SAVE_CODE(PlayerCheckDeath), - SAVE_CODE(PlayerTakeDamage), - SAVE_CODE(StarBlood), - SAVE_CODE(DoDamage), SAVE_CODE(DoDamageTest), - SAVE_CODE(DoHitscanDamage), - SAVE_CODE(DoFlamesDamageTest), SAVE_CODE(DoStar), SAVE_CODE(DoCrossBolt), SAVE_CODE(DoPlasmaDone), - SAVE_CODE(MissileSeek), - SAVE_CODE(ComboMissileSeek), - SAVE_CODE(VectorMissileSeek), - SAVE_CODE(VectorWormSeek), - SAVE_CODE(DoBlurExtend), - SAVE_CODE(InitPlasmaFountain), SAVE_CODE(DoPlasmaFountain), SAVE_CODE(DoPlasma), SAVE_CODE(DoCoolgFire), SAVE_CODE(DoEelFire), SAVE_CODE(DoGrenade), SAVE_CODE(DoVulcanBoulder), - SAVE_CODE(OwnerIsPlayer), - SAVE_CODE(DoMineRangeTest), SAVE_CODE(DoMineStuck), - SAVE_CODE(SetMineStuck), SAVE_CODE(DoMine), SAVE_CODE(DoPuff), SAVE_CODE(DoRailPuff), @@ -21447,26 +21412,9 @@ static saveable_code saveable_weapon_code[] = SAVE_CODE(DoElectro), SAVE_CODE(DoLavaBoulder), SAVE_CODE(DoSpear), - SAVE_CODE(SpawnBasicExp), - SAVE_CODE(SpawnFireballFlames), - SAVE_CODE(SpawnBreakFlames), - SAVE_CODE(SpawnBreakStaticFlames), - SAVE_CODE(SpawnFireballExp), - SAVE_CODE(SpawnGoroFireballExp), - SAVE_CODE(SpawnBoltExp), - SAVE_CODE(SpawnBunnyExp), - SAVE_CODE(SpawnTankShellExp), - SAVE_CODE(SpawnNuclearSecondaryExp), - SAVE_CODE(SpawnNuclearExp), - SAVE_CODE(SpawnTracerExp), - SAVE_CODE(SpawnMicroExp), - SAVE_CODE(AddSpriteToSectorObject), - SAVE_CODE(SpawnBigGunFlames), - SAVE_CODE(SpawnGrenadeSecondaryExp), SAVE_CODE(SpawnGrenadeSmallExp), SAVE_CODE(SpawnGrenadeExp), SAVE_CODE(SpawnMineExp), - SAVE_CODE(QueueLoWangs), // dead entry, for savegame compatibility. SAVE_CODE(DoSectorExp), SAVE_CODE(SpawnSectorExp), SAVE_CODE(SpawnLargeExp), @@ -21477,22 +21425,17 @@ static saveable_code saveable_weapon_code[] = SAVE_CODE(DoFindGroundPoint), SAVE_CODE(DoNapalm), SAVE_CODE(DoBloodWorm), - SAVE_CODE(DoBloodWorm), SAVE_CODE(DoMeteor), SAVE_CODE(DoSerpMeteor), SAVE_CODE(DoMirvMissile), SAVE_CODE(DoMirv), - SAVE_CODE(MissileSetPos), - SAVE_CODE(TestMissileSetPos), SAVE_CODE(DoRing), - SAVE_CODE(InitSpellRing), SAVE_CODE(DoSerpRing), SAVE_CODE(InitLavaFlame), SAVE_CODE(InitLavaThrow), SAVE_CODE(InitVulcanBoulder), SAVE_CODE(InitSerpRing), SAVE_CODE(InitSerpRing), - //SAVE_CODE(InitSerpRing2), SAVE_CODE(InitSpellNapalm), SAVE_CODE(InitEnemyNapalm), SAVE_CODE(InitSpellMirv), @@ -21503,35 +21446,16 @@ static saveable_code saveable_weapon_code[] = SAVE_CODE(InitSumoSkull), SAVE_CODE(InitSumoStompAttack), SAVE_CODE(InitMiniSumoClap), - SAVE_CODE(WeaponAutoAim), - SAVE_CODE(WeaponAutoAimZvel), - SAVE_CODE(AimHitscanToTarget), - SAVE_CODE(WeaponAutoAimHitscan), - SAVE_CODE(WeaponHitscanShootFeet), - SAVE_CODE(InitStar), - SAVE_CODE(InitHeartAttack), - SAVE_CODE(InitHeartAttack), - SAVE_CODE(InitShotgun), - SAVE_CODE(InitLaser), - SAVE_CODE(InitRail), SAVE_CODE(InitZillaRail), - SAVE_CODE(InitRocket), - SAVE_CODE(InitBunnyRocket), - SAVE_CODE(InitNuke), SAVE_CODE(InitEnemyNuke), - SAVE_CODE(InitMicro), SAVE_CODE(InitRipperSlash), SAVE_CODE(InitBunnySlash), SAVE_CODE(InitSerpSlash), - SAVE_CODE(WallSpriteInsideSprite), - SAVE_CODE(DoBladeDamage), - SAVE_CODE(DoStaticFlamesDamage), SAVE_CODE(InitCoolgBash), SAVE_CODE(InitSkelSlash), SAVE_CODE(InitGoroChop), SAVE_CODE(InitHornetSting), SAVE_CODE(InitSerpSpell), - SAVE_CODE(SpawnDemonFist), SAVE_CODE(InitSerpMonstSpell), SAVE_CODE(DoTeleRipper), SAVE_CODE(InitEnemyRocket), @@ -21550,55 +21474,17 @@ static saveable_code saveable_weapon_code[] = SAVE_CODE(InitSpearTrap), SAVE_CODE(DoSuicide), SAVE_CODE(DoDefaultStat), - SAVE_CODE(InitTracerUzi), - SAVE_CODE(InitTracerTurret), - SAVE_CODE(InitTracerAutoTurret), - SAVE_CODE(BulletHitSprite), - SAVE_CODE(HitscanSpriteAdjust), - SAVE_CODE(InitUzi), - SAVE_CODE(InitEMP), - SAVE_CODE(InitTankShell), - SAVE_CODE(InitTurretMicro), - SAVE_CODE(InitTurretRocket), - SAVE_CODE(InitTurretFireball), - SAVE_CODE(InitTurretRail), - SAVE_CODE(InitTurretLaser), - SAVE_CODE(InitSobjMachineGun), - SAVE_CODE(InitSobjGun), - SAVE_CODE(SpawnBoatSparks), - SAVE_CODE(SpawnSwordSparks), - SAVE_CODE(SpawnTurretSparks), - SAVE_CODE(SpawnShotgunSparks), - SAVE_CODE(InitTurretMgun), SAVE_CODE(InitEnemyUzi), - SAVE_CODE(InitGrenade), SAVE_CODE(InitSpriteGrenade), - SAVE_CODE(InitMine), SAVE_CODE(InitEnemyMine), - SAVE_CODE(HelpMissileLateral), - SAVE_CODE(InitFireball), SAVE_CODE(InitEnemyFireball), - SAVE_CODE(WarpToUnderwater), - SAVE_CODE(WarpToSurface), - SAVE_CODE(SpriteWarpToUnderwater), - SAVE_CODE(SpriteWarpToSurface), - SAVE_CODE(SpawnSplash), - SAVE_CODE(SpawnSplashXY), - SAVE_CODE(SpawnUnderSplash), - SAVE_CODE(MissileHitDiveArea), - SAVE_CODE(SpawnBubble), SAVE_CODE(DoVehicleSmoke), SAVE_CODE(DoWaterSmoke), SAVE_CODE(SpawnVehicleSmoke), SAVE_CODE(SpawnSmokePuff), SAVE_CODE(DoBubble), - SAVE_CODE(SpriteQueueDelete), SAVE_CODE(DoFloorBlood), SAVE_CODE(DoWallBlood), - //SAVE_CODE(DoShellShrap), - SAVE_CODE(SpawnShell), - SAVE_CODE(DoShrapVelocity), - SAVE_CODE(ShrapKillSprite), SAVE_CODE(DoItemFly), }; diff --git a/source/games/sw/src/zilla.cpp b/source/games/sw/src/zilla.cpp index e51ccf4fe..0d5b39ec2 100644 --- a/source/games/sw/src/zilla.cpp +++ b/source/games/sw/src/zilla.cpp @@ -800,7 +800,6 @@ int DoZillaDeathMelt(DSWActor* actor) static saveable_code saveable_zilla_code[] = { - SAVE_CODE(SetupZilla), SAVE_CODE(NullZilla), SAVE_CODE(DoZillaMove), SAVE_CODE(DoZillaStomp), diff --git a/source/games/sw/src/zombie.cpp b/source/games/sw/src/zombie.cpp index 914c041dc..5e6382a41 100644 --- a/source/games/sw/src/zombie.cpp +++ b/source/games/sw/src/zombie.cpp @@ -981,9 +981,6 @@ int DoZombiePain(DSWActor* actor) static saveable_code saveable_zombie_code[] = { - SAVE_CODE(SetupZombie), - SAVE_CODE(SpawnZombie), - SAVE_CODE(SpawnZombie2), SAVE_CODE(DoZombieMove), SAVE_CODE(NullZombie), SAVE_CODE(DoZombiePain),