- Split thingdef.cpp into several files so that the state and property code

no longer gets in the way of the main parser.
- Changed A_MissileAttack, A_MeleeAttack and A_ComboAttack so that they use
  metadata. Now all the hack code associated with these functions can be removed.


SVN r538 (trunk)
This commit is contained in:
Christoph Oelckers 2007-05-28 22:18:51 +00:00
parent 50f75b6e8a
commit 8f6fdc1d21
14 changed files with 5416 additions and 5348 deletions

View file

@ -1,4 +1,8 @@
May 28, 2007 (Changes by Graf Zahl) May 28, 2007 (Changes by Graf Zahl)
- Split thingdef.cpp into several files so that the state and property code
no longer gets in the way of the main parser.
- Changed A_MissileAttack, A_MeleeAttack and A_ComboAttack so that they use
metadata. Now all the hack code associated with these functions can be removed.
- Fixed: deadthings.txt contained a superfluous ';' which created parsing errors - Fixed: deadthings.txt contained a superfluous ';' which created parsing errors
with my changed code. with my changed code.
- Cleaned up DECORATE parser a little - moved the old style parsing code into its - Cleaned up DECORATE parser a little - moved the old style parsing code into its

View file

@ -11,6 +11,7 @@ WEAPON(Light)
ACTOR(ChangeFlag) ACTOR(ChangeFlag)
ACTOR(MeleeAttack) ACTOR(MeleeAttack)
ACTOR(MissileAttack) ACTOR(MissileAttack)
ACTOR(ComboAttack)
ACTOR(BulletAttack) ACTOR(BulletAttack)
ACTOR(ScreamAndUnblock) ACTOR(ScreamAndUnblock)
ACTOR(ActiveAndUnblock) ACTOR(ActiveAndUnblock)

View file

@ -49,7 +49,6 @@ FDecalLib DecalLibrary;
static fixed_t ReadScale (); static fixed_t ReadScale ();
static TArray<BYTE> DecalTranslations; static TArray<BYTE> DecalTranslations;
extern TArray<char*> DecalNames;
// A decal group holds multiple decals and returns one randomly // A decal group holds multiple decals and returns one randomly
// when GetDecal() is called. // when GetDecal() is called.
@ -355,19 +354,12 @@ void FDecalLib::ReadAllDecals ()
{ {
AActor *def = (AActor*)GetDefaultByType (PClass::m_RuntimeActors[i]); AActor *def = (AActor*)GetDefaultByType (PClass::m_RuntimeActors[i]);
intptr_t v = (intptr_t)def->DecalGenerator; FName v = ENamedName(intptr_t(def->DecalGenerator));
if (v > 0 && v <= (intptr_t)DecalNames.Size()) if (v.IsValidName())
{ {
def->DecalGenerator = ScanTreeForName (DecalNames[v-1], Root); def->DecalGenerator = ScanTreeForName (v, Root);
} }
} }
// Free the array which is no longer needed!
for (i = 0; i < DecalNames.Size(); i++)
{
delete[] DecalNames[i];
}
DecalNames.Clear();
DecalNames.ShrinkToFit();
} }
void FDecalLib::ReadDecals () void FDecalLib::ReadDecals ()

View file

@ -77,7 +77,6 @@ enum
TK_For, TK_For,
TK_If, TK_If,
TK_Return, TK_Return,
TK_States,
TK_Switch, TK_Switch,
TK_Until, TK_Until,
TK_While, TK_While,

File diff suppressed because it is too large Load diff

View file

