============ idProgram::AllocDef ============ */
| 1278 | ============ |
| 1279 | */ |
| 1280 | idVarDef *idProgram::AllocDef( idTypeDef *type, const char *name, idVarDef *scope, bool constant ) { |
| 1281 | idVarDef *def; |
| 1282 | idStr element; |
| 1283 | idVarDef *def_x; |
| 1284 | idVarDef *def_y; |
| 1285 | idVarDef *def_z; |
| 1286 | |
| 1287 | // allocate a new def |
| 1288 | def = AllocVarDef(type, name, scope); |
| 1289 | |
| 1290 | if ( ( type->Type() == ev_vector ) || ( ( type->Type() == ev_field ) && ( type->FieldType()->Type() == ev_vector ) ) ) { |
| 1291 | // |
| 1292 | // vector |
| 1293 | // |
| 1294 | if ( !strcmp( name, RESULT_STRING ) ) { |
| 1295 | // <RESULT> vector defs don't need the _x, _y and _z components |
| 1296 | assert( scope->Type() == ev_function ); |
| 1297 | def->value.stackOffset = scope->value.functionPtr->locals; |
| 1298 | def->initialized = idVarDef::stackVariable; |
| 1299 | scope->value.functionPtr->locals += type->Size(); |
| 1300 | } else if ( scope->TypeDef()->Inherits( &type_object ) ) { |
| 1301 | idTypeDef newtype( ev_field, NULL, "float field", 0, &type_float ); |
| 1302 | idTypeDef *ftype = GetType( newtype, true ); |
| 1303 | |
| 1304 | // set the value to the variable's position in the object |
| 1305 | def->value.ptrOffset = scope->TypeDef()->Size(); |
| 1306 | |
| 1307 | // make automatic defs for the vectors elements |
| 1308 | // origin can be accessed as origin_x, origin_y, and origin_z |
| 1309 | sprintf( element, "%s_x", def->Name() ); |
| 1310 | def_x = AllocDef( ftype, element, scope, constant ); |
| 1311 | |
| 1312 | sprintf( element, "%s_y", def->Name() ); |
| 1313 | def_y = AllocDef( ftype, element, scope, constant ); |
| 1314 | def_y->value.ptrOffset = def_x->value.ptrOffset + sizeof(float); |
| 1315 | |
| 1316 | sprintf( element, "%s_z", def->Name() ); |
| 1317 | def_z = AllocDef( ftype, element, scope, constant ); |
| 1318 | def_z->value.ptrOffset = def_y->value.ptrOffset + sizeof(float); |
| 1319 | } else { |
| 1320 | idTypeDef newtype( ev_float, &def_float, "vector float", 0, NULL ); |
| 1321 | idTypeDef *ftype = GetType( newtype, true ); |
| 1322 | |
| 1323 | // make automatic defs for the vectors elements |
| 1324 | // origin can be accessed as origin_x, origin_y, and origin_z |
| 1325 | sprintf( element, "%s_x", def->Name() ); |
| 1326 | def_x = AllocVarDef( ftype, element, scope ); |
| 1327 | |
| 1328 | sprintf( element, "%s_y", def->Name() ); |
| 1329 | def_y = AllocVarDef( ftype, element, scope ); |
| 1330 | |
| 1331 | sprintf( element, "%s_z", def->Name() ); |
| 1332 | def_z = AllocVarDef( ftype, element, scope ); |
| 1333 | |
| 1334 | // get the memory for the full vector and point the _x, _y and _z |
| 1335 | // defs at the vector member offsets |
| 1336 | if ( scope->Type() == ev_function ) { |
| 1337 | // vector on stack |
no test coverage detected