Use the new tree-based registration system in the mover.
This commit is contained in:
parent
61f0c28983
commit
9c660caec6
7 changed files with 45 additions and 16 deletions
|
@ -68,16 +68,17 @@ namespace cloonel {
|
|||
std::unique_ptr<MoverLeftRight> moverLeftRight(new MoverLeftRight(1.5f, 5.0f, 40.0f));
|
||||
std::unique_ptr<MoverWorld> moverWorld(new MoverWorld(halfRefHeight));
|
||||
std::unique_ptr<TiledWallpaper> wallpaper(new TiledWallpaper("resources/graphics/background_tile.png", SDLObject()));
|
||||
std::unique_ptr<PlatformSystem> platforms(new PlatformSystem("resources/graphics/platform.png", SDLObject(), this, halfRefHeight * 0.9f, *moverWorld));
|
||||
std::unique_ptr<PlatformSystem> platforms(new PlatformSystem("resources/graphics/platform.png", SDLObject(), this, halfRefHeight * 0.9f));
|
||||
|
||||
player->Prepare();
|
||||
platforms->Prepare();
|
||||
moverSine->RegisterPlaceable(player.get());
|
||||
moverSine->RegisterPlaceable(moverWorld.get()); //Keep an invisible mover
|
||||
moverLeftRight->RegisterPlaceable(player.get());
|
||||
moverWorld->RegisterPlaceable(player.get()); //It compensates the position when the chara goes over the mid
|
||||
moverWorld->RegisterPlaceable(moverWorld.get()); //The mover has to be in sync with the character
|
||||
moverWorld->RegisterPlaceable(platforms.get());
|
||||
wallpaper->Reload();
|
||||
platforms->Prepare();
|
||||
|
||||
std::swap(moverSine, m_moverSine);
|
||||
std::swap(player, m_player);
|
||||
|
|
|
@ -30,4 +30,13 @@ namespace cloonel {
|
|||
UpdateSingle(currPlaceable);
|
||||
}
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
Mover::PlaceableTicketType Mover::RegisterPlaceable (Placeable* parPlaceable, PlaceableTicketType parTicket) {
|
||||
assert(parPlaceable);
|
||||
const auto currTicket = m_placeables.Add(parPlaceable, parTicket);
|
||||
parPlaceable->OnRegister(*this, currTicket);
|
||||
return currTicket;
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -30,11 +30,15 @@ namespace cloonel {
|
|||
public:
|
||||
typedef ObserversManager<Placeable*>::TicketType PlaceableTicketType;
|
||||
|
||||
enum {
|
||||
NullTicket = ObserversManager<Placeable*>::Ticket_Null
|
||||
};
|
||||
|
||||
Mover ( void ) = default;
|
||||
virtual ~Mover ( void ) noexcept = default;
|
||||
|
||||
virtual void Update ( float parDelta );
|
||||
PlaceableTicketType RegisterPlaceable ( Placeable* parPlaceable ) { return m_placeables.Add(parPlaceable); }
|
||||
PlaceableTicketType RegisterPlaceable ( Placeable* parPlaceable, PlaceableTicketType parParent=ObserversManager<Placeable*>::Ticket_Null );
|
||||
void UnregisterPlaceable ( PlaceableTicketType parID ) noexcept { m_placeables.Remove(parID); }
|
||||
|
||||
protected:
|
||||
|
|
|
@ -28,4 +28,10 @@ namespace cloonel {
|
|||
m_pos(parPos)
|
||||
{
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void Placeable::OnRegister (Mover&, Mover::PlaceableTicketType) {
|
||||
return;
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -21,14 +21,14 @@
|
|||
#define id703E4B8DFFF747DFA97864384B87E9C1
|
||||
|
||||
#include "vector.hpp"
|
||||
#include "mover.hpp"
|
||||
|
||||
namespace cloonel {
|
||||
class Mover;
|
||||
|
||||
class Placeable {
|
||||
public:
|
||||
float2 GetPos ( void ) const noexcept;
|
||||
void AddOffset ( const float2& parOffset ) noexcept;
|
||||
virtual void OnRegister ( Mover& parMover, Mover::PlaceableTicketType parParentTicket );
|
||||
|
||||
protected:
|
||||
explicit Placeable ( float2 parPos );
|
||||
|
|
|
@ -66,10 +66,9 @@ namespace cloonel {
|
|||
};
|
||||
|
||||
struct PlatformSystem::LocalData : public boost::noncopyable {
|
||||
LocalData ( const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene, float parMaxDistance, Mover& parMover );
|
||||
LocalData ( const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene, float parMaxDistance );
|
||||
~LocalData ( void ) noexcept = default;
|
||||
|
||||
Mover& mover;
|
||||
std::vector<PlatformInfo> platformsBuff;
|
||||
CircularBuffer<std::vector<PlatformInfo>::iterator> platforms;
|
||||
Texture texture;
|
||||
|
@ -80,8 +79,7 @@ namespace cloonel {
|
|||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
PlatformSystem::LocalData::LocalData (const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene, float parMaxDistance, Mover& parMover) :
|
||||
mover(parMover),
|
||||
PlatformSystem::LocalData::LocalData (const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene, float parMaxDistance) :
|
||||
platformsBuff(MAX_PLATFORMS_ON_SCREEN),
|
||||
platforms(platformsBuff.begin(), platformsBuff.end()),
|
||||
texture(parTexturePath, parSDLMain, false),
|
||||
|
@ -93,8 +91,9 @@ namespace cloonel {
|
|||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
PlatformSystem::PlatformSystem (const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene, float parMaxDistance, Mover& parMover) :
|
||||
m_localdata(new LocalData(parTexturePath, parSDLMain, parScene, parMaxDistance, parMover))
|
||||
PlatformSystem::PlatformSystem (const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene, float parMaxDistance) :
|
||||
Placeable(float2(0.0f)),
|
||||
m_localdata(new LocalData(parTexturePath, parSDLMain, parScene, parMaxDistance))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -163,8 +162,15 @@ namespace cloonel {
|
|||
for (size_t z = 0; z < m_localdata->platforms.size(); ++z) {
|
||||
PlatformInfo& newPlatf = m_localdata->platforms[z];
|
||||
m_localdata->scene->AddDrawable(newPlatf.platform.get());
|
||||
const Mover::PlaceableTicketType ticket = m_localdata->mover.RegisterPlaceable(newPlatf.platform.get());
|
||||
newPlatf.ticket = ticket;
|
||||
newPlatf.ticket = Mover::NullTicket;
|
||||
}
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void PlatformSystem::OnRegister (Mover& parMover, Mover::PlaceableTicketType parTicket) {
|
||||
for (size_t z = 0; z < m_localdata->platforms.size(); ++z) {
|
||||
m_localdata->platforms[z].ticket = parMover.RegisterPlaceable(m_localdata->platforms[z].platform.get(), parTicket);
|
||||
}
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -19,17 +19,17 @@
|
|||
|
||||
#ifndef id17908979556C47F8A978688BBE4A9D22
|
||||
|
||||
#include "placeable.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace cloonel {
|
||||
class SDLMain;
|
||||
class GameplayScene;
|
||||
class Mover;
|
||||
|
||||
class PlatformSystem {
|
||||
class PlatformSystem : public Placeable {
|
||||
public:
|
||||
PlatformSystem ( void ) = delete;
|
||||
PlatformSystem ( const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene, float parMaxDistance, Mover& parMover );
|
||||
PlatformSystem ( const char* parTexturePath, SDLMain* parSDLMain, GameplayScene* parScene, float parMaxDistance );
|
||||
PlatformSystem ( const PlatformSystem& ) = delete;
|
||||
PlatformSystem ( PlatformSystem&& parOther ) = delete;
|
||||
~PlatformSystem ( void ) noexcept;
|
||||
|
@ -40,6 +40,9 @@ namespace cloonel {
|
|||
void Destroy ( void ) noexcept;
|
||||
void SpawnPlatforms ( void );
|
||||
|
||||
//Overrides
|
||||
virtual void OnRegister ( Mover& parOut, Mover::PlaceableTicketType parTicket );
|
||||
|
||||
private:
|
||||
struct LocalData;
|
||||
|
||||
|
|
Loading…
Reference in a new issue