consoleObject.h 48 KB

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