MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / writeNewObject

Method writeNewObject

Engine/source/console/persistenceManager.cpp:1226–1329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1224}
1225
1226PersistenceManager::ParsedObject* PersistenceManager::writeNewObject(SimObject* object, const Vector<const char*>& properties, const U32 insertLine, ParsedObject* parentObject)
1227{
1228 ParsedObject* parsedObject = new ParsedObject;
1229
1230 parsedObject->name = object->getName();
1231 parsedObject->className = object->getClassName();
1232 parsedObject->simObject = object;
1233
1234 U32 currInsertLine = insertLine;
1235
1236 // If the parentObject isn't set see if
1237 // we can find it in the file
1238 if (!parentObject)
1239 parentObject = findParentObject(object);
1240
1241 parsedObject->parentObject = parentObject;
1242
1243 char* indent = getObjectIndent(parentObject);
1244
1245 if (parentObject)
1246 dStrcat(indent, " \0");
1247
1248 // Write out the beginning of the object declaration
1249 const char* dclToken = "new";
1250
1251 if (dynamic_cast<Material*>(object) ||
1252 dynamic_cast<CustomMaterial*>(object) ||
1253 dynamic_cast<GuiControlProfile*>(object) ||
1254 dynamic_cast<TSShapeConstructor*>(object))
1255 dclToken = "singleton";
1256 else if( dynamic_cast< SimDataBlock* >( object ) )
1257 {
1258 SimDataBlock* db = static_cast<SimDataBlock*>(object);
1259
1260 if( db->isClientOnly() )
1261 {
1262 if( db->getName() && db->getName()[ 0 ] )
1263 dclToken = "singleton";
1264 }
1265 else
1266 dclToken = "datablock";
1267 }
1268
1269 char newLine[ 4096 ];
1270 dMemset(newLine, 0, sizeof( newLine));
1271
1272 // New line before an object declaration
1273 dSprintf(newLine, sizeof( newLine ), "");
1274
1275 mLineBuffer.insert(currInsertLine, dStrdup(newLine));
1276 currInsertLine++;
1277 dMemset(newLine, 0, sizeof( newLine ));
1278
1279 parsedObject->startLine = currInsertLine;
1280 parsedObject->nameLine = currInsertLine;
1281 parsedObject->namePosition = dStrlen(indent) + dStrlen(dclToken) + dStrlen(object->getClassName()) + 2;
1282
1283 // Objects that had no name were getting saved out as: Object((null))

Callers

nothing calls this directly

Calls 13

dStrcatFunction · 0.85
dSprintfFunction · 0.85
isClientOnlyMethod · 0.80
getCopySourceMethod · 0.80
setOriginalNameMethod · 0.80
setDeclarationLineMethod · 0.80
dMemsetFunction · 0.50
dStrlenFunction · 0.50
getNameMethod · 0.45
getClassNameMethod · 0.45
insertMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected