mirror of
https://github.com/ZDoom/Raze.git
synced 2025-04-22 07:50:54 +00:00
compile AI states into the engine's state array.
This commit is contained in:
parent
6528bb7e69
commit
bd44d87ce7
4 changed files with 32 additions and 4 deletions
|
@ -41,6 +41,7 @@
|
|||
#include "templates.h"
|
||||
#include "states.h"
|
||||
#include "texturemanager.h"
|
||||
#include "codegen.h"
|
||||
|
||||
|
||||
// stores indices for symbolic state labels for some old-style DECORATE functions.
|
||||
|
@ -699,7 +700,7 @@ void FStateDefinitions::RetargetStatePointers (intptr_t count, const char *targe
|
|||
}
|
||||
else
|
||||
{
|
||||
statelist[i].State = (FState *)copystring (target);
|
||||
statelist[i].State = (FState *)FxAlloc.Strdup(target);
|
||||
statelist[i].DefineFlags = SDF_LABEL;
|
||||
}
|
||||
}
|
||||
|
@ -800,7 +801,6 @@ FState *FStateDefinitions::ResolveGotoLabel (PClassActor *mytype, char *name)
|
|||
{
|
||||
Printf (TEXTCOLOR_RED "Attempt to get invalid state %s from actor %s.\n", label, type->TypeName.GetChars());
|
||||
}
|
||||
delete[] namestart; // free the allocated string buffer
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -864,7 +864,7 @@ bool FStateDefinitions::SetGotoLabel(const char *string)
|
|||
// copy the text - this must be resolved later!
|
||||
if (laststate != nullptr)
|
||||
{ // Following a state definition: Modify it.
|
||||
laststate->NextState = (FState*)copystring(string);
|
||||
laststate->NextState = (FState*)FxAlloc.Strdup(string);
|
||||
laststate->DefineFlags = SDF_LABEL;
|
||||
laststatebeforelabel = nullptr;
|
||||
return true;
|
||||
|
@ -874,7 +874,7 @@ bool FStateDefinitions::SetGotoLabel(const char *string)
|
|||
RetargetStates (lastlabel+1, string);
|
||||
if (laststatebeforelabel != nullptr)
|
||||
{
|
||||
laststatebeforelabel->NextState = (FState*)copystring(string);
|
||||
laststatebeforelabel->NextState = (FState*)FxAlloc.Strdup(string);
|
||||
laststatebeforelabel->DefineFlags = SDF_LABEL;
|
||||
laststatebeforelabel = nullptr;
|
||||
}
|
||||
|
|
|
@ -79,6 +79,10 @@ enum EStateFlags
|
|||
{
|
||||
STF_TICADJUST = 1,
|
||||
STF_FULLBRIGHT = 4, // State is fullbright
|
||||
STF_SPRITESEQMASK = 24,
|
||||
STF_SPRITESEQNAME = 8,
|
||||
STF_SPRITESEQINDEX = 16,
|
||||
STF_SPRITESEQOFFSET = 24,
|
||||
};
|
||||
|
||||
enum EStateType : int // this must ensure proper alignment.
|
||||
|
@ -161,6 +165,7 @@ struct FDefiningState
|
|||
VMFunction* EnterFunc; // called when entering the state.
|
||||
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;
|
||||
|
|
|
@ -1025,6 +1025,28 @@ void ZCCRazeCompiler::CompileStates()
|
|||
|
||||
int numframes = 0;
|
||||
|
||||
// first set up the AI states so that regular states can 'goto' to them.
|
||||
for (auto& defstate : static_cast<PClassActor*>(c->ClassType())->ActorInfo()->AIStates)
|
||||
{
|
||||
statedef.AddStateLabel(defstate.Label.GetChars());
|
||||
|
||||
FState state;
|
||||
memset(&state, 0, sizeof(state));
|
||||
state.UseFlags = SUF_ACTOR; // AI states are only for actors and nothing else.;
|
||||
state.sprite = defstate.sprite & 0xfffffff;
|
||||
if (defstate.sprite & 0x10000000) state.StateFlags = STF_SPRITESEQINDEX;
|
||||
else if (defstate.sprite & 0x20000000) state.StateFlags = STF_SPRITESEQOFFSET;
|
||||
else state.StateFlags = STF_SPRITESEQNAME;
|
||||
state.Tics = defstate.Tics;
|
||||
//state.? = defstate.Type; // no idea if we will need this.
|
||||
state.ActionFunc = defstate.ActionFunc;
|
||||
state.MoveFunc = defstate.MoveFunc;
|
||||
state.TickFunc = defstate.TickFunc;
|
||||
state.EnterFunc = defstate.EnterFunc;
|
||||
statedef.AddStates(&state, "A", defstate.scriptpos);
|
||||
statedef.SetGotoLabel(defstate.NextStaten.GetChars());
|
||||
}
|
||||
|
||||
for (auto s : c->States)
|
||||
{
|
||||
int flags;
|
||||
|
|
|
@ -818,6 +818,7 @@ DEFINE_PROPERTY(aistate, SSIIGGGGs, CoreActor)
|
|||
if (*seq == 0) state.sprite = 0;
|
||||
else if (*seq == '#') state.sprite = (int)strtoull(seq + 1, &endp, 10) | 0x10000000;
|
||||
else if (*seq == '+') state.sprite = (int)strtoull(seq + 1, &endp, 10) | 0x20000000;
|
||||
else state.sprite = FName(seq).GetIndex();
|
||||
|
||||
state.Label = label;
|
||||
state.Type = type;
|
||||
|
|
Loading…
Reference in a new issue