1 #ifndef DOBJTYPE_H 2 #define DOBJTYPE_H 3 4 #ifndef __DOBJECT_H__ 5 #error You must #include "dobject.h" to get dobjtype.h 6 #endif 7 8 #include "thingdef/thingdef_type.h" 9 10 // Symbol information ------------------------------------------------------- 11 12 enum ESymbolType 13 { 14 SYM_Const, 15 SYM_Variable, 16 SYM_ActionFunction 17 }; 18 19 struct PSymbol 20 { 21 virtual ~PSymbol(); 22 23 ESymbolType SymbolType; 24 FName SymbolName; 25 26 protected: PSymbolPSymbol27 PSymbol(FName name, ESymbolType type) { SymbolType = type; SymbolName = name; } 28 }; 29 30 // A constant value --------------------------------------------------------- 31 32 struct PSymbolConst : public PSymbol 33 { 34 int ValueType; 35 union 36 { 37 int Value; 38 double Float; 39 }; 40 PSymbolConstPSymbolConst41 PSymbolConst(FName name) : PSymbol(name, SYM_Const) {} 42 }; 43 44 // A variable --------------------------------------------------------- 45 46 struct PSymbolVariable : public PSymbol 47 { 48 FExpressionType ValueType; 49 //int size; 50 intptr_t offset; 51 bool bUserVar; 52 PSymbolVariablePSymbolVariable53 PSymbolVariable(FName name) : PSymbol(name, SYM_Variable) {} 54 }; 55 56 // An action function ------------------------------------------------------- 57 // 58 // The Arguments string is a string of characters as understood by 59 // the DECORATE parser: 60 // 61 // If the letter is uppercase, it is required. Lowercase letters are optional. 62 // i = integer 63 // f = fixed point 64 // s = sound name 65 // m = actor name 66 // t = string 67 // l = jump label 68 // c = color 69 // x = expression 70 // y = expression 71 // If the final character is a +, the previous parameter is repeated indefinitely, 72 // and an "imaginary" first parameter is inserted containing the total number of 73 // parameters passed. 74 struct FState; 75 struct StateCallData; 76 typedef void (*actionf_p)(AActor *self, AActor *stateowner, FState *state, int parameters, StateCallData *statecall); 77 78 struct PSymbolActionFunction : public PSymbol 79 { 80 FString Arguments; 81 actionf_p Function; 82 int defaultparameterindex; 83 PSymbolActionFunctionPSymbolActionFunction84 PSymbolActionFunction(FName name) : PSymbol(name, SYM_ActionFunction) {} 85 }; 86 87 // A symbol table ----------------------------------------------------------- 88 89 class PSymbolTable 90 { 91 public: PSymbolTable()92 PSymbolTable() : ParentSymbolTable(NULL) 93 { 94 } 95 96 ~PSymbolTable(); 97 98 // Sets the table to use for searches if this one doesn't contain the 99 // requested symbol. 100 void SetParentTable (PSymbolTable *parent); 101 102 // Finds a symbol in the table, optionally searching parent tables 103 // as well. 104 PSymbol *FindSymbol (FName symname, bool searchparents) const; 105 106 // Places the symbol in the table and returns a pointer to it or NULL if 107 // a symbol with the same name is already in the table. This symbol is 108 // not copied and will be freed when the symbol table is destroyed. 109 PSymbol *AddSymbol (PSymbol *sym); 110 111 // Frees all symbols from this table. 112 void ReleaseSymbols(); 113 114 private: 115 PSymbolTable *ParentSymbolTable; 116 TArray<PSymbol *> Symbols; 117 118 friend class DObject; 119 }; 120 121 // Meta-info for every class derived from DObject --------------------------- 122 123 struct PClass 124 { 125 static void StaticInit (); 126 static void StaticShutdown (); 127 static void StaticFreeData (PClass *type); 128 static void ClearRuntimeData(); 129 130 // Per-class information ------------------------------------- 131 FName TypeName; // this class's name 132 unsigned int Size; // this class's size 133 PClass *ParentClass; // the class this class derives from 134 const size_t *Pointers; // object pointers defined by this class *only* 135 const size_t *FlatPointers; // object pointers defined by this class and all its superclasses; not initialized by default 136 FActorInfo *ActorInfo; 137 PClass *HashNext; 138 FMetaTable Meta; 139 BYTE *Defaults; 140 bool bRuntimeClass; // class was defined at run-time, not compile-time 141 unsigned short ClassIndex; 142 PSymbolTable Symbols; 143 144 void (*ConstructNative)(void *); 145 146 // The rest are all functions and static data ---------------- 147 void InsertIntoHash (); 148 DObject *CreateNew () const; 149 PClass *CreateDerivedClass (FName name, unsigned int size); 150 unsigned int Extend(unsigned int extension); 151 void InitializeActorInfo (); 152 void BuildFlatPointers (); 153 void FreeStateList(); 154 const PClass *NativeClass() const; 155 156 // Returns true if this type is an ancestor of (or same as) the passed type. IsAncestorOfPClass157 bool IsAncestorOf (const PClass *ti) const 158 { 159 while (ti) 160 { 161 if (this == ti) 162 return true; 163 ti = ti->ParentClass; 164 } 165 return false; 166 } IsDescendantOfPClass167 inline bool IsDescendantOf (const PClass *ti) const 168 { 169 return ti->IsAncestorOf (this); 170 } 171 172 // Find a type, given its name. FindClassPClass173 static const PClass *FindClass (const char *name) { return FindClass (FName (name, true)); } FindClassPClass174 static const PClass *FindClass (const FString &name) { return FindClass (FName (name, true)); } FindClassPClass175 static const PClass *FindClass (ENamedName name) { return FindClass (FName (name)); } 176 static const PClass *FindClass (FName name); 177 const PClass *FindClassTentative (FName name); // not static! 178 PClass *GetReplacement() const; 179 180 static TArray<PClass *> m_Types; 181 static TArray<PClass *> m_RuntimeActors; 182 183 enum { HASH_SIZE = 256 }; 184 static PClass *TypeHash[HASH_SIZE]; 185 186 static bool bShutdown; 187 }; 188 189 #endif 190