]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fixes, main cleanup
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 12 Jan 2017 14:27:43 +0000 (09:27 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 12 Jan 2017 14:27:43 +0000 (09:27 -0500)
12 files changed:
include/common.hpp
include/components.hpp
include/engine.hpp
include/render.hpp
include/window.hpp
main.cpp
src/components.cpp
src/engine.cpp
src/render.cpp
src/ui.cpp
src/window.cpp
src/world.cpp

index 12231dcf48f2d44595b4284ab9e675c2388d7fb6..abfd28bbb805ef27fb2c6e2f18adfa9464c212b2 100644 (file)
@@ -14,7 +14,6 @@
 #include <algorithm>
 #include <list>
 #include <iterator>
-#include <unordered_map>
 
 // alternative windows thread library
 #ifndef __WIN32__
index 00ac8fad1b8553383df853c8f2c0e6783937a3fb..2ec7a2829ad9fd65552d33a4bc91b838929c6e76 100644 (file)
@@ -336,19 +336,11 @@ private:
        std::string loadTexString;
        Texture loadTexResult;
 
-       float fadeIntensity;
-       bool fadeIn;
 public:
-       RenderSystem(void)
-               : fadeIntensity(1), fadeIn(true) {}
-
        Texture loadTexture(const std::string& file);
-       void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
-
-       void fade(void);
-       void fadeLock(void);
-       void unfade(void);
-       void unfadeLock(void);
+       void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override
+       { (void)en; (void)ev; (void)dt; }
+       void render(void);
 };
 
 class DialogSystem : public entityx::System<DialogSystem>, public entityx::Receiver<DialogSystem> {
index a331e50121327c875db9ed51a0cd247b1446e82e..417522d9825f1bcabd9e4a7a6ce0d39354447c28 100644 (file)
@@ -39,13 +39,6 @@ public:
         */
        void init(void);
 
-       /**
-        * Updates all rendering systems.
-        * @param dt the delta time
-        */
-    void render(entityx::TimeDelta dt);
-       void resetRender(entityx::TimeDelta dt);
-
        /**
         * Updates all logic systems.
         * @param dt the delta time
index 0a2adcde3655ed3622a959b2c90edffe01f861f9..cf58519e44822e3acbc4240f775af2a4ec4d0948 100644 (file)
@@ -74,6 +74,9 @@ namespace Render {
     void useShader(Shader *s);
 
     void drawRect(vec2 ll, vec2 ur, float z);
+
+       void init(void);
+       void render(const int& fps);
 }
 
 #endif // RENDER_HPP_
index 5cf05ea3f84e3e645065ea0f29e9fe0a2b5ff8fa..d53a2bf54fae17dcad34e1272357fa1e8d845795 100644 (file)
@@ -36,7 +36,9 @@ public:
        void die(void);
 
        void configure(entityx::EventManager &ev);
-    void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
+    void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override
+       { (void)en; (void)ev; (void)dt; }
+       void render(void);
        void receive(const WindowResizeEvent&); 
        void receive(const ScreenshotEvent&);
 };
index 712c44afdb101eeacda1820140cc2ffeb171a7d5..40a84977f82eb5fca551115b4780d99150f696c4 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -4,15 +4,11 @@
  */
 
 // standard library includes
-#include <fstream>
-#include <mutex>
 #include <chrono>
 using namespace std::literals::chrono_literals;
 
 // local library includes
 #include <entityx/entityx.h>
-#include <tinyxml2.h>
-using namespace tinyxml2;
 
 // our own includes
 #include <brice.hpp>
@@ -20,17 +16,15 @@ using namespace tinyxml2;
 #include <common.hpp>
 #include <engine.hpp>
 #include <gametime.hpp>
-#include <player.hpp>
 #include <window.hpp>
 #include <world.hpp>
 #include <render.hpp>
 #include <ui.hpp>
-#include <particle.hpp>
 
 /**
  * The currently used folder to look for XML files in.
  */
-std::string xmlFolder;
+std::string xmlFolder = "xml/";
 
 /**
  * The current menu, if any are open (TODO why is this here)
@@ -42,13 +36,6 @@ Menu *currentMenu;
  */
 vec2 offset;
 
-/**
- * The current FPS of the game.
- */
-static unsigned int fps = 0;
-
-void render(void);
-
 /**
  * The main program.
  * Init, load, run. Die.
@@ -58,10 +45,7 @@ int main(int argc, char *argv[])
        static bool worldReset = false, worldDontReallyRun = false;
        std::string worldActuallyUseThisXMLFile;
 
-       //
-       // get command line arguments, if any
-       //
-
+       // handle command line args
        if (argc > 1) {
                for (int i = 1; i < argc; i++) {
                        std::string s = argv[i];
@@ -80,67 +64,17 @@ int main(int argc, char *argv[])
        //
 
        game::engine.init();
-       // used three times below
-       auto worldSys = game::engine.getSystem<WorldSystem>();
-
-       //
-       // initialize GLEW
-       //
-
-#ifndef __WIN32__
-       glewExperimental = GL_TRUE;
-#endif
 
-       auto glewError = glewInit();
-       if (glewError != GLEW_OK)
-               UserError(std::string("GLEW was not able to initialize! Error: ")
-                       + reinterpret_cast<const char *>(glewGetErrorString(glewError)));
-
-       //
-       // start the random number generator (TODO our own?)
-       //
+       // initialize the renderer
+       Render::init();
 
+       // start the random number generator
        randInit(millis());
 
-       //
-       // some basic OpenGL setup stuff
-       //
-
-       SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-       // enable v-sync (TODO but 1000 fps?)
-       SDL_GL_SetSwapInterval(0);
-       // hide the cursor
-       SDL_ShowCursor(SDL_DISABLE);
-       // switch to pixel grid
-       glViewport(0, 0, game::SCREEN_WIDTH, game::SCREEN_HEIGHT);
-       glEnable(GL_BLEND);
-       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-       glClearColor(1, 1, 1, 1);
-
-       //
-       // initialize shaders
-       //
-
-       std::cout << "Initializing shaders!\n";
-       Render::initShaders();
-       Colors::init();
-
-       //
-       // load some saved data
-       //
-
+       // load saved data
        game::briceLoad();
        game::briceUpdate();
 
-       // load sprites used in the inventory menu. See src/inventory.cpp
-       //initInventorySprites();
-
-       // get a world
-       //
-
-       if (xmlFolder.empty())
-               xmlFolder = "xml/";
-
        // read in all XML file names in the folder
        std::list<std::string> xmlFiles;
        if (getdir(std::string("./" + xmlFolder).c_str(), xmlFiles))
@@ -148,11 +82,12 @@ int main(int argc, char *argv[])
 
        // kill the world if needed
        if (worldReset) {
-               // TODO TODO TODO we do xml/*.dat now...
+               // TODO TODO TODO we do xml/*.dat now... kill that
                game::briceClear();
        }
 
        // either load the given XML, or find one
+       auto worldSys = game::engine.getSystem<WorldSystem>();
        if (!worldActuallyUseThisXMLFile.empty()) {
                worldSys->load(worldActuallyUseThisXMLFile);
        } else {
@@ -167,19 +102,14 @@ int main(int argc, char *argv[])
                }
        }
 
-       //
-       // initialize ui
-       //
-
-       ui::menu::init();
-
-
        /////////////////////////////
        //                         //
        // actually start the game //
        //                         //
        /////////////////////////////
 
+       std::list<SDL_Event> eventQueue;
+
        if (!worldDontReallyRun) {
                // the main loop, in all of its gloriousness...
                std::thread thMain ([&] {
@@ -193,19 +123,24 @@ int main(int argc, char *argv[])
                                        worldShade = 50 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
 
                                        // update fades
-                                       //ui::fadeUpdate();
+                                       ui::fadeUpdate();
 
                                        // increment game ticker
                                        game::time::tick();
                                }
 
+                               while (!eventQueue.empty()) {
+                                       game::events.emit<MainSDLEvent>(eventQueue.back());
+                                       eventQueue.pop_back();
+                               }
+
                                game::engine.update(game::time::getDeltaTime());
 
                                std::this_thread::sleep_for(1ms);
                        }
                });
                
-               static float fpsInternal = 0;
+               static int fps = 0, fpsInternal = 0;
 
                // the debug loop, gets debug screen values
                std::thread thDebug ([&] {
@@ -220,12 +155,11 @@ int main(int argc, char *argv[])
                const bool &run = game::engine.shouldRun;
                while (run) {
                        fpsInternal++;
-                       render();
-                       game::engine.resetRender(0); // TODO stupid
+                       Render::render(fps);
                        
                        SDL_Event e;
                        while (SDL_PollEvent(&e))
-                               game::events.emit<MainSDLEvent>(e);
+                               eventQueue.push_back(e);
                }
 
                // on game end, get back together
@@ -234,17 +168,11 @@ int main(int argc, char *argv[])
                //game::engine.getSystem<WorldSystem>()->thAmbient.join(); // segfault or something
        }
 
-       //
-       // put away the brice for later, save world
-       //
-
+       // save
        game::briceSave();
        worldSys->save();
 
-       //
-       // close things, free stuff, yada yada
-       //
-
+       // exit
     Mix_HaltMusic();
     Mix_CloseAudio();
 
@@ -253,103 +181,5 @@ int main(int argc, char *argv[])
 
        game::engine.getSystem<WindowSystem>()->die();
 
-       //
-       // goodbye
-       //
-
     return 0; // Calls everything passed to atexit
 }
-
-void render() {
-       static const Texture mouseTex ("assets/goodmouse.png");
-       static const glm::mat4 view = glm::lookAt(
-               glm::vec3(0.0f, 0.0f, 0.0f),   // pos
-               glm::vec3(0.0f, 0.0f, -10.0f), // looking at
-               glm::vec3(0.0f, 1.0f, 0.0f)    // up vector
-       );
-
-       static const auto& SCREEN_WIDTH2  = game::SCREEN_WIDTH / 2.0f;
-       static const auto& SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2.0f;
-
-       //
-       // set the ortho
-       //
-
-       auto ps = game::engine.getSystem<PlayerSystem>();
-       auto ploc = ps->getPosition();
-       offset.x = ploc.x + ps->getWidth() / 2;
-
-       const auto& worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
-       if (worldWidth < (int)SCREEN_WIDTH2 * 2)
-               offset.x = 0;
-       else if (offset.x - SCREEN_WIDTH2 < worldWidth * -0.5f)
-               offset.x = ((worldWidth * -0.5f) + SCREEN_WIDTH2);
-       else if (offset.x + SCREEN_WIDTH2 > worldWidth *  0.5f)
-               offset.x = ((worldWidth *  0.5f) - SCREEN_WIDTH2);
-
-       // ortho y snapping
-       offset.y = std::max(ploc.y /*+ player->height / 2*/, SCREEN_HEIGHT2);
-
-       // "setup"
-       glm::mat4 projection = glm::ortho(floor(offset.x - SCREEN_WIDTH2),             // left
-                                         floor(offset.x + SCREEN_WIDTH2),             // right
-                                         floor(offset.y - SCREEN_HEIGHT2),            // bottom
-                                         floor(offset.y + SCREEN_HEIGHT2),            // top
-                                         static_cast<decltype(floor(10.0f))>(10.0),   // near
-                                         static_cast<decltype(floor(10.0f))>(-10.0)); // far
-
-       glm::mat4 ortho = projection * view;
-
-       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-       // TODO add depth
-    glEnable(GL_DEPTH_TEST);
-
-
-    Render::worldShader.use();
-               glUniformMatrix4fv(Render::worldShader.uniform[WU_ortho], 1, GL_FALSE, glm::value_ptr(ortho));
-               glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
-       Render::worldShader.unuse();
-
-       Render::textShader.use();
-               glUniformMatrix4fv(Render::textShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(ortho));
-       glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
-       Render::textShader.unuse();
-
-       // draw the world and player
-       game::engine.getSystem<WorldSystem>()->render();
-       game::engine.getSystem<ParticleSystem>()->render();
-
-       // draw the player's inventory
-       //player->inv->draw();
-
-       game::engine.render(0);
-
-       // draw the fade overlay
-       ui::drawFade();
-
-       // draw ui elements
-       ui::draw();
-
-       // draw the debug overlay if desired
-       if (ui::debug) {
-               auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
-               ui::putText(offset.x - SCREEN_WIDTH2, (offset.y + SCREEN_HEIGHT2) - ui::fontSize,
-                   "loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s",
-                       pos.toString().c_str(), offset.toString().c_str(), fps,
-                       game::time::getTickCount(), game::engine.getSystem<ParticleSystem>()->getCount(),
-                       game::engine.getSystem<WorldSystem>()->getXMLFile().c_str());
-       }
-
-       // draw the menu
-       if (currentMenu)
-               ui::menu::draw();
-
-       // draw the mouse
-       Render::textShader.use();
-               glActiveTexture(GL_TEXTURE0);
-               mouseTex.use();
-               Render::useShader(&Render::textShader);
-               Render::drawRect(vec2(ui::mouse.x, ui::mouse.y - 64), vec2(ui::mouse.x + 64, ui::mouse.y), -9.9);
-       Render::textShader.unuse();
-}
index 4d80d258f836a5577b39076f0d74ba5ceff388cf..28a81fe30cc9ead3e558ae3d8966543bff719e0e 100644 (file)
@@ -72,49 +72,18 @@ Texture RenderSystem::loadTexture(const std::string& file)
        return loadTexResult;
 }
 
