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

Function setFieldComponent

Engine/source/console/compiledEval.cpp:219–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219static void setFieldComponent(SimObject* object, StringTableEntry field, const char* array, StringTableEntry subField, S32 currentLocalRegister)
220{
221 // Copy the current string value
222 char strValue[1024];
223 dStrncpy(strValue, stack[_STK].getString(), 1024);
224
225 char val[1024] = "";
226 const char* prevVal = NULL;
227
228 if (object && field)
229 prevVal = object->getDataField(field, array);
230 else if (currentLocalRegister != -1)
231 prevVal = gEvalState.getLocalStringVariable(currentLocalRegister);
232 // Set the value on a variable.
233 else if (gEvalState.currentVariable)
234 prevVal = gEvalState.getStringVariable();
235
236 // Ensure that the variable has a value
237 if (!prevVal)
238 return;
239
240 static const StringTableEntry xyzw[] =
241 {
242 StringTable->insert("x"),
243 StringTable->insert("y"),
244 StringTable->insert("z"),
245 StringTable->insert("w")
246 };
247
248 static const StringTableEntry rgba[] =
249 {
250 StringTable->insert("r"),
251 StringTable->insert("g"),
252 StringTable->insert("b"),
253 StringTable->insert("a")
254 };
255
256 // Insert the value into the specified
257 // component of the string.
258 if (subField == xyzw[0] || subField == rgba[0])
259 dStrcpy(val, StringUnit::setUnit(prevVal, 0, strValue, " \t\n"), 128);
260
261 else if (subField == xyzw[1] || subField == rgba[1])
262 dStrcpy(val, StringUnit::setUnit(prevVal, 1, strValue, " \t\n"), 128);
263
264 else if (subField == xyzw[2] || subField == rgba[2])
265 dStrcpy(val, StringUnit::setUnit(prevVal, 2, strValue, " \t\n"), 128);
266
267 else if (subField == xyzw[3] || subField == rgba[3])
268 dStrcpy(val, StringUnit::setUnit(prevVal, 3, strValue, " \t\n"), 128);
269
270 if (val[0] != 0)
271 {
272 // Update the field or variable.
273 if (object && field)
274 object->setDataField(field, 0, val);
275 else if (currentLocalRegister != -1)
276 gEvalState.setLocalStringVariable(currentLocalRegister, val, dStrlen(val));

Callers 1

execMethod · 0.85

Calls 12

dStrncpyFunction · 0.85
dStrcpyFunction · 0.85
setUnitFunction · 0.85
getDataFieldMethod · 0.80
getStringVariableMethod · 0.80
setStringVariableMethod · 0.80
dStrlenFunction · 0.50
getStringMethod · 0.45
insertMethod · 0.45
setDataFieldMethod · 0.45

Tested by

no test coverage detected