consoleObject.h 49 KB

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