Using the new ObserversManager.

This commit is contained in:
King_DuckZ 2014-02-21 23:13:15 +01:00
parent 402681762a
commit e2bd48ec90
2 changed files with 6 additions and 27 deletions

View file

@ -1,7 +1,6 @@
#include "mover.hpp"
#include "placeable.hpp"
#include <cassert>
#include <algorithm>
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<int>(retVal);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void Mover::UnregisterPlaceable (int parID) {
assert(static_cast<std::size_t>(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

View file

@ -2,19 +2,21 @@
#define id20409B43E62B4247A278B413D1114896
#include "vector.hpp"
#include <vector>
#include "observersmanager.hpp"
namespace cloonel {
class Placeable;
class Mover {
public:
typedef ObserversManager<Placeable*>::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<Placeable*> m_placeables;
ObserversManager<Placeable*> m_placeables;
};
} //namespace cloonel