IOQ3 commit 2086

This commit is contained in:
Richard Allen 2011-07-18 17:17:59 +00:00
parent 7b29f92e36
commit 54cfc7d84b
3 changed files with 51 additions and 18 deletions

View file

@ -140,23 +140,28 @@ void MSG_WriteBits( msg_t *msg, int value, int bits ) {
bits = -bits; bits = -bits;
} }
if (msg->oob) { if (msg->oob) {
if (bits==8) { if(bits==8)
{
msg->data[msg->cursize] = value; msg->data[msg->cursize] = value;
msg->cursize += 1; msg->cursize += 1;
msg->bit += 8; msg->bit += 8;
} else if (bits==16) { }
unsigned short *sp = (unsigned short *)&msg->data[msg->cursize]; else if(bits==16)
*sp = LittleShort(value); {
short temp = value;
CopyLittleShort(&msg->data[msg->cursize], &temp);
msg->cursize += 2; msg->cursize += 2;
msg->bit += 16; msg->bit += 16;
} else if (bits==32) { }
unsigned int *ip = (unsigned int *)&msg->data[msg->cursize]; else if(bits==32)
*ip = LittleLong(value); {
CopyLittleLong(&msg->data[msg->cursize], &value);
msg->cursize += 4; msg->cursize += 4;
msg->bit += 32; msg->bit += 32;
} else {
Com_Error(ERR_DROP, "can't read %d bits", bits);
} }
else
Com_Error(ERR_DROP, "can't write %d bits", bits);
} else { } else {
// fp = fopen("c:\\netchan.bin", "a"); // fp = fopen("c:\\netchan.bin", "a");
value &= (0xffffffff>>(32-bits)); value &= (0xffffffff>>(32-bits));
@ -198,23 +203,29 @@ int MSG_ReadBits( msg_t *msg, int bits ) {
} }
if (msg->oob) { if (msg->oob) {
if (bits==8) { if(bits==8)
{
value = msg->data[msg->readcount]; value = msg->data[msg->readcount];
msg->readcount += 1; msg->readcount += 1;
msg->bit += 8; msg->bit += 8;
} else if (bits==16) { }
unsigned short *sp = (unsigned short *)&msg->data[msg->readcount]; else if(bits==16)
value = LittleShort(*sp); {
short temp;
CopyLittleShort(&temp, &msg->data[msg->readcount]);
value = temp;
msg->readcount += 2; msg->readcount += 2;
msg->bit += 16; msg->bit += 16;
} else if (bits==32) { }
unsigned int *ip = (unsigned int *)&msg->data[msg->readcount]; else if(bits==32)
value = LittleLong(*ip); {
CopyLittleLong(&value, &msg->data[msg->readcount]);
msg->readcount += 4; msg->readcount += 4;
msg->bit += 32; msg->bit += 32;
} else {
Com_Error(ERR_DROP, "can't read %d bits", bits);
} }
else
Com_Error(ERR_DROP, "can't read %d bits", bits);
} else { } else {
nbits = 0; nbits = 0;
if (bits&7) { if (bits&7) {

View file

@ -348,6 +348,8 @@ float FloatSwap (const float *f);
#error "Endianness defined as both big and little" #error "Endianness defined as both big and little"
#elif defined( Q3_BIG_ENDIAN ) #elif defined( Q3_BIG_ENDIAN )
#define CopyLittleShort(dest, src) CopyShortSwap(dest, src)
#define CopyLittleLong(dest, src) CopyLongSwap(dest, src)
#define LittleShort(x) ShortSwap(x) #define LittleShort(x) ShortSwap(x)
#define LittleLong(x) LongSwap(x) #define LittleLong(x) LongSwap(x)
#define LittleFloat(x) FloatSwap(&x) #define LittleFloat(x) FloatSwap(&x)
@ -357,6 +359,8 @@ float FloatSwap (const float *f);
#elif defined( Q3_LITTLE_ENDIAN ) #elif defined( Q3_LITTLE_ENDIAN )
#define CopyLittleShort(dest, src) Com_Memcpy(dest, src, 2)
#define CopyLittleLong(dest, src) Com_Memcpy(dest, src, 4)
#define LittleShort #define LittleShort
#define LittleLong #define LittleLong
#define LittleFloat #define LittleFloat

View file

@ -129,6 +129,24 @@ float BigFloat (const float *l) {return _BigFloat(l);}
float LittleFloat (const float *l) {return _LittleFloat(l);} float LittleFloat (const float *l) {return _LittleFloat(l);}
*/ */
void CopyShortSwap(void *dest, void *src)
{
byte *to = dest, *from = src;
to[0] = from[1];
to[1] = from[0];
}
void CopyLongSwap(void *dest, void *src)
{
byte *to = dest, *from = src;
to[0] = from[3];
to[1] = from[2];
to[2] = from[1];
to[3] = from[0];
}
short ShortSwap (short l) short ShortSwap (short l)
{ {
byte b1,b2; byte b1,b2;