consoleObject.h 50 KB

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