]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world draw fix; offset fix
authorClyne Sullivan <tullivan99@gmail.com>
Sun, 27 Nov 2016 21:28:51 +0000 (16:28 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Sun, 27 Nov 2016 21:28:51 +0000 (16:28 -0500)
13 files changed:
include/events.hpp
include/player.hpp
include/ui.hpp
include/ui_action.hpp.bak [deleted file]
include/world.hpp
main.cpp
src/player.cpp
src/texture.cpp
src/ui.cpp
src/ui_action.cpp.bak [deleted file]
src/world.cpp
xml/!town.xml
xml/bobshouse.xml

index 975855c443cf29e3ffa8e965ba096ca9960accb3..f38d4e67d75883644b3a58276311693fcc99d25b 100644 (file)
@@ -1,4 +1,4 @@
-#ifndef EVENTS_HPP_
+z#ifndef EVENTS_HPP_
 #define EVENTS_HPP_
 
 /**
@@ -75,7 +75,7 @@ struct BGMToggleEvent {
 struct WindowResizeEvent {
        WindowResizeEvent(int w = 640, int h = 480)
                : x(w), y(h) {}
-       
+
        int x;
        int y;
 };
@@ -83,9 +83,9 @@ struct WindowResizeEvent {
 struct ScreenshotEvent {
        ScreenshotEvent(int w = game::SCREEN_HEIGHT, int h = game::SCREEN_WIDTH)
                : w(w), h(h) {}
-       
+
        int w;
-       int h;  
+       int h;
 };
 
 #endif // EVENTS_HPP_
index 187e77e1296986dc933a31c29258e76f01617c54..59d6368e57d3b8001adeba6a8a7a6701d056ac59 100644 (file)
@@ -4,6 +4,7 @@
 #include <entityx/entityx.h>
 
 #include <events.hpp>
+#include <engine.hpp>
 #include <components.hpp>
 #include <common.hpp>
 
@@ -34,6 +35,8 @@ public:
     vec2 getPosition(void) const;
        inline void setX(const float& x)
        { player.component<Position>().get()->x = x; }
+    inline float getWidth(void) const
+    { return game::entities.component<Solid>(player.id())->width; }
 };
 
 #endif // PLAYER_HPP_
index 5863cf06ac04bb16c2143981efe56b88653f2454..85c5997a30e9672ba2bf5f29e67fff6fb85fa734 100644 (file)
@@ -23,7 +23,7 @@
 #include <config.hpp>
 //#include <inventory.hpp>
 #include <ui_menu.hpp>
-//#include <ui_action.hpp>
+#include <events.hpp>
 
 // local library headers
 #include <SDL2/SDL_opengl.h>
@@ -160,7 +160,7 @@ namespace ui {
        /*
         *  Takes a screenshot of the game
         */
-       
+
        void takeScreenshot(GLubyte *pixels);
 }
 
diff --git a/include/ui_action.hpp.bak b/include/ui_action.hpp.bak
deleted file mode 100644 (file)
index a275ab3..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef ACTION_H_
-#define ACTION_H_
-
-#include <common.hpp>
-#include <ui.hpp>
-
-namespace ui {
-    namespace action {
-        extern bool make;
-
-        // enables the action ui
-        void enable(void);
-        // disables the action ui
-        void disable(void);
-
-        // draws the action ui
-        void draw(vec2 loc);
-    }
-}
-
-#endif // ACTION_H_
index cb8c30d40939a1436d1b592648e5a037cfaf5f07..b8a80a418f6483ff9478c40128bc9ad0abddc204 100644 (file)
@@ -168,6 +168,8 @@ private:
        std::string currentXMLFile;
 
 public:
+       std::thread thAmbient;
+
        explicit WorldSystem(void);
        ~WorldSystem(void);
 
@@ -206,7 +208,7 @@ public:
        // worlddata2 stuff
        WorldData2 worldData;
 
-       void generate(unsigned int width = 0);
+       void generate(int width = 0);
        void addHole(const unsigned int& start, const unsigned int& end);
        void addHill(const ivec2& peak, const unsigned int& width);
 
