diff options
Diffstat (limited to 'src/content_cao.cpp')
-rw-r--r-- | src/content_cao.cpp | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 84ec3e143..dc3bae00d 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -41,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/mathconstants.h" #include "map.h" #include "main.h" // g_settings +#include "game.h" // CameraModes #include <IMeshManipulator.h> #include <IAnimatedMeshSceneNode.h> #include <IBoneSceneNode.h> @@ -858,7 +859,7 @@ public: m_visuals_expired = false; - if(!m_prop.is_visible || m_is_local_player) + if(!m_prop.is_visible) return; //video::IVideoDriver* driver = smgr->getVideoDriver(); @@ -1078,6 +1079,60 @@ public: void step(float dtime, ClientEnvironment *env) { + // Handel model of local player instantly to prevent lags + if(m_is_local_player) { + LocalPlayer *player = m_env->getLocalPlayer(); + + if (player->camera_mode > CAMERA_MODE_FIRST) { + int old_anim = player->last_animation; + float old_anim_speed = player->last_animation_speed; + m_is_visible = true; + 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(); + + bool walking = false; + if(controls.up || controls.down || controls.left || controls.right) + walking = true; + + m_animation_speed = player->local_animation_speed; + if(controls.sneak && walking) + m_animation_speed = player->local_animation_speed/2; + + player->last_animation_speed = m_animation_speed; + + if(walking && (controls.LMB || controls.RMB)) { + m_animation_range = player->local_animations[3]; + player->last_animation = WD_ANIM; + } else if(walking) { + m_animation_range = player->local_animations[1]; + player->last_animation = WALK_ANIM; + } else if(controls.LMB || controls.RMB) { + m_animation_range = player->local_animations[2]; + player->last_animation = DIG_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(); + } + } + + // Update local player animations + if ((player->last_animation != old_anim && player->last_animation != NO_ANIM) || m_animation_speed != old_anim_speed) + updateAnimation(); + + } else { + m_is_visible = false; + } + } + if(m_visuals_expired && m_smgr && m_irr){ m_visuals_expired = false; @@ -1701,6 +1756,7 @@ public: bool sneak = !readU8(is); bool sneak_glitch = !readU8(is); + if(m_is_local_player) { LocalPlayer *player = m_env->getLocalPlayer(); @@ -1713,11 +1769,25 @@ public: } else if(cmd == GENERIC_CMD_SET_ANIMATION) { - m_animation_range = readV2F1000(is); - m_animation_speed = readF1000(is); - m_animation_blend = readF1000(is); - - updateAnimation(); + if (!m_is_local_player) { + m_animation_range = readV2F1000(is); + 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_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) + updateAnimation(); + } } else if(cmd == GENERIC_CMD_SET_BONE_POSITION) { |