- 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.
This commit is contained in:
Christoph Oelckers 2017-01-12 11:44:33 +01:00
parent da43576035
commit 23482735a0
17 changed files with 30 additions and 62 deletions

View File

@ -44,7 +44,6 @@
#include "portal.h" #include "portal.h"
struct subsector_t; struct subsector_t;
class PClassAmmo;
struct FBlockNode; struct FBlockNode;
struct FPortalGroupArray; struct FPortalGroupArray;
@ -733,7 +732,7 @@ public:
AInventory *FirstInv (); AInventory *FirstInv ();
// Tries to give the actor some ammo. // 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. // Destroys all the inventory the actor is holding.
void DestroyAllInventory (); void DestroyAllInventory ();

View File

@ -147,7 +147,7 @@ struct StyleName
static TArray<StyleName> StyleNames; static TArray<StyleName> StyleNames;
static TArray<PClassAmmo *> AmmoNames; static TArray<PClassActor *> AmmoNames;
static TArray<PClassActor *> WeaponNames; static TArray<PClassActor *> WeaponNames;
// DeHackEd trickery to support MBF-style parameters // DeHackEd trickery to support MBF-style parameters
@ -1535,7 +1535,7 @@ static int PatchSprite (int sprNum)
static int PatchAmmo (int ammoNum) static int PatchAmmo (int ammoNum)
{ {
PClassAmmo *ammoType = NULL; PClassActor *ammoType = NULL;
AAmmo *defaultAmmo = NULL; AAmmo *defaultAmmo = NULL;
int result; int result;
int oldclip; int oldclip;
@ -1670,7 +1670,7 @@ static int PatchWeapon (int weapNum)
{ {
val = 5; val = 5;
} }
info->AmmoType1 = AmmoNames[val]; info->AmmoType1 = (PClassInventory*)AmmoNames[val];
if (info->AmmoType1 != NULL) if (info->AmmoType1 != NULL)
{ {
info->AmmoGive1 = ((AAmmo*)GetDefaultByType (info->AmmoType1))->Amount * 2; info->AmmoGive1 = ((AAmmo*)GetDefaultByType (info->AmmoType1))->Amount * 2;
@ -2929,8 +2929,8 @@ static bool LoadDehSupp ()
} }
else else
{ {
PClassAmmo *cls = dyn_cast<PClassAmmo>(PClass::FindClass(sc.String)); auto cls = PClass::FindActor(sc.String);
if (cls == NULL) if (cls == NULL || !cls->IsDescendantOf(RUNTIME_CLASS(AAmmo)))
{ {
sc.ScriptError("Unknown ammo type '%s'", sc.String); sc.ScriptError("Unknown ammo type '%s'", sc.String);
} }

View File

@ -120,9 +120,9 @@ public:
void TweakSpeeds (double &forwardmove, double &sidemove); void TweakSpeeds (double &forwardmove, double &sidemove);
void MorphPlayerThink (); void MorphPlayerThink ();
void ActivateMorphWeapon (); void ActivateMorphWeapon ();
AWeapon *PickNewWeapon (PClassAmmo *ammotype); AWeapon *PickNewWeapon (PClassInventory *ammotype);
AWeapon *BestWeapon (PClassAmmo *ammotype); AWeapon *BestWeapon (PClassInventory *ammotype);
void CheckWeaponSwitch(PClassAmmo *ammotype); void CheckWeaponSwitch(PClassInventory *ammotype);
void GiveDeathmatchInventory (); void GiveDeathmatchInventory ();
void FilterCoopRespawnInventory (APlayerPawn *oldplayer); void FilterCoopRespawnInventory (APlayerPawn *oldplayer);

View File

@ -94,7 +94,6 @@ enum
CLASSREG_PClass, CLASSREG_PClass,
CLASSREG_PClassActor, CLASSREG_PClassActor,
CLASSREG_PClassInventory, CLASSREG_PClassInventory,
CLASSREG_PClassAmmo,
CLASSREG_PClassHealth, CLASSREG_PClassHealth,
CLASSREG_PClassPuzzleItem, CLASSREG_PClassPuzzleItem,
CLASSREG_PClassWeapon, CLASSREG_PClassWeapon,

View File

@ -3090,7 +3090,6 @@ PClass *ClassReg::RegisterClass()
&PClass::RegistrationInfo, &PClass::RegistrationInfo,
&PClassActor::RegistrationInfo, &PClassActor::RegistrationInfo,
&PClassInventory::RegistrationInfo, &PClassInventory::RegistrationInfo,
&PClassAmmo::RegistrationInfo,
&PClassHealth::RegistrationInfo, &PClassHealth::RegistrationInfo,
&PClassPuzzleItem::RegistrationInfo, &PClassPuzzleItem::RegistrationInfo,
&PClassWeapon::RegistrationInfo, &PClassWeapon::RegistrationInfo,

View File

@ -341,7 +341,7 @@ inline int T_FindFirstSectorFromTag(int tagnum)
// Doom index is only supported for the 4 original ammo types // 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; const char * p;
@ -362,7 +362,7 @@ static PClassAmmo * T_GetAmmo(const svalue_t &t)
} }
p=DefAmmo[ammonum]; p=DefAmmo[ammonum];
} }
PClassAmmo * am=dyn_cast<PClassAmmo>(PClass::FindActor(p)); PClassInventory * am=dyn_cast<PClassInventory>(PClass::FindActor(p));
if (am == NULL) if (am == NULL)
{ {
script_error("unknown ammo type : %s", p); script_error("unknown ammo type : %s", p);
@ -2572,7 +2572,7 @@ void FParser::SF_PlayerKeys(void)
void FParser::SF_PlayerAmmo(void) void FParser::SF_PlayerAmmo(void)
{ {
int playernum, amount; int playernum, amount;
PClassAmmo * ammotype; PClassInventory * ammotype;
if (CheckArgs(2)) if (CheckArgs(2))
{ {
@ -2608,7 +2608,7 @@ void FParser::SF_PlayerAmmo(void)
void FParser::SF_MaxPlayerAmmo() void FParser::SF_MaxPlayerAmmo()
{ {
int playernum, amount; int playernum, amount;
PClassAmmo * ammotype; PClassInventory * ammotype;
if (CheckArgs(2)) if (CheckArgs(2))
{ {

View File

@ -37,22 +37,6 @@
#include "d_player.h" #include "d_player.h"
#include "serializer.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<PClassAmmo *>(newclass);
newc->DropAmount = DropAmount;
}
IMPLEMENT_CLASS(AAmmo, false, false) IMPLEMENT_CLASS(AAmmo, false, false)
DEFINE_FIELD(AAmmo, BackpackAmount) DEFINE_FIELD(AAmmo, BackpackAmount)

View File

@ -1,21 +1,9 @@
#pragma once #pragma once
#include "a_pickups.h" #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 class AAmmo : public AInventory
{ {
DECLARE_CLASS_WITH_META(AAmmo, AInventory, PClassAmmo) DECLARE_CLASS(AAmmo, AInventory)
public: public:
virtual void Serialize(FSerializer &arc) override; virtual void Serialize(FSerializer &arc) override;
@ -24,7 +12,7 @@ public:
virtual AInventory *CreateTossable () override; virtual AInventory *CreateTossable () override;
PClassActor *GetParentAmmo () const; PClassActor *GetParentAmmo () const;
int BackpackAmount, BackpackMaxAmount; int BackpackAmount, BackpackMaxAmount, DropAmount;
}; };

View File

@ -107,7 +107,7 @@ class AWeapon : public AStateProvider
HAS_OBJECT_POINTERS HAS_OBJECT_POINTERS
public: public:
DWORD WeaponFlags; 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 AmmoGive1, AmmoGive2; // Amount of each ammo to get when picking up weapon
int MinAmmo1, MinAmmo2; // Minimum ammo needed to switch to this weapon int MinAmmo1, MinAmmo2; // Minimum ammo needed to switch to this weapon
int AmmoUse1, AmmoUse2; // How much ammo to use with each shot int AmmoUse1, AmmoUse2; // How much ammo to use with each shot

View File

@ -517,14 +517,14 @@ static int DrawKeys(player_t * CPlayer, int x, int y)
// Drawing Ammo // Drawing Ammo
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static TArray<PClassAmmo *> orderedammos; static TArray<PClassInventory *> orderedammos;
static void AddAmmoToList(AWeapon * weapdef) static void AddAmmoToList(AWeapon * weapdef)
{ {
for(int i=0; i<2;i++) 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) if (ti)
{ {
AAmmo * ammodef=(AAmmo*)GetDefaultByType(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--) for(i=orderedammos.Size()-1;i>=0;i--)
{ {
PClassAmmo * type = orderedammos[i]; PClassInventory * type = orderedammos[i];
AAmmo * ammoitem = (AAmmo*)CPlayer->mo->FindInventory(type); AAmmo * ammoitem = (AAmmo*)CPlayer->mo->FindInventory(type);
AAmmo * inv = ammoitem? ammoitem : (AAmmo*)GetDefaultByType(orderedammos[i]); AAmmo * inv = ammoitem? ammoitem : (AAmmo*)GetDefaultByType(orderedammos[i]);

View File

@ -646,7 +646,7 @@ void cht_Give (player_t *player, const char *name, int amount)
if (type->ParentClass == RUNTIME_CLASS(AAmmo)) if (type->ParentClass == RUNTIME_CLASS(AAmmo))
{ {
PClassAmmo *atype = static_cast<PClassAmmo *>(type); PClassInventory *atype = static_cast<PClassInventory *>(type);
AInventory *ammo = player->mo->FindInventory(atype); AInventory *ammo = player->mo->FindInventory(atype);
if (ammo == NULL) if (ammo == NULL)
{ {

View File

@ -8720,19 +8720,19 @@ scriptwait:
case PCD_SETAMMOCAPACITY: case PCD_SETAMMOCAPACITY:
if (activator != NULL) if (activator != NULL)
{ {
PClass *type = PClass::FindClass (FBehavior::StaticLookupString (STACK(2))); PClassActor *type = PClass::FindActor (FBehavior::StaticLookupString (STACK(2)));
AInventory *item; AInventory *item;
if (type != NULL && type->ParentClass == RUNTIME_CLASS(AAmmo)) if (type != NULL && type->ParentClass == RUNTIME_CLASS(AAmmo))
{ {
item = activator->FindInventory (static_cast<PClassActor *>(type)); item = activator->FindInventory (type);
if (item != NULL) if (item != NULL)
{ {
item->MaxAmount = STACK(1); item->MaxAmount = STACK(1);
} }
else else
{ {
item = activator->GiveInventoryType (static_cast<PClassAmmo *>(type)); item = activator->GiveInventoryType (type);
if (item != NULL) if (item != NULL)
{ {
item->MaxAmount = STACK(1); item->MaxAmount = STACK(1);

View File

@ -3241,7 +3241,7 @@ void ModifyDropAmount(AInventory *inv, int dropamount)
else if (inv->IsKindOf (RUNTIME_CLASS(AAmmo))) else if (inv->IsKindOf (RUNTIME_CLASS(AAmmo)))
{ {
// Half ammo when dropped by bad guys. // Half ammo when dropped by bad guys.
int amount = static_cast<PClassAmmo *>(inv->GetClass())->DropAmount; int amount = static_cast<AAmmo *>(inv)->DropAmount;
if (amount <= 0) if (amount <= 0)
{ {
amount = MAX(1, int(inv->Amount * dropammofactor)); amount = MAX(1, int(inv->Amount * dropammofactor));

View File

@ -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) if (type != NULL)
{ {

View File

@ -942,7 +942,7 @@ bool APlayerPawn::UseInventory (AInventory *item)
// //
//=========================================================================== //===========================================================================
AWeapon *APlayerPawn::BestWeapon(PClassAmmo *ammotype) AWeapon *APlayerPawn::BestWeapon(PClassInventory *ammotype)
{ {
AWeapon *bestMatch = NULL; AWeapon *bestMatch = NULL;
int bestOrder = INT_MAX; 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); 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() && if (!player->userinfo.GetNeverSwitch() &&
player->PendingWeapon == WP_NOCHANGE && player->PendingWeapon == WP_NOCHANGE &&

View File

@ -1723,8 +1723,7 @@ DEFINE_CLASS_PROPERTY(backpackmaxamount, I, Ammo)
DEFINE_CLASS_PROPERTY(dropamount, I, Ammo) DEFINE_CLASS_PROPERTY(dropamount, I, Ammo)
{ {
PROP_INT_PARM(i, 0); PROP_INT_PARM(i, 0);
assert(info->IsKindOf(RUNTIME_CLASS(PClassAmmo))); defaults->DropAmount = i;
static_cast<PClassAmmo *>(info)->DropAmount = i;
} }
//========================================================================== //==========================================================================

View File

@ -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 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 "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 "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 CONTROL "Exit", IDCANCEL, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 166, 228, 50, 14
} }