summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-01 22:57:29 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-11 02:34:03 +0200
commitebc1db2172d3dc1e954647fc21e80f074e6cda4b (patch)
tree4aa020517c83eb1e625b289cb20135d890f5af6e
parent5c5e17c0b200004c6d18a51e2c02fd21d710f04f (diff)
downloadmana-ebc1db2172d3dc1e954647fc21e80f074e6cda4b.tar.gz
mana-ebc1db2172d3dc1e954647fc21e80f074e6cda4b.tar.bz2
mana-ebc1db2172d3dc1e954647fc21e80f074e6cda4b.tar.xz
mana-ebc1db2172d3dc1e954647fc21e80f074e6cda4b.zip
Made the delay between to keyboard move calls functional.
It has been fixed and be made adapted to the being movement speed. Now, for instance, the client sends 3x times less move calls to the tA server, and roughly 20x times for the Manaserv's one. Resolves: Mana-Mantis #346.
-rw-r--r--src/being.h2
-rw-r--r--src/localplayer.cpp15
-rw-r--r--src/localplayer.h9
-rw-r--r--src/net/manaserv/playerhandler.cpp8
-rw-r--r--src/net/manaserv/playerhandler.h2
-rw-r--r--src/net/playerhandler.h8
-rw-r--r--src/net/tmwa/playerhandler.cpp6
-rw-r--r--src/net/tmwa/playerhandler.h2
8 files changed, 44 insertions, 8 deletions
diff --git a/src/being.h b/src/being.h
index a2a78bfd..b702cf1a 100644
--- a/src/being.h
+++ b/src/being.h
@@ -316,7 +316,7 @@ class Being : public ActorSprite, public EventListener
* in ticks per tile for eAthena,
* in tiles per second for Manaserv (0.1 precision).
*/
- void setMoveSpeed(const Vector &speed);
+ virtual void setMoveSpeed(const Vector &speed);
/**
* Gets the original Move speed.
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index f941dd5f..3c1cc259 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -58,11 +58,6 @@
#include <cassert>
-// This is the minimal delay between to permitted
-// setDestination() calls using the keyboard.
-// TODO: This can fine tuned later on when running is added...
-const short walkingKeyboardDelay = 1000;
-
#define AWAY_LIMIT_TIMER 60
LocalPlayer *player_node = NULL;
@@ -79,6 +74,7 @@ LocalPlayer::LocalPlayer(int id, int subtype):
mWalkingDir(0),
mPathSetByMouse(false),
mLocalWalkTime(-1),
+ mKeyboardMoveDelay(500),
mMessageTime(0),
mShowIp(false),
mAwayDialog(0),
@@ -741,8 +737,9 @@ void LocalPlayer::setWalkingDir(int dir)
// If the delay to send another walk message to the server hasn't expired,
// don't do anything or we could get disconnected for spamming the server
- if (get_elapsed_time(mLocalWalkTime) < walkingKeyboardDelay)
+ if (get_elapsed_time(mLocalWalkTime) < mKeyboardMoveDelay)
return;
+ mLocalWalkTime = tick_time;
mWalkingDir = dir;
@@ -808,6 +805,12 @@ void LocalPlayer::stopWalking(bool sendToServer)
clearPath();
}
+void LocalPlayer::setMoveSpeed(const Vector& speed)
+{
+ Being::setMoveSpeed(speed);
+ mKeyboardMoveDelay = Net::getPlayerHandler()->getKeyboardMoveDelay(speed);
+}
+
void LocalPlayer::toggleSit()
{
if (mLastAction != -1)
diff --git a/src/localplayer.h b/src/localplayer.h
index ab309d8f..ae27e51e 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -147,6 +147,8 @@ class LocalPlayer : public Being
*/
void setTarget(Being *target);
+ void setMoveSpeed(const Vector &speed);
+
/**
* Sets a new destination for this being to walk to.
*/
@@ -253,6 +255,13 @@ class LocalPlayer : public Being
int mLocalWalkTime; /**< Timestamp used to control keyboard walk
messages flooding */
+ /**
+ * The delay between two permitted setDestination() call using
+ * the keyboard.
+ * It's set in milliseconds per tile.
+ */
+ int mKeyboardMoveDelay;
+
typedef std::pair<std::string, int> MessagePair;
/** Queued messages*/
std::list<MessagePair> mMessages;
diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp
index a114da3d..d7c3dab6 100644
--- a/src/net/manaserv/playerhandler.cpp
+++ b/src/net/manaserv/playerhandler.cpp
@@ -442,4 +442,12 @@ Vector PlayerHandler::getPixelsPerTickMoveSpeed(const Vector &speed, Map *map)
return speedInTicks;
}
+int PlayerHandler::getKeyboardMoveDelay(const Vector& speed)
+{
+ int maxSpeed = std::max(speed.x, speed.y);
+ if (maxSpeed <= 0)
+ maxSpeed = 2;
+ return 1000 / maxSpeed;
+}
+
} // namespace ManaServ
diff --git a/src/net/manaserv/playerhandler.h b/src/net/manaserv/playerhandler.h
index 3e3f8aad..0edb4354 100644
--- a/src/net/manaserv/playerhandler.h
+++ b/src/net/manaserv/playerhandler.h
@@ -69,6 +69,8 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler
Vector getPixelsPerTickMoveSpeed(const Vector &speed, Map *map = 0);
+ int getKeyboardMoveDelay(const Vector& speed);
+
bool usePixelPrecision()
{ return true; }
diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h
index f9396caf..b52b6315 100644
--- a/src/net/playerhandler.h
+++ b/src/net/playerhandler.h
@@ -71,12 +71,18 @@ class PlayerHandler
virtual Vector getDefaultMoveSpeed() const = 0;
/**
- * Convert the original speed in pixel per tick for internal use.
+ * Convert the original server-dependant speed for internal use.
*/
virtual Vector getPixelsPerTickMoveSpeed(const Vector &speed,
Map *map = 0) = 0;
/**
+ * Convert the original speed into the keyboard move delay.
+ * The delay is set in milliseconds per tiles.
+ */
+ virtual int getKeyboardMoveDelay(const Vector& speed) = 0;
+
+ /**
* Tells whether the client has to use pixel paths.
* Return false when tiles-center positions only are to be used.
*/
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index f30baecd..dd228f11 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -22,6 +22,7 @@
#include "net/tmwa/playerhandler.h"
#include "net/tmwa/beinghandler.h"
+#include "client.h"
#include "configuration.h"
#include "game.h"
#include "localplayer.h"
@@ -661,4 +662,9 @@ Vector PlayerHandler::getPixelsPerTickMoveSpeed(const Vector &speed, Map *map)
return speedInTicks;
}
+int PlayerHandler::getKeyboardMoveDelay(const Vector& speed)
+{
+ return std::min(speed.x, speed.y) * MILLISECONDS_IN_A_TICK;
+}
+
} // namespace TmwAthena
diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h
index 63812f47..3e22be22 100644
--- a/src/net/tmwa/playerhandler.h
+++ b/src/net/tmwa/playerhandler.h
@@ -62,6 +62,8 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler
Vector getPixelsPerTickMoveSpeed(const Vector &speed, Map *map = 0);
+ int getKeyboardMoveDelay(const Vector& speed);
+
bool usePixelPrecision()
{ return false; }
};