aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>2012-12-02 14:59:08 +0200
committerPerttu Ahola <celeron55@gmail.com>2012-12-02 20:22:02 +0200
commit15b86a6b9b4d32cc1213ebf8e1a2c12f56a83c16 (patch)
treedddc025113b03cda3ce0bb976c4a333956a47966 /src
parenteeb0900291583c6d81656fbbd977fa74b1a733b6 (diff)
downloadminetest-15b86a6b9b4d32cc1213ebf8e1a2c12f56a83c16.tar.gz
minetest-15b86a6b9b4d32cc1213ebf8e1a2c12f56a83c16.tar.bz2
minetest-15b86a6b9b4d32cc1213ebf8e1a2c12f56a83c16.zip
Don't send player position from client to server if the player hasn't moved
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp18
-rw-r--r--src/localplayer.cpp5
-rw-r--r--src/localplayer.h8
-rw-r--r--src/player.h2
4 files changed, 30 insertions, 3 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 865cf71ee..3463e9262 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 17c4cdeb9..14d1ac60e 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 9d1829db8..c9d010d7c 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 6c7c1e4ea..5a489e64f 100644
--- a/src/player.h
+++ b/src/player.h
@@ -220,7 +220,7 @@ public:
}
u32 keyPressed;
-
+
protected:
IGameDef *m_gamedef;