void SZ_Print (sizebuf_t *buf, char *data) { int len; len = strlen(data) + 1; if (!buf->cursize || buf->data[buf->cursize-1]) memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0 else memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0 }
/* ============ MSG_WriteRawBytes ============ */ static void MSG_WriteRawBytes( sizebuf_t *msg, int value, int bits ) { qbyte *buf; if( bits <= 8 ) { buf = SZ_GetSpace( msg, 1 ); buf[0] = value; } else if( bits <= 16 ) { buf = SZ_GetSpace( msg, 2 ); buf[0] = value & 0xFF; buf[1] = value >> 8; }
void MSG_WriteFloat(sizebuf_t *sb, float f) { //Unfortunately I'm not confident that the same tricks work with //floating point numbers... union floatlong { float f; int l; }; #if(defined(_MSC_VER) || defined(__BORLANDC__)) union floatlong ret; #endif char * buf; buf = (byte *)SZ_GetSpace (sb, 4); /*cast the float to the given union, pull out that union's int member //hope there aren't any implied conversions. This worked in mingw, //but it's possible that there could be some compiler dependancy... //There are. */ #if(defined(_MSC_VER) || defined(__BORLANDC__)) ret.f = f; *(int *)buf = hosttole32(ret.l); #else *(int *)buf = hosttole32( ((union floatlong)f).l ); #endif }
void SZ_Print (sizebuf_t *buf, char *data) { int len; len = (int)strlen(data)+1; if (buf->cursize) { if (buf->data[buf->cursize-1]) memcpy ((byte *)SZ_GetSpace(buf, len),data,len); /* no trailing 0 */ else memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); /* write over trailing 0 */ } else memcpy ((byte *)SZ_GetSpace(buf, len),data,len); }
void MSG_WriteByte (sizebuf_t *sb, int c) { byte *buf; #ifdef PARANOID if (c < 0 || c > 255) Com_Error(ERR_FATAL, "MSG_WriteByte: range error"); #endif if (buf = SZ_GetSpace(sb, 1)) // jit buf[0] = c; }
void MSG_WriteShort (sizebuf_t *sb, int c) { byte *buf; #ifdef PARANOID if (c < ((short)0x8000) || c > (short)0x7fff) Com_Error (ERR_FATAL, "MSG_WriteShort: range error"); #endif if (buf = SZ_GetSpace(sb, 2)) // jit { buf[0] = c & 0xff; buf[1] = c >> 8; }
void MSG_WriteByte(sizebuf_t *sb, unsigned int c) { byte *buf; buf = (byte *)SZ_GetSpace (sb, 1); buf[0] = (byte)c; }
void MSG_WriteLong (sizebuf_t *sb, uint32 c) { byte *buf; buf = (byte *)SZ_GetSpace (sb, 4); *(ulong *)buf = hosttole32(c); }
void SZ_Write (sizebuf_t *buf, const void *data, int length) { memcpy (SZ_GetSpace(buf,length),data,length); }
void MSG_WriteByte_C(sizebuf_t *sb, byte c) { byte *buf; buf = (byte *)SZ_GetSpace (sb, 1); buf[0] = c; }
/* ================= CL_SendBatchedCmd ================= */ static void CL_SendBatchedCmd( void ) { int i, j, seq, bits; int numCmds, numDups; int totalCmds, totalMsec; size_t cursize; usercmd_t *cmd, *oldcmd; client_history_t *history, *oldest; byte *patch; // see if we are ready to send this packet if( !ready_to_send() ) { return; } // archive this packet seq = cls.netchan->outgoing_sequence; history = &cl.history[seq & CMD_MASK]; history->cmdNumber = cl.cmdNumber; history->sent = cls.realtime; // for ping calculation history->rcvd = 0; cl.lastTransmitTime = cls.realtime; cl.lastTransmitCmdNumber = cl.cmdNumber; cl.lastTransmitCmdNumberReal = cl.cmdNumber; // begin a client move command patch = SZ_GetSpace( &msg_write, 1 ); // let the server know what the last frame we // got was, so the next message can be delta compressed if( cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/ ) { *patch = clc_move_nodelta; // no compression } else { *patch = clc_move_batched; MSG_WriteLong( cl.frame.number ); } Cvar_ClampInteger( cl_packetdup, 0, MAX_PACKET_FRAMES - 1 ); numDups = cl_packetdup->integer; *patch |= numDups << SVCMD_BITS; // send lightlevel MSG_WriteByte( cl.lightlevel ); // send this and the previous cmds in the message, so // if the last packet was dropped, it can be recovered oldcmd = NULL; totalCmds = 0; totalMsec = 0; for( i = seq - numDups; i <= seq; i++ ) { oldest = &cl.history[( i - 1 ) & CMD_MASK]; history = &cl.history[i & CMD_MASK]; numCmds = history->cmdNumber - oldest->cmdNumber; if( numCmds >= MAX_PACKET_USERCMDS ) { Com_WPrintf( "%s: MAX_PACKET_USERCMDS exceeded\n", __func__ ); SZ_Clear( &msg_write ); break; } totalCmds += numCmds; MSG_WriteBits( numCmds, 5 ); for( j = oldest->cmdNumber + 1; j <= history->cmdNumber; j++ ) { cmd = &cl.cmds[j & CMD_MASK]; totalMsec += cmd->msec; bits = MSG_WriteDeltaUsercmd_Enhanced( oldcmd, cmd, cls.protocolVersion ); #ifdef _DEBUG if( cl_showpackets->integer == 3 ) { MSG_ShowDeltaUsercmdBits_Enhanced( bits ); } #endif oldcmd = cmd; } } P_FRAMES++; // // deliver the message // cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data, 1 ); #ifdef _DEBUG if( cl_showpackets->integer == 1 ) { Com_Printf( "%"PRIz"(%i) ", cursize, totalCmds ); } else if( cl_showpackets->integer == 2 ) { Com_Printf( "%"PRIz"(%i) ", cursize, totalMsec ); } else if( cl_showpackets->integer == 3 ) { Com_Printf( " | " ); } #endif SZ_Clear( &msg_write ); }
void MSG_WriteShort(sizebuf_t *sb, int c) { byte *buf; buf = (byte *)SZ_GetSpace (sb, 2); *(word *)buf = hosttole16((word)c); }
/* ================= CL_SendDefaultCmd ================= */ static void CL_SendDefaultCmd( void ) { size_t cursize, checksumIndex; usercmd_t *cmd, *oldcmd; client_history_t *history; // archive this packet history = &cl.history[cls.netchan->outgoing_sequence & CMD_MASK]; history->cmdNumber = cl.cmdNumber; history->sent = cls.realtime; // for ping calculation history->rcvd = 0; cl.lastTransmitCmdNumber = cl.cmdNumber; // see if we are ready to send this packet if( !ready_to_send_hacked() ) { cls.netchan->outgoing_sequence++; // just drop the packet return; } cl.lastTransmitTime = cls.realtime; cl.lastTransmitCmdNumberReal = cl.cmdNumber; // begin a client move command MSG_WriteByte( clc_move ); // save the position for a checksum byte checksumIndex = 0; if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) { checksumIndex = msg_write.cursize; SZ_GetSpace( &msg_write, 1 ); } // let the server know what the last frame we // got was, so the next message can be delta compressed if( cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/ ) { MSG_WriteLong( -1 ); // no compression } else { MSG_WriteLong( cl.frame.number ); } // send this and the previous cmds in the message, so // if the last packet was dropped, it can be recovered cmd = &cl.cmds[( cl.cmdNumber - 2 ) & CMD_MASK]; MSG_WriteDeltaUsercmd( NULL, cmd, cls.protocolVersion ); MSG_WriteByte( cl.lightlevel ); oldcmd = cmd; cmd = &cl.cmds[( cl.cmdNumber - 1 ) & CMD_MASK]; MSG_WriteDeltaUsercmd( oldcmd, cmd, cls.protocolVersion ); MSG_WriteByte( cl.lightlevel ); oldcmd = cmd; cmd = &cl.cmds[cl.cmdNumber & CMD_MASK]; MSG_WriteDeltaUsercmd( oldcmd, cmd, cls.protocolVersion ); MSG_WriteByte( cl.lightlevel ); if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) { // calculate a checksum over the move commands msg_write.data[checksumIndex] = COM_BlockSequenceCRCByte( msg_write.data + checksumIndex + 1, msg_write.cursize - checksumIndex - 1, cls.netchan->outgoing_sequence ); } P_FRAMES++; // // deliver the message // cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data, 1 ); #ifdef _DEBUG if( cl_showpackets->integer ) { Com_Printf( "%"PRIz" ", cursize ); } #endif SZ_Clear( &msg_write ); }
void MSG_WriteShort_S(sizebuf_t *sb, unsigned short int c) { byte *buf; buf = (byte *)SZ_GetSpace (sb, 2); *(word *)buf = hosttole16(c); }
void MSG_WriteChar_C(sizebuf_t *sb, unsigned char c) { byte *buf; buf = (byte *)SZ_GetSpace(sb, 1); buf[0] = c; }
void MSG_WriteWord_S(sizebuf_t *sb, word c) { byte *buf; buf = (byte *)SZ_GetSpace (sb, 2); *(word *)buf = hosttole16(c); }
void MSG_WriteWord(sizebuf_t *sb, unsigned int c) { byte *buf; buf = (byte *)SZ_GetSpace (sb, 2); *(word *)buf = hosttole16((word)c); }