| 1318 | } |
| 1319 | |
| 1320 | std::optional<float> GetUvScaleFromAnnotation( const char* paramName, const Tr2EffectParameterAnnotation& annotation, const Tr2ConstantEffectParameterStructureList& constParams ) |
| 1321 | { |
| 1322 | if( annotation.type == Tr2EffectParameterAnnotation::FLOAT ) |
| 1323 | { |
| 1324 | return { annotation.floatValue }; |
| 1325 | } |
| 1326 | else if( annotation.type == Tr2EffectParameterAnnotation::STRING ) |
| 1327 | { |
| 1328 | std::string expr( annotation.stringValue ); |
| 1329 | for( size_t i = 0; i < expr.length(); ++i ) |
| 1330 | { |
| 1331 | auto& c = expr[i]; |
| 1332 | if( c == '.' ) |
| 1333 | { |
| 1334 | bool isId = false; |
| 1335 | for( size_t j = i; j > 0; --j ) |
| 1336 | { |
| 1337 | auto pc = expr[j - 1]; |
| 1338 | if( isdigit( pc ) ) |
| 1339 | { |
| 1340 | continue; |
| 1341 | } |
| 1342 | if( isalpha( pc ) ) |
| 1343 | { |
| 1344 | isId = true; |
| 1345 | break; |
| 1346 | } |
| 1347 | break; |
| 1348 | } |
| 1349 | if( isId ) |
| 1350 | { |
| 1351 | c = '_'; |
| 1352 | } |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | VariableFactoryArguments factoryArgs = { &constParams, false }; |
| 1357 | CcpParser::Externals externals; |
| 1358 | externals.variableFactory = { &GetParserVariable, &factoryArgs }; |
| 1359 | CcpParser::Program program; |
| 1360 | auto parsed = CcpParser::Parse( expr.c_str(), externals, program ); |
| 1361 | if( !parsed ) |
| 1362 | { |
| 1363 | if( !factoryArgs.hasInvalidVariable ) |
| 1364 | { |
| 1365 | CCP_LOGWARN( "Invalid LodUvScale annotation for effect parameter \"%s\": %s", paramName, ToString( parsed, expr.c_str() ).c_str() ); |
| 1366 | } |
| 1367 | return std::nullopt; |
| 1368 | } |
| 1369 | void* buffers[] = { (void*)&constParams[0] }; |
| 1370 | std::unique_ptr<uint8_t[]> tempArena( new uint8_t[program.GetTempArenaSize()] ); |
| 1371 | return program.Eval( buffers, tempArena.get() ); |
| 1372 | } |
| 1373 | return std::nullopt; |
| 1374 | } |
| 1375 | |
| 1376 | bool ExtractLodingAnnotations( std::array<float, ITriEffectTextureParameter::UV_SET_MAX_COUNT>& densityScale, const char* name, const Tr2EffectAnnotationMap& effectAnnotations, const Tr2ConstantEffectParameterStructureList& constParams ) |
| 1377 | { |
no test coverage detected