mirror of
https://github.com/edubart/otclient.git
synced 2025-04-30 01:29:21 +02:00
Fix laggy diagonal movement (#1108)
This commit is contained in:
parent
b3d947d4c3
commit
c6d0fc0f71
@ -483,14 +483,14 @@ void Creature::onDeath()
|
||||
callLuaField("onDeath");
|
||||
}
|
||||
|
||||
void Creature::updateWalkAnimation(int totalPixelsWalked)
|
||||
void Creature::updateWalkAnimation(int totalPixelsWalked, int stepDuration)
|
||||
{
|
||||
// update outfit animation
|
||||
if(m_outfit.getCategory() != ThingCategoryCreature)
|
||||
return;
|
||||
|
||||
int footAnimPhases = getAnimationPhases() - 1;
|
||||
int footDelay = getStepDuration(true) / 3;
|
||||
int footDelay = stepDuration / 3;
|
||||
// Since mount is a different outfit we need to get the mount animation phases
|
||||
if(m_outfit.getMount() != 0) {
|
||||
ThingType *type = g_things.rawGetThingType(m_outfit.getMount(), m_outfit.getCategory());
|
||||
@ -579,20 +579,20 @@ void Creature::nextWalkUpdate()
|
||||
m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] {
|
||||
self->m_walkUpdateEvent = nullptr;
|
||||
self->nextWalkUpdate();
|
||||
}, getStepDuration() / 32);
|
||||
}, getStepDuration(true) / Otc::TILE_PIXELS);
|
||||
}
|
||||
}
|
||||
|
||||
void Creature::updateWalk()
|
||||
{
|
||||
float walkTicksPerPixel = getStepDuration(true) / 32;
|
||||
int totalPixelsWalked = std::min<int>(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f);
|
||||
int stepDuration = getStepDuration(true);
|
||||
int totalPixelsWalked = stepDuration ? std::min<int>((m_walkTimer.ticksElapsed() * Otc::TILE_PIXELS) / stepDuration, Otc::TILE_PIXELS) : 0;
|
||||
|
||||
// needed for paralyze effect
|
||||
m_walkedPixels = std::max<int>(m_walkedPixels, totalPixelsWalked);
|
||||
|
||||
// update walk animation and offsets
|
||||
updateWalkAnimation(totalPixelsWalked);
|
||||
updateWalkAnimation(totalPixelsWalked, stepDuration);
|
||||
updateWalkOffset(m_walkedPixels);
|
||||
updateWalkingTile();
|
||||
|
||||
|
@ -135,7 +135,7 @@ public:
|
||||
virtual void onDeath();
|
||||
|
||||
protected:
|
||||
virtual void updateWalkAnimation(int totalPixelsWalked);
|
||||
virtual void updateWalkAnimation(int totalPixelsWalked, int stepDuration);
|
||||
virtual void updateWalkOffset(int totalPixelsWalked);
|
||||
void updateWalkingTile();
|
||||
virtual void nextWalkUpdate();
|
||||
|
@ -265,17 +265,16 @@ void LocalPlayer::updateWalkOffset(int totalPixelsWalked)
|
||||
|
||||
void LocalPlayer::updateWalk()
|
||||
{
|
||||
int stepDuration = getStepDuration();
|
||||
float walkTicksPerPixel = getStepDuration(true) / 32.0f;
|
||||
int totalPixelsWalked = std::min<int>(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f);
|
||||
int stepDuration = getStepDuration(true);
|
||||
int totalPixelsWalked = stepDuration ? std::min<int>((m_walkTimer.ticksElapsed() * Otc::TILE_PIXELS) / stepDuration, Otc::TILE_PIXELS) : 0;
|
||||
|
||||
// update walk animation and offsets
|
||||
updateWalkAnimation(totalPixelsWalked);
|
||||
updateWalkAnimation(totalPixelsWalked, stepDuration);
|
||||
updateWalkOffset(totalPixelsWalked);
|
||||
updateWalkingTile();
|
||||
|
||||
// terminate walk only when client and server side walk are completed
|
||||
if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= stepDuration)
|
||||
if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration())
|
||||
terminateWalk();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user