diff options
Diffstat (limited to 'src/content_cao.cpp')
-rw-r--r-- | src/content_cao.cpp | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp index dbaf13cc8..5f53fd644 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -581,7 +581,7 @@ private: v2s16 m_tx_basepos; bool m_initial_tx_basepos_set; bool m_tx_select_horiz_by_yawpitch; - v2f m_animation_range; + v2s32 m_animation_range; int m_animation_speed; int m_animation_blend; std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name @@ -624,7 +624,7 @@ public: m_tx_basepos(0,0), m_initial_tx_basepos_set(false), m_tx_select_horiz_by_yawpitch(false), - m_animation_range(v2f(0,0)), + m_animation_range(v2s32(0,0)), m_animation_speed(15), m_animation_blend(0), m_bone_position(std::map<std::string, core::vector2d<v3f> >()), @@ -1098,41 +1098,51 @@ public: if(controls.up || controls.down || controls.left || controls.right) walking = true; - m_animation_speed = player->local_animation_speed; + f32 new_speed = player->local_animation_speed; + v2s32 new_anim = v2s32(0,0); + bool allow_update = false; + if(!player->touching_ground && g_settings->getBool("free_move") && m_gamedef->checkLocalPrivilege("fly") && g_settings->getBool("fast_move") && m_gamedef->checkLocalPrivilege("fast")) - m_animation_speed *= 1.5; + new_speed *= 1.5; if(controls.sneak && walking) - m_animation_speed /= 2; - - player->last_animation_speed = m_animation_speed; + new_speed /= 2; if(walking && (controls.LMB || controls.RMB)) { - m_animation_range = player->local_animations[3]; + new_anim = player->local_animations[3]; player->last_animation = WD_ANIM; } else if(walking) { - m_animation_range = player->local_animations[1]; + new_anim = player->local_animations[1]; player->last_animation = WALK_ANIM; } else if(controls.LMB || controls.RMB) { - m_animation_range = player->local_animations[2]; + new_anim = player->local_animations[2]; player->last_animation = DIG_ANIM; } + if ((new_anim.X + new_anim.Y) > 0) { + 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; + } // reset animation when no input detected if (!walking && !controls.LMB && !controls.RMB) { player->last_animation = NO_ANIM; if (old_anim != NO_ANIM) { m_animation_range = player->local_animations[0]; - updateAnimation(); + updateAnimation(); } } // Update local player animations - if ((player->last_animation != old_anim && player->last_animation != NO_ANIM) || m_animation_speed != old_anim_speed) - updateAnimation(); + if ((player->last_animation != old_anim || m_animation_speed != old_anim_speed) && + player->last_animation != NO_ANIM && allow_update) + updateAnimation(); } else { m_is_visible = false; @@ -1501,8 +1511,7 @@ public: { if(m_animated_meshnode == NULL) return; - - m_animated_meshnode->setFrameLoop((int)m_animation_range.X, (int)m_animation_range.Y); + m_animated_meshnode->setFrameLoop(m_animation_range.X, m_animation_range.Y); m_animated_meshnode->setAnimationSpeed(m_animation_speed); m_animated_meshnode->setTransitionTime(m_animation_blend); } @@ -1775,24 +1784,30 @@ public: } else if(cmd == GENERIC_CMD_SET_ANIMATION) { - if (!m_is_local_player) { - m_animation_range = readV2F1000(is); + // TODO: change frames send as v2s32 value + v2f range = readV2F1000(is); + if (!m_is_local_player) { + m_animation_range = v2s32((s32)range.X, (s32)range.Y); m_animation_speed = readF1000(is); m_animation_blend = readF1000(is); updateAnimation(); } else { LocalPlayer *player = m_env->getLocalPlayer(); if(player->last_animation == NO_ANIM) { - m_animation_range = readV2F1000(is); + m_animation_range = v2s32((s32)range.X, (s32)range.Y); m_animation_speed = readF1000(is); m_animation_blend = readF1000(is); } - // update animation only if object is not player - // or the received animation is not registered - if(m_animation_range.X != player->local_animations[1].X && - m_animation_range.X != player->local_animations[2].X && - m_animation_range.X != player->local_animations[3].X) + // update animation only if local animations present + // and received animation is not unknown + int frames = 0; + for (int i = 0;i<4;i++) { + frames += (int)player->local_animations[i].Y; + } + if(frames < 1) { + player->last_animation = NO_ANIM; updateAnimation(); + } } } else if(cmd == GENERIC_CMD_SET_BONE_POSITION) |