diff options
-rw-r--r-- | assets/style/classic/bg/bg.png | bin | 1072758 -> 863 bytes | |||
-rw-r--r-- | config/controls.dat | 2 | ||||
-rw-r--r-- | freetype6.dll | bin | 522240 -> 0 bytes | |||
-rw-r--r-- | glew32.dll | bin | 568892 -> 0 bytes | |||
-rw-r--r-- | include/common.hpp | 3 | ||||
-rw-r--r-- | include/error.hpp | 7 | ||||
-rw-r--r-- | include/texture.hpp | 3 | ||||
-rw-r--r-- | include/vector2.hpp | 5 | ||||
-rw-r--r-- | src/brice.cpp | 3 | ||||
-rw-r--r-- | src/common.cpp | 17 | ||||
-rw-r--r-- | src/components.cpp | 9 | ||||
-rw-r--r-- | src/inventory.cpp | 3 | ||||
-rw-r--r-- | src/particle.cpp | 25 | ||||
-rw-r--r-- | src/quest.cpp | 21 | ||||
-rw-r--r-- | src/render.cpp | 5 | ||||
-rw-r--r-- | src/texture.cpp | 11 | ||||
-rw-r--r-- | src/ui.cpp | 10 | ||||
-rw-r--r-- | src/ui_menu.cpp | 4 | ||||
-rw-r--r-- | src/world.cpp | 31 | ||||
-rw-r--r-- | xml/!town.xml | 3 |
20 files changed, 84 insertions, 78 deletions
diff --git a/assets/style/classic/bg/bg.png b/assets/style/classic/bg/bg.png Binary files differindex 2dbc3f9..d3ada5d 100644 --- a/assets/style/classic/bg/bg.png +++ b/assets/style/classic/bg/bg.png diff --git a/config/controls.dat b/config/controls.dat index 679c014..b5a4720 100644 --- a/config/controls.dat +++ b/config/controls.dat @@ -3,4 +3,4 @@ 100 1073742049 1073742048 -101 +100 diff --git a/freetype6.dll b/freetype6.dll Binary files differdeleted file mode 100644 index e35edc6..0000000 --- a/freetype6.dll +++ /dev/null diff --git a/glew32.dll b/glew32.dll Binary files differdeleted file mode 100644 index c7e3cc2..0000000 --- a/glew32.dll +++ /dev/null diff --git a/include/common.hpp b/include/common.hpp index b9be831..9ecd912 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -5,6 +5,9 @@ #ifndef COMMON_HPP_ #define COMMON_HPP_ +#include <algorithm> +#include <cctype> + // windows stuff #ifdef __WIN32__ using uint = unsigned int; diff --git a/include/error.hpp b/include/error.hpp index ef61c91..c435889 100644 --- a/include/error.hpp +++ b/include/error.hpp @@ -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(); } diff --git a/include/texture.hpp b/include/texture.hpp index fb4e588..25f73a5 100644 --- a/include/texture.hpp +++ b/include/texture.hpp @@ -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 diff --git a/include/vector2.hpp b/include/vector2.hpp index d335a4b..c1148da 100644 --- a/include/vector2.hpp +++ b/include/vector2.hpp @@ -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); diff --git a/src/brice.cpp b/src/brice.cpp index e1a5b3e..638c02f 100644 --- a/src/brice.cpp +++ b/src/brice.cpp @@ -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'); diff --git a/src/common.cpp b/src/common.cpp index 8c63800..f2e7a2b 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -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(); -} diff --git a/src/components.cpp b/src/components.cpp index 7506d40..cbec9fc 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -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 diff --git a/src/inventory.cpp b/src/inventory.cpp index f1332f2..bf6b6bb 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -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); diff --git a/src/particle.cpp b/src/particle.cpp index 006bc45..52d0b23 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -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(); diff --git a/src/quest.cpp b/src/quest.cpp index 920ac84..8fd786e 100644 --- a/src/quest.cpp +++ b/src/quest.cpp @@ -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; } diff --git a/src/render.cpp b/src/render.cpp index 303ff1c..84f3e7e 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -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 diff --git a/src/texture.cpp b/src/texture.cpp index 5723bd8..44e48a0 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -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()); @@ -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); diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp index 6ef06c1..e5f5f9d 100644 --- a/src/ui_menu.cpp +++ b/src/ui_menu.cpp @@ -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) diff --git a/src/world.cpp b/src/world.cpp index 8db9344..d38708d 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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; diff --git a/xml/!town.xml b/xml/!town.xml index eb53921..9ab4c1c 100644 --- a/xml/!town.xml +++ b/xml/!town.xml @@ -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"/> |