From 9c9b2ccf6d341296100b4effe52fa8a92468fed2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 12 Apr 2017 10:20:58 +0200 Subject: [PATCH] - replaced more dyn_casts and checks for RUNTIME_CLASS(PClassActor) It is preferable to use IsDescendantOf wherever possible if we ever want to be able to separate PClass from PType. --- src/actor.h | 11 +++++++++++ src/d_dehacked.cpp | 2 +- src/d_net.cpp | 2 +- src/dobject.cpp | 2 +- src/dobjtype.cpp | 2 +- src/info.h | 5 ----- src/p_acs.cpp | 3 +-- src/p_conversation.cpp | 6 +++--- src/p_mobj.cpp | 4 ++-- src/p_states.cpp | 4 ++-- src/scripting/backend/codegen.cpp | 2 +- src/scripting/decorate/thingdef_parse.cpp | 4 ++-- src/scripting/zscript/zcc_compile.cpp | 4 ++-- 13 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/actor.h b/src/actor.h index a856103dd..7a7e55518 100644 --- a/src/actor.h +++ b/src/actor.h @@ -1572,6 +1572,17 @@ template inline T *Spawn() // for inventory items we do not need coordi return static_cast(AActor::StaticSpawn(RUNTIME_TEMPLATE_CLASS(T), DVector3(0, 0, 0), NO_REPLACE)); } +inline PClassActor *PClass::FindActor(FName name) +{ + auto cls = FindClass(name); + return cls && cls->IsDescendantOf(RUNTIME_CLASS(AActor)) ? static_cast(cls) : nullptr; +} + +inline PClassActor *ValidateActor(PClass *cls) +{ + return cls && cls->IsDescendantOf(RUNTIME_CLASS(AActor)) ? static_cast(cls) : nullptr; +} + void PrintMiscActorInfo(AActor * query); AActor *P_LinePickActor(AActor *t1, DAngle angle, double distance, DAngle pitch, ActorFlags actorMask, uint32_t wallMask); diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 0a360648b..8bb16a687 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -2827,7 +2827,7 @@ static bool LoadDehSupp () { sc.ScriptError ("Can't find type %s", sc.String); } - else if (!type->IsKindOf(RUNTIME_CLASS(PClassActor))) + else if (!type->IsDescendantOf(RUNTIME_CLASS(AActor))) { sc.ScriptError ("%s is not an actor", sc.String); } diff --git a/src/d_net.cpp b/src/d_net.cpp index 0af1bd9c1..12449111a 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2592,7 +2592,7 @@ void Net_DoCommand (int type, uint8_t **stream, int player) char *classname = ReadString(stream); int removecount = 0; PClassActor *cls = PClass::FindActor(classname); - if (cls != NULL && cls->IsKindOf(RUNTIME_CLASS(PClassActor))) + if (cls != NULL && cls->IsDescendantOf(RUNTIME_CLASS(AActor))) { removecount = RemoveClass(cls); const PClass *cls_rep = cls->GetReplacement(); diff --git a/src/dobject.cpp b/src/dobject.cpp index 95dc5980e..a28ff62fc 100644 --- a/src/dobject.cpp +++ b/src/dobject.cpp @@ -95,7 +95,7 @@ CCMD (dumpactors) for (unsigned int i = 0; i < PClass::AllClasses.Size(); i++) { PClass *cls = PClass::AllClasses[i]; - PClassActor *acls = dyn_cast(cls); + PClassActor *acls = ValidateActor(cls); if (acls != NULL) { auto ainfo = acls->ActorInfo(); diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 9f8b88deb..88b6aa9e4 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -3229,7 +3229,7 @@ void PClass::Derive(PClass *newclass, FName name) void PClass::InitializeDefaults() { - if (IsKindOf(RUNTIME_CLASS(PClassActor))) + if (IsDescendantOf(RUNTIME_CLASS(AActor))) { assert(Defaults == nullptr); Defaults = (uint8_t *)M_Malloc(Size); diff --git a/src/info.h b/src/info.h index 6be614aa7..907b9a3b2 100644 --- a/src/info.h +++ b/src/info.h @@ -354,11 +354,6 @@ public: static TArray AllActorClasses; }; -inline PClassActor *PClass::FindActor(FName name) -{ - return dyn_cast(FindClass(name)); -} - struct FDoomEdEntry { PClassActor *Type; diff --git a/src/p_acs.cpp b/src/p_acs.cpp index f9e0f58e7..f198f7e10 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -9777,8 +9777,7 @@ scriptwait: } else { - AInventory *item = activator->FindInventory (dyn_cast( - PClass::FindClass (FBehavior::StaticLookupString (STACK(1))))); + AInventory *item = activator->FindInventory (PClass::FindActor (FBehavior::StaticLookupString (STACK(1)))); if (item == NULL || !item->IsKindOf(NAME_Weapon)) { diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index d01fb5193..0e734479a 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -367,7 +367,7 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpea node->SpeakerName = speech.Name; // The item the speaker should drop when killed. - node->DropType = dyn_cast(GetStrifeType(speech.DropType)); + node->DropType = GetStrifeType(speech.DropType); // Items you need to have to make the speaker use a different node. node->ItemCheck.Resize(3); @@ -447,7 +447,7 @@ static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpea node->SpeakerName = speech.Name; // The item the speaker should drop when killed. - node->DropType = dyn_cast(GetStrifeType (speech.DropType)); + node->DropType = GetStrifeType (speech.DropType); // Items you need to have to make the speaker use a different node. node->ItemCheck.Resize(3); @@ -512,7 +512,7 @@ static void ParseReplies (FStrifeDialogueReply **replyptr, Response *responses) reply->LogString = ""; // The item to receive when this reply is used. - reply->GiveType = dyn_cast(GetStrifeType (rsp->GiveType)); + reply->GiveType = GetStrifeType (rsp->GiveType); reply->ActionSpecial = 0; // Do you need anything special for this reply to succeed? diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 30e462b10..f702606ce 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -5041,7 +5041,7 @@ PClassActor *ClassForSpawn(FName classname) { I_Error("Attempt to spawn actor of unknown type '%s'\n", classname.GetChars()); } - if (!cls->IsKindOf(RUNTIME_CLASS(PClassActor))) + if (!cls->IsDescendantOf(RUNTIME_CLASS(AActor))) { I_Error("Attempt to spawn non-actor of type '%s'\n", classname.GetChars()); } @@ -5863,7 +5863,7 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position) Printf ("%s at (%.1f, %.1f) has no frames\n", i->TypeName.GetChars(), mthing->pos.X, mthing->pos.Y); i = PClass::FindActor("Unknown"); - assert(i->IsKindOf(RUNTIME_CLASS(PClassActor))); + assert(i->IsDescendantOf(RUNTIME_CLASS(AActor))); } const AActor *info = GetDefaultByType (i); diff --git a/src/p_states.cpp b/src/p_states.cpp index 8d10cc7a9..fae4e13df 100644 --- a/src/p_states.cpp +++ b/src/p_states.cpp @@ -120,7 +120,7 @@ PClassActor *FState::StaticFindStateOwner (const FState *state, PClassActor *inf { return info; } - info = dyn_cast(info->ParentClass); + info = ValidateActor(info->ParentClass); } return NULL; } @@ -739,7 +739,7 @@ FState *FStateDefinitions::ResolveGotoLabel (AActor *actor, PClassActor *mytype, // superclass, or it may be the name of any class that this one derives from. if (stricmp (classname, "Super") == 0) { - type = dyn_cast(type->ParentClass); + type = ValidateActor(type->ParentClass); actor = GetDefaultByType(type); } else diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 7f2db4d77..66f9f308e 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -10982,7 +10982,7 @@ FxExpression *FxMultiNameState::Resolve(FCompileContext &ctx) } else if (names[0] == NAME_Super) { - scope = dyn_cast(clstype->ParentClass); + scope = ValidateActor(clstype->ParentClass); } else { diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index 8950a7067..adda5b0e9 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -582,7 +582,7 @@ static FState *CheckState(FScanner &sc, PClass *type) FState *state = NULL; sc.MustGetString(); - PClassActor *info = dyn_cast(type->ParentClass); + PClassActor *info = ValidateActor(type->ParentClass); if (info != NULL) { @@ -999,7 +999,7 @@ PClassActor *CreateNewActor(const FScriptPosition &sc, FName typeName, FName par sc.Message(MSG_ERROR, "'%s' inherits from a class with the same name", typeName.GetChars()); break; } - p = dyn_cast(p->ParentClass); + p = ValidateActor(p->ParentClass); } if (parent == NULL) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 0feda59e6..572e5a422 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -1385,7 +1385,7 @@ void ZCCCompiler::CompileAllProperties() bool ZCCCompiler::CompileProperties(PClass *type, TArray &Properties, FName prefix) { - if (!type->IsKindOf(RUNTIME_CLASS(PClassActor))) + if (!type->IsDescendantOf(RUNTIME_CLASS(AActor))) { Error(Properties[0], "Properties can only be defined for actors"); return false; @@ -2850,7 +2850,7 @@ void ZCCCompiler::CompileStates() FString statename; // The state builder wants the label as one complete string, not separated into tokens. FStateDefinitions statedef; - statedef.MakeStateDefines(dyn_cast(c->Type()->ParentClass)); + statedef.MakeStateDefines(ValidateActor(c->Type()->ParentClass)); int numframes = 0; for (auto s : c->States)