consoleObject.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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
  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. };
  397. struct Field
  398. {
  399. Field()
  400. : pFieldname( NULL ),
  401. pGroupname( NULL ),
  402. pFieldDocs( NULL ),
  403. groupExpand( false ),
  404. type( 0 ),
  405. offset( 0 ),
  406. elementCount( 0 ),
  407. table( NULL ),
  408. validator( NULL ),
  409. setDataFn( NULL ),
  410. getDataFn( NULL )
  411. {
  412. }
  413. StringTableEntry pFieldname; ///< Name of the field.
  414. const char* pGroupname; ///< Optionally filled field containing the group name.
  415. ///
  416. /// This is filled when type is StartField or EndField
  417. const char* pFieldDocs; ///< Documentation about this field; see consoleDoc.cc.
  418. bool groupExpand; ///< Flag to track expanded/not state of this group in the editor.
  419. U32 type; ///< A data type ID or one of the special custom fields. @see ACRFieldTypes
  420. U32 offset; ///< Memory offset from beginning of class for this field.
  421. S32 elementCount; ///< Number of elements, if this is an array.
  422. const EnumTable * table; ///< If this is an enum, this points to the table defining it.
  423. BitSet32 flag; ///< Stores various flags
  424. TypeValidator *validator; ///< Validator, if any.
  425. SetDataNotify setDataFn; ///< Set data notify Fn
  426. GetDataNotify getDataFn; ///< Get data notify Fn
  427. WriteDataNotify writeDataFn; ///< Function to determine whether data should be written or not.
  428. };
  429. typedef Vector<Field> FieldList;
  430. FieldList mFieldList;
  431. bool mDynamicGroupExpand;
  432. const Field* findField( StringTableEntry fieldName ) const;
  433. /// @}
  434. /// @name Console Type Interface
  435. /// @{
  436. virtual void* getNativeVariable() { return new ( AbstractClassRep* ); } // Any pointer-sized allocation will do.
  437. virtual void deleteNativeVariable( void* var ) { delete reinterpret_cast< AbstractClassRep** >( var ); }
  438. /// @}
  439. /// @name Abstract Class Database
  440. /// @{
  441. protected:
  442. static AbstractClassRep ** classTable[NetClassGroupsCount][NetClassTypesCount];
  443. static AbstractClassRep * classLinkList;
  444. static U32 classCRC[NetClassGroupsCount];
  445. static bool initialized;
  446. static ConsoleObject* create(const char* in_pClassName);
  447. static ConsoleObject* create(const U32 groupId, const U32 typeId, const U32 in_classId);
  448. public:
  449. static U32 NetClassCount [NetClassGroupsCount][NetClassTypesCount];
  450. static U32 NetClassBitSize[NetClassGroupsCount][NetClassTypesCount];
  451. static void registerClassRep(AbstractClassRep*);
  452. static AbstractClassRep* findClassRep(const char* in_pClassName);
  453. static AbstractClassRep* findClassRep( U32 groupId, U32 typeId, U32 classId );
  454. static void removeClassRep(AbstractClassRep*); // This should not be used lightly
  455. static void initialize(); // Called from Con::init once on startup
  456. static void shutdown();
  457. /// @}
  458. };
  459. extern AbstractClassRep::FieldList sg_tempFieldList;
  460. //=============================================================================
  461. // ConcreteClassRep.
  462. //=============================================================================
  463. /// Helper class for AbstractClassRep.
  464. ///
  465. /// @see AbtractClassRep
  466. /// @see ConsoleObject
  467. template< class T >
  468. class ConcreteClassRep : public AbstractClassRep
  469. {
  470. public:
  471. static EnginePropertyTable _smPropertyTable;
  472. static EnginePropertyTable& smPropertyTable;
  473. ConcreteClassRep( const char* name,
  474. const char* conTypeName,
  475. S32* conTypeIdPtr,
  476. S32 netClassGroupMask,
  477. S32 netClassType,
  478. S32 netEventDir,
  479. AbstractClassRep* parent,
  480. const char* ( *parentDesc )() )
  481. : AbstractClassRep( conTypeIdPtr, conTypeName )
  482. {
  483. mClassName = StringTable->insert( name );
  484. mCategory = T::__category();
  485. mTypeInfo = _MAPTYPE< T >();
  486. if( mTypeInfo )
  487. const_cast< EngineTypeInfo* >( mTypeInfo )->mPropertyTable = &smPropertyTable;
  488. if( &T::__description != parentDesc )
  489. mDescription = T::__description();
  490. // Clean up mClassId
  491. for(U32 i = 0; i < NetClassGroupsCount; i++)
  492. mClassId[i] = -1;
  493. // Set properties for this ACR
  494. mClassType = netClassType;
  495. mClassGroupMask = netClassGroupMask;
  496. mNetEventDir = netEventDir;
  497. parentClass = parent;
  498. mClassSizeof = sizeof(T);
  499. // Finally, register ourselves.
  500. registerClassRep(this);
  501. };
  502. virtual AbstractClassRep* getContainerChildClass(const bool recurse)
  503. {
  504. // Fetch container children type.
  505. AbstractClassRep* pChildren = T::getContainerChildStaticClassRep();
  506. if (!recurse || pChildren != NULL)
  507. return pChildren;
  508. // Fetch parent type.
  509. AbstractClassRep* pParent = T::getParentStaticClassRep();
  510. if (pParent == NULL)
  511. return NULL;
  512. // Get parent container children.
  513. return pParent->getContainerChildClass(recurse);
  514. }
  515. virtual WriteCustomTamlSchema getCustomTamlSchema(void)
  516. {
  517. return T::getStaticWriteCustomTamlSchema();
  518. }
  519. /// Perform class specific initialization tasks.
  520. ///
  521. /// Link namespaces, call initPersistFields() and consoleInit().
  522. void init()
  523. {
  524. // Get handle to our parent class, if any, and ourselves (we are our parent's child).
  525. AbstractClassRep *parent = T::getParentStaticClassRep();
  526. AbstractClassRep *child = T::getStaticClassRep();
  527. // If we got reps, then link those namespaces! (To get proper inheritance.)
  528. if(parent && child)
  529. Con::classLinkNamespaces(parent->getNameSpace(), child->getNameSpace());
  530. // Finally, do any class specific initialization...
  531. T::initPersistFields();
  532. T::consoleInit();
  533. // Let the base finish up.
  534. AbstractClassRep::init();
  535. }
  536. /// Wrap constructor.
  537. ConsoleObject* create() const { return new T; }
  538. /// @name Console Type Interface
  539. /// @{
  540. virtual void setData( void* dptr, S32 argc, const char** argv, const EnumTable* tbl, BitSet32 flag )
  541. {
  542. if( argc == 1 )
  543. {
  544. T** obj = ( T** ) dptr;
  545. *obj = dynamic_cast< T* >( T::__findObject( argv[ 0 ] ) );
  546. }
  547. else
  548. Con::errorf( "Cannot set multiple args to a single ConsoleObject*.");
  549. }
  550. virtual const char* getData( void* dptr, const EnumTable* tbl, BitSet32 flag )
  551. {
  552. T** obj = ( T** ) dptr;
  553. return Con::getReturnBuffer( T::__getObjectId( *obj ) );
  554. }
  555. virtual const char* getTypeClassName() { return mClassName; }
  556. virtual const bool isDatablock() { return T::__smIsDatablock; };
  557. /// @}
  558. };
  559. template< typename T > EnginePropertyTable ConcreteClassRep< T >::_smPropertyTable( 0, NULL );
  560. template< typename T > EnginePropertyTable& ConcreteClassRep< T >::smPropertyTable = ConcreteClassRep< T >::_smPropertyTable;
  561. //------------------------------------------------------------------------------
  562. // Forward declaration of this function so it can be used in the class
  563. const char *defaultProtectedGetFn( void *obj, const char *data );
  564. bool defaultProtectedWriteFn(void* obj, StringTableEntry pFieldName);
  565. //=============================================================================
  566. // ConsoleObject.
  567. //=============================================================================
  568. /// Interface class to the console.
  569. ///
  570. /// @section ConsoleObject_basics The Basics
  571. ///
  572. /// Any object which you want to work with the console system should derive from this,
  573. /// and access functionality through the static interface.
  574. ///
  575. /// This class is always used with the DECLARE_CONOBJECT and IMPLEMENT_* macros.
  576. ///
  577. /// @code
  578. /// // A very basic example object. It will do nothing!
  579. /// class TorqueObject : public ConsoleObject {
  580. /// // Must provide a Parent typedef so the console system knows what we inherit from.
  581. /// typedef ConsoleObject Parent;
  582. ///
  583. /// // This does a lot of menial declaration for you.
  584. /// DECLARE_CONOBJECT(TorqueObject);
  585. ///
  586. /// // This is for us to register our fields in.
  587. /// static void initPersistFields();
  588. ///
  589. /// // A sample field.
  590. /// S8 mSample;
  591. /// }
  592. /// @endcode
  593. ///
  594. /// @code
  595. /// // And the accordant implementation...
  596. /// IMPLEMENT_CONOBJECT(TorqueObject);
  597. ///
  598. /// void TorqueObject::initPersistFields()
  599. /// {
  600. /// // If you want to inherit any fields from the parent (you do), do this:
  601. /// Parent::initPersistFields();
  602. ///
  603. /// // Pass the field, the type, the offset, and a usage string.
  604. /// addField("sample", TypeS8, Offset(mSample, TorqueObject), "A test field.");
  605. /// }
  606. /// @endcode
  607. ///
  608. /// That's all you need to do to get a class registered with the console system. At this point,
  609. /// you can instantiate it via script, tie methods to it using ConsoleMethod, register fields,
  610. /// and so forth. You can also register any global variables related to the class by creating
  611. /// a consoleInit() method.
  612. ///
  613. /// You will need to use different IMPLEMENT_ macros in different cases; for instance, if you
  614. /// are making a NetObject (for ghosting), a DataBlock, or a NetEvent.
  615. ///
  616. /// @see AbstractClassRep for gory implementation details.
  617. /// @nosubgrouping
  618. class ConsoleObject : public EngineObject
  619. {
  620. DECLARE_ABSTRACT_CLASS( ConsoleObject, EngineObject );
  621. protected:
  622. /// @deprecated This is disallowed.
  623. ConsoleObject(const ConsoleObject&);
  624. public:
  625. ConsoleObject() {}
  626. /// Get a reference to a field by name.
  627. const AbstractClassRep::Field *findField(StringTableEntry fieldName) const;
  628. /// Gets the ClassRep.
  629. virtual AbstractClassRep* getClassRep() const;
  630. /// Set the value of a field.
  631. bool setField(const char *fieldName, const char *value);
  632. public:
  633. /// @name Object Creation
  634. /// @{
  635. static ConsoleObject* create(const char* in_pClassName);
  636. static ConsoleObject* create(const U32 groupId, const U32 typeId, const U32 in_classId);
  637. /// @}
  638. public:
  639. /// Get the classname from a class tag.
  640. static const char* lookupClassName(const U32 in_classTag);
  641. /// @name Fields
  642. /// @{
  643. /// Mark the beginning of a group of fields.
  644. ///
  645. /// This is used in the consoleDoc system.
  646. /// @see console_autodoc
  647. static void addGroup(const char* in_pGroupname, const char* in_pGroupDocs = NULL);
  648. /// Mark the end of a group of fields.
  649. ///
  650. /// This is used in the consoleDoc system.
  651. /// @see console_autodoc
  652. static void endGroup(const char* in_pGroupname);
  653. /// Marks the start of a fixed size array of fields.
  654. /// @see console_autodoc
  655. static void addArray( const char *arrayName, S32 count );
  656. /// Marks the end of an array of fields.
  657. /// @see console_autodoc
  658. static void endArray( const char *arrayName );
  659. /// Register a complex field.
  660. ///
  661. /// @param in_pFieldname Name of the field.
  662. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  663. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  664. /// @param in_elementCount Number of elements in this field. Arrays of elements are assumed to be contiguous in memory.
  665. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  666. static void addField(const char* in_pFieldname,
  667. const U32 in_fieldType,
  668. const dsize_t in_fieldOffset,
  669. const U32 in_elementCount = 1,
  670. const char* in_pFieldDocs = NULL,
  671. U32 flags = 0 );
  672. static void addField(const char* in_pFieldname,
  673. const U32 in_fieldType,
  674. const dsize_t in_fieldOffset,
  675. AbstractClassRep::WriteDataNotify in_writeDataFn,
  676. const U32 in_elementCount = 1,
  677. const char* in_pFieldDocs = NULL,
  678. U32 flags = 0);
  679. /// Register a simple field.
  680. ///
  681. /// @param in_pFieldname Name of the field.
  682. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  683. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  684. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  685. static void addField(const char* in_pFieldname,
  686. const U32 in_fieldType,
  687. const dsize_t in_fieldOffset,
  688. const char* in_pFieldDocs,
  689. U32 flags = 0 );
  690. static void addField(const char* in_pFieldname,
  691. const U32 in_fieldType,
  692. const dsize_t in_fieldOffset,
  693. AbstractClassRep::WriteDataNotify in_writeDataFn,
  694. const char* in_pFieldDocs,
  695. U32 flags = 0);
  696. /// Register a validated field.
  697. ///
  698. /// A validated field is just like a normal field except that you can't
  699. /// have it be an array, and that you give it a pointer to a TypeValidator
  700. /// subclass, which is then used to validate any value placed in it. Invalid
  701. /// values are ignored and an error is printed to the console.
  702. ///
  703. /// @see addField
  704. /// @see typeValidators.h
  705. static void addFieldV(const char* in_pFieldname,
  706. const U32 in_fieldType,
  707. const dsize_t in_fieldOffset,
  708. TypeValidator *v,
  709. const char * in_pFieldDocs = NULL);
  710. /// Register a complex protected field.
  711. ///
  712. /// @param in_pFieldname Name of the field.
  713. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  714. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  715. /// @param in_setDataFn When this field gets set, it will call the callback provided. @see console_protected
  716. /// @param in_getDataFn When this field is accessed for it's data, it will return the value of this function
  717. /// @param in_elementCount Number of elements in this field. Arrays of elements are assumed to be contiguous in memory.
  718. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  719. static void addProtectedField(const char* in_pFieldname,
  720. const U32 in_fieldType,
  721. const dsize_t in_fieldOffset,
  722. AbstractClassRep::SetDataNotify in_setDataFn,
  723. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  724. AbstractClassRep::WriteDataNotify in_writeDataFn = &defaultProtectedWriteFn,
  725. const U32 in_elementCount = 1,
  726. const char* in_pFieldDocs = NULL,
  727. U32 flags = 0);
  728. static void addProtectedField(const char* in_pFieldname,
  729. const U32 in_fieldType,
  730. const dsize_t in_fieldOffset,
  731. AbstractClassRep::SetDataNotify in_setDataFn,
  732. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  733. const U32 in_elementCount = 1,
  734. const char* in_pFieldDocs = NULL,
  735. U32 flags = 0);
  736. /// Register a simple protected field.
  737. ///
  738. /// @param in_pFieldname Name of the field.
  739. /// @param in_fieldType Type of the field. @see ConsoleDynamicTypes
  740. /// @param in_fieldOffset Offset to the field from the start of the class; calculated using the Offset() macro.
  741. /// @param in_setDataFn When this field gets set, it will call the callback provided. @see console_protected
  742. /// @param in_getDataFn When this field is accessed for it's data, it will return the value of this function
  743. /// @param in_pFieldDocs Usage string for this field. @see console_autodoc
  744. static void addProtectedField(const char* in_pFieldname,
  745. const U32 in_fieldType,
  746. const dsize_t in_fieldOffset,
  747. AbstractClassRep::SetDataNotify in_setDataFn,
  748. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  749. AbstractClassRep::WriteDataNotify in_writeDataFn = &defaultProtectedWriteFn,
  750. const char* in_pFieldDocs = NULL,
  751. U32 flags = 0);
  752. static void addProtectedField(const char* in_pFieldname,
  753. const U32 in_fieldType,
  754. const dsize_t in_fieldOffset,
  755. AbstractClassRep::SetDataNotify in_setDataFn,
  756. AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
  757. const char* in_pFieldDocs = NULL,
  758. U32 flags = 0);
  759. /// Add a deprecated field.
  760. ///
  761. /// A deprecated field will always be undefined, even if you assign a value to it. This
  762. /// is useful when you need to make sure that a field is not being used anymore.
  763. static void addDeprecatedField(const char *fieldName);
  764. /// Remove a field.
  765. ///
  766. /// Sometimes, you just have to remove a field!
  767. /// @returns True on success.
  768. static bool removeField(const char* in_pFieldname);
  769. /// @}
  770. /// @name Logging
  771. /// @{
  772. /// Overload this in subclasses to change the message formatting.
  773. /// @param fmt A printf style format string.
  774. /// @param args A va_list containing the args passed ot a log function.
  775. /// @note It is suggested that you use String::VToString.
  776. virtual String _getLogMessage(const char* fmt, va_list args) const;
  777. /// @}
  778. public:
  779. /// @name Logging
  780. /// These functions will try to print out a message along the lines
  781. /// of "ObjectClass - ObjectName(ObjectId) - formatted message"
  782. /// @{
  783. /// Logs with Con::printf.
  784. void logMessage(const char* fmt, ...) const;
  785. /// Logs with Con::warnf.
  786. void logWarning(const char* fmt, ...) const;
  787. /// Logs with Con::errorf.
  788. void logError(const char* fmt, ...) const;
  789. /// @}
  790. /// Register dynamic fields in a subclass of ConsoleObject.
  791. ///
  792. /// @see addField(), addFieldV(), addDeprecatedField(), addGroup(), endGroup()
  793. static void initPersistFields();
  794. /// Register global constant variables and do other one-time initialization tasks in
  795. /// a subclass of ConsoleObject.
  796. ///
  797. /// @deprecated You should use ConsoleMethod and ConsoleFunction, not this, to
  798. /// register methods or commands.
  799. /// @see console
  800. static void consoleInit();
  801. /// @name Field List
  802. /// @{
  803. /// Get a list of all the fields. This information cannot be modified.
  804. const AbstractClassRep::FieldList& getFieldList() const;
  805. /// Get a list of all the fields, set up so we can modify them.
  806. ///
  807. /// @note This is a bad trick to pull if you aren't very careful,
  808. /// since you can blast field data!
  809. AbstractClassRep::FieldList& getModifiableFieldList();
  810. /// Get a handle to a boolean telling us if we expanded the dynamic group.
  811. ///
  812. /// @see GuiInspector::Inspect()
  813. bool& getDynamicGroupExpand();
  814. /// @}
  815. /// @name ConsoleObject Implementation
  816. ///
  817. /// These functions are implemented in every subclass of
  818. /// ConsoleObject by an IMPLEMENT_CONOBJECT or IMPLEMENT_CO_* macro.
  819. /// @{
  820. /// Get the abstract class information for this class.
  821. static AbstractClassRep *getStaticClassRep() { return NULL; }
  822. /// Get the abstract class information for this class's superclass.
  823. static AbstractClassRep *getParentStaticClassRep() { return NULL; }
  824. /// Get our network-layer class id.
  825. ///
  826. /// @param netClassGroup The net class for which we want our ID.
  827. /// @see
  828. S32 getClassId(U32 netClassGroup) const;
  829. /// Get our compiler and platform independent class name.
  830. ///
  831. /// @note This name can be used to instantiate another instance using create()
  832. StringTableEntry getClassName() const;
  833. /// @}
  834. static const char* __category() { return ""; }
  835. static const char* __description() { return ""; }
  836. /// Subclasses of ConsoleObjects that are datablocks should redefine this static member variable
  837. /// and set it to true.
  838. static const bool __smIsDatablock = false;
  839. /// @name Object IDs and lookup.
  840. /// For a subclass hierarchy based on ConsoleObject to become functional for use as a console object type,
  841. /// the hierarchy must implement a naming scheme and indexing function for looking up objects by name.
  842. /// @{
  843. static ConsoleObject* __findObject( const char* ) { return NULL; }
  844. static const char* __getObjectId( ConsoleObject* ) { return ""; }
  845. };
  846. #define addNamedField(fieldName,type,className) addField(#fieldName, type, Offset(fieldName,className))
  847. #define addNamedFieldV(fieldName,type,className, validator) addFieldV(#fieldName, type, Offset(fieldName,className), validator)
  848. //------------------------------------------------------------------------------
  849. //-------------------------------------- Inlines
  850. //
  851. inline S32 ConsoleObject::getClassId(U32 netClassGroup) const
  852. {
  853. AssertFatal(getClassRep() != NULL,"Cannot get tag from non-declared dynamic class!");
  854. return getClassRep()->getClassId(netClassGroup);
  855. }
  856. inline StringTableEntry ConsoleObject::getClassName() const
  857. {
  858. AssertFatal(getClassRep() != NULL,
  859. "Cannot get tag from non-declared dynamic class");
  860. return getClassRep()->getClassName();
  861. }
  862. inline const AbstractClassRep::Field * ConsoleObject::findField(StringTableEntry name) const
  863. {
  864. AssertFatal(getClassRep() != NULL,
  865. avar("Cannot get field '%s' from non-declared dynamic class.", name));
  866. return getClassRep()->findField(name);
  867. }
  868. inline bool ConsoleObject::setField(const char *fieldName, const char *value)
  869. {
  870. //sanity check
  871. if ((! fieldName) || (! fieldName[0]) || (! value))
  872. return false;
  873. if (! getClassRep())
  874. return false;
  875. const AbstractClassRep::Field *myField = getClassRep()->findField(StringTable->insert(fieldName));
  876. if (! myField)
  877. return false;
  878. Con::setData(
  879. myField->type,
  880. (void *) (((const char *)(this)) + myField->offset),
  881. 0,
  882. 1,
  883. &value,
  884. myField->table,
  885. myField->flag);
  886. return true;
  887. }
  888. inline ConsoleObject* ConsoleObject::create(const char* in_pClassName)
  889. {
  890. return AbstractClassRep::create(in_pClassName);
  891. }
  892. inline ConsoleObject* ConsoleObject::create(const U32 groupId, const U32 typeId, const U32 in_classId)
  893. {
  894. return AbstractClassRep::create(groupId, typeId, in_classId);
  895. }
  896. inline const AbstractClassRep::FieldList& ConsoleObject::getFieldList() const
  897. {
  898. return getClassRep()->mFieldList;
  899. }
  900. inline AbstractClassRep::FieldList& ConsoleObject::getModifiableFieldList()
  901. {
  902. return getClassRep()->mFieldList;
  903. }
  904. inline bool& ConsoleObject::getDynamicGroupExpand()
  905. {
  906. return getClassRep()->mDynamicGroupExpand;
  907. }
  908. /// @name ConsoleObject Macros
  909. /// @{
  910. #define DECLARE_CONOBJECT( className ) \
  911. DECLARE_CLASS( className, Parent ); \
  912. static S32 _smTypeId; \
  913. static ConcreteClassRep< className > dynClassRep; \
  914. static AbstractClassRep* getParentStaticClassRep(); \
  915. static AbstractClassRep* getStaticClassRep(); \
  916. static SimObjectRefConsoleBaseType< className > ptrRefType; \
  917. static AbstractClassRep::WriteCustomTamlSchema getStaticWriteCustomTamlSchema(); \
  918. static AbstractClassRep* getContainerChildStaticClassRep(); \
  919. virtual AbstractClassRep* getClassRep() const
  920. #define DECLARE_CATEGORY( string ) \
  921. static const char* __category() { return string; }
  922. #define DECLARE_DESCRIPTION( string ) \
  923. static const char* __description() { return string; }
  924. #define IMPLEMENT_CONOBJECT( className ) \
  925. IMPLEMENT_CLASS( className, NULL ) \
  926. END_IMPLEMENT_CLASS; \
  927. S32 className::_smTypeId; \
  928. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  929. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  930. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  931. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  932. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  933. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  934. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  935. #define IMPLEMENT_CONOBJECT_CHILDREN( className ) \
  936. IMPLEMENT_CLASS( className, NULL ) \
  937. END_IMPLEMENT_CLASS; \
  938. S32 className::_smTypeId; \
  939. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  940. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  941. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  942. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  943. AbstractClassRep* className::getContainerChildStaticClassRep() { return Children::getStaticClassRep(); } \
  944. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  945. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  946. #define IMPLEMENT_CONOBJECT_SCHEMA( className, schema ) \
  947. IMPLEMENT_CLASS( className, NULL ) \
  948. END_IMPLEMENT_CLASS; \
  949. S32 className::_smTypeId; \
  950. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  951. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  952. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  953. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  954. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  955. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \
  956. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  957. #define IMPLEMENT_CONOBJECT_CHILDREN_SCHEMA( className, schema ) \
  958. IMPLEMENT_CLASS( className, NULL ) \
  959. END_IMPLEMENT_CLASS; \
  960. S32 className::_smTypeId; \
  961. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  962. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  963. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  964. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  965. AbstractClassRep* className::getContainerChildStaticClassRep() { return Children::getStaticClassRep(); } \
  966. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \
  967. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
  968. #define IMPLEMENT_CO_NETOBJECT_V1( className ) \
  969. IMPLEMENT_CLASS( className, NULL ) \
  970. END_IMPLEMENT_CLASS; \
  971. S32 className::_smTypeId; \
  972. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  973. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  974. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  975. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  976. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  977. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  978. ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, NetClassGroupGameMask, NetClassTypeObject, 0, className::getParentStaticClassRep(), &Parent::__description )
  979. #define IMPLEMENT_CO_DATABLOCK_V1( className ) \
  980. IMPLEMENT_CLASS( className, NULL ) \
  981. END_IMPLEMENT_CLASS; \
  982. S32 className::_smTypeId; \
  983. SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
  984. AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
  985. AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
  986. AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
  987. AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
  988. AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
  989. ConcreteClassRep<className> className::dynClassRep(#className, "Type" #className, &_smTypeId, NetClassGroupGameMask, NetClassTypeDataBlock, 0, className::getParentStaticClassRep(), &Parent::__description )
  990. // Support for adding properties to classes CONOBJECT style.
  991. #define PROPERTY_TABLE( className ) \
  992. namespace { namespace _ ## className { \
  993. extern EnginePropertyTable _propTable; \
  994. } } \
  995. template<> EnginePropertyTable& \
  996. ConcreteClassRep< className >::smPropertyTable = _ ## className::_propTable; \
  997. namespace { namespace _ ## className { \
  998. EnginePropertyTable::Property _props[] = {
  999. #define END_PROPERTY_TABLE \
  1000. { NULL } \
  1001. }; \
  1002. EnginePropertyTable _propTable( sizeof( _props ) / sizeof( _props[ 0 ] ) - 1, _props ); \
  1003. } }
  1004. /// Add an auto-doc for a class.
  1005. #define ConsoleDocClass( className, docString ) \
  1006. CLASSDOC( className, docString )
  1007. /// @}
  1008. //------------------------------------------------------------------------------
  1009. // Protected field default get/set functions
  1010. //
  1011. // The reason for these functions is that it will save one branch per console
  1012. // data request and script functions will still execute at the same speed as
  1013. // before the modifications to allow protected static fields. These will just
  1014. // inline and the code should be roughly the same size, and just as fast as
  1015. // before the modifications. -pw
  1016. inline bool defaultProtectedSetFn( void *object, const char *index, const char *data )
  1017. {
  1018. return true;
  1019. }
  1020. inline bool defaultProtectedSetNotEmptyFn( void *object, const char *index, const char *data )
  1021. {
  1022. return data && data[0];
  1023. }
  1024. inline const char *defaultProtectedGetFn( void *obj, const char *data )
  1025. {
  1026. return data;
  1027. }
  1028. inline const char *emptyStringProtectedGetFn( void *obj, const char *data )
  1029. {
  1030. return "";
  1031. }
  1032. inline bool defaultProtectedWriteFn(void* obj, StringTableEntry pFieldName)
  1033. {
  1034. return true;
  1035. }
  1036. inline bool defaultProtectedNotSetFn(void* obj, const char *array, const char* data)
  1037. {
  1038. return false;
  1039. }
  1040. inline bool defaultProtectedNotWriteFn(void* obj, StringTableEntry pFieldName)
  1041. {
  1042. return false;
  1043. }
  1044. /// @}
  1045. #endif //_CONSOLEOBJECT_H_