From 82e16d1cf9903a78d603566794efdd0093b3b63a Mon Sep 17 00:00:00 2001
From: "Sven (Sbte)" <svenb.linux@gmail.com>
Date: Sun, 24 Feb 2013 15:59:54 +0100
Subject: Don't reinterpolate if the position of a component does not change
---
source/simulation2/components/CCmpPosition.cpp | 12 ++++++++++++
source/simulation2/components/CCmpVisualActor.cpp | 8 ++++++++
source/simulation2/components/ICmpPosition.cpp | 1 +
source/simulation2/components/ICmpPosition.h | 2 ++
source/simulation2/components/tests/test_RangeManager.h | 1 +
5 files changed, 24 insertions(+)
diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp
index 80c72d9..97110dc 100644
a
|
b
|
public:
|
123 | 123 | |
124 | 124 | m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0); |
125 | 125 | m_InterpolatedRotY = 0; |
| 126 | |
| 127 | m_PositionChanged = false; |
126 | 128 | } |
127 | 129 | |
128 | 130 | virtual void Deinit() |
… |
… |
public:
|
454 | 456 | m_LastX = m_X; |
455 | 457 | m_LastZ = m_Z; |
456 | 458 | |
| 459 | m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ; |
| 460 | |
457 | 461 | break; |
458 | 462 | } |
459 | 463 | } |
460 | 464 | } |
461 | 465 | |
| 466 | virtual bool GetReinterpolate() |
| 467 | { |
| 468 | return m_PositionChanged; |
| 469 | } |
| 470 | |
462 | 471 | private: |
463 | 472 | void AdvertisePositionChanges() |
464 | 473 | { |
… |
… |
private:
|
472 | 481 | CMessagePositionChanged msg(GetEntityId(), false, entity_pos_t::Zero(), entity_pos_t::Zero(), entity_angle_t::Zero()); |
473 | 482 | GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); |
474 | 483 | } |
| 484 | m_PositionChanged = true; |
475 | 485 | } |
| 486 | |
| 487 | bool m_PositionChanged; |
476 | 488 | }; |
477 | 489 | |
478 | 490 | REGISTER_COMPONENT_TYPE(Position) |
diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp
index 376ddbb..d6b4c88 100644
a
|
b
|
|
44 | 44 | #include "ps/CLogger.h" |
45 | 45 | #include "renderer/Scene.h" |
46 | 46 | |
| 47 | #include "tools/atlas/GameInterface/GameLoop.h" |
| 48 | |
47 | 49 | class CCmpVisualActor : public ICmpVisual |
48 | 50 | { |
49 | 51 | public: |
… |
… |
void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)
|
733 | 735 | UpdateVisibility(); |
734 | 736 | m_PreviouslyRendered = true; |
735 | 737 | } |
| 738 | else if (!cmpPosition->GetReinterpolate() && m_ConstructionProgress.IsZero() && |
| 739 | !g_AtlasGameLoop->running) |
| 740 | { |
| 741 | m_Unit->UpdateModel(frameTime); |
| 742 | return; |
| 743 | } |
736 | 744 | |
737 | 745 | // Even if HIDDEN due to LOS, we need to set up the transforms |
738 | 746 | // 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 9aaeecc..4b73667 100644
a
|
b
|
DEFINE_INTERFACE_METHOD_1("TurnTo", void, ICmpPosition, TurnTo, entity_angle_t)
|
38 | 38 | DEFINE_INTERFACE_METHOD_1("SetYRotation", void, ICmpPosition, SetYRotation, entity_angle_t) |
39 | 39 | DEFINE_INTERFACE_METHOD_2("SetXZRotation", void, ICmpPosition, SetXZRotation, entity_angle_t, entity_angle_t) |
40 | 40 | DEFINE_INTERFACE_METHOD_0("GetRotation", CFixedVector3D, ICmpPosition, GetRotation) |
| 41 | DEFINE_INTERFACE_METHOD_0("GetReinterpolate", bool, ICmpPosition, GetReinterpolate) |
41 | 42 | // Excluded: GetInterpolatedTransform (not safe for scripts) |
42 | 43 | END_INTERFACE_WRAPPER(Position) |
diff --git a/source/simulation2/components/ICmpPosition.h b/source/simulation2/components/ICmpPosition.h
index 3e454ce..39c9a0e 100644
a
|
b
|
public:
|
168 | 168 | */ |
169 | 169 | virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) = 0; |
170 | 170 | |
| 171 | virtual bool GetReinterpolate() = 0; |
| 172 | |
171 | 173 | DECLARE_INTERFACE_TYPE(Position) |
172 | 174 | }; |
173 | 175 | |
diff --git a/source/simulation2/components/tests/test_RangeManager.h b/source/simulation2/components/tests/test_RangeManager.h
index cf2ee71..f8328dc 100644
a
|
b
|
public:
|
59 | 59 | virtual fixed GetDistanceTravelled() { return fixed::Zero(); } |
60 | 60 | virtual void GetInterpolatedPosition2D(float UNUSED(frameOffset), float& x, float& z, float& rotY) { x = z = rotY = 0; } |
61 | 61 | virtual CMatrix3D GetInterpolatedTransform(float UNUSED(frameOffset), bool UNUSED(forceFloating)) { return CMatrix3D(); } |
| 62 | virtual bool GetReinterpolate() { return true; } |
62 | 63 | }; |
63 | 64 | |
64 | 65 | class TestCmpRangeManager : public CxxTest::TestSuite |