=================== CL_WritePacket Create and send the command packet to the server Including both the reliable commands and the usercmds During normal gameplay, a client packet will contain something like: 4 sequence number 2 qport 4 serverid 4 acknowledged sequence number 4 clc.serverCommandSequence 1 clc_move or clc_moveNoDelta 1 command count
| 811 | =================== |
| 812 | */ |
| 813 | void CL_WritePacket( void ) { |
| 814 | msg_t buf; |
| 815 | byte data[MAX_MSGLEN]; |
| 816 | int i, j; |
| 817 | usercmd_t *cmd, *oldcmd; |
| 818 | usercmd_t nullcmd; |
| 819 | int packetNum; |
| 820 | int oldPacketNum; |
| 821 | int count; |
| 822 | |
| 823 | // don't send anything if playing back a demo |
| 824 | // if ( cls.state == CA_CINEMATIC ) |
| 825 | if ( cls.state == CA_CINEMATIC || CL_IsRunningInGameCinematic()) |
| 826 | { |
| 827 | return; |
| 828 | } |
| 829 | |
| 830 | MSG_Init( &buf, data, sizeof(data) ); |
| 831 | |
| 832 | // write any unacknowledged clientCommands |
| 833 | for ( i = clc.reliableAcknowledge + 1 ; i <= clc.reliableSequence ; i++ ) { |
| 834 | MSG_WriteByte( &buf, clc_clientCommand ); |
| 835 | MSG_WriteLong( &buf, i ); |
| 836 | MSG_WriteString( &buf, clc.reliableCommands[ i & (MAX_RELIABLE_COMMANDS-1) ] ); |
| 837 | } |
| 838 | |
| 839 | // we want to send all the usercmds that were generated in the last |
| 840 | // few packet, so even if a couple packets are dropped in a row, |
| 841 | // all the cmds will make it to the server |
| 842 | if ( cl_packetdup->integer < 0 ) { |
| 843 | Cvar_Set( "cl_packetdup", "0" ); |
| 844 | } else if ( cl_packetdup->integer > 5 ) { |
| 845 | Cvar_Set( "cl_packetdup", "5" ); |
| 846 | } |
| 847 | oldPacketNum = (clc.netchan.outgoingSequence - 1 - cl_packetdup->integer) & PACKET_MASK; |
| 848 | count = cl.cmdNumber - cl.packetCmdNumber[ oldPacketNum ]; |
| 849 | if ( count > MAX_PACKET_USERCMDS ) { |
| 850 | count = MAX_PACKET_USERCMDS; |
| 851 | Com_Printf("MAX_PACKET_USERCMDS\n"); |
| 852 | } |
| 853 | if ( count >= 1 ) { |
| 854 | // begin a client move command |
| 855 | MSG_WriteByte (&buf, clc_move); |
| 856 | |
| 857 | // write the last reliable message we received |
| 858 | MSG_WriteLong( &buf, clc.serverCommandSequence ); |
| 859 | |
| 860 | // write the current serverId so the server |
| 861 | // can tell if this is from the current gameState |
| 862 | MSG_WriteLong (&buf, cl.serverId); |
| 863 | |
| 864 | // write the current time |
| 865 | MSG_WriteLong (&buf, cls.realtime); |
| 866 | |
| 867 | // let the server know what the last messagenum we |
| 868 | // got was, so the next message can be delta compressed |
| 869 | // FIXME: this could just be a bit flag, with the message implicit |
| 870 | // from the unreliable ack of the netchan |
no test coverage detected