Fix regression in walk paralyze

This commit is contained in:
Eduardo Bart 2012-08-09 00:51:13 -03:00
parent b5cb4e2c93
commit 10c564f90e
5 changed files with 24 additions and 13 deletions

View File

@ -572,6 +572,7 @@ void Application::registerLuaFunctions()
g_lua.registerClass<UIVerticalLayout, UIBoxLayout>(); g_lua.registerClass<UIVerticalLayout, UIBoxLayout>();
g_lua.bindClassStaticFunction<UIVerticalLayout>("create", [](UIWidgetPtr parent){ return UIVerticalLayoutPtr(new UIVerticalLayout(parent)); } ); g_lua.bindClassStaticFunction<UIVerticalLayout>("create", [](UIWidgetPtr parent){ return UIVerticalLayoutPtr(new UIVerticalLayout(parent)); } );
g_lua.bindClassMemberFunction<UIVerticalLayout>("setAlignBottom", &UIVerticalLayout::setAlignBottom); g_lua.bindClassMemberFunction<UIVerticalLayout>("setAlignBottom", &UIVerticalLayout::setAlignBottom);
g_lua.bindClassMemberFunction<UIVerticalLayout>("isAlignBottom", &UIVerticalLayout::isAlignBottom);
// UIHorizontalLayout // UIHorizontalLayout
g_lua.registerClass<UIHorizontalLayout, UIBoxLayout>(); g_lua.registerClass<UIHorizontalLayout, UIBoxLayout>();

View File

@ -34,6 +34,7 @@ public:
void applyStyle(const OTMLNodePtr& styleNode); void applyStyle(const OTMLNodePtr& styleNode);
void setAlignBottom(bool aliginBottom) { m_alignBottom = aliginBottom; update(); } void setAlignBottom(bool aliginBottom) { m_alignBottom = aliginBottom; update(); }
bool isAlignBottom() { return m_alignBottom; }
bool isUIVerticalLayout() { return true; } bool isUIVerticalLayout() { return true; }

View File

