1
0
forked from 0ad/0ad

Only use interpolation for moving objects in VisualActor. Patch by sbte. Fixes #1846.

This was SVN commit r13223.
This commit is contained in:
Jonathan Waller 2013-03-05 20:02:16 +00:00
parent 121fb35f72
commit 21f13f9683
5 changed files with 26 additions and 0 deletions

View File

@ -123,6 +123,8 @@ public:
m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0); m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0);
m_InterpolatedRotY = 0; m_InterpolatedRotY = 0;
m_PositionChanged = false;
} }
virtual void Deinit() virtual void Deinit()
@ -454,11 +456,18 @@ public:
m_LastX = m_X; m_LastX = m_X;
m_LastZ = m_Z; m_LastZ = m_Z;
m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ;
break; break;
} }
} }
} }
virtual bool GetReinterpolate()
{
return m_PositionChanged;
}
private: private:
void AdvertisePositionChanges() void AdvertisePositionChanges()
{ {
@ -472,7 +481,10 @@ private:
CMessagePositionChanged msg(GetEntityId(), false, entity_pos_t::Zero(), entity_pos_t::Zero(), entity_angle_t::Zero()); CMessagePositionChanged msg(GetEntityId(), false, entity_pos_t::Zero(), entity_pos_t::Zero(), entity_angle_t::Zero());
GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg);
} }
m_PositionChanged = true;
} }
bool m_PositionChanged;
}; };
REGISTER_COMPONENT_TYPE(Position) REGISTER_COMPONENT_TYPE(Position)

View File

@ -44,6 +44,8 @@
#include "ps/CLogger.h" #include "ps/CLogger.h"
#include "renderer/Scene.h" #include "renderer/Scene.h"
#include "tools/atlas/GameInterface/GameLoop.h"
class CCmpVisualActor : public ICmpVisual class CCmpVisualActor : public ICmpVisual
{ {
public: public:
@ -733,6 +735,14 @@ void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)
UpdateVisibility(); UpdateVisibility();
m_PreviouslyRendered = true; 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 // Even if HIDDEN due to LOS, we need to set up the transforms
// so that projectiles will be launched from the right place // so that projectiles will be launched from the right place

View File

@ -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_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_2("SetXZRotation", void, ICmpPosition, SetXZRotation, entity_angle_t, entity_angle_t)
DEFINE_INTERFACE_METHOD_0("GetRotation", CFixedVector3D, ICmpPosition, GetRotation) DEFINE_INTERFACE_METHOD_0("GetRotation", CFixedVector3D, ICmpPosition, GetRotation)
DEFINE_INTERFACE_METHOD_0("GetReinterpolate", bool, ICmpPosition, GetReinterpolate)
// Excluded: GetInterpolatedTransform (not safe for scripts) // Excluded: GetInterpolatedTransform (not safe for scripts)
END_INTERFACE_WRAPPER(Position) END_INTERFACE_WRAPPER(Position)

View File

@ -168,6 +168,8 @@ public:
*/ */
virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) = 0; virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) = 0;
virtual bool GetReinterpolate() = 0;
DECLARE_INTERFACE_TYPE(Position) DECLARE_INTERFACE_TYPE(Position)
}; };

View File

@ -59,6 +59,7 @@ public:
virtual fixed GetDistanceTravelled() { return fixed::Zero(); } virtual fixed GetDistanceTravelled() { return fixed::Zero(); }
virtual void GetInterpolatedPosition2D(float UNUSED(frameOffset), float& x, float& z, float& rotY) { x = z = rotY = 0; } 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 CMatrix3D GetInterpolatedTransform(float UNUSED(frameOffset), bool UNUSED(forceFloating)) { return CMatrix3D(); }
virtual bool GetReinterpolate() { return true; }
}; };
class TestCmpRangeManager : public CxxTest::TestSuite class TestCmpRangeManager : public CxxTest::TestSuite