diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-12-22 10:49:33 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-12-22 10:49:33 -0500 |
commit | 6dd6d03bb1af3c1c482a67355446998eccc3288c (patch) | |
tree | b1ed2891b510611e5e89532feb0a89cb48a67c78 /src | |
parent | ae9ceadaa184f5e9775135ae264c8bbffd4efa9d (diff) |
fade fix, other stuff too
Diffstat (limited to 'src')
-rw-r--r-- | src/brice.cpp | 6 | ||||
-rw-r--r-- | src/common.cpp | 39 | ||||
-rw-r--r-- | src/ui.cpp | 13 | ||||
-rw-r--r-- | src/world.cpp | 16 |
4 files changed, 13 insertions, 61 deletions
diff --git a/src/brice.cpp b/src/brice.cpp index 5e7237f..53b1431 100644 --- a/src/brice.cpp +++ b/src/brice.cpp @@ -58,9 +58,9 @@ namespace game { } void briceLoad(void) { - const char *data = readFile("brice.dat"); + auto data = readFile("brice.dat"); - if (data == nullptr) { + if (data.empty()) { briceClear(); data = readFile("brice.dat"); } @@ -74,8 +74,6 @@ namespace game { brice.emplace(std::make_pair(datas[i], datas[i + 1])); } } - - delete[] data; } void briceUpdate(void) { diff --git a/src/common.cpp b/src/common.cpp index 01a7db8..706bc3c 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -43,22 +43,6 @@ void DEBUG_prints(const char* file, int line, const char *s,...) va_end(args); } -void safeSetColor(int r, int g, int b) -{ - r = static_cast<int>(fmax(fmin(r, 255), 0)); - g = static_cast<int>(fmax(fmin(g, 255), 0)); - b = static_cast<int>(fmax(fmin(b, 255), 0)); - glColor3ub(r, g, b); -} - -void safeSetColorA(int r,int g,int b,int a) { - r = static_cast<int>(fmax(fmin(r, 255), 0)); - g = static_cast<int>(fmax(fmin(g, 255), 0)); - b = static_cast<int>(fmax(fmin(b, 255), 0)); - a = static_cast<int>(fmax(fmin(a, 255), 0)); - glColor4ub(r, g, b, a); -} - int getdir(std::string dir, std::vector<std::string> &files) { #ifndef __WIN32__ @@ -111,27 +95,6 @@ void strVectorSortAlpha(std::vector<std::string> *v) } while (change); } -const char *readFile(const char *path) -{ - std::ifstream in (path,std::ios::in); - unsigned int size; - GLchar *buf; - - if (!in.is_open()) { -// UserError("Error reading file " + (std::string)path + "!"); - return nullptr; - } - - in.seekg(0,in.end); - buf = new GLchar[(size = in.tellg()) + 1]; - in.seekg(0,in.beg); - in.read(buf,size); - buf[size] = '\0'; - - in.close(); - return buf; -} - std::string readFile(const std::string& path) { std::ifstream in (path, std::ios::in); @@ -141,7 +104,7 @@ std::string readFile(const std::string& path) UserError("Error reading file " + path); in.seekg(0, in.end); - buffer.reserve(in.tellg()); + buffer.resize(in.tellg()); in.seekg(0, in.beg); in.read(&buffer[0], buffer.size()); @@ -1014,8 +1014,8 @@ namespace ui { } void drawFade(void) { - auto SCREEN_WIDTH2 = game::SCREEN_WIDTH / 2; - auto SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2; + static const auto SCREEN_WIDTH2 = game::SCREEN_WIDTH / 2; + static const auto SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2; if (!fadeIntensity) { if (fontSize != 16) @@ -1023,9 +1023,6 @@ namespace ui { return; } - ColorTex fadeTex (fadeWhite ? Color(255, 255, 255, fadeIntensity) : - Color(0, 0, 0, fadeIntensity)); - static const GLfloat tex[] = { 0.0, 0.0, 1.0, 0.0, @@ -1045,8 +1042,8 @@ namespace ui { Render::textShader.use(); Render::textShader.enable(); - - fadeTex.use(); + 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); @@ -1055,8 +1052,6 @@ namespace ui { Render::textShader.unuse(); setFontZ(-8.0); - - fadeTex.destroy(); } void fadeUpdate(void) { diff --git a/src/world.cpp b/src/world.cpp index c458ab0..d0727e2 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -196,9 +196,7 @@ void WorldSystem::load(const std::string& file) // load file data to string auto xmlPath = xmlFolder + file; - auto xmlRawData = readFile(xmlPath.c_str()); - std::string xmlRaw = xmlRawData; - delete[] xmlRawData; + auto xmlRaw = readFile(xmlPath); // let tinyxml parse the file if (xmlDoc.Parse(xmlRaw.data()) != XML_NO_ERROR) @@ -211,9 +209,7 @@ void WorldSystem::load(const std::string& file) if (file != nullptr) { DEBUG_printf("Including file: %s\n", file); - auto include = readFile((xmlFolder + file).c_str()); - xmlRaw.append(include); - delete[] include; + xmlRaw.append(readFile(xmlFolder + file)); } else { UserError("XML Error: <include> tag file not given"); } @@ -936,11 +932,11 @@ void WorldSystem::render(void) GLfloat *dirtp = &dirt[0]; for (int i = iStart; i < iEnd; i++) { - if (world.data[i].groundHeight <= 0) { // TODO holes (andy) + if (world.data[i].groundHeight <= 0) { // TODO holes (andy) TODO TODO TODO world.data[i].groundHeight = GROUND_HEIGHT_MINIMUM - 1; - glColor4ub(0, 0, 0, 255); + //glColor4ub(0, 0, 0, 255); } else { - safeSetColorA(150, 150, 150, 255); + //safeSetColorA(150, 150, 150, 255); } int ty = world.data[i].groundHeight / 64 + world.data[i].groundColor; @@ -978,7 +974,7 @@ void WorldSystem::render(void) if (!world.indoor) { bgTex++; - safeSetColorA(255, 255, 255, 255); + //safeSetColorA(255, 255, 255, 255); TODO TODO TODO static std::vector<GLfloat> grass; if (grass.size() != world.data.size() * 60) { |