@ -48,7 +48,6 @@ Creature::Creature() : Thing()
m_direction = Otc::South; m_direction = Otc::South;
m_walkAnimationPhase = 0; m_walkAnimationPhase = 0;
m_walkedPixels = 0; m_walkedPixels = 0;
m_walkStepDuration = 0;
m_walkTurnDirection = Otc::InvalidDirection; m_walkTurnDirection = Otc::InvalidDirection;
m_skull = Otc::SkullNone; m_skull = Otc::SkullNone;
m_shield = Otc::ShieldNone; m_shield = Otc::ShieldNone;
@ -258,6 +257,7 @@ void Creature::walk(const Position& oldPos, const Position& newPos)
// get walk direction // get walk direction
m_lastStepDirection = oldPos.getDirectionFromPosition(newPos); m_lastStepDirection = oldPos.getDirectionFromPosition(newPos);
m_lastStepPosition = newPos;
// set current walking direction // set current walking direction
setDirection(m_lastStepDirection); setDirection(m_lastStepDirection);
@ -266,7 +266,6 @@ void Creature::walk(const Position& oldPos, const Position& newPos)
m_walking = true; m_walking = true;
m_walkTimer.restart(); m_walkTimer.restart();
m_walkedPixels = 0; m_walkedPixels = 0;
m_walkStepDuration = getStepDuration();
// no direction need to be changed when the walk ends // no direction need to be changed when the walk ends
m_walkTurnDirection = Otc::InvalidDirection; m_walkTurnDirection = Otc::InvalidDirection;
@ -351,7 +350,7 @@ void Creature::updateWalkAnimation(int totalPixelsWalked)
int footAnimPhases = getAnimationPhases() - 1; int footAnimPhases = getAnimationPhases() - 1;
if(totalPixelsWalked == 32 || footAnimPhases == 0) if(totalPixelsWalked == 32 || footAnimPhases == 0)
m_walkAnimationPhase = 0; m_walkAnimationPhase = 0;
else if(m_footStepDrawn && m_footTimer.ticksElapsed() >= m_walkStepDuration / 4 ) { else if(m_footStepDrawn && m_footTimer.ticksElapsed() >= getStepDuration() / 4 ) {
m_footStep++; m_footStep++;
m_walkAnimationPhase = 1 + (m_footStep % footAnimPhases); m_walkAnimationPhase = 1 + (m_footStep % footAnimPhases);
m_footStepDrawn = false; m_footStepDrawn = false;
@ -415,13 +414,14 @@ 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();
}, m_walkStepDuration / 32); }, getStepDuration() / 32);
} }
} }
void Creature::updateWalk() void Creature::updateWalk()
{ {
float walkTicksPerPixel = m_walkStepDuration / 32; int stepDuration = getStepDuration();
float walkTicksPerPixel = stepDuration / 32;
int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f);
// needed for paralyze effect // needed for paralyze effect
@ -433,7 +433,7 @@ void Creature::updateWalk()
updateWalkingTile(); updateWalkingTile();
// terminate walk // terminate walk
if(m_walking && m_walkTimer.ticksElapsed() >= m_walkStepDuration) if(m_walking && m_walkTimer.ticksElapsed() >= stepDuration)
terminateWalk(); terminateWalk();
} }
@ -608,7 +608,11 @@ Point Creature::getDrawOffset()
int Creature::getStepDuration() int Creature::getStepDuration()
{ {
int groundSpeed = 0; int groundSpeed = 0;
const TilePtr& tile = getTile();
Position tilePos = m_lastStepPosition;
if(!tilePos.isValid())
tilePos = m_position;
const TilePtr& tile = g_map.getTile(tilePos);
if(tile) if(tile)
groundSpeed = tile->getGroundSpeed(); groundSpeed = tile->getGroundSpeed();

View File

@ -139,7 +139,6 @@ protected:
// walk related // walk related
int m_walkAnimationPhase; int m_walkAnimationPhase;
int m_walkedPixels; int m_walkedPixels;
int m_walkStepDuration;
uint m_footStep; uint m_footStep;
Timer m_walkTimer; Timer m_walkTimer;
Timer m_footTimer; Timer m_footTimer;
@ -151,6 +150,7 @@ protected:
Point m_walkOffset; Point m_walkOffset;
Otc::Direction m_walkTurnDirection; Otc::Direction m_walkTurnDirection;
Otc::Direction m_lastStepDirection; Otc::Direction m_lastStepDirection;
Position m_lastStepPosition;
Position m_oldPosition; Position m_oldPosition;
}; };

View File

@ -66,12 +66,16 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
if(m_walkLockExpiration != 0 && g_clock.millis() < m_walkLockExpiration) if(m_walkLockExpiration != 0 && g_clock.millis() < m_walkLockExpiration)
return false; return false;
// paralyzed
if(m_speed == 0)
return false;
// last walk is not done yet // last walk is not done yet
if(m_walkTimer.ticksElapsed() < m_walkStepDuration) if(m_walkTimer.ticksElapsed() < getStepDuration())
return false; return false;
// prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk // prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk
bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= m_walkStepDuration + PREWALK_TIMEOUT; bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration() + PREWALK_TIMEOUT;
// avoid doing more walks than wanted when receiving a lot of walks from server // avoid doing more walks than wanted when receiving a lot of walks from server
if(!m_lastPrewalkDone && m_preWalking && !prewalkTimeouted) if(!m_lastPrewalkDone && m_preWalking && !prewalkTimeouted)
@ -178,7 +182,8 @@ void LocalPlayer::updateWalkOffset(int totalPixelsWalked)
void LocalPlayer::updateWalk() void LocalPlayer::updateWalk()
{ {
float walkTicksPerPixel = m_walkStepDuration / 32.0f; int stepDuration = getStepDuration();
float walkTicksPerPixel = stepDuration / 32.0f;
int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f);
// update walk animation and offsets // update walk animation and offsets
@ -186,8 +191,8 @@ void LocalPlayer::updateWalk()
updateWalkOffset(totalPixelsWalked); updateWalkOffset(totalPixelsWalked);
updateWalkingTile(); updateWalkingTile();
// terminate walk only when client and server side walk are complated // terminate walk only when client and server side walk are completed
if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= m_walkStepDuration) if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= stepDuration)
terminateWalk(); terminateWalk();
} }