- moved the 'Finalize' methods back into a single function in the parser code.

It has been like this initially but was changed when ZDoom gained an overly complicated polymorphic class descriptor object that required a lot of support code. All these complications have long been removed but these methods remained. Since they prevent a class from being moved to the script side entirely they had to be removed.

This was the last major blocker to make Weapon a purely scripted class, the only remaining native method is Serialize which is of no concern for the coming work.
This commit is contained in:
Christoph Oelckers 2018-11-25 08:16:18 +01:00
parent 7012179904
commit 00a48b09e5
12 changed files with 70 additions and 73 deletions

View file

@ -640,7 +640,6 @@ public:
AActor &operator= (const AActor &other);
~AActor ();
virtual void Finalize(FStateDefinitions &statedef);
virtual void OnDestroy() override;
virtual void Serialize(FSerializer &arc) override;
virtual void PostSerialize() override;

View file

@ -54,12 +54,6 @@
EXTERN_CVAR(Bool, sv_unlimited_pickup)
void AInventory::Finalize(FStateDefinitions &statedef)
{
Super::Finalize(statedef);
flags |= MF_SPECIAL;
}
IMPLEMENT_CLASS(AInventory, false, true)
IMPLEMENT_POINTERS_START(AInventory)

View file

@ -70,7 +70,6 @@ class AInventory : public AActor
HAS_OBJECT_POINTERS
public:
virtual void Finalize(FStateDefinitions &statedef) override;
virtual void Serialize(FSerializer &arc) override;
virtual void OnDestroy() override;
virtual void Tick() override;

View file

@ -101,45 +101,6 @@ TMap<PClassActor *, int> Weapons_hton;
static int ntoh_cmp(const void *a, const void *b);
//===========================================================================
//
//
//
//===========================================================================
void AWeapon::Finalize(FStateDefinitions &statedef)
{
Super::Finalize(statedef);
FState *ready = FindState(NAME_Ready);
FState *select = FindState(NAME_Select);
FState *deselect = FindState(NAME_Deselect);
FState *fire = FindState(NAME_Fire);
auto TypeName = GetClass()->TypeName;
// Consider any weapon without any valid state abstract and don't output a warning
// This is for creating base classes for weapon groups that only set up some properties.
if (ready || select || deselect || fire)
{
if (!ready)
{
I_Error("Weapon %s doesn't define a ready state.", TypeName.GetChars());
}
if (!select)
{
I_Error("Weapon %s doesn't define a select state.", TypeName.GetChars());
}
if (!deselect)
{
I_Error("Weapon %s doesn't define a deselect state.", TypeName.GetChars());
}
if (!fire)
{
I_Error("Weapon %s doesn't define a fire state.", TypeName.GetChars());
}
}
}
//===========================================================================
//
// AWeapon :: Serialize

View file

@ -159,7 +159,6 @@ public:
bool bAltFire; // *** only accessed from ZScript. Set when this weapon's alternate fire is used.
bool bDehAmmo;
void Finalize(FStateDefinitions &statedef) override;
void Serialize(FSerializer &arc) override;
enum

View file

@ -365,29 +365,6 @@ bool PClassActor::SetReplacement(FName replaceName)
return true;
}
//==========================================================================
//
// PClassActor :: Finalize
//
// Installs the parsed states and does some sanity checking
//
//==========================================================================
void AActor::Finalize(FStateDefinitions &statedef)
{
try
{
statedef.FinishStates(GetClass());
}
catch (CRecoverableError &)
{
statedef.MakeStateDefines(nullptr);
throw;
}
statedef.InstallStates(GetClass(), this);
statedef.MakeStateDefines(nullptr);
}
//==========================================================================
//
// PClassActor :: RegisterIDs

View file

@ -316,6 +316,7 @@ enum // P_AimLineAttack flags
ALF_CHECKCONVERSATION = 8,
ALF_NOFRIENDS = 16,
ALF_PORTALRESTRICT = 32, // only work through portals with a global offset (to be used for stuff that cannot remember the calculated FTranslatedLineTarget info)
ALF_NOWEAPONCHECK = 64, // ignore NOAUTOAIM flag on a player's weapon.
};
enum // P_LineAttack flags

View file

@ -1187,7 +1187,7 @@ static void ParseActor(FScanner &sc, PNamespace *ns)
}
try
{
GetDefaultByType(info)->Finalize(bag.statedef);
FinalizeClass(info, bag.statedef);
}
catch (CRecoverableError &err)
{

View file

@ -51,6 +51,8 @@
#include "v_text.h"
#include "backend/codegen.h"
#include "stats.h"
#include "info.h"
#include "thingdef.h"
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
void InitThingdef();
@ -60,6 +62,69 @@ void InitThingdef();
static TMap<FState *, FScriptPosition> StateSourceLines;
static FScriptPosition unknownstatesource("unknown file", 0);
//==========================================================================
//
// PClassActor :: Finalize
//
// Installs the parsed states and does some sanity checking
//
//==========================================================================
void FinalizeClass(PClass *ccls, FStateDefinitions &statedef)
{
if (!ccls->IsDescendantOf(NAME_Actor)) return;
auto cls = static_cast<PClassActor*>(ccls);
try
{
statedef.FinishStates(cls);
}
catch (CRecoverableError &)
{
statedef.MakeStateDefines(nullptr);
throw;
}
auto def = GetDefaultByType(cls);
statedef.InstallStates(cls, def);
statedef.MakeStateDefines(nullptr);
if (cls->IsDescendantOf(NAME_Inventory))
{
def->flags |= MF_SPECIAL;
}
if (cls->IsDescendantOf(NAME_Weapon))
{
FState *ready = def->FindState(NAME_Ready);
FState *select = def->FindState(NAME_Select);
FState *deselect = def->FindState(NAME_Deselect);
FState *fire = def->FindState(NAME_Fire);
auto TypeName = cls->TypeName;
// Consider any weapon without any valid state abstract and don't output a warning
// This is for creating base classes for weapon groups that only set up some properties.
if (ready || select || deselect || fire)
{
if (!ready)
{
I_Error("Weapon %s doesn't define a ready state.", TypeName.GetChars());
}
if (!select)
{
I_Error("Weapon %s doesn't define a select state.", TypeName.GetChars());
}
if (!deselect)
{
I_Error("Weapon %s doesn't define a deselect state.", TypeName.GetChars());
}
if (!fire)
{
I_Error("Weapon %s doesn't define a fire state.", TypeName.GetChars());
}
}
}
}
//==========================================================================
//
// Saves the state's source lines for error messages during postprocessing

View file

@ -68,6 +68,7 @@ struct FFlagDef
int varflags;
};
void FinalizeClass(PClass *cls, FStateDefinitions &statedef);
FFlagDef *FindFlag (const PClass *type, const char *part1, const char *part2, bool strict = false);
void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int index);
bool CheckDeprecatedFlags(const AActor *actor, PClassActor *info, int index);

View file

@ -3105,7 +3105,7 @@ void ZCCCompiler::CompileStates()
}
try
{
GetDefaultByType(c->ClassType())->Finalize(statedef);
FinalizeClass(c->ClassType(), statedef);
}
catch (CRecoverableError &err)
{

View file

@ -884,6 +884,7 @@ enum EAimFlags
ALF_CHECKCONVERSATION = 8,
ALF_NOFRIENDS = 16,
ALF_PORTALRESTRICT = 32, // only work through portals with a global offset (to be used for stuff that cannot remember the calculated FTranslatedLineTarget info)
ALF_NOWEAPONCHECK = 64, // ignore NOAUTOAIM flag on a player's weapon.
}
enum ELineAttackFlags