simObject.cc 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. #include "sim/simObject.h"
  23. #include "sim/simObjectTimerEvent.h"
  24. #include "console/consoleInternal.h"
  25. #include "console/codeBlock.h"
  26. #include "console/consoleInternal.h"
  27. #include "memory/frameAllocator.h"
  28. #include "io/fileStream.h"
  29. #include "io/fileObject.h"
  30. #include "console/ConsoleTypeValidators.h"
  31. #include "simObject_ScriptBinding.h"
  32. //-----------------------------------------------------------------------------
  33. IMPLEMENT_CONOBJECT(SimObject);
  34. namespace Sim
  35. {
  36. extern U32 gNextObjectId;
  37. extern SimIdDictionary *gIdDictionary;
  38. extern SimManagerNameDictionary *gNameDictionary;
  39. extern void cancelPendingEvents(SimObject *obj);
  40. }
  41. //-----------------------------------------------------------------------------
  42. SimObject::SimObject( const U8 namespaceLinkMask ) : mNSLinkMask( namespaceLinkMask )
  43. {
  44. mFlags.set( ModStaticFields | ModDynamicFields );
  45. objectName = NULL;
  46. mInternalName = NULL;
  47. nextNameObject = (SimObject*)-1;
  48. nextManagerNameObject = (SimObject*)-1;
  49. nextIdObject = NULL;
  50. mId = 0;
  51. mIdString = StringTable->EmptyString;
  52. mGroup = 0;
  53. mNameSpace = NULL;
  54. mNotifyList = NULL;
  55. mTypeMask = 0;
  56. mScriptCallbackGuard = 0;
  57. mFieldDictionary = NULL;
  58. mCanSaveFieldDictionary = true;
  59. mClassName = NULL;
  60. mSuperClassName = NULL;
  61. mProgenitorFile = CodeBlock::getCurrentCodeBlockFullPath();
  62. mPeriodicTimerID = 0;
  63. }
  64. //---------------------------------------------------------------------------
  65. bool SimObject::isMethod( const char* methodName )
  66. {
  67. if( !methodName || !methodName[0] )
  68. return false;
  69. StringTableEntry stname = StringTable->insert( methodName );
  70. if( getNamespace() )
  71. return ( getNamespace()->lookup( stname ) != NULL );
  72. return false;
  73. }
  74. //---------------------------------------------------------------------------
  75. bool SimObject::registerObject()
  76. {
  77. AssertFatal( !mFlags.test( Added ), "reigsterObject - Object already registered!");
  78. mFlags.clear(Deleted | Removed);
  79. if( mId == 0 )
  80. {
  81. mId = Sim::gNextObjectId++;
  82. char idBuffer[64];
  83. dSprintf(idBuffer, sizeof(idBuffer), "%d", mId);
  84. mIdString = StringTable->insert( idBuffer );
  85. }
  86. AssertFatal(Sim::gIdDictionary && Sim::gNameDictionary,
  87. "SimObject::registerObject - tried to register an object before Sim::init()!");
  88. Sim::gIdDictionary->insert(this);
  89. Sim::gNameDictionary->insert(this);
  90. // Notify object
  91. bool ret = onAdd();
  92. if(!ret)
  93. unregisterObject();
  94. AssertFatal(!ret || isProperlyAdded(), "Object did not call SimObject::onAdd()");
  95. if ( isMethod( "onAdd" ) )
  96. Con::executef( this, 1, "onAdd" );
  97. return ret;
  98. }
  99. //---------------------------------------------------------------------------
  100. void SimObject::unregisterObject()
  101. {
  102. // Sanity!
  103. AssertISV( getScriptCallbackGuard() == 0, "SimObject::unregisterObject: Object is being unregistered whilst performing a script callback!" );
  104. if ( isMethod( "onRemove" ) )
  105. Con::executef( this, 1, "onRemove" );
  106. mFlags.set(Removed);
  107. // Notify object first
  108. onRemove();
  109. // Clear out any pending notifications before
  110. // we call our own, just in case they delete
  111. // something that we have referenced.
  112. clearAllNotifications();
  113. // Notify all objects that are waiting for delete
  114. // messages
  115. if (getGroup())
  116. getGroup()->removeObject(this);
  117. processDeleteNotifies();
  118. // Do removals from the Sim.
  119. Sim::gNameDictionary->remove(this);
  120. Sim::gIdDictionary->remove(this);
  121. Sim::cancelPendingEvents(this);
  122. }
  123. //---------------------------------------------------------------------------
  124. void SimObject::deleteObject()
  125. {
  126. // Sanity!
  127. AssertISV( getScriptCallbackGuard() == 0, "SimObject::deleteObject: Object is being deleted whilst performing a script callback!" );
  128. AssertFatal(mFlags.test(Added),
  129. "SimObject::deleteObject: Object not registered.");
  130. AssertFatal(!isDeleted(),"SimManager::deleteObject: "
  131. "Object has already been deleted");
  132. AssertFatal(!isRemoved(),"SimManager::deleteObject: "
  133. "Object in the process of being removed");
  134. mFlags.set(Deleted);
  135. unregisterObject();
  136. delete this;
  137. }
  138. //---------------------------------------------------------------------------
  139. void SimObject::setId(SimObjectId newId)
  140. {
  141. if(!mFlags.test(Added))
  142. {
  143. mId = newId;
  144. }
  145. else
  146. {
  147. // get this object out of the id dictionary if it's in it
  148. Sim::gIdDictionary->remove(this);
  149. // Free current Id.
  150. // Assign new one.
  151. mId = newId ? newId : Sim::gNextObjectId++;
  152. Sim::gIdDictionary->insert(this);
  153. }
  154. char idBuffer[64];
  155. dSprintf(idBuffer, sizeof(idBuffer), "%d", mId);
  156. mIdString = StringTable->insert( idBuffer );
  157. }
  158. void SimObject::assignName(const char *name)
  159. {
  160. // Added this assert 3/30/2007 because it is dumb to try to name
  161. // a SimObject the same thing as it's class name -patw
  162. //AssertFatal( dStricmp( getClassName(), name ), "Attempted to assign a name to a SimObject which matches it's type name." );
  163. if( dStricmp( getClassName(), name ) == 0 )
  164. Con::errorf( "SimObject::assignName - Assigning name '%s' to instance of object with type '%s'."
  165. " This can cause namespace linking issues.", getClassName(), name );
  166. #if 0
  167. Con::printf( "SimObject::assignName(%s)", name );
  168. #endif
  169. // Is this name already registered?
  170. if ( Sim::gNameDictionary->find(name) != NULL )
  171. {
  172. // Yes, so error,
  173. Con::errorf( "SimObject::assignName() - Attempted to set object to name '%s' but it is already assigned to another object.", name );
  174. return;
  175. }
  176. StringTableEntry newName = NULL;
  177. if(name[0])
  178. newName = StringTable->insert(name);
  179. if(mGroup)
  180. mGroup->nameDictionary.remove(this);
  181. if(mFlags.test(Added))
  182. Sim::gNameDictionary->remove(this);
  183. objectName = newName;
  184. if(mGroup)
  185. mGroup->nameDictionary.insert(this);
  186. if(mFlags.test(Added))
  187. Sim::gNameDictionary->insert(this);
  188. }
  189. //---------------------------------------------------------------------------
  190. bool SimObject::registerObject(U32 id)
  191. {
  192. setId(id);
  193. return registerObject();
  194. }
  195. bool SimObject::registerObject(const char *name)
  196. {
  197. assignName(name);
  198. return registerObject();
  199. }
  200. bool SimObject::registerObject(const char *name, U32 id)
  201. {
  202. setId(id);
  203. assignName(name);
  204. return registerObject();
  205. }
  206. void SimObject::assignDynamicFieldsFrom(SimObject* parent)
  207. {
  208. if(parent->mFieldDictionary)
  209. {
  210. if( mFieldDictionary == NULL )
  211. mFieldDictionary = new SimFieldDictionary;
  212. mFieldDictionary->assignFrom(parent->mFieldDictionary);
  213. }
  214. }
  215. void SimObject::assignFieldsFrom(SimObject *parent)
  216. {
  217. // only allow field assigns from objects of the same class:
  218. if(getClassRep() == parent->getClassRep())
  219. {
  220. const AbstractClassRep::FieldList &list = getFieldList();
  221. // copy out all the fields:
  222. for(U32 i = 0; i < (U32)list.size(); i++)
  223. {
  224. const AbstractClassRep::Field* f = &list[i];
  225. S32 lastField = f->elementCount - 1;
  226. for(S32 j = 0; j <= lastField; j++)
  227. {
  228. const char* fieldVal = (*f->getDataFn)( this, Con::getData(f->type, (void *) (((const char *)parent) + f->offset), j, f->table, f->flag));
  229. //if(fieldVal)
  230. // Con::setData(f->type, (void *) (((const char *)this) + f->offset), j, 1, &fieldVal, f->table);
  231. if(fieldVal)
  232. {
  233. // code copied from SimObject::setDataField().
  234. // TODO: paxorr: abstract this into a better setData / getData that considers prot fields.
  235. FrameTemp<char> buffer(2048);
  236. FrameTemp<char> bufferSecure(2048); // This buffer is used to make a copy of the data
  237. ConsoleBaseType *cbt = ConsoleBaseType::getType( f->type );
  238. const char* szBuffer = cbt->prepData( fieldVal, buffer, 2048 );
  239. dMemset( bufferSecure, 0, 2048 );
  240. dMemcpy( bufferSecure, szBuffer, dStrlen( szBuffer ) );
  241. if((*f->setDataFn)( this, bufferSecure ) )
  242. Con::setData(f->type, (void *) (((const char *)this) + f->offset), j, 1, &fieldVal, f->table);
  243. }
  244. }
  245. }
  246. }
  247. assignDynamicFieldsFrom(parent);
  248. }
  249. bool SimObject::writeField(StringTableEntry fieldname, const char* value)
  250. {
  251. // Don't write empty fields.
  252. if (!value || !*value)
  253. return false;
  254. // Don't write ParentGroup
  255. if( fieldname == StringTable->insert("parentGroup") )
  256. return false;
  257. return true;
  258. }
  259. void SimObject::writeFields(Stream &stream, U32 tabStop)
  260. {
  261. const AbstractClassRep::FieldList &list = getFieldList();
  262. for(U32 i = 0; i < (U32)list.size(); i++)
  263. {
  264. const AbstractClassRep::Field* f = &list[i];
  265. if( f->type == AbstractClassRep::DepricatedFieldType ||
  266. f->type == AbstractClassRep::StartGroupFieldType ||
  267. f->type == AbstractClassRep::EndGroupFieldType) continue;
  268. // Fetch fieldname.
  269. StringTableEntry fieldName = StringTable->insert( f->pFieldname );
  270. // Fetch element count.
  271. const S32 elementCount = f->elementCount;
  272. // Skip if the field should not be written.
  273. // For now, we only deal with non-array fields.
  274. if ( elementCount == 1 &&
  275. f->writeDataFn != NULL &&
  276. f->writeDataFn( this, fieldName ) == false )
  277. continue;
  278. for(U32 j = 0; S32(j) < elementCount; j++)
  279. {
  280. char array[8];
  281. dSprintf( array, 8, "%d", j );
  282. const char *val = getDataField(fieldName, array );
  283. // Make a copy for the field check.
  284. if (!val)
  285. continue;
  286. U32 nBufferSize = dStrlen( val ) + 1;
  287. FrameTemp<char> valCopy( nBufferSize );
  288. dStrcpy( (char *)valCopy, val );
  289. if (!writeField(fieldName, valCopy))
  290. continue;
  291. val = valCopy;
  292. U32 expandedBufferSize = ( nBufferSize * 2 ) + 32;
  293. FrameTemp<char> expandedBuffer( expandedBufferSize );
  294. if(f->elementCount == 1)
  295. dSprintf(expandedBuffer, expandedBufferSize, "%s = \"", f->pFieldname);
  296. else
  297. dSprintf(expandedBuffer, expandedBufferSize, "%s[%d] = \"", f->pFieldname, j);
  298. // detect and collapse relative path information
  299. char fnBuf[1024];
  300. if (f->type == TypeFilename)
  301. {
  302. Con::collapsePath(fnBuf, 1024, val);
  303. val = fnBuf;
  304. }
  305. expandEscape((char*)expandedBuffer + dStrlen(expandedBuffer), val);
  306. dStrcat(expandedBuffer, "\";\r\n");
  307. stream.writeTabs(tabStop);
  308. stream.write(dStrlen(expandedBuffer),expandedBuffer);
  309. }
  310. }
  311. if(mFieldDictionary && mCanSaveFieldDictionary)
  312. mFieldDictionary->writeFields(this, stream, tabStop);
  313. }
  314. void SimObject::write(Stream &stream, U32 tabStop, U32 flags)
  315. {
  316. // Only output selected objects if they want that.
  317. if((flags & SelectedOnly) && !isSelected())
  318. return;
  319. stream.writeTabs(tabStop);
  320. char buffer[1024];
  321. dSprintf(buffer, sizeof(buffer), "new %s(%s) {\r\n", getClassName(), getName() ? getName() : "");
  322. stream.write(dStrlen(buffer), buffer);
  323. writeFields(stream, tabStop + 1);
  324. stream.writeTabs(tabStop);
  325. stream.write(4, "};\r\n");
  326. }
  327. bool SimObject::save(const char* pcFileName, bool bOnlySelected)
  328. {
  329. static const char *beginMessage = "//--- OBJECT WRITE BEGIN ---";
  330. static const char *endMessage = "//--- OBJECT WRITE END ---";
  331. FileStream stream;
  332. FileObject f;
  333. f.readMemory(pcFileName);
  334. // check for flags <selected, ...>
  335. U32 writeFlags = 0;
  336. if(bOnlySelected)
  337. writeFlags |= SimObject::SelectedOnly;
  338. if(!ResourceManager->openFileForWrite(stream, pcFileName))
  339. return false;
  340. char docRoot[256];
  341. char modRoot[256];
  342. dStrcpy(docRoot, pcFileName);
  343. char *p = dStrrchr(docRoot, '/');
  344. if (p) *++p = '\0';
  345. else docRoot[0] = '\0';
  346. dStrcpy(modRoot, pcFileName);
  347. p = dStrchr(modRoot, '/');
  348. if (p) *++p = '\0';
  349. else modRoot[0] = '\0';
  350. Con::setVariable("$DocRoot", docRoot);
  351. Con::setVariable("$ModRoot", modRoot);
  352. const char *buffer;
  353. while(!f.isEOF())
  354. {
  355. buffer = (const char *) f.readLine();
  356. if(!dStrcmp(buffer, beginMessage))
  357. break;
  358. stream.write(dStrlen(buffer), buffer);
  359. stream.write(2, "\r\n");
  360. }
  361. stream.write(dStrlen(beginMessage), beginMessage);
  362. stream.write(2, "\r\n");
  363. write(stream, 0, writeFlags);
  364. stream.write(dStrlen(endMessage), endMessage);
  365. stream.write(2, "\r\n");
  366. while(!f.isEOF())
  367. {
  368. buffer = (const char *) f.readLine();
  369. if(!dStrcmp(buffer, endMessage))
  370. break;
  371. }
  372. while(!f.isEOF())
  373. {
  374. buffer = (const char *) f.readLine();
  375. stream.write(dStrlen(buffer), buffer);
  376. stream.write(2, "\r\n");
  377. }
  378. Con::setVariable("$DocRoot", NULL);
  379. Con::setVariable("$ModRoot", NULL);
  380. return true;
  381. }
  382. void SimObject::setInternalName(const char* newname)
  383. {
  384. if(newname)
  385. mInternalName = StringTable->insert(newname);
  386. }
  387. StringTableEntry SimObject::getInternalName()
  388. {
  389. return mInternalName;
  390. }
  391. void SimObject::dumpClassHierarchy()
  392. {
  393. AbstractClassRep* pRep = getClassRep();
  394. while(pRep)
  395. {
  396. Con::warnf("%s ->", pRep->getClassName());
  397. pRep = pRep->getParentClass();
  398. }
  399. }
  400. const char *SimObject::tabComplete(const char *prevText, S32 baseLen, bool fForward)
  401. {
  402. return mNameSpace->tabComplete(prevText, baseLen, fForward);
  403. }
  404. //-----------------------------------------------------------------------------
  405. void SimObject::setDataField(StringTableEntry slotName, const char *array, const char *value)
  406. {
  407. // first search the static fields if enabled
  408. if(mFlags.test(ModStaticFields))
  409. {
  410. const AbstractClassRep::Field *fld = findField(slotName);
  411. if(fld)
  412. {
  413. if( fld->type == AbstractClassRep::DepricatedFieldType ||
  414. fld->type == AbstractClassRep::StartGroupFieldType ||
  415. fld->type == AbstractClassRep::EndGroupFieldType)
  416. return;
  417. S32 array1 = array ? dAtoi(array) : 0;
  418. if(array1 >= 0 && array1 < fld->elementCount && fld->elementCount >= 1)
  419. {
  420. // If the set data notify callback returns true, then go ahead and
  421. // set the data, otherwise, assume the set notify callback has either
  422. // already set the data, or has deemed that the data should not
  423. // be set at all.
  424. FrameTemp<char> buffer(2048);
  425. FrameTemp<char> bufferSecure(2048); // This buffer is used to make a copy of the data
  426. // so that if the prep functions or any other functions use the string stack, the data
  427. // is not corrupted.
  428. ConsoleBaseType *cbt = ConsoleBaseType::getType( fld->type );
  429. AssertFatal( cbt != NULL, "Could not resolve Type Id." );
  430. const char* szBuffer = cbt->prepData( value, buffer, 2048 );
  431. dMemset( bufferSecure, 0, 2048 );
  432. dMemcpy( bufferSecure, szBuffer, dStrlen( szBuffer ) );
  433. if( (*fld->setDataFn)( this, bufferSecure ) )
  434. Con::setData(fld->type, (void *) (((const char *)this) + fld->offset), array1, 1, &value, fld->table);
  435. onStaticModified( slotName, value );
  436. return;
  437. }
  438. if(fld->validator)
  439. fld->validator->validateType(this, (void *) (((const char *)this) + fld->offset));
  440. onStaticModified( slotName, value );
  441. return;
  442. }
  443. }
  444. if(mFlags.test(ModDynamicFields))
  445. {
  446. if(!mFieldDictionary)
  447. mFieldDictionary = new SimFieldDictionary;
  448. if(!array)
  449. mFieldDictionary->setFieldValue(slotName, value);
  450. else
  451. {
  452. char buf[256];
  453. dStrcpy(buf, slotName);
  454. dStrcat(buf, array);
  455. mFieldDictionary->setFieldValue(StringTable->insert(buf), value);
  456. }
  457. }
  458. }
  459. //-----------------------------------------------------------------------------
  460. const char *SimObject::getDataField(StringTableEntry slotName, const char *array)
  461. {
  462. if(mFlags.test(ModStaticFields))
  463. {
  464. S32 array1 = array ? dAtoi(array) : -1;
  465. const AbstractClassRep::Field *fld = findField(slotName);
  466. if(fld)
  467. {
  468. if(array1 == -1 && fld->elementCount == 1)
  469. return (*fld->getDataFn)( this, Con::getData(fld->type, (void *) (((const char *)this) + fld->offset), 0, fld->table, fld->flag) );
  470. if(array1 >= 0 && array1 < fld->elementCount)
  471. return (*fld->getDataFn)( this, Con::getData(fld->type, (void *) (((const char *)this) + fld->offset), array1, fld->table, fld->flag) );// + typeSizes[fld.type] * array1));
  472. return "";
  473. }
  474. }
  475. if(mFlags.test(ModDynamicFields))
  476. {
  477. if(!mFieldDictionary)
  478. return "";
  479. if(!array)
  480. {
  481. if (const char* val = mFieldDictionary->getFieldValue(slotName))
  482. return val;
  483. }
  484. else
  485. {
  486. static char buf[256];
  487. dStrcpy(buf, slotName);
  488. dStrcat(buf, array);
  489. if (const char* val = mFieldDictionary->getFieldValue(StringTable->insert(buf)))
  490. return val;
  491. }
  492. }
  493. return "";
  494. }
  495. //-----------------------------------------------------------------------------
  496. const char *SimObject::getPrefixedDataField(StringTableEntry fieldName, const char *array)
  497. {
  498. // Sanity!
  499. AssertFatal( fieldName != NULL, "Cannot get field value with NULL field name." );
  500. // Fetch field value.
  501. const char* pFieldValue = getDataField( fieldName, array );
  502. // Sanity.
  503. AssertFatal( pFieldValue != NULL, "Field value cannot be NULL." );
  504. // Return without the prefix if there's no value.
  505. if ( *pFieldValue == 0 )
  506. return StringTable->EmptyString;
  507. // Fetch the field prefix.
  508. StringTableEntry fieldPrefix = getDataFieldPrefix( fieldName );
  509. // Sanity!
  510. AssertFatal( fieldPrefix != NULL, "Field prefix cannot be NULL." );
  511. // Calculate a buffer size including prefix.
  512. const U32 valueBufferSize = dStrlen(fieldPrefix) + dStrlen(pFieldValue) + 1;
  513. // Fetch a buffer.
  514. char* pValueBuffer = Con::getReturnBuffer( valueBufferSize );
  515. // Format the value buffer.
  516. dSprintf( pValueBuffer, valueBufferSize, "%s%s", fieldPrefix, pFieldValue );
  517. return pValueBuffer;
  518. }
  519. //-----------------------------------------------------------------------------
  520. void SimObject::setPrefixedDataField(StringTableEntry fieldName, const char *array, const char *value)
  521. {
  522. // Sanity!
  523. AssertFatal( fieldName != NULL, "Cannot set object field value with NULL field name." );
  524. AssertFatal( value != NULL, "Field value cannot be NULL." );
  525. // Set value without prefix if there's no value.
  526. if ( *value == 0 )
  527. {
  528. setDataField( fieldName, NULL, value );
  529. return;
  530. }
  531. // Fetch the field prefix.
  532. StringTableEntry fieldPrefix = getDataFieldPrefix( fieldName );
  533. // Sanity.
  534. AssertFatal( fieldPrefix != NULL, "Field prefix cannot be NULL." );
  535. // Do we have a field prefix?
  536. if ( fieldPrefix == StringTable->EmptyString )
  537. {
  538. // No, so set the data field in the usual way.
  539. setDataField( fieldName, NULL, value );
  540. return;
  541. }
  542. // Yes, so fetch the length of the field prefix.
  543. const U32 fieldPrefixLength = dStrlen(fieldPrefix);
  544. // Yes, so does it start with the object field prefix?
  545. if ( dStrnicmp( value, fieldPrefix, fieldPrefixLength ) != 0 )
  546. {
  547. // No, so set the data field in the usual way.
  548. setDataField( fieldName, NULL, value );
  549. return;
  550. }
  551. // Yes, so set the data excluding the prefix.
  552. setDataField( fieldName, NULL, value + fieldPrefixLength );
  553. }
  554. //-----------------------------------------------------------------------------
  555. const char *SimObject::getPrefixedDynamicDataField(StringTableEntry fieldName, const char *array, const S32 fieldType )
  556. {
  557. // Sanity!
  558. AssertFatal( fieldName != NULL, "Cannot get field value with NULL field name." );
  559. // Fetch field value.
  560. const char* pFieldValue = getDataField( fieldName, array );
  561. // Sanity.
  562. AssertFatal( pFieldValue != NULL, "Field value cannot be NULL." );
  563. // Return the field if no field type is specified.
  564. if ( fieldType == -1 )
  565. return pFieldValue;
  566. // Return without the prefix if there's no value.
  567. if ( *pFieldValue == 0 )
  568. return StringTable->EmptyString;
  569. // Fetch the console base type.
  570. ConsoleBaseType* pConsoleBaseType = ConsoleBaseType::getType( fieldType );
  571. // Did we find the console base type?
  572. if ( pConsoleBaseType == NULL )
  573. {
  574. // No, so warn.
  575. Con::warnf("getPrefixedDynamicDataField() - Invalid field type '%d' specified for field '%s' with value '%s'.",
  576. fieldType, fieldName, pFieldValue );
  577. }
  578. // Fetch the field prefix.
  579. StringTableEntry fieldPrefix = pConsoleBaseType->getTypePrefix();
  580. // Sanity!
  581. AssertFatal( fieldPrefix != NULL, "Field prefix cannot be NULL." );
  582. // Calculate a buffer size including prefix.
  583. const U32 valueBufferSize = dStrlen(fieldPrefix) + dStrlen(pFieldValue) + 1;
  584. // Fetch a buffer.
  585. char* pValueBuffer = Con::getReturnBuffer( valueBufferSize );
  586. // Format the value buffer.
  587. dSprintf( pValueBuffer, valueBufferSize, "%s%s", fieldPrefix, pFieldValue );
  588. return pValueBuffer;
  589. }
  590. //-----------------------------------------------------------------------------
  591. void SimObject::setPrefixedDynamicDataField(StringTableEntry fieldName, const char *array, const char *value, const S32 fieldType )
  592. {
  593. // Sanity!
  594. AssertFatal( fieldName != NULL, "Cannot set object field value with NULL field name." );
  595. AssertFatal( value != NULL, "Field value cannot be NULL." );
  596. // Set value without prefix if no field type was specified.
  597. if ( fieldType == -1 )
  598. {
  599. setDataField( fieldName, NULL, value );
  600. return;
  601. }
  602. // Fetch the console base type.
  603. ConsoleBaseType* pConsoleBaseType = ConsoleBaseType::getType( fieldType );
  604. // Did we find the console base type?
  605. if ( pConsoleBaseType == NULL )
  606. {
  607. // No, so warn.
  608. Con::warnf("setPrefixedDynamicDataField() - Invalid field type '%d' specified for field '%s' with value '%s'.",
  609. fieldType, fieldName, value );
  610. }
  611. // Set value without prefix if there's no value or we didn't find the console base type.
  612. if ( *value == 0 || pConsoleBaseType == NULL )
  613. {
  614. setDataField( fieldName, NULL, value );
  615. return;
  616. }
  617. // Fetch the field prefix.
  618. StringTableEntry fieldPrefix = pConsoleBaseType->getTypePrefix();
  619. // Sanity.
  620. AssertFatal( fieldPrefix != NULL, "Field prefix cannot be NULL." );
  621. // Do we have a field prefix?
  622. if ( fieldPrefix == StringTable->EmptyString )
  623. {
  624. // No, so set the data field in the usual way.
  625. setDataField( fieldName, NULL, value );
  626. return;
  627. }
  628. // Yes, so fetch the length of the field prefix.
  629. const U32 fieldPrefixLength = dStrlen(fieldPrefix);
  630. // Yes, so does it start with the object field prefix?
  631. if ( dStrnicmp( value, fieldPrefix, fieldPrefixLength ) != 0 )
  632. {
  633. // No, so set the data field in the usual way.
  634. setDataField( fieldName, NULL, value );
  635. return;
  636. }
  637. // Yes, so set the data excluding the prefix.
  638. setDataField( fieldName, NULL, value + fieldPrefixLength );
  639. }
  640. //-----------------------------------------------------------------------------
  641. StringTableEntry SimObject::getDataFieldPrefix( StringTableEntry fieldName )
  642. {
  643. // Sanity!
  644. AssertFatal( fieldName != NULL, "Cannot get field prefix with NULL field name." );
  645. // Find the field.
  646. const AbstractClassRep::Field* pField = findField( fieldName );
  647. // Return nothing if field was not found.
  648. if ( pField == NULL )
  649. return StringTable->EmptyString;
  650. // Yes, so fetch the console base type.
  651. ConsoleBaseType* pConsoleBaseType = ConsoleBaseType::getType( pField->type );
  652. // Fetch the type prefix.
  653. return pConsoleBaseType->getTypePrefix();
  654. }
  655. //-----------------------------------------------------------------------------
  656. U32 SimObject::getDataFieldType( StringTableEntry slotName, const char* array )
  657. {
  658. const AbstractClassRep::Field* field = findField( slotName );
  659. if( field )
  660. return field->type;
  661. return 0;
  662. }
  663. SimObject::~SimObject()
  664. {
  665. delete mFieldDictionary;
  666. AssertFatal(nextNameObject == (SimObject*)-1,avar(
  667. "SimObject::~SimObject: Not removed from dictionary: name %s, id %i",
  668. objectName, mId));
  669. AssertFatal(nextManagerNameObject == (SimObject*)-1,avar(
  670. "SimObject::~SimObject: Not removed from manager dictionary: name %s, id %i",
  671. objectName,mId));
  672. AssertFatal(mFlags.test(Added) == 0, "SimObject::object "
  673. "missing call to SimObject::onRemove");
  674. }
  675. //---------------------------------------------------------------------------
  676. bool SimObject::isLocked()
  677. {
  678. if(!mFieldDictionary)
  679. return false;
  680. const char * val = mFieldDictionary->getFieldValue( StringTable->insert( "locked", false ) );
  681. return( val ? dAtob(val) : false );
  682. }
  683. void SimObject::setLocked( bool b = true )
  684. {
  685. setDataField(StringTable->insert("locked", false), NULL, b ? "true" : "false" );
  686. }
  687. bool SimObject::isHidden()
  688. {
  689. if(!mFieldDictionary)
  690. return false;
  691. const char * val = mFieldDictionary->getFieldValue( StringTable->insert( "hidden", false ) );
  692. return( val ? dAtob(val) : false );
  693. }
  694. void SimObject::setHidden(bool b = true)
  695. {
  696. setDataField(StringTable->insert("hidden", false), NULL, b ? "true" : "false" );
  697. }
  698. //---------------------------------------------------------------------------
  699. bool SimObject::onAdd()
  700. {
  701. mFlags.set(Added);
  702. linkNamespaces();
  703. // onAdd() should return FALSE if there was an error
  704. return true;
  705. }
  706. void SimObject::onRemove()
  707. {
  708. mFlags.clear(Added);
  709. unlinkNamespaces();
  710. }
  711. void SimObject::onGroupAdd()
  712. {
  713. }
  714. void SimObject::onGroupRemove()
  715. {
  716. }
  717. void SimObject::onDeleteNotify(SimObject*)
  718. {
  719. }
  720. void SimObject::onNameChange(const char*)
  721. {
  722. }
  723. void SimObject::onStaticModified(const char* slotName, const char* newValue)
  724. {
  725. }
  726. bool SimObject::processArguments(S32 argc, const char**)
  727. {
  728. return argc == 0;
  729. }
  730. bool SimObject::isChildOfGroup(SimGroup* pGroup)
  731. {
  732. if(!pGroup)
  733. return false;
  734. //if we *are* the group in question,
  735. //return true:
  736. if(pGroup == dynamic_cast<SimGroup*>(this))
  737. return true;
  738. SimGroup* temp = mGroup;
  739. while(temp)
  740. {
  741. if(temp == pGroup)
  742. return true;
  743. temp = temp->mGroup;
  744. }
  745. return false;
  746. }
  747. //---------------------------------------------------------------------------
  748. static Chunker<SimObject::Notify> notifyChunker(128000);
  749. SimObject::Notify *SimObject::mNotifyFreeList = NULL;
  750. SimObject::Notify *SimObject::allocNotify()
  751. {
  752. if(mNotifyFreeList)
  753. {
  754. SimObject::Notify *ret = mNotifyFreeList;
  755. mNotifyFreeList = ret->next;
  756. return ret;
  757. }
  758. return notifyChunker.alloc();
  759. }
  760. void SimObject::freeNotify(SimObject::Notify* note)
  761. {
  762. AssertFatal(note->type != SimObject::Notify::Invalid, "Invalid notify");
  763. note->type = SimObject::Notify::Invalid;
  764. note->next = mNotifyFreeList;
  765. mNotifyFreeList = note;
  766. }
  767. //------------------------------------------------------------------------------
  768. SimObject::Notify* SimObject::removeNotify(void *ptr, SimObject::Notify::Type type)
  769. {
  770. Notify **list = &mNotifyList;
  771. while(*list)
  772. {
  773. if((*list)->ptr == ptr && (*list)->type == type)
  774. {
  775. SimObject::Notify *ret = *list;
  776. *list = ret->next;
  777. return ret;
  778. }
  779. list = &((*list)->next);
  780. }
  781. return NULL;
  782. }
  783. void SimObject::deleteNotify(SimObject* obj)
  784. {
  785. AssertFatal(!obj->isDeleted(),
  786. "SimManager::deleteNotify: Object is being deleted");
  787. Notify *note = allocNotify();
  788. note->ptr = (void *) this;
  789. note->next = obj->mNotifyList;
  790. note->type = Notify::DeleteNotify;
  791. obj->mNotifyList = note;
  792. note = allocNotify();
  793. note->ptr = (void *) obj;
  794. note->next = mNotifyList;
  795. note->type = Notify::ClearNotify;
  796. mNotifyList = note;
  797. //obj->deleteNotifyList.pushBack(this);
  798. //clearNotifyList.pushBack(obj);
  799. }
  800. void SimObject::registerReference(SimObject **ptr)
  801. {
  802. Notify *note = allocNotify();
  803. note->ptr = (void *) ptr;
  804. note->next = mNotifyList;
  805. note->type = Notify::ObjectRef;
  806. mNotifyList = note;
  807. }
  808. void SimObject::unregisterReference(SimObject **ptr)
  809. {
  810. Notify *note = removeNotify((void *) ptr, Notify::ObjectRef);
  811. if(note)
  812. freeNotify(note);
  813. }
  814. void SimObject::clearNotify(SimObject* obj)
  815. {
  816. Notify *note = obj->removeNotify((void *) this, Notify::DeleteNotify);
  817. if(note)
  818. freeNotify(note);
  819. note = removeNotify((void *) obj, Notify::ClearNotify);
  820. if(note)
  821. freeNotify(note);
  822. }
  823. void SimObject::processDeleteNotifies()
  824. {
  825. // clear out any delete notifies and
  826. // object refs.
  827. while(mNotifyList)
  828. {
  829. Notify *note = mNotifyList;
  830. mNotifyList = note->next;
  831. AssertFatal(note->type != Notify::ClearNotify, "Clear notes should be all gone.");
  832. if(note->type == Notify::DeleteNotify)
  833. {
  834. SimObject *obj = (SimObject *) note->ptr;
  835. Notify *cnote = obj->removeNotify((void *)this, Notify::ClearNotify);
  836. obj->onDeleteNotify(this);
  837. freeNotify(cnote);
  838. }
  839. else
  840. {
  841. // it must be an object ref - a pointer refs this object
  842. *((SimObject **) note->ptr) = NULL;
  843. }
  844. freeNotify(note);
  845. }
  846. }
  847. void SimObject::clearAllNotifications()
  848. {
  849. for(Notify **cnote = &mNotifyList; *cnote; )
  850. {
  851. Notify *temp = *cnote;
  852. if(temp->type == Notify::ClearNotify)
  853. {
  854. *cnote = temp->next;
  855. Notify *note = ((SimObject *) temp->ptr)->removeNotify((void *) this, Notify::DeleteNotify);
  856. freeNotify(temp);
  857. freeNotify(note);
  858. }
  859. else
  860. cnote = &(temp->next);
  861. }
  862. }
  863. //---------------------------------------------------------------------------
  864. void SimObject::initPersistFields()
  865. {
  866. Parent::initPersistFields();
  867. addGroup("SimBase");
  868. addField("canSaveDynamicFields", TypeBool, Offset(mCanSaveFieldDictionary, SimObject), &writeCanSaveDynamicFields, "");
  869. addField("internalName", TypeString, Offset(mInternalName, SimObject), &writeInternalName, "");
  870. addProtectedField("parentGroup", TypeSimObjectPtr, Offset(mGroup, SimObject), &setParentGroup, &defaultProtectedGetFn, &writeParentGroup, "Group hierarchy parent of the object." );
  871. endGroup("SimBase");
  872. // Namespace Linking.
  873. addGroup("Namespace Linking");
  874. addProtectedField("superclass", TypeString, Offset(mSuperClassName, SimObject), &setSuperClass, &defaultProtectedGetFn, &writeSuperclass, "Script Class of object.");
  875. addProtectedField("class", TypeString, Offset(mClassName, SimObject), &setClass, &defaultProtectedGetFn, &writeClass, "Script SuperClass of object.");
  876. endGroup("Namespace Linking");
  877. }
  878. //-----------------------------------------------------------------------------
  879. SimObject* SimObject::clone( const bool copyDynamicFields )
  880. {
  881. // Craete cloned object.
  882. SimObject* pCloneObject = dynamic_cast<SimObject*>( ConsoleObject::create(getClassName()) );
  883. if (!pCloneObject)
  884. {
  885. Con::errorf("SimObject::clone() - Unable to create cloned object.");
  886. return NULL;
  887. }
  888. // Register object.
  889. if ( !pCloneObject->registerObject() )
  890. {
  891. Con::warnf("SimObject::clone() - Unable to register cloned object.");
  892. delete pCloneObject;
  893. return NULL;
  894. }
  895. // Copy object.
  896. copyTo( pCloneObject );
  897. // Copy over dynamic fields if requested.
  898. if ( copyDynamicFields )
  899. pCloneObject->assignDynamicFieldsFrom( this );
  900. return pCloneObject;
  901. }
  902. //-----------------------------------------------------------------------------
  903. void SimObject::copyTo(SimObject* object)
  904. {
  905. object->mClassName = mClassName;
  906. object->mSuperClassName = mSuperClassName;
  907. object->mNameSpace = NULL;
  908. object->linkNamespaces();
  909. }
  910. //-----------------------------------------------------------------------------
  911. bool SimObject::setParentGroup(void* obj, const char* data)
  912. {
  913. SimGroup *parent = NULL;
  914. SimObject *object = static_cast<SimObject*>(obj);
  915. if(Sim::findObject(data, parent))
  916. parent->addObject(object);
  917. // always return false, because we've set mGroup when we called addObject
  918. return false;
  919. }
  920. bool SimObject::addToSet(SimObjectId spid)
  921. {
  922. if (mFlags.test(Added) == false)
  923. return false;
  924. SimObject* ptr = Sim::findObject(spid);
  925. if (ptr)
  926. {
  927. SimSet* sp = dynamic_cast<SimSet*>(ptr);
  928. AssertFatal(sp != 0,
  929. "SimObject::addToSet: "
  930. "ObjectId does not refer to a set object");
  931. if (sp)
  932. {
  933. sp->addObject(this);
  934. return true;
  935. }
  936. }
  937. return false;
  938. }
  939. bool SimObject::addToSet(const char *ObjectName)
  940. {
  941. if (mFlags.test(Added) == false)
  942. return false;
  943. SimObject* ptr = Sim::findObject(ObjectName);
  944. if (ptr)
  945. {
  946. SimSet* sp = dynamic_cast<SimSet*>(ptr);
  947. AssertFatal(sp != 0,
  948. "SimObject::addToSet: "
  949. "ObjectName does not refer to a set object");
  950. if (sp)
  951. {
  952. sp->addObject(this);
  953. return true;
  954. }
  955. }
  956. return false;
  957. }
  958. bool SimObject::removeFromSet(SimObjectId sid)
  959. {
  960. if (mFlags.test(Added) == false)
  961. return false;
  962. SimSet *set;
  963. if(Sim::findObject(sid, set))
  964. {
  965. set->removeObject(this);
  966. return true;
  967. }
  968. return false;
  969. }
  970. bool SimObject::removeFromSet(const char *objectName)
  971. {
  972. if (mFlags.test(Added) == false)
  973. return false;
  974. SimSet *set;
  975. if(Sim::findObject(objectName, set))
  976. {
  977. set->removeObject(this);
  978. return true;
  979. }
  980. return false;
  981. }
  982. void SimObject::inspectPreApply()
  983. {
  984. }
  985. void SimObject::inspectPostApply()
  986. {
  987. }
  988. void SimObject::linkNamespaces()
  989. {
  990. if( mNameSpace )
  991. unlinkNamespaces();
  992. StringTableEntry parent = StringTable->insert( getClassName() );
  993. if( ( mNSLinkMask & LinkSuperClassName ) && mSuperClassName && mSuperClassName[0] )
  994. {
  995. if( Con::linkNamespaces( parent, mSuperClassName ) )
  996. parent = mSuperClassName;
  997. else
  998. mSuperClassName = StringTable->EmptyString; // CodeReview Is this behavior that we want?
  999. // CodeReview This will result in the mSuperClassName variable getting hosed
  1000. // CodeReview if Con::linkNamespaces returns false. Looking at the code for
  1001. // CodeReview Con::linkNamespaces, and the call it makes to classLinkTo, it seems
  1002. // CodeReview like this would only fail if it had bogus data to begin with, but
  1003. // CodeReview I wanted to note this behavior which occurs in some implementations
  1004. // CodeReview but not all. -patw
  1005. }
  1006. // ClassName -> SuperClassName
  1007. if ( ( mNSLinkMask & LinkClassName ) && mClassName && mClassName[0] )
  1008. {
  1009. if( Con::linkNamespaces( parent, mClassName ) )
  1010. parent = mClassName;
  1011. else
  1012. mClassName = StringTable->EmptyString; // CodeReview (See previous note on this code)
  1013. }
  1014. // ObjectName -> ClassName
  1015. StringTableEntry objectName = getName();
  1016. if( objectName && objectName[0] )
  1017. {
  1018. if( Con::linkNamespaces( parent, objectName ) )
  1019. parent = objectName;
  1020. }
  1021. // Store our namespace.
  1022. mNameSpace = Con::lookupNamespace( parent );
  1023. }
  1024. void SimObject::unlinkNamespaces()
  1025. {
  1026. if (!mNameSpace)
  1027. return;
  1028. // Restore NameSpace's
  1029. StringTableEntry child = getName();
  1030. if( child && child[0] )
  1031. {
  1032. if( ( mNSLinkMask & LinkClassName ) && mClassName && mClassName[0])
  1033. {
  1034. if( Con::unlinkNamespaces( mClassName, child ) )
  1035. child = mClassName;
  1036. }
  1037. if( ( mNSLinkMask & LinkSuperClassName ) && mSuperClassName && mSuperClassName[0] )
  1038. {
  1039. if( Con::unlinkNamespaces( mSuperClassName, child ) )
  1040. child = mSuperClassName;
  1041. }
  1042. Con::unlinkNamespaces( getClassName(), child );
  1043. }
  1044. else
  1045. {
  1046. child = mClassName;
  1047. if( child && child[0] )
  1048. {
  1049. if( ( mNSLinkMask & LinkSuperClassName ) && mSuperClassName && mSuperClassName[0] )
  1050. {
  1051. if( Con::unlinkNamespaces( mSuperClassName, child ) )
  1052. child = mSuperClassName;
  1053. }
  1054. Con::unlinkNamespaces( getClassName(), child );
  1055. }
  1056. else
  1057. {
  1058. if( ( mNSLinkMask & LinkSuperClassName ) && mSuperClassName && mSuperClassName[0] )
  1059. Con::unlinkNamespaces( getClassName(), mSuperClassName );
  1060. }
  1061. }
  1062. mNameSpace = NULL;
  1063. }
  1064. void SimObject::setClassNamespace( const char *classNamespace )
  1065. {
  1066. mClassName = StringTable->insert( classNamespace );
  1067. if (mFlags.test(Added))
  1068. linkNamespaces();
  1069. }
  1070. void SimObject::setSuperClassNamespace( const char *superClassNamespace )
  1071. {
  1072. mSuperClassName = StringTable->insert( superClassNamespace );
  1073. if (mFlags.test(Added))
  1074. linkNamespaces();
  1075. }
  1076. static S32 QSORT_CALLBACK compareFields(const void* a,const void* b)
  1077. {
  1078. const AbstractClassRep::Field* fa = *((const AbstractClassRep::Field**)a);
  1079. const AbstractClassRep::Field* fb = *((const AbstractClassRep::Field**)b);
  1080. return dStricmp(fa->pFieldname, fb->pFieldname);
  1081. }
  1082. void SimObject::dump()
  1083. {
  1084. const AbstractClassRep::FieldList &list = getFieldList();
  1085. char expandedBuffer[4096];
  1086. Con::printf("Static Fields:");
  1087. Vector<const AbstractClassRep::Field *> flist(__FILE__, __LINE__);
  1088. for(U32 i = 0; i < (U32)list.size(); i++)
  1089. flist.push_back(&list[i]);
  1090. dQsort(flist.address(),flist.size(),sizeof(AbstractClassRep::Field *),compareFields);
  1091. for(Vector<const AbstractClassRep::Field *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
  1092. {
  1093. const AbstractClassRep::Field* f = *itr;
  1094. if( f->type == AbstractClassRep::DepricatedFieldType ||
  1095. f->type == AbstractClassRep::StartGroupFieldType ||
  1096. f->type == AbstractClassRep::EndGroupFieldType) continue;
  1097. for(U32 j = 0; S32(j) < f->elementCount; j++)
  1098. {
  1099. // [neo, 07/05/2007 - #3000]
  1100. // Some objects use dummy vars and projected fields so make sure we call the get functions
  1101. //const char *val = Con::getData(f->type, (void *) (((const char *)object) + f->offset), j, f->table, f->flag);
  1102. const char *val = (*f->getDataFn)( this, Con::getData(f->type, (void *) (((const char *)this) + f->offset), j, f->table, f->flag) );// + typeSizes[fld.type] * array1));
  1103. if(!val /*|| !*val*/)
  1104. continue;
  1105. if(f->elementCount == 1)
  1106. dSprintf(expandedBuffer, sizeof(expandedBuffer), " %s = \"", f->pFieldname);
  1107. else
  1108. dSprintf(expandedBuffer, sizeof(expandedBuffer), " %s[%d] = \"", f->pFieldname, j);
  1109. expandEscape(expandedBuffer + dStrlen(expandedBuffer), val);
  1110. Con::printf("%s\"", expandedBuffer);
  1111. }
  1112. }
  1113. Con::printf("Dynamic Fields:");
  1114. if(getFieldDictionary())
  1115. getFieldDictionary()->printFields(this);
  1116. Con::printf("Methods:");
  1117. Namespace *ns = getNamespace();
  1118. Vector<Namespace::Entry *> vec(__FILE__, __LINE__);
  1119. if(ns)
  1120. ns->getEntryList(&vec);
  1121. for(Vector<Namespace::Entry *>::iterator j = vec.begin(); j != vec.end(); j++)
  1122. Con::printf(" %s() - %s", (*j)->mFunctionName, (*j)->mUsage ? (*j)->mUsage : "");
  1123. }