]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fade fix, other stuff too
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 22 Dec 2016 15:49:33 +0000 (10:49 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 22 Dec 2016 15:49:33 +0000 (10:49 -0500)
include/common.hpp
include/config.hpp
include/shader_utils.hpp
include/world.hpp
main.cpp
src/brice.cpp
src/common.cpp
src/ui.cpp
src/world.cpp

index 7028296103cad1096e642c17d81a47ef63038fb7..56928b57fde4371ad6fa28990e0ad1a7de9b1e57 100644 (file)
 // game library includes
 #include <config.hpp>
 
-
-
 // windows stuff
 #ifdef __WIN32__
-typedef unsigned int uint;
 #undef near
 #endif
 
@@ -192,8 +189,6 @@ public:
        }
 };
 
-extern GLuint colorIndex;
-
 /**
  * The amount of game ticks that should occur each second.
  */
@@ -259,17 +254,6 @@ extern vec2 offset;
  */
 void DEBUG_prints(const char* file, int line, const char *s,...);
 
-// TODO make sure we don't use these. Then burn them.
-/**
- * Sets color using glColor3ub(), but handles potential overflow.
- */
-void safeSetColor(int r,int g,int b);
-
-/**
- * Sets color using glColor4ub(), but handles potential overflow.
- */
-void safeSetColorA(int r,int g,int b,int a);
-
 unsigned int millis(void);
 
 // reads the names of files in a directory into the given string vector
@@ -279,7 +263,6 @@ int getdir(std::string dir, std::vector<std::string> &files);
 void strVectorSortAlpha(std::vector<std::string> *v);
 
 // reads the given file into a buffer and returns a pointer to the buffer
-const char *readFile(const char *path);
 std::string readFile(const std::string& path);
 std::vector<std::string> readFileA(const std::string& path);
 
index 908c3766d86b9791d1063f0a5445d87fbdf76f17..e17df24ad650af2a337036c48f8f71729a02725f 100644 (file)
@@ -29,7 +29,7 @@ namespace game {
        /**
         * The window is fullscreen if this is true.
         */
-       extern bool         FULLSCREEN;
+       extern bool FULLSCREEN;
 
        namespace config {
                /**
index 08ca7b3bda33f2c57a6f20481968b6ce095abee5..06ac318314a6b9bed0b46d5f260e53fde6569393 100644 (file)
 
 #include <SDL2/SDL.h>
 
-extern char* file_read(const char* filename);
-extern void print_log(GLuint object);
-extern GLuint create_shader(const char* filename, GLenum type);
-extern GLuint create_program(const char* vertexfile, const char *fragmentfile);
-extern GLint get_attrib(GLuint program, const char *name);
-extern GLint get_uniform(GLuint program, const char *name);
-extern void print_opengl_info();
+char* file_read(const char* filename);
+void print_log(GLuint object);
+GLuint create_shader(const char* filename, GLenum type);
+GLuint create_program(const char* vertexfile, const char *fragmentfile);
+GLint get_attrib(GLuint program, const char *name);
+GLint get_uniform(GLuint program, const char *name);
+void print_opengl_info();
 
 #endif
index 8b24987066265eb80bc8216d1a8986296c47537e..8864d305b9c65723028dedb6768315d388f2d838 100644 (file)
@@ -59,13 +59,6 @@ typedef struct {
     unsigned char groundColor;    /**< a value that affects the ground's color */
 } WorldData;
 
-/**
- * Alters how bright world elements are drawn.
- * This value is based off of the current time of day (tick count), set in
- * main.cpp.
- */
-extern int worldShade;
-
 /**
  * Defines how many game ticks it takes to go from day to night or vice versa.
  * Technically a half day cycle...
index 857970727d73110b68c19d71cbff102124fd60ec..7fc165877428eb811bdc98ca0656727b88d2afe1 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -189,6 +189,7 @@ int main(int argc, char *argv[])
 
                                if (game::time::tickHasPassed()) {
                                        // calculate the world shading value
+                                       extern int worldShade; // TODO kill
                                        worldShade = 50 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
 
                                        // update fades
index 5e7237fbff93f1a3f09d34994424422d771321f9..53b1431184f312be87d029f2ffdf3b7e9357e3e2 100644 (file)
@@ -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) {
index 01a7db87f4f632f6edc37a09fccf861cf19a3d6e..706bc3c3ad5a36895a6784b8ceeaab8f2dda86f4 100644 (file)
@@ -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());
 
index a154d7eac964175d7287e18481d3f19b2d4ae692..9f0e0148ab477e9672722e787b02dd82fa0e2f67 100644 (file)
@@ -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) {
index c458ab06a6cd74e48626438e4bf0a604afae8ff9..d0727e2bbcf8a49005b5abfa285d630f988c7929 100644 (file)
@@ -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) {