consoleObject.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  26. #ifndef _CONSOLEOBJECT_H_
  27. #define _CONSOLEOBJECT_H_
  28. #ifndef _TVECTOR_H_
  29. #include "core/util/tVector.h"
  30. #endif
  31. #ifndef _STRINGTABLE_H_
  32. #include "core/stringTable.h"
  33. #endif
  34. #ifndef _STRINGFUNCTIONS_H_
  35. #include "core/strings/stringFunctions.h"
  36. #endif
  37. #ifndef _BITSET_H_
  38. #include "core/bitSet.h"
  39. #endif
  40. #ifndef _DYNAMIC_CONSOLETYPES_H_
  41. #include "console/dynamicTypes.h"
  42. #endif
  43. #ifndef _ENGINEOBJECT_H_
  44. #include "console/engineObject.h"
  45. #endif
  46. #ifndef _ENGINEFUNCTIONS_H_
  47. #include "console/engineFunctions.h"
  48. #endif
  49. #ifndef _SIMOBJECTREF_H_
  50. #include "console/simObjectRef.h"
  51. #endif
  52. #ifndef TINYXML_INCLUDED
  53. #include "tinyxml2.h"
  54. #endif
  55. #ifndef _CONSOLFUNCTIONS_H_
  56. #include "console/consoleFunctions.h"
  57. #endif
  58. /// @file
  59. /// Legacy console object system.
  60. /// @ingroup console_system Console System
  61. /// @{
  62. class Namespace;
  63. class ConsoleObject;
  64. enum NetClassTypes
  65. {
  66. NetClassTypeObject = 0,
  67. NetClassTypeDataBlock,
  68. NetClassTypeEvent,
  69. NetClassTypesCount,
  70. };
  71. enum NetClassGroups
  72. {
  73. NetClassGroupGame = 0,
  74. NetClassGroupCommunity,
  75. NetClassGroup3,
  76. NetClassGroup4,
  77. NetClassGroupsCount,
  78. };
  79. enum NetClassMasks
  80. {
  81. NetClassGroupGameMask = BIT(NetClassGroupGame),
  82. NetClassGroupCommunityMask = BIT(NetClassGroupCommunity),
  83. };
  84. enum NetDirection
  85. {
  86. NetEventDirAny,
  87. NetEventDirServerToClient,
  88. NetEventDirClientToServer,
  89. };
  90. class SimObject;
  91. class TypeValidator;
  92. class ConsoleClassObject;
  93. DECLARE_SCOPE( ConsoleAPI );
  94. //=============================================================================
  95. // AbstractClassRep.
  96. //=============================================================================
  97. /// Core functionality for class manipulation.
  98. ///
  99. /// @section AbstractClassRep_intro Introduction (or, Why AbstractClassRep?)
  100. ///
  101. /// Many of Torque's subsystems, especially network, console, and sim,
  102. /// require the ability to programatically instantiate classes. For instance,
  103. /// when objects are ghosted, the networking layer needs to be able to create
  104. /// an instance of the object on the client. When the console scripting
  105. /// language runtime encounters the "new" keyword, it has to be able to fill
  106. /// that request.
  107. ///
  108. /// Since standard C++ doesn't provide a function to create a new instance of
  109. /// an arbitrary class at runtime, one must be created. This is what
  110. /// AbstractClassRep and ConcreteClassRep are all about. They allow the registration
  111. /// and instantiation of arbitrary classes at runtime.
  112. ///
  113. /// In addition, ACR keeps track of the fields (registered via addField() and co.) of
  114. /// a class, allowing programmatic access of class fields.
  115. ///
  116. /// @see ConsoleObject
  117. ///
  118. /// @note In general, you will only access the functionality implemented in this class via
  119. /// ConsoleObject::create(). Most of the time, you will only ever need to use this part
  120. /// part of the engine indirectly - ie, you will use the networking system or the console,
  121. /// or ConsoleObject, and they will indirectly use this code. <b>The following discussion
  122. /// is really only relevant for advanced engine users.</b>
  123. ///
  124. /// @section AbstractClassRep_netstuff NetClasses and Class IDs
  125. ///
  126. /// Torque supports a notion of group, type, and direction for objects passed over
  127. /// the network. Class IDs are assigned sequentially per-group, per-type, so that, for instance,
  128. /// the IDs assigned to Datablocks are seperate from the IDs assigned to NetObjects or NetEvents.
  129. /// This can translate into significant bandwidth savings (especially since the size of the fields
  130. /// for transmitting these bits are determined at run-time based on the number of IDs given out.
  131. ///
  132. /// @section AbstractClassRep_details AbstractClassRep Internals
  133. ///
  134. /// Much like ConsoleConstructor, ACR does some preparatory work at runtime before execution
  135. /// is passed to main(). In actual fact, this preparatory work is done by the ConcreteClassRep
  136. /// template. Let's examine this more closely.
  137. ///
  138. /// If we examine ConsoleObject, we see that two macros must be used in the definition of a
  139. /// properly integrated objects. From the ConsoleObject example:
  140. ///
  141. /// @code
  142. /// // This is from inside the class definition...
  143. /// DECLARE_CONOBJECT(TorqueObject);
  144. ///
  145. /// // And this is from outside the class definition...
  146. /// IMPLEMENT_CONOBJECT(TorqueObject);
  147. /// @endcode
  148. ///
  149. /// What do these things actually do?
  150. ///
  151. /// Not all that much, in fact. They expand to code something like this:
  152. ///
  153. /// @code
  154. /// // This is from inside the class definition...
  155. /// static ConcreteClassRep<TorqueObject> dynClassRep;
  156. /// static AbstractClassRep* getParentStaticClassRep();
  157. /// static AbstractClassRep* getStaticClassRep();
  158. /// virtual AbstractClassRep* getClassRep() const;
  159. /// @endcode
  160. ///
  161. /// @code
  162. /// // And this is from outside the class definition...
  163. /// AbstractClassRep* TorqueObject::getClassRep() const { return &TorqueObject::dynClassRep; }
  164. /// AbstractClassRep* TorqueObject::getStaticClassRep() { return &dynClassRep; }
  165. /// AbstractClassRep* TorqueObject::getParentStaticClassRep() { return Parent::getStaticClassRep(); }
  166. /// ConcreteClassRep<TorqueObject> TorqueObject::dynClassRep("TorqueObject", 0, -1, 0);
  167. /// @endcode
  168. ///
  169. /// As you can see, getClassRep(), getStaticClassRep(), and getParentStaticClassRep() are just
  170. /// accessors to allow access to various ConcreteClassRep instances. This is where the Parent
  171. /// typedef comes into play as well - it lets getParentStaticClassRep() get the right
  172. /// class rep.
  173. ///
  174. /// In addition, dynClassRep is declared as a member of TorqueObject, and defined later
  175. /// on. Much like ConsoleConstructor, ConcreteClassReps add themselves to a global linked
  176. /// list in their constructor.
  177. ///
  178. /// Then, when AbstractClassRep::initialize() is called, from Con::init(), we iterate through
  179. /// the list and perform the following tasks:
  180. /// - Sets up a Namespace for each class.
  181. /// - Call the init() method on each ConcreteClassRep. This method:
  182. /// - Links namespaces between parent and child classes, using Con::classLinkNamespaces.
  183. /// - Calls initPersistFields() and consoleInit().
  184. /// - As a result of calling initPersistFields, the field list for the class is populated.
  185. /// - Assigns network IDs for classes based on their NetGroup membership. Determines
  186. /// bit allocations for network ID fields.
  187. ///
  188. /// @nosubgrouping
  189. class AbstractClassRep : public ConsoleBaseType
  190. {
  191. friend class ConsoleObject;
  192. public:
  193. typedef ConsoleBaseType Parent;
  194. /// Allows the writing of a custom TAML schema.
  195. typedef void(*WriteCustomTamlSchema)(const AbstractClassRep* pClassRep, tinyxml2::XMLElement* pParentElement);
  196. /// @name 'Tructors
  197. /// @{
  198. ///
  199. /// @param conIdPtr Pointer to the static S32 console ID.
  200. /// @param conTypeName Console type name.
  201. AbstractClassRep( S32* conIdPtr, const char* typeName )
  202. : Parent( sizeof( void* ), conIdPtr, typeName )
  203. {
  204. VECTOR_SET_ASSOCIATION( mFieldList );
  205. mCategory = StringTable->EmptyString();
  206. mClassGroupMask = 0;
  207. std::fill_n(mClassId, NetClassGroupsCount, -1);
  208. mClassName = StringTable->EmptyString();
  209. mClassSizeof = 0;
  210. mClassType = 0;
  211. mDescription = StringTable->EmptyString();
  212. #ifdef TORQUE_NET_STATS
  213. dMemset(mDirtyMaskFrequency, 0, sizeof(mDirtyMaskFrequency));
  214. dMemset(mDirtyMaskTotal, 0, sizeof(mDirtyMaskTotal));
  215. #endif
  216. mDynamicGroupExpand = false;
  217. mNamespace = NULL;
  218. mNetEventDir = 0;
  219. nextClass = NULL;
  220. parentClass = NULL;
  221. mIsRenderEnabled = true;
  222. mIsSelectionEnabled = true;
  223. }
  224. /// @}
  225. /// @name Representation Interface
  226. /// @{
  227. //TODO: move over to EngineTypeNetInfo
  228. S32 mClassGroupMask; ///< Mask indicating in which NetGroups this object belongs.
  229. S32 mClassType; ///< Stores the NetClass of this class.
  230. S32 mNetEventDir; ///< Stores the NetDirection of this class.
  231. S32 mClassId[ NetClassGroupsCount ]; ///< Stores the IDs assigned to this class for each group.
  232. S32 mClassSizeof; ///< Size of instances in bytes.
  233. //TODO: move over to EngineTypeNetInfo
  234. #ifdef TORQUE_NET_STATS
  235. struct NetStatInstance
  236. {
  237. U32 numEvents;
  238. U32 total;
  239. S32 min;
  240. S32 max;
  241. void reset()
  242. {
  243. numEvents = 0;
  244. total = 0;
  245. min = S32_MAX;
  246. max = S32_MIN;
  247. }
  248. void update(U32 amount)
  249. {
  250. numEvents++;
  251. total += amount;
  252. min = getMin((S32)amount, min);
  253. max = getMax((S32)amount, max);
  254. }
  255. NetStatInstance()
  256. {
  257. reset();
  258. }
  259. };
  260. NetStatInstance mNetStatPack;
  261. NetStatInstance mNetStatUnpack;
  262. NetStatInstance mNetStatWrite;
  263. NetStatInstance mNetStatRead;
  264. U32 mDirtyMaskFrequency[32];
  265. U32 mDirtyMaskTotal[32];
  266. void resetNetStats()
  267. {
  268. mNetStatPack.reset();
  269. mNetStatUnpack.reset();
  270. mNetStatWrite.reset();
  271. mNetStatRead.reset();
  272. for(S32 i=0; i<32; i++)
  273. {
  274. mDirtyMaskFrequency[i] = 0;
  275. mDirtyMaskTotal[i] = 0;
  276. }
  277. }
  278. void updateNetStatPack(U32 dirtyMask, U32 length)
  279. {
  280. mNetStatPack.update(length);
  281. for(S32 i=0; i<32; i++)
  282. if(BIT(i) & dirtyMask)
  283. {
  284. mDirtyMaskFrequency[i]++;
  285. mDirtyMaskTotal[i] += length;
  286. }
  287. }
  288. void updateNetStatUnpack(U32 length)
  289. {
  290. mNetStatUnpack.update(length);
  291. }
  292. void updateNetStatWriteData(U32 length)
  293. {
  294. mNetStatWrite.update(length);
  295. }
  296. void updateNetStatReadData(U32 length)
  297. {
  298. mNetStatRead.update(length);
  299. }
  300. #endif
  301. S32 getClassId (U32 netClassGroup) const { return mClassId[ netClassGroup ]; }
  302. static U32 getClassCRC (U32 netClassGroup) { return classCRC[ netClassGroup ]; }
  303. AbstractClassRep* getCommonParent( const AbstractClassRep *otherClass ) const;
  304. /// Return the name of this class.
  305. StringTableEntry getClassName() const { return mClassName; }
  306. /// Return the namespace that contains the methods of this class.
  307. Namespace* getNameSpace() const { return mNamespace; }
  308. /// Return the AbstractClassRep of the class that this class is derived from.
  309. AbstractClassRep* getParentClass() const { return parentClass; }
  310. virtual AbstractClassRep* getContainerChildClass(const bool recurse) = 0;
  311. virtual WriteCustomTamlSchema getCustomTamlSchema(void) = 0;
  312. /// Return the size of instances of this class in bytes.
  313. S32 getSizeof() const { return mClassSizeof; }
  314. /// Return the next class in the global class list link chain.
  315. AbstractClassRep* getNextClass() const { return nextClass; }
  316. /// Return the head of the global class list.
  317. static AbstractClassRep* getClassList() { return classLinkList; }
  318. /// Helper class to see if we are a given class, or a subclass thereof by
  319. /// comparing AbstractClassRep pointers.
  320. bool isSubclassOf( const AbstractClassRep* klass ) const
  321. {
  322. const AbstractClassRep *walk = this;
  323. // Walk up parents, checking for equivalence.
  324. while ( walk )
  325. {
  326. if ( walk == klass )
  327. return true;
  328. walk = walk->parentClass;
  329. };
  330. return false;
  331. }
  332. /// Helper class to see if we are a given class, or a subclass thereof by
  333. /// comparing the class name strings.
  334. bool isSubclassOf( const char *klass ) const
  335. {
  336. klass = StringTable->insert( klass );
  337. // Walk up parents, checking for equivalence.
  338. const AbstractClassRep *walk = this;
  339. while ( walk )
  340. {
  341. if ( walk->mClassName == klass )
  342. return true;
  343. walk = walk->parentClass;
  344. };
  345. return false;
  346. }
  347. /// @deprecated Use isSubclassOf.
  348. bool isClass( const AbstractClassRep* acr ) const
  349. {
  350. return isSubclassOf( acr );
  351. }
  352. virtual ConsoleObject* create () const = 0;
  353. AbstractClassRep* findFieldRoot(StringTableEntry fieldName);
  354. protected:
  355. virtual void init();
  356. const char * mClassName;
  357. AbstractClassRep * nextClass;
  358. AbstractClassRep * parentClass;
  359. Namespace * mNamespace;
  360. /// @}
  361. public:
  362. bool mIsRenderEnabled;
  363. bool mIsSelectionEnabled;
  364. bool isRenderEnabled() const { return mIsRenderEnabled; }
  365. bool isSelectionEnabled() const { return mIsSelectionEnabled; }
  366. /// @name Categories
  367. /// @{
  368. protected:
  369. const char* mCategory;
  370. const char* mDescription;
  371. public:
  372. /// Return the space separated category path for the class.
  373. const char* getCategory() const { return mCategory; }
  374. /// Return a short description string suitable for displaying in tooltips.
  375. const char* getDescription() const { return mDescription; }
  376. /// @}
  377. /// @name Fields
  378. /// @{
  379. public:
  380. /// This is a function pointer typedef to support get/set callbacks for fields
  381. typedef bool (*SetDataNotify)( void *obj, const char *array, const char *data );
  382. typedef const char *(*GetDataNotify)( void *obj, const char *data );
  383. /// This is a function pointer typedef to support optional writing for fields.
  384. typedef bool(*WriteDataNotify)(void* obj, StringTableEntry pFieldName);
  385. /// These are special field type values used to mark
  386. /// groups and arrays in the field list.
  387. /// @see Field::type
  388. /// @see addArray, endArray
  389. /// @see addGroup, endGroup
  390. /// @see addGroup, endGroup
  391. /// @see addDeprecatedField
  392. enum ACRFieldTypes : U32
  393. {
  394. /// The first custom field type... all fields
  395. /// types greater or equal to this one are not
  396. /// console data types.
  397. ARCFirstCustomField = 0xFFFFFFFB,
  398. /// Marks the start of a fixed size array of fields.
  399. /// @see addArray
  400. StartArrayFieldType = 0xFFFFFFFB,
  401. /// Marks the end of a fixed size array of fields.
  402. /// @see endArray
  403. EndArrayFieldType = 0xFFFFFFFC,
  404. /// Marks the beginning of a group of fields.
  405. /// @see addGroup
  406. StartGroupFieldType = 0xFFFFFFFD,
  407. /// Marks the beginning of a group of fields.
  408. /// @see endGroup
  409. EndGroupFieldType = 0xFFFFFFFE,
  410. /// Marks a field that is depreciated and no
  411. /// longer stores a value.
  412. /// @see addDeprecatedField
  413. DeprecatedFieldType = 0xFFFFFFFF
  414. };
  415. enum FieldFlags
  416. {
  417. FIELD_HideInInspectors = BIT( 0 ), ///< Do not show the field in inspectors.
  418. FIELD_ComponentInspectors = BIT(1), ///< Custom fields used by components. They are likely to be non-standard size/configuration, so
  419. ///< They are handled specially
  420. FIELD_CustomInspectors = BIT(2), ///< Display as a button in inspectors.
  421. FIELD_SpecialtyArrayField = BIT(3)
  422. };
  423. struct Field
  424. {
  425. Field()
  426. : pFieldname( NULL ),
  427. pGroupname( NULL ),
  428. pFieldDocs( NULL ),
  429. groupExpand( false ),
  430. type( 0 ),
  431. offset( 0 ),
  432. elementCount( 0 ),
  433. table( NULL ),
  434. validator( NULL ),
  435. setDataFn( NULL ),
  436. getDataFn( NULL ),
  437. writeDataFn(NULL),
  438. networkMask(0)
  439. {
  440. doNotSubstitute = keepClearSubsOnly = false;
  441. }
  442. StringTableEntry pFieldname; ///< Name of the field.
  443. const char* pGroupname; ///< Optionally filled field containing the group name.
  444. ///
  445. /// This is filled when type is StartField or EndField
  446. const char* pFieldDocs; ///< Documentation about this field; see consoleDoc.cc.
  447. bool groupExpand; ///< Flag to track expanded/not state of this group in the editor.
  448. U32 type; ///< A data type ID or one of the special custom fields. @see ACRFieldTypes
  449. U32 offset; ///< Memory offset from beginning of class for this field.
  450. S32 elementCount; ///< Number of elements, if this is an array.
  451. const EnumTable * table; ///< If this is an enum, this points to the table defining it.
  452. BitSet32 flag; ///< Stores various flags
  453. TypeValidator *validator; ///< Validator, if any.
  454. SetDataNotify setDataFn; ///< Set data notify Fn
  455. GetDataNotify getDataFn; ///< Get data notify Fn
  456. WriteDataNotify writeDataFn; ///< Function to determine whether data should be written or not.
  457. bool doNotSubstitute;
  458. bool keepClearSubsOnly;
  459. U32 networkMask;
  460. };
  461. typedef Vector<Field> FieldList;
  462. FieldList mFieldList;
  463. bool mDynamicGroupExpand;
  464. const Field* findField( StringTableEntry fieldName ) const;
  465. /// @}
  466. /// @name Console Type Interface
  467. /// @{
  468. void* getNativeVariable() override { return new ( AbstractClassRep* ); } // Any pointer-sized allocation will do.
  469. void deleteNativeVariable( void* var ) override { delete reinterpret_cast< AbstractClassRep** >( var ); }
  470. /// @}
  471. /// @name Abstract Class Database
  472. /// @{
  473. protected:
  474. static AbstractClassRep ** classTable[NetClassGroupsCount][NetClassTypesCount];
  475. static AbstractClassRep * classLinkList;
  476. static U32 classCRC[NetClassGroupsCount];
  477. static bool initialized;
  478. static ConsoleObject* create(const char* in_pClassName);
  479. static ConsoleObject* create(const U32 groupId, const U32 typeId, const U32 in_classId);
  480. public:
  481. static U32 NetClassCount [NetClassGroupsCount][NetClassTypesCount];
  482. static U32 NetClassBitSize[NetClassGroupsCount][NetClassTypesCount];
  483. static void registerClassRep(AbstractClassRep*);
  484. static AbstractClassRep* findClassRep(const char* in_pClassName);
  485. static AbstractClassRep* findClassRep( U32 groupId, U32 typeId, U32 classId );
  486. static void removeClassRep(AbstractClassRep*); // This should not be used lightly
  487. static void initialize(); // Called from Con::init once on startup
  488. static void shutdown();
  489. /// @}
  490. };
  491. extern AbstractClassRep::FieldList sg_tempFieldList;
  492. //=============================================================================
  493. // ConcreteClassRep.
  494. //=============================================================================
  495. /// Helper class for AbstractClassRep.
  496. ///
  497. /// @see AbtractClassRep
  498. /// @see ConsoleObject
  499. template< class T >
  500. class ConcreteAbstractClassRep : public AbstractClassRep
  501. {
  502. public:
  503. AbstractClassRep* getContainerChildClass(const bool recurse) override
  504. {
  505. // Fetch container children type.
  506. AbstractClassRep* pChildren = T::getContainerChildStaticClassRep();
  507. if (!recurse || pChildren != NULL)
  508. return pChildren;
  509. // Fetch parent type.
  510. AbstractClassRep* pParent = T::getParentStaticClassRep();
  511. if (pParent == NULL)
  512. return NULL;
  513. // Get parent container children.
  514. return pParent->getContainerChildClass(recurse);
  515. }
  516. WriteCustomTamlSchema getCustomTamlSchema(void) override
  517. {
  518. return T::getStaticWriteCustomTamlSchema();
  519. }
  520. static EnginePropertyTable _smPropertyTable;
  521. static EnginePropertyTable& smPropertyTable;
  522. ConcreteAbstractClassRep(const char* name,
  523. const char* conTypeName,
  524. S32* conTypeIdPtr,
  525. S32 netClassGroupMask,
  526. S32 netClassType,
  527. S32 netEventDir,
  528. AbstractClassRep* parent,
  529. const char* (*parentDesc)())
  530. : AbstractClassRep(conTypeIdPtr, conTypeName)
  531. {
  532. mClassName = StringTable->insert(name);
  533. mCategory = T::__category();
  534. mTypeInfo = _MAPTYPE< T >();
  535. if (mTypeInfo)
  536. const_cast< EngineTypeInfo* >(mTypeInfo)->mPropertyTable = &smPropertyTable;
  537. if (&T::__description != parentDesc)
  538. mDescription = T::__description();
  539. // Clean up mClassId
  540. for (U32 i = 0; i < NetClassGroupsCount; i++)
  541. mClassId[i] = -1;
  542. // Set properties for this ACR
  543. mClassType = netClassType;
  544. mClassGroupMask = netClassGroupMask;
  545. mNetEventDir = netEventDir;
  546. parentClass = parent;
  547. mClassSizeof = sizeof(T);
  548. // Finally, register ourselves.
  549. registerClassRep(this);
  550. };
  551. /// Wrap constructor.
  552. ConsoleObject* create() const override { return NULL; }
  553. /// Perform class specific initialization tasks.
  554. ///
  555. /// Link namespaces, call initPersistFields() and consoleInit().
  556. void init() override
  557. {
  558. // Get handle to our parent class, if any, and ourselves (we are our parent's child).
  559. AbstractClassRep *parent = T::getParentStaticClassRep();
  560. AbstractClassRep *child = T::getStaticClassRep();
  561. // If we got reps, then link those namespaces! (To get proper inheritance.)
  562. if (parent && child)
  563. Con::classLinkNamespaces(parent->getNameSpace(), child->getNameSpace());
  564. // Finally, do any class specific initialization...
  565. T::initPersistFields();
  566. T::consoleInit();
  567. EnginePropertyTable::Property* props = new EnginePropertyTable::Property[sg_tempFieldList.size() + 1];
  568. for (int i = 0; i < sg_tempFieldList.size(); ++i)
  569. {
  570. EnginePropertyTable::Property prop;
  571. prop.mDocString = sg_tempFieldList[i].pFieldDocs;
  572. prop.mName = sg_tempFieldList[i].pFieldname;
  573. prop.mNumElements = sg_tempFieldList[i].elementCount;
  574. prop.mFlags = 0;
  575. if (sg_tempFieldList[i].type == StartGroupFieldType)
  576. prop.mFlags |= EnginePropertyGroupBegin;
  577. if (sg_tempFieldList[i].type == EndGroupFieldType)
  578. prop.mFlags |= EnginePropertyGroupEnd;
  579. prop.mType = sg_tempFieldList[i].type;
  580. props[i] = prop;
  581. }
  582. _smPropertyTable = EnginePropertyTable(sg_tempFieldList.size(), props);
  583. smPropertyTable = _smPropertyTable;
  584. const_cast<EngineTypeInfo*>(mTypeInfo)->mPropertyTable = &_smPropertyTable;
  585. // Let the base finish up.
  586. AbstractClassRep::init();
  587. }
  588. /// @name Console Type Interface
  589. /// @{
  590. void setData(void* dptr, S32 argc, const char** argv, const EnumTable* tbl, BitSet32 flag) override
  591. {
  592. if (argc == 1)
  593. {
  594. T** obj = (T**)dptr;
  595. *obj = dynamic_cast< T* >(T::__findObject(argv[0]));
  596. }
  597. else
  598. Con::errorf("Cannot set multiple args to a single ConsoleObject*.");
  599. }
  600. const char* getData(void* dptr, const EnumTable* tbl, BitSet32 flag) override
  601. {
  602. T** obj = (T**)dptr;
  603. return Con::getReturnBuffer(T::__getObjectId(*obj));
  604. }
  605. const char* getTypeClassName() override { return mClassName; }
  606. const bool isDatablock() override { return T::__smIsDatablock; };
  607. /// @}
  608. };
  609. template< class T >
  610. class ConcreteClassRep : public ConcreteAbstractClassRep<T>
  611. {
  612. public:
  613. ConcreteClassRep(const char* name,
  614. const char* conTypeName,
  615. S32* conTypeIdPtr,
  616. S32 netClassGroupMask,
  617. S32 netClassType,
  618. S32 netEventDir,
  619. AbstractClassRep* parent,
  620. const char* (*parentDesc)())
  621. : ConcreteAbstractClassRep<T>(name, conTypeName, conTypeIdPtr, netClassGroupMask, netClassType, netEventDir, parent, parentDesc)
  622. {
  623. }
  624. /// Wrap constructor.
  625. ConsoleObject* create() const override { return new T; }
  626. };
  627. template< typename T > EnginePropertyTable ConcreteAbstractClassRep< T >::_smPropertyTable(0, NULL);
  628. template< typename T > EnginePropertyTable& ConcreteAbstractClassRep< T >::smPropertyTable = ConcreteAbstractClassRep< T >::_smPropertyTable;
  629. //------------------------------------------------------------------------------
  630. // Forward declaration of this function so it can be used in the class
  631. const char *defaultProtectedGetFn( void *obj, const char *data );
  632. bool defaultProtectedWriteFn(void* obj, StringTableEntry pFieldName);
  633. //=============================================================================
  634. // ConsoleObject.
  635. //=============================================================================
  636. /// Interface class to the console.
  637. ///
  638. /// @section ConsoleObject_basics The Basics
  639. ///
  640. /// Any object which you want to work with the console system should derive from this,
  641. /// and access functionality through the static interface.
  642. ///
  643. /// This class is always used with the DECLARE_CONOBJECT and IMPLEMENT_* macros.
  644. ///
  645. /// @code
  646. /// // A very basic example object. It will do nothing!
  647. /// class TorqueObject : public ConsoleObject {
  648. /// // Must provide a Parent typedef so the console system knows what we inherit from.
  649. /// typedef ConsoleObject Parent;
  650. ///
  651. /// // This does a lot of menial declaration for you.
  652. /// DECLARE_CONOBJECT(TorqueObject);
  653. ///
  654. /// // This is for us to register our fields in.
  655. /// static void initPersistFields();
  656. ///
  657. /// // A sample field.
  658. /// S8 mSample;
  659. /// }
  660. /// @endcode
  661. ///
  662. /// @code
  663. /// // And the accordant implementation...
  664. /// IMPLEMENT_CONOBJECT(TorqueObject);
  665. ///
  666. /// void TorqueObject::initPersistFields()
  667. /// {
  668. /// // If you want to inherit any fields from the parent (you do), do this:
  669. /// Parent::initPersistFields();
  670. ///
  671. /// // Pass the field, the type, the offset, and a usage string.
  672. /// addField("sample", TypeS8, Offset(mSample, TorqueObject), "A test field.");
  673. /// }
  674. /// @endcode
  675. ///
  676. /// That's all you need to do to get a class registered with the console system. At this point,
  677. /// you can instantiate it via script, tie methods to it using ConsoleMethod, register fields,
  678. /// and so forth. You can also register any global variables related to the class by creating
  679. /// a consoleInit() method.
  680. ///
  681. /// You will need to use different IMPLEMENT_ macros in different cases; for instance, if you
  682. /// are making a NetObject (for ghosting), a DataBlock, or a NetEvent.
  683. ///
  684. /// @see AbstractClassRep for gory implementation details.
  685. /// @nosubgrouping
  686. class ConsoleObject : public EngineObject
  687. {
  688. DECLARE_ABSTRACT_CLASS( ConsoleObject, EngineObject );
  689. protected:
  690. /// @deprecated This is disallowed.
  691. ConsoleObject(const ConsoleObject&) { mDocsClick = false; };
  692. public:
  693. /// <summary>
  694. /// Only used for interfacing with the editor's inspector docsURL button
  695. /// </summary>
  696. bool mDocsClick;
  697. ConsoleObject() { mDocsClick = false; }
  698. /// Get a reference to a field by name.
  699. const AbstractClassRep::Field *findField(StringTableEntry fieldName) const;
  700. /// Gets the ClassRep.
  701. virtual AbstractClassRep* getClassRep() const;
  702. #define DECLARE_ABSTRACT_CONOBJECT( className ) \
  703. DECLARE_ABSTRACT_CLASS( className, Parent ); \
  704. static S32 _smTypeId; \
  705. static ConcreteAbstractClassRep< className > dynClassRep; \
  706. static AbstractClassRep* getParentStaticClassRep(); \
  707. static AbstractClassRep* getStaticClassRep(); \
  708. static SimObjectRefConsoleBaseType< className > ptrRefType; \
  709. virtual AbstractClassRep* getClassRep() const
  710. /// Set the value of a field.
  711. bool setField(const char *fieldName, const char *value);
  712. public:
  713. /// @name Object Creation
  714. /// @{
  715. static ConsoleObject* create(const char* in_pClassName);
  716. static ConsoleObject* create(const U32 groupId, const U32 typeId, const U32 in_classId);
  717. /// @}
  718. public:
  719. /// Get the classname from a class tag.
  720. static const char* lookupClassName(const U32 in_classTag) { return ""; };
  721. /// @name Fields
  722. /// @{
  723. /// Mark the beginning of a group of fields.
  724. ///
  725. /// This is used in the consoleDoc system.
  726. /// @see console_autodoc
  727. static void addGroup(const char* in_pGroupname, const char* in_pGroupDocs = NULL);
  728. /// Mark the end of a group of fields.
  729. ///
  730. /// This is used in the consoleDoc system.
  731. /// @see console_autodoc
  732. static void endGroup(const char* in_pGroupname);
  733. /// Marks the start of a fixed size array of fields.
  734. /// @see console_autodoc
  735. static void addArray( const char *arrayName, S32 count );
  736. /// Marks the end of an array of fields.
  737. /// @see console_autodoc
  738. static void endArray( const char *arrayName );
  739. /// Register a complex field.
  740. ///
  741. /// @param in_pFieldname Name of the field.
  742. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  743. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  744. /// @param in_elementCount Number of elements in this field. Arrays of elements are assumed to be contiguous in memory.
  745. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  746. static void addField(const char* in_pFieldname,
  747. const U32 in_fieldType,
  748. const dsize_t in_fieldOffset,
  749. const U32 in_elementCount = 1,
  750. const char* in_pFieldDocs = NULL,
  751. U32 flags = 0 );
  752. static void addField(const char* in_pFieldname,
  753. const U32 in_fieldType,
  754. const dsize_t in_fieldOffset,
  755. AbstractClassRep::WriteDataNotify in_writeDataFn,
  756. const U32 in_elementCount = 1,
  757. const char* in_pFieldDocs = NULL,
  758. U32 flags = 0);
  759. /// Register a simple field.
  760. ///
  761. /// @param in_pFieldname Name of the field.
  762. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  763. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  764. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  765. static void addField(const char* in_pFieldname,
  766. const U32 in_fieldType,
  767. const dsize_t in_fieldOffset,
  768. const char* in_pFieldDocs,
  769. U32 flags = 0 );
  770. static void addField(const char* in_pFieldname,
  771. const U32 in_fieldType,
  772. const dsize_t in_fieldOffset,
  773. AbstractClassRep::WriteDataNotify in_writeDataFn,
  774. const char* in_pFieldDocs,
  775. U32 flags = 0);
  776. /// Register a validated field.
  777. ///
  778. /// A validated field is just like a normal field except that you can't
  779. /// have it be an array, and that you give it a pointer to a TypeValidator
  780. /// subclass, which is then used to validate any value placed in it. Invalid
  781. /// values are ignored and an error is printed to the console.
  782. ///
  783. /// @see addField
  784. /// @see typeValidators.h
  785. static void addFieldV(const char* in_pFieldname,
  786. const U32 in_fieldType,
  787. const dsize_t in_fieldOffset,
  788. TypeValidator *v,
  789. const char * in_pFieldDocs = NULL);
  790. /// Register a complex protected field.
  791. ///
  792. /// @param in_pFieldname Name of the field.
  793. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  794. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  795. /// @param in_setDataFn When this field gets set, it will call the callback provided. @see console_protected
  796. /// @param in_getDataFn When this field is accessed for it's data, it will return the value of this function
  797. /// @param in_elementCount Number of elements in this field. Arrays of elements are assumed to be contiguous in memory.
  798. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  799. static void addProtectedField(const char* in_pFieldname,
  800. const U32 in_fieldType,
  801. const dsize_t in_fieldOffset,
  802. AbstractClassRep::SetDataNotify in_setDataFn,
  803. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  804. AbstractClassRep::WriteDataNotify in_writeDataFn = &defaultProtectedWriteFn,
  805. const U32 in_elementCount = 1,
  806. const char* in_pFieldDocs = NULL,
  807. U32 flags = 0);
  808. static void addProtectedField(const char* in_pFieldname,
  809. const U32 in_fieldType,
  810. const dsize_t in_fieldOffset,
  811. AbstractClassRep::SetDataNotify in_setDataFn,
  812. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  813. const U32 in_elementCount = 1,
  814. const char* in_pFieldDocs = NULL,
  815. U32 flags = 0);
  816. /// Register a simple protected field.
  817. ///
  818. /// @param in_pFieldname Name of the field.
  819. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  820. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  821. /// @param in_setDataFn When this field gets set, it will call the callback provided. @see console_protected
  822. /// @param in_getDataFn When this field is accessed for it's data, it will return the value of this function
  823. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  824. static void addProtectedField(const char* in_pFieldname,
  825. const U32 in_fieldType,
  826. const dsize_t in_fieldOffset,
  827. AbstractClassRep::SetDataNotify in_setDataFn,
  828. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  829. AbstractClassRep::WriteDataNotify in_writeDataFn = &defaultProtectedWriteFn,
  830. const char* in_pFieldDocs = NULL,
  831. U32 flags = 0);
  832. static void addProtectedField(const char* in_pFieldname,
  833. const U32 in_fieldType,
  834. const dsize_t in_fieldOffset,
  835. AbstractClassRep::SetDataNotify in_setDataFn,
  836. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  837. const char* in_pFieldDocs = NULL,
  838. U32 flags = 0);
  839. /// Add a deprecated field.
  840. ///
  841. /// A deprecated field will always be undefined, even if you assign a value to it. This
  842. /// is useful when you need to make sure that a field is not being used anymore.
  843. static void addDeprecatedField(const char *fieldName);
  844. /// Remove a field.
  845. ///
  846. /// Sometimes, you just have to remove a field!
  847. /// @returns True on success.
  848. static bool removeField(const char* in_pFieldname);
  849. /// @}
  850. /// @name Logging
  851. /// @{
  852. /// Overload this in subclasses to change the message formatting.
  853. /// @param fmt A printf style format string.
  854. /// @param args A va_list containing the args passed ot a log function.
  855. /// @note It is suggested that you use String::VToString.
  856. virtual String _getLogMessage(const char* fmt, va_list args) const;
  857. /// @}
  858. public:
  859. /// @name Logging
  860. /// These functions will try to print out a message along the lines
  861. /// of "ObjectClass - ObjectName(ObjectId) - formatted message"
  862. /// @{
  863. /// Logs with Con::printf.
  864. void logMessage(const char* fmt, ...) const;
  865. /// Logs with Con::warnf.
  866. void logWarning(const char* fmt, ...) const;
  867. /// Logs with Con::errorf.
  868. void logError(const char* fmt, ...) const;
  869. /// @}
  870. /// Register dynamic fields in a subclass of ConsoleObject.
  871. ///
  872. /// @see addField(), addFieldV(), addDeprecatedField(), addGroup(), endGroup()
  873. static void initPersistFields();
  874. /// Register global constant variables and do other one-time initialization tasks in
  875. /// a subclass of ConsoleObject.
  876. ///
  877. /// @deprecated You should use ConsoleMethod and ConsoleFunction, not this, to
  878. /// register methods or commands.
  879. /// @see console
  880. static void consoleInit();
  881. /// @name Field List
  882. /// @{
  883. /// Get a list of all the fields. This information cannot be modified.
  884. const AbstractClassRep::FieldList& getFieldList() const;
  885. /// Get a list of all the fields, set up so we can modify them.
  886. ///
  887. /// @note This is a bad trick to pull if you aren't very careful,
  888. /// since you can blast field data!
  889. AbstractClassRep::FieldList& getModifiableFieldList();
  890. /// Get a handle to a boolean telling us if we expanded the dynamic group.
  891. ///
  892. /// @see GuiInspector::Inspect()
  893. bool& getDynamicGroupExpand();
  894. /// @}
  895. /// @name ConsoleObject Implementation
  896. ///
  897. /// These functions are implemented in every subclass of
  898. /// ConsoleObject by an IMPLEMENT_CONOBJECT or IMPLEMENT_CO_* macro.
  899. /// @{
  900. /// Get the abstract class information for this class.
  901. static AbstractClassRep *getStaticClassRep() { return NULL; }
  902. /// Get the abstract class information for this class's superclass.
  903. static AbstractClassRep *getParentStaticClassRep() { return NULL; }
  904. /// Get our network-layer class id.
  905. ///
  906. /// @param netClassGroup The net class for which we want our ID.
  907. /// @see
  908. S32 getClassId(U32 netClassGroup) const;
  909. /// Get our compiler and platform independent class name.
  910. ///
  911. /// @note This name can be used to instantiate another instance using create()
  912. StringTableEntry getClassName() const;
  913. /// @}
  914. static const char* __category() { return ""; }
  915. static const char* __description() { return ""; }
  916. /// Subclasses of ConsoleObjects that are datablocks should redefine this static member variable
  917. /// and set it to true.
  918. static const bool __smIsDatablock = false;
  919. /// @name Object IDs and lookup.
  920. /// For a subclass hierarchy based on ConsoleObject to become functional for use as a console object type,
  921. /// the hierarchy must implement a naming scheme and indexing function for looking up objects by name.
  922. /// @{
  923. static ConsoleObject* __findObject( const char* ) { return NULL; }
  924. static const char* __getObjectId( ConsoleObject* ) { return ""; }
  925. protected:
  926. static bool disableFieldSubstitutions(const char* in_pFieldname);
  927. static bool onlyKeepClearSubstitutions(const char* in_pFieldname);
  928. };
  929. #define addNamedField(fieldName,type,className) addField(#fieldName, type, Offset(fieldName,className))
  930. #define addNamedFieldV(fieldName,type,className, validator) addFieldV(#fieldName, type, Offset(fieldName,className), validator)
  931. //------------------------------------------------------------------------------
  932. //-------------------------------------- Inlines
  933. //
  934. inline S32 ConsoleObject::getClassId(U32 netClassGroup) const
  935. {
  936. AssertFatal(getClassRep() != NULL,"Cannot get tag from non-declared dynamic class!");
  937. return getClassRep()->getClassId(netClassGroup);
  938. }
  939. inline StringTableEntry ConsoleObject::getClassName() const
  940. {
  941. AssertFatal(getClassRep() != NULL,
  942. "Cannot get tag from non-declared dynamic class");
  943. return getClassRep()->getClassName();
  944. }
  945. inline const AbstractClassRep::Field * ConsoleObject::findField(StringTableEntry name) const
  946. {
  947. AssertFatal(getClassRep() != NULL,
  948. avar("Cannot get field '%s' from non-declared dynamic class.", name));
  949. return getClassRep()->findField(name);
  950. }
  951. inline bool ConsoleObject::setField(const char *fieldName, const char *value)
  952. {
  953. //sanity check
  954. if ((! fieldName) || (! fieldName[0]) || (! value))
  955. return false;
  956. if (! getClassRep())
  957. return false;
  958. const AbstractClassRep::Field *myField = getClassRep()->findField(StringTable->insert(fieldName));
  959. if (! myField)
  960. return false;
  961. Con::setData(
  962. myField->type,
  963. (void *) (((const char *)(this)) + myField->offset),
  964. 0,
  965. 1,
  966. &value,
  967. myField->table,
  968. myField->flag);
  969. return true;
  970. }
  971. inline ConsoleObject* ConsoleObject::create(const char* in_pClassName)
  972. {
  973. return AbstractClassRep::create(in_pClassName);
  974. }
  975. inline ConsoleObject* ConsoleObject::create(const U32 groupId, const U32 typeId, const U32 in_classId)
  976. {
  977. return AbstractClassRep::create(groupId, typeId, in_classId);
  978. }
  979. inline const AbstractClassRep::FieldList& ConsoleObject::getFieldList() const
  980. {
  981. return getClassRep()->mFieldList;
  982. }
  983. inline AbstractClassRep::FieldList& ConsoleObject::getModifiableFieldList()
  984. {
  985. return getClassRep()->mFieldList;
  986. }
  987. inline bool& ConsoleObject::getDynamicGroupExpand()
  988. {
  989. return getClassRep()->mDynamicGroupExpand;
  990. }
  991. /// @name ConsoleObject Macros
  992. /// @{
  993. #define DECLARE_CONOBJECT( className ) \
  994. DECLARE_CLASS( className, Parent ); \
  995. static S32 _smTypeId; \
  996. static ConcreteClassRep< className > dynClassRep; \
  997. static AbstractClassRep* getParentStaticClassRep(); \
  998. static AbstractClassRep* getStaticClassRep(); \
  999. static SimObjectRefConsoleBaseType< className > ptrRefType; \
  1000. static AbstractClassRep::WriteCustomTamlSchema getStaticWriteCustomTamlSchema(); \
  1001. static AbstractClassRep* getContainerChildStaticClassRep(); \
  1002. AbstractClassRep* getClassRep() const override
  1003. #define DECLARE_CATEGORY( string ) \
  1004. static const char* __category() { return string; }
  1005. #define DECLARE_DESCRIPTION( string ) \
  1006. static const char* __description() { return string; }
  1007. #define IMPLEMENT_CONOBJECT( className ) \
  1008. IMPLEMENT_CLASS( className, NULL ) \
  1009. END_IMPLEMENT_CLASS; \
  1010. S32 className::_smTypeId; \
  1011. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  1012. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  1013. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  1014. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  1015. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  1016. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  1017. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  1018. #define IMPLEMENT_CONOBJECT_CHILDREN( className ) \
  1019. IMPLEMENT_CLASS( className, NULL ) \
  1020. END_IMPLEMENT_CLASS; \
  1021. S32 className::_smTypeId; \
  1022. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  1023. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  1024. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  1025. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  1026. AbstractClassRep* className::getContainerChildStaticClassRep() { return Children::getStaticClassRep(); } \
  1027. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  1028. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  1029. #define IMPLEMENT_CONOBJECT_SCHEMA( className, schema ) \
  1030. IMPLEMENT_CLASS( className, NULL ) \
  1031. END_IMPLEMENT_CLASS; \
  1032. S32 className::_smTypeId; \
  1033. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  1034. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  1035. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  1036. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  1037. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  1038. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \
  1039. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  1040. #define IMPLEMENT_CONOBJECT_CHILDREN_SCHEMA( className, schema ) \
  1041. IMPLEMENT_CLASS( className, NULL ) \
  1042. END_IMPLEMENT_CLASS; \
  1043. S32 className::_smTypeId; \
  1044. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  1045. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  1046. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  1047. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  1048. AbstractClassRep* className::getContainerChildStaticClassRep() { return Children::getStaticClassRep(); } \
  1049. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \
  1050. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  1051. #define IMPLEMENT_ABSTRACT_CONOBJECT( className ) \
  1052. IMPLEMENT_NONINSTANTIABLE_CLASS( className, NULL ) \
  1053. END_IMPLEMENT_CLASS; \
  1054. S32 className::_smTypeId; \
  1055. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  1056. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  1057. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  1058. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  1059. ConcreteAbstractClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  1060. #define IMPLEMENT_CO_NETOBJECT_V1( className ) \
  1061. IMPLEMENT_CLASS( className, NULL ) \
  1062. END_IMPLEMENT_CLASS; \
  1063. S32 className::_smTypeId; \
  1064. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  1065. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  1066. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  1067. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  1068. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  1069. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  1070. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, NetClassGroupGameMask, NetClassTypeObject, 0, className::getParentStaticClassRep(), &Parent::__description )
  1071. #define IMPLEMENT_CO_DATABLOCK_V1( className ) \
  1072. IMPLEMENT_CLASS( className, NULL ) \
  1073. END_IMPLEMENT_CLASS; \
  1074. S32 className::_smTypeId; \
  1075. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  1076. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  1077. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  1078. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  1079. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  1080. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  1081. ConcreteClassRep<className> className::dynClassRep(#className, "Type" #className, &_smTypeId, NetClassGroupGameMask, NetClassTypeDataBlock, 0, className::getParentStaticClassRep(), &Parent::__description )
  1082. // Support for adding properties to classes CONOBJECT style.
  1083. #define PROPERTY_TABLE( className ) \
  1084. namespace { namespace _ ## className { \
  1085. extern EnginePropertyTable _propTable; \
  1086. } } \
  1087. template<> EnginePropertyTable& \
  1088. ConcreteClassRep< className >::smPropertyTable = _ ## className::_propTable; \
  1089. namespace { namespace _ ## className { \
  1090. EnginePropertyTable::Property _props[] = {
  1091. #define END_PROPERTY_TABLE \
  1092. { NULL } \
  1093. }; \
  1094. EnginePropertyTable _propTable( sizeof( _props ) / sizeof( _props[ 0 ] ) - 1, _props ); \
  1095. } }
  1096. /// @}
  1097. //------------------------------------------------------------------------------
  1098. // Protected field default get/set functions
  1099. //
  1100. // The reason for these functions is that it will save one branch per console
  1101. // data request and script functions will still execute at the same speed as
  1102. // before the modifications to allow protected static fields. These will just
  1103. // inline and the code should be roughly the same size, and just as fast as
  1104. // before the modifications. -pw
  1105. inline bool defaultProtectedSetFn( void *object, const char *index, const char *data )
  1106. {
  1107. return true;
  1108. }
  1109. inline bool defaultProtectedSetNotEmptyFn( void *object, const char *index, const char *data )
  1110. {
  1111. return data && data[0];
  1112. }
  1113. inline const char *defaultProtectedGetFn( void *obj, const char *data )
  1114. {
  1115. return data;
  1116. }
  1117. inline const char *emptyStringProtectedGetFn( void *obj, const char *data )
  1118. {
  1119. return "";
  1120. }
  1121. inline bool defaultProtectedWriteFn(void* obj, StringTableEntry pFieldName)
  1122. {
  1123. return true;
  1124. }
  1125. inline bool defaultProtectedNotSetFn(void* obj, const char *array, const char* data)
  1126. {
  1127. return false;
  1128. }
  1129. inline bool defaultProtectedNotWriteFn(void* obj, StringTableEntry pFieldName)
  1130. {
  1131. return false;
  1132. }
  1133. /// @}
  1134. #endif //_CONSOLEOBJECT_H_