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

Method restore

Engine/source/console/simObjectMemento.cpp:76–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76SimObject *SimObjectMemento::restore() const
77{
78 // Make sure we have data to restore.
79 if ( !mState )
80 return NULL;
81
82 // TODO: We could potentially make this faster by
83 // caching the CodeBlock generated from the string
84
85 SimObject* object;
86 if( !mIsDatablock )
87 {
88 // Set the redefine behavior to automatically giving
89 // the new objects unique names. This will restore the
90 // old names if they are still available or give reasonable
91 // approximations if not.
92
93 const char* oldRedefineBehavior = Con::getVariable( "$Con::redefineBehavior" );
94 Con::setVariable( "$Con::redefineBehavior", "renameNew" );
95
96 // Read the object.
97
98 const UTF8* result = Con::evaluate( mState );
99
100 // Restore the redefine behavior.
101
102 Con::setVariable( "$Con::redefineBehavior", oldRedefineBehavior );
103
104 if ( !result || !result[ 0 ] )
105 return NULL;
106
107 // Look up the object.
108
109 U32 objectId = dAtoi( result );
110 object = Sim::findObject( objectId );
111 }
112 else
113 {
114 String objectName = mObjectName;
115
116 // For datablocks, it's getting a little complicated. Datablock definitions cannot be used
117 // as expressions and thus we can't get to the datablock object we create by using the
118 // Con::evaluate() return value. Instead, we need to rely on the object name. However, if
119 // the name is already taken and needs to be changed, we need to manually do that. To complicate
120 // this further, we cannot rely on automatic renaming since then we don't know by what name
121 // the newly created object actually goes. So what we do is we alter the source text snapshot
122 // and substitute a name in case the old object name is actually taken now.
123
124 char* tempBuffer;
125 if( !Sim::findObject( objectName ) )
126 tempBuffer = mState;
127 else
128 {
129 String uniqueName = Sim::getUniqueName( objectName );
130 U32 uniqueNameLen = uniqueName.length();
131
132 char* pLeftParen = dStrchr( mState, '(' );
133 if( pLeftParen == NULL )

Callers

nothing calls this directly

Calls 12

getVariableFunction · 0.85
setVariableFunction · 0.85
evaluateFunction · 0.85
dStrcpyFunction · 0.85
dAtoiFunction · 0.70
findObjectFunction · 0.70
getUniqueNameFunction · 0.70
dStrchrFunction · 0.50
dStrlenFunction · 0.50
dMemcpyFunction · 0.50
dFreeFunction · 0.50
lengthMethod · 0.45

Tested by

no test coverage detected