From c1911c9339f99f86946604dba66fdd24bf4b7859 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 | 34 +++++++++++++++++-----
source/simulation2/components/ICmpPosition.cpp | 1 -
source/simulation2/components/ICmpPosition.h | 2 --
.../components/tests/test_RangeManager.h | 1 -
5 files changed, 28 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..a541866 100644
a
|
b
|
|
42 | 42 | #include "maths/Matrix3D.h" |
43 | 43 | #include "maths/Vector3D.h" |
44 | 44 | #include "ps/CLogger.h" |
| 45 | #include "ps/Game.h" |
| 46 | #include "network/NetTurnManager.h" |
45 | 47 | #include "renderer/Scene.h" |
46 | 48 | |
47 | 49 | #include "tools/atlas/GameInterface/GameLoop.h" |
… |
… |
public:
|
55 | 57 | componentManager.SubscribeToMessageType(MT_Interpolate); |
56 | 58 | componentManager.SubscribeToMessageType(MT_RenderSubmit); |
57 | 59 | componentManager.SubscribeToMessageType(MT_OwnershipChanged); |
| 60 | componentManager.SubscribeToMessageType(MT_PositionChanged); |
58 | 61 | componentManager.SubscribeGloballyToMessageType(MT_TerrainChanged); |
59 | 62 | } |
60 | 63 | |
… |
… |
public:
|
83 | 86 | bool m_ConstructionPreview; |
84 | 87 | fixed m_ConstructionProgress; |
85 | 88 | |
| 89 | bool m_Interpolated; |
| 90 | u32 m_PositionChangedTurn; |
| 91 | |
86 | 92 | static std::string GetSchema() |
87 | 93 | { |
88 | 94 | return |
… |
… |
public:
|
172 | 178 | |
173 | 179 | // We need to select animation even if graphics are disabled, as this modifies serialized state |
174 | 180 | SelectAnimation("idle", false, fixed::FromInt(1), L""); |
| 181 | |
| 182 | m_Interpolated = false; |
| 183 | m_PositionChangedTurn = 0; |
175 | 184 | } |
176 | 185 | |
177 | 186 | virtual void Deinit() |
… |
… |
public:
|
285 | 294 | m_Unit->GetModel().SetTerrainDirty(msgData.i0, msgData.j0, msgData.i1, msgData.j1); |
286 | 295 | break; |
287 | 296 | } |
| 297 | case MT_PositionChanged: |
| 298 | { |
| 299 | // The position was changed, so we need to interpolate again |
| 300 | m_PositionChangedTurn = g_Game->GetTurnManager()->GetCurrentTurn(); |
| 301 | m_Interpolated = false; |
| 302 | break; |
| 303 | } |
288 | 304 | } |
289 | 305 | } |
290 | 306 | |
… |
… |
void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)
|
726 | 742 | if (m_Unit == NULL) |
727 | 743 | return; |
728 | 744 | |
| 745 | if (m_Interpolated && m_ConstructionProgress.IsZero() && !g_AtlasGameLoop->running) |
| 746 | { |
| 747 | // Position hasn't changed so skip most of the work. Special cases are when placing a building or being |
| 748 | // in atlas (since terrain height can change in atlas) |
| 749 | m_Unit->UpdateModel(frameTime); |
| 750 | return; |
| 751 | } |
| 752 | |
729 | 753 | // Disable rendering of the unit if it has no position |
730 | 754 | CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId()); |
731 | 755 | if (!cmpPosition || !cmpPosition->IsInWorld()) |
… |
… |
void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)
|
735 | 759 | UpdateVisibility(); |
736 | 760 | m_PreviouslyRendered = true; |
737 | 761 | } |
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 | | } |
| 762 | |
| 763 | m_Interpolated = (g_Game->GetTurnManager()->GetCurrentTurn() > m_PositionChangedTurn); |
746 | 764 | |
747 | 765 | // Even if HIDDEN due to LOS, we need to set up the transforms |
748 | 766 | // 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 |