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