diff --git a/src/mover.cpp b/src/mover.cpp index 11b985e..7316074 100644 --- a/src/mover.cpp +++ b/src/mover.cpp @@ -1,7 +1,6 @@ #include "mover.hpp" #include "placeable.hpp" #include -#include namespace cloonel { ///-------------------------------------------------------------------------- @@ -13,26 +12,4 @@ namespace cloonel { } } } - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - int Mover::RegisterPlaceable (Placeable* parPlaceable) { - assert(parPlaceable); - m_placeables.push_back(parPlaceable); - const std::size_t retVal = m_placeables.size(); - return static_cast(retVal); - } - - ///-------------------------------------------------------------------------- - ///-------------------------------------------------------------------------- - void Mover::UnregisterPlaceable (int parID) { - assert(static_cast(parID) <= m_placeables.size()); - assert(m_placeables[parID - 1]); - - m_placeables[parID - 1] = nullptr; - auto lastNull = std::find_if(m_placeables.rbegin(), m_placeables.rend(), [](const Placeable* parPlaceable) { return nullptr != parPlaceable; }); - if (m_placeables.rend() != lastNull) { - m_placeables.resize(m_placeables.size() - (lastNull - m_placeables.rbegin()) + 1); - } - } } //namespace cloonel diff --git a/src/mover.hpp b/src/mover.hpp index c082928..394c7c5 100644 --- a/src/mover.hpp +++ b/src/mover.hpp @@ -2,19 +2,21 @@ #define id20409B43E62B4247A278B413D1114896 #include "vector.hpp" -#include +#include "observersmanager.hpp" namespace cloonel { class Placeable; class Mover { public: + typedef ObserversManager::TicketType PlaceableTicketType; + Mover ( void ) = default; virtual ~Mover ( void ) noexcept = default; virtual void ApplyMotion ( float parDelta ) = 0; - int RegisterPlaceable ( Placeable* parPlaceable ); - void UnregisterPlaceable ( int parID ); + PlaceableTicketType RegisterPlaceable ( Placeable* parPlaceable ) { return m_placeables.Add(parPlaceable); } + void UnregisterPlaceable ( PlaceableTicketType parID ) noexcept { m_placeables.Remove(parID); } protected: virtual void Update ( float parDelta ) = 0; @@ -22,7 +24,7 @@ namespace cloonel { void ApplyOffsetToPlaceables ( const float2& parOffset ); private: - std::vector m_placeables; + ObserversManager m_placeables; }; } //namespace cloonel