consoleObject.h 51 KB

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