]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
more entityx, main.cpp cleanup
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 12 Oct 2016 00:02:04 +0000 (19:02 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 12 Oct 2016 00:02:04 +0000 (19:02 -0500)
14 files changed:
brice.dat
include/common.hpp
include/engine.hpp [new file with mode: 0644]
include/events.hpp
include/inventory.hpp
include/ui.hpp
include/world.hpp
main.cpp
src/entities.cpp
src/render.cpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp
xml/!town.xml

index a49519bc19be0df833e2e9e14dad4233653b8805..308f5c8c2c968edc4e514e70d9d83d86dfdce438 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,7 +1,7 @@
 3
-canSprint
-1
-canJump
-1
 Slow
 0
+canJump
+1
+canSprint
+1
index 8d74cda941e1c7904c87c425012ba005e0ffded9..15442a7a23e59b15bfb00aedabc16e6e21d73295 100644 (file)
@@ -245,27 +245,6 @@ constexpr const float PI = 3.1415926535f;
 // references the variable in main.cpp, used for drawing with the player
 extern vec2 offset;
 
-// reference to the shader programs we use throughout
-extern GLuint textShader;
-extern GLint textShader_attribute_coord;
-extern GLint textShader_attribute_tex;
-extern GLint textShader_uniform_texture;
-extern GLint textShader_uniform_color;
-
-extern GLuint worldShader;
-extern GLint worldShader_attribute_coord;
-extern GLint worldShader_attribute_tex;
-extern GLint worldShader_uniform_texture;
-extern GLint worldShader_uniform_texture_normal;
-extern GLint worldShader_uniform_color;
-extern GLint worldShader_uniform_transform;
-extern GLint worldShader_uniform_ambient;
-extern GLint worldShader_uniform_light;
-extern GLint worldShader_uniform_light_color;
-extern GLint worldShader_uniform_light_impact;
-extern GLint worldShader_uniform_light_amt;
-
-extern Color ambient;
 /**
  *     Prints a formatted debug message to the console, along with the callee's file and line
  *     number.
diff --git a/include/engine.hpp b/include/engine.hpp
new file mode 100644 (file)
index 0000000..0fabdb3
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef ENGINE_HPP_
+#define ENGINE_HPP_
+
+#include <entityx/entityx.h>
+
+#include <events.hpp>
+
+namespace game {
+    extern entityx::EventManager events;
+    extern entityx::EntityManager entities;
+
+    inline void endGame(void) {
+        events.emit<GameEndEvent>();
+    }
+}
+
+#endif // ENGINE_HPP_
index aa3ca0779df7a55db8828e1ea027e9a39113caf6..1fe7d7afa93e935034e63aae15e7ef8ae2f9ad21 100644 (file)
@@ -8,24 +8,31 @@
 #include <SDL2/SDL.h>
 
  struct MouseScrollEvent {
-       MouseScrollEvent(int sd)
+       MouseScrollEvent(int sd = 0)
                : scrollDistance(sd) {}
 
        int scrollDistance;
  };
 
 struct KeyDownEvent {
-    KeyDownEvent(SDL_Keycode kc)
+    KeyDownEvent(SDL_Keycode kc = 0)
         : keycode(kc) {}
 
     SDL_Keycode keycode;
 };
 
 struct KeyUpEvent {
-    KeyUpEvent(SDL_Keycode kc)
+    KeyUpEvent(SDL_Keycode kc = 0)
         : keycode(kc) {}
 
     SDL_Keycode keycode;
 };
 
+struct GameEndEvent {
+    GameEndEvent(bool r = true)
+        : really(r) {}
+
+    bool really;
+};
+
 #endif // EVENTS_HPP_
index 9a42aa480196a4884f45163b12e7a4ead523f686..533318c5035bf89044c7e5548f6efe7b1619bbdb 100644 (file)
@@ -18,8 +18,10 @@ class Entity;
 class Item {
 private:
        bool beingUsed;
+
 protected:
        std::vector<Entity*> interact;
+       
 public:
 
        // what we want to call each item
index f27688235015cfc8d220b22bf4d3c555c2cd8c69..86713937debf07dd6815ee10464a24feb9cd08a9 100644 (file)
@@ -149,13 +149,6 @@ namespace ui {
 
        void quitGame();
 
-
-
-       /*
-        *      Handle keyboard/mouse events.
-       */
-       void handleEvents(void);
-
        /*
         *      Toggle the black overlay thing.
        */
index 92a07b2f888672bb9de942d9cfb1bd0e8e097b21..6b264522849d454bebb8c65505bfaf1f4197bef9 100644 (file)
@@ -131,7 +131,7 @@ public:
 };
 
 /**
- * The world class. 
+ * The world class.
  * This class handles entity creation, management, and deletion. Most
  * world-related operations have to be done through this class, such as
  * drawing.
@@ -262,7 +262,7 @@ protected:
         * This function is only called in the world destructor.
         */
        void deleteEntities(void);
