# HG changeset patch # User Adam Kaminski # Date 1644162752 18000 # Sun Feb 06 10:52:32 2022 -0500 # Node ID 0a0876d37d4b0965cdd0f62e65ff0d4655ebba6c # Parent 45c98957c0eb2132ba08dbca7c98f04387e5ae1d Added optimizations to the "MovePlayer" server command: the velocity is now only sent if it's not zero per axis and the crouch status is now sent as another flag bit. diff -r 45c98957c0eb -r 0a0876d37d4b protocolspec/spec.players.txt --- a/protocolspec/spec.players.txt Sun Feb 06 10:38:24 2022 -0500 +++ b/protocolspec/spec.players.txt Sun Feb 06 10:52:32 2022 -0500 @@ -33,10 +33,22 @@ 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_SENDVELX)) + CheckFunction IsMovingX AproxFixed velx + EndIf + + If ((flags & PLAYER_VISIBLE) && (flags & PLAYER_SENDVELY)) + CheckFunction IsMovingY AproxFixed vely + EndIf + + If ((flags & PLAYER_VISIBLE) && (flags & PLAYER_SENDVELZ)) + CheckFunction IsMovingZ AproxFixed velz - Bool isCrouching EndIf EndCommand diff -r 45c98957c0eb -r 0a0876d37d4b src/cl_main.cpp --- a/src/cl_main.cpp Sun Feb 06 10:38:24 2022 -0500 +++ b/src/cl_main.cpp Sun Feb 06 10:52:32 2022 -0500 @@ -3806,12 +3806,13 @@ player->mo->angle = angle; // Set the player's XYZ momentum. - player->mo->velx = velx; - player->mo->vely = vely; - player->mo->velz = velz; + // [AK] Check if the server sent us this player's velocity on each axis. + player->mo->velx = IsMovingX() ? velx : 0; + player->mo->vely = IsMovingY() ? vely : 0; + player->mo->velz = IsMovingZ() ? 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 45c98957c0eb -r 0a0876d37d4b src/network.h --- a/src/network.h Sun Feb 06 10:38:24 2022 -0500 +++ b/src/network.h Sun Feb 06 10:52:32 2022 -0500 @@ -86,8 +86,12 @@ enum { PLAYER_VISIBLE = 1 << 0, - PLAYER_ATTACK = 1 << 1, + PLAYER_ATTACK = 1 << 1, PLAYER_ALTATTACK = 1 << 2, + PLAYER_CROUCHING = 1 << 3, + PLAYER_SENDVELX = 1 << 4, + PLAYER_SENDVELY = 1 << 5, + PLAYER_SENDVELZ = 1 << 6, }; /* [BB] This is not used anywhere anymore. diff -r 45c98957c0eb -r 0a0876d37d4b src/sv_commands.cpp --- a/src/sv_commands.cpp Sun Feb 06 10:38:24 2022 -0500 +++ b/src/sv_commands.cpp Sun Feb 06 10:52:32 2022 -0500 @@ -289,20 +289,33 @@ // void SERVERCOMMANDS_MovePlayer( ULONG ulPlayer, ULONG ulPlayerExtra, ServerCommandFlags flags ) { - ULONG ulPlayerAttackFlags = 0; + ULONG ulPlayerFlags = 0; 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 the velocity to zero by themselves. + if ( players[ulPlayer].mo->velx ) + ulPlayerFlags |= PLAYER_SENDVELX; + if ( players[ulPlayer].mo->vely ) + ulPlayerFlags |= PLAYER_SENDVELY; + if ( players[ulPlayer].mo->velz ) + ulPlayerFlags |= PLAYER_SENDVELZ; 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 ); @@ -310,10 +323,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 ) {