@ -68,7 +68,6 @@ std2:
'goto' { RET(TK_Goto); } 'goto' { RET(TK_Goto); }
'if' { RET(TK_If); } 'if' { RET(TK_If); }
'return' { RET(TK_Return); } 'return' { RET(TK_Return); }
'states' { RET(TK_States); }
'switch' { RET(TK_Switch); } 'switch' { RET(TK_Switch); }
'until' { RET(TK_Until); } 'until' { RET(TK_Until); }
'volatile' { RET(TK_Volatile); } 'volatile' { RET(TK_Volatile); }

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,13 @@
#ifndef __THINGDEF_H #ifndef __THINGDEF_H
#define __THINGDEF_H #define __THINGDEF_H
//==========================================================================
//
// This class is for storing a name inside a const PClass* field without // This class is for storing a name inside a const PClass* field without
// generating compiler warnings. It does not manipulate data in any other // generating compiler warnings. It does not manipulate data in any other
// way. // way.
//
//==========================================================================
class fuglyname : public FName class fuglyname : public FName
{ {
public: public:
@ -21,23 +25,12 @@ public:
} }
}; };
// All state parameters are stored in this array now.
extern TArray<int> StateParameters;
extern TArray<FName> JumpParameters;
//==========================================================================
int ParseExpression (bool _not, PClass *cls); //
// Dropitem list
int EvalExpressionI (int id, AActor *self, const PClass *cls=NULL); //
float EvalExpressionF (int id, AActor *self, const PClass *cls=NULL); //==========================================================================
bool EvalExpressionN (int id, AActor *self, const PClass *cls=NULL);
void ClearStateLabels();
void AddState (const char * statename, FState * state);
FState * FindState(AActor * actor, const PClass * type, const char * name);
void InstallStates(FActorInfo *info, AActor *defaults);
void MakeStateDefines(const FStateLabels *list);
FState *P_GetState(AActor *self, FState *CallingState, int offset);
struct FDropItem struct FDropItem
{ {
@ -49,6 +42,86 @@ struct FDropItem
FDropItem *GetDropItems(const PClass * cls); FDropItem *GetDropItems(const PClass * cls);
//==========================================================================
//
// Extra info maintained while defining an actor.
//
//==========================================================================
struct Baggage
{
FActorInfo *Info;
bool DropItemSet;
bool StateSet;
int CurrentState;
FDropItem *DropItemList;
};
inline void ResetBaggage (Baggage *bag)
{
bag->DropItemList = NULL;
bag->DropItemSet = false;
bag->CurrentState = 0;
bag->StateSet = false;
}
//==========================================================================
//
// Action function lookup
//
//==========================================================================
struct AFuncDesc
{
const char *Name;
actionf_p Function;
};
AFuncDesc * FindFunction(const char * string);
//==========================================================================
//
// State parser
//
//==========================================================================
extern TArray<int> StateParameters;
extern TArray<FName> JumpParameters;
void ClearStateLabels();
void AddState (const char * statename, FState * state);
FState * FindState(AActor * actor, const PClass * type, const char * name);
void InstallStates(FActorInfo *info, AActor *defaults);
void MakeStateDefines(const FStateLabels *list);
FState *P_GetState(AActor *self, FState *CallingState, int offset);
int FinishStates (FActorInfo *actor, AActor *defaults, Baggage &bag);
int ParseStates(FActorInfo * actor, AActor * defaults, Baggage &bag);
FState *CheckState(PClass *type);
//==========================================================================
//
// Property parser
//
//==========================================================================
void ParseActorProperty(Baggage &bag);
void ParseActorFlag (Baggage &bag, int mod);
void FinishActor(FActorInfo *info, Baggage &bag);
void ParseConstant (PSymbolTable * symt, PClass *cls);
void ParseEnum (PSymbolTable * symt, PClass *cls);
int ParseExpression (bool _not, PClass *cls);
int EvalExpressionI (int id, AActor *self, const PClass *cls=NULL);
float EvalExpressionF (int id, AActor *self, const PClass *cls=NULL);
bool EvalExpressionN (int id, AActor *self, const PClass *cls=NULL);
// A truly awful hack to get to the state that called an action function // A truly awful hack to get to the state that called an action function
// without knowing whether it has been called from a weapon or actor. // without knowing whether it has been called from a weapon or actor.
@ -64,6 +137,10 @@ enum
ACMETA_ExplosionDamage, ACMETA_ExplosionDamage,
ACMETA_ExplosionRadius, ACMETA_ExplosionRadius,
ACMETA_DontHurtShooter, ACMETA_DontHurtShooter,
ACMETA_MeleeSound,
ACMETA_MeleeDamage,
ACMETA_MissileName,
ACMETA_MissileHeight,
}; };

View file