-void RenderSystem::fade(void)
+void RenderSystem::render(void)
 {
-       fadeIn = false, fadeIntensity = 0;
-}
-
-void RenderSystem::fadeLock(void)
-{
-       fade();
-       while (fadeIntensity < 1)
-               std::this_thread::sleep_for(1ms);
-}
-
-void RenderSystem::unfade(void)
-{
-       fadeIn = true, fadeIntensity = 1;
-}
-
-void RenderSystem::unfadeLock(void)
-{
-       fade();
-       while (fadeIntensity > 0)
-               std::this_thread::sleep_for(1ms);
-}
-
-void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
-{
-       (void)ev;
-
        if (!loadTexString.empty()) {
                loadTexResult = Texture(loadTexString);
                loadTexString.clear();
        }
-
-       // update fade system
-       if (fadeIn && fadeIntensity > 0)
-               fadeIntensity -= 0.01f;
-       else if(!fadeIn && fadeIntensity < 1)
-               fadeIntensity += 0.01f;
        
        Render::worldShader.use();
        Render::worldShader.enable();
 
-       en.each<Visible, Sprite, Position>([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
+       game::entities.lock();
+       game::entities.each<Visible, Sprite, Position>([](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
                // Verticies and shit
                float its = 0;
                
@@ -179,38 +148,13 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
        Render::worldShader.disable();
        Render::worldShader.unuse();
 
-       en.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) {
+       game::entities.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) {
                (void)e;
                (void)v;
                ui::setFontZ(-5.0);
                ui::putStringCentered(pos.x + dim.width / 2, pos.y - ui::fontSize - HLINES(0.5), name.name);
        });
-
-       // draw fade
-       static const GLfloat tex[8] = {
-               0, 0, 0, 0, 0, 0, 0, 0
-       };
-
-       auto SCREEN_WIDTH2 = game::SCREEN_WIDTH / 2, SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2;
-       GLfloat coord[12] = {
-               offset.x - SCREEN_WIDTH2 - 1, offset.y - SCREEN_HEIGHT2, -7.9,
-               offset.x + SCREEN_WIDTH2,     offset.y - SCREEN_HEIGHT2, -7.9,
-               offset.x - SCREEN_WIDTH2 - 1, offset.y + SCREEN_HEIGHT2, -7.9,
-               offset.x + SCREEN_WIDTH2,     offset.y + SCREEN_HEIGHT2, -7.9
-       };
-
-       Render::textShader.use();
-       Render::textShader.enable();
-
-       Colors::black.use();
-       glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, fadeIntensity);
-       glUniform1i(Render::textShader.uniform[WU_texture], 0);
-       glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coord);
-       glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
-       glDrawArrays(GL_QUADS, 0, 4);
-
-       Render::textShader.disable();
-       Render::textShader.unuse();
+       game::entities.unlock();
 }
 
 void DialogSystem::configure(entityx::EventManager &ev)
