diff options
author | Bertram <bertram@cegetel.net> | 2010-02-01 11:49:11 +0100 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2010-02-01 11:49:11 +0100 |
commit | 7e2a54bedefc6b5e2b34c9dafccb8322f46266e7 (patch) | |
tree | 8a016c196e36f94ac7454e2300226461e71305c8 /src | |
parent | 3fe06a98c0af45d7fccce99f39f402485dae71be (diff) | |
download | mana-7e2a54bedefc6b5e2b34c9dafccb8322f46266e7.tar.gz mana-7e2a54bedefc6b5e2b34c9dafccb8322f46266e7.tar.bz2 mana-7e2a54bedefc6b5e2b34c9dafccb8322f46266e7.tar.xz mana-7e2a54bedefc6b5e2b34c9dafccb8322f46266e7.zip |
Reduced CPU consumption by setting speed per ticks value only once.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 8 | ||||
-rw-r--r-- | src/being.h | 3 | ||||
-rw-r--r-- | src/net/manaserv/beinghandler.cpp | 16 | ||||
-rw-r--r-- | src/net/manaserv/playerhandler.cpp | 6 |
4 files changed, 20 insertions, 13 deletions
diff --git a/src/being.cpp b/src/being.cpp index 1e6da93e..6ce2120a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -534,17 +534,11 @@ void Being::logic() // When we've not reached our destination, move to it. if (nominalLength > 1.0f && mWalkSpeed > 0.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)); + Vector diff = (dir / (nominalLength / mWalkSpeed)); // Test if we don't miss the destination by a move too far: if (diff.length() > nominalLength) diff --git a/src/being.h b/src/being.h index 747a5428..b286ef41 100644 --- a/src/being.h +++ b/src/being.h @@ -646,7 +646,8 @@ class Being : public Sprite, public ConfigListener /** * Walk speed. * In pixels per second for eAthena, - * In tiles per second (0.1 precision) for Manaserv. + * In pixels per ticks for Manaserv. + * @see MILLISECONDS_IN_A_TICK */ float mWalkSpeed; diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index 2db76255..09608891 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -202,10 +202,18 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg) } if (speed) { - // The being's speed is transfered in tiles per second * 10 - // to keep it transferable in a Byte. - // We set it back to tiles per second and in a float. - being->setWalkSpeed((float) speed / 10); + /** + * The being's speed is transfered in tiles per second * 10 + * to keep it transferable in a Byte. + * We set it back to tiles per second and in a float. + * Then, we translate it in pixels per ticks, to correspond + * with the Being::logic() function calls + * @see MILLISECONDS_IN_A_TICK + */ + const float walkSpeedInTicks = + ((float)DEFAULT_TILE_SIDE_LENGTH * (float) speed / 10) + / 1000 * (float)MILLISECONDS_IN_A_TICK; + being->setWalkSpeed(walkSpeedInTicks); } // Ignore messages from the server for the local player diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 0d7544fd..aac6dc22 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -49,6 +49,8 @@ extern BuyDialog *buyDialog; extern SellDialog *sellDialog; extern Window *buySellDialog; +extern const int MILLISECONDS_IN_A_TICK; + /* Max. distance we are willing to scroll after a teleport; * everything beyond will reset the port hard. */ @@ -425,7 +427,9 @@ int PlayerHandler::getJobLocation() float PlayerHandler::getDefaultWalkSpeed() { - return 6.0f; + // Return translation in pixels per ticks. + return (6.0f * (float)DEFAULT_TILE_SIDE_LENGTH) + / 1000 * (float)MILLISECONDS_IN_A_TICK; } } // namespace ManaServ |