From 92bec13dec53933a9cf8045ab486b47dc13fe46f Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 12 Feb 2018 20:33:48 +0100 Subject: Remove Actor::Type and Scene::Type in favor of dynamic_cast() --- src/main/cpp/Actor.cpp | 4 ++-- src/main/cpp/Subconscious.cpp | 21 ++++++++++----------- src/main/cpp/WorldScene.cpp | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'src/main/cpp') diff --git a/src/main/cpp/Actor.cpp b/src/main/cpp/Actor.cpp index 219488d..a6dc597 100644 --- a/src/main/cpp/Actor.cpp +++ b/src/main/cpp/Actor.cpp @@ -1,7 +1,7 @@ #include "Actor.hpp" -Actor::Actor(std::string _name, unsigned _maxHp, Type _type) : - name(_name), maxHp(_maxHp), type(_type) +Actor::Actor(std::string _name, unsigned _maxHp) : + name(_name), maxHp(_maxHp) {} Actor::~Actor() diff --git a/src/main/cpp/Subconscious.cpp b/src/main/cpp/Subconscious.cpp index a5f8620..5d04e5c 100644 --- a/src/main/cpp/Subconscious.cpp +++ b/src/main/cpp/Subconscious.cpp @@ -34,26 +34,26 @@ void Subconscious::run() case sf::Event::KeyPressed: switch (event.key.code) { case sf::Keyboard::Up: - if (_currentScene->type == Scene::Type::WORLD) { - static_cast(_currentScene)->pan(0, -10); + if (WorldScene *worldScene = dynamic_cast(_currentScene)) { + worldScene->pan(0, -10); } break; case sf::Keyboard::Down: - if (_currentScene->type == Scene::Type::WORLD) { - static_cast(_currentScene)->pan(0, 10); + if (WorldScene *worldScene = dynamic_cast(_currentScene)) { + worldScene->pan(0, 10); } break; case sf::Keyboard::Left: - if (_currentScene->type == Scene::Type::WORLD) { - static_cast(_currentScene)->pan(-10, 0); + if (WorldScene *worldScene = dynamic_cast(_currentScene)) { + worldScene->pan(-10, 0); } break; case sf::Keyboard::Right: - if (_currentScene->type == Scene::Type::WORLD) { - static_cast(_currentScene)->pan(10, 0); + if (WorldScene *worldScene = dynamic_cast(_currentScene)) { + worldScene->pan(10, 0); } break; @@ -83,9 +83,8 @@ void Subconscious::run() // // std::cout << std::fixed << std::setprecision(3) // << event.mouseWheelScroll.delta << std::endl; - - if (_currentScene->type == Scene::Type::WORLD) { - static_cast(_currentScene)->zoom(event.mouseWheelScroll.delta/10.0); + if (WorldScene *worldScene = dynamic_cast(_currentScene)) { + worldScene->zoom(event.mouseWheelScroll.delta/10.0); } break; diff --git a/src/main/cpp/WorldScene.cpp b/src/main/cpp/WorldScene.cpp index 1be2097..8887f6f 100644 --- a/src/main/cpp/WorldScene.cpp +++ b/src/main/cpp/WorldScene.cpp @@ -1,6 +1,6 @@ #include "WorldScene.hpp" -WorldScene::WorldScene(sf::RenderWindow &window) : Scene(window, Scene::Type::WORLD) +WorldScene::WorldScene(sf::RenderWindow &window) : Scene(window) { _tileSize = DEFAULT_TILE_SIZE_PX; } -- cgit v1.2.1