diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp index 80c72d9fbb..97110dc4ee 100644 --- a/source/simulation2/components/CCmpPosition.cpp +++ b/source/simulation2/components/CCmpPosition.cpp @@ -123,6 +123,8 @@ public: m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0); m_InterpolatedRotY = 0; + + m_PositionChanged = false; } virtual void Deinit() @@ -454,11 +456,18 @@ public: m_LastX = m_X; m_LastZ = m_Z; + m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ; + break; } } } + virtual bool GetReinterpolate() + { + return m_PositionChanged; + } + private: void AdvertisePositionChanges() { @@ -472,7 +481,10 @@ private: CMessagePositionChanged msg(GetEntityId(), false, entity_pos_t::Zero(), entity_pos_t::Zero(), entity_angle_t::Zero()); GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); } + m_PositionChanged = true; } + + bool m_PositionChanged; }; REGISTER_COMPONENT_TYPE(Position) diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp index 376ddbbee2..fed3044fb5 100644 --- a/source/simulation2/components/CCmpVisualActor.cpp +++ b/source/simulation2/components/CCmpVisualActor.cpp @@ -44,6 +44,8 @@ #include "ps/CLogger.h" #include "renderer/Scene.h" +#include "tools/atlas/GameInterface/GameLoop.h" + class CCmpVisualActor : public ICmpVisual { public: @@ -733,6 +735,14 @@ void CCmpVisualActor::Interpolate(float frameTime, float frameOffset) UpdateVisibility(); m_PreviouslyRendered = true; } + else if (!cmpPosition->GetReinterpolate() && m_ConstructionProgress.IsZero() && + !g_AtlasGameLoop->running) + { + // Position hasn't changed so skip most of the work. Special cases are when placing a building or being + // in atlas (since terrain height can change in atlas) + m_Unit->UpdateModel(frameTime); + return; + } // Even if HIDDEN due to LOS, we need to set up the transforms // so that projectiles will be launched from the right place diff --git a/source/simulation2/components/ICmpPosition.cpp b/source/simulation2/components/ICmpPosition.cpp index 9aaeecc801..4b73667542 100644 --- a/source/simulation2/components/ICmpPosition.cpp +++ b/source/simulation2/components/ICmpPosition.cpp @@ -38,5 +38,6 @@ DEFINE_INTERFACE_METHOD_1("TurnTo", void, ICmpPosition, TurnTo, entity_angle_t) DEFINE_INTERFACE_METHOD_1("SetYRotation", void, ICmpPosition, SetYRotation, entity_angle_t) DEFINE_INTERFACE_METHOD_2("SetXZRotation", void, ICmpPosition, SetXZRotation, entity_angle_t, entity_angle_t) DEFINE_INTERFACE_METHOD_0("GetRotation", CFixedVector3D, ICmpPosition, GetRotation) +DEFINE_INTERFACE_METHOD_0("GetReinterpolate", bool, ICmpPosition, GetReinterpolate) // Excluded: GetInterpolatedTransform (not safe for scripts) END_INTERFACE_WRAPPER(Position) diff --git a/source/simulation2/components/ICmpPosition.h b/source/simulation2/components/ICmpPosition.h index 3e454ced41..39c9a0e90f 100644 --- a/source/simulation2/components/ICmpPosition.h +++ b/source/simulation2/components/ICmpPosition.h @@ -168,6 +168,8 @@ public: */ virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) = 0; + virtual bool GetReinterpolate() = 0; + DECLARE_INTERFACE_TYPE(Position) }; diff --git a/source/simulation2/components/tests/test_RangeManager.h b/source/simulation2/components/tests/test_RangeManager.h index cf2ee7134d..786b2d64ed 100644 --- a/source/simulation2/components/tests/test_RangeManager.h +++ b/source/simulation2/components/tests/test_RangeManager.h @@ -59,6 +59,7 @@ public: virtual fixed GetDistanceTravelled() { return fixed::Zero(); } virtual void GetInterpolatedPosition2D(float UNUSED(frameOffset), float& x, float& z, float& rotY) { x = z = rotY = 0; } virtual CMatrix3D GetInterpolatedTransform(float UNUSED(frameOffset), bool UNUSED(forceFloating)) { return CMatrix3D(); } + virtual bool GetReinterpolate() { return true; } }; class TestCmpRangeManager : public CxxTest::TestSuite