From 6475d772ca3ce7553a8262b8b56a600bd513e08a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 30 Nov 2020 00:23:57 +0100 Subject: [PATCH] - Exhumed: Runlist and Rand. --- source/exhumed/src/aistuff.h | 7 +++- source/exhumed/src/random.cpp | 16 +++++--- source/exhumed/src/runlist.cpp | 70 ++++++++++++++++++---------------- source/exhumed/src/save.cpp | 4 ++ 4 files changed, 58 insertions(+), 39 deletions(-) diff --git a/source/exhumed/src/aistuff.h b/source/exhumed/src/aistuff.h index 50f7cbf5f..a6d5a1b99 100644 --- a/source/exhumed/src/aistuff.h +++ b/source/exhumed/src/aistuff.h @@ -383,8 +383,13 @@ struct RunStruct int nMoves; struct { +#if B_BIG_ENDIAN == 1 + short nRef; + short nVal; +#else short nVal; short nRef; +#endif }; }; @@ -402,7 +407,7 @@ struct RunChannel typedef void(*AiFunc)(int, int, int nRun); -extern RunStruct RunData[kMaxRuns]; +extern FreeListArray RunData; extern RunChannel sRunChannels[kMaxChannels]; extern short NewRun; extern int nRadialOwner; diff --git a/source/exhumed/src/random.cpp b/source/exhumed/src/random.cpp index 4b0295a46..f709aeef7 100644 --- a/source/exhumed/src/random.cpp +++ b/source/exhumed/src/random.cpp @@ -25,12 +25,16 @@ int randA = 0; int randB = 0x11111111; int randC = 0x1010101; -static SavegameHelper sghrandom("rand", - SV(randA), - SV(randB), - SV(randC), - nullptr); - +void SerializeRand(FSerializer& arc) +{ + if (arc.BeginObject("rand")) + { + arc("a", randA) + ("b", randB) + ("c", randC) + .EndObject(); + } +} void InitRandom() { diff --git a/source/exhumed/src/runlist.cpp b/source/exhumed/src/runlist.cpp index bda15be34..d9ffecf9f 100644 --- a/source/exhumed/src/runlist.cpp +++ b/source/exhumed/src/runlist.cpp @@ -32,7 +32,6 @@ enum }; -short RunCount = -1; short nRadialSpr = -1; short nStackCount = 0; short word_966BE = 0; @@ -46,9 +45,42 @@ short RunChain; short NewRun; int sRunStack[kMaxRunStack]; -short RunFree[kMaxRuns]; RunChannel sRunChannels[kMaxChannels]; -RunStruct RunData[kMaxRuns]; +FreeListArray RunData; + + +FSerializer& Serialize(FSerializer& arc, const char* keyname, RunStruct& w, RunStruct* def) +{ + if (arc.BeginObject(keyname)) + { + arc("moves", w.nMoves) + ("_4", w._4) + ("_6", w._6) + .EndObject(); + } + return arc; +} + +void SerializeRunList(FSerializer& arc) +{ + if (arc.BeginObject("runlist")) + { + arc("data", RunData) + ("radialspr", nRadialSpr) + ("stackcount", nStackCount) + ("w966be", word_966BE) + ("list", ChannelList) + ("last", ChannelLast) + ("radialowner", nRadialOwner) + ("damageradius", nDamageRadius) + ("radialdamage", nRadialDamage) + ("runchain", RunChain) + ("newrun", NewRun) + .Array("runstack", sRunStack, nStackCount) + .Array("runchannels", &sRunChannels[0].a, 4 * kMaxChannels) // save this in a more compact form than an array of structs. + .EndObject(); + } +} AiFunc aiFunctions[kFuncMax] = { FuncElev, @@ -95,25 +127,17 @@ AiFunc aiFunctions[kFuncMax] = { int runlist_GrabRun() { - assert(RunCount > 0 && RunCount <= kMaxRuns); - - RunCount--; - - return RunFree[RunCount]; + return RunData.Get(); } int runlist_FreeRun(int nRun) { - assert(RunCount >= 0 && RunCount < kMaxRuns); assert(nRun >= 0 && nRun < kMaxRuns); - RunFree[RunCount] = nRun; - RunCount++; - RunData[nRun]._6 = -1; RunData[nRun].nMoves = -1; RunData[nRun]._4 = RunData[nRun]._6; - + RunData.Release(nRun); return 1; } @@ -131,14 +155,13 @@ void runlist_InitRun() { int i; - RunCount = kMaxRuns; + RunData.Clear(); nStackCount = 0; for (i = 0; i < kMaxRuns; i++) { RunData[i].nMoves = -1; RunData[i]._6 = -1; - RunFree[i] = i; RunData[i]._4 = -1; } @@ -1669,22 +1692,5 @@ void runlist_DamageEnemy(int nSprite, int nSprite2, short nDamage) } } -static SavegameHelper sghrunlist("runlist", - SV(RunCount), - SV(nRadialSpr), - SV(nStackCount), - SV(word_966BE), - SV(ChannelList), - SV(ChannelLast), - SV(nRadialOwner), - SV(nDamageRadius), - SV(nRadialDamage), - SV(RunChain), - SV(NewRun), - SA(sRunStack), - SA(RunFree), - SA(sRunChannels), - SA(RunData), - nullptr); END_PS_NS diff --git a/source/exhumed/src/save.cpp b/source/exhumed/src/save.cpp index af70e7351..be84a682f 100644 --- a/source/exhumed/src/save.cpp +++ b/source/exhumed/src/save.cpp @@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS +void SerializeRand(FSerializer& arc); +void SerializeRunList(FSerializer& arc); void SerializeSequence(FSerializer& arc); void SerializeSnake(FSerializer& arc); void SerializeSwitch(FSerializer& arc); @@ -63,6 +65,8 @@ void GameInterface::SerializeGameState(FSerializer& arc) { if (arc.BeginObject("exhumed")) { + SerializeRand(arc); + SerializeRunList(arc); SerializeSequence(arc); SerializeSnake(arc); SerializeSwitch(arc);