From 63bb31e72809c580aa3cce15aaae4318d7672e80 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Mon, 28 Jul 2014 10:58:15 +0200 Subject: [PATCH] Make the Prepare and Destroy step more customizable. --- src/gamebase.cpp | 7 +++++++ src/gamebase.hpp | 8 +++++--- src/gameplayscene.hpp | 3 +++ src/gameplaysceneclassic.cpp | 5 ++++- src/gameplaysceneclassic.hpp | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/gamebase.cpp b/src/gamebase.cpp index 7fd05d6..785295f 100644 --- a/src/gamebase.cpp +++ b/src/gamebase.cpp @@ -108,4 +108,11 @@ namespace cloonel { bool GameBase::ShouldQuit() const { return false; } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + void GameBase::Prepare() { + this->OnPrepare(); + this->OnPrepareDone(); + } } //namespace cloonel diff --git a/src/gamebase.hpp b/src/gamebase.hpp index 1b92420..245d083 100644 --- a/src/gamebase.hpp +++ b/src/gamebase.hpp @@ -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 m_input; diff --git a/src/gameplayscene.hpp b/src/gameplayscene.hpp index 905859c..df4d550 100644 --- a/src/gameplayscene.hpp +++ b/src/gameplayscene.hpp @@ -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 ); diff --git a/src/gameplaysceneclassic.cpp b/src/gameplaysceneclassic.cpp index 5ccbfc4..09fc604 100644 --- a/src/gameplaysceneclassic.cpp +++ b/src/gameplaysceneclassic.cpp @@ -60,7 +60,7 @@ namespace cloonel { ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- - void GameplaySceneClassic::Prepare() { + void GameplaySceneClassic::OnPrepare() { const float halfRefHeight = static_cast(REFERENCE_HEIGHT) / 2.0f; std::unique_ptr 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(nullptr)); m_wallpaper = std::move(std::unique_ptr(nullptr)); @@ -108,6 +110,7 @@ namespace cloonel { m_moverLeftRight = std::move(std::unique_ptr(nullptr)); m_player = std::move(std::unique_ptr(nullptr)); m_moverSine = std::move(std::unique_ptr(nullptr)); + } ///-------------------------------------------------------------------------- diff --git a/src/gameplaysceneclassic.hpp b/src/gameplaysceneclassic.hpp index 31485f2..686779c 100644 --- a/src/gameplaysceneclassic.hpp +++ b/src/gameplaysceneclassic.hpp @@ -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 m_player; std::unique_ptr m_moverSine;