consoleObject.h 51 KB

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