Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove buggy premature sendPlayerPos optimization #15532

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,49 +1371,21 @@ void Client::sendPlayerPos()
if (!player)
return;

// Save bandwidth by only updating position when
// player is not dead and something changed

// Don't send anything when player is dead:
// The server would ignore it anyways
if (m_activeobjects_received && player->isDead())
return;

ClientMap &map = m_env.getClientMap();
u8 camera_fov = std::fmin(255.0f, map.getCameraFov() * 80.0f);
u8 wanted_range = std::fmin(255.0f,
std::ceil(map.getWantedRange() * (1.0f / MAP_BLOCKSIZE)));

u32 keyPressed = player->control.getKeysPressed();
bool camera_inverted = m_camera->getCameraMode() == CAMERA_MODE_THIRD_FRONT;
f32 movement_speed = player->control.movement_speed;
f32 movement_dir = player->control.movement_direction;

if (
player->last_position == player->getPosition() &&
player->last_speed == player->getSpeed() &&
player->last_pitch == player->getPitch() &&
player->last_yaw == player->getYaw() &&
player->last_keyPressed == keyPressed &&
player->last_camera_fov == camera_fov &&
player->last_camera_inverted == camera_inverted &&
player->last_wanted_range == wanted_range &&
player->last_movement_speed == movement_speed &&
player->last_movement_dir == movement_dir)
return;

player->last_position = player->getPosition();
appgurueu marked this conversation as resolved.
Show resolved Hide resolved
player->last_speed = player->getSpeed();
player->last_pitch = player->getPitch();
player->last_yaw = player->getYaw();
player->last_keyPressed = keyPressed;
player->last_camera_fov = camera_fov;
player->last_camera_inverted = camera_inverted;
player->last_wanted_range = wanted_range;
player->last_movement_speed = movement_speed;
player->last_movement_dir = movement_dir;

NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4 + 1 + 1 + 1 + 4 + 4);

writePlayerPos(player, &map, &pkt, camera_inverted);
writePlayerPos(player, &m_env.getClientMap(), &pkt, camera_inverted);

Send(&pkt);
}
Expand Down
6 changes: 0 additions & 6 deletions src/client/localplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ class LocalPlayer : public Player
v3f last_speed;
float last_pitch = 0.0f;
float last_yaw = 0.0f;
u32 last_keyPressed = 0;
u8 last_camera_fov = 0;
u8 last_wanted_range = 0;
bool last_camera_inverted = false;
f32 last_movement_speed = 0.0f;
f32 last_movement_dir = 0.0f;

float camera_impact = 0.0f;

Expand Down
Loading