Fix local animations not resetting

Converts `LocalPlayerAnimation` to a scoped enum to prevent such bugs in the future
This commit is contained in:
Lars Müller 2023-07-02 12:47:18 +02:00 committed by GitHub
parent ff498fc206
commit 25ef8f3934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

@ -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);
@ -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
@ -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();
}
@ -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();
}
@ -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);

@ -34,7 +34,7 @@ class ClientEnvironment;
class IGameDef;
struct collisionMoveResult;
enum LocalPlayerAnimations
enum class LocalPlayerAnimation
{
NO_ANIM,
WALK_ANIM,
@ -90,7 +90,7 @@ public:
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 = "";

@ -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"
@ -1508,7 +1509,7 @@ void Client::handleCommand_LocalPlayerAnimations(NetworkPacket* pkt)
*pkt >> player->local_animations[3];
*pkt >> player->local_animation_speed;
player->last_animation = -1;
player->last_animation = LocalPlayerAnimation::NO_ANIM;
}
void Client::handleCommand_EyeOffset(NetworkPacket* pkt)