From 1778e685ac768ca38d4fa6cfa2ed12659dde9b7d Mon Sep 17 00:00:00 2001 From: wraitii Date: Sun, 10 Mar 2013 20:28:01 +0000 Subject: [PATCH] Improve detection of when a component needs to be interpolated. Patch by sbte. Fixes #1858. This was SVN commit r13251. --- .../simulation2/components/CCmpPosition.cpp | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp index e1f92df2f6..a7eafca13e 100644 --- a/source/simulation2/components/CCmpPosition.cpp +++ b/source/simulation2/components/CCmpPosition.cpp @@ -72,7 +72,7 @@ public: entity_pos_t m_YOffset; bool m_RelativeToGround; // whether m_YOffset is relative to terrain/water plane, or an absolute height - entity_angle_t m_RotX, m_RotY, m_RotZ; + entity_angle_t m_RotX, m_RotY, m_LastRotY, m_PrevRotY, m_RotZ; float m_InterpolatedRotY; // not serialized static std::string GetSchema() @@ -121,10 +121,11 @@ public: m_RotYSpeed = paramNode.GetChild("TurnRate").ToFixed().ToFloat(); - m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0); + m_RotX = m_RotY = m_RotZ = m_PrevRotY = m_LastRotY = entity_angle_t::FromInt(0); m_InterpolatedRotY = 0; m_PositionChanged = false; + m_Interpolated = false; } virtual void Deinit() @@ -329,6 +330,8 @@ public: virtual void SetYRotation(entity_angle_t y) { m_RotY = y; + m_PrevRotY = y; + m_LastRotY = y; m_InterpolatedRotY = m_RotY.ToFloat(); AdvertisePositionChanges(); @@ -431,6 +434,10 @@ public: { case MT_Interpolate: { + m_Interpolated = true; + if (!m_PositionChanged) + return; + const CMessageInterpolate& msgData = static_cast (msg); float rotY = m_RotY.ToFloat(); @@ -444,10 +451,6 @@ public: // Calculate new orientation, in a peculiar way in order to make sure the // result gets close to m_orientation (rather than being n*2*M_PI out) m_InterpolatedRotY = rotY + deltaClamped - delta; - - // Anything smaller than this will not be visible - if (abs(delta) > 0.0001) - m_PositionChanged = true; break; } @@ -456,11 +459,14 @@ public: // Store the positions from the turn before m_PrevX = m_LastX; m_PrevZ = m_LastZ; - + m_PrevRotY = m_LastRotY; + m_LastX = m_X; m_LastZ = m_Z; + m_LastRotY = m_RotY; - m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ; + m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ || m_RotY != m_PrevRotY || !m_Interpolated; + m_Interpolated = false; break; } @@ -489,6 +495,7 @@ private: } bool m_PositionChanged; + bool m_Interpolated; }; REGISTER_COMPONENT_TYPE(Position)