index 982d70b505c2fd9ac32ef297d508f97f41e02f67..298fc6be3702d5ee74a66d77469fa3e962004ef2 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -199,7 +199,7 @@ int main(int argc, char *argv[])
 
        if (!worldDontReallyRun) {
                // the main loop, in all of its gloriousness..
-               std::thread([&] {
+               std::thread thMain ([&] {
                        const bool &run = game::engine.shouldRun;
                        while (run) {
                                game::time::mainLoopHandler();
@@ -211,10 +211,10 @@ int main(int argc, char *argv[])
 
                                std::this_thread::sleep_for(1ms);
                        }
-               }).detach();
+               });
 
                // the debug loop, gets debug screen values
-               std::thread([&] {
+               std::thread thDebug ([&] {
                        const bool &run = game::engine.shouldRun;
                        while (run) {
                                fps = 1000 / game::time::getDeltaTime();
@@ -222,13 +222,17 @@ int main(int argc, char *argv[])
 
                                std::this_thread::sleep_for(1s);
                        }
-               }).detach();
+               });
 
                const bool &run = game::engine.shouldRun;
                while (run) {
                        game::engine.render(0);
                        render();
                }
+
+               thMain.join();
+               thDebug.join();
+               //game::engine.getSystem<WorldSystem>()->thAmbient.join();
        }
 
        // put away the brice for later
@@ -254,7 +258,8 @@ void render() {
        const auto SCREEN_WIDTH = game::SCREEN_WIDTH;
        const auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
 
-       offset.x = game::engine.getSystem<PlayerSystem>()->getPosition().x;// + player->width / 2;
+       auto ps = game::engine.getSystem<PlayerSystem>();
+       offset.x = ps->getPosition().x + ps->getWidth() / 2;
 
        const auto& worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
        if (worldWidth < (int)SCREEN_WIDTH)
index 2694a549ba3bd3bca25ccf0eed64686fe5eb256a..a88734a343234f13b84078cad8b7e0ad973cf0c4 100644 (file)
@@ -1,7 +1,6 @@
 #include <player.hpp>
 
 #include <brice.hpp>
-#include <engine.hpp>
 #include <ui.hpp>
 #include <gametime.hpp>
 #include <world.hpp>
@@ -71,10 +70,7 @@ void PlayerSystem::receive(const KeyUpEvent &kue)
                                p->inv->selected = false;
 
                        p->inv->mouseSel = false;
-               }
-
-               // disable action ui
-               ui::action::disable();*/
+               }*/
        }
 }
 
@@ -114,23 +110,17 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                } else if (kc == getControl(4)) {
                        speed = .5;
                } else if (kc == getControl(5)) {
-                       /*static int heyOhLetsGo = 0;
-
+                       //static int heyOhLetsGo = 0;
                        //edown = true;
-
                        // start hover counter?
-                       if (!heyOhLetsGo) {
-                               heyOhLetsGo = game::time::getTickCount();
-                               p->inv->mouseSel = false;
-                       }
+                       //if (!heyOhLetsGo) {
+                       //      heyOhLetsGo = game::time::getTickCount();
+                       //      p->inv->mouseSel = false;
+                       //}
 
                        // run hover thing
-                       if (game::time::getTickCount() - heyOhLetsGo >= 2 && !(p->inv->invOpen) && !(p->inv->selected)) {
-                               p->inv->invHover = true;
-
-                               // enable action ui
-                               ui::action::enable();
-                       }*/
+                       //if (game::time::getTickCount() - heyOhLetsGo >= 2 && !(p->inv->invOpen) && !(p->inv->selected))
+                       //      p->inv->invHover = true;
                }
        } else if (kc == SDLK_DELETE) {
                game::endGame();
index 3a2f0717acb8abea6ac1b29180f857b766406c76..a232e0e2157df3e17899f1ccee3f4c2e5a382b30 100644 (file)
@@ -46,7 +46,6 @@ namespace Texture{
 
        GLuint loadTexture(std::string fileName) {
                SDL_Surface *image;
-               static GLuint object = 0;
 
                // check if texture is already loaded
                for(auto &t : LoadedTexture) {
@@ -67,11 +66,13 @@ namespace Texture{
 #ifdef DEBUG
                DEBUG_printf("Loaded image file: %s\n", fileName.c_str());
 #endif // DEBUG
+
                /*
                 * Load texture through OpenGL.
                 */
-               //glGenTextures(1,&object);                             // Turns "object" into a texture
-               glBindTexture(GL_TEXTURE_2D,++object);  // Binds "object" to the top of the stack
+               GLuint object;
+               glGenTextures(1, &object);                              // Turns "object" into a texture
+               glBindTexture(GL_TEXTURE_2D, object);   // Binds "object" to the top of the stack
                glPixelStoref(GL_UNPACK_ALIGNMENT,1);
 
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);      // Sets the "min" filter
index 94100e470e90dac97111ae06178ca8a84fb848fe..9439e30b3e0cbc383998ce1540cbc5ddfc29f780 100644 (file)
@@ -9,6 +9,7 @@
 #include <engine.hpp>
 #include <events.hpp>
 #include <window.hpp>
+#include <player.hpp>
 
 #include <chrono>
 using namespace std::literals::chrono_literals;
@@ -850,9 +851,6 @@ namespace ui {
 
                auto SCREEN_HEIGHT = static_cast<float>(game::SCREEN_HEIGHT);
 
-               // will return if not toggled
-               //action::draw(vec2 {player->loc.x + player->width / 2, player->loc.y + player->height + game::HLINE});
-
                // will return if not toggled
                quest::draw();
 
diff --git a/src/ui_action.cpp.bak b/src/ui_action.cpp.bak
deleted file mode 100644 (file)
index 9029907..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-#include <ui_action.hpp>
-#include <world.hpp>
-
-#define ACTION_PROLOUGE { actioning = true; }
-#define ACTION_EPILOUGE { actioning = false; actionHover = 0; }
-
-extern World *currentWorld;
-extern Arena *arena;
-extern Player *player;
-extern bool inBattle;
-
-static std::vector<std::pair<std::string, vec3>> actionText = {
-    {"Attack", vec3 {0, 0, 0}},
-    {"Action", vec3 {0, 0, 0}},
-    {"Umm"   , vec3 {0, 0, 0}}
-};
-
-void actionAttack(void);
-void actionAction(void);
-
-static std::vector<void (*)(void)> actionFunc = {
-    actionAttack,
-    actionAction,
-    nullptr,
-};
-
-static bool actionToggle = false, actioning = false;
-static unsigned int actionHover = 0;
-static Entity *nearEntity = nullptr, *lastEntity = nullptr;
-
-namespace ui {
-    namespace action {
-        bool make = false;
-
-        // enables action ui
-        void enable(void) {
-            actionToggle = true;
-        }
-
-        // disables action ui
-        void disable(void) {
-            actionToggle = false;
-
-            if (lastEntity != nullptr)
-                lastEntity->canMove = true;
-        }
-
-        // draws the action ui
-        void draw(vec2 loc) {
-            unsigned int i = 1;
-            float y = loc.y;
-
-            if (!actionToggle)
-                return;
-
-            nearEntity = currentWorld->getNearInteractable(*player);
-
-            if (nearEntity == nullptr) {
-                if (lastEntity != nullptr) {
-                    lastEntity->canMove = true;
-                    lastEntity = nullptr;
-                }
-                return;
-            } else if (nearEntity != lastEntity) {
-                if (lastEntity != nullptr)
-                    lastEntity->canMove = true;
-                lastEntity = nearEntity;
-            }
-
-            if (make) {
-                while(actioning);
-
-                if (!actionHover) {
-                    make = false;
-                    return;
-                }
-
-                if (actionFunc[actionHover - 1] != nullptr)
-                    std::thread(actionFunc[actionHover - 1]).detach();
-
-                actionHover = 0;
-            } else {
-                nearEntity->canMove = false;
-                ui::drawBox(vec2 {loc.x - HLINES(11), loc.y}, vec2 {loc.x + HLINES(12), loc.y + actionText.size() * HLINES(8)});
-
-                for (auto &s : actionText) {
-                    s.second.z = ui::putStringCentered((s.second.x = loc.x), (s.second.y = (y += fontSize * 1.15f)), s.first) / 2;
-
-                    if (ui::mouse.x > s.second.x - s.second.z && ui::mouse.x < s.second.x + s.second.z &&
-                        ui::mouse.y > s.second.y && ui::mouse.y < s.second.y + ui::fontSize) {
-                        actionHover = i;
-                        ui::setFontColor(255, 100, 100, 255);
-                        ui::putStringCentered(s.second.x, s.second.y, s.first);
-                        ui::setFontColor(255, 255, 255, 255);
-                    }
-                    i++;
-                }
-
-                ui::putStringCentered(loc.x, y + fontSize * 1.2f, nearEntity->name);
-            }
-
-            if (i == actionText.size())
-                actionHover = 0;
-
-            ui::setFontColor(255, 255, 255, 255);
-            make = false;
-        }
-    }
-}
-
-void actionAttack(void)
-{
-    ACTION_PROLOUGE;
-
-    auto m = currentWorld->getNearInteractable(*player);
-
-    if (m->type == MOBT) {
-        if (!inBattle && m != nullptr) {
-            arena->fight(currentWorld, player, Mobp(m));
-
-            ui::toggleWhiteFast();
-            ui::waitForCover();
-            currentWorld = arena;
-            ui::toggleWhiteFast();
-        }
-    } else {
-        ui::dialogBox(player->name, "", false, "%s doesn't appear to be in the mood for fighting...", m->name.c_str());
-    }
-
-    ACTION_EPILOUGE;
-}
-
-void actionAction(void)
-{
-    ACTION_PROLOUGE;
-
-    auto e = currentWorld->getNearInteractable(*player);
-
-    if (e->type == NPCT)
-        e->interact();
-
-    ACTION_EPILOUGE;
-}
index f4795aca6bb00505f1a2f4099231adff867c64f3..4ab8af7bb899026c697f7ed8e3d778e816e18aca 100644 (file)
@@ -114,7 +114,7 @@ static const float bgDraw[4][3]={
 ** Functions section
 ** --------------------------------------------------------------------------*/
 
-void WorldSystem::generate(unsigned int width)
+void WorldSystem::generate(int width)
 {
        float geninc = 0;
 
@@ -209,7 +209,9 @@ void WorldSystem::load(const std::string& file)
                auto file = ixml->Attribute("file");
                if (file != nullptr) {
                        DEBUG_printf("Including file: %s\n", file);
-                       xmlRaw.append(readFile((xmlFolder + file).c_str()));
+                       auto include = readFile((xmlFolder + file).c_str());
+                       xmlRaw.append(include);
+                       delete[] include;
                }
                ixml = ixml->NextSiblingElement();
        }
@@ -263,7 +265,7 @@ void WorldSystem::load(const std::string& file)
 
         // world generation
         else if (tagName == "generation") {
-                       generate(wxml->UnsignedAttribute("width") / game::HLINE);
+                       generate(wxml->IntAttribute("width"));
                }
 
                // indoor stuff
@@ -272,7 +274,9 @@ void WorldSystem::load(const std::string& file)
                                UserError("<house> can only be used inside <IndoorWorld>");
 
                        world.indoorWidth = wxml->FloatAttribute("width");
-                       world.indoorTex = Texture::loadTexture(wxml->Attribute("texture"));
+                       auto str = wxml->StrAttribute("texture");
+                       auto tex = Texture::loadTexture(str);
+                       world.indoorTex = tex;
                }
 
                // weather tag
@@ -649,8 +653,9 @@ void WorldSystem::render(void)
        static bool ambientUpdaterStarted = false;
        if (!ambientUpdaterStarted) {
                ambientUpdaterStarted = true;
-               std::thread([&](void) {
-                       while (true) {
+               thAmbient = std::thread([&](void) {
+                       const bool &run = game::engine.shouldRun;
+                       while (run) {
                                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);
@@ -659,7 +664,8 @@ void WorldSystem::render(void)
 
                                std::this_thread::sleep_for(1ms);
                        }
-               }).detach();
+               });
+               thAmbient.detach();
        }
 
 
@@ -883,8 +889,8 @@ void WorldSystem::render(void)
     // only draw world within player vision
     iStart = std::clamp(static_cast<int>(pOffset - (SCREEN_WIDTH / 2 / HLINE) - GROUND_HILLINESS),
                            0, static_cast<int>(world.data.size()));
-       iEnd = std::clamp(static_cast<int>(pOffset + (SCREEN_WIDTH / 2 / HLINE)),
-                      0, static_cast<int>(world.data.size())) + 1;
+       iEnd = std::clamp(static_cast<int>(pOffset + (SCREEN_WIDTH / 2 / HLINE) + 2),
+                      0, static_cast<int>(world.data.size()));
 
     // draw the dirt
        waitToSwap = true;
@@ -1010,7 +1016,7 @@ void WorldSystem::render(void)
                // the starting pixel of the world
                float s = -(static_cast<float>(SCREEN_WIDTH)/2.0f);
                // the ending pixel of the world
-               float e =  (static_cast<float>(SCREEN_WIDTH)/2.0f);
+               float e = (static_cast<float>(SCREEN_WIDTH)/2.0f);
 
                if (offset.x + world.startX > s) {
 
index 1e193fb16d1699e357deba242f3876d6a1117149..d98e8c65142e703a6d49cc21681b8775245efa6c 100644 (file)
@@ -3,7 +3,7 @@
 
 <World>
     <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
-    <generation width="1600"/>
+    <generation width="320"/>
     <time>6000</time>
     <link right="!town2.xml"/>
     <spawnx>-300</spawnx>
@@ -17,7 +17,7 @@
 <Dialog name="Bob">
     <text id="0" nextid="1" pause="true">
         <give id="Dank MayMay" count="10"/>
-        <content> 
+        <content>
                        Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
                </content>
     </text>
index 8993a5c8097868bccb077fc69fc0d5f1b4ac9fa6..b638ae5d731fe2e1871a240b12eefcb8e2b83e00 100644 (file)
@@ -3,7 +3,7 @@
 
 <IndoorWorld>
     <style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
-    <!--<house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>-->
+    <house width="640" texture="assets/style/classic/bg/insideWoodHouse.png"/>
     <generation width="1600"/>
     <time>6000</time>
     <!--<link outside="town.xml"/>-->