From 72f569c250b440ae05a5edbe6d82af1c32203e63 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 11 Jun 2012 16:03:36 -0300 Subject: [PATCH] improve walk animation on low end hardware --- src/otclient/core/creature.cpp | 13 ++++++++++--- src/otclient/core/creature.h | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 691d7ca2..05f24e86 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -54,6 +54,7 @@ Creature::Creature() : Thing() m_emblem = Otc::EmblemNone; m_nameCache.setFont(g_fonts.getFont("verdana-11px-rounded")); m_nameCache.setAlign(Fw::AlignTopCenter); + m_footStep = 0; } /* @@ -82,6 +83,7 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate) } internalDrawOutfit(dest + animationOffset * scaleFactor, scaleFactor, animate, animate, m_direction); + m_footStepDrawn = true; } void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction) @@ -304,10 +306,15 @@ void Creature::updateWalkAnimation(int totalPixelsWalked) if(m_outfit.getCategory() != ThingsType::Creature) return; - if(totalPixelsWalked == 32 || totalPixelsWalked == 0 || getAnimationPhases() <= 1) + int footAnimPhases = getAnimationPhases() - 1; + if(totalPixelsWalked == 32 || footAnimPhases == 0) m_walkAnimationPhase = 0; - else if(getAnimationPhases() > 1) - m_walkAnimationPhase = 1 + ((totalPixelsWalked * 4) / Otc::TILE_PIXELS) % (getAnimationPhases() - 1); + else if(m_footStepDrawn && m_footTimer.ticksElapsed() >= m_walkAnimationInterval / 4 ) { + m_footStep++; + m_walkAnimationPhase = 1 + (m_footStep % footAnimPhases); + m_footStepDrawn = false; + m_footTimer.restart(); + } } void Creature::updateWalkOffset(int totalPixelsWalked) diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index d7269a5e..bc8f89de 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -129,11 +129,14 @@ protected: // walk related int m_walkAnimationPhase; + int m_footStep; Timer m_walkTimer; + Timer m_footTimer; TilePtr m_walkingTile; int m_walkInterval; int m_walkAnimationInterval; Boolean m_walking; + Boolean m_footStepDrawn; ScheduledEventPtr m_walkUpdateEvent; Point m_walkOffset; Otc::Direction m_walkTurnDirection;