- moved 'move' data out of the ScriptCode array as well.

This commit is contained in:
Christoph Oelckers 2022-12-21 13:32:00 +01:00
parent 30ccbe2710
commit b9702fbb66
12 changed files with 59 additions and 70 deletions

View file

@ -3255,10 +3255,10 @@ void alterang(int ang, DDukeActor* actor, int playernum)
aang = actor->spr.Angles.Yaw;
actor->vel.X += (actor->GetMoveX() - actor->vel.X) / 5;
actor->vel.X += (actor->curMove->movex - actor->vel.X) / 5;
if (actor->vel.Z < (648 / 256.))
{
actor->vel.Z += (actor->GetMoveZ() - actor->vel.Z) / 5;
actor->vel.Z += (actor->curMove->movez - actor->vel.Z) / 5;
}
if (isRRRA() && (ang & windang))

View file

@ -1185,7 +1185,7 @@ void move_d(DDukeActor *actor, int playernum, int xvel)
actor->spr.Angles.Yaw += angdif;
}
if (actor->temp_data[1] == 0 || a == 0)
if (actor->curMove->name == NAME_None || a == 0)
{
if ((badguy(actor) && actor->spr.extra <= 0) || (actor->opos.X != actor->spr.pos.X) || (actor->opos.Y != actor->spr.pos.Y))
{
@ -1195,8 +1195,8 @@ void move_d(DDukeActor *actor, int playernum, int xvel)
return;
}
if (a & geth) actor->vel.X += (actor->GetMoveX() - actor->vel.X) * 0.5;
if (a & getv) actor->vel.Z += (actor->GetMoveZ() - actor->vel.Z) * 0.5;
if (a & geth) actor->vel.X += (actor->curMove->movex - actor->vel.X) * 0.5;
if (a & getv) actor->vel.Z += (actor->curMove->movez - actor->vel.Z) * 0.5;
if (a & dodgebullet)
dodge(actor);
@ -1293,7 +1293,7 @@ void move_d(DDukeActor *actor, int playernum, int xvel)
}
else if (!(actor->flags2 & SFLAG2_FLOATING))
{
if (actor->GetMoveZ() == 0)
if (actor->curMove->movez == 0)
{
if (actor->opos.Z != actor->spr.pos.Z || (ud.multimode < 2 && ud.player_skill < 2))
{

View file

@ -1318,7 +1318,7 @@ void move_r(DDukeActor *actor, int pnum, int xvel)
actor->spr.Angles.Yaw += angdif;
}
if (actor->temp_data[1] == 0 || a == 0)
if (actor->curMove->name == NAME_None || a == 0)
{
if ((badguy(actor) && actor->spr.extra <= 0) || (actor->opos.X != actor->spr.pos.X) || (actor->opos.Y != actor->spr.pos.Y))
{
@ -1346,8 +1346,8 @@ void move_r(DDukeActor *actor, int pnum, int xvel)
return;
}
if (a & geth) actor->vel.X += (actor->GetMoveX() - actor->vel.X) * 0.5;
if (a & getv) actor->vel.Z += (actor->GetMoveZ() - actor->vel.Z) * 0.5;
if (a & geth) actor->vel.X += (actor->curMove->movex - actor->vel.X) * 0.5;
if (a & getv) actor->vel.Z += (actor->curMove->movez - actor->vel.Z) * 0.5;
if (a & dodgebullet)
dodge(actor);
@ -1420,7 +1420,7 @@ void move_r(DDukeActor *actor, int pnum, int xvel)
}
else if (!(actor->flags2 & SFLAG2_FLOATING))
{
if (actor->GetMoveZ() == 0)
if (actor->curMove->movez == 0)
{
if (actor->opos.Z != actor->spr.pos.Z || (ud.multimode < 2 && ud.player_skill < 2))
{

View file

@ -48,7 +48,6 @@ BEGIN_DUKE_NS
void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle viewang, double interpfrac)
{
int p;
int t1, t3, t4;
tspritetype* t;
DDukeActor* h;
@ -117,10 +116,6 @@ void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi
continue;
}
t1 = h->temp_data[1];
t3 = h->temp_data[3];
t4 = h->temp_data[4];
if (h->spr.picnum == DTILE_APLAYER)
{
p = h->PlayerIndex();
@ -202,13 +197,6 @@ void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi
else h->spr.yoffset = 0;
}
if (ps[p].newOwner != nullptr)
{
t4 = ScriptCode[gs.actorinfo[DTILE_APLAYER].scriptaddress + 1];
t3 = 0;
t1 = ScriptCode[gs.actorinfo[DTILE_APLAYER].scriptaddress + 2];
}
if (ud.cameraactor == nullptr && ps[p].newOwner == nullptr)
if (h->GetOwner() && display_mirror == 0 && ps[p].over_shoulder_on == 0)
if (ud.multimode < 2 || (ud.multimode > 1 && p == screenpeek))

View file

@ -41,7 +41,6 @@ BEGIN_DUKE_NS
void animatesprites_r(tspriteArray& tsprites, const DVector2& viewVec, DAngle viewang, double interpfrac)
{
int k, p;
int t1, t3, t4;
tspritetype* t;
DDukeActor* h;
@ -115,10 +114,6 @@ void animatesprites_r(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi
continue;
}
t1 = h->temp_data[1];
t3 = h->temp_data[3];
t4 = h->temp_data[4];
if (h->spr.picnum == RTILE_APLAYER)
{
p = h->PlayerIndex();

View file

@ -381,6 +381,7 @@ void GameInterface::app_init()
ud.m_monsters_off = userConfig.nomonsters;
ps[0].aim_mode = 1;
ud.cameraactor = nullptr;
moves.Push({}); // make sure the first entry in 'moves' is a null move.
actions.Push({}); // make sure the first entry in 'actions' is a null action.
if (fileSystem.FileExists("DUKESW.BIN"))

View file

@ -984,24 +984,25 @@ int ConCompiler::parsecommand()
checkforkeyword();
for (i = 0; i < (int)labels.Size(); i++)
if (labels[i].compare(parselabel) == 0)
{
warningcount++;
Printf(TEXTCOLOR_RED " * WARNING.(%s, line %d) Duplicate move '%s' ignored.\n", fn, line_number, parselabel.GetChars());
break;
}
if (i == (int)labels.Size())
appendlabeladdress(LABEL_MOVE);
for (j = 0; j < 2; j++)
lnum = findlabel(parselabel);
if (lnum >= 0)
{
if (keyword() >= 0) break;
transnum(LABEL_DEFINE);
}
for (k = j; k < 2; k++)
{
appendscriptvalue(0);
warningcount++;
Printf(TEXTCOLOR_RED " * WARNING.(%s, line %d) Duplicate move '%s' ignored.\n", fn, line_number, parselabel.GetChars());
}
else appendlabelvalue(LABEL_MOVE, moves.Size());
ActorMove& move = moves[moves.Reserve(1)];
move.qualifiedName = FStringf("$con$.%s", parselabel.GetChars());
move.name = parselabel.GetChars();
move.movex = move.movez = 0;
if (keyword() >= 0) return 0;
transnum(LABEL_DEFINE);
move.movex = popscriptvalue() / 16.f;
if (keyword() >= 0) return 0;
transnum(LABEL_DEFINE);
move.movez = popscriptvalue() / 16.f;
}
return 0;

View file

@ -1555,7 +1555,7 @@ int ParseState::parse(void)
insptr++;
g_t[5] = *insptr;
g_ac->curAction = &actions[ScriptCode[g_t[5]]]; // Action
g_t[1] = ScriptCode[g_t[5] + 1]; // move
g_ac->curMove = &moves[ScriptCode[g_t[5] + 1]]; // move
g_ac->spr.hitag = ScriptCode[g_t[5] + 2]; // Ai
g_t[0] = g_t[2] = g_t[3] = 0;
if (g_ac->spr.hitag & random_angle)
@ -1888,7 +1888,7 @@ int ParseState::parse(void)
case concmd_move:
g_t[0]=0;
insptr++;
g_t[1] = *insptr;
g_ac->curMove = &moves[*insptr];
insptr++;
g_ac->spr.hitag = *insptr;
insptr++;
@ -1954,7 +1954,7 @@ int ParseState::parse(void)
break;
case concmd_ifmove:
insptr++;
parseifelse(g_t[1] == *insptr);
parseifelse((g_ac->curMove - moves.Data()) == *insptr);
break;
case concmd_resetplayer:
insptr++;

View file

@ -314,18 +314,6 @@ inline void processinputvel(int snum)
p->sync.svel = (float)velvect.Y;
}
inline double DDukeActor::GetMoveX() const
{
auto moveptr = &ScriptCode[temp_data[1]];
return moveptr[0] / 16.;
}
inline double DDukeActor::GetMoveZ() const
{
auto moveptr = &ScriptCode[temp_data[1]];
return moveptr[1] / 16.;
}
inline void setPlayerActorViewZOffset(DDukeActor* const pact)
{
if (!PlayClock)

View file

@ -47,24 +47,35 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, GameVarValue& w, G
void lava_serialize(FSerializer& arc);
void SerializeGameVars(FSerializer &arc);
FSerializer& Serialize(FSerializer& arc, const char* keyname, ActorAction*& w, ActorAction** def)
template<class T>
FSerializer& NamedSerialize(FSerializer& arc, const char* keyname, T*& w, TArray<T>& store)
{
if (arc.isWriting())
{
auto ww = w ? w : &actions[0];
auto ww = w ? w : &store[0];
if (keyname == nullptr || ww->qualifiedName != NAME_None) Serialize(arc, keyname, ww->qualifiedName, nullptr);
}
else
{
FName n = NAME_None;
Serialize(arc, keyname, n, nullptr);
auto index = actions.FindEx([=](const ActorAction& el) { return el.qualifiedName == n; });
if (index >= actions.Size()) index = 0;
w = &actions[index];
auto index = store.FindEx([=](const auto& el) { return el.qualifiedName == n; });
if (index >= store.Size()) index = 0;
w = &store[index];
}
return arc;
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, ActorMove*& w, ActorMove** def)
{
return NamedSerialize(arc, keyname, w, moves);
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, ActorAction*& w, ActorAction** def)
{
return NamedSerialize(arc, keyname, w, actions);
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, animwalltype& w, animwalltype* def)
{
if (arc.BeginObject(keyname))
@ -307,6 +318,7 @@ void DDukeActor::Serialize(FSerializer& arc)
("flags1", flags1)
("flags2", flags2)
("flags3", flags3)
("curmove", curMove)
("curaction", curAction);
}

View file

@ -45,6 +45,7 @@ BEGIN_DUKE_NS
void setFromSpawnRec(DDukeActor* act, SpawnRec* info)
{
act->curMove = &moves[0];
act->curAction = &actions[0];
if (info)
{
@ -126,7 +127,7 @@ DDukeActor* CreateActor(sectortype* whatsectp, const DVector3& pos, PClassActor*
auto sa = &ScriptCode[gs.actorinfo[s_pn].scriptaddress];
act->spr.extra = sa[0];
act->curAction = &actions[sa[1]];
act->temp_data[1] = sa[2];
act->curMove = &moves[sa[2]];
act->spr.hitag = sa[3];
}
else
@ -249,7 +250,7 @@ bool initspriteforspawn(DDukeActor* act)
{
act->spr.extra = ScriptCode[gs.actorinfo[s].scriptaddress];
act->curAction = &actions[ScriptCode[gs.actorinfo[s].scriptaddress+1]];
act->temp_data[1] = ScriptCode[gs.actorinfo[s].scriptaddress+2];
act->curMove = &moves[ScriptCode[gs.actorinfo[s].scriptaddress+2]];
int s3 = ScriptCode[gs.actorinfo[s].scriptaddress+3];
if (s3 && act->spr.hitag == 0)
act->spr.hitag = s3;

View file

@ -22,6 +22,12 @@ struct STATUSBARTYPE
bool gotweapon[MAX_WEAPONS];
};
struct ActorMove
{
FName qualifiedName; // this is only used for serialization.
FName name;
float movex, movez;
};
struct ActorAction
{
FName qualifiedName; // this is only used for serialization.
@ -34,6 +40,7 @@ struct ActorAction
int16_t delay;
};
inline TArray<ActorMove> moves;
inline TArray<ActorAction> actions;
struct ActorInfo
@ -82,6 +89,7 @@ public:
sectortype* temp_sect, *actorstayput;
DAngle temp_angle;
DVector3 temp_pos, temp_pos2;
ActorMove* curMove;
ActorAction* curAction;
TObjPtr<DDukeActor*> temp_actor, seek_actor;
@ -149,11 +157,6 @@ public:
auto tex = TexMan.GetGameTexture(spr.spritetexture());
clipdist = spr.scale.X * tex->GetDisplayWidth() * 0.125;
}
// Wrappers around CON data.
double GetMoveX() const;
double GetMoveZ() const;
};
// subclassed to add a game specific actor() method