Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some reported issues with the new walking system. #932

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,12 @@ void Creature::walk(const Position& oldPos, const Position& newPos)

// starts counting walk
m_walking = true;
m_walkSteps = std::max<int>(++m_walkSteps, 1);
m_walkTimer.restart();
m_walkedPixels = 0;

if (++m_walkSteps == 0)
m_walkSteps = 1;

// no direction need to be changed when the walk ends
m_walkTurnDirection = Otc::InvalidDirection;

Expand Down Expand Up @@ -639,6 +641,7 @@ void Creature::nextWalkUpdate()

// do the update
updateWalk();

if (isLocalPlayer()) {
g_map.notificateCameraMove(m_walkOffset);
}
Expand Down Expand Up @@ -666,9 +669,8 @@ void Creature::updateWalk(const bool isPreWalking)
updateWalkOffset(m_walkedPixels);
updateWalkingTile();

if (m_walkedPixels == g_gameConfig.getSpriteSize()) {
if (isPreWalking) resetWalkAnimationPhase(false);
else terminateWalk();
if (m_walkedPixels == g_gameConfig.getSpriteSize() && !isPreWalking) {
terminateWalk();
}
}

Expand All @@ -695,24 +697,6 @@ void Creature::terminateWalk()
m_walkOffset = {};
m_walking = false;

if (isLocalPlayer() && !static_self_cast<LocalPlayer>()->isAutoWalking()) {
g_dispatcher.addEvent([] {
g_dispatcher.deferEvent([] {
if (g_game.getLocalPlayer())
g_game.walk(g_game.getLocalPlayer()->getNextWalkDir());
});
});
}

resetWalkAnimationPhase(true);
}

void Creature::resetWalkAnimationPhase(bool toSchedule) {
if (!toSchedule) {
m_walkAnimationPhase = 0;
return;
}

const auto self = static_self_cast<Creature>();
m_walkFinishAnimEvent = g_dispatcher.scheduleEvent([self] {
self->m_walkSteps = 0;
Expand Down Expand Up @@ -955,12 +939,13 @@ uint16_t Creature::getStepDuration(bool ignoreDiagonal, Otc::Direction dir)
stepDuration = ((stepDuration + serverBeat - 1) / serverBeat) * serverBeat;
}

if (isLocalPlayer() && stepDuration < 100)
if (isLocalPlayer() && stepDuration <= 100)
stepDuration += 10;

m_stepCache.duration = stepDuration;

m_stepCache.walkDuration = std::min<int>(stepDuration / g_gameConfig.getSpriteSize(), DrawPool::FPS60);

m_stepCache.diagonalDuration = stepDuration *
(g_game.getClientVersion() > 810 || g_gameConfig.isForcingNewWalkingFormula()
? (isPlayer() ? g_gameConfig.getPlayerDiagonalWalkSpeed() : g_gameConfig.getCreatureDiagonalWalkSpeed())
Expand Down
1 change: 0 additions & 1 deletion src/client/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ class Creature : public Thing
void updateShield();
void updateWalkingTile();
void updateWalkAnimation();
void resetWalkAnimationPhase(bool toSchedule = false);

uint16_t getCurrentAnimationPhase(bool mount = false);

Expand Down
13 changes: 9 additions & 4 deletions src/client/localplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ void LocalPlayer::terminateWalk()
{
Creature::terminateWalk();
m_preWalking = false;

if (!static_self_cast<LocalPlayer>()->isAutoWalking()) {
g_dispatcher.addEvent([] {
g_dispatcher.deferEvent([] {
if (g_game.getLocalPlayer())
g_game.walk(g_game.getLocalPlayer()->getNextWalkDir());
});
});
}
}

void LocalPlayer::onPositionChange(const Position& newPos, const Position& oldPos)
Expand All @@ -218,10 +227,6 @@ void LocalPlayer::onPositionChange(const Position& newPos, const Position& oldPo
stopAutoWalk();
else if (m_autoWalkDestination.isValid() && newPos == m_lastAutoWalkPosition)
autoWalk(m_autoWalkDestination);

if (newPos.z != oldPos.z) {
m_walkTimer.update(-getStepDuration());
}
}

void LocalPlayer::setStates(uint32_t states)
Expand Down
Loading