content_cao: fix getPlayerControl structure copy on each step (#5677)

Also fix some codestyle issues around it.
This commit is contained in:
Loïc Blot 2017-04-29 18:16:58 +02:00 committed by GitHub
parent 3db66b4531
commit 3251e44938

@ -1041,12 +1041,9 @@ void GenericCAO::updateNodePos()
void GenericCAO::step(float dtime, ClientEnvironment *env) void GenericCAO::step(float dtime, ClientEnvironment *env)
{ {
// Handel model of local player instantly to prevent lags // Handel model of local player instantly to prevent lags
if(m_is_local_player) if (m_is_local_player) {
{
LocalPlayer *player = m_env->getLocalPlayer(); LocalPlayer *player = m_env->getLocalPlayer();
if (m_is_visible) {
if (m_is_visible)
{
int old_anim = player->last_animation; int old_anim = player->last_animation;
float old_anim_speed = player->last_animation_speed; float old_anim_speed = player->last_animation_speed;
m_position = player->getPosition() + v3f(0,BS,0); m_position = player->getPosition() + v3f(0,BS,0);
@ -1054,7 +1051,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
m_acceleration = v3f(0,0,0); m_acceleration = v3f(0,0,0);
pos_translator.vect_show = m_position; pos_translator.vect_show = m_position;
m_yaw = player->getYaw(); m_yaw = player->getYaw();
PlayerControl controls = player->getPlayerControl(); const PlayerControl &controls = player->getPlayerControl();
bool walking = false; bool walking = false;
if (controls.up || controls.down || controls.left || controls.right || if (controls.up || controls.down || controls.left || controls.right ||
@ -1078,8 +1075,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
if (controls.sneak && walking) if (controls.sneak && walking)
new_speed /= 2; new_speed /= 2;
if(walking && (controls.LMB || controls.RMB)) if (walking && (controls.LMB || controls.RMB)) {
{
new_anim = player->local_animations[3]; new_anim = player->local_animations[3];
player->last_animation = WD_ANIM; player->last_animation = WD_ANIM;
} else if(walking) { } else if(walking) {
@ -1092,8 +1088,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
// Apply animations if input detected and not attached // Apply animations if input detected and not attached
// or set idle animation // or set idle animation
if ((new_anim.X + new_anim.Y) > 0 && !player->isAttached) if ((new_anim.X + new_anim.Y) > 0 && !player->isAttached) {
{
allow_update = true; allow_update = true;
m_animation_range = new_anim; m_animation_range = new_anim;
m_animation_speed = new_speed; m_animation_speed = new_speed;
@ -1101,8 +1096,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
} else { } else {
player->last_animation = NO_ANIM; player->last_animation = NO_ANIM;
if (old_anim != NO_ANIM) if (old_anim != NO_ANIM) {
{
m_animation_range = player->local_animations[0]; m_animation_range = player->local_animations[0];
updateAnimation(); updateAnimation();
} }