/* ============ MSG_WriteBits ============ */ void MSG_WriteBits( sizebuf_t *msg, int value, int bits ) { int remaining; int i; byte *buf; if( msg->maxsize - msg->cursize < 4 ) { msg->overflowed = qtrue; return; } if( !bits || bits < -31 || bits > 32 ) { Com_Error( ERR_DROP, "MSG_WriteBits: bad bits %i", bits ); } if( bits < 0 ) { bits = -bits; } if( msg->uncompressed ) { if( bits <= 8 ) { buf = MSG_GetSpace( msg, 1 ); buf[0] = value; } else if( bits <= 16 ) { buf = MSG_GetSpace( msg, 2 ); buf[0] = value & 0xFF; buf[1] = value >> 8; } else if( bits <= 32 ) {
void MSG_WriteInt3( msg_t *msg, int c ) { qbyte *buf = ( qbyte* )MSG_GetSpace( msg, 3 ); buf[0] = ( qbyte )( c&0xff ); buf[1] = ( qbyte )( ( c>>8 )&0xff ); buf[2] = ( qbyte )( ( c>>16 )&0xff ); }
void MSG_WriteInt3( msg_t *msg, int c ) { uint8_t *buf = ( uint8_t* )MSG_GetSpace( msg, 3 ); buf[0] = ( uint8_t )( c&0xff ); buf[1] = ( uint8_t )( ( c>>8 )&0xff ); buf[2] = ( uint8_t )( ( c>>16 )&0xff ); }
void MSG_WriteLong( msg_t *msg, int c ) { uint8_t *buf = ( uint8_t* )MSG_GetSpace( msg, 4 ); buf[0] = ( uint8_t )( c&0xff ); buf[1] = ( uint8_t )( ( c>>8 )&0xff ); buf[2] = ( uint8_t )( ( c>>16 )&0xff ); buf[3] = ( uint8_t )( c>>24 ); }
void MSG_WriteShort( msg_t *msg, int c ) { unsigned short *sp = (unsigned short *)MSG_GetSpace( msg, 2 ); *sp = LittleShort( c ); }
void MSG_WriteByte( msg_t *msg, int c ) { qbyte *buf = ( qbyte* )MSG_GetSpace( msg, 1 ); buf[0] = ( qbyte )( c&0xff ); }
void MSG_WriteChar( msg_t *msg, int c ) { qbyte *buf = ( qbyte* )MSG_GetSpace( msg, 1 ); buf[0] = ( char )c; }
void MSG_CopyData( msg_t *buf, const void *data, size_t length ) { memcpy( MSG_GetSpace( buf, length ), data, length ); }
void MSG_WriteLong( msg_t *msg, int c ) { unsigned int *ip = (unsigned int *)MSG_GetSpace( msg, 4 ); *ip = LittleLong( c ); }
/* ============ MSG_WriteRawData ============ */ void MSG_WriteRawData( sizebuf_t *msg, const void *data, int length ) { if( length > 0 ) { memcpy( MSG_GetSpace( msg, length ), data, length ); } }
} if( bits < 0 ) { bits = -bits; } if( msg->uncompressed ) { if( bits <= 8 ) { buf = MSG_GetSpace( msg, 1 ); buf[0] = value; } else if( bits <= 16 ) { buf = MSG_GetSpace( msg, 2 ); buf[0] = value & 0xFF; buf[1] = value >> 8; } else if( bits <= 32 ) { buf = MSG_GetSpace( msg, 4 ); buf[0] = value & 0xFF; buf[1] = (value >> 8) & 0xFF; buf[2] = (value >> 16) & 0xFF; buf[3] = value >> 24; } return; } value &= 0xFFFFFFFFU >> (32 - bits); remaining = bits & 7; for( i=0; i<remaining ; i++ ) { if( !(msg->bit & 7) ) { msg->data[msg->bit >> 3] = 0; }
void MSG_WriteData( msg_t *buf, const void *data, int length ) { memcpy (MSG_GetSpace(buf,length),data,length); }
void MSG_WriteShort( msg_t *msg, int c ) { uint8_t *buf = ( uint8_t* )MSG_GetSpace( msg, 2 ); buf[0] = ( uint8_t )( c&0xff ); buf[1] = ( uint8_t )( ( c>>8 )&0xff ); }
void MSG_WriteByte( msg_t *msg, int c ) { uint8_t *buf = ( uint8_t* )MSG_GetSpace( msg, 1 ); buf[0] = ( uint8_t )( c&0xff ); }
void MSG_WriteChar( msg_t *msg, int c ) { uint8_t *buf = ( uint8_t* )MSG_GetSpace( msg, 1 ); buf[0] = ( char )c; }