diff options
author | Bertram <bertram@cegetel.net> | 2010-02-03 22:38:07 +0100 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2010-02-03 22:55:28 +0100 |
commit | e5ec83786f01d91da97f75f68ccc707c37780db4 (patch) | |
tree | 03987f52016ad7bc17f096d5a37cc958fc038963 /src | |
parent | 20d2a17c8c0fa9220c257d61641a6459e154de26 (diff) | |
download | mana-e5ec83786f01d91da97f75f68ccc707c37780db4.tar.gz mana-e5ec83786f01d91da97f75f68ccc707c37780db4.tar.bz2 mana-e5ec83786f01d91da97f75f68ccc707c37780db4.tar.xz mana-e5ec83786f01d91da97f75f68ccc707c37780db4.zip |
Factorized speed translation from tile per seconds to pixels per ticks.
Diffstat (limited to 'src')
-rw-r--r-- | src/net/manaserv/beinghandler.cpp | 14 | ||||
-rw-r--r-- | src/net/manaserv/beinghandler.h | 8 | ||||
-rw-r--r-- | src/net/manaserv/playerhandler.cpp | 10 |
3 files changed, 24 insertions, 8 deletions
diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index 09608891..025a9e7e 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -91,6 +91,12 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) } } +float BeingHandler::giveSpeedInPixelsPerTicks(float speedInTilesPerSeconds) +{ + return (speedInTilesPerSeconds * (float)DEFAULT_TILE_SIDE_LENGTH) + / 1000 * (float)MILLISECONDS_IN_A_TICK; +} + static void handleLooks(Player *being, Net::MessageIn &msg) { // Order of sent slots. Has to be in sync with the server code. @@ -202,7 +208,7 @@ 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. @@ -210,10 +216,8 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg) * 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); + being->setWalkSpeed( + giveSpeedInPixelsPerTicks((float) speed / 10)); } // Ignore messages from the server for the local player diff --git a/src/net/manaserv/beinghandler.h b/src/net/manaserv/beinghandler.h index 0da4a296..a34e6537 100644 --- a/src/net/manaserv/beinghandler.h +++ b/src/net/manaserv/beinghandler.h @@ -33,6 +33,14 @@ class BeingHandler : public MessageHandler void handleMessage(Net::MessageIn &msg); + /** + * Translate a given speed in tiles per seconds + * into pixels per ticks. + * Used to optimize Being::logic() calls. + * @see MILLISECONDS_IN_A_TICKS + */ + static float giveSpeedInPixelsPerTicks(float speedInTilesPerSeconds); + private: void handleBeingAttackMessage(Net::MessageIn &msg); void handleBeingEnterMessage(Net::MessageIn &msg); diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index aac6dc22..9225b765 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -20,6 +20,7 @@ */ #include "net/manaserv/playerhandler.h" +#include "net/manaserv/beinghandler.h" #include "effectmanager.h" #include "engine.h" @@ -49,12 +50,16 @@ extern BuyDialog *buyDialog; extern SellDialog *sellDialog; extern Window *buySellDialog; +/** @see in game.cpp */ extern const int MILLISECONDS_IN_A_TICK; +/** @see in map.cpp */ +extern const int DEFAULT_TILE_SIDE_LENGTH; + /* Max. distance we are willing to scroll after a teleport; * everything beyond will reset the port hard. */ -static const int MAP_TELEPORT_SCROLL_DISTANCE = 8 * 32; +static const int MAP_TELEPORT_SCROLL_DISTANCE = 8 * DEFAULT_TILE_SIDE_LENGTH; /** * Listener used for handling the overweigth message. @@ -428,8 +433,7 @@ int PlayerHandler::getJobLocation() float PlayerHandler::getDefaultWalkSpeed() { // Return translation in pixels per ticks. - return (6.0f * (float)DEFAULT_TILE_SIDE_LENGTH) - / 1000 * (float)MILLISECONDS_IN_A_TICK; + return ManaServ::BeingHandler::giveSpeedInPixelsPerTicks(6.0f); } } // namespace ManaServ |