summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorBertram <bertram@cegetel.net>2009-10-15 01:38:18 +0200
committerBertram <bertram@cegetel.net>2009-10-15 01:38:18 +0200
commit2f55dd130c886376a45c9d0054dbd987cc055155 (patch)
treea0a1f25a6310b9e29ab10c442ba10cb2a1a1145e /src/being.cpp
parentb4befc985875588a4b454b112b8b79a94c26e5e6 (diff)
downloadmana-client-2f55dd130c886376a45c9d0054dbd987cc055155.tar.gz
mana-client-2f55dd130c886376a45c9d0054dbd987cc055155.tar.bz2
mana-client-2f55dd130c886376a45c9d0054dbd987cc055155.tar.xz
mana-client-2f55dd130c886376a45c9d0054dbd987cc055155.zip
Speed code unification part 3: Made the client handle the speed in tiles per second in TMWserv.
While I was on it, I tweaked the default speed value to its final 6 tiles per second value, which seems to be nice to me. Another notice, the server does already send speed value to the player. The keyboard movement protocol is one step ahead Release Candidate, enjoy ;)
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/being.cpp b/src/being.cpp
index ef71b748..c13b52f7 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -58,10 +58,12 @@
#define BEING_EFFECTS_FILE "effects.xml"
#define HAIR_FILE "hair.xml"
-int Being::mNumberOfHairstyles = 1;
+static const int DEFAULT_BEING_WIDTH = 32;
+static const int DEFAULT_BEING_HEIGHT = 32;
+extern const int MILLISECONDS_IN_A_TICK;
+
-static const int DEFAULT_WIDTH = 32;
-static const int DEFAULT_HEIGHT = 32;
+int Being::mNumberOfHairstyles = 1;
Being::Being(int id, int job, Map *map):
#ifdef EATHENA_SUPPORT
@@ -87,7 +89,7 @@ Being::Being(int id, int job, Map *map):
mChildParticleEffects(&mStatusParticleEffects, false),
mMustResetParticles(false),
#ifdef TMWSERV_SUPPORT
- mWalkSpeed(100),
+ mWalkSpeed(6.0f), // default speed in tile per second
#else
mWalkSpeed(150),
#endif
@@ -525,16 +527,30 @@ void Being::logic()
mDest : Vector(mPath.front().x,
mPath.front().y);
+ // The Vector representing the difference between current position
+ // and the next destination path node.
Vector dir = dest - mPos;
- const float length = dir.length();
+
+ const float nominalLength = dir.length();
// When we've not reached our destination, move to it.
- if (length > 0.0f)
+ if (nominalLength > 0.0f && mWalkSpeed > 0.0f)
{
- const float speed = mWalkSpeed / 100.0f;
+
+ // The private mWalkSpeed member is the speed in tiles per second.
+ // We translate it into pixels per tick,
+ // because the logic is called every ticks.
+ const float speedInTicks = ((float)DEFAULT_TILE_SIDE_LENGTH * mWalkSpeed)
+ / 1000 * (float)MILLISECONDS_IN_A_TICK;
+
+ // The deplacement of a point along a vector is calculated
+ // using the Unit Vector (â) multiplied by the point speed.
+ // â = a / ||a|| (||a|| is the a length.)
+ // Then, diff = (dir/||dir||)*speed, or (dir / ||dir|| / 1/speed).
+ Vector diff = (dir / (nominalLength / speedInTicks));
// Test if we don't miss the destination by a move too far:
- if ((dir / (length / speed)).length() > dir.length())
+ if (diff.length() > nominalLength)
{
setPosition(mPos + dir);
@@ -545,7 +561,7 @@ void Being::logic()
}
// Otherwise, go to it using the nominal speed.
else
- setPosition(mPos + (dir / (length / speed)));
+ setPosition(mPos + diff);
if (mAction != WALK)
setAction(WALK);
@@ -780,9 +796,9 @@ int Being::getWidth() const
break;
if (base)
- return std::max(base->getWidth(), DEFAULT_WIDTH);
+ return std::max(base->getWidth(), DEFAULT_BEING_WIDTH);
else
- return DEFAULT_WIDTH;
+ return DEFAULT_BEING_WIDTH;
}
int Being::getHeight() const
@@ -794,9 +810,9 @@ int Being::getHeight() const
break;
if (base)
- return std::max(base->getHeight(), DEFAULT_HEIGHT);
+ return std::max(base->getHeight(), DEFAULT_BEING_HEIGHT);
else
- return DEFAULT_HEIGHT;
+ return DEFAULT_BEING_HEIGHT;
}
void Being::setTargetAnimation(SimpleAnimation* animation)