Ticket #1865: 0003-Move-checking-for-reinterpolation-after-a-position-h.2.patch
File 0003-Move-checking-for-reinterpolation-after-a-position-h.2.patch, 7.2 KB (added by , 11 years ago) |
---|
-
source/simulation2/components/CCmpPosition.cpp
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() … … 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() … … 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(); … … 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(); … … 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 444 456 m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ || m_RotY != m_PrevRotY || !m_Interpolated;457 m_Interpolated = false;458 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 { … … 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) -
source/simulation2/components/CCmpVisualActor.cpp
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 … … 83 85 bool m_ConstructionPreview; 84 86 fixed m_ConstructionProgress; 85 87 88 bool m_NeedsInterpolation; 89 bool m_PositionChanged; 90 86 91 static std::string GetSchema() 87 92 { 88 93 return … … 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_NeedsInterpolation = true; 182 m_PositionChanged = true; 175 183 } 176 184 177 185 virtual void Deinit() … … 283 291 { 284 292 const CMessageTerrainChanged& msgData = static_cast<const CMessageTerrainChanged&> (msg); 285 293 m_Unit->GetModel().SetTerrainDirty(msgData.i0, msgData.j0, msgData.i1, msgData.j1); 294 // Terrain has changed, so we need to interpolate again 295 m_NeedsInterpolation = true; 286 296 break; 287 297 } 298 case MT_PositionChanged: 299 { 300 // The position was changed, so we need to interpolate again 301 m_PositionChanged = true; 302 m_NeedsInterpolation = true; 303 break; 288 304 } 305 case MT_TurnStart: 306 { 307 // Check whether we need to reinterpolate during this turn 308 m_NeedsInterpolation = m_PositionChanged || m_NeedsInterpolation; 309 m_PositionChanged = false; 310 break; 311 } 312 } 289 313 } 290 314 291 315 virtual CBoundingBoxAligned GetBounds() … … 453 477 454 478 virtual void SetConstructionProgress(fixed progress) 455 479 { 456 m_ConstructionProgress = progress; 480 if (progress != m_ConstructionProgress) 481 { 482 m_ConstructionProgress = progress; 483 // Visual height changed, so we need to interpolate again 484 m_NeedsInterpolation = true; 485 } 457 486 } 458 487 459 488 virtual void Hotload(const VfsPath& name) … … 726 755 if (m_Unit == NULL) 727 756 return; 728 757 758 if (!m_NeedsInterpolation) 759 { 760 // Position hasn't changed so skip most of the work 761 m_Unit->UpdateModel(frameTime); 762 return; 763 } 764 729 765 // Disable rendering of the unit if it has no position 730 766 CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId()); 731 767 if (!cmpPosition || !cmpPosition->IsInWorld()) … … 735 771 UpdateVisibility(); 736 772 m_PreviouslyRendered = true; 737 773 } 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 being742 // in atlas (since terrain height can change in atlas)743 m_Unit->UpdateModel(frameTime);744 return;745 }746 774 775 m_NeedsInterpolation = m_PositionChanged; 776 747 777 // Even if HIDDEN due to LOS, we need to set up the transforms 748 778 // so that projectiles will be launched from the right place 749 779 -
source/simulation2/components/ICmpPosition.cpp
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) -
source/simulation2/components/ICmpPosition.h
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 -
source/simulation2/components/tests/test_RangeManager.h
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