From b1d3354d93187a6bededc280ddb6dee5b159bbe7 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 27 Nov 2016 18:49:32 -0500 Subject: menu, indoor fixes --- include/components.hpp | 6 ++++++ main.cpp | 2 +- src/components.cpp | 15 +++++++++++++++ src/engine.cpp | 2 -- src/ui.cpp | 9 ++++++--- src/ui_menu.cpp | 14 ++++++-------- src/world.cpp | 3 ++- xml/bobshouse.xml | 4 ++-- 8 files changed, 38 insertions(+), 17 deletions(-) diff --git a/include/components.hpp b/include/components.hpp index 58f5aea..367b8a3 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -14,6 +14,8 @@ #include #include +#include + /** * @struct Position * @brief Stores the position of an entity on the xy plane. @@ -275,7 +277,11 @@ public: }; class RenderSystem : public entityx::System { +private: + std::string loadTexString; + std::atomic loadTexResult; public: + GLuint loadTexture(const std::string& file); void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; }; diff --git a/main.cpp b/main.cpp index 298fc6b..c3a0a6b 100644 --- a/main.cpp +++ b/main.cpp @@ -226,8 +226,8 @@ int main(int argc, char *argv[]) const bool &run = game::engine.shouldRun; while (run) { - game::engine.render(0); render(); + game::engine.render(0); } thMain.join(); diff --git a/src/components.cpp b/src/components.cpp index 5b85f51..d9b9b60 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -47,9 +47,24 @@ void PhysicsSystem::update(entityx::EntityManager &en, entityx::EventManager &ev }); } +GLuint RenderSystem::loadTexture(const std::string& file) +{ + loadTexString = file; + loadTexResult = 0xFFFF; + while (loadTexResult == 0xFFFF) + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + return loadTexResult; +} + void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) { (void)ev; + + if (!loadTexString.empty()) { + loadTexResult = Texture::loadTexture(loadTexString); + loadTexString.clear(); + } + Render::worldShader.use(); en.each([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) { diff --git a/src/engine.cpp b/src/engine.cpp index 8db4689..4b156f3 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -8,8 +8,6 @@ #include #include -extern World *currentWorld; - Engine::Engine(void) : shouldRun(true), systems(game::entities, game::events) { diff --git a/src/ui.cpp b/src/ui.cpp index ac7a400..bc1f28c 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -14,7 +14,7 @@ #include using namespace std::literals::chrono_literals; -extern Menu* currentMenu; +extern Menu *currentMenu; std::array controlMap = { SDLK_w, SDLK_a, SDLK_d, SDLK_LSHIFT, SDLK_LCTRL, SDLK_e @@ -72,8 +72,6 @@ static bool typeOutSustain = false; static Mix_Chunk *dialogClick; -extern void mainLoop(void); - /* * Fade effect flags */ @@ -1244,6 +1242,8 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, (void)ev; (void)dt; + if (currentMenu != nullptr) + return; auto SCREEN_WIDTH = game::SCREEN_WIDTH; auto SCREEN_HEIGHT = game::SCREEN_HEIGHT; @@ -1284,6 +1284,9 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, //case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: + if (currentMenu != nullptr) + break; + ev.emit(mouse, e.button.button); // run actions? diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp index f0660f3..e7845c2 100644 --- a/src/ui_menu.cpp +++ b/src/ui_menu.cpp @@ -6,8 +6,6 @@ #include -extern bool gameRunning; - extern Menu *currentMenu; static Menu pauseMenu; @@ -248,13 +246,13 @@ namespace ui { for (auto &m : currentMenu->items) { // reset the background modifier cMult = 1.0f; - + //if the menu is any type of button if (m.member == 0 || m.member == -1 || m.member == -2) { //tests if the mouse is over the button if (mouse.x >= offset.x+m.button.loc.x && mouse.x <= offset.x+m.button.loc.x + m.button.dim.x) { if (mouse.y >= offset.y+m.button.loc.y && mouse.y <= offset.y+m.button.loc.y + m.button.dim.y) { - + // set the darkness multiplier cMult = 0.6f; @@ -310,20 +308,20 @@ namespace ui { //test if mouse is inside of the slider's borders if (mouse.x >= offset.x+m.slider.loc.x && mouse.x <= offset.x+m.slider.loc.x+m.slider.dim.x) { if (mouse.y >= offset.y+m.slider.loc.y && mouse.y <= offset.y+m.slider.loc.y+m.slider.dim.y) { - + // change multiplier background modifier cMult = 0.75f; - + //if we are inside the slider and click it will set the slider to that point if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) { //change handle location if (m.slider.dim.y > m.slider.dim.x) { *m.slider.var = (((mouse.y-offset.y) - m.slider.loc.y)/m.slider.dim.y)*100; - + cMult = 0.5f; }else{ *m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100; - + cMult = 0.5f; } } diff --git a/src/world.cpp b/src/world.cpp index 4ab8af7..cd606af 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -178,6 +178,7 @@ bool WorldSystem::save(void) void WorldSystem::load(const std::string& file) { + auto& render = *game::engine.getSystem(); auto str2coord = [](std::string s) -> vec2 { auto cpos = s.find(','); s[cpos] = '\0'; @@ -275,7 +276,7 @@ void WorldSystem::load(const std::string& file) world.indoorWidth = wxml->FloatAttribute("width"); auto str = wxml->StrAttribute("texture"); - auto tex = Texture::loadTexture(str); + auto tex = render.loadTexture(str); world.indoorTex = tex; } diff --git a/xml/bobshouse.xml b/xml/bobshouse.xml index b638ae5..cde1cdc 100644 --- a/xml/bobshouse.xml +++ b/xml/bobshouse.xml @@ -3,8 +3,8 @@