diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-10-11 21:24:43 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-10-11 21:24:43 -0500 |
commit | f46be773dd1283688ec1feda1c50e6edaf6d1113 (patch) | |
tree | e776569254517ba8a76763623b02c0f5530a1eb1 /src | |
parent | 8a71861846c41c5f432570262b398c7627743c91 (diff) |
WIP make worldsystem manage music
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 51 | ||||
-rw-r--r-- | src/world.cpp | 91 |
2 files changed, 95 insertions, 47 deletions
diff --git a/src/engine.cpp b/src/engine.cpp new file mode 100644 index 0000000..b4677a9 --- /dev/null +++ b/src/engine.cpp @@ -0,0 +1,51 @@ +#include <engine.hpp> + +#include <config.hpp> +#include <world.hpp> +#include <ui.hpp> +#include <inventory.hpp> +#include <entities.hpp> +#include <window.hpp> + +extern World *currentWorld; + +Engine::Engine(void) + : gameRunning(true), systems(game::entities, game::events) +{ +} + +void Engine::init(void) { + game::config::read(); + game::events.subscribe<GameEndEvent>(*this); + + systems.add<WindowSystem>(); + systems.add<InputSystem>(); + systems.add<InventorySystem>(); + systems.add<WorldSystem>(); + systems.add<PlayerSystem>(&player); + + systems.configure(); +} + +void Engine::render(entityx::TimeDelta dt) +{ + systems.update<WindowSystem>(dt); +} + +void Engine::update(entityx::TimeDelta dt) +{ + systems.update<InputSystem>(dt); + systems.update<InventorySystem>(dt); + systems.update<PlayerSystem>(dt); + + currentWorld->update(player, dt); + currentWorld->detect(player); +} + + +namespace game { + entityx::EventManager events; + entityx::EntityManager entities (events); + + Engine engine; +} diff --git a/src/world.cpp b/src/world.cpp index 320c1db..8bc0306 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -16,6 +16,7 @@ #include <gametime.hpp> #include <render.hpp> +#include <engine.hpp> // local library headers #include <tinyxml2.h> @@ -53,12 +54,6 @@ extern World *currentWorldToRight; // main.cpp extern bool inBattle; // ui.cpp? extern std::string xmlFolder; -static const std::array<std::string, 3> WorldWeatherString { - "None", - "Rainy", - "Snowy" -}; - // particle mutex std::mutex partMutex; @@ -232,8 +227,6 @@ generate(int width) s.x = (randGet() % (static_cast<int>(-worldStart) * 2)) + worldStart; s.y = (randGet() % game::SCREEN_HEIGHT) + 100; } - - weather = WorldWeather::None; } static Color ambient; @@ -254,25 +247,24 @@ void World::drawBackgrounds(void) // used for alpha values of background textures int alpha; + switch (game::engine.getSystem<WorldSystem>()->getWeatherId()) { + case WorldWeather::Snowy: + alpha = 150; + break; + case WorldWeather::Rain: + alpha = 0; + break; + default: + alpha = 255 - worldShade * 4; + break; + } + // shade value for GLSL float shadeAmbient = std::max(0.0f, static_cast<float>(-worldShade) / 50 + 0.5f); // 0 to 1.5f if (shadeAmbient > 0.9f) shadeAmbient = 1; - // the sunny wallpaper is faded with the night depending on tickCount - switch (weather) { - case WorldWeather::Snowy: - alpha = 150; - break; - case WorldWeather::Rain: - alpha = 0; - break; - default: - alpha = 255 - worldShade * 4; - break; - } - glActiveTexture(GL_TEXTURE0); glUniform1i(Render::worldShader.uniform[WU_texture], 0); @@ -1198,30 +1190,6 @@ void World::setStyle(std::string pre) /** * Pretty self-explanatory. */ -std::string World::getWeatherStr(void) const -{ - return WorldWeatherString[static_cast<int>(weather)]; -} - -const WorldWeather& World::getWeatherId(void) const -{ - return weather; -} - -void World::setWeather(const std::string &s) -{ - for (unsigned int i = WorldWeatherString.size(); i--;) { - if (WorldWeatherString[i] == s) { - weather = static_cast<WorldWeather>(i); - return; - } - } - weather = WorldWeather::None; -} - -/** - * Pretty self-explanatory. - */ std::string World::setToLeft(std::string file) { return (toLeft = file); @@ -1976,7 +1944,7 @@ loadWorldFromXMLNoSave(std::string path) { // weather tags else if (name == "weather") { - tmp->setWeather(wxml->GetText()); + game::engine.getSystem<WorldSystem>()->setWeather(wxml->GetText()); } // set spawn x for player @@ -2166,9 +2134,38 @@ loadWorldFromXMLNoSave(std::string path) { } Village::Village(std::string meme, World *w) + : name(meme) { - name = meme; start.x = w->getTheWidth() / 2.0f; end.x = -start.x; in = false; } + + + +WorldSystem::WorldSystem(void) + : weather(WorldWeather::None) {} + +void WorldSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) +{ + (void)en; + (void)ev; + (void)dt; +} + +void WorldSystem::receive(const BGMToggleEvent &bte) +{ + +} + +void WorldSystem::setWeather(const std::string &s) +{ + for (unsigned int i = 3; i--;) { + if (WorldWeatherString[i] == s) { + weather = static_cast<WorldWeather>(i); + return; + } + } + + weather = WorldWeather::None; +} |