From 028a5735c5f98aa10718c94de07d2f4b4c1fa6b3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 29 Sep 2021 23:17:03 +0100 Subject: Spectation: add dedicated pathway for spectator mode (#5303) * Spectation: add dedicated pathway for spectator mode + Sync player rotation with spectated entity. + Add dedicated infrastructure to cPlayer for handling spectation, instead of misusing entity riding. * Avoid infinite recursion when exiting spectation, fixes #5296 * AttachTo: Change parameter to reference --- src/Entities/Boat.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/Entities/Boat.cpp') diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index cd66c523b..9ad0dd5f9 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -17,17 +17,18 @@ class cBoatCollisionCallback { public: - cBoatCollisionCallback(cBoat * a_Boat, cEntity * a_Attachee) : + + cBoatCollisionCallback(cBoat & a_Boat, cEntity * a_Attachee) : m_Boat(a_Boat), m_Attachee(a_Attachee) { } bool operator()(cEntity & a_Entity) { - // Checks if boat is empty and if given entity is a mob - if ((m_Attachee == nullptr) && (a_Entity.IsMob())) + // Checks if boat is empty and if given entity is a mob: + if ((m_Attachee == nullptr) && a_Entity.IsMob()) { - // if so attach and return true + // If so attach and stop iterating: a_Entity.AttachTo(m_Boat); return true; } @@ -36,7 +37,8 @@ public: } protected: - cBoat * m_Boat; + + cBoat & m_Boat; cEntity * m_Attachee; }; @@ -159,7 +161,7 @@ void cBoat::OnRightClicked(cPlayer & a_Player) } // Attach the player to this boat - a_Player.AttachTo(this); + a_Player.AttachTo(*this); } @@ -349,7 +351,7 @@ void cBoat::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) normal physics calcualtions */ // Calculate boat's bounding box, run collision callback on all entities in said box - cBoatCollisionCallback BoatCollisionCallback(this, m_Attachee); + cBoatCollisionCallback BoatCollisionCallback(*this, m_Attachee); Vector3d BoatPosition = GetPosition(); cBoundingBox bbBoat( Vector3d(BoatPosition.x, floor(BoatPosition.y), BoatPosition.z), GetWidth() / 2, GetHeight()); -- cgit v1.2.3