index abadf3fa1750c8f1ad4ff0a3a0da9530817e3855..c7999edbd243c2c02436c608f5bea8db1a6f0a28 100644 (file)
@@ -38,22 +38,11 @@ void Engine::init(void) {
     systems.configure();
 
     ui::initSounds();
+       ui::menu::init();
        game::config::update();
        getSystem<PlayerSystem>()->create();
 }
 
-void Engine::render(entityx::TimeDelta dt)
-{
-    systems.update<RenderSystem>(dt);
-    //systems.update<InventorySystem>(dt); // doesn't do anything...
-
-       ui::fadeUpdate();
-}
-void Engine::resetRender(entityx::TimeDelta dt)
-{
-       systems.update<WindowSystem>(dt);
-}
-
 void Engine::update(entityx::TimeDelta dt)
 {
     systems.update<InputSystem>(dt);
index 908b6200b332e9761ef874005e2f8d339637db0b..4e323119a8b7d84c5e1dcdde0ea89acdc928e284 100644 (file)
@@ -1,7 +1,12 @@
 #include <render.hpp>
 
+#include <texture.hpp>
+
 static Shader *currentShader = nullptr;
 
+void preRender(void);
+void render(const int&);
+
 namespace Render {
 
 Shader worldShader;
@@ -62,4 +67,123 @@ void drawRect(vec2 ll, vec2 ur, float z)
     currentShader->disable();
 }
 
+void init(void)
+{
+#ifndef __WIN32__
+       glewExperimental = GL_TRUE;
+#endif
+
+       auto glewError = glewInit();
+       if (glewError != GLEW_OK)
+               UserError(std::string("GLEW was not able to initialize! Error: ")
+                       + reinterpret_cast<const char *>(glewGetErrorString(glewError)));
+
+       SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);               // anti-aliasing
+       SDL_GL_SetSwapInterval(0);                                 // v-sync
+       SDL_ShowCursor(SDL_DISABLE);                               // hide the cursor
+       glViewport(0, 0, game::SCREEN_WIDTH, game::SCREEN_HEIGHT); // pixel coordinates
+       glEnable(GL_BLEND);                                        // alpha enabling
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);         //
+       glClearColor(1, 1, 1, 1);                                  // white clear color
+
+       std::cout << "Initializing shaders!\n";
+       initShaders();
+       ::Colors::init();
+}
+
+void render(const int& fps)
+{
+       preRender();
+       ::render(fps);
+}
+
+} // namespace render
+
+#include <ui.hpp>
+#include <window.hpp>
+#include <world.hpp>
+#include <engine.hpp>
+#include <particle.hpp>
+#include <player.hpp>
+#include <entityx/entityx.h>
+#include <gametime.hpp>
+
+void preRender(void)
+{
+       static const glm::mat4 view = glm::lookAt(
+               glm::vec3(0.0f, 0.0f,  0.0f),  // pos
+               glm::vec3(0.0f, 0.0f, -10.0f), // looking at
+               glm::vec3(0.0f, 1.0f,  0.0f)   // up vector
+       );
+
+       static const auto& SCREEN_WIDTH2  = game::SCREEN_WIDTH / 2.0f;
+       static const auto& SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2.0f;
+
+       //
+       // set the ortho
+       //
+
+       auto ps = game::engine.getSystem<PlayerSystem>();
+       auto ploc = ps->getPosition();
+       offset.x = ploc.x + ps->getWidth() / 2;
+
+       const auto& worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
+       if (worldWidth < (int)SCREEN_WIDTH2 * 2)
+               offset.x = 0;
+       else if (offset.x - SCREEN_WIDTH2 < worldWidth * -0.5f)
+               offset.x = ((worldWidth * -0.5f) + SCREEN_WIDTH2);
+       else if (offset.x + SCREEN_WIDTH2 > worldWidth *  0.5f)
+               offset.x = ((worldWidth *  0.5f) - SCREEN_WIDTH2);
+
+       // ortho y snapping
+       offset.y = std::max(ploc.y /*+ player->height / 2*/, SCREEN_HEIGHT2);
+
+       // "setup"
+       glm::mat4 projection = glm::ortho(floor(offset.x - SCREEN_WIDTH2),             // left
+                                         floor(offset.x + SCREEN_WIDTH2),             // right
+                                         floor(offset.y - SCREEN_HEIGHT2),            // bottom
+                                         floor(offset.y + SCREEN_HEIGHT2),            // top
+                                         static_cast<decltype(floor(10.0f))>(10.0),   // near
+                                         static_cast<decltype(floor(10.0f))>(-10.0)); // far
+
+       glm::mat4 ortho = projection * view;
+
+       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+    glEnable(GL_DEPTH_TEST);
+
+    Render::worldShader.use();
+               glUniformMatrix4fv(Render::worldShader.uniform[WU_ortho], 1, GL_FALSE, glm::value_ptr(ortho));
+               glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
+       Render::worldShader.unuse();
+
+       Render::textShader.use();
+               glUniformMatrix4fv(Render::textShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(ortho));
+       glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
+       Render::textShader.unuse();
+}
+
+void render(const int& fps)
+{
+       preRender();
+
+       game::engine.getSystem<WorldSystem>()->render();
+
+       game::engine.getSystem<ParticleSystem>()->render();
+
+       game::engine.getSystem<RenderSystem>()->render();
+
+       // draw the debug overlay if desired
+       if (ui::debug) {
+               auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
+               ui::putText(offset.x - game::SCREEN_WIDTH / 2, (offset.y + game::SCREEN_HEIGHT / 2) - ui::fontSize,
+                   "loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s",
+                       pos.toString().c_str(), offset.toString().c_str(), fps,
+                       game::time::getTickCount(), game::engine.getSystem<ParticleSystem>()->getCount(),
+                       game::engine.getSystem<WorldSystem>()->getXMLFile().c_str());
+       }
+
+       ui::drawFade();
+       ui::draw();
+       
+       game::engine.getSystem<WindowSystem>()->render();
 }
