diff options
author | Tim Angus <tim@ngus.net> | 2009-10-03 12:31:59 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:16:03 +0000 |
commit | 304d4258d3a49488f570b8ad71931faa7e5d40ba (patch) | |
tree | bf9ec15bd9154305ff9fab2943b3daf25024f8a5 /src/qcommon/msg.c | |
parent | 6e90e4e7861f5cb354487d1fe0f1fd06c385308e (diff) |
* Merge ioq3-r1498, by popular demand
Diffstat (limited to 'src/qcommon/msg.c')
-rw-r--r-- | src/qcommon/msg.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/qcommon/msg.c b/src/qcommon/msg.c index 8be19aca..34434d15 100644 --- a/src/qcommon/msg.c +++ b/src/qcommon/msg.c @@ -292,13 +292,9 @@ void MSG_WriteLong( msg_t *sb, int c ) { } void MSG_WriteFloat( msg_t *sb, float f ) { - union { - float f; - int l; - } dat; - + floatint_t dat; dat.f = f; - MSG_WriteBits( sb, dat.l, 32 ); + MSG_WriteBits( sb, dat.i, 32 ); } void MSG_WriteString( msg_t *sb, const char *s ) { @@ -424,13 +420,9 @@ int MSG_ReadLong( msg_t *msg ) { } float MSG_ReadFloat( msg_t *msg ) { - union { - byte b[4]; - float f; - int l; - } dat; + floatint_t dat; - dat.l = MSG_ReadBits( msg, 32 ); + dat.i = MSG_ReadBits( msg, 32 ); if ( msg->readcount > msg->cursize ) { dat.f = -1; } @@ -552,20 +544,22 @@ int MSG_ReadDelta( msg_t *msg, int oldV, int bits ) { } void MSG_WriteDeltaFloat( msg_t *msg, float oldV, float newV ) { + floatint_t fi; if ( oldV == newV ) { MSG_WriteBits( msg, 0, 1 ); return; } + fi.f = newV; MSG_WriteBits( msg, 1, 1 ); - MSG_WriteBits( msg, *(int *)&newV, 32 ); + MSG_WriteBits( msg, fi.i, 32 ); } float MSG_ReadDeltaFloat( msg_t *msg, float oldV ) { if ( MSG_ReadBits( msg, 1 ) ) { - float newV; + floatint_t fi; - *(int *)&newV = MSG_ReadBits( msg, 32 ); - return newV; + fi.i = MSG_ReadBits( msg, 32 ); + return fi.f; } return oldV; } @@ -606,20 +600,22 @@ int MSG_ReadDeltaKey( msg_t *msg, int key, int oldV, int bits ) { } void MSG_WriteDeltaKeyFloat( msg_t *msg, int key, float oldV, float newV ) { + floatint_t fi; if ( oldV == newV ) { MSG_WriteBits( msg, 0, 1 ); return; } + fi.f = newV; MSG_WriteBits( msg, 1, 1 ); - MSG_WriteBits( msg, (*(int *)&newV) ^ key, 32 ); + MSG_WriteBits( msg, fi.i ^ key, 32 ); } float MSG_ReadDeltaKeyFloat( msg_t *msg, int key, float oldV ) { if ( MSG_ReadBits( msg, 1 ) ) { - float newV; + floatint_t fi; - *(int *)&newV = MSG_ReadBits( msg, 32 ) ^ key; - return newV; + fi.i = MSG_ReadBits( msg, 32 ) ^ key; + return fi.f; } return oldV; } |