From 37ae27d47e148f3b4b7eaaa76ce98df680abcc6f Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 11 Jan 2017 19:11:56 -0500 Subject: entity manager lock --- include/engine.hpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'include/engine.hpp') diff --git a/include/engine.hpp b/include/engine.hpp index 2b03696..a331e50 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -70,6 +70,38 @@ public: } }; +#include +#include + +class LockableEntityManager : public entityx::EntityManager { +private: + std::atomic_bool locked; + +public: + LockableEntityManager(entityx::EventManager& ev) + : EntityManager(ev) { + locked.store(false); + } + + void lock(void) { + while (locked.load()) + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + + locked.store(true); + } + + void unlock(void) { + locked.store(false); + } + + bool try_lock(void) { + if (locked.load()) + return false; + + locked.store(true); + return true; + } +}; namespace game { /** @@ -80,8 +112,8 @@ namespace game { /** * Handles entity data. */ - extern entityx::EntityManager entities; - + extern LockableEntityManager entities; + /** * An instance of the main game engine. */ -- cgit v1.2.3 From 620311fb15953984c2fe37917d678f9b3aaa00b6 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 12 Jan 2017 09:27:43 -0500 Subject: fixes, main cleanup --- include/common.hpp | 1 - include/components.hpp | 14 +--- include/engine.hpp | 7 -- include/render.hpp | 3 + include/window.hpp | 4 +- main.cpp | 212 +++++-------------------------------------------- src/components.cpp | 66 ++------------- src/engine.cpp | 13 +-- src/render.cpp | 124 +++++++++++++++++++++++++++++ src/ui.cpp | 47 ++++++----- src/window.cpp | 6 +- src/world.cpp | 10 ++- 12 files changed, 196 insertions(+), 311 deletions(-) (limited to 'include/engine.hpp') diff --git a/include/common.hpp b/include/common.hpp index 12231dc..abfd28b 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -14,7 +14,6 @@ #include #include #include -#include // alternative windows thread library #ifndef __WIN32__ diff --git a/include/components.hpp b/include/components.hpp index 00ac8fa..2ec7a28 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -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, public entityx::Receiver { diff --git a/include/engine.hpp b/include/engine.hpp index a331e50..417522d 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -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 diff --git a/include/render.hpp b/include/render.hpp index 0a2adcd..cf58519 100644 --- a/include/render.hpp +++ b/include/render.hpp @@ -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_ diff --git a/include/window.hpp b/include/window.hpp index 5cf05ea..d53a2bf 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -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&); }; diff --git a/main.cpp b/main.cpp index 712c44a..40a8497 100644 --- a/main.cpp +++ b/main.cpp @@ -4,15 +4,11 @@ */ // standard library includes -#include -#include #include using namespace std::literals::chrono_literals; // local library includes #include -#include -using namespace tinyxml2; // our own includes #include @@ -20,17 +16,15 @@ using namespace tinyxml2; #include #include #include -#include #include #include #include #include -#include /** * 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(); - - // - // 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(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 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(); 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 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(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(e); + eventQueue.push_back(e); } // on game end, get back together @@ -234,17 +168,11 @@ int main(int argc, char *argv[]) //game::engine.getSystem()->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()->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(); - auto ploc = ps->getPosition(); - offset.x = ploc.x + ps->getWidth() / 2; - - const auto& worldWidth = game::engine.getSystem()->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(10.0), // near - static_cast(-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()->render(); - game::engine.getSystem()->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()->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()->getCount(), - game::engine.getSystem()->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(); -} diff --git a/src/components.cpp b/src/components.cpp index 4d80d25..28a81fe 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -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([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) { + game::entities.lock(); + game::entities.each([](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([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) { + game::entities.each([](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) diff --git a/src/engine.cpp b/src/engine.cpp index abadf3f..c7999ed 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -38,22 +38,11 @@ void Engine::init(void) { systems.configure(); ui::initSounds(); + ui::menu::init(); game::config::update(); getSystem()->create(); } -void Engine::render(entityx::TimeDelta dt) -{ - systems.update(dt); - //systems.update(dt); // doesn't do anything... - - ui::fadeUpdate(); -} -void Engine::resetRender(entityx::TimeDelta dt) -{ - systems.update(dt); -} - void Engine::update(entityx::TimeDelta dt) { systems.update(dt); diff --git a/src/render.cpp b/src/render.cpp index 908b620..4e32311 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -1,7 +1,12 @@ #include +#include + 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(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 +#include +#include +#include +#include +#include +#include +#include + +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(); + auto ploc = ps->getPosition(); + offset.x = ploc.x + ps->getWidth() / 2; + + const auto& worldWidth = game::engine.getSystem()->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(10.0), // near + static_cast(-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()->render(); + + game::engine.getSystem()->render(); + + game::engine.getSystem()->render(); + + // draw the debug overlay if desired + if (ui::debug) { + auto pos = game::engine.getSystem()->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()->getCount(), + game::engine.getSystem()->getXMLFile().c_str()); + } + + ui::drawFade(); + ui::draw(); + + game::engine.getSystem()->render(); } diff --git a/src/ui.cpp b/src/ui.cpp index 21ed180..9470a56 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -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); } diff --git a/src/window.cpp b/src/window.cpp index 29bd7c7..992e3c1 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -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); } diff --git a/src/world.cpp b/src/world.cpp index a80fba8..6551442 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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(data.size()) && + auto thing = line + dir * 2; + if (thing > 0 && thing < static_cast(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(); - rs.fadeLock(); + //rs.fadeLock(); + ui::toggleBlack(); + ui::waitForCover(); while (waitToSwap) std::this_thread::sleep_for(1ms); load(world.toRight); game::engine.getSystem()->setX(world.startX + HLINES(10)); - rs.unfade(); + ui::toggleBlack(); + //rs.unfade(); } } -- cgit v1.2.3