- made more parts of USER serialization friendly.

This commit is contained in:
Christoph Oelckers 2021-04-02 10:44:41 +02:00
parent dcb393bc44
commit cd45a1f035
7 changed files with 50 additions and 45 deletions

View file

@ -1451,10 +1451,12 @@ public:
return Ptr;
}
#if 0 // this is too dangerous.
operator T* () const
{
return Ptr;
}
#endif
void Alloc()
{

View file

@ -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<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
@ -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;

View file

@ -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;

View file

@ -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 <<OR>> 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);

View file

@ -371,6 +371,7 @@ bool GameInterface::SaveGame()
MWRITE(u,sizeof(USER),1,fil);
#if 0
if (u->WallShade)
{
MWRITE(u->WallShade, sizeof(*u->WallShade) * u->WallCount, 1, fil);
@ -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,6 +755,7 @@ 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);
@ -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);

View file

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

View file

@ -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();
}
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,8 +2594,8 @@ 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++)
@ -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++)