consoleObject.h 52 KB

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