From 319f8743dbe99280abfc55ac310a1dbdaee42b50 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 2 Dec 2018 16:53:12 +0100 Subject: [PATCH] - consolidated the check for "is actor an owned inventory item" into a subfunction. This check occured 9 times in the source, better have it only once. --- src/actor.h | 1 + src/c_cmds.cpp | 5 +---- src/d_net.cpp | 2 +- src/fragglescript/t_func.cpp | 14 ++------------ src/fragglescript/t_variable.cpp | 8 ++------ src/p_acs.cpp | 6 ++---- src/p_mobj.cpp | 8 ++++++++ src/p_things.cpp | 8 +++----- 8 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/actor.h b/src/actor.h index dac14a8229..b1a46892e0 100644 --- a/src/actor.h +++ b/src/actor.h @@ -1271,6 +1271,7 @@ public: void UnlinkFromWorld(FLinkContext *ctx); void AdjustFloorClip (); bool InStateSequence(FState * newstate, FState * basestate); + bool IsMapActor(); int GetTics(FState * newstate); bool SetState (FState *newstate, bool nofunction=false); virtual void SplashCheck(); diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp index 18be473e80..57c4c20ea6 100644 --- a/src/c_cmds.cpp +++ b/src/c_cmds.cpp @@ -914,10 +914,7 @@ static bool IsActorACountItem(AActor *mo) // [SP] for all actors static bool IsActor(AActor *mo) { - if (mo->IsKindOf(RUNTIME_CLASS(AInventory))) - return static_cast(mo)->Owner == NULL; // [SP] Exclude inventory-owned items - else - return true; + return mo->IsMapActor(); } // [SP] modified - now allows showing count only, new arg must be passed. Also now still counts regardless, if lists are printed. diff --git a/src/d_net.cpp b/src/d_net.cpp index 609311cb42..583b99ebf0 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2100,7 +2100,7 @@ static int RemoveClass(const PClass *cls) continue; } // [SP] Don't remove owned inventory objects. - if (actor->IsKindOf(RUNTIME_CLASS(AInventory)) && static_cast(actor)->Owner != NULL) + if (!actor->IsMapActor()) { continue; } diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index abfec10334..13f42b4fe5 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -3134,16 +3134,7 @@ void FParser::SF_MapThingNumExist() } else { - // Inventory items in the player's inventory have to be considered non-present. - if (SpawnedThings[intval]->IsKindOf(RUNTIME_CLASS(AInventory)) && - barrier_cast(SpawnedThings[intval])->Owner != NULL) - { - t_return.value.i = 0; - } - else - { - t_return.value.i = 1; - } + t_return.value.i = SpawnedThings[intval]->IsMapActor(); t_return.type = svt_int; } } @@ -3673,8 +3664,7 @@ again: { if (mo->IsA(pClass)) { - if (!mo->IsKindOf (RUNTIME_CLASS(AInventory)) || - static_cast(mo)->Owner == NULL) + if (mo->IsMapActor()) { count++; } diff --git a/src/fragglescript/t_variable.cpp b/src/fragglescript/t_variable.cpp index 47735d26f0..6ece4f22ab 100644 --- a/src/fragglescript/t_variable.cpp +++ b/src/fragglescript/t_variable.cpp @@ -129,9 +129,7 @@ AActor* actorvalue(const svalue_t &svalue) if(svalue.type == svt_mobj) { // Inventory items in the player's inventory have to be considered non-present. - if (svalue.value.mobj != NULL && - svalue.value.mobj->IsKindOf(RUNTIME_CLASS(AInventory)) && - static_cast(svalue.value.mobj)->Owner != NULL) + if (svalue.value.mobj == NULL || !svalue.value.mobj->IsMapActor()) { return NULL; } @@ -150,9 +148,7 @@ AActor* actorvalue(const svalue_t &svalue) return NULL; } // Inventory items in the player's inventory have to be considered non-present. - if (SpawnedThings[intval] != NULL && - SpawnedThings[intval]->IsKindOf(RUNTIME_CLASS(AInventory)) && - barrier_cast(SpawnedThings[intval])->Owner != NULL) + if (svalue.value.mobj == NULL || !svalue.value.mobj->IsMapActor()) { return NULL; } diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 52786b2f94..287db7cde8 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -3697,8 +3697,7 @@ do_count: if (tag == -1 || tagManager.SectorHasTag(actor->Sector, tag)) { // Don't count items in somebody's inventory - if (!actor->IsKindOf (RUNTIME_CLASS(AInventory)) || - static_cast(actor)->Owner == NULL) + if (actor->IsMapActor()) { count++; } @@ -3717,8 +3716,7 @@ do_count: if (tag == -1 || tagManager.SectorHasTag(actor->Sector, tag)) { // Don't count items in somebody's inventory - if (!actor->IsKindOf (RUNTIME_CLASS(AInventory)) || - static_cast(actor)->Owner == NULL) + if (actor->IsMapActor()) { count++; } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 804397a05f..6699354052 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -620,6 +620,14 @@ DEFINE_ACTION_FUNCTION(AActor, InStateSequence) PARAM_POINTER(basestate, FState); ACTION_RETURN_BOOL(self->InStateSequence(newstate, basestate)); } + + +bool AActor::IsMapActor() +{ + // [SP] Don't remove owned inventory objects. + return (!IsKindOf(RUNTIME_CLASS(AInventory)) || static_cast(this)->Owner == nullptr); +} + //========================================================================== // // AActor::GetTics diff --git a/src/p_things.cpp b/src/p_things.cpp index 8b38141d71..4cac8866f4 100644 --- a/src/p_things.cpp +++ b/src/p_things.cpp @@ -423,7 +423,7 @@ void P_RemoveThing(AActor * actor) if (actor->player == NULL || actor != actor->player->mo) { // Don't also remove owned inventory items - if (actor->IsKindOf(RUNTIME_CLASS(AInventory)) && static_cast(actor)->Owner != NULL) return; + if (!actor->IsMapActor()) // be friendly to the level statistics. ;) actor->ClearCounters(); @@ -774,13 +774,11 @@ int P_Thing_CheckProximity(AActor *self, PClass *classname, double distance, int else if (classname != mo->GetClass()) continue; - if (mo->IsKindOf(RUNTIME_CLASS(AInventory))) + if (!mo->IsMapActor()) { // Skip owned item because its position could remain unchanged since attachment to owner // Most likely it is the last location of this item in the world before pick up - AInventory *const inventory = static_cast(mo); - if (inventory != nullptr && inventory->Owner != nullptr) - continue; + continue; } // [MC]Make sure it's in range and respect the desire for Z or not. The function forces it to use