From 82a0eab42381e89803d93f6ae1a9cfafd2abb254 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Fri, 29 Dec 2006 23:15:54 +0000 Subject: Improved movement smoothness by avoiding useless changes of sprite direction. --- ChangeLog | 5 +++++ src/being.cpp | 28 +++++++++++++++++++++++++--- src/being.h | 2 +- src/net/network.cpp | 2 +- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c5e01461..f9327b2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-12-30 Guillaume Melquiond + + * src/being.h, src/being.cpp: Improved movement smoothness by avoiding + useless changes of sprite direction. + 2006-12-29 Guillaume Melquiond * src/gui/connection.cpp: Fixed displaying of progress dialog. diff --git a/src/being.cpp b/src/being.cpp index 9cd0af0d..55a321ab 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -60,7 +60,7 @@ Being::Being(Uint16 id, Uint16 job, Map *map): mWeapon(0), mWalkSpeed(150), mSpeedModifier(1024), - mDirection(DOWN), + mOldDirection(DOWN), mDirection(DOWN), mMap(NULL), mHairStyle(0), mHairColor(0), mSpeechTime(0), @@ -368,6 +368,9 @@ Being::setAction(Uint8 action) void Being::setDirection(Uint8 direction) { + if (mDirection == direction) + return; + mOldDirection = mDirection; mDirection = direction; SpriteDirection dir = getSpriteDirection(); @@ -383,7 +386,25 @@ Being::getSpriteDirection() const { SpriteDirection dir; - if (mDirection & UP) + // if the direction has not changed much, keep it for the sprite + if (mOldDirection & mDirection & UP) + { + dir = DIRECTION_UP; + } + else if (mOldDirection & mDirection & RIGHT) + { + dir = DIRECTION_RIGHT; + } + else if (mOldDirection & mDirection & DOWN) + { + dir = DIRECTION_DOWN; + } + else if (mOldDirection & mDirection & LEFT) + { + dir = DIRECTION_LEFT; + } + // otherwise, use only the new direction + else if (mDirection & UP) { dir = DIRECTION_UP; } @@ -395,7 +416,8 @@ Being::getSpriteDirection() const { dir = DIRECTION_DOWN; } - else { + else + { dir = DIRECTION_LEFT; } diff --git a/src/being.h b/src/being.h index c95cd191..ff65b034 100644 --- a/src/being.h +++ b/src/being.h @@ -365,7 +365,7 @@ class Being : public Sprite Uint16 mWeapon; /**< Weapon picture id */ Uint16 mWalkSpeed; /**< Walking speed */ Uint16 mSpeedModifier; /**< Modifier to keep course on sync (1024 = normal speed) */ - Uint8 mDirection; /**< Facing direction */ + Uint8 mOldDirection,mDirection; /**< Facing direction */ Map *mMap; /**< Map on which this being resides */ SpriteIterator mSpriteIterator; diff --git a/src/net/network.cpp b/src/net/network.cpp index b94c9eb8..6b29ff33 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -148,7 +148,7 @@ void Net::flush() switch (event.type) { case ENET_EVENT_TYPE_CONNECT: - logger->log("Connected."); + logger->log("Connected to port %d.", event.peer->address.port); // Store any relevant server information here. event.peer->data = 0; break; -- cgit v1.2.3-70-g09d2