simObject.cc 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  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. linkNamespaces();
  1068. }
  1069. void SimObject::setSuperClassNamespace( const char *superClassNamespace )
  1070. {
  1071. mSuperClassName = StringTable->insert( superClassNamespace );
  1072. linkNamespaces();
  1073. }
  1074. static S32 QSORT_CALLBACK compareFields(const void* a,const void* b)
  1075. {
  1076. const AbstractClassRep::Field* fa = *((const AbstractClassRep::Field**)a);
  1077. const AbstractClassRep::Field* fb = *((const AbstractClassRep::Field**)b);
  1078. return dStricmp(fa->pFieldname, fb->pFieldname);
  1079. }
  1080. void SimObject::dump()
  1081. {
  1082. const AbstractClassRep::FieldList &list = getFieldList();
  1083. char expandedBuffer[4096];
  1084. Con::printf("Static Fields:");
  1085. Vector<const AbstractClassRep::Field *> flist(__FILE__, __LINE__);
  1086. for(U32 i = 0; i < (U32)list.size(); i++)
  1087. flist.push_back(&list[i]);
  1088. dQsort(flist.address(),flist.size(),sizeof(AbstractClassRep::Field *),compareFields);
  1089. for(Vector<const AbstractClassRep::Field *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
  1090. {
  1091. const AbstractClassRep::Field* f = *itr;
  1092. if( f->type == AbstractClassRep::DepricatedFieldType ||
  1093. f->type == AbstractClassRep::StartGroupFieldType ||
  1094. f->type == AbstractClassRep::EndGroupFieldType) continue;
  1095. for(U32 j = 0; S32(j) < f->elementCount; j++)
  1096. {
  1097. // [neo, 07/05/2007 - #3000]
  1098. // Some objects use dummy vars and projected fields so make sure we call the get functions
  1099. //const char *val = Con::getData(f->type, (void *) (((const char *)object) + f->offset), j, f->table, f->flag);
  1100. 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));
  1101. if(!val /*|| !*val*/)
  1102. continue;
  1103. if(f->elementCount == 1)
  1104. dSprintf(expandedBuffer, sizeof(expandedBuffer), " %s = \"", f->pFieldname);
  1105. else
  1106. dSprintf(expandedBuffer, sizeof(expandedBuffer), " %s[%d] = \"", f->pFieldname, j);
  1107. expandEscape(expandedBuffer + dStrlen(expandedBuffer), val);
  1108. Con::printf("%s\"", expandedBuffer);
  1109. }
  1110. }
  1111. Con::printf("Dynamic Fields:");
  1112. if(getFieldDictionary())
  1113. getFieldDictionary()->printFields(this);
  1114. Con::printf("Methods:");
  1115. Namespace *ns = getNamespace();
  1116. Vector<Namespace::Entry *> vec(__FILE__, __LINE__);
  1117. if(ns)
  1118. ns->getEntryList(&vec);
  1119. for(Vector<Namespace::Entry *>::iterator j = vec.begin(); j != vec.end(); j++)
  1120. Con::printf(" %s() - %s", (*j)->mFunctionName, (*j)->mUsage ? (*j)->mUsage : "");
  1121. }