From 4afe2d4218b311b2e6b856de2ed7ff822e4bbaf1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 11 Apr 2017 22:44:35 +0200 Subject: [PATCH] - moved OwnedStates and NumOwnedStates out of PClassActor. --- src/d_dehacked.cpp | 2 +- src/gl/textures/gl_texture.cpp | 7 ++++--- src/info.cpp | 6 +----- src/info.h | 7 ++++--- src/p_actionfunctions.cpp | 4 ++-- src/p_states.cpp | 8 ++++---- src/scripting/backend/codegen.cpp | 10 +++++----- src/scripting/decorate/olddecorations.cpp | 16 +++++++--------- src/scripting/thingdef.cpp | 8 ++++---- src/serializer.cpp | 6 +++--- src/swrenderer/r_swrenderer.cpp | 4 ++-- 11 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index b050bd48c..affe344cb 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -2843,7 +2843,7 @@ static bool LoadDehSupp () sc.MustGetStringName(","); sc.MustGetNumber(); - if (s.State == NULL || s.State + sc.Number > actortype->OwnedStates + actortype->NumOwnedStates) + if (s.State == NULL || !actortype->OwnsState(s.State + sc.Number)) { sc.ScriptError("Invalid state range in '%s'", type->TypeName.GetChars()); } diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index bef0da5d5..a7260879b 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -841,10 +841,11 @@ void gl_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl PClassActor *cls = pair->Key; int gltrans = GLTranslationPalette::GetInternalTranslation(GetDefaultByType(cls)->Translation); - for (int i = 0; i < cls->NumOwnedStates; i++) + for (int i = 0; i < cls->ActorInfo()->NumOwnedStates; i++) { - spritelist[cls->OwnedStates[i].sprite].Insert(gltrans, true); - FSpriteModelFrame * smf = gl_FindModelFrame(cls, cls->OwnedStates[i].sprite, cls->OwnedStates[i].Frame, false); + auto &state = cls->ActorInfo()->OwnedStates[i]; + spritelist[state.sprite].Insert(gltrans, true); + FSpriteModelFrame * smf = gl_FindModelFrame(cls, state.sprite, state.Frame, false); if (smf != NULL) { for (int i = 0; i < MAX_MODELS_PER_FRAME; i++) diff --git a/src/info.cpp b/src/info.cpp index 23c7fb7cc..55369555f 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -162,15 +162,13 @@ bool FState::CallAction(AActor *self, AActor *stateowner, FStateParamInfo *info, catch (CVMAbortException &err) { err.MaybePrintMessage(); - auto owner = FState::StaticFindStateOwner(this); - int offs = int(this - owner->OwnedStates); const char *callinfo = ""; if (info != nullptr && info->mStateType == STATE_Psprite) { if (stateowner->IsKindOf(NAME_Weapon) && stateowner != self) callinfo = "weapon "; else callinfo = "overlay "; } - err.stacktrace.AppendFormat("Called from %sstate %s.%d in %s\n", callinfo, owner->TypeName.GetChars(), offs, stateowner->GetClass()->TypeName.GetChars()); + err.stacktrace.AppendFormat("Called from %sstate %s in %s\n", callinfo, FState::StaticGetStateName(this), stateowner->GetClass()->TypeName.GetChars()); throw; throw; } @@ -299,8 +297,6 @@ PClassActor::PClassActor() GameFilter = GAME_Any; SpawnID = 0; DoomEdNum = -1; - OwnedStates = NULL; - NumOwnedStates = 0; StateList = NULL; DamageFactors = NULL; PainChances = NULL; diff --git a/src/info.h b/src/info.h index 466e925cb..935d62907 100644 --- a/src/info.h +++ b/src/info.h @@ -242,6 +242,8 @@ struct FActorInfo TArray LightAssociations; PClassActor *Replacement = nullptr; PClassActor *Replacee = nullptr; + FState *OwnedStates = nullptr; + int NumOwnedStates = 0; FActorInfo() {} FActorInfo(const FActorInfo & other) @@ -284,14 +286,13 @@ public: bool OwnsState(const FState *state) { - return state >= OwnedStates && state < OwnedStates + NumOwnedStates; + auto i = ActorInfo(); + return state >= i->OwnedStates && state < i->OwnedStates + i->NumOwnedStates; } PClassActor *GetReplacement(bool lookskill=true); PClassActor *GetReplacee(bool lookskill=true); - FState *OwnedStates; - int NumOwnedStates; uint8_t GameFilter; uint8_t DefaultStateUsage; // state flag defaults for blocks without a qualifier. uint16_t SpawnID; diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 657a89bb3..5ffc88384 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -3317,9 +3317,9 @@ DEFINE_ACTION_FUNCTION(AActor, A_SpawnDebris) { mo->Translation = self->Translation; } - if (i < mo->GetClass()->NumOwnedStates) + if (i < mo->GetInfo()->NumOwnedStates) { - mo->SetState (mo->GetClass()->OwnedStates + i); + mo->SetState (mo->GetInfo()->OwnedStates + i); } mo->Vel.X = mult_h * pr_spawndebris.Random2() / 64.; mo->Vel.Y = mult_h * pr_spawndebris.Random2() / 64.; diff --git a/src/p_states.cpp b/src/p_states.cpp index 731cbed9c..b6593613a 100644 --- a/src/p_states.cpp +++ b/src/p_states.cpp @@ -133,7 +133,7 @@ PClassActor *FState::StaticFindStateOwner (const FState *state, PClassActor *inf FString FState::StaticGetStateName(const FState *state) { auto so = FState::StaticFindStateOwner(state); - return FStringf("%s.%d", so->TypeName.GetChars(), int(state - so->OwnedStates)); + return FStringf("%s.%d", so->TypeName.GetChars(), int(state - so->ActorInfo()->OwnedStates)); } //========================================================================== @@ -816,7 +816,7 @@ void FStateDefinitions::FixStatePointers (PClassActor *actor, TArrayOwnedStates + v - 1; + list[i].State = actor->ActorInfo()->OwnedStates + v - 1; list[i].DefineFlags = SDF_STATE; } if (list[i].Children.Size() > 0) @@ -1012,8 +1012,8 @@ int FStateDefinitions::FinishStates(PClassActor *actor, AActor *defaults) int i; memcpy(realstates, &StateArray[0], count*sizeof(FState)); - actor->OwnedStates = realstates; - actor->NumOwnedStates = count; + actor->ActorInfo()->OwnedStates = realstates; + actor->ActorInfo()->NumOwnedStates = count; SaveStateSourceLines(realstates, SourceLines); // adjust the state pointers diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 4327bde9d..6b38999d3 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -10838,16 +10838,16 @@ FxExpression *FxStateByIndex::Resolve(FCompileContext &ctx) auto aclass = dyn_cast(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(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; } diff --git a/src/scripting/decorate/olddecorations.cpp b/src/scripting/decorate/olddecorations.cpp index b9c618971..3cf2c4f7d 100644 --- a/src/scripting/decorate/olddecorations.cpp +++ b/src/scripting/decorate/olddecorations.cpp @@ -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(); } //========================================================================== diff --git a/src/scripting/thingdef.cpp b/src/scripting/thingdef.cpp index 0cb25b1c2..0b7e35aba 100644 --- a/src/scripting/thingdef.cpp +++ b/src/scripting/thingdef.cpp @@ -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)); } } } diff --git a/src/serializer.cpp b/src/serializer.cpp index f514449ac..d5b3e286b 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -1877,7 +1877,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState { arc.w->StartArray(); arc.w->String(info->TypeName.GetChars()); - arc.w->Uint((uint32_t)(state - info->OwnedStates)); + arc.w->Uint((uint32_t)(state - info->ActorInfo()->OwnedStates)); arc.w->EndArray(); } else @@ -1908,9 +1908,9 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState if (cls.IsString() && ndx.IsUint()) { PClassActor *clas = PClass::FindActor(UnicodeToString(cls.GetString())); - if (clas && ndx.GetUint() < (unsigned)clas->NumOwnedStates) + if (clas && ndx.GetUint() < (unsigned)clas->ActorInfo()->NumOwnedStates) { - state = clas->OwnedStates + ndx.GetUint(); + state = clas->ActorInfo()->OwnedStates + ndx.GetUint(); } else { diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index 0564dcfcf..11f4d801b 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -132,9 +132,9 @@ void FSoftwareRenderer::Precache(uint8_t *texhitlist, TMap & { PClassActor *cls = pair->Key; - for (int i = 0; i < cls->NumOwnedStates; i++) + for (int i = 0; i < cls->ActorInfo()->NumOwnedStates; i++) { - spritelist[cls->OwnedStates[i].sprite] = true; + spritelist[cls->ActorInfo()->OwnedStates[i].sprite] = true; } }