From 510763d591eeca4e2cb39747fd818e50e7aec216 Mon Sep 17 00:00:00 2001
From: "Sven (Sbte)" <svenb.linux@gmail.com>
Date: Sun, 17 Mar 2013 23:47:25 +0100
Subject: Move checking for reinterpolation after a position has changed to
VisualActor
---
source/simulation2/components/CCmpPosition.cpp | 27 ++-------------
source/simulation2/components/CCmpVisualActor.cpp | 40 +++++++++++++++++-----
source/simulation2/components/ICmpPosition.cpp | 1 -
source/simulation2/components/ICmpPosition.h | 2 --
.../components/tests/test_RangeManager.h | 1 -
5 files changed, 34 insertions(+), 37 deletions(-)
diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp
index 3634187..57fcb1b 100644
a
|
b
|
public:
|
72 | 72 | entity_pos_t m_YOffset; |
73 | 73 | bool m_RelativeToGround; // whether m_YOffset is relative to terrain/water plane, or an absolute height |
74 | 74 | |
75 | | entity_angle_t m_RotX, m_RotY, m_LastRotY, m_PrevRotY, m_RotZ; |
| 75 | entity_angle_t m_RotX, m_RotY, m_RotZ; |
76 | 76 | float m_InterpolatedRotY; // not serialized |
77 | 77 | |
78 | 78 | static std::string GetSchema() |
… |
… |
public:
|
121 | 121 | |
122 | 122 | m_RotYSpeed = paramNode.GetChild("TurnRate").ToFixed().ToFloat(); |
123 | 123 | |
124 | | m_RotX = m_RotY = m_RotZ = m_PrevRotY = m_LastRotY = entity_angle_t::FromInt(0); |
| 124 | m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0); |
125 | 125 | m_InterpolatedRotY = 0; |
126 | | |
127 | | m_PositionChanged = false; |
128 | | m_Interpolated = false; |
129 | 126 | } |
130 | 127 | |
131 | 128 | virtual void Deinit() |
… |
… |
public:
|
330 | 327 | virtual void SetYRotation(entity_angle_t y) |
331 | 328 | { |
332 | 329 | m_RotY = y; |
333 | | m_PrevRotY = y; |
334 | | m_LastRotY = y; |
335 | 330 | m_InterpolatedRotY = m_RotY.ToFloat(); |
336 | 331 | |
337 | 332 | AdvertisePositionChanges(); |
… |
… |
public:
|
422 | 417 | { |
423 | 418 | case MT_Interpolate: |
424 | 419 | { |
425 | | m_Interpolated = true; |
426 | | if (!m_PositionChanged) |
427 | | return; |
428 | | |
429 | 420 | const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); |
430 | 421 | |
431 | 422 | float rotY = m_RotY.ToFloat(); |
… |
… |
public:
|
447 | 438 | // Store the positions from the turn before |
448 | 439 | m_PrevX = m_LastX; |
449 | 440 | m_PrevZ = m_LastZ; |
450 | | m_PrevRotY = m_LastRotY; |
451 | 441 | |
452 | 442 | m_LastX = m_X; |
453 | 443 | m_LastZ = m_Z; |
454 | | m_LastRotY = m_RotY; |
455 | | |
456 | | m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ || m_RotY != m_PrevRotY || !m_Interpolated; |
457 | | m_Interpolated = false; |
458 | 444 | |
459 | 445 | break; |
460 | 446 | } |
461 | 447 | } |
462 | 448 | } |
463 | 449 | |
464 | | virtual bool GetReinterpolate() |
465 | | { |
466 | | return m_PositionChanged; |
467 | | } |
468 | | |
469 | 450 | private: |
470 | 451 | void AdvertisePositionChanges() |
471 | 452 | { |
… |
… |
private:
|
479 | 460 | CMessagePositionChanged msg(GetEntityId(), false, entity_pos_t::Zero(), entity_pos_t::Zero(), entity_angle_t::Zero()); |
480 | 461 | GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); |
481 | 462 | } |
482 | | m_PositionChanged = true; |
483 | 463 | } |
484 | | |
485 | | bool m_PositionChanged; |
486 | | bool m_Interpolated; |
487 | 464 | }; |
488 | 465 | |
489 | 466 | REGISTER_COMPONENT_TYPE(Position) |
diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp
index fed3044..51ec089 100644
a
|
b
|
public:
|
55 | 55 | componentManager.SubscribeToMessageType(MT_Interpolate); |
56 | 56 | componentManager.SubscribeToMessageType(MT_RenderSubmit); |
57 | 57 | componentManager.SubscribeToMessageType(MT_OwnershipChanged); |
| 58 | componentManager.SubscribeToMessageType(MT_PositionChanged); |
| 59 | componentManager.SubscribeToMessageType(MT_TurnStart); |
58 | 60 | componentManager.SubscribeGloballyToMessageType(MT_TerrainChanged); |
59 | 61 | } |
60 | 62 | |
… |
… |
public:
|
83 | 85 | bool m_ConstructionPreview; |
84 | 86 | fixed m_ConstructionProgress; |
85 | 87 | |
| 88 | bool m_Interpolated; |
| 89 | bool m_PositionChanged; |
| 90 | |
86 | 91 | static std::string GetSchema() |
87 | 92 | { |
88 | 93 | return |
… |
… |
public:
|
172 | 177 | |
173 | 178 | // We need to select animation even if graphics are disabled, as this modifies serialized state |
174 | 179 | SelectAnimation("idle", false, fixed::FromInt(1), L""); |
| 180 | |
| 181 | m_Interpolated = false; |
| 182 | m_PositionChanged = true; |
175 | 183 | } |
176 | 184 | |
177 | 185 | virtual void Deinit() |
… |
… |
public:
|
285 | 293 | m_Unit->GetModel().SetTerrainDirty(msgData.i0, msgData.j0, msgData.i1, msgData.j1); |
286 | 294 | break; |
287 | 295 | } |
| 296 | case MT_PositionChanged: |
| 297 | { |
| 298 | // The position was changed, so we need to interpolate again |
| 299 | m_PositionChanged = true; |
| 300 | m_Interpolated = false; |
| 301 | break; |
| 302 | } |
| 303 | case MT_TurnStart: |
| 304 | { |
| 305 | // Check whether we need to reinterpolate during this turn |
| 306 | m_Interpolated = !m_PositionChanged && m_Interpolated; |
| 307 | m_PositionChanged = false; |
| 308 | break; |
| 309 | } |
288 | 310 | } |
289 | 311 | } |
290 | 312 | |
… |
… |
void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)
|
726 | 748 | if (m_Unit == NULL) |
727 | 749 | return; |
728 | 750 | |
| 751 | if (m_Interpolated && m_ConstructionProgress.IsZero() && !g_AtlasGameLoop->running) |
| 752 | { |
| 753 | // Position hasn't changed so skip most of the work. Special cases are when placing a building or being |
| 754 | // in atlas (since terrain height can change in atlas) |
| 755 | m_Unit->UpdateModel(frameTime); |
| 756 | return; |
| 757 | } |
| 758 | |
729 | 759 | // Disable rendering of the unit if it has no position |
730 | 760 | CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId()); |
731 | 761 | if (!cmpPosition || !cmpPosition->IsInWorld()) |
… |
… |
void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)
|
735 | 765 | UpdateVisibility(); |
736 | 766 | m_PreviouslyRendered = true; |
737 | 767 | } |
738 | | else if (!cmpPosition->GetReinterpolate() && m_ConstructionProgress.IsZero() && |
739 | | !g_AtlasGameLoop->running) |
740 | | { |
741 | | // Position hasn't changed so skip most of the work. Special cases are when placing a building or being |
742 | | // in atlas (since terrain height can change in atlas) |
743 | | m_Unit->UpdateModel(frameTime); |
744 | | return; |
745 | | } |
| 768 | |
| 769 | m_Interpolated = !m_PositionChanged; |
746 | 770 | |
747 | 771 | // Even if HIDDEN due to LOS, we need to set up the transforms |
748 | 772 | // 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 4b73667..9aaeecc 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) |
42 | 41 | // Excluded: GetInterpolatedTransform (not safe for scripts) |
43 | 42 | END_INTERFACE_WRAPPER(Position) |
diff --git a/source/simulation2/components/ICmpPosition.h b/source/simulation2/components/ICmpPosition.h
index 39c9a0e..3e454ce 100644
a
|
b
|
public:
|
168 | 168 | */ |
169 | 169 | virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) = 0; |
170 | 170 | |
171 | | virtual bool GetReinterpolate() = 0; |
172 | | |
173 | 171 | DECLARE_INTERFACE_TYPE(Position) |
174 | 172 | }; |
175 | 173 | |
diff --git a/source/simulation2/components/tests/test_RangeManager.h b/source/simulation2/components/tests/test_RangeManager.h
index 786b2d6..cf2ee71 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; } |
63 | 62 | }; |
64 | 63 | |
65 | 64 | class TestCmpRangeManager : public CxxTest::TestSuite |