migrate Blood to engine states.

This both enables saving again and allows efficient state searching.
This commit is contained in:
Christoph Oelckers 2023-10-08 16:55:37 +02:00
parent d898d1e53d
commit 60c44d74ca
7 changed files with 28 additions and 37 deletions

View file

@ -166,10 +166,6 @@ struct FDefiningState
VMFunction* TickFunc; // called when ticking the state.
VMFunction* MoveFunc; // called when moving the actor
FScriptPosition scriptpos;
// these are only here so we can use this struct directly in the first stage of transitioning the states in Blood.
FDefiningState* NextState;
int seqId;
};
struct FStateLabels;

View file

@ -1045,6 +1045,7 @@ void ZCCRazeCompiler::CompileStates()
state.EnterFunc = defstate.EnterFunc;
statedef.AddStates(&state, "A", defstate.scriptpos);
if (defstate.NextStaten != NAME_None) statedef.SetGotoLabel(defstate.NextStaten.GetChars());
else statedef.SetStop();
}
static_cast<PClassActor*>(c->ClassType())->ActorInfo()->AIStates.Reset();

View file

@ -77,16 +77,31 @@ void aiPlay3DSound(DBloodActor* actor, int soundid, AI_SFX_PRIORITY a3, int play
//
//---------------------------------------------------------------------------
void aiNewState(DBloodActor* actor, FDefiningState* pAIState)
void aiNewState(DBloodActor* actor, FState* pAIState)
{
DUDEINFO* pDudeInfo = getDudeInfo(actor);
actor->xspr.stateTimer = pAIState->Tics;
actor->xspr.aiState = pAIState;
int seqStartId = pDudeInfo->seqStartID;
int seqStartId = -1;
if (pAIState->seqId >= 0)
switch (pAIState->StateFlags & STF_SPRITESEQMASK)
{
case STF_SPRITESEQNAME:
if (pAIState->sprite > 0)
I_Error("Named SEQs not supported yet!");
break;
case STF_SPRITESEQINDEX:
seqStartId = pAIState->sprite;
break;
case STF_SPRITESEQOFFSET:
seqStartId = pAIState->sprite + pDudeInfo->seqStartID;
break;
}
if (seqStartId >= 0)
{
seqStartId += pAIState->seqId;
if (getSequence(seqStartId))
seqSpawn(seqStartId, actor, pAIState->ActionFunc);
}
@ -97,18 +112,10 @@ void aiNewState(DBloodActor* actor, FDefiningState* pAIState)
void aiNewState(DBloodActor* actor, FName nAIState)
{
auto cls = actor->GetClass();
while (cls)
auto state = actor->FindState(nAIState);
if (state != nullptr)
{
for (auto& state : static_cast<PClassActor*>(cls)->ActorInfo()->AIStates)
{
if (state.Label == nAIState)
{
aiNewState(actor, &state);
return;
}
}
cls = cls->ParentClass;
aiNewState(actor, state);
}
}
@ -630,14 +637,14 @@ void aiActivateDude(DBloodActor* actor)
{
actor->dudeExtra.thinkTime = 1;
if (actor->xspr.aiState->Label == NAME_zombieEIdle) aiNewState(actor, NAME_zombieEUp);
if (actor->xspr.aiState == actor->FindState(NAME_zombieEIdle)) aiNewState(actor, NAME_zombieEUp);
break;
}
case kDudeZombieAxeLaying:
{
actor->dudeExtra.thinkTime = 1;
if (actor->xspr.aiState->Label == NAME_zombieSIdle) aiNewState(actor, NAME_zombieEStand);
if (actor->xspr.aiState == actor->FindState(NAME_zombieSIdle)) aiNewState(actor, NAME_zombieEStand);
break;
}
case kDudeZombieButcher:

View file

@ -49,7 +49,7 @@ extern const int gCultTeslaFireChance[5];
bool dudeIsPlayingSeq(DBloodActor* pSprite, int nSeq);
void aiPlay3DSound(DBloodActor* pSprite, int a2, AI_SFX_PRIORITY a3, int a4);
void aiNewState(DBloodActor* actor, FName pAIState);
void aiNewState(DBloodActor* actor, FDefiningState* pAIState);
void aiNewState(DBloodActor* actor, FState* pAIState);
void aiChooseDirection(DBloodActor* actor, DAngle a3);
void aiMoveForward(DBloodActor*pXSprite);
void aiMoveTurn(DBloodActor*pXSprite);

View file

@ -718,19 +718,6 @@ void GameInterface::FinalizeSetup()
actorinfo->TypeNum = pair->Key;
}
}
// Make the StatesToDefine array temporarily operable to allow transitioning the state calls without first altering the state table implementation.
#pragma message("remove after state transitioning")
auto cls = PClass::FindActor("BloodDudeBase");
for (auto& state : cls->ActorInfo()->AIStates)
{
state.seqId = state.sprite == 0 ? -1 : state.sprite & 0xffff;
state.NextState = nullptr;
for (auto& state2 : cls->ActorInfo()->AIStates)
{
if (state.NextStaten == state2.Label) state.NextState = &state2;
}
}
}
//---------------------------------------------------------------------------

View file

@ -213,7 +213,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, XSPRITE& w, XSPRIT
if (arc.BeginObject(keyname))
{
arc("flags", w.flags, def->flags)
//("aistate", w.aiState, def->aiState) disabled until we can transition to engine states.
("aistate", w.aiState, def->aiState)
("busy", w.busy, def->busy)
("txid", w.txID, def->txID)
("rxid", w.rxID, def->rxID)

View file

@ -60,7 +60,7 @@ class DBloodActor;
struct XSPRITE {
FDefiningState* aiState; // ai
FState* aiState; // ai
union
{
uint32_t flags;