| 614 | #define FLOAT_INT_BIAS (1<<(FLOAT_INT_BITS-1)) |
| 615 | |
| 616 | void MSG_WriteField (msg_t *msg, const int *toF, const netField_t *field) |
| 617 | { |
| 618 | int trunc; |
| 619 | float fullFloat; |
| 620 | |
| 621 | if ( field->bits == -1) |
| 622 | { // a -1 in the bits field means it's a float that's always between -1 and 1 |
| 623 | int temp = *(float *)toF * 32767; |
| 624 | MSG_WriteBits( msg, temp, -16 ); |
| 625 | } |
| 626 | else |
| 627 | if ( field->bits == 0 ) { |
| 628 | // float |
| 629 | fullFloat = *(float *)toF; |
| 630 | trunc = (int)fullFloat; |
| 631 | |
| 632 | if (fullFloat == 0.0f) { |
| 633 | MSG_WriteBits( msg, 0, 1 ); //it's a zero |
| 634 | } else { |
| 635 | MSG_WriteBits( msg, 1, 1 ); //not a zero |
| 636 | if ( trunc == fullFloat && trunc + FLOAT_INT_BIAS >= 0 && |
| 637 | trunc + FLOAT_INT_BIAS < ( 1 << FLOAT_INT_BITS ) ) { |
| 638 | // send as small integer |
| 639 | MSG_WriteBits( msg, 0, 1 ); |
| 640 | MSG_WriteBits( msg, trunc + FLOAT_INT_BIAS, FLOAT_INT_BITS ); |
| 641 | } else { |
| 642 | // send as full floating point value |
| 643 | MSG_WriteBits( msg, 1, 1 ); |
| 644 | MSG_WriteBits( msg, *toF, 32 ); |
| 645 | } |
| 646 | } |
| 647 | } else { |
| 648 | if (*toF == 0) { |
| 649 | MSG_WriteBits( msg, 0, 1 ); //it's a zero |
| 650 | } else { |
| 651 | MSG_WriteBits( msg, 1, 1 ); //not a zero |
| 652 | // integer |
| 653 | MSG_WriteBits( msg, *toF, field->bits ); |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | void MSG_ReadField (msg_t *msg, int *toF, const netField_t *field, int print) |
| 659 | { |
no test coverage detected