index 21ed180d55f67e17b63e48869d11974fda270b25..9470a56d1682fa8fc88de45c93b2e14288cb3112 100644 (file)
@@ -535,8 +535,8 @@ namespace ui {
                auto& fi = fadeIntensity;
                fi = 0;
 
-               //while (fi < 255)
-                       //std::this_thread::sleep_for(1ms);
+               while (fi < 255)
+                       std::this_thread::sleep_for(1ms);
                        
                fi = 255;
        }
@@ -973,6 +973,18 @@ namespace ui {
                        }*/
                        setFontColor(255,255,255,255);
                }
+
+               if (currentMenu != nullptr)
+                       menu::draw();
+
+               // draw the mouse
+               static const Texture mouseTex ("assets/goodmouse.png");
+               Render::textShader.use();
+               glActiveTexture(GL_TEXTURE0);
+               mouseTex.use();
+               Render::useShader(&Render::textShader);
+               Render::drawRect(vec2(ui::mouse.x, ui::mouse.y - 64), vec2(ui::mouse.x + 64, ui::mouse.y), -9.9);
+               Render::textShader.unuse();
        }
 
        void closeBox() {
@@ -1017,43 +1029,40 @@ namespace ui {
        }
 
        void drawFade(void) {
-               static const auto SCREEN_WIDTH2 = game::SCREEN_WIDTH / 2;
-               static const auto SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2;
-
                if (!fadeIntensity) {
                        if (fontSize != 16)
                                setFontSize(16);
                        return;
                }
 
-               static const GLfloat tex[] = {
-                       0.0, 0.0,
-                       1.0, 0.0,
-                       0.0, 1.0,
-                       1.0, 1.0
+               static const GLfloat tex[12] = {
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                };
 
-        GLfloat backdrop[] = {
-                       offset.x - SCREEN_WIDTH2 - 1, offset.y - SCREEN_HEIGHT2, -7.9,
-                       offset.x + SCREEN_WIDTH2, offset.y - SCREEN_HEIGHT2, -7.9,
-                       offset.x - SCREEN_WIDTH2 - 1, offset.y + SCREEN_HEIGHT2, -7.9,
-                       offset.x + SCREEN_WIDTH2, offset.y + SCREEN_HEIGHT2, -7.9
+               vec2 p1 (offset.x - game::SCREEN_WIDTH / 2, offset.y - game::SCREEN_HEIGHT / 2);
+               vec2 p2 (p1.x + game::SCREEN_WIDTH, p1.y + game::SCREEN_HEIGHT);
+        GLfloat backdrop[18] = {
+                       p1.x, p1.y, -7.9,
+                       p2.x, p1.y, -7.9,
+                       p2.x, p2.y, -7.9,
+
+                       p2.x, p2.y, -7.9,
+                       p1.x, p2.y, -7.9,
+                       p1.x, p1.y, -7.9
                };
 
                setFontZ(-8.2);
-        glUniform1i(Render::textShader.uniform[WU_texture], 0);
-
                Render::textShader.use();
                Render::textShader.enable();
+
                Colors::black.use();
                glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, fadeIntensity / 255.0f);
         glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, backdrop);
         glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
-        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
 
                Render::textShader.disable();
                Render::textShader.unuse();
-
                setFontZ(-8.0);
     }
 
index 29bd7c7a7b1d9961d3c849083b6c36aed5699367..992e3c1a88fafabbffe4094bc3996b7906fc7ccd 100644 (file)
@@ -95,11 +95,7 @@ void WindowSystem::receive(const ScreenshotEvent &scr)
        std::cout << "Triggered\n";
 }
 
