From: MirceaKitsune Date: Sun, 2 Dec 2012 12:59:08 +0000 (+0200) Subject: Don't send player position from client to server if the player hasn't moved X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=15b86a6b9b4d32cc1213ebf8e1a2c12f56a83c16;p=zefram%2Fminetest%2Fminetest_engine.git Don't send player position from client to server if the player hasn't moved --- diff --git a/src/client.cpp b/src/client.cpp index 865cf71e..3463e926 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1976,10 +1976,24 @@ void Client::sendPlayerPos() { //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out - Player *myplayer = m_env.getLocalPlayer(); + LocalPlayer *myplayer = m_env.getLocalPlayer(); if(myplayer == NULL) 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; { //JMutexAutoLock lock(m_con_mutex); //bulk comment-out diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 17c4cdeb..14d1ac60 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -36,6 +36,11 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef): Player(gamedef), isAttached(false), 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_exists(false), m_old_node_below(32767,32767,32767), diff --git a/src/localplayer.h b/src/localplayer.h index 9d1829db..c9d010d7 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -44,6 +44,14 @@ public: void applyControl(float dtime); 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: // This is used for determining the sneaking range v3s16 m_sneak_node; diff --git a/src/player.h b/src/player.h index 6c7c1e4e..5a489e64 100644 --- a/src/player.h +++ b/src/player.h @@ -220,7 +220,7 @@ public: } u32 keyPressed; - + protected: IGameDef *m_gamedef;