Skip to content

Commit

Permalink
- made more parts of USER serialization friendly.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Apr 21, 2021
1 parent dcb393b commit cd45a1f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 45 deletions.
2 changes: 2 additions & 0 deletions source/common/utility/tarray.h
Expand Up @@ -1451,10 +1451,12 @@ class TPointer
return Ptr;
}

#if 0 // this is too dangerous.
operator T* () const
{
return Ptr;
}
#endif

void Alloc()
{
Expand Down
30 changes: 23 additions & 7 deletions source/games/sw/src/game.h
Expand Up @@ -1098,18 +1098,35 @@ 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
int tgt; // current target
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<int> origX;
TArray<int> 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
Expand All @@ -1133,8 +1150,7 @@ struct USER
TPointer<ROTATOR> rotator;

// wall vars for lighting
int WallCount;
int8_t* WallShade; // malloced - save off wall shades for lighting
TArray<int8_t> WallShade;

WALLp WallP; // operate on wall instead of sprite
STATEp State;
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/light.cpp
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions source/games/sw/src/rotator.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -101,7 +101,7 @@ void SetRotatorActive(short SpriteNum)
SPRITEp sp = u->SpriteP;
ROTATORp r;

r = u->rotator;
r = u->rotator.Data();

DoRotatorSetInterp(SpriteNum);

Expand Down Expand Up @@ -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 <<OR>> from 0 to -512

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions source/games/sw/src/save.cpp
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions source/games/sw/src/slidor.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -96,7 +96,7 @@ void SetSlidorActive(short SpriteNum)
SPRITEp sp = u->SpriteP;
ROTATORp r;

r = u->rotator;
r = u->rotator.Data();

DoSlidorInterp(SpriteNum, StartInterpolation);

Expand Down Expand Up @@ -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 <<OR>> from 0 to -512

Expand Down
37 changes: 10 additions & 27 deletions source/games/sw/src/sprite.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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++)
Expand Down

0 comments on commit cd45a1f

Please sign in to comment.