-void WindowSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
+void WindowSystem::render(void)
 {
-    (void)en;
-    (void)ev;
-    (void)dt;
-
     SDL_GL_SwapWindow(window);
 }
index a80fba8b47c896aa7d312869f909a1ec828ce17e..65514421aa603fa73c8e3fc73ad4a0aa8caa6eef 100644 (file)
@@ -1147,7 +1147,8 @@ void WorldSystem::detect(entityx::TimeDelta dt)
                const auto& data = world.data;
                if (loc.y < data[line].groundHeight) {
                        int dir = vel.x < 0 ? -1 : 1;
-                       if (line + dir * 2 < static_cast<int>(data.size()) &&
+                       auto thing = line + dir * 2;
+                       if (thing > 0 && thing < static_cast<int>(data.size()) &&
                            data[line + dir * 2].groundHeight - 30 > data[line + dir].groundHeight) {
                                loc.x -= (PLAYER_SPEED_CONSTANT + 2.7f) * dir * 2;
                                vel.x = 0;
@@ -1179,12 +1180,15 @@ void WorldSystem::goWorldRight(Position& p, Solid &d)
 {
        if (!(world.toRight.empty()) && (p.x + d.width > world.startX * -1 - HLINES(5))) {
                auto& rs = *game::engine.getSystem<RenderSystem>();
-               rs.fadeLock();
+               //rs.fadeLock();
+               ui::toggleBlack();
+               ui::waitForCover();
                while (waitToSwap)
                        std::this_thread::sleep_for(1ms);
                load(world.toRight);
                game::engine.getSystem<PlayerSystem>()->setX(world.startX + HLINES(10));
-               rs.unfade();
+               ui::toggleBlack();
+               //rs.unfade();
        }
 }