From 6afa1a4cd4a7e48a2f5d5007fd6c3a10ae93b9ce Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 26 Oct 2016 00:50:14 +0200 Subject: [PATCH] Make virtual methods protected. --- .gitignore | 1 + CMakeLists.txt | 1 + src/gamescenebase.cpp | 26 ++++++++++++++++++++++++++ src/gamescenebase.hpp | 17 ++++++++++++++--- src/ingamescene.cpp | 8 ++------ src/ingamescene.hpp | 7 ++++--- 6 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 src/gamescenebase.cpp diff --git a/.gitignore b/.gitignore index 32fc22b..2fb272d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ compile_commands.json .ycm_extra_conf.py tags +__pycache__/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 85d7882..6192067 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ add_executable(${PROJECT_NAME} src/ingamescene.cpp src/sizenotifiable.cpp src/sizeratio.cpp + src/gamescenebase.cpp ) target_include_directories(${PROJECT_NAME} SYSTEM diff --git a/src/gamescenebase.cpp b/src/gamescenebase.cpp new file mode 100644 index 0000000..c5f1e05 --- /dev/null +++ b/src/gamescenebase.cpp @@ -0,0 +1,26 @@ +#include "gamescenebase.hpp" + +namespace curry { + GameSceneBase::GameSceneBase() : + m_wants_to_quit(false) + { + } + + void GameSceneBase::prepare() { + m_wants_to_quit = false; + this->on_prepare(); + } + + void GameSceneBase::destroy() noexcept { + set_wants_to_quit(); + this->on_destroy(); + } + + bool GameSceneBase::wants_to_quit() const { + return m_wants_to_quit; + } + + void GameSceneBase::set_wants_to_quit() { + m_wants_to_quit = true; + } +} //namespace curry diff --git a/src/gamescenebase.hpp b/src/gamescenebase.hpp index 8b244b0..9fd7cb5 100644 --- a/src/gamescenebase.hpp +++ b/src/gamescenebase.hpp @@ -3,11 +3,22 @@ namespace curry { class GameSceneBase { public: + GameSceneBase(); virtual ~GameSceneBase() noexcept = default; - virtual void prepare() = 0; + void prepare(); + void destroy() noexcept; + virtual void exec() = 0; - virtual bool wants_to_quit() const = 0; - virtual void destroy() noexcept = 0; + + bool wants_to_quit() const; + void set_wants_to_quit(); + + protected: + virtual void on_prepare() = 0; + virtual void on_destroy() noexcept = 0; + + private: + bool m_wants_to_quit; }; } //namespace curry diff --git a/src/ingamescene.cpp b/src/ingamescene.cpp index 8ba27bf..152e377 100644 --- a/src/ingamescene.cpp +++ b/src/ingamescene.cpp @@ -9,7 +9,7 @@ namespace curry { IngameScene::~IngameScene() noexcept = default; - void IngameScene::prepare() { + void IngameScene::on_prepare() { std::cout << "game prepare\n"; } @@ -17,11 +17,7 @@ namespace curry { std::cout << "game exec\n"; } - bool IngameScene::wants_to_quit() const { - return true; - } - - void IngameScene::destroy() noexcept { + void IngameScene::on_destroy() noexcept { std::cout << "game destroy\n"; } } //namespace curry diff --git a/src/ingamescene.hpp b/src/ingamescene.hpp index 7bc5a31..f2fe68d 100644 --- a/src/ingamescene.hpp +++ b/src/ingamescene.hpp @@ -12,10 +12,11 @@ namespace curry { explicit IngameScene (cloonel::SDLMain* parSDLMain); virtual ~IngameScene() noexcept; - virtual void prepare() override; virtual void exec() override; - virtual bool wants_to_quit() const override; - virtual void destroy() noexcept override; + + protected: + virtual void on_prepare() override; + virtual void on_destroy() noexcept override; private: cloonel::SDLMain* m_sdlmain;