From 123192db10cdf5244f27d08256ece738f60a9e2c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 4 May 2018 10:23:02 -0400 Subject: Unferried players while changing maps This fixes the third problem described in 8f1c4f1 -- that if a ferried body's transform is modified outside of the PonderingSystem, it will not be unferried as appropriate. This does still require that any future code that modifies a body's transform also unferries the body first. --- src/systems/playing.cpp | 8 +++----- src/systems/pondering.cpp | 26 +++++++++++++++++++------- src/systems/pondering.h | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/systems/playing.cpp b/src/systems/playing.cpp index b04f0cb..acec4e7 100644 --- a/src/systems/playing.cpp +++ b/src/systems/playing.cpp @@ -79,11 +79,7 @@ void PlayingSystem::changeMap( auto& transformable = game_.getEntityManager(). getComponent(player); - auto& animatable = game_.getEntityManager(). - getComponent(player); - - auto& ponderable = game_.getEntityManager(). - getComponent(player); + auto& pondering = game_.getSystemManager().getSystem(); auto& realizing = game_.getSystemManager().getSystem(); @@ -105,6 +101,8 @@ void PlayingSystem::changeMap( playable.mapId = newMapEntity; } + pondering.unferry(player); + transformable.x = x; transformable.y = y; diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index ccfd66f..4aa47f2 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp @@ -655,7 +655,7 @@ void PonderingSystem::tick(double dt) } } - // Handle ferry passengers + // Ferry or unferry as necessary if ((ponderable.type == PonderableComponent::Type::freefalling) && (ponderable.grounded != oldGrounded)) { @@ -674,15 +674,11 @@ void PonderingSystem::tick(double dt) } else if (ponderable.ferried) { // The body is no longer being ferried - ponderable.ferried = false; - - auto& ferryPonder = game_.getEntityManager(). - getComponent(ponderable.ferry); - - ferryPonder.passengers.erase(entity); + unferry(entity); } } + // Update a ferry passenger's relative position if (ponderable.ferried) { auto& ferryTrans = game_.getEntityManager(). @@ -768,6 +764,22 @@ void PonderingSystem::initPrototype(id_type prototype) ponderable.passengers.clear(); } +void PonderingSystem::unferry(id_type entity) +{ + auto& ponderable = game_.getEntityManager(). + getComponent(entity); + + if (ponderable.ferried) + { + ponderable.ferried = false; + + auto& ferryPonder = game_.getEntityManager(). + getComponent(ponderable.ferry); + + ferryPonder.passengers.erase(entity); + } +} + void PonderingSystem::processCollision( id_type entity, id_type collider, diff --git a/src/systems/pondering.h b/src/systems/pondering.h index b195814..adc0cda 100644 --- a/src/systems/pondering.h +++ b/src/systems/pondering.h @@ -16,8 +16,22 @@ public: void initializeBody(id_type entity, PonderableComponent::Type type); + /** + * Initializes a ponderable map object from its prototype data. + * + * @requires entity is ponderable + * @requires entity is a map object + */ void initPrototype(id_type prototype); + /** + * Unferries an entity if it is a passenger of another entity. Use before + * moving a ponderable entity outside the PonderingSystem. + * + * @requires entity is ponderable + */ + void unferry(id_type entity); + private: struct CollisionResult -- cgit 1.4.1