]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
menu, indoor fixes
authorClyne Sullivan <tullivan99@gmail.com>
Sun, 27 Nov 2016 23:49:32 +0000 (18:49 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Sun, 27 Nov 2016 23:49:32 +0000 (18:49 -0500)
include/components.hpp
main.cpp
src/components.cpp
src/engine.cpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp
xml/bobshouse.xml

index 58f5aea568640c21f0856d926f4de5fe5d4fe892..367b8a3755f1e8038f87484e52be47e65c1d7994 100644 (file)
@@ -14,6 +14,8 @@
 #include <texture.hpp>
 #include <events.hpp>
 
+#include <atomic>
+
 /**
  * @struct Position
  * @brief Stores the position of an entity on the xy plane.
@@ -275,7 +277,11 @@ public:
 };
 
 class RenderSystem : public entityx::System<RenderSystem> {
+private:
+       std::string loadTexString;
+       std::atomic<GLuint> loadTexResult;
 public:
+       GLuint loadTexture(const std::string& file);
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
 };
 
index 298fc6be3702d5ee74a66d77469fa3e962004ef2..c3a0a6bbe29c52aa8dec867808366f0627d85ecd 100644 (file)
--- 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();
index 5b85f51a68c9cb4a8a0fc74d7e77dcd6b91da726..d9b9b60a6118b0e9d5366f3817d47d71d3d427ca 100644 (file)
@@ -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<Visible, Sprite, Position>([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
index 8db46890641e94f4dff6fc91bcb9ac11141ae9a5..4b156f3527c1a9891a5cd5efaae9db07b14e8a72 100644 (file)
@@ -8,8 +8,6 @@
 #include <components.hpp>
 #include <player.hpp>
 
-extern World *currentWorld;
-
 Engine::Engine(void)
     : shouldRun(true), systems(game::entities, game::events)
 {
index ac7a40035b84543b7294d5257d494cba0bc56498..bc1f28c12ba51aade5182ef5aaea0796ced8df8b 100644 (file)
@@ -14,7 +14,7 @@
 #include <chrono>
 using namespace std::literals::chrono_literals;
 
-extern MenucurrentMenu;
+extern Menu *currentMenu;
 
 std::array<SDL_Keycode, 6> 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<MouseClickEvent>(mouse, e.button.button);
 
                        // run actions?
index f0660f3748ebf26e8cc113db35607d11457f802b..e7845c2809dcaf6aae07a42c0f13dc0b582b0b11 100644 (file)
@@ -6,8 +6,6 @@
 
 #include <fstream>
 
-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;
                                 }
                             }
index 4ab8af7bb899026c697f7ed8e3d778e816e18aca..cd606affd6683d0add67647391175666b17896de 100644 (file)
@@ -178,6 +178,7 @@ bool WorldSystem::save(void)
 
 void WorldSystem::load(const std::string& file)
 {
+       auto& render = *game::engine.getSystem<RenderSystem>();
        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;
                }
 
index b638ae5d731fe2e1871a240b12eefcb8e2b83e00..cde1cdcf9b09f290631aff9160e4c5e9806b44e0 100644 (file)
@@ -3,8 +3,8 @@
 
 <IndoorWorld>
     <style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
-    <house width="640" texture="assets/style/classic/bg/insideWoodHouse.png"/>
-    <generation width="1600"/>
+    <house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>
+    <generation width="320"/>
     <time>6000</time>
     <!--<link outside="town.xml"/>-->
     <npc name="Bob" hasDialog="false" spawnx="30"/>