- crane cleanup

This now uses its own struct where it can store the needed actor pointer directly.
This commit is contained in:
Christoph Oelckers 2021-11-18 00:12:28 +01:00
parent d405da9195
commit 9d8e7ea759
8 changed files with 44 additions and 15 deletions

View file

@ -644,6 +644,7 @@ void movecrane(DDukeActor *actor, int crane)
auto spri = actor->s;
auto sectp = spri->sector();
int x;
auto& cpt = cranes[t[4]];
//t[0] = state
//t[1] = checking sector number
@ -661,8 +662,8 @@ void movecrane(DDukeActor *actor, int crane)
case STAT_ZOMBIEACTOR:
case STAT_STANDABLE:
case STAT_PLAYER:
spri->ang = getangle(msx[t[4] + 1] - spri->x, msy[t[4] + 1] - spri->y);
setsprite(a2, msx[t[4] + 1], msy[t[4] + 1], a2->s->z);
spri->ang = getangle(cpt.polex - spri->x, cpt.poley - spri->y);
setsprite(a2, cpt.polex, cpt.poley, a2->s->z);
t[0]++;
return;
}
@ -758,7 +759,7 @@ void movecrane(DDukeActor *actor, int crane)
if ((sectp->floorz - spri->z) > 8192)
spri->picnum++;
if (spri->z < msx[t[4] + 2])
if (spri->z < cpt.z)
{
t[0]++;
spri->xvel = 0;
@ -770,16 +771,16 @@ void movecrane(DDukeActor *actor, int crane)
{
if (spri->xvel < 192)
spri->xvel += 8;
spri->ang = getangle(msx[t[4]] - spri->x, msy[t[4]] - spri->y);
spri->ang = getangle(cpt.x - spri->x, cpt.y - spri->y);
ssp(actor, CLIPMASK0);
if (((spri->x - msx[t[4]]) * (spri->x - msx[t[4]]) + (spri->y - msy[t[4]]) * (spri->y - msy[t[4]])) < (128 * 128))
if (((spri->x - cpt.x) * (spri->x - cpt.x) + (spri->y - cpt.y) * (spri->y - cpt.y)) < (128 * 128))
t[0]++;
}
else if (t[0] == 9)
t[0] = 0;
setsprite(ScriptIndexToActor(msy[t[4] + 2]), spri->x, spri->y, spri->z - (34 << 8));
setsprite(cpt.poleactor, spri->x, spri->y, spri->z - (34 << 8));
auto Owner = actor->GetOwner();
if (Owner != nullptr || actor->IsActiveCrane())

View file

@ -267,6 +267,7 @@ enum
MAXANIMATES = 1024,
MAXANIMWALLS = 512,
MAXANIMPOINTS = 2048,
MAXCRANES = 16,
};
enum amoveflags_t

View file

@ -87,6 +87,8 @@ int show_shareware; // display only.
int rtsplaying; // RTS playback state
int tempwallptr; // msx/y index.
int msx[MAXANIMPOINTS], msy[MAXANIMPOINTS];
TArray<CraneDef> cranes;
bool sound445done; // used in checksectors_r. This was local state inside a function, but this must be maintained globally and serialized
// serialized

View file

@ -120,7 +120,8 @@ extern int geocnt;
extern short ambientlotag[64];
extern short ambienthitag[64];
extern unsigned ambientfx;
extern int msx[MAXANIMPOINTS], msy[MAXANIMPOINTS];
extern int msx[MAXANIMPOINTS], msy[MAXANIMPOINTS]; // todo: unlimit
extern TArray<CraneDef> cranes;
extern int WindTime, WindDir;
extern short fakebubba_spawn, mamaspawn_count, banjosound;
extern short BellTime;

View file

@ -420,6 +420,7 @@ void resetprestat(int snum,int g)
paused = 0;
ud.cameraactor =nullptr;
tempwallptr = 0;
cranes.Clear();
camsprite =nullptr;
earthquaketime = 0;

View file

@ -55,6 +55,21 @@ void lava_serialize(FSerializer& arc);
void SerializeGameVars(FSerializer &arc);
FSerializer& Serialize(FSerializer& arc, const char* keyname, CraneDef& w, CraneDef* def)
{
if (arc.BeginObject(keyname))
{
arc("x", w.x)
("y", w.y)
("z", w.z)
("polex", w.polex)
("poley", w.poley)
("pole", w.poleactor)
.EndObject();
}
return arc;
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, animwalltype& w, animwalltype* def)
{
if (arc.BeginObject(keyname))
@ -373,6 +388,7 @@ void GameInterface::SerializeGameState(FSerializer& arc)
.Array("sectorextra", sectorextra, numsectors)
("rtsplaying", rtsplaying)
("tempwallptr", tempwallptr)
("cranes", cranes)
("sound445done", sound445done)
.Array("players", ps, ud.multimode)
("spriteqamount", spriteqamount)

View file

@ -488,11 +488,12 @@ void initcrane(DDukeActor* actj, DDukeActor* acti, int CRANEPOLE)
sp->picnum += 2;
sp->z = sector[sect].ceilingz + (48 << 8);
t[4] = tempwallptr;
t[4] = cranes.Reserve(1);
msx[tempwallptr] = sp->x;
msy[tempwallptr] = sp->y;
msx[tempwallptr + 2] = sp->z;
auto& apt = cranes[t[4]];
apt.x = sp->x;
apt.y = sp->y;
apt.z = sp->z;
DukeStatIterator it(STAT_DEFAULT);
while (auto act = it.Next())
@ -500,15 +501,15 @@ void initcrane(DDukeActor* actj, DDukeActor* acti, int CRANEPOLE)
auto ss = act->s;
if (ss->picnum == CRANEPOLE && sp->hitag == (ss->hitag))
{
msy[tempwallptr + 2] = ActorToScriptIndex(act);
apt.poleactor = act;
t[1] = ss->sectnum;
ss->xrepeat = 48;
ss->yrepeat = 128;
msx[tempwallptr + 1] = ss->x;
msy[tempwallptr + 1] = ss->y;
apt.polex = ss->x;
apt.poley = ss->y;
ss->x = sp->x;
ss->y = sp->y;
@ -520,7 +521,6 @@ void initcrane(DDukeActor* actj, DDukeActor* acti, int CRANEPOLE)
}
}
tempwallptr += 3;
acti->SetOwner(nullptr);
sp->extra = 8;
changeactorstat(acti, STAT_STANDABLE);

View file

@ -160,6 +160,13 @@ struct player_orig
short oa, os;
};
struct CraneDef
{
int x, y, z;
int polex, poley;
DDukeActor* poleactor;
};
struct player_struct
{
// This is basically the version from JFDuke but this first block contains a few changes to make it work with other parts of Raze.