MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / writeFields

Method writeFields

Engine/source/console/simObject.cpp:306–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304//-----------------------------------------------------------------------------
305
306void SimObject::writeFields(Stream &stream, U32 tabStop)
307{
308 // Write static fields.
309
310 // Create a default object of the same type
311 ConsoleObject* defaultConObject = ConsoleObject::create(getClassName());
312 SimObject* defaultObject = dynamic_cast<SimObject*>(defaultConObject);
313
314 const AbstractClassRep::FieldList &list = getFieldList();
315
316 for(U32 i = 0; i < list.size(); i++)
317 {
318 const AbstractClassRep::Field* f = &list[i];
319
320 // Skip the special field types.
321 if ( f->type >= AbstractClassRep::ARCFirstCustomField )
322 continue;
323
324 for(U32 j = 0; S32(j) < f->elementCount; j++)
325 {
326 char array[8];
327 dSprintf( array, 8, "%d", j );
328 const char *val = getDataField(StringTable->insert( f->pFieldname ), array );
329
330 // Make a copy for the field check.
331 if (!val)
332 continue;
333
334 U32 nBufferSize = dStrlen( val ) + 1;
335 FrameTemp<char> valCopy( nBufferSize );
336 dStrcpy( (char *)valCopy, val, nBufferSize );
337
338 if (!writeField(f->pFieldname, valCopy))
339 continue;
340
341 //If the field hasn't been changed from the default value, then don't bother writing it out
342 const char* defaultValueCheck = defaultObject->getDataField(f->pFieldname, array);
343 if (defaultValueCheck && defaultValueCheck[0] != '\0' && dStricmp(defaultValueCheck, valCopy) == 0)
344 continue;
345
346 val = valCopy;
347
348 U32 expandedBufferSize = ( nBufferSize * 2 ) + dStrlen(f->pFieldname) + 32;
349 FrameTemp<char> expandedBuffer( expandedBufferSize );
350 if(f->elementCount == 1)
351 dSprintf(expandedBuffer, expandedBufferSize, "%s = \"", f->pFieldname);
352 else
353 dSprintf(expandedBuffer, expandedBufferSize, "%s[%d] = \"", f->pFieldname, j);
354
355 // detect and collapse relative path information
356 char fnBuf[1024];
357 if (f->type == TypeFilename ||
358 f->type == TypeStringFilename ||
359 f->type == TypeImageFilename ||
360 f->type == TypePrefabFilename ||
361 f->type == TypeShapeFilename ||
362 f->type == TypeSoundFilename )
363 {

Callers

nothing calls this directly

Calls 12

dSprintfFunction · 0.85
dStrcpyFunction · 0.85
dStricmpFunction · 0.85
collapseScriptFilenameFunction · 0.85
expandEscapeFunction · 0.85
dStrcatFunction · 0.85
getDataFieldMethod · 0.80
writeTabsMethod · 0.80
dStrlenFunction · 0.50
sizeMethod · 0.45
insertMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected