consoleObject.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  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.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. /// These are special field type values used to mark
  364. /// groups and arrays in the field list.
  365. /// @see Field::type
  366. /// @see addArray, endArray
  367. /// @see addGroup, endGroup
  368. /// @see addGroup, endGroup
  369. /// @see addDeprecatedField
  370. enum ACRFieldTypes : U32
  371. {
  372. /// The first custom field type... all fields
  373. /// types greater or equal to this one are not
  374. /// console data types.
  375. ARCFirstCustomField = 0xFFFFFFFB,
  376. /// Marks the start of a fixed size array of fields.
  377. /// @see addArray
  378. StartArrayFieldType = 0xFFFFFFFB,
  379. /// Marks the end of a fixed size array of fields.
  380. /// @see endArray
  381. EndArrayFieldType = 0xFFFFFFFC,
  382. /// Marks the beginning of a group of fields.
  383. /// @see addGroup
  384. StartGroupFieldType = 0xFFFFFFFD,
  385. /// Marks the beginning of a group of fields.
  386. /// @see endGroup
  387. EndGroupFieldType = 0xFFFFFFFE,
  388. /// Marks a field that is depreciated and no
  389. /// longer stores a value.
  390. /// @see addDeprecatedField
  391. DeprecatedFieldType = 0xFFFFFFFF
  392. };
  393. enum FieldFlags
  394. {
  395. FIELD_HideInInspectors = BIT( 0 ), ///< Do not show the field in inspectors.
  396. FIELD_ComponentInspectors = BIT(1), ///< Custom fields used by components. They are likely to be non-standard size/configuration, so
  397. ///< They are handled specially
  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 ConcreteAbstractClassRep : public AbstractClassRep
  471. {
  472. public:
  473. virtual AbstractClassRep* getContainerChildClass(const bool recurse)
  474. {
  475. // Fetch container children type.
  476. AbstractClassRep* pChildren = T::getContainerChildStaticClassRep();
  477. if (!recurse || pChildren != NULL)
  478. return pChildren;
  479. // Fetch parent type.
  480. AbstractClassRep* pParent = T::getParentStaticClassRep();
  481. if (pParent == NULL)
  482. return NULL;
  483. // Get parent container children.
  484. return pParent->getContainerChildClass(recurse);
  485. }
  486. virtual WriteCustomTamlSchema getCustomTamlSchema(void)
  487. {
  488. return T::getStaticWriteCustomTamlSchema();
  489. }
  490. static EnginePropertyTable _smPropertyTable;
  491. static EnginePropertyTable& smPropertyTable;
  492. ConcreteAbstractClassRep(const char* name,
  493. const char* conTypeName,
  494. S32* conTypeIdPtr,
  495. S32 netClassGroupMask,
  496. S32 netClassType,
  497. S32 netEventDir,
  498. AbstractClassRep* parent,
  499. const char* (*parentDesc)())
  500. : AbstractClassRep(conTypeIdPtr, conTypeName)
  501. {
  502. mClassName = StringTable->insert(name);
  503. mCategory = T::__category();
  504. mTypeInfo = _MAPTYPE< T >();
  505. if (mTypeInfo)
  506. const_cast< EngineTypeInfo* >(mTypeInfo)->mPropertyTable = &smPropertyTable;
  507. if (&T::__description != parentDesc)
  508. mDescription = T::__description();
  509. // Clean up mClassId
  510. for (U32 i = 0; i < NetClassGroupsCount; i++)
  511. mClassId[i] = -1;
  512. // Set properties for this ACR
  513. mClassType = netClassType;
  514. mClassGroupMask = netClassGroupMask;
  515. mNetEventDir = netEventDir;
  516. parentClass = parent;
  517. mClassSizeof = sizeof(T);
  518. // Finally, register ourselves.
  519. registerClassRep(this);
  520. };
  521. /// Wrap constructor.
  522. ConsoleObject* create() const { return NULL; }
  523. /// Perform class specific initialization tasks.
  524. ///
  525. /// Link namespaces, call initPersistFields() and consoleInit().
  526. void init()
  527. {
  528. // Get handle to our parent class, if any, and ourselves (we are our parent's child).
  529. AbstractClassRep *parent = T::getParentStaticClassRep();
  530. AbstractClassRep *child = T::getStaticClassRep();
  531. // If we got reps, then link those namespaces! (To get proper inheritance.)
  532. if (parent && child)
  533. Con::classLinkNamespaces(parent->getNameSpace(), child->getNameSpace());
  534. // Finally, do any class specific initialization...
  535. T::initPersistFields();
  536. T::consoleInit();
  537. // Let the base finish up.
  538. AbstractClassRep::init();
  539. }
  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< class T >
  562. class ConcreteClassRep : public ConcreteAbstractClassRep<T>
  563. {
  564. public:
  565. ConcreteClassRep(const char* name,
  566. const char* conTypeName,
  567. S32* conTypeIdPtr,
  568. S32 netClassGroupMask,
  569. S32 netClassType,
  570. S32 netEventDir,
  571. AbstractClassRep* parent,
  572. const char* (*parentDesc)())
  573. : ConcreteAbstractClassRep<T>(name, conTypeName, conTypeIdPtr, netClassGroupMask, netClassType, netEventDir, parent, parentDesc)
  574. {
  575. }
  576. /// Wrap constructor.
  577. ConsoleObject* create() const { return new T; }
  578. };
  579. template< typename T > EnginePropertyTable ConcreteAbstractClassRep< T >::_smPropertyTable(0, NULL);
  580. template< typename T > EnginePropertyTable& ConcreteAbstractClassRep< T >::smPropertyTable = ConcreteAbstractClassRep< T >::_smPropertyTable;
  581. //------------------------------------------------------------------------------
  582. // Forward declaration of this function so it can be used in the class
  583. const char *defaultProtectedGetFn( void *obj, const char *data );
  584. bool defaultProtectedWriteFn(void* obj, StringTableEntry pFieldName);
  585. //=============================================================================
  586. // ConsoleObject.
  587. //=============================================================================
  588. /// Interface class to the console.
  589. ///
  590. /// @section ConsoleObject_basics The Basics
  591. ///
  592. /// Any object which you want to work with the console system should derive from this,
  593. /// and access functionality through the static interface.
  594. ///
  595. /// This class is always used with the DECLARE_CONOBJECT and IMPLEMENT_* macros.
  596. ///
  597. /// @code
  598. /// // A very basic example object. It will do nothing!
  599. /// class TorqueObject : public ConsoleObject {
  600. /// // Must provide a Parent typedef so the console system knows what we inherit from.
  601. /// typedef ConsoleObject Parent;
  602. ///
  603. /// // This does a lot of menial declaration for you.
  604. /// DECLARE_CONOBJECT(TorqueObject);
  605. ///
  606. /// // This is for us to register our fields in.
  607. /// static void initPersistFields();
  608. ///
  609. /// // A sample field.
  610. /// S8 mSample;
  611. /// }
  612. /// @endcode
  613. ///
  614. /// @code
  615. /// // And the accordant implementation...
  616. /// IMPLEMENT_CONOBJECT(TorqueObject);
  617. ///
  618. /// void TorqueObject::initPersistFields()
  619. /// {
  620. /// // If you want to inherit any fields from the parent (you do), do this:
  621. /// Parent::initPersistFields();
  622. ///
  623. /// // Pass the field, the type, the offset, and a usage string.
  624. /// addField("sample", TypeS8, Offset(mSample, TorqueObject), "A test field.");
  625. /// }
  626. /// @endcode
  627. ///
  628. /// That's all you need to do to get a class registered with the console system. At this point,
  629. /// you can instantiate it via script, tie methods to it using ConsoleMethod, register fields,
  630. /// and so forth. You can also register any global variables related to the class by creating
  631. /// a consoleInit() method.
  632. ///
  633. /// You will need to use different IMPLEMENT_ macros in different cases; for instance, if you
  634. /// are making a NetObject (for ghosting), a DataBlock, or a NetEvent.
  635. ///
  636. /// @see AbstractClassRep for gory implementation details.
  637. /// @nosubgrouping
  638. class ConsoleObject : public EngineObject
  639. {
  640. DECLARE_ABSTRACT_CLASS( ConsoleObject, EngineObject );
  641. protected:
  642. /// @deprecated This is disallowed.
  643. ConsoleObject(const ConsoleObject&);
  644. public:
  645. ConsoleObject() {}
  646. /// Get a reference to a field by name.
  647. const AbstractClassRep::Field *findField(StringTableEntry fieldName) const;
  648. /// Gets the ClassRep.
  649. virtual AbstractClassRep* getClassRep() const;
  650. #define DECLARE_ABSTRACT_CONOBJECT( className ) \
  651. DECLARE_ABSTRACT_CLASS( className, Parent ); \
  652. static S32 _smTypeId; \
  653. static ConcreteAbstractClassRep< className > dynClassRep; \
  654. static AbstractClassRep* getParentStaticClassRep(); \
  655. static AbstractClassRep* getStaticClassRep(); \
  656. static SimObjectRefConsoleBaseType< className > ptrRefType; \
  657. virtual AbstractClassRep* getClassRep() const
  658. /// Set the value of a field.
  659. bool setField(const char *fieldName, const char *value);
  660. public:
  661. /// @name Object Creation
  662. /// @{
  663. static ConsoleObject* create(const char* in_pClassName);
  664. static ConsoleObject* create(const U32 groupId, const U32 typeId, const U32 in_classId);
  665. /// @}
  666. public:
  667. /// Get the classname from a class tag.
  668. static const char* lookupClassName(const U32 in_classTag);
  669. /// @name Fields
  670. /// @{
  671. /// Mark the beginning of a group of fields.
  672. ///
  673. /// This is used in the consoleDoc system.
  674. /// @see console_autodoc
  675. static void addGroup(const char* in_pGroupname, const char* in_pGroupDocs = NULL);
  676. /// Mark the end of a group of fields.
  677. ///
  678. /// This is used in the consoleDoc system.
  679. /// @see console_autodoc
  680. static void endGroup(const char* in_pGroupname);
  681. /// Marks the start of a fixed size array of fields.
  682. /// @see console_autodoc
  683. static void addArray( const char *arrayName, S32 count );
  684. /// Marks the end of an array of fields.
  685. /// @see console_autodoc
  686. static void endArray( const char *arrayName );
  687. /// Register a complex field.
  688. ///
  689. /// @param in_pFieldname Name of the field.
  690. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  691. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  692. /// @param in_elementCount Number of elements in this field. Arrays of elements are assumed to be contiguous in memory.
  693. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  694. static void addField(const char* in_pFieldname,
  695. const U32 in_fieldType,
  696. const dsize_t in_fieldOffset,
  697. const U32 in_elementCount = 1,
  698. const char* in_pFieldDocs = NULL,
  699. U32 flags = 0 );
  700. static void addField(const char* in_pFieldname,
  701. const U32 in_fieldType,
  702. const dsize_t in_fieldOffset,
  703. AbstractClassRep::WriteDataNotify in_writeDataFn,
  704. const U32 in_elementCount = 1,
  705. const char* in_pFieldDocs = NULL,
  706. U32 flags = 0);
  707. /// Register a simple field.
  708. ///
  709. /// @param in_pFieldname Name of the field.
  710. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  711. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  712. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  713. static void addField(const char* in_pFieldname,
  714. const U32 in_fieldType,
  715. const dsize_t in_fieldOffset,
  716. const char* in_pFieldDocs,
  717. U32 flags = 0 );
  718. static void addField(const char* in_pFieldname,
  719. const U32 in_fieldType,
  720. const dsize_t in_fieldOffset,
  721. AbstractClassRep::WriteDataNotify in_writeDataFn,
  722. const char* in_pFieldDocs,
  723. U32 flags = 0);
  724. /// Register a validated field.
  725. ///
  726. /// A validated field is just like a normal field except that you can't
  727. /// have it be an array, and that you give it a pointer to a TypeValidator
  728. /// subclass, which is then used to validate any value placed in it. Invalid
  729. /// values are ignored and an error is printed to the console.
  730. ///
  731. /// @see addField
  732. /// @see typeValidators.h
  733. static void addFieldV(const char* in_pFieldname,
  734. const U32 in_fieldType,
  735. const dsize_t in_fieldOffset,
  736. TypeValidator *v,
  737. const char * in_pFieldDocs = NULL);
  738. /// Register a complex 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_elementCount Number of elements in this field. Arrays of elements are assumed to be contiguous in memory.
  746. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  747. static void addProtectedField(const char* in_pFieldname,
  748. const U32 in_fieldType,
  749. const dsize_t in_fieldOffset,
  750. AbstractClassRep::SetDataNotify in_setDataFn,
  751. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  752. AbstractClassRep::WriteDataNotify in_writeDataFn = &defaultProtectedWriteFn,
  753. const U32 in_elementCount = 1,
  754. const char* in_pFieldDocs = NULL,
  755. U32 flags = 0);
  756. static void addProtectedField(const char* in_pFieldname,
  757. const U32 in_fieldType,
  758. const dsize_t in_fieldOffset,
  759. AbstractClassRep::SetDataNotify in_setDataFn,
  760. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  761. const U32 in_elementCount = 1,
  762. const char* in_pFieldDocs = NULL,
  763. U32 flags = 0);
  764. /// Register a simple protected field.
  765. ///
  766. /// @param in_pFieldname Name of the field.
  767. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  768. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  769. /// @param in_setDataFn When this field gets set, it will call the callback provided. @see console_protected
  770. /// @param in_getDataFn When this field is accessed for it's data, it will return the value of this function
  771. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  772. static void addProtectedField(const char* in_pFieldname,
  773. const U32 in_fieldType,
  774. const dsize_t in_fieldOffset,
  775. AbstractClassRep::SetDataNotify in_setDataFn,
  776. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  777. AbstractClassRep::WriteDataNotify in_writeDataFn = &defaultProtectedWriteFn,
  778. const char* in_pFieldDocs = NULL,
  779. U32 flags = 0);
  780. static void addProtectedField(const char* in_pFieldname,
  781. const U32 in_fieldType,
  782. const dsize_t in_fieldOffset,
  783. AbstractClassRep::SetDataNotify in_setDataFn,
  784. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  785. const char* in_pFieldDocs = NULL,
  786. U32 flags = 0);
  787. /// Add a deprecated field.
  788. ///
  789. /// A deprecated field will always be undefined, even if you assign a value to it. This
  790. /// is useful when you need to make sure that a field is not being used anymore.
  791. static void addDeprecatedField(const char *fieldName);
  792. /// Remove a field.
  793. ///
  794. /// Sometimes, you just have to remove a field!
  795. /// @returns True on success.
  796. static bool removeField(const char* in_pFieldname);
  797. /// @}
  798. /// @name Logging
  799. /// @{
  800. /// Overload this in subclasses to change the message formatting.
  801. /// @param fmt A printf style format string.
  802. /// @param args A va_list containing the args passed ot a log function.
  803. /// @note It is suggested that you use String::VToString.
  804. virtual String _getLogMessage(const char* fmt, va_list args) const;
  805. /// @}
  806. public:
  807. /// @name Logging
  808. /// These functions will try to print out a message along the lines
  809. /// of "ObjectClass - ObjectName(ObjectId) - formatted message"
  810. /// @{
  811. /// Logs with Con::printf.
  812. void logMessage(const char* fmt, ...) const;
  813. /// Logs with Con::warnf.
  814. void logWarning(const char* fmt, ...) const;
  815. /// Logs with Con::errorf.
  816. void logError(const char* fmt, ...) const;
  817. /// @}
  818. /// Register dynamic fields in a subclass of ConsoleObject.
  819. ///
  820. /// @see addField(), addFieldV(), addDeprecatedField(), addGroup(), endGroup()
  821. static void initPersistFields();
  822. /// Register global constant variables and do other one-time initialization tasks in
  823. /// a subclass of ConsoleObject.
  824. ///
  825. /// @deprecated You should use ConsoleMethod and ConsoleFunction, not this, to
  826. /// register methods or commands.
  827. /// @see console
  828. static void consoleInit();
  829. /// @name Field List
  830. /// @{
  831. /// Get a list of all the fields. This information cannot be modified.
  832. const AbstractClassRep::FieldList& getFieldList() const;
  833. /// Get a list of all the fields, set up so we can modify them.
  834. ///
  835. /// @note This is a bad trick to pull if you aren't very careful,
  836. /// since you can blast field data!
  837. AbstractClassRep::FieldList& getModifiableFieldList();
  838. /// Get a handle to a boolean telling us if we expanded the dynamic group.
  839. ///
  840. /// @see GuiInspector::Inspect()
  841. bool& getDynamicGroupExpand();
  842. /// @}
  843. /// @name ConsoleObject Implementation
  844. ///
  845. /// These functions are implemented in every subclass of
  846. /// ConsoleObject by an IMPLEMENT_CONOBJECT or IMPLEMENT_CO_* macro.
  847. /// @{
  848. /// Get the abstract class information for this class.
  849. static AbstractClassRep *getStaticClassRep() { return NULL; }
  850. /// Get the abstract class information for this class's superclass.
  851. static AbstractClassRep *getParentStaticClassRep() { return NULL; }
  852. /// Get our network-layer class id.
  853. ///
  854. /// @param netClassGroup The net class for which we want our ID.
  855. /// @see
  856. S32 getClassId(U32 netClassGroup) const;
  857. /// Get our compiler and platform independent class name.
  858. ///
  859. /// @note This name can be used to instantiate another instance using create()
  860. StringTableEntry getClassName() const;
  861. /// @}
  862. static const char* __category() { return ""; }
  863. static const char* __description() { return ""; }
  864. /// Subclasses of ConsoleObjects that are datablocks should redefine this static member variable
  865. /// and set it to true.
  866. static const bool __smIsDatablock = false;
  867. /// @name Object IDs and lookup.
  868. /// For a subclass hierarchy based on ConsoleObject to become functional for use as a console object type,
  869. /// the hierarchy must implement a naming scheme and indexing function for looking up objects by name.
  870. /// @{
  871. static ConsoleObject* __findObject( const char* ) { return NULL; }
  872. static const char* __getObjectId( ConsoleObject* ) { return ""; }
  873. };
  874. #define addNamedField(fieldName,type,className) addField(#fieldName, type, Offset(fieldName,className))
  875. #define addNamedFieldV(fieldName,type,className, validator) addFieldV(#fieldName, type, Offset(fieldName,className), validator)
  876. //------------------------------------------------------------------------------
  877. //-------------------------------------- Inlines
  878. //
  879. inline S32 ConsoleObject::getClassId(U32 netClassGroup) const
  880. {
  881. AssertFatal(getClassRep() != NULL,"Cannot get tag from non-declared dynamic class!");
  882. return getClassRep()->getClassId(netClassGroup);
  883. }
  884. inline StringTableEntry ConsoleObject::getClassName() const
  885. {
  886. AssertFatal(getClassRep() != NULL,
  887. "Cannot get tag from non-declared dynamic class");
  888. return getClassRep()->getClassName();
  889. }
  890. inline const AbstractClassRep::Field * ConsoleObject::findField(StringTableEntry name) const
  891. {
  892. AssertFatal(getClassRep() != NULL,
  893. avar("Cannot get field '%s' from non-declared dynamic class.", name));
  894. return getClassRep()->findField(name);
  895. }
  896. inline bool ConsoleObject::setField(const char *fieldName, const char *value)
  897. {
  898. //sanity check
  899. if ((! fieldName) || (! fieldName[0]) || (! value))
  900. return false;
  901. if (! getClassRep())
  902. return false;
  903. const AbstractClassRep::Field *myField = getClassRep()->findField(StringTable->insert(fieldName));
  904. if (! myField)
  905. return false;
  906. Con::setData(
  907. myField->type,
  908. (void *) (((const char *)(this)) + myField->offset),
  909. 0,
  910. 1,
  911. &value,
  912. myField->table,
  913. myField->flag);
  914. return true;
  915. }
  916. inline ConsoleObject* ConsoleObject::create(const char* in_pClassName)
  917. {
  918. return AbstractClassRep::create(in_pClassName);
  919. }
  920. inline ConsoleObject* ConsoleObject::create(const U32 groupId, const U32 typeId, const U32 in_classId)
  921. {
  922. return AbstractClassRep::create(groupId, typeId, in_classId);
  923. }
  924. inline const AbstractClassRep::FieldList& ConsoleObject::getFieldList() const
  925. {
  926. return getClassRep()->mFieldList;
  927. }
  928. inline AbstractClassRep::FieldList& ConsoleObject::getModifiableFieldList()
  929. {
  930. return getClassRep()->mFieldList;
  931. }
  932. inline bool& ConsoleObject::getDynamicGroupExpand()
  933. {
  934. return getClassRep()->mDynamicGroupExpand;
  935. }
  936. /// @name ConsoleObject Macros
  937. /// @{
  938. #define DECLARE_CONOBJECT( className ) \
  939. DECLARE_CLASS( className, Parent ); \
  940. static S32 _smTypeId; \
  941. static ConcreteClassRep< className > dynClassRep; \
  942. static AbstractClassRep* getParentStaticClassRep(); \
  943. static AbstractClassRep* getStaticClassRep(); \
  944. static SimObjectRefConsoleBaseType< className > ptrRefType; \
  945. static AbstractClassRep::WriteCustomTamlSchema getStaticWriteCustomTamlSchema(); \
  946. static AbstractClassRep* getContainerChildStaticClassRep(); \
  947. virtual AbstractClassRep* getClassRep() const
  948. #define DECLARE_CATEGORY( string ) \
  949. static const char* __category() { return string; }
  950. #define DECLARE_DESCRIPTION( string ) \
  951. static const char* __description() { return string; }
  952. #define IMPLEMENT_CONOBJECT( className ) \
  953. IMPLEMENT_CLASS( className, NULL ) \
  954. END_IMPLEMENT_CLASS; \
  955. S32 className::_smTypeId; \
  956. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  957. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  958. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  959. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  960. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  961. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  962. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  963. #define IMPLEMENT_CONOBJECT_CHILDREN( className ) \
  964. IMPLEMENT_CLASS( className, NULL ) \
  965. END_IMPLEMENT_CLASS; \
  966. S32 className::_smTypeId; \
  967. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  968. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  969. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  970. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  971. AbstractClassRep* className::getContainerChildStaticClassRep() { return Children::getStaticClassRep(); } \
  972. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  973. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  974. #define IMPLEMENT_CONOBJECT_SCHEMA( className, schema ) \
  975. IMPLEMENT_CLASS( className, NULL ) \
  976. END_IMPLEMENT_CLASS; \
  977. S32 className::_smTypeId; \
  978. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  979. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  980. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  981. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  982. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  983. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \
  984. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  985. #define IMPLEMENT_CONOBJECT_CHILDREN_SCHEMA( className, schema ) \
  986. IMPLEMENT_CLASS( className, NULL ) \
  987. END_IMPLEMENT_CLASS; \
  988. S32 className::_smTypeId; \
  989. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  990. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  991. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  992. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  993. AbstractClassRep* className::getContainerChildStaticClassRep() { return Children::getStaticClassRep(); } \
  994. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \
  995. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  996. #define IMPLEMENT_ABSTRACT_CONOBJECT( className ) \
  997. IMPLEMENT_NONINSTANTIABLE_CLASS( className, NULL ) \
  998. END_IMPLEMENT_CLASS; \
  999. S32 className::_smTypeId; \
  1000. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  1001. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  1002. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  1003. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  1004. ConcreteAbstractClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  1005. #define IMPLEMENT_CO_NETOBJECT_V1( className ) \
  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 NULL; } \
  1015. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, NetClassGroupGameMask, NetClassTypeObject, 0, className::getParentStaticClassRep(), &Parent::__description )
  1016. #define IMPLEMENT_CO_DATABLOCK_V1( className ) \
  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 NULL; } \
  1025. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  1026. ConcreteClassRep<className> className::dynClassRep(#className, "Type" #className, &_smTypeId, NetClassGroupGameMask, NetClassTypeDataBlock, 0, className::getParentStaticClassRep(), &Parent::__description )
  1027. // Support for adding properties to classes CONOBJECT style.
  1028. #define PROPERTY_TABLE( className ) \
  1029. namespace { namespace _ ## className { \
  1030. extern EnginePropertyTable _propTable; \
  1031. } } \
  1032. template<> EnginePropertyTable& \
  1033. ConcreteClassRep< className >::smPropertyTable = _ ## className::_propTable; \
  1034. namespace { namespace _ ## className { \
  1035. EnginePropertyTable::Property _props[] = {
  1036. #define END_PROPERTY_TABLE \
  1037. { NULL } \
  1038. }; \
  1039. EnginePropertyTable _propTable( sizeof( _props ) / sizeof( _props[ 0 ] ) - 1, _props ); \
  1040. } }
  1041. /// Add an auto-doc for a class.
  1042. #define ConsoleDocClass( className, docString ) \
  1043. CLASSDOC( className, docString )
  1044. /// @}
  1045. //------------------------------------------------------------------------------
  1046. // Protected field default get/set functions
  1047. //
  1048. // The reason for these functions is that it will save one branch per console
  1049. // data request and script functions will still execute at the same speed as
  1050. // before the modifications to allow protected static fields. These will just
  1051. // inline and the code should be roughly the same size, and just as fast as
  1052. // before the modifications. -pw
  1053. inline bool defaultProtectedSetFn( void *object, const char *index, const char *data )
  1054. {
  1055. return true;
  1056. }
  1057. inline bool defaultProtectedSetNotEmptyFn( void *object, const char *index, const char *data )
  1058. {
  1059. return data && data[0];
  1060. }
  1061. inline const char *defaultProtectedGetFn( void *obj, const char *data )
  1062. {
  1063. return data;
  1064. }
  1065. inline const char *emptyStringProtectedGetFn( void *obj, const char *data )
  1066. {
  1067. return "";
  1068. }
  1069. inline bool defaultProtectedWriteFn(void* obj, StringTableEntry pFieldName)
  1070. {
  1071. return true;
  1072. }
  1073. inline bool defaultProtectedNotSetFn(void* obj, const char *array, const char* data)
  1074. {
  1075. return false;
  1076. }
  1077. inline bool defaultProtectedNotWriteFn(void* obj, StringTableEntry pFieldName)
  1078. {
  1079. return false;
  1080. }
  1081. /// @}
  1082. #endif //_CONSOLEOBJECT_H_