consoleObject.h 49 KB

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