Make virtual methods protected.

This commit is contained in:
King_DuckZ 2016-10-26 00:50:14 +02:00
parent 482a13ea47
commit 6afa1a4cd4
6 changed files with 48 additions and 12 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
compile_commands.json
.ycm_extra_conf.py
tags
__pycache__/

View file

@ -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

26
src/gamescenebase.cpp Normal file
View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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;