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

Method performSubstitutions

Engine/source/console/simDatablock.cpp:193–315  ·  view source on GitHub ↗

This is the method that evaluates any substitution statements on a datablock and does the actual replacement of substituted datablock fields. Much of the work is done by passing the statement to Con::evaluate() but first there are some key operations performed on the statement. -- Instances of "%%" in the statement are replaced with the id of the object. -- Instances of "##" are replaced wi

Source from the content-addressed store, hash-verified

191// -- A result of "~0" will clear the original field to "" without producing an error message.
192//
193void SimDataBlock::performSubstitutions(SimDataBlock* dblock, const SimObject* obj, S32 index)
194{
195 if (!dblock || !dblock->getClassRep())
196 {
197 // error message
198 return;
199 }
200
201 char obj_str[32];
202 dStrcpy(obj_str, Con::getIntArg(obj->getId()), 32);
203
204 char index_str[32];
205 dStrcpy(index_str, Con::getIntArg(index), 32);
206
207 for (S32 i = 0; i < substitutions.size(); i++)
208 {
209 if (substitutions[i])
210 {
211 static char buffer[1024];
212 static char* b_oob = &buffer[1024];
213 char* b = buffer;
214
215 // perform special token expansion (%% and ##)
216 const char* v = substitutions[i]->mValue;
217 while (*v != '\0')
218 {
219 // identify "%%" tokens and replace with <obj> id
220 if (v[0] == '%' && v[1] == '%')
221 {
222 const char* s = obj_str;
223 while (*s != '\0')
224 {
225 b[0] = s[0];
226 b++;
227 s++;
228 }
229 v += 2;
230 }
231 // identify "##" tokens and replace with <index> value
232 else if (v[0] == '#' && v[1] == '#')
233 {
234 const char* s = index_str;
235 while (*s != '\0')
236 {
237 b[0] = s[0];
238 b++;
239 s++;
240 }
241 v += 2;
242 }
243 else
244 {
245 b[0] = v[0];
246 b++;
247 v++;
248 }
249 }
250

Callers 15

effects_initMethod · 0.80
onNewDataBlockMethod · 0.80
onAddMethod · 0.80
cast_spellMethod · 0.80
onNewDataBlockMethod · 0.80
onAddMethod · 0.80
start_effectMethod · 0.80
start_selectronMethod · 0.80
init_pathsMethod · 0.80

Calls 14

dStrcpyFunction · 0.85
getIntArgFunction · 0.85
evaluateFunction · 0.85
avarFunction · 0.85
setDataFunction · 0.85
getClassRepMethod · 0.80
errorfFunction · 0.70
getIdMethod · 0.65
sizeMethod · 0.45
findFieldMethod · 0.45
getClassNameMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected