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 local animations not resetting #13638

Merged
merged 1 commit into from
Jul 2, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/client/content_cao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
rot_translator.val_current = m_rotation;

if (m_is_visible) {
int old_anim = player->last_animation;
LocalPlayerAnimation old_anim = player->last_animation;
float old_anim_speed = player->last_animation_speed;
m_velocity = v3f(0,0,0);
m_acceleration = v3f(0,0,0);
Expand Down Expand Up @@ -1062,13 +1062,13 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)

if (walking && (controls.dig || controls.place)) {
new_anim = player->local_animations[3];
player->last_animation = WD_ANIM;
player->last_animation = LocalPlayerAnimation::WD_ANIM;
} else if (walking) {
new_anim = player->local_animations[1];
player->last_animation = WALK_ANIM;
player->last_animation = LocalPlayerAnimation::WALK_ANIM;
} else if (controls.dig || controls.place) {
new_anim = player->local_animations[2];
player->last_animation = DIG_ANIM;
player->last_animation = LocalPlayerAnimation::DIG_ANIM;
}

// Apply animations if input detected and not attached
Expand All @@ -1079,9 +1079,9 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
m_animation_speed = new_speed;
player->last_animation_speed = m_animation_speed;
} else {
player->last_animation = NO_ANIM;
player->last_animation = LocalPlayerAnimation::NO_ANIM;

if (old_anim != NO_ANIM) {
if (old_anim != LocalPlayerAnimation::NO_ANIM) {
m_animation_range = player->local_animations[0];
updateAnimation();
}
Expand All @@ -1090,7 +1090,8 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
// Update local player animations
if ((player->last_animation != old_anim ||
m_animation_speed != old_anim_speed) &&
player->last_animation != NO_ANIM && allow_update)
player->last_animation != LocalPlayerAnimation::NO_ANIM &&
allow_update)
updateAnimation();

}
Expand Down Expand Up @@ -1801,7 +1802,7 @@ void GenericCAO::processMessage(const std::string &data)
updateAnimation();
} else {
LocalPlayer *player = m_env->getLocalPlayer();
if(player->last_animation == NO_ANIM)
if(player->last_animation == LocalPlayerAnimation::NO_ANIM)
{
m_animation_range = v2s32((s32)range.X, (s32)range.Y);
m_animation_speed = readF32(is);
Expand Down
4 changes: 2 additions & 2 deletions src/client/localplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ClientEnvironment;
class IGameDef;
struct collisionMoveResult;

enum LocalPlayerAnimations
enum class LocalPlayerAnimation
{
NO_ANIM,
WALK_ANIM,
Expand Down Expand Up @@ -90,7 +90,7 @@ class LocalPlayer : public Player

bool makes_footstep_sound = true;

int last_animation = NO_ANIM;
LocalPlayerAnimation last_animation = LocalPlayerAnimation::NO_ANIM;
float last_animation_speed = 0.0f;

std::string hotbar_image = "";
Expand Down
3 changes: 2 additions & 1 deletion src/network/clientpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/strfnd.h"
#include "client/clientevent.h"
#include "client/sound.h"
#include "client/localplayer.h"
#include "network/clientopcodes.h"
#include "network/connection.h"
#include "network/networkpacket.h"
Expand Down Expand Up @@ -1504,7 +1505,7 @@ void Client::handleCommand_LocalPlayerAnimations(NetworkPacket* pkt)
*pkt >> player->local_animations[3];
*pkt >> player->local_animation_speed;

player->last_animation = -1;
Copy link
Contributor Author

@appgurueu appgurueu Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the crucial change. If this change is fine, the PR is fine. The rest is just conversion to scoped enum.

player->last_animation = LocalPlayerAnimation::NO_ANIM;
}

void Client::handleCommand_EyeOffset(NetworkPacket* pkt)
Expand Down