Make the Prepare and Destroy step more customizable.

This commit is contained in:
King_DuckZ 2014-07-28 10:58:15 +02:00
parent 250600d8b2
commit 63bb31e728
5 changed files with 20 additions and 5 deletions

View file

@ -108,4 +108,11 @@ namespace cloonel {
bool GameBase::ShouldQuit() const {
return false;
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
void GameBase::Prepare() {
this->OnPrepare();
this->OnPrepareDone();
}
} //namespace cloonel

View file

@ -32,13 +32,13 @@ namespace cloonel {
float Exec ( void );
bool WantsToQuit ( void ) const;
void Prepare ( void );
virtual void Destroy ( void ) noexcept = 0;
protected:
explicit GameBase ( SDLMain* parSdlMain );
virtual ~GameBase ( void ) noexcept;
virtual void Prepare ( void ) = 0;
virtual void Destroy ( void ) noexcept = 0;
SDLMain* SDLObject ( void ) { return m_sdlmain; }
InputBag* InputBagObject ( void ) { return m_input.get(); }
@ -46,6 +46,8 @@ namespace cloonel {
virtual void OnRender ( void ) = 0;
virtual void OnPreUpdate ( void ) = 0;
virtual void OnUpdate ( float parDelta ) = 0;
virtual void OnPrepare ( void ) = 0;
virtual void OnPrepareDone ( void ) = 0;
virtual bool ShouldQuit ( void ) const;
const std::unique_ptr<InputBag> m_input;

View file

@ -36,6 +36,9 @@ namespace cloonel {
void AddMover ( Mover* parMover ) { assert(parMover); m_movers.push_back(parMover); }
void AddDrawable ( const Drawable* parDrawable ) { assert(parDrawable); m_drawables.push_back(parDrawable); }
virtual void Destroy ( void ) noexcept;
protected:
private:
virtual void OnRender ( void );
virtual void OnUpdate ( float parDelta );

View file

@ -60,7 +60,7 @@ namespace cloonel {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void GameplaySceneClassic::Prepare() {
void GameplaySceneClassic::OnPrepare() {
const float halfRefHeight = static_cast<float>(REFERENCE_HEIGHT) / 2.0f;
std::unique_ptr<MoverSine> moverSine(new MoverSine());
@ -101,6 +101,8 @@ namespace cloonel {
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void GameplaySceneClassic::Destroy() noexcept {
GameplayScene::Destroy();
//Destroy in reverse creation order
m_platforms = std::move(std::unique_ptr<PlatformSystem>(nullptr));
m_wallpaper = std::move(std::unique_ptr<TiledWallpaper>(nullptr));
@ -108,6 +110,7 @@ namespace cloonel {
m_moverLeftRight = std::move(std::unique_ptr<MoverLeftRight>(nullptr));
m_player = std::move(std::unique_ptr<Character>(nullptr));
m_moverSine = std::move(std::unique_ptr<MoverSine>(nullptr));
}
///--------------------------------------------------------------------------

View file

@ -38,11 +38,11 @@ namespace cloonel {
explicit GameplaySceneClassic ( SDLMain* parSdlMain );
virtual ~GameplaySceneClassic ( void ) noexcept;
virtual void Prepare ( void );
virtual void Destroy ( void ) noexcept;
private:
virtual void OnPreUpdate ( void );
virtual void OnPrepare ( void );
std::unique_ptr<Character> m_player;
std::unique_ptr<MoverSine> m_moverSine;