Skip to content

Commit

Permalink
content_cao: fix getPlayerControl structure copy on each step (#5677)
Browse files Browse the repository at this point in the history
Also fix some codestyle issues around it.
  • Loading branch information
nerzhul authored Apr 29, 2017
1 parent 3db66b4 commit 3251e44
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/content_cao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,20 +1041,17 @@ void GenericCAO::updateNodePos()
void GenericCAO::step(float dtime, ClientEnvironment *env)
{
// Handel model of local player instantly to prevent lags
if(m_is_local_player)
{
if (m_is_local_player) {
LocalPlayer *player = m_env->getLocalPlayer();

if (m_is_visible)
{
if (m_is_visible) {
int old_anim = player->last_animation;
float old_anim_speed = player->last_animation_speed;
m_position = player->getPosition() + v3f(0,BS,0);
m_velocity = v3f(0,0,0);
m_acceleration = v3f(0,0,0);
pos_translator.vect_show = m_position;
m_yaw = player->getYaw();
PlayerControl controls = player->getPlayerControl();
const PlayerControl &controls = player->getPlayerControl();

bool walking = false;
if (controls.up || controls.down || controls.left || controls.right ||
Expand All @@ -1075,11 +1072,10 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
m_client->checkLocalPrivilege("fly"))))
new_speed *= 1.5;
// slowdown speed if sneeking
if(controls.sneak && walking)
if (controls.sneak && walking)
new_speed /= 2;

if(walking && (controls.LMB || controls.RMB))
{
if (walking && (controls.LMB || controls.RMB)) {
new_anim = player->local_animations[3];
player->last_animation = WD_ANIM;
} else if(walking) {
Expand All @@ -1092,17 +1088,15 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)

// Apply animations if input detected and not attached
// 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;
m_animation_range = new_anim;
m_animation_speed = new_speed;
player->last_animation_speed = m_animation_speed;
} else {
player->last_animation = NO_ANIM;

if (old_anim != NO_ANIM)
{
if (old_anim != NO_ANIM) {
m_animation_range = player->local_animations[0];
updateAnimation();
}
Expand Down

0 comments on commit 3251e44

Please sign in to comment.