From f46be773dd1283688ec1feda1c50e6edaf6d1113 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 11 Oct 2016 21:24:43 -0500 Subject: WIP make worldsystem manage music --- include/engine.hpp | 36 ++++++++++++++++++++++++++++++++++++ include/events.hpp | 11 ++++++++++- include/world.hpp | 51 ++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 84 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/engine.hpp b/include/engine.hpp index 0fabdb3..2bde6de 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -5,13 +5,49 @@ #include +class Engine : public entityx::Receiver { +private: + bool gameRunning; + +public: + entityx::SystemManager systems; + + explicit Engine(void); + + void init(void); + void render(entityx::TimeDelta dt); + void update(entityx::TimeDelta dt); + + template + inline T* getSystem(void) { + return dynamic_cast(systems.system().get()); + } + + /*void configure(entityx::EventManager &ev) { + (void)ev; + }*/ + + inline void receive(const GameEndEvent &gee) { + gameRunning = !(gee.really); + } + + inline bool shouldRun(void) const { + return gameRunning; + } +}; + + namespace game { extern entityx::EventManager events; extern entityx::EntityManager entities; + extern Engine engine; + inline void endGame(void) { events.emit(); } } + + #endif // ENGINE_HPP_ diff --git a/include/events.hpp b/include/events.hpp index 1fe7d7a..4d1415c 100644 --- a/include/events.hpp +++ b/include/events.hpp @@ -7,7 +7,9 @@ #include - struct MouseScrollEvent { +#include + +struct MouseScrollEvent { MouseScrollEvent(int sd = 0) : scrollDistance(sd) {} @@ -35,4 +37,11 @@ struct GameEndEvent { bool really; }; +struct BGMToggleEvent { + BGMToggleEvent(std::string f) + : file(f) {} + + std::string file; +} + #endif // EVENTS_HPP_ diff --git a/include/world.hpp b/include/world.hpp index 6b26452..3b116ed 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -49,7 +49,7 @@ typedef struct { * This pair contains a pointer to the new world, and the new set of * coordinates the player should be at in that world. */ -typedef std::pair WorldSwitchInfo; +using WorldSwitchInfo = std::pair; /** * Alters how bright world elements are drawn. @@ -130,6 +130,42 @@ public: ~Village(void){} }; + +#include + +constexpr const char* WorldWeatherString[3] = { + "None", + "Rainy", + "Snowy" +}; + +class WorldSystem : public entityx::System, public entityx::Receiver { +private: + WorldWeather weather; + + Mix_Music *bgmObj; + +public: + explicit WorldSystem(void); + + void configure(entityx::EventManager &ev) { + ev.subscribe(*this); + } + + void receive(const BGMToggleEvent &bte); + + void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; + + inline const std::string getWeatherStr(void) const + { return WorldWeatherString[static_cast(weather)]; } + + inline const WorldWeather& getWeatherId(void) const + { return weather; } + + void setWeather(const std::string &s); +}; + + /** * The world class. * This class handles entity creation, management, and deletion. Most @@ -137,22 +173,16 @@ public: * drawing. */ class World { -friend class ItemLight; +//friend class ItemLight; protected: /** * An array of all the world's ground data, populated through * World::generate(). - * * @see generate() */ std::vector worldData; - /** - * Contains the current state of weather in the world. - */ - WorldWeather weather; - /** * Contains the size of the 'worldData' array. */ @@ -175,11 +205,6 @@ protected: */ WorldBGType bgType; - /** - * SDL_Mixer's object for the loaded BGM. - */ - Mix_Music *bgmObj; - /** * The filename of the world's BGM file. * -- cgit v1.2.3