From cd45a1f03509770c133dc5c57f013781f864f068 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 2 Apr 2021 10:44:41 +0200 Subject: [PATCH] - made more parts of USER serialization friendly. --- source/common/utility/tarray.h | 2 ++ source/games/sw/src/game.h | 30 +++++++++++++++++++------- source/games/sw/src/light.cpp | 4 ++-- source/games/sw/src/rotator.cpp | 8 +++---- source/games/sw/src/save.cpp | 8 +++++-- source/games/sw/src/slidor.cpp | 6 +++--- source/games/sw/src/sprite.cpp | 37 +++++++++------------------------ 7 files changed, 50 insertions(+), 45 deletions(-) diff --git a/source/common/utility/tarray.h b/source/common/utility/tarray.h index c8508a022..d10c3224f 100644 --- a/source/common/utility/tarray.h +++ b/source/common/utility/tarray.h @@ -1451,10 +1451,12 @@ public: return Ptr; } +#if 0 // this is too dangerous. operator T* () const { return Ptr; } +#endif void Alloc() { diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 5452cc9c1..79a9691f5 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1098,7 +1098,7 @@ typedef struct STATEp *Dive; } ACTOR_ACTION_SET,*ACTOR_ACTION_SETp; -typedef struct +struct ROTATOR { int pos; // current position - always moves toward tgt int open_dest; // destination of open position @@ -1106,10 +1106,27 @@ typedef struct int speed; // speed of movement int orig_speed; // original speed - vel jacks with speed int vel; // velocity adjuments - int num_walls; // save off positions of walls for rotator - int *origx; - int *origy; -} ROTATOR, *ROTATORp; + + TArray origX; + TArray origY; + + void SetNumWalls(int num) + { + origX.Resize(num); + origY.Resize(num); + memset(origX.Data(), 0, num * sizeof(int)); + memset(origY.Data(), 0, num * sizeof(int)); + } + + void ClearWalls() + { + origX.Reset(); + origY.Reset(); + } + +}; + +using ROTATORp = ROTATOR*; // // User Extension record @@ -1133,8 +1150,7 @@ struct USER TPointer rotator; // wall vars for lighting - int WallCount; - int8_t* WallShade; // malloced - save off wall shades for lighting + TArray WallShade; WALLp WallP; // operate on wall instead of sprite STATEp State; diff --git a/source/games/sw/src/light.cpp b/source/games/sw/src/light.cpp index 22537de2d..4d19decda 100644 --- a/source/games/sw/src/light.cpp +++ b/source/games/sw/src/light.cpp @@ -78,8 +78,8 @@ void SectorLightShade(SPRITEp sp, short intensity) // change wall if (!TEST_BOOL4(sp)) { - ASSERT(User[sp - sprite] && User[sp - sprite]->WallShade); - wall_shade = User[sp - sprite]->WallShade; + ASSERT(User[sp - sprite] && User[sp - sprite]->WallShade.Data()); + wall_shade = User[sp - sprite]->WallShade.Data(); startwall = sector[sp->sectnum].wallptr; endwall = startwall + sector[sp->sectnum].wallnum - 1; diff --git a/source/games/sw/src/rotator.cpp b/source/games/sw/src/rotator.cpp index f506db318..6478545ad 100644 --- a/source/games/sw/src/rotator.cpp +++ b/source/games/sw/src/rotator.cpp @@ -50,7 +50,7 @@ void ReverseRotator(short SpriteNum) USERp u = User[SpriteNum]; ROTATORp r; - r = u->rotator; + r = u->rotator.Data(); // if paused go ahead and start it up again if (u->Tics) @@ -101,7 +101,7 @@ void SetRotatorActive(short SpriteNum) SPRITEp sp = u->SpriteP; ROTATORp r; - r = u->rotator; + r = u->rotator.Data(); DoRotatorSetInterp(SpriteNum); @@ -320,7 +320,7 @@ int DoRotatorMove(short SpriteNum) int dist,closest; bool kill = false; - r = u->rotator; + r = u->rotator.Data(); // Example - ang pos moves from 0 to 512 <> from 0 to -512 @@ -416,7 +416,7 @@ int DoRotatorMove(short SpriteNum) // move points for (w = startwall, ndx = 0; w <= endwall; w++) { - vec2_t const orig = { r->origx[ndx], r->origy[ndx] }; + vec2_t const orig = { r->origX[ndx], r->origY[ndx] }; rotatepoint(pivot->pos.vec2, orig, r->pos, &nxy); dragpoint(w, nxy.x, nxy.y, 0); diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index ae452686e..e1c060db5 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -371,9 +371,10 @@ bool GameInterface::SaveGame() MWRITE(u,sizeof(USER),1,fil); +#if 0 if (u->WallShade) { - MWRITE(u->WallShade,sizeof(*u->WallShade)*u->WallCount,1,fil); + MWRITE(u->WallShade, sizeof(*u->WallShade) * u->WallCount, 1, fil); } if (u->rotator) @@ -384,6 +385,7 @@ bool GameInterface::SaveGame() if (u->rotator->origy) MWRITE(u->rotator->origy,sizeof(*u->rotator->origy)*u->rotator->num_walls,1,fil); } +#endif saveisshot |= SaveSymDataInfo(fil, u->WallP); assert(!saveisshot); @@ -753,10 +755,11 @@ bool GameInterface::LoadGame() MREAD(u,sizeof(USER),1,fil); memset((void*)&u->rotator, 0, sizeof(u->rotator)); +#if 0 if (u->WallShade) { u->WallShade = (int8_t*)CallocMem(u->WallCount * sizeof(*u->WallShade), 1); - MREAD(u->WallShade,sizeof(*u->WallShade)*u->WallCount,1,fil); + MREAD(u->WallShade, sizeof(*u->WallShade) * u->WallCount, 1, fil); } if (u->rotator) @@ -775,6 +778,7 @@ bool GameInterface::LoadGame() MREAD(u->rotator->origy,sizeof(*u->rotator->origy)*u->rotator->num_walls,1,fil); } } +#endif saveisshot |= LoadSymDataInfo(fil, (void **)&u->WallP); saveisshot |= LoadSymDataInfo(fil, (void **)&u->State); diff --git a/source/games/sw/src/slidor.cpp b/source/games/sw/src/slidor.cpp index b94a24413..4650bda82 100644 --- a/source/games/sw/src/slidor.cpp +++ b/source/games/sw/src/slidor.cpp @@ -44,7 +44,7 @@ void ReverseSlidor(short SpriteNum) USERp u = User[SpriteNum]; ROTATORp r; - r = u->rotator; + r = u->rotator.Data(); // if paused go ahead and start it up again if (u->Tics) @@ -96,7 +96,7 @@ void SetSlidorActive(short SpriteNum) SPRITEp sp = u->SpriteP; ROTATORp r; - r = u->rotator; + r = u->rotator.Data(); DoSlidorInterp(SpriteNum, StartInterpolation); @@ -543,7 +543,7 @@ int DoSlidorMove(short SpriteNum) int old_pos; bool kill = false; - r = u->rotator; + r = u->rotator.Data(); // Example - ang pos moves from 0 to 512 <> from 0 to -512 diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index 5caa2b056..ebbae6c36 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -642,12 +642,6 @@ KillSprite(int16_t SpriteNum) PLAYERp pp; short pnum; - if (u->WallShade) - { - FreeMem(u->WallShade); - u->WallShade = NULL; - } - // doing a MissileSetPos - don't allow killing if (TEST(u->Flags, SPR_SET_POS_DONT_KILL)) return; @@ -784,15 +778,7 @@ KillSprite(int16_t SpriteNum) SetSuicide(u->flame); } - if (u->rotator) - { - if (u->rotator->origx) - FreeMem(u->rotator->origx); - if (u->rotator->origy) - FreeMem(u->rotator->origy); - - u->rotator.Clear(); - } + u->rotator.Clear(); FreeUser(SpriteNum); } @@ -909,7 +895,6 @@ SpawnUser(short SpriteNum, short id, STATEp state) u->SpriteNum = SpriteNum; u->WaitTics = 0; u->OverlapZ = Z(4); - u->WallShade = NULL; u->bounce = 0; u->motion_blur_num = 0; @@ -2405,21 +2390,19 @@ SpriteSetup(void) wallcount++; u->rotator.Alloc(); - u->rotator->num_walls = wallcount; u->rotator->open_dest = SP_TAG5(sp); u->rotator->speed = SP_TAG7(sp); u->rotator->vel = SP_TAG8(sp); u->rotator->pos = 0; // closed u->rotator->tgt = u->rotator->open_dest; // closed - u->rotator->origx = (int*)CallocMem(sizeof(u->rotator->origx) * wallcount, 1); - u->rotator->origy = (int*)CallocMem(sizeof(u->rotator->origy) * wallcount, 1); + u->rotator->SetNumWalls(wallcount); u->rotator->orig_speed = u->rotator->speed; for (w = startwall, wallcount = 0; w <= endwall; w++) { - u->rotator->origx[wallcount] = wall[w].x; - u->rotator->origy[wallcount] = wall[w].y; + u->rotator->origX[wallcount] = wall[w].x; + u->rotator->origY[wallcount] = wall[w].y; wallcount++; } @@ -2466,7 +2449,7 @@ SpriteSetup(void) u->rotator->vel = SP_TAG8(sp); u->rotator->pos = 0; // closed u->rotator->tgt = u->rotator->open_dest; // closed - u->rotator->num_walls = 0; + u->rotator->ClearWalls(); u->rotator->orig_speed = u->rotator->speed; SET(u->Flags, SPR_ACTIVE); @@ -2611,13 +2594,13 @@ SpriteSetup(void) } User[SpriteNum] = u = SpawnUser(SpriteNum, 0, NULL); - u->WallCount = wallcount; - wall_shade = u->WallShade = (int8_t*)CallocMem(u->WallCount * sizeof(*u->WallShade), 1); + u->WallShade.Resize(wallcount); + wall_shade = u->WallShade.Data(); // save off original wall shades for (w = startwall, wallcount = 0; w <= endwall; w++) { - wall_shade[wallcount] = wall[w].shade; + wall_shade[wallcount] = wall[w].shade; wallcount++; if (TEST_BOOL5(sp)) { @@ -2667,8 +2650,8 @@ SpriteSetup(void) // !LIGHT // make an wall_shade array and put it in User User[SpriteNum] = u = SpawnUser(SpriteNum, 0, NULL); - u->WallCount = wallcount; - wall_shade = u->WallShade = (int8_t*)CallocMem(u->WallCount * sizeof(*u->WallShade), 1); + u->WallShade.Resize(wallcount); + wall_shade = u->WallShade.Data(); // save off original wall shades for (w = startwall, wallcount = 0; w <= endwall; w++)