Don't send player position from client to server if the player hasn't moved

This commit is contained in:
MirceaKitsune 2012-12-02 14:59:08 +02:00 committed by Perttu Ahola
parent eeb0900291
commit 15b86a6b9b
4 changed files with 30 additions and 3 deletions

@ -1976,10 +1976,24 @@ void Client::sendPlayerPos()
{ {
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
Player *myplayer = m_env.getLocalPlayer(); LocalPlayer *myplayer = m_env.getLocalPlayer();
if(myplayer == NULL) if(myplayer == NULL)
return; return;
// Save bandwidth by only updating position when something changed
if(myplayer->last_position == myplayer->getPosition() &&
myplayer->last_speed == myplayer->getSpeed() &&
myplayer->last_pitch == myplayer->getPitch() &&
myplayer->last_yaw == myplayer->getYaw() &&
myplayer->last_keyPressed == myplayer->keyPressed)
return;
myplayer->last_position = myplayer->getPosition();
myplayer->last_speed = myplayer->getSpeed();
myplayer->last_pitch = myplayer->getPitch();
myplayer->last_yaw = myplayer->getYaw();
myplayer->last_keyPressed = myplayer->keyPressed;
u16 our_peer_id; u16 our_peer_id;
{ {
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out //JMutexAutoLock lock(m_con_mutex); //bulk comment-out

@ -36,6 +36,11 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef):
Player(gamedef), Player(gamedef),
isAttached(false), isAttached(false),
overridePosition(v3f(0,0,0)), overridePosition(v3f(0,0,0)),
last_position(v3f(0,0,0)),
last_speed(v3f(0,0,0)),
last_pitch(0),
last_yaw(0),
last_keyPressed(0),
m_sneak_node(32767,32767,32767), m_sneak_node(32767,32767,32767),
m_sneak_node_exists(false), m_sneak_node_exists(false),
m_old_node_below(32767,32767,32767), m_old_node_below(32767,32767,32767),

@ -44,6 +44,14 @@ public:
void applyControl(float dtime); void applyControl(float dtime);
v3s16 getStandingNodePos(); v3s16 getStandingNodePos();
// Used to check if anything changed and prevent sending packets if not
v3f last_position;
v3f last_speed;
float last_pitch;
float last_yaw;
unsigned int last_keyPressed;
private: private:
// This is used for determining the sneaking range // This is used for determining the sneaking range
v3s16 m_sneak_node; v3s16 m_sneak_node;