# HG changeset patch # User Adam Kaminski # Date 1638123584 18000 # Sun Nov 28 13:19:44 2021 -0500 # Node ID 4c88126d213948cea4f17b05b8bf0f8e6742efb2 # Parent c687969ea3b3ec70abd2f315d78b819d515837b7 Added optimizations to the "MovePlayer" server command: - If a player's velocity is zero, then it won't be sent with the command and the clients can set it to zero on their own ends. - A player's crouching status is no longer sent as a separate byte, but rather as another bit with the flags. diff -r c687969ea3b3 -r 4c88126d2139 protocolspec/spec.players.txt --- a/protocolspec/spec.players.txt Sun Nov 28 10:16:12 2021 -0500 +++ b/protocolspec/spec.players.txt Sun Nov 28 13:19:44 2021 -0500 @@ -34,10 +34,14 @@ Fixed y AproxFixed z Angle angle + EndIf + + # [AK] The server should only send the player's velocity when it's not zero. + If ((flags & PLAYER_VISIBLE) && (flags & PLAYER_MOVING)) + CheckFunction IsVisibleAndMoving AproxFixed velx AproxFixed vely AproxFixed velz - Bool isCrouching EndIf EndCommand diff -r c687969ea3b3 -r 4c88126d2139 src/cl_main.cpp --- a/src/cl_main.cpp Sun Nov 28 10:16:12 2021 -0500 +++ b/src/cl_main.cpp Sun Nov 28 13:19:44 2021 -0500 @@ -3809,12 +3809,20 @@ player->mo->angle = angle; // Set the player's XYZ momentum. - player->mo->velx = velx; - player->mo->vely = vely; - player->mo->velz = velz; + // [AK] If the server didn't tell us that this player is moving, set their velocity to zero. + if ( IsVisibleAndMoving() ) + { + player->mo->velx = velx; + player->mo->vely = vely; + player->mo->velz = velz; + } + else + { + player->mo->velx = player->mo->vely = player->mo->velz = 0; + } // Is the player crouching? - player->crouchdir = ( isCrouching ) ? 1 : -1; + player->crouchdir = ( flags & PLAYER_CROUCHING ) ? 1 : -1; if (( player->crouchdir == 1 ) && ( player->crouchfactor < FRACUNIT ) && diff -r c687969ea3b3 -r 4c88126d2139 src/network.h --- a/src/network.h Sun Nov 28 10:16:12 2021 -0500 +++ b/src/network.h Sun Nov 28 13:19:44 2021 -0500 @@ -86,8 +86,10 @@ enum { PLAYER_VISIBLE = 1 << 0, - PLAYER_ATTACK = 1 << 1, + PLAYER_ATTACK = 1 << 1, PLAYER_ALTATTACK = 1 << 2, + PLAYER_CROUCHING = 1 << 3, + PLAYER_MOVING = 1 << 4, }; /* [BB] This is not used anywhere anymore. diff -r c687969ea3b3 -r 4c88126d2139 src/sv_commands.cpp --- a/src/sv_commands.cpp Sun Nov 28 10:16:12 2021 -0500 +++ b/src/sv_commands.cpp Sun Nov 28 13:19:44 2021 -0500 @@ -291,20 +291,30 @@ // void SERVERCOMMANDS_MovePlayer( ULONG ulPlayer, ULONG ulPlayerExtra, ServerCommandFlags flags ) { - ULONG ulPlayerAttackFlags = 0; + ULONG ulPlayerFlags = 0; + ULONG ulBitShift = FRACBITS; if ( PLAYER_IsValidPlayerWithMo( ulPlayer ) == false ) return; // [BB] Check if ulPlayer is pressing any attack buttons. if ( players[ulPlayer].cmd.ucmd.buttons & BT_ATTACK ) - ulPlayerAttackFlags |= PLAYER_ATTACK; + ulPlayerFlags |= PLAYER_ATTACK; if ( players[ulPlayer].cmd.ucmd.buttons & BT_ALTATTACK ) - ulPlayerAttackFlags |= PLAYER_ALTATTACK; + ulPlayerFlags |= PLAYER_ALTATTACK; + + // [AK] Check if the player is crouching. + if ( players[ulPlayer].crouchdir >= 0 ) + ulPlayerFlags |= PLAYER_CROUCHING; + + // [AK] Ideally, we should only need to send the player's velocity if it's not zero. + // Otherwise, the client can set their velocity to zero by themselves. + if (( players[ulPlayer].mo->velx ) || ( players[ulPlayer].mo->vely ) || ( players[ulPlayer].mo->velz )) + ulPlayerFlags |= PLAYER_MOVING; ServerCommands::MovePlayer fullCommand; fullCommand.SetPlayer ( &players[ulPlayer] ); - fullCommand.SetFlags( ulPlayerAttackFlags | PLAYER_VISIBLE ); + fullCommand.SetFlags( ulPlayerFlags | PLAYER_VISIBLE ); fullCommand.SetX( players[ulPlayer].mo->x ); fullCommand.SetY( players[ulPlayer].mo->y ); fullCommand.SetZ( players[ulPlayer].mo->z ); @@ -312,10 +322,9 @@ fullCommand.SetVelx( players[ulPlayer].mo->velx ); fullCommand.SetVely( players[ulPlayer].mo->vely ); fullCommand.SetVelz( players[ulPlayer].mo->velz ); - fullCommand.SetIsCrouching(( players[ulPlayer].crouchdir >= 0 ) ? true : false ); ServerCommands::MovePlayer stubCommand = fullCommand; - stubCommand.SetFlags( ulPlayerAttackFlags ); + stubCommand.SetFlags( ulPlayerFlags ); for ( ClientIterator it ( ulPlayerExtra, flags ); it.notAtEnd(); ++it ) {