]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world bg, other fixes
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 11 Feb 2017 16:24:52 +0000 (11:24 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 11 Feb 2017 16:24:52 +0000 (11:24 -0500)
20 files changed:
assets/style/classic/bg/bg.png
config/controls.dat
freetype6.dll [deleted file]
glew32.dll [deleted file]
include/common.hpp
include/error.hpp
include/texture.hpp
include/vector2.hpp
src/brice.cpp
src/common.cpp
src/components.cpp
src/inventory.cpp
src/particle.cpp
src/quest.cpp
src/render.cpp
src/texture.cpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp
xml/!town.xml

index 2dbc3f96fb3fbcc60b52dfe943ea5b739c07ed47..d3ada5dffda8808508ed939ad413a3714570d2f3 100644 (file)
Binary files a/assets/style/classic/bg/bg.png and b/assets/style/classic/bg/bg.png differ
index 679c014997ea62f66b389359dde88a31cf906777..b5a4720a12ab7353802b82655f7af7f98565776d 100644 (file)
@@ -3,4 +3,4 @@
 100
 1073742049
 1073742048
-101
+100
diff --git a/freetype6.dll b/freetype6.dll
deleted file mode 100644 (file)
index e35edc6..0000000
Binary files a/freetype6.dll and /dev/null differ
diff --git a/glew32.dll b/glew32.dll
deleted file mode 100644 (file)
index c7e3cc2..0000000
Binary files a/glew32.dll and /dev/null differ
index b9be83175f82a0927803a03fc994eb4bf01450fb..9ecd912e6d18783af6e6cb0813996b373e784d10 100644 (file)
@@ -5,6 +5,9 @@
 #ifndef COMMON_HPP_
 #define COMMON_HPP_
 
+#include <algorithm>
+#include <cctype>
+
 // windows stuff
 #ifdef __WIN32__
 using uint = unsigned int;
index ef61c91165e6b1797daf46f60ab38162b2c14a84..c4358894f6a9e3a0405f7c3c486bab6ef31fe520 100644 (file)
@@ -4,9 +4,12 @@
 #include <string>
 #include <iostream>
 
-inline void UserError(const std::string& why)
+#define UserError(w) _UserError(__FILE__, __LINE__, w)
+#define UserAssert(c, e) if (!(c)) { UserError(e); }
+
+inline void _UserError(const char* file, int line, const std::string& why)
 {
-       std::cout << "User error: " << why << "!\n";
+       std::cout << file << ':' << line << ": error: " << why << "!\n";
        abort();
 }
 
index fb4e588a18486b1537b2a4ee7d1128cfa7dea38b..25f73a5d3810318884cc3277c463b6d41ef047cd 100644 (file)
@@ -41,9 +41,12 @@ public:
         * @param file the path to the desired texture
         * @param t the GLuint for the texture, if known
         * @param v the size of the texture, if known
+        * @param hline if true, divides texture dim. by HLINE
         */
        Texture(const std::string& file = "", const GLuint& t = 0xFFFFF, const vec2& v = vec2(0, 0));
 
+       Texture(const std::string& file, bool hline);
+
        /**
         * Gets the name (path) of the loaded texture.
         * @return the texture's name
index d335a4bcdb8aa31c32436ea90caf9c955e4bcd47..c1148da53f872338404d3b7d6e31f7c971d24304 100644 (file)
@@ -66,6 +66,11 @@ struct vector2 {
                return vector2<T>(x / n, y / n);
        }
 
+       vector2<T> operator/=(const T& n) {
+               x /= n, y /= n;
+               return *this;
+       }
+
        // compare
        bool operator==(const vector2<T>& v) const {
                return (x == v.x) && (y == v.y);
index e1a5b3ed6336a15c6fffc3ca7393fb181f4428f2..638c02f58355d5ec4fa42c4b15f936a4d838fe04 100644 (file)
@@ -49,8 +49,7 @@ namespace game {
                std::ofstream out ("brice.dat", std::ios::out | std::ios::binary);
                std::string data = std::to_string(brice.size()) + '\n';
 
-               if (!out.is_open())
-                       UserError("Cannot open brice data file");
+               UserAssert(out.is_open(), "Cannot open brice data file");
 
                for (const auto& i : brice) {
                        data.append(i.first  + '\n');
index 8c63800a94c908284fd05b6bbfd5a006d31ca527..f2e7a2b2d960d0a83ac2b4b8cefdba7cb82b3090 100644 (file)
@@ -61,8 +61,7 @@ int getdir(std::string dir, std::list<std::string>& files)
 {
 #ifndef __WIN32__
        auto dp = opendir(dir.c_str());
-       if (dp == nullptr)
-               UserError("Couldn\'t open folder: " + dir);
+       UserAssert(dp != nullptr, "Couldn\'t open folder: " + dir);
 
        auto dirp = readdir(dp);
        while (dirp != nullptr) {
@@ -74,8 +73,7 @@ int getdir(std::string dir, std::list<std::string>& files)
 #else
        WIN32_FIND_DATA fileData;
        auto dirh = FindFirstFile((dir + "/*").c_str(), &fileData);
-       if (dirh == INVALID_HANDLE_VALUE)
-               UserError("Couldn\'t open folder: " + dir);
+       UserAssert(dirh != INVALID_HANDLE_VALUE, "Couldn\'t open folder: " + dir);
 
        do {
                auto fileName = fileData.cFileName;
@@ -99,8 +97,7 @@ std::string readFile(const std::string& path)
        std::ifstream in (path, std::ios::in);
        std::string buffer;
 
-       if (!in.is_open())
-               UserError("Error reading file " + path);
+       UserAssert(in.is_open(), "Error reading file " + path);
 
        in.seekg(0, in.end);
        buffer.resize(in.tellg());
@@ -117,8 +114,7 @@ std::vector<std::string> readFileA(const std::string& path)
        std::vector<std::string> lines;
        std::string line;
 
-       if (!in.is_open())
-               UserError("Error reading file " + path);
+       UserAssert(in.is_open(), "Error reading file " + path);
 
        while(std::getline(in, line))
                lines.push_back(line);
@@ -127,8 +123,3 @@ std::vector<std::string> readFileA(const std::string& path)
        return lines;
 }
 
-void UserError(std::string reason)
-{
-    std::cout << "User error: " << reason << "!\n";
-    abort();
-}
index 7506d40e88f8ac45c7228046c87e77575667ace4..cbec9fc63b81ae95ef682bfd4c87db6e586bcc59 100644 (file)
@@ -88,19 +88,24 @@ Texture RenderSystem::loadTexture(const std::string& file)
        loadTexResult = Texture();
        while (loadTexResult.isEmpty())
                std::this_thread::sleep_for(1ms);
-       return loadTexResult;
+       auto t = loadTexResult;
+       loadTexResult = Texture();
+       return t;
 }
 
 void RenderSystem::render(void)
 {
        if (!loadTexString.empty()) {
-               loadTexResult = Texture(loadTexString);
+               loadTexResult = Texture(loadTexString, true);
                loadTexString.clear();
        }
        
        Render::worldShader.use();
        Render::worldShader.enable();
 
+       if (!loadTexResult.isEmpty())
+               return;
+
        game::entities.lock();
        game::entities.each<Visible, Sprite, Position>([](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
                // Verticies and shit
index f1332f2a93ab1bafe1bcc896d0f24a1946cb92f5..bf6b6bbef36bd52570362f730ceeebc2549a5956 100644 (file)
@@ -39,8 +39,7 @@ void InventorySystem::loadItems(void) {
        doc.LoadFile(itemsPath);
 
        auto item = doc.FirstChildElement("item");
-       if (item == nullptr)
-               UserError("No items found");
+       UserAssert(item != nullptr, "No items found");
 
        do {
                itemList.emplace(item->StrAttribute("name"), item);
index 006bc45d1836cb259c6add71f75bd8346fe208c2..52d0b23631a94fe325bf0ab55846c49dacfd35c5 100644 (file)
@@ -1,9 +1,12 @@
 #include <particle.hpp>
 
 #include <engine.hpp>
+#include <error.hpp>
 #include <render.hpp>
 #include <world.hpp>
 
+#include <mutex>
+
 ParticleSystem::ParticleSystem(unsigned int max)
        : maximum(max)
 {
@@ -27,17 +30,21 @@ void ParticleSystem::addMultiple(const int& count, const ParticleType& type, std
 
 void ParticleSystem::render(void)
 {
-       static GLuint particleVBO = 9999;
+       static GLuint particleVBO;
        static const Texture palette ("assets/colorIndex.png");
        // six vertices, 3d coord + 2d tex coord = 5
        constexpr auto entrySize = (6 * 5) * sizeof(GLfloat);
 
-       if (particleVBO == 9999) {
+       static std::once_flag init;
+       std::call_once(init, [this](GLuint& vbo) {
                // generate VBO
-               glGenBuffers(1, &particleVBO);
-               glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
+               glGenBuffers(1, &vbo);
+               glBindBuffer(GL_ARRAY_BUFFER, vbo);
                glBufferData(GL_ARRAY_BUFFER, maximum * entrySize, nullptr,     GL_DYNAMIC_DRAW);
-       }
+       }, particleVBO);
+
+       if (parts.empty())
+               return;
 
        // clear dead particles
        parts.erase(std::remove_if(parts.begin(), parts.end(),
@@ -46,6 +53,9 @@ void ParticleSystem::render(void)
        // copy data into VBO
        glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
 
+       auto vbobuf = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
+       UserAssert(vbobuf != nullptr, "Failed to map the particle VBO");
+
        for (unsigned int i = 0, offset = 0; i < parts.size(); i++, offset += entrySize) {
                const auto& p = parts[i];
                static const auto& hl = game::HLINE;
@@ -58,9 +68,12 @@ void ParticleSystem::render(void)
                        p.location.x,      p.location.y,      -1, p.color.x, p.color.y
                };
 
-               glBufferSubData(GL_ARRAY_BUFFER, offset, entrySize, coords);
+               //glBufferSubData(GL_ARRAY_BUFFER, offset, entrySize, coords);
+               std::memcpy((void *)((unsigned long)vbobuf + offset), coords, entrySize);
        }
 
+       UserAssert(glUnmapBuffer(GL_ARRAY_BUFFER) == GL_TRUE, "Failed to unmap the particle VBO");
+
        // begin actual rendering
        Render::worldShader.use();
        Render::worldShader.enable();
index 920ac845f2322ab365e2ec6d357f89159bcc101c..8fd786edf8b4032780c90624d8d0d42c1528d9a5 100644 (file)
@@ -1,21 +1,7 @@
 #include <quest.hpp>
 
 #include <algorithm>
-
-std::vector<std::string> StringTokenizer(const std::string& str, char delim);
-
-std::vector<std::string> split(std::string s, const std::string& delim)
-{
-       std::vector<std::string> res;
-
-       while (!s.empty()) {
-               auto pos = s.find(delim);
-               res.emplace_back(s.substr(0, pos));
-               s = s.substr(pos + 1);
-       }
-
-       return res;
-}
+#include <sstream>
 
 void QuestSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
 {
@@ -26,10 +12,7 @@ void QuestSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
 
 int QuestSystem::assign(std::string title, std::string desc, std::string req)
 {
-       const auto& reqs = StringTokenizer(req, ',');
-       for (const auto& s : reqs)
-               std::cout << s << '\n';
-
+       (void)req;
        current.emplace_back(title, desc);
        return 0;
 }
index 303ff1c40fc2bec7c6edc245e3ad0556aa83c646..84f3e7e0ca4b269aa99183779866518778b4bc01 100644 (file)
@@ -81,9 +81,8 @@ void init(void)
 #endif
 
        auto glewError = glewInit();
-       if (glewError != GLEW_OK)
-               UserError(std::string("GLEW was not able to initialize! Error: ")
-                       + reinterpret_cast<const char *>(glewGetErrorString(glewError)));
+       UserAssert(glewError == GLEW_OK, 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(1);                                 // v-sync
index 5723bd8f9d59dad29b5018548c0ee0d70d7913fb..44e48a0f1cae9bed9fcee4acf323266d7ffae1bd 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <SDL2/SDL_image.h>
 
+#include <config.hpp>
 #include <debug.hpp>
 #include <error.hpp>
 
@@ -37,6 +38,13 @@ Texture::Texture(const std::string& file, const GLuint& t, const vec2& v)
                loadTexture(file, *this);
 }
 
+Texture::Texture(const std::string& file, bool hline)
+{
+       loadTexture(file, *this);
+       if (hline)
+               dim /= game::HLINE;
+}
+
 const std::string& Texture::getName(void) const
 {
        return name;
@@ -80,8 +88,7 @@ void loadTexture(const std::string& file, Texture& texture)
 
        if (preloaded == std::end(loadedTextures)) {
                auto image = IMG_Load(file.c_str());
-               if (image == nullptr)
-                       UserError("File not found: " + file);
+               UserAssert(image != nullptr, "File not found: " + file);
 
 #ifdef DEBUG
                DEBUG_printf("Loaded image file: %s\n", file.c_str());
index b14ea2cbd9284ce683c4f07a9cba4879812e552c..b9c2119d78ad689583da66c2ef1c048456b9a078 100644 (file)
@@ -104,8 +104,7 @@ void loadFontSize(int size, std::vector<FT_Info> &data)
 
        for (char i = 33; i < 126; i++) {
                // load the character from the font family file
-               if (FT_Load_Char(ftf, i, FT_LOAD_RENDER))
-                       UserError("Error! Unsupported character " + i);
+               UserAssert(!FT_Load_Char(ftf, i, FT_LOAD_RENDER), "Error! Unsupported character " + i);
 
                // transfer the character's bitmap (?) to a texture for rendering
                glBindTexture(GL_TEXTURE_2D, data[i - 33].tex);
@@ -191,8 +190,7 @@ namespace ui {
        */
 
        void initFonts(void) {
-               if (FT_Init_FreeType(&ftl))
-                       UserError("Couldn't initialize freetype.");
+               UserAssert(!FT_Init_FreeType(&ftl), "Couldn't initialize freetype.");
 
 #ifdef DEBUG
                DEBUG_printf("Initialized FreeType2.\n", nullptr);
@@ -221,8 +219,8 @@ namespace ui {
        */
 
        void setFontFace(const char *ttf) {
-               if (FT_New_Face(ftl, ttf, 0, &ftf))
-                       UserError("Error! Couldn't open " + (std::string)ttf + ".");
+               UserAssert(!FT_New_Face(ftl, ttf, 0, &ftf), "Error! Couldn't open " +
+                       std::string(ttf) + ".");
 
 #ifdef DEBUG
                DEBUG_printf("Using font %s\n",ttf);
index 6ef06c152f8aaa02ff104e0375fe1bbaf2fabaa7..e5f5f9db6ff6e9856380b548269cf5570bb7fccc 100644 (file)
@@ -20,8 +20,8 @@ void Menu::gotoParent(void)
 {
        if (parent == nullptr)
                game::config::update();
-       else
-               currentMenu = parent;
+       
+       currentMenu = parent;
 }
 
 std::string& deleteWord(std::string& s)
index 8db9344972fcbe5a71e741c32f9d00c41205bcd3..d38708de84a15555a4d616ef59dfbfcb1e938e15 100644 (file)
@@ -199,14 +199,15 @@ void WorldSystem::load(const std::string& file)
        auto xmlRaw = readFile(xmlPath);
 
        // let tinyxml parse the file
-       if (xmlDoc.Parse(xmlRaw.data()) != XML_NO_ERROR)
-               UserError("XML Error: Failed to parse file (not your fault though..?)");
+       UserAssert(xmlDoc.Parse(xmlRaw.data()) == XML_NO_ERROR,
+               "XML Error: Failed to parse file (not your fault though..?)");
 
        // include headers
        std::vector<std::string> toAdd;
        auto ixml = xmlDoc.FirstChildElement("include");
        while (ixml != nullptr) {
                auto file = ixml->Attribute("file");
+               UserAssert(file != nullptr, "XML Error: <include> tag file not given");
 
                if (file != nullptr) {
                        DEBUG_printf("Including file: %s\n", file);
@@ -222,8 +223,8 @@ void WorldSystem::load(const std::string& file)
        for (const auto& f : toAdd)
                xmlRaw.append(readFile(f)); 
 
-       if (xmlDoc.Parse(xmlRaw.data()) != XML_NO_ERROR)
-               UserError("XML Error:");
+       UserAssert(xmlDoc.Parse(xmlRaw.data()) == XML_NO_ERROR,
+               "XML Error: failed to append includes");
 
        // look for an opening world tag
        auto wxml = xmlDoc.FirstChildElement("World");
@@ -232,12 +233,9 @@ void WorldSystem::load(const std::string& file)
                world.indoor = false;
        } else {
                wxml = xmlDoc.FirstChildElement("IndoorWorld");
-               if (wxml != nullptr) {
-                       wxml = wxml->FirstChildElement();
-                       world.indoor = true;
-               } else {
-                       UserError("XML Error: Cannot find a <World> or <IndoorWorld> tag in " + xmlPath);
-               }
+               UserAssert(wxml != nullptr, "XML Error: Cannot find a <World> or <IndoorWorld> tag in " + xmlPath);
+               wxml = wxml->FirstChildElement();
+               world.indoor = true;
        }
 
        world.toLeft = world.toRight = "";
@@ -282,10 +280,10 @@ void WorldSystem::load(const std::string& file)
                                UserError("<house> can only be used inside <IndoorWorld>");
 
                        //world.indoorWidth = wxml->FloatAttribute("width");
-                       (void)render;//world.indoorTex = render.loadTexture(wxml->StrAttribute("texture")); // TODO winbloze lol
-                       //auto str = wxml->StrAttribute("texture");
-                       //auto tex = render.loadTexture(str);
-                       //world.indoorTex = tex;
+                       world.indoorTex = render.loadTexture(wxml->StrAttribute("texture")); // TODO winbloze lol
+                       auto str = wxml->StrAttribute("texture");
+                       auto tex = render.loadTexture(str);
+                       world.indoorTex = tex;
                }
 
                // weather tag
@@ -728,10 +726,11 @@ void WorldSystem::render(void)
                shadeAmbient = 1;
 
        // TODO scroll backdrop
-       GLfloat bgOff = game::time::getTickCount() / static_cast<float>(DAY_CYCLE * 2);
+       //GLfloat bgOff = game::time::getTickCount() / static_cast<float>(DAY_CYCLE * 2);
+       GLfloat bgOff = -0.5f * cos(PI / DAY_CYCLE * game::time::getTickCount()) + 0.5f;
 
        GLfloat topS = .125f + bgOff;
-       GLfloat bottomS = 0.0f + bgOff;
+       GLfloat bottomS = bgOff;
 
        if (topS < 0.0f)
                topS += 1.0f;
index eb5392175f1109b1f60bac4cd7ee908fdfca712a..9ab4c1c47c67d825a72ed61a2fb53c9e2f74a956 100644 (file)
@@ -4,8 +4,7 @@
 <World>
     <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
     <generation width="320"/>
-       <weather>Snowy</weather>
-    <time>6000</time>
+       <weather>Sunny</weather>
     <link right="!town2.xml"/>
     <spawnx>-300</spawnx>
     <npc name="Sanc" hasDialog="true"/>