@ -47,7 +47,7 @@
// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
void ProcessActor(); void ParseActor();
void ParseClass(); void ParseClass();
void ParseGlobalConst(); void ParseGlobalConst();
void ParseGlobalEnum(); void ParseGlobalEnum();
@ -96,27 +96,27 @@ static void ParseDecorate ()
break; break;
case TK_Class: case TK_Class:
ParseClass(); ParseClass ();
break; break;
case TK_Const: case TK_Const:
ParseGlobalConst(); ParseConstant (&RUNTIME_CLASS(AActor)->Symbols, RUNTIME_CLASS(AActor));
break; break;
case TK_Enum: case TK_Enum:
ParseGlobalEnum(); ParseEnum (&RUNTIME_CLASS(AActor)->Symbols, RUNTIME_CLASS(AActor));
break; break;
case TK_Pickup: case TK_Pickup:
ParseOldDecoration(DEF_Pickup); ParseOldDecoration (DEF_Pickup);
break; break;
case TK_Breakable: case TK_Breakable:
ParseOldDecoration(DEF_BreakableDecoration); ParseOldDecoration (DEF_BreakableDecoration);
break; break;
case TK_Projectile: case TK_Projectile:
ParseOldDecoration(DEF_Projectile); ParseOldDecoration (DEF_Projectile);
break; break;
case ';': case ';':
@ -132,7 +132,7 @@ static void ParseDecorate ()
// so let's do a special case for this. // so let's do a special case for this.
if (SC_Compare("ACTOR")) if (SC_Compare("ACTOR"))
{ {
ProcessActor (); ParseActor ();
break; break;
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -202,14 +202,27 @@ void A_UnsetFloat(AActor * self)
static void DoAttack (AActor *self, bool domelee, bool domissile) static void DoAttack (AActor *self, bool domelee, bool domissile)
{ {
int index=CheckIndex(4); int index=CheckIndex(4);
int MeleeDamage;
int MeleeSound;
FName MissileName;
fixed_t MissileHeight;
if (index<0) return;
if (self->target == NULL) return; if (self->target == NULL) return;
int MeleeDamage=StateParameters[index]; if (index > 0)
int MeleeSound=StateParameters[index+1]; {
FName MissileName=(ENamedName)StateParameters[index+2]; MeleeDamage=StateParameters[index];
fixed_t MissileHeight=StateParameters[index+3]; MeleeSound=StateParameters[index+1];
MissileName=(ENamedName)StateParameters[index+2];
MissileHeight=StateParameters[index+3];
}
else
{
MeleeDamage = self->GetClass()->Meta.GetMetaInt (ACMETA_MeleeDamage, 0);
MeleeSound = self->GetClass()->Meta.GetMetaInt (ACMETA_MeleeSound, 0);
MissileName=(ENamedName) self->GetClass()->Meta.GetMetaInt (ACMETA_MissileName, NAME_None);
MissileHeight= self->GetClass()->Meta.GetMetaFixed (ACMETA_MissileHeight, 32*FRACUNIT);
}
A_FaceTarget (self); A_FaceTarget (self);
if (domelee && MeleeDamage>0 && self->CheckMeleeRange ()) if (domelee && MeleeDamage>0 && self->CheckMeleeRange ())

View file

@ -115,6 +115,9 @@ class Actor extends Thinker
action native A_FireAssaultGun(); action native A_FireAssaultGun();
action native A_CheckTerrain(); action native A_CheckTerrain();
action native A_MissileAttack();
action native A_MeleeAttack();
action native A_ComboAttack();
action native A_BulletAttack(); action native A_BulletAttack();
action native A_PlaySound(sound whattoplay); action native A_PlaySound(sound whattoplay);
action native A_PlayWeaponSound(sound whattoplay); action native A_PlayWeaponSound(sound whattoplay);

View file

@ -4306,10 +4306,18 @@
RelativePath=".\src\thingdef\thingdef_main.cpp" RelativePath=".\src\thingdef\thingdef_main.cpp"
> >
</File> </File>
<File
RelativePath=".\src\thingdef\thingdef_properties.cpp"
>
</File>
<File <File
RelativePath=".\src\thingdef\thingdef_specials.h" RelativePath=".\src\thingdef\thingdef_specials.h"
> >
</File> </File>
<File
RelativePath=".\src\thingdef\thingdef_states.cpp"
>
</File>
</Filter> </Filter>
</Filter> </Filter>
<Filter <Filter