-       
+
        /**
         * Draws background textures.
         */
@@ -271,7 +271,7 @@ protected:
 public:
 
        CoolArray<Particles>    particles;
-       
+
        /**
         * A vector of pointers to all entities from the other vectors.
         * This is used to mass-manage entities, or operate on entities
@@ -330,6 +330,10 @@ public:
         */
        float getWorldStart(void) const;
 
+       inline unsigned int getEntityCount(void) const {
+               return entity.size();
+       }
+
        /**
         * Gets a pointer to the most recently created light.
         * This is used to update properties of the light outside of the
@@ -413,7 +417,7 @@ public:
         * Adopts an NPC from another world, taking its ownership.
         */
        void adoptNPC(NPC *e);
-       
+
        /**
         * Adopts a mob from another world, taking its ownership.
         */
index 454f4b47570d4d650b69c67a9c39215a046fd2e7..83afdc18ddb9c8687ae9b41d1fa63bdb0b9f5a68 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -12,6 +12,7 @@
 
 #include <window.hpp>
 #include <render.hpp>
+#include <engine.hpp>
 
 // local library includes
 #include <tinyxml2.h>
@@ -32,9 +33,6 @@ using namespace tinyxml2;
 ** Variables section
 ** --------------------------------------------------------------------------*/
 
-// main loop runs based on this variable's value
-bool gameRunning = true;
-
 // world objects for the current world and the two that are adjacent
 World *currentWorld        = NULL,
          *currentWorldToLeft  = NULL,
@@ -52,9 +50,6 @@ Menu *currentMenu;
 // the player object
 Player *player;
 
-// the ambient light of the current world
-Color ambient;
-
 // keeps a simple palette of colors for single-color draws
 GLuint colorIndex;
 
@@ -86,12 +81,25 @@ void mainLoop(void);
 ** MAIN ************************************************************************
 ********************************************************************************/
 
-class Engine : public entityx::EntityX {
+namespace game {
+       entityx::EventManager events;
+       entityx::EntityManager entities (events);
+}
+
+class Engine : public entityx::Receiver<Engine> {
+private:
+       bool gameRunning;
+
 public:
-       explicit Engine(void) {}
+       entityx::SystemManager systems;
+
+       explicit Engine(void)
+               : gameRunning(true), systems(game::entities, game::events) {}
 
        void init(void) {
                game::config::read();
+               game::events.subscribe<GameEndEvent>(*this);
+
                systems.add<WindowSystem>();
                systems.add<InputSystem>();
                systems.add<InventorySystem>();
@@ -112,6 +120,18 @@ public:
                currentWorld->update(player, dt);
                currentWorld->detect(player);
        }
+
+       void configure(entityx::EventManager &ev) {
+               (void)ev;
+       }
+
+       void receive(const GameEndEvent &gee) {
+               gameRunning = !(gee.really);
+       }
+
+       inline bool shouldRun(void) const {
+               return gameRunning;
+       }
 };
 
 Engine engine;
@@ -260,13 +280,9 @@ int main(int argc, char *argv[])
        arena->setBackground(WorldBGType::Forest);
        arena->setBGM("assets/music/embark.wav");
 
-
-       player->inv->addItem("Hunters Bow", 1);
-
-
        // the main loop, in all of its gloriousness..
        std::thread([&]{
-               while (gameRunning) {
+               while (engine.shouldRun()) {
                        mainLoop();
                        std::this_thread::sleep_for(std::chrono::milliseconds(1));
                }
@@ -274,7 +290,7 @@ int main(int argc, char *argv[])
 
        // the debug loop, gets debug screen values
        std::thread([&]{
-               while (gameRunning) {
+               while (engine.shouldRun()) {
                        fps = 1000 / game::time::getDeltaTime();
                        debugY = player->loc.y;
 
@@ -282,10 +298,9 @@ int main(int argc, char *argv[])
                }
        }).detach();
 
-       while (gameRunning) {
+       while (engine.shouldRun()) {
                engine.render(0);
                render();
-               ui::handleEvents();
        }
 
        // put away the brice for later
@@ -307,14 +322,21 @@ int main(int argc, char *argv[])
     return 0; // Calls everything passed to atexit
 }
 
+extern std::vector<NPC *> aipreload;
+
 void mainLoop(void){
        game::time::mainLoopHandler();
 
        if (currentMenu) {
                return;
        } else {
-               // handle keypresses - currentWorld could change here
-               //ui::handleEvents();
+               // Flush preloaded AI functions if necessary
+               if (!ui::dialogBoxExists) {
+                       while (!aipreload.empty()) {
+                               aipreload.front()->addAIFunc(false);
+                               aipreload.erase(std::begin(aipreload));
+                       }
+               }
 
                if (game::time::tickHasPassed())
                        logic();
@@ -358,51 +380,30 @@ void render() {
 
        // TODO add depth
     glEnable(GL_DEPTH_TEST);
-       //glEnable(GL_CULL_FACE);
 
        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);
+               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();
     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)));
-
-       glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
-       glUniform4f(Render::worldShader.uniform[WU_ambient], ambient.red, ambient.green, ambient.blue, 1.0);
-       glUniform1f(Render::worldShader.uniform[WU_light_impact], 1.0);
-
-       /*static GLfloat l[]  = {460.0, 100.0, 0.0, 300.0};
-       static GLfloat lc[] = {1.0, 1.0, 1.0, 1.0};
-       glUniform4fv(worldShader_uniform_light, 1, l);
-       glUniform4fv(worldShader_uniform_light_color, 1, lc);
-       glUniform1i(worldShader_uniform_light_amt, 1);
-       */
-       /**************************
-       **** RENDER STUFF HERE ****
-       **************************/
-
-       /**
-        * Call the world's draw function, drawing the player, the world, the background, and entities. Also
-        * draw the player's inventory if it exists.
-        */
-       //player->near = true; // allow player's name to be drawn
+               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();
+
+       // draw the world and player
        currentWorld->draw(player);
 
        // draw the player's inventory
        player->inv->draw();
 
-
        // draw the fade overlay
        ui::drawFade();
 
        // draw ui elements
        ui::draw();
 
-       /*
-        * Draw the debug overlay if it has been enabled.
-        */
-
-       if(ui::debug){
+       // draw the debug overlay if desired
+       if (ui::debug) {
                ui::putText(offset.x-SCREEN_WIDTH/2, (offset.y+SCREEN_HEIGHT/2)-ui::fontSize,
                                        "fps: %d\ngrounded:%d\nresolution: %ux%u\nentity cnt: %d\nloc: (%+.2f, %+.2f)\nticks: %u\nvolume: %f\nweather: %s\nxml: %s",
                                        fps,
@@ -418,16 +419,12 @@ void render() {
                                        currentXML.c_str()
                                        );
 
-               static GLuint tracerText = Texture::genColor(Color(100,100,255));
-
-               uint es = currentWorld->entity.size();
-               GLfloat tpoint[es * 2 * 5];
-               GLfloat *tp = &tpoint[0];
-
-               Render::textShader.use();
-               glBindTexture(GL_TEXTURE_2D, tracerText);
-
+               // draw tracer lines if desired
+               static const GLuint tracerText = Texture::genColor(Color(100,100,255));
                if (ui::posFlag) {
+                       GLfloat *tpoint = new GLfloat[currentWorld->getEntityCount() * 2 * 5];
+                       auto tp = tpoint;
+
                        for (auto &e : currentWorld->entity) {
                                *(tp++) = player->loc.x + player->width / 2;
                                *(tp++) = player->loc.y + player->height / 2;
@@ -443,58 +440,32 @@ void render() {
                                *(tp++) = 1.0;
                                *(tp++) = 1.0;
                        }
-               }
 
-               Render::worldShader.enable();
+                       Render::textShader.use();
+                               glBindTexture(GL_TEXTURE_2D, tracerText);
+                               Render::textShader.enable();
+                               glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &tpoint[0]);
+                               glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &tpoint[3]);
+                               glDrawArrays(GL_LINES, 0, currentWorld->getEntityCount() * 2);
+                               Render::textShader.disable();
+                       Render::textShader.unuse();
 
-               glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &tpoint[0]);
-               glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &tpoint[3]);
-               glDrawArrays(GL_LINES, 0, es * 2);
-
-               Render::worldShader.disable();
-               Render::worldShader.unuse();
+                       delete[] tpoint;
+               }
 
        }
 
-
-
+       // draw the menu
        if (currentMenu)
                ui::menu::draw();
 
+       // draw the mouse
        Render::textShader.use();
-       glActiveTexture(GL_TEXTURE0);
-       glBindTexture(GL_TEXTURE_2D, mouseTex);
-       glUniform1i(Render::textShader.uniform[WU_texture], 0);
-
-       Render::textShader.enable();
-
-       glDisable(GL_DEPTH_TEST);
-
-       GLfloat mouseCoords[] = {
-               ui::mouse.x                     ,ui::mouse.y,         -9.9, //bottom left
-               ui::mouse.x+15          ,ui::mouse.y,             -9.9, //bottom right
-               ui::mouse.x+15          ,ui::mouse.y-15,          -9.9, //top right
-
-               ui::mouse.x+15          ,ui::mouse.y-15,          -9.9, //top right
-               ui::mouse.x             ,ui::mouse.y-15,          -9.9, //top left
-               ui::mouse.x                     ,ui::mouse.y,             -9.9, //bottom left
-       };
-
-       GLfloat mouseTex[] = {
-               0.0f, 0.0f, //bottom left
-               1.0f, 0.0f, //bottom right
-               1.0f, 1.0f, //top right
-
-               1.0f, 1.0f, //top right
-               0.0f, 1.0f, //top left
-               0.0f, 0.0f, //bottom left
-       };
-
-       glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, mouseCoords);
-       glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, mouseTex);
-       glDrawArrays(GL_TRIANGLES, 0, 6);
-
-       Render::textShader.disable();
+               glActiveTexture(GL_TEXTURE0);
+               glBindTexture(GL_TEXTURE_2D, mouseTex);
+               Render::useShader(&Render::textShader);
+               Render::drawRect(ui::mouse, ui::mouse + 15, -9.9);
+       Render::textShader.unuse();
 }
 
 void logic(){
@@ -503,7 +474,7 @@ void logic(){
 
        // exit the game if the player falls out of the world
        if (player->loc.y < 0)
-               gameRunning = false;
+               game::endGame();
 
        if (player->inv->usingi) {
                for (auto &e : currentWorld->entity) {
@@ -557,13 +528,6 @@ void logic(){
        // calculate the world shading value
        worldShade = 50 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
 
-       float ws = 75 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
-
-       float ambRG = std::clamp(.5f + (-ws / 100.0f), 0.01f, .9f);
-       float ambB =    std::clamp(.5f + (-ws / 80.0f), 0.03f, .9f);
-
-       ambient = Color(ambRG, ambRG, ambB, 1.0f);
-
        // update fades
        ui::fadeUpdate();
 
index fbab59f2e94de769025cb76bd58920c1a1bae990..544b1c83186ad718c2c997681c36da07e8e34ce4 100644 (file)
@@ -10,6 +10,7 @@
 #include <brice.hpp>
 
 #include <render.hpp>
+#include <engine.hpp>
 
 extern std::istream *names;
 
@@ -47,7 +48,6 @@ void PlayerSystem::configure(entityx::EventManager &ev)
        ev.subscribe<KeyUpEvent>(*this);
 }
 
-extern std::array<SDL_Keycode, 6> controlMap;
 extern World  *currentWorldToLeft;
 extern World  *currentWorldToRight;
 extern bool gameRunning;
@@ -61,13 +61,13 @@ void PlayerSystem::receive(const KeyUpEvent &kue)
        if (kc == SDLK_ESCAPE) {
                ui::menu::toggle();
                p->save();
-       } else if (kc == controlMap[1]) {
+       } else if (kc == getControl(1)) {
                m_MoveLeft = false;
-       } else if (kc == controlMap[2]) {
+       } else if (kc == getControl(2)) {
                m_MoveRight = false;
-       } else if (kc == controlMap[3] || kc == controlMap[4]) {
+       } else if (kc == getControl(3) || kc == getControl(4)) {
                player->speed = 1;
-       } else if (kc == controlMap[5]) {
+       } else if (kc == getControl(5)) {
                if (p->inv->invHover) {
                        p->inv->invHover = false;
                } else {
@@ -94,10 +94,10 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                ui::toggleBlackFast();
                ui::waitForCover();
                wsi.first->bgmPlay(currentWorld);
-               std::tie(currentWorld, p->loc) = wsi;
+               std::tie(currentWorld, player->loc) = wsi; // using p causes segfault
                ui::toggleBlackFast();
                ui::waitForUncover();
-               p->canMove = true;
+               player->canMove = true; // using p causes segfault
        };
 
        if ((kc == SDLK_SPACE) && (game::canJump & p->ground)) {
@@ -107,7 +107,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
        }
 
        if (!ui::dialogBoxExists || ui::dialogPassive) {
-               if (kc == controlMap[0]) {
+               if (kc == getControl(0)) {
                        if (inBattle) {
                                std::thread([&](void){
                                        auto thing = dynamic_cast<Arena *>(currentWorld)->exitArena(p);
@@ -121,7 +121,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                                                worldSwitch(thing);
                                }).detach();
                        }
-               } else if (kc == controlMap[1]) {
+               } else if (kc == getControl(1)) {
                        if (!ui::fadeEnable) {
                                p->vel.x = -PLAYER_SPEED_CONSTANT;
                                if (std::stoi(game::getValue("Slow")) == 1)
@@ -136,7 +136,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                                        }).detach();
                                }
                        }
-               } else if (kc == controlMap[2]) {
+               } else if (kc == getControl(2)) {
                        if (!ui::fadeEnable) {
                                p->vel.x = PLAYER_SPEED_CONSTANT;
                                if (std::stoi(game::getValue("Slow")) == 1)
@@ -151,12 +151,12 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                                        }).detach();
                                }
                        }
-               } else if (kc == controlMap[3]) {
+               } else if (kc == getControl(3)) {
                        if (game::canSprint)
                                p->speed = 2.0f;
-               } else if (kc == controlMap[4]) {
+               } else if (kc == getControl(4)) {
                        p->speed = .5;
-               } else if (kc == controlMap[5]) {
+               } else if (kc == getControl(5)) {
                        static int heyOhLetsGo = 0;
 
                        //edown = true;
@@ -176,7 +176,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                        }
                }
        } else if (kc == SDLK_DELETE) {
-               gameRunning = false;
+               game::endGame();
        } else if (kc == SDLK_t) {
                game::time::tick(50);
        }
index 0c522f69b8cf85d2f5da15f0b13429e2465f71db..908b6200b332e9761ef874005e2f8d339637db0b 100644 (file)
@@ -62,5 +62,4 @@ void drawRect(vec2 ll, vec2 ur, float z)
     currentShader->disable();
 }
 
-
 }
index a7e377728c79c26ed8a8652d078eef75f310e737..f7cc0992f1d068b77eadebc36abfdc8737198df6 100644 (file)
@@ -6,6 +6,7 @@
 #include <gametime.hpp>
 
 #include <render.hpp>
+#include <engine.hpp>
 #include <events.hpp>
 
 extern Menu* currentMenu;
@@ -21,12 +22,6 @@ extern World  *currentWorld;
 extern World  *currentWorldToLeft;
 extern World  *currentWorldToRight;
 
-/**
- * In the case of dialog, some NPC quests can be preloaded so that they aren't assigned until
- * the dialog box closes. Reference variables for that here.
- */
-extern std::vector<NPC *> aipreload;
-
 /**
  * Pressing ESC or closing the window will set this to false.
  */
@@ -1214,9 +1209,9 @@ namespace ui {
        void quitGame() {
                dialogBoxExists = false;
                currentMenu = NULL;
-               gameRunning = false;
                game::config::update();
                game::config::save();
+               game::endGame();
        }
 
        void closeBox() {
@@ -1281,16 +1276,6 @@ EXIT:
                }
        }
 
-       void handleEvents(void) {
-               // Flush preloaded AI functions if necessary
-               if (!dialogBoxExists) {
-                       while (!aipreload.empty()) {
-                               aipreload.front()->addAIFunc(false);
-                               aipreload.erase(std::begin(aipreload));
-                       }
-               }
-       }
-
        void drawFade(void) {
                auto SCREEN_WIDTH = game::SCREEN_WIDTH;
                auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
@@ -1474,7 +1459,7 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
 
                // escape - quit game
                case SDL_QUIT:
-                       gameRunning = false;
+                       game::endGame();
                        break;
 
                // mouse movement - update mouse vector
index f0299c62f3662aaf92f59f8cc4c88a19504eb976..4b4b05c41eebc4a21b941320412ccc91c4d206d0 100644 (file)
@@ -1,5 +1,6 @@
 #include <ui_menu.hpp>
 
+#include <engine.hpp>
 #include <render.hpp>
 
 #include <fstream>
@@ -211,7 +212,7 @@ namespace ui {
             while(SDL_PollEvent(&e)) {
                 switch (e.type) {
                 case SDL_QUIT:
-                    gameRunning = false;
+                    game::endGame();
                     return;
                     break;
                 case SDL_MOUSEMOTION:
index 38718677f61a84eb32906a20663367266b4a58d2..320c1dbba3aac4ce3c69f8129bd4b76fecee5f26 100644 (file)
@@ -236,11 +236,8 @@ generate(int width)
        weather = WorldWeather::None;
 }
 
-/**
- * The world draw function.
- * This function will draw the background layers, entities, and player to the
- * screen.
- */
+static Color ambient;
+
 void World::drawBackgrounds(void)
 {
     auto SCREEN_WIDTH = game::SCREEN_WIDTH;
@@ -515,6 +512,22 @@ void World::draw(Player *p)
        uint lpIndex = 0;
        uint lcIndex = 0;
 
+       static bool ambientUpdaterStarted = false;
+       if (!ambientUpdaterStarted) {
+               ambientUpdaterStarted = true;
+               std::thread([&](void) {
+                       while (true) {
+                               float v = 75 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
+                               float rg = std::clamp(.5f + (-v / 100.0f), 0.01f, .9f);
+                               float b  = std::clamp(.5f + (-v / 80.0f), 0.03f, .9f);
+
+                               ambient = Color(rg, rg, b, 1.0f);
+
+                               std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                       }
+               }).detach();
+       }
+
        for (uint i = 0; i < ls; i++) {
                auto &l = light[i];
                if (l.belongsTo) {
index b105127021304a345f06069cb7221f420b7ec837..2627e8248b805d7f63265e7e8e6edd1474f14dff 100644 (file)
@@ -4,8 +4,8 @@
     <generation type="Random" width="1600"/>
     <time>6000</time>
     <spawnx>-300</spawnx>
-    <npc name="Sanc" hasDialog="true" health="1" x="406.31683" y="72.998955" dindex="9999"/>
-    <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="403.52261" y="72.998955" dindex="0"/>
+    <npc name="Sanc" hasDialog="true" health="1" x="735" y="66.199104" dindex="9999"/>
+    <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="460.8461" y="67.399094" dindex="0"/>
     <structure type="1" spawnx="300" alive="1"/>
     <structure inside="bobshouse.xml" type="1" spawnx="10" alive="1"/>
     <chest alive="1"/>