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

Function getFieldComponent

Engine/source/console/compiledEval.cpp:327–378  ·  view source on GitHub ↗

Gets a component of an object's field value or a variable and returns it in val.

Source from the content-addressed store, hash-verified

325// Gets a component of an object's field value or a variable and returns it
326// in val.
327static void getFieldComponent( SimObject* object, StringTableEntry field, const char* array, StringTableEntry subField, char val[] )
328{
329 const char* prevVal = NULL;
330
331 // Grab value from object.
332 if( object && field )
333 prevVal = object->getDataField( field, array );
334
335 // Otherwise, grab from the string stack. The value coming in will always
336 // be a string because that is how multicomponent variables are handled.
337 else
338 prevVal = STR.getStringValue();
339
340 // Make sure we got a value.
341 if ( prevVal && *prevVal )
342 {
343 static const StringTableEntry xyzw[] =
344 {
345 StringTable->insert( "x" ),
346 StringTable->insert( "y" ),
347 StringTable->insert( "z" ),
348 StringTable->insert( "w" )
349 };
350
351 static const StringTableEntry rgba[] =
352 {
353 StringTable->insert( "r" ),
354 StringTable->insert( "g" ),
355 StringTable->insert( "b" ),
356 StringTable->insert( "a" )
357 };
358
359 // Translate xyzw and rgba into the indexed component
360 // of the variable or field.
361 if ( subField == xyzw[0] || subField == rgba[0] )
362 dStrcpy( val, StringUnit::getUnit( prevVal, 0, " \t\n") );
363
364 else if ( subField == xyzw[1] || subField == rgba[1] )
365 dStrcpy( val, StringUnit::getUnit( prevVal, 1, " \t\n") );
366
367 else if ( subField == xyzw[2] || subField == rgba[2] )
368 dStrcpy( val, StringUnit::getUnit( prevVal, 2, " \t\n") );
369
370 else if ( subField == xyzw[3] || subField == rgba[3] )
371 dStrcpy( val, StringUnit::getUnit( prevVal, 3, " \t\n") );
372
373 else
374 val[0] = 0;
375 }
376 else
377 val[0] = 0;
378}
379
380// Sets a component of an object's field value based on the sub field. 'x' will
381// set the first field, 'y' the second, and 'z' the third.

Callers 1

execMethod · 0.85

Calls 5

dStrcpyFunction · 0.85
getUnitFunction · 0.85
getDataFieldMethod · 0.80
getStringValueMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected