Fix laggy diagonal movement (#1108)

This commit is contained in:
vfjpl 2020-10-07 03:14:00 +02:00 committed by GitHub
parent b3d947d4c3
commit c6d0fc0f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View File

@ -483,14 +483,14 @@ void Creature::onDeath()
callLuaField("onDeath"); callLuaField("onDeath");
} }
void Creature::updateWalkAnimation(int totalPixelsWalked) void Creature::updateWalkAnimation(int totalPixelsWalked, int stepDuration)
{ {
// update outfit animation // update outfit animation
if(m_outfit.getCategory() != ThingCategoryCreature) if(m_outfit.getCategory() != ThingCategoryCreature)
return; return;
int footAnimPhases = getAnimationPhases() - 1; 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 // Since mount is a different outfit we need to get the mount animation phases
if(m_outfit.getMount() != 0) { if(m_outfit.getMount() != 0) {
ThingType *type = g_things.rawGetThingType(m_outfit.getMount(), m_outfit.getCategory()); ThingType *type = g_things.rawGetThingType(m_outfit.getMount(), m_outfit.getCategory());
@ -579,20 +579,20 @@ void Creature::nextWalkUpdate()
m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] {
self->m_walkUpdateEvent = nullptr; self->m_walkUpdateEvent = nullptr;
self->nextWalkUpdate(); self->nextWalkUpdate();
}, getStepDuration() / 32); }, getStepDuration(true) / Otc::TILE_PIXELS);
} }
} }
void Creature::updateWalk() void Creature::updateWalk()
{ {
float walkTicksPerPixel = getStepDuration(true) / 32; int stepDuration = getStepDuration(true);
int totalPixelsWalked = std::min<int>(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); int totalPixelsWalked = stepDuration ? std::min<int>((m_walkTimer.ticksElapsed() * Otc::TILE_PIXELS) / stepDuration, Otc::TILE_PIXELS) : 0;
// needed for paralyze effect // needed for paralyze effect
m_walkedPixels = std::max<int>(m_walkedPixels, totalPixelsWalked); m_walkedPixels = std::max<int>(m_walkedPixels, totalPixelsWalked);
// update walk animation and offsets // update walk animation and offsets
updateWalkAnimation(totalPixelsWalked); updateWalkAnimation(totalPixelsWalked, stepDuration);
updateWalkOffset(m_walkedPixels); updateWalkOffset(m_walkedPixels);
updateWalkingTile(); updateWalkingTile();

View File

@ -135,7 +135,7 @@ public:
virtual void onDeath(); virtual void onDeath();
protected: protected:
virtual void updateWalkAnimation(int totalPixelsWalked); virtual void updateWalkAnimation(int totalPixelsWalked, int stepDuration);
virtual void updateWalkOffset(int totalPixelsWalked); virtual void updateWalkOffset(int totalPixelsWalked);
void updateWalkingTile(); void updateWalkingTile();
virtual void nextWalkUpdate(); virtual void nextWalkUpdate();

View File

@ -265,17 +265,16 @@ void LocalPlayer::updateWalkOffset(int totalPixelsWalked)
void LocalPlayer::updateWalk() void LocalPlayer::updateWalk()
{ {
int stepDuration = getStepDuration(); int stepDuration = getStepDuration(true);
float walkTicksPerPixel = getStepDuration(true) / 32.0f; int totalPixelsWalked = stepDuration ? std::min<int>((m_walkTimer.ticksElapsed() * Otc::TILE_PIXELS) / stepDuration, Otc::TILE_PIXELS) : 0;
int totalPixelsWalked = std::min<int>(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f);
// update walk animation and offsets // update walk animation and offsets
updateWalkAnimation(totalPixelsWalked); updateWalkAnimation(totalPixelsWalked, stepDuration);
updateWalkOffset(totalPixelsWalked); updateWalkOffset(totalPixelsWalked);
updateWalkingTile(); updateWalkingTile();
// terminate walk only when client and server side walk are completed // 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(); terminateWalk();
} }