- moved DisplayName, the last remaining PlayerPawn meta property, to PClassActor so that PClassPlayerPawn could be removed.

Now all actors have the same metaclass and therefore it will always be the same size which will finally allow some needed changes to the type system which couldn't be done because it was occasionally necessary to replace tentatively created classes due to size mismatches.
This commit is contained in:
Christoph Oelckers 2017-02-08 19:42:24 +01:00
parent 68e9918ed5
commit 17a2666bd4
20 changed files with 49 additions and 86 deletions

View file

@ -2539,7 +2539,7 @@ void Net_DoCommand (int type, BYTE **stream, int player)
case DEM_MORPHEX:
{
s = ReadString (stream);
const char *msg = cht_Morph (players + player, dyn_cast<PClassPlayerPawn>(PClass::FindClass (s)), false);
const char *msg = cht_Morph (players + player, PClass::FindActor (s), false);
if (player == consoleplayer)
{
Printf ("%s\n", *msg != '\0' ? msg : "Morph failed.");

View file

@ -72,21 +72,11 @@ typedef TArray<std::tuple<PClass*, int, FPlayerColorSet>> ColorSetList;
extern PainFlashList PainFlashes;
extern ColorSetList ColorSets;
class PClassPlayerPawn : public PClassActor
{
DECLARE_CLASS(PClassPlayerPawn, PClassActor);
protected:
public:
PClassPlayerPawn();
virtual void DeriveData(PClass *newclass);
FString DisplayName; // Display name (used in menus, etc.)
};
FString GetPrintableDisplayName(PClassPlayerPawn *cls);
FString GetPrintableDisplayName(PClassActor *cls);
class APlayerPawn : public AActor
{
DECLARE_CLASS_WITH_META(APlayerPawn, AActor, PClassPlayerPawn)
DECLARE_CLASS(APlayerPawn, AActor)
HAS_OBJECT_POINTERS
public:
@ -271,7 +261,7 @@ public:
bool CheckSkin (int skin);
PClassPlayerPawn *Type;
PClassActor *Type;
DWORD Flags;
TArray<int> Skins;
};
@ -343,7 +333,7 @@ struct userinfo_t : TMap<FName,FBaseCVar *>
{
return *static_cast<FIntCVar *>(*CheckKey(NAME_PlayerClass));
}
PClassPlayerPawn *GetPlayerClassType() const
PClassActor *GetPlayerClassType() const
{
return PlayerClasses[GetPlayerClassNum()].Type;
}
@ -401,7 +391,7 @@ public:
userinfo_t userinfo; // [RH] who is this?
PClassPlayerPawn *cls; // class of associated PlayerPawn
PClassActor *cls; // class of associated PlayerPawn
float DesiredFOV; // desired field of vision
float FOV; // current field of vision
@ -459,7 +449,7 @@ public:
short fixedcolormap; // can be set to REDCOLORMAP, etc.
short fixedlightlevel;
int morphTics; // player is a chicken/pig if > 0
PClassPlayerPawn *MorphedPlayerClass; // [MH] (for SBARINFO) class # for this player instance when morphed
PClassActor *MorphedPlayerClass; // [MH] (for SBARINFO) class # for this player instance when morphed
int MorphStyle; // which effects to apply for this player instance when morphed
PClassActor *MorphExitFlash; // flash to apply when demorphing (cache of value given to P_MorphPlayer)
TObjPtr<AWeapon> PremorphWeapon; // ready weapon before morphing

View file

@ -93,7 +93,6 @@ enum
{
CLASSREG_PClass,
CLASSREG_PClassActor,
CLASSREG_PClassPlayerPawn,
};
struct ClassReg

View file

@ -2955,7 +2955,6 @@ PClass *ClassReg::RegisterClass()
{
&PClass::RegistrationInfo,
&PClassActor::RegistrationInfo,
&PClassPlayerPawn::RegistrationInfo,
};
// Skip classes that have already been registered

View file

@ -1361,7 +1361,7 @@ void G_PlayerReborn (int player)
BYTE currclass;
userinfo_t userinfo; // [RH] Save userinfo
APlayerPawn *actor;
PClassPlayerPawn *cls;
PClassActor *cls;
FString log;
DBot *Bot; //Added by MC:

View file

@ -9,7 +9,6 @@
class player_t;
class FConfigFile;
class PClassPlayerPawn;
struct visstyle_t;
/************************************************************************/

View file

@ -1058,7 +1058,7 @@ void FWeaponSlots::SetFromGameInfo()
//
//===========================================================================
void FWeaponSlots::StandardSetup(PClassPlayerPawn *type)
void FWeaponSlots::StandardSetup(PClassActor *type)
{
SetFromPlayer(type);
AddExtraWeapons();
@ -1151,7 +1151,7 @@ void FWeaponSlots::SendDifferences(int playernum, const FWeaponSlots &other)
//
//===========================================================================
void FWeaponSlots::SetFromPlayer(PClassPlayerPawn *type)
void FWeaponSlots::SetFromPlayer(PClassActor *type)
{
Clear();
auto Slot = ((APlayerPawn*)GetDefaultByType(type))->Slot;

View file

@ -65,8 +65,8 @@ struct FWeaponSlots
ESlotDef AddDefaultWeapon (int slot, PClassActor *type);
void AddExtraWeapons();
void SetFromGameInfo();
void SetFromPlayer(PClassPlayerPawn *type);
void StandardSetup(PClassPlayerPawn *type);
void SetFromPlayer(PClassActor *type);
void StandardSetup(PClassActor *type);
void LocalSetup(PClassActor *type);
void SendDifferences(int playernum, const FWeaponSlots &other);
int RestoreSlots (FConfigFile *config, const char *section);

View file

@ -33,7 +33,7 @@ void InitAllPowerupEffects(AInventory *item);
//
//---------------------------------------------------------------------------
bool P_MorphPlayer (player_t *activator, player_t *p, PClassPlayerPawn *spawntype, int duration, int style, PClassActor *enter_flash, PClassActor *exit_flash)
bool P_MorphPlayer (player_t *activator, player_t *p, PClassActor *spawntype, int duration, int style, PClassActor *enter_flash, PClassActor *exit_flash)
{
AInventory *item;
APlayerPawn *morphed;

View file

@ -35,7 +35,7 @@ class AActor;
class player_t;
class AMorphedMonster;
bool P_MorphPlayer (player_t *activator, player_t *player, PClassPlayerPawn *morphclass, int duration = 0, int style = 0,
bool P_MorphPlayer (player_t *activator, player_t *player, PClassActor *morphclass, int duration = 0, int style = 0,
PClassActor *enter_flash = NULL, PClassActor *exit_flash = NULL);
bool P_UndoPlayerMorph (player_t *activator, player_t *player, int unmorphflag = 0, bool force = false);
bool P_MorphMonster (AActor *actor, PClassActor *morphclass, int duration = 0, int style = 0,

View file

@ -354,6 +354,7 @@ void PClassActor::DeriveData(PClass *newclass)
newa->ForbiddenToPlayerClass = ForbiddenToPlayerClass;
newa->RestrictedToPlayerClass = RestrictedToPlayerClass;
newa->DisplayName = DisplayName;
}
//==========================================================================
@ -638,7 +639,7 @@ size_t PClassActor::PointerSubstitution(DObject *oldclass, DObject *newclass)
{
if (VisibleToPlayerClass[i] == oldclass)
{
VisibleToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
VisibleToPlayerClass[i] = static_cast<PClassActor*>(newclass);
changed++;
}
}
@ -647,7 +648,7 @@ size_t PClassActor::PointerSubstitution(DObject *oldclass, DObject *newclass)
{
if (ForbiddenToPlayerClass[i] == oldclass)
{
ForbiddenToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
ForbiddenToPlayerClass[i] = static_cast<PClassActor*>(newclass);
changed++;
}
}
@ -655,7 +656,7 @@ size_t PClassActor::PointerSubstitution(DObject *oldclass, DObject *newclass)
{
if (RestrictedToPlayerClass[i] == oldclass)
{
RestrictedToPlayerClass[i] = static_cast<PClassPlayerPawn*>(newclass);
RestrictedToPlayerClass[i] = static_cast<PClassActor*>(newclass);
changed++;
}
}

View file

@ -235,7 +235,6 @@ private:
};
class DDropItem;
class PClassPlayerPawn;
class PClassActor : public PClass
{
@ -287,7 +286,7 @@ public:
DmgFactors *DamageFactors;
PainChanceList *PainChances;
TArray<PClassPlayerPawn *> VisibleToPlayerClass;
TArray<PClassActor *> VisibleToPlayerClass;
FString Obituary; // Player was killed by this actor
FString HitObituary; // Player was killed by this actor in melee
@ -319,8 +318,11 @@ public:
// These are only valid for inventory items.
FString PickupMsg;
TArray<PClassPlayerPawn *> RestrictedToPlayerClass;
TArray<PClassPlayerPawn *> ForbiddenToPlayerClass;
TArray<PClassActor *> RestrictedToPlayerClass;
TArray<PClassActor *> ForbiddenToPlayerClass;
// This is from PClassPlayerPawn
FString DisplayName;
// For those times when being able to scan every kind of actor is convenient
static TArray<PClassActor *> AllActorClasses;

View file

@ -170,7 +170,7 @@ void cht_DoCheat (player_t *player, int cheat)
break;
case CHT_MORPH:
msg = cht_Morph (player, static_cast<PClassPlayerPawn *>(PClass::FindClass (gameinfo.gametype == GAME_Heretic ? NAME_ChickenPlayer : NAME_PigPlayer)), true);
msg = cht_Morph (player, PClass::FindActor (gameinfo.gametype == GAME_Heretic ? NAME_ChickenPlayer : NAME_PigPlayer), true);
break;
case CHT_NOTARGET:
@ -548,13 +548,13 @@ void cht_DoCheat (player_t *player, int cheat)
Printf ("%s cheats: %s\n", player->userinfo.GetName(), msg);
}
const char *cht_Morph (player_t *player, PClassPlayerPawn *morphclass, bool quickundo)
const char *cht_Morph (player_t *player, PClassActor *morphclass, bool quickundo)
{
if (player->mo == NULL)
{
return "";
}
PClassPlayerPawn *oldclass = player->mo->GetClass();
auto oldclass = player->mo->GetClass();
// Set the standard morph style for the current game
int style = MORPH_UNDOBYTOMEOFPOWER;

View file

@ -29,12 +29,12 @@
// [RH] Functions that actually perform the cheating
class player_t;
class PClassPlayerPawn;
class PClassActor;
void cht_DoCheat (player_t *player, int cheat);
void cht_Give (player_t *player, const char *item, int amount=1);
void cht_Take (player_t *player, const char *item, int amount=1);
void cht_Suicide (player_t *player);
const char *cht_Morph (player_t *player, PClassPlayerPawn *morphclass, bool quickundo);
const char *cht_Morph (player_t *player, PClassActor *morphclass, bool quickundo);
#endif

View file

@ -899,7 +899,7 @@ void DPlayerMenu::ClassChanged (DMenuItemBase *li)
players[consoleplayer].userinfo.PlayerClassNumChanged(gameinfo.norandomplayerclass ? sel : sel-1);
PickPlayerClass();
cvar_set ("playerclass", sel == 0 && !gameinfo.norandomplayerclass ? "Random" : PlayerClass->Type->DisplayName.GetChars());
cvar_set ("playerclass", sel == 0 && !gameinfo.norandomplayerclass ? "Random" : GetPrintableDisplayName(PlayerClass->Type).GetChars());
UpdateSkins();
UpdateColorsets();

View file

@ -9491,7 +9491,7 @@ scriptwait:
{
int tag = STACK(7);
FName playerclass_name = FBehavior::StaticLookupString(STACK(6));
PClassPlayerPawn *playerclass = dyn_cast<PClassPlayerPawn>(PClass::FindClass (playerclass_name));
auto playerclass = PClass::FindActor (playerclass_name);
FName monsterclass_name = FBehavior::StaticLookupString(STACK(5));
PClassActor *monsterclass = PClass::FindActor(monsterclass_name);
int duration = STACK(4);

View file

@ -148,7 +148,7 @@ bool FPlayerClass::CheckSkin (int skin)
//
//===========================================================================
FString GetPrintableDisplayName(PClassPlayerPawn *cls)
FString GetPrintableDisplayName(PClassActor *cls)
{
// Fixme; This needs a decent way to access the string table without creating a mess.
// [RH] ????
@ -167,7 +167,7 @@ bool ValidatePlayerClass(PClassActor *ti, const char *name)
Printf("Invalid player class '%s'\n", name);
return false;
}
else if (static_cast<PClassPlayerPawn *>(ti)->DisplayName.IsEmpty())
else if (ti->DisplayName.IsEmpty())
{
Printf ("Missing displayname for player class '%s'\n", name);
return false;
@ -186,7 +186,7 @@ void SetupPlayerClasses ()
if (ValidatePlayerClass(cls, gameinfo.PlayerClasses[i]))
{
newclass.Flags = 0;
newclass.Type = static_cast<PClassPlayerPawn *>(cls);
newclass.Type = cls;
if ((GetDefaultByType(cls)->flags6 & MF6_NOMENU))
{
newclass.Flags |= PCF_NOMENU;
@ -214,7 +214,7 @@ CCMD (addplayerclass)
{
FPlayerClass newclass;
newclass.Type = static_cast<PClassPlayerPawn *>(ti);
newclass.Type = ti;
newclass.Flags = 0;
int arg = 2;
@ -535,27 +535,6 @@ int player_t::GetSpawnClass()
return static_cast<APlayerPawn*>(GetDefaultByType(type))->SpawnMask;
}
//===========================================================================
//
// PClassPlayerPawn
//
//===========================================================================
IMPLEMENT_CLASS(PClassPlayerPawn, false, false)
PClassPlayerPawn::PClassPlayerPawn()
{
}
void PClassPlayerPawn::DeriveData(PClass *newclass)
{
assert(newclass->IsKindOf(RUNTIME_CLASS(PClassPlayerPawn)));
Super::DeriveData(newclass);
PClassPlayerPawn *newp = static_cast<PClassPlayerPawn *>(newclass);
newp->DisplayName = DisplayName;
}
//===========================================================================
//
// EnumColorsets
@ -1247,7 +1226,7 @@ const char *APlayerPawn::GetSoundClass() const
}
// [GRB]
PClassPlayerPawn *pclass = GetClass();
auto pclass = GetClass();
return SoundClass != NAME_None? SoundClass.GetChars() : "player";
}
@ -1729,7 +1708,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_SkullPop)
// [GRB] Parameterized version
if (spawntype == NULL || !spawntype->IsDescendantOf("PlayerChunk"))
{
spawntype = dyn_cast<PClassPlayerPawn>(PClass::FindClass("BloodySkull"));
spawntype = PClass::FindActor("BloodySkull");
if (spawntype == NULL)
return 0;
}
@ -3276,7 +3255,7 @@ DEFINE_FIELD(APlayerPawn, HexenArmor)
DEFINE_FIELD(APlayerPawn, ColorRangeStart)
DEFINE_FIELD(APlayerPawn, ColorRangeEnd)
DEFINE_FIELD(PClassPlayerPawn, DisplayName)
DEFINE_FIELD(PClassActor, DisplayName)
DEFINE_FIELD_X(PlayerInfo, player_t, mo)
DEFINE_FIELD_X(PlayerInfo, player_t, playerstate)

View file

@ -517,7 +517,7 @@ void R_InitSkins (void)
int lastlump;
int aliasid;
bool remove;
PClassPlayerPawn *basetype, *transtype;
PClassActor *basetype, *transtype;
key[sizeof(key)-1] = 0;
i = PlayerClasses.Size () - 1;
@ -602,11 +602,11 @@ void R_InitSkins (void)
else if (0 == stricmp (key, "game"))
{
if (gameinfo.gametype == GAME_Heretic)
basetype = dyn_cast<PClassPlayerPawn>(PClass::FindActor(NAME_HereticPlayer));
basetype = PClass::FindActor(NAME_HereticPlayer);
else if (gameinfo.gametype == GAME_Strife)
basetype = dyn_cast<PClassPlayerPawn>(PClass::FindActor(NAME_StrifePlayer));
basetype = PClass::FindActor(NAME_StrifePlayer);
else
basetype = dyn_cast<PClassPlayerPawn>(PClass::FindActor(NAME_DoomPlayer));
basetype = PClass::FindActor(NAME_DoomPlayer);
transtype = basetype;
@ -614,7 +614,7 @@ void R_InitSkins (void)
{
if (gameinfo.gametype & GAME_DoomChex)
{
transtype = dyn_cast<PClassPlayerPawn>(PClass::FindActor(NAME_HereticPlayer));
transtype = PClass::FindActor(NAME_HereticPlayer);
skins[i].othergame = true;
}
else if (gameinfo.gametype != GAME_Heretic)
@ -633,7 +633,7 @@ void R_InitSkins (void)
{
if (gameinfo.gametype == GAME_Heretic)
{
transtype = dyn_cast<PClassPlayerPawn>(PClass::FindActor(NAME_DoomPlayer));
transtype = PClass::FindActor(NAME_DoomPlayer);
skins[i].othergame = true;
}
else if (!(gameinfo.gametype & GAME_DoomChex))
@ -709,12 +709,12 @@ void R_InitSkins (void)
{
if (gameinfo.gametype & GAME_DoomChex)
{
basetype = transtype = dyn_cast<PClassPlayerPawn>(PClass::FindActor(NAME_DoomPlayer));
basetype = transtype = PClass::FindActor(NAME_DoomPlayer);
}
else if (gameinfo.gametype == GAME_Heretic)
{
basetype = dyn_cast<PClassPlayerPawn>(PClass::FindActor(NAME_HereticPlayer));
transtype = dyn_cast<PClassPlayerPawn>(PClass::FindActor(NAME_DoomPlayer));
basetype = PClass::FindActor(NAME_HereticPlayer);
transtype = PClass::FindActor(NAME_DoomPlayer);
skins[i].othergame = true;
}
else
@ -734,7 +734,7 @@ void R_InitSkins (void)
remove = true;
for (j = 0; j < (int)PlayerClasses.Size (); j++)
{
PClassPlayerPawn *type = PlayerClasses[j].Type;
auto type = PlayerClasses[j].Type;
auto type_def = ((APlayerPawn*)GetDefaultByType(type));
if (type->IsDescendantOf (basetype) &&

View file

@ -2277,8 +2277,7 @@ DEFINE_SCRIPTED_PROPERTY_PREFIX(powerup, type, S, PowerupGiver)
DEFINE_CLASS_PROPERTY_PREFIX(player, displayname, S, PlayerPawn)
{
PROP_STRING_PARM(str, 0);
assert(info->IsKindOf(RUNTIME_CLASS(PClassPlayerPawn)));
static_cast<PClassPlayerPawn *>(info)->DisplayName = str;
info->DisplayName = str;
}
//==========================================================================

View file

@ -246,11 +246,6 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, FDoorAnimat
template<> FSerializer &Serialize(FSerializer &arc, const char *key, char *&pstr, char **def);
template<> FSerializer &Serialize(FSerializer &arc, const char *key, FFont *&font, FFont **def);
template<> inline FSerializer &Serialize(FSerializer &arc, const char *key, PClassPlayerPawn *&clst, PClassPlayerPawn **def)
{
return Serialize(arc, key, (PClassActor *&)clst, (PClassActor **)def);
}
FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState **def, bool *retcode);
template<> inline FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState **def)
{