| 1521 | |
| 1522 | |
| 1523 | bool GetStateValue( ParserState& state, ASTNode* value, const StateDescription& desc, void* dataBlob ) |
| 1524 | { |
| 1525 | BYTE* blob = reinterpret_cast<BYTE*>( dataBlob ); |
| 1526 | if( value == nullptr ) |
| 1527 | { |
| 1528 | return false; |
| 1529 | } |
| 1530 | Type expectedType, type; |
| 1531 | switch( desc.type ) |
| 1532 | { |
| 1533 | case SVT_BYTE: |
| 1534 | case SVT_DWORD: |
| 1535 | case SVT_BOOL: |
| 1536 | expectedType.FromTokenType( OP_INT ); |
| 1537 | break; |
| 1538 | case SVT_FLOAT: |
| 1539 | expectedType.FromTokenType( OP_FLOAT ); |
| 1540 | break; |
| 1541 | case SVT_COLOR: |
| 1542 | expectedType.FromTokenType( OP_FLOAT ); |
| 1543 | expectedType.width = 4; |
| 1544 | break; |
| 1545 | } |
| 1546 | ExpressionValue exprValue; |
| 1547 | |
| 1548 | if( value->GetNodeType() == NT_INLINE_CONSTRUCTOR ) |
| 1549 | { |
| 1550 | if( !EvaluateInitializer( state, value, expectedType, exprValue, desc.stateValues ) ) |
| 1551 | { |
| 1552 | return false; |
| 1553 | } |
| 1554 | } |
| 1555 | else |
| 1556 | { |
| 1557 | if( !EvaluateExpression( state, value, type, exprValue, desc.stateValues ) ) |
| 1558 | { |
| 1559 | return false; |
| 1560 | } |
| 1561 | if( expectedType != type ) |
| 1562 | { |
| 1563 | if( !CastExpressionValue( exprValue, type, expectedType ) ) |
| 1564 | { |
| 1565 | if( desc.type == SVT_COLOR ) |
| 1566 | { |
| 1567 | expectedType.builtInType = OP_INT; |
| 1568 | expectedType.width = 1; |
| 1569 | if( !CastExpressionValue( exprValue, type, expectedType ) ) |
| 1570 | { |
| 1571 | return false; |
| 1572 | } |
| 1573 | auto color = reinterpret_cast<float*>( blob + desc.offset ); |
| 1574 | CONST float f = 1.0f / 255.0f; |
| 1575 | auto dw = (uint32_t)exprValue[0].intValue; |
| 1576 | color[0] = f * (FLOAT)(unsigned char)( dw >> 16 ); |
| 1577 | color[1] = f * (FLOAT)(unsigned char)( dw >> 8 ); |
| 1578 | color[2] = f * (FLOAT)(unsigned char)( dw >> 0 ); |
| 1579 | color[3] = f * (FLOAT)(unsigned char)( dw >> 24 ); |
| 1580 | return true; |
no test coverage detected