From ad310e2bafab23e60d90ceb49b4e68f3163a6752 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 19 Jan 2012 02:50:48 -0200 Subject: [PATCH] fix diagonal walking regression --- src/otclient/core/creature.cpp | 20 ++++++++++++-------- src/otclient/core/creature.h | 1 + src/otclient/core/localplayer.cpp | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index c89771a0..d6fa5d4a 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -46,6 +46,7 @@ Creature::Creature() : Thing() m_direction = Otc::South; m_walking = false; m_walkInterval = 0; + m_walkAnimationInterval = 0; m_walkTurnDirection = Otc::InvalidDirection; m_skull = Otc::SkullNone; m_shield = Otc::ShieldNone; @@ -207,16 +208,19 @@ void Creature::walk(const Position& oldPos, const Position& newPos) m_walkTimer.restart(); // calculates walk interval - float walkInterval = 1000; + float interval = 1000; int groundSpeed = g_map.getTile(oldPos)->getGroundSpeed(); if(groundSpeed != 0) - walkInterval = (1000.0f * groundSpeed) / m_speed; + interval = (1000.0f * groundSpeed) / m_speed; + + interval = std::ceil(interval / g_game.getServerBeat()) * g_game.getServerBeat(); + + m_walkAnimationInterval = interval; + m_walkInterval = interval; // diagonal walking lasts 3 times more. - //if(direction == Otc::NorthWest || direction == Otc::NorthEast || direction == Otc::SouthWest || direction == Otc::SouthEast) - // walkInterval *= 3; - - m_walkInterval = std::ceil(walkInterval / g_game.getServerBeat()) * g_game.getServerBeat(); + if(direction == Otc::NorthWest || direction == Otc::NorthEast || direction == Otc::SouthWest || direction == Otc::SouthEast) + m_walkInterval *= 3; // no direction needs to be changed when the walk ends m_walkTurnDirection = Otc::InvalidDirection; @@ -278,13 +282,13 @@ void Creature::nextWalkUpdate() m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { self->m_walkUpdateEvent = nullptr; self->nextWalkUpdate(); - }, m_walkInterval / 32); + }, m_walkAnimationInterval / 32); } } void Creature::updateWalk() { - float walkTicksPerPixel = m_walkInterval / 32.0f; + float walkTicksPerPixel = m_walkAnimationInterval / 32; int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); // update walk animation and offsets diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 64247a59..3b63bcf7 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -117,6 +117,7 @@ protected: // walk related Timer m_walkTimer; int m_walkInterval; + int m_walkAnimationInterval; bool m_walking; ScheduledEventPtr m_walkUpdateEvent; Point m_walkOffset; diff --git a/src/otclient/core/localplayer.cpp b/src/otclient/core/localplayer.cpp index ad6581f9..558347cc 100644 --- a/src/otclient/core/localplayer.cpp +++ b/src/otclient/core/localplayer.cpp @@ -140,7 +140,7 @@ void LocalPlayer::updateWalkOffset(int totalPixelsWalked) void LocalPlayer::updateWalk() { - float walkTicksPerPixel = m_walkInterval / 32.0f; + float walkTicksPerPixel = m_walkAnimationInterval / 32.0f; int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); // update walk animation and offsets