- moved OwnedStates and NumOwnedStates out of PClassActor.

This commit is contained in:
Christoph Oelckers 2017-04-11 22:44:35 +02:00
commit 4afe2d4218
11 changed files with 37 additions and 41 deletions

View file

@ -10838,16 +10838,16 @@ FxExpression *FxStateByIndex::Resolve(FCompileContext &ctx)
auto aclass = dyn_cast<PClassActor>(ctx.Class);
// This expression type can only be used from actors, for everything else it has already produced a compile error.
assert(aclass != nullptr && aclass->NumOwnedStates > 0);
assert(aclass != nullptr && aclass->ActorInfo()->NumOwnedStates > 0);
if (aclass->NumOwnedStates <= index)
if (aclass->ActorInfo()->NumOwnedStates <= index)
{
ScriptPosition.Message(MSG_ERROR, "%s: Attempt to jump to non existing state index %d",
ctx.Class->TypeName.GetChars(), index);
delete this;
return nullptr;
}
int symlabel = StateLabels.AddPointer(aclass->OwnedStates + index);
int symlabel = StateLabels.AddPointer(aclass->ActorInfo()->OwnedStates + index);
FxExpression *x = new FxConstant(symlabel, ScriptPosition);
x->ValueType = TypeStateLabel;
delete this;
@ -10912,8 +10912,8 @@ FxExpression *FxRuntimeStateIndex::Resolve(FCompileContext &ctx)
SAFE_RESOLVE(Index, ctx);
}
auto aclass = dyn_cast<PClassActor>(ctx.Class);
assert(aclass != nullptr && aclass->NumOwnedStates > 0);
symlabel = StateLabels.AddPointer(aclass->OwnedStates + ctx.StateIndex);
assert(aclass != nullptr && aclass->ActorInfo()->NumOwnedStates > 0);
symlabel = StateLabels.AddPointer(aclass->ActorInfo()->OwnedStates + ctx.StateIndex);
ValueType = TypeStateLabel;
return this;
}

View file

@ -130,8 +130,7 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def, PNamespace *ns)
memset (&extra, 0, sizeof(extra));
ParseInsideDecoration (bag, (AActor *)(type->Defaults), extra, def, sc, StateArray, SourceLines);
bag.Info->NumOwnedStates = StateArray.Size();
if (bag.Info->NumOwnedStates == 0)
if (StateArray.Size() == 0)
{
sc.ScriptError ("%s does not define any animation frames", typeName.GetChars() );
}
@ -155,14 +154,13 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def, PNamespace *ns)
FScriptPosition icepos = SourceLines[extra.IceDeathEnd - 1];
StateArray.Push (icecopy);
SourceLines.Push(icepos);
type->NumOwnedStates += 1;
}
FState *states;
states = type->OwnedStates = (FState*)ClassDataAllocator.Alloc(type->NumOwnedStates * sizeof(FState));
states = type->ActorInfo()->OwnedStates = (FState*)ClassDataAllocator.Alloc(StateArray.Size() * sizeof(FState));
SaveStateSourceLines(states, SourceLines);
memcpy (states, &StateArray[0], type->NumOwnedStates * sizeof(states[0]));
if (type->NumOwnedStates == 1)
memcpy (states, &StateArray[0], StateArray.Size() * sizeof(states[0]));
if (StateArray.Size() == 1)
{
states->Tics = -1;
states->TicRange = 0;
@ -171,7 +169,6 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def, PNamespace *ns)
else
{
size_t i;
// auto
// Spawn states loop endlessly
for (i = extra.SpawnStart; i < extra.SpawnEnd-1; ++i)
@ -281,13 +278,13 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def, PNamespace *ns)
states[i].NextState = &states[i+1];
}
FState *state = &states[i];
state->NextState = &states[type->NumOwnedStates-1];
state->NextState = &states[StateArray.Size() - 1];
state->Tics = 5;
state->TicRange = 0;
state->Misc1 = 0;
state->SetAction("A_FreezeDeath");
i = type->NumOwnedStates - 1;
i = StateArray.Size() - 1;
state->NextState = &states[i];
state->Tics = 1;
state->TicRange = 0;
@ -310,6 +307,7 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def, PNamespace *ns)
}
bag.statedef.SetStateLabel("Spawn", &states[extra.SpawnStart]);
bag.statedef.InstallStates (type, ((AActor *)(type->Defaults)));
bag.Info->ActorInfo()->NumOwnedStates = StateArray.Size();
}
//==========================================================================

View file

@ -353,13 +353,13 @@ static void CheckStates(PClassActor *obj)
{
CheckStateLabels(obj, pickupstates, SUF_ITEM, "CustomInventory state chain");
}
for (int i = 0; i < obj->NumOwnedStates; i++)
for (int i = 0; i < obj->ActorInfo()->NumOwnedStates; i++)
{
auto state = obj->OwnedStates + i;
auto state = obj->ActorInfo()->OwnedStates + i;
if (state->NextState && (state->UseFlags & state->NextState->UseFlags) != state->UseFlags)
{
GetStateSource(state).Message(MSG_ERROR, TEXTCOLOR_RED "State %s.%d links to a state with incompatible restrictions.\n",
obj->TypeName.GetChars(), int(state - obj->OwnedStates));
GetStateSource(state).Message(MSG_ERROR, TEXTCOLOR_RED "State %s links to a state with incompatible restrictions.\n",
FState::StaticGetStateName(state));
}
}
}