From 23482735a074bf53ef110c0154b3338f6d66f351 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 12 Jan 2017 11:44:33 +0100 Subject: [PATCH] - removed PClassAmmo. No need to maintain these clunky meta class for one single property. The overhead the mere existence of this class creates is far more than 100 spawned ammo items would cost. There is no need to serialize AAmmo::DropAmount, this value has no meaning on an already spawned item. --- src/actor.h | 3 +-- src/d_dehacked.cpp | 10 +++++----- src/d_player.h | 6 +++--- src/dobject.h | 1 - src/dobjtype.cpp | 1 - src/fragglescript/t_func.cpp | 8 ++++---- src/g_inventory/a_ammo.cpp | 16 ---------------- src/g_inventory/a_ammo.h | 16 ++-------------- src/g_inventory/a_weapons.h | 2 +- src/g_shared/shared_hud.cpp | 6 +++--- src/m_cheat.cpp | 2 +- src/p_acs.cpp | 6 +++--- src/p_enemy.cpp | 2 +- src/p_mobj.cpp | 2 +- src/p_user.cpp | 6 +++--- src/scripting/thingdef_properties.cpp | 3 +-- src/win32/zdoom.rc | 2 +- 17 files changed, 30 insertions(+), 62 deletions(-) diff --git a/src/actor.h b/src/actor.h index d4f5f27c5a..a32e15277f 100644 --- a/src/actor.h +++ b/src/actor.h @@ -44,7 +44,6 @@ #include "portal.h" struct subsector_t; -class PClassAmmo; struct FBlockNode; struct FPortalGroupArray; @@ -733,7 +732,7 @@ public: AInventory *FirstInv (); // Tries to give the actor some ammo. - bool GiveAmmo (PClassAmmo *type, int amount); + bool GiveAmmo (PClassInventory *type, int amount); // Destroys all the inventory the actor is holding. void DestroyAllInventory (); diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index f4663f4bf6..4f380ee04a 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -147,7 +147,7 @@ struct StyleName static TArray StyleNames; -static TArray AmmoNames; +static TArray AmmoNames; static TArray WeaponNames; // DeHackEd trickery to support MBF-style parameters @@ -1535,7 +1535,7 @@ static int PatchSprite (int sprNum) static int PatchAmmo (int ammoNum) { - PClassAmmo *ammoType = NULL; + PClassActor *ammoType = NULL; AAmmo *defaultAmmo = NULL; int result; int oldclip; @@ -1670,7 +1670,7 @@ static int PatchWeapon (int weapNum) { val = 5; } - info->AmmoType1 = AmmoNames[val]; + info->AmmoType1 = (PClassInventory*)AmmoNames[val]; if (info->AmmoType1 != NULL) { info->AmmoGive1 = ((AAmmo*)GetDefaultByType (info->AmmoType1))->Amount * 2; @@ -2929,8 +2929,8 @@ static bool LoadDehSupp () } else { - PClassAmmo *cls = dyn_cast(PClass::FindClass(sc.String)); - if (cls == NULL) + auto cls = PClass::FindActor(sc.String); + if (cls == NULL || !cls->IsDescendantOf(RUNTIME_CLASS(AAmmo))) { sc.ScriptError("Unknown ammo type '%s'", sc.String); } diff --git a/src/d_player.h b/src/d_player.h index 81a1c43a69..16bcb18059 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -120,9 +120,9 @@ public: void TweakSpeeds (double &forwardmove, double &sidemove); void MorphPlayerThink (); void ActivateMorphWeapon (); - AWeapon *PickNewWeapon (PClassAmmo *ammotype); - AWeapon *BestWeapon (PClassAmmo *ammotype); - void CheckWeaponSwitch(PClassAmmo *ammotype); + AWeapon *PickNewWeapon (PClassInventory *ammotype); + AWeapon *BestWeapon (PClassInventory *ammotype); + void CheckWeaponSwitch(PClassInventory *ammotype); void GiveDeathmatchInventory (); void FilterCoopRespawnInventory (APlayerPawn *oldplayer); diff --git a/src/dobject.h b/src/dobject.h index ed9c0fffa9..4fe7346f08 100644 --- a/src/dobject.h +++ b/src/dobject.h @@ -94,7 +94,6 @@ enum CLASSREG_PClass, CLASSREG_PClassActor, CLASSREG_PClassInventory, - CLASSREG_PClassAmmo, CLASSREG_PClassHealth, CLASSREG_PClassPuzzleItem, CLASSREG_PClassWeapon, diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 3abdd58009..99071c5208 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -3090,7 +3090,6 @@ PClass *ClassReg::RegisterClass() &PClass::RegistrationInfo, &PClassActor::RegistrationInfo, &PClassInventory::RegistrationInfo, - &PClassAmmo::RegistrationInfo, &PClassHealth::RegistrationInfo, &PClassPuzzleItem::RegistrationInfo, &PClassWeapon::RegistrationInfo, diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 514d9aaea9..6d656cbcec 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -341,7 +341,7 @@ inline int T_FindFirstSectorFromTag(int tagnum) // Doom index is only supported for the 4 original ammo types // //========================================================================== -static PClassAmmo * T_GetAmmo(const svalue_t &t) +static PClassInventory * T_GetAmmo(const svalue_t &t) { const char * p; @@ -362,7 +362,7 @@ static PClassAmmo * T_GetAmmo(const svalue_t &t) } p=DefAmmo[ammonum]; } - PClassAmmo * am=dyn_cast(PClass::FindActor(p)); + PClassInventory * am=dyn_cast(PClass::FindActor(p)); if (am == NULL) { script_error("unknown ammo type : %s", p); @@ -2572,7 +2572,7 @@ void FParser::SF_PlayerKeys(void) void FParser::SF_PlayerAmmo(void) { int playernum, amount; - PClassAmmo * ammotype; + PClassInventory * ammotype; if (CheckArgs(2)) { @@ -2608,7 +2608,7 @@ void FParser::SF_PlayerAmmo(void) void FParser::SF_MaxPlayerAmmo() { int playernum, amount; - PClassAmmo * ammotype; + PClassInventory * ammotype; if (CheckArgs(2)) { diff --git a/src/g_inventory/a_ammo.cpp b/src/g_inventory/a_ammo.cpp index 23a9221874..6ef2c64d4f 100644 --- a/src/g_inventory/a_ammo.cpp +++ b/src/g_inventory/a_ammo.cpp @@ -37,22 +37,6 @@ #include "d_player.h" #include "serializer.h" -IMPLEMENT_CLASS(PClassAmmo, false, false) - -PClassAmmo::PClassAmmo() -{ - DropAmount = 0; -} - -void PClassAmmo::DeriveData(PClass *newclass) -{ - assert(newclass->IsKindOf(RUNTIME_CLASS(PClassAmmo))); - Super::DeriveData(newclass); - PClassAmmo *newc = static_cast(newclass); - - newc->DropAmount = DropAmount; -} - IMPLEMENT_CLASS(AAmmo, false, false) DEFINE_FIELD(AAmmo, BackpackAmount) diff --git a/src/g_inventory/a_ammo.h b/src/g_inventory/a_ammo.h index 643d4b9248..d74f1405a2 100644 --- a/src/g_inventory/a_ammo.h +++ b/src/g_inventory/a_ammo.h @@ -1,21 +1,9 @@ #pragma once #include "a_pickups.h" -// Ammo: Something a weapon needs to operate -class PClassAmmo : public PClassInventory -{ - DECLARE_CLASS(PClassAmmo, PClassInventory) -protected: - virtual void DeriveData(PClass *newclass); -public: - PClassAmmo(); - - int DropAmount; // Specifies the amount for a dropped ammo item. -}; - class AAmmo : public AInventory { - DECLARE_CLASS_WITH_META(AAmmo, AInventory, PClassAmmo) + DECLARE_CLASS(AAmmo, AInventory) public: virtual void Serialize(FSerializer &arc) override; @@ -24,7 +12,7 @@ public: virtual AInventory *CreateTossable () override; PClassActor *GetParentAmmo () const; - int BackpackAmount, BackpackMaxAmount; + int BackpackAmount, BackpackMaxAmount, DropAmount; }; diff --git a/src/g_inventory/a_weapons.h b/src/g_inventory/a_weapons.h index 1b12584012..8913963cc2 100644 --- a/src/g_inventory/a_weapons.h +++ b/src/g_inventory/a_weapons.h @@ -107,7 +107,7 @@ class AWeapon : public AStateProvider HAS_OBJECT_POINTERS public: DWORD WeaponFlags; - PClassAmmo *AmmoType1, *AmmoType2; // Types of ammo used by this weapon + PClassInventory *AmmoType1, *AmmoType2; // Types of ammo used by this weapon int AmmoGive1, AmmoGive2; // Amount of each ammo to get when picking up weapon int MinAmmo1, MinAmmo2; // Minimum ammo needed to switch to this weapon int AmmoUse1, AmmoUse2; // How much ammo to use with each shot diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index 0c9b74255d..b645ac511e 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -517,14 +517,14 @@ static int DrawKeys(player_t * CPlayer, int x, int y) // Drawing Ammo // //--------------------------------------------------------------------------- -static TArray orderedammos; +static TArray orderedammos; static void AddAmmoToList(AWeapon * weapdef) { for(int i=0; i<2;i++) { - PClassAmmo * ti = i==0? weapdef->AmmoType1 : weapdef->AmmoType2; + PClassInventory * ti = i==0? weapdef->AmmoType1 : weapdef->AmmoType2; if (ti) { AAmmo * ammodef=(AAmmo*)GetDefaultByType(ti); @@ -647,7 +647,7 @@ static int DrawAmmo(player_t *CPlayer, int x, int y) for(i=orderedammos.Size()-1;i>=0;i--) { - PClassAmmo * type = orderedammos[i]; + PClassInventory * type = orderedammos[i]; AAmmo * ammoitem = (AAmmo*)CPlayer->mo->FindInventory(type); AAmmo * inv = ammoitem? ammoitem : (AAmmo*)GetDefaultByType(orderedammos[i]); diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index 414fafba90..36c6249cd1 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -646,7 +646,7 @@ void cht_Give (player_t *player, const char *name, int amount) if (type->ParentClass == RUNTIME_CLASS(AAmmo)) { - PClassAmmo *atype = static_cast(type); + PClassInventory *atype = static_cast(type); AInventory *ammo = player->mo->FindInventory(atype); if (ammo == NULL) { diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 3fb7ea314d..5355b10a08 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -8720,19 +8720,19 @@ scriptwait: case PCD_SETAMMOCAPACITY: if (activator != NULL) { - PClass *type = PClass::FindClass (FBehavior::StaticLookupString (STACK(2))); + PClassActor *type = PClass::FindActor (FBehavior::StaticLookupString (STACK(2))); AInventory *item; if (type != NULL && type->ParentClass == RUNTIME_CLASS(AAmmo)) { - item = activator->FindInventory (static_cast(type)); + item = activator->FindInventory (type); if (item != NULL) { item->MaxAmount = STACK(1); } else { - item = activator->GiveInventoryType (static_cast(type)); + item = activator->GiveInventoryType (type); if (item != NULL) { item->MaxAmount = STACK(1); diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index ac4e0f04b6..1587ef9f8e 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -3241,7 +3241,7 @@ void ModifyDropAmount(AInventory *inv, int dropamount) else if (inv->IsKindOf (RUNTIME_CLASS(AAmmo))) { // Half ammo when dropped by bad guys. - int amount = static_cast(inv->GetClass())->DropAmount; + int amount = static_cast(inv)->DropAmount; if (amount <= 0) { amount = MAX(1, int(inv->Amount * dropammofactor)); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index d5ec020a05..80545bb141 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -1134,7 +1134,7 @@ DEFINE_ACTION_FUNCTION(AActor, GiveInventoryType) // //============================================================================ -bool AActor::GiveAmmo (PClassAmmo *type, int amount) +bool AActor::GiveAmmo (PClassInventory *type, int amount) { if (type != NULL) { diff --git a/src/p_user.cpp b/src/p_user.cpp index 662e60a289..98bc1ca16a 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -942,7 +942,7 @@ bool APlayerPawn::UseInventory (AInventory *item) // //=========================================================================== -AWeapon *APlayerPawn::BestWeapon(PClassAmmo *ammotype) +AWeapon *APlayerPawn::BestWeapon(PClassInventory *ammotype) { AWeapon *bestMatch = NULL; int bestOrder = INT_MAX; @@ -1004,7 +1004,7 @@ AWeapon *APlayerPawn::BestWeapon(PClassAmmo *ammotype) // //=========================================================================== -AWeapon *APlayerPawn::PickNewWeapon(PClassAmmo *ammotype) +AWeapon *APlayerPawn::PickNewWeapon(PClassInventory *ammotype) { AWeapon *best = BestWeapon (ammotype); @@ -1032,7 +1032,7 @@ AWeapon *APlayerPawn::PickNewWeapon(PClassAmmo *ammotype) // //=========================================================================== -void APlayerPawn::CheckWeaponSwitch(PClassAmmo *ammotype) +void APlayerPawn::CheckWeaponSwitch(PClassInventory *ammotype) { if (!player->userinfo.GetNeverSwitch() && player->PendingWeapon == WP_NOCHANGE && diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index c4c44a7091..32f7dd622d 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -1723,8 +1723,7 @@ DEFINE_CLASS_PROPERTY(backpackmaxamount, I, Ammo) DEFINE_CLASS_PROPERTY(dropamount, I, Ammo) { PROP_INT_PARM(i, 0); - assert(info->IsKindOf(RUNTIME_CLASS(PClassAmmo))); - static_cast(info)->DropAmount = i; + defaults->DropAmount = i; } //========================================================================== diff --git a/src/win32/zdoom.rc b/src/win32/zdoom.rc index 70175cc167..3a1b52d571 100644 --- a/src/win32/zdoom.rc +++ b/src/win32/zdoom.rc @@ -258,7 +258,7 @@ FONT 8, "MS Shell Dlg" CONTROL "Load lights", IDC_WELCOME_LIGHTS, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 130, 180, 51, 10 CONTROL "Load brightmaps", IDC_WELCOME_BRIGHTMAPS, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 130, 190, 65, 10 CONTROL "Don't ask me this again", IDC_DONTASKIWAD, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 73, 211, 87, 10 - CONTROL "Play QZDoom", IDOK, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 8, 228, 90, 14 + CONTROL "Play GZDoom", IDOK, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 8, 228, 90, 14 CONTROL "Exit", IDCANCEL, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 166, 228, 50, 14 }