From 8259fd61807d046bede0245a2648eac3dfbfcd0c Mon Sep 17 00:00:00 2001 From: dummy Date: Wed, 7 Feb 2018 14:30:53 -0500 Subject: [PATCH] added aixlog for better logging --- src/Makefile | 2 +- src/hexgame.cpp | 64 ++++++++----------------------------------------- src/hexgame.h | 1 - src/renderer.h | 30 ++++++++++------------- 4 files changed, 24 insertions(+), 73 deletions(-) diff --git a/src/Makefile b/src/Makefile index 46e31a4..5be9587 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ CXXFLAGS = -std=c++11 -g -Wall -INCLUDES = +INCLUDES = -I../ext/aixlog/include # libGLEW needs to be >= 2.0.0 to use opengl core context # don't know a good way to require this in make without forcing a specific version LDFLAGS = -lSDL2 -lGLEW -lGL diff --git a/src/hexgame.cpp b/src/hexgame.cpp index 50cad61..2b5f3e1 100644 --- a/src/hexgame.cpp +++ b/src/hexgame.cpp @@ -1,30 +1,6 @@ -/* - * TODO: - * - * - Platform Layer: - * - make a global debug logging function in hexgame.h - * - centralize memory allocation/deallocation - * - custom dynamic arrays in C: - * https://stackoverflow.com/questions/3536153/c-dynamically-growing-array - * - File IO - * - * - Debug UI: - * - font metrics - * - render lines of glyphs to texture - * - simple buttons to select game states - * - * - game states: - * - hex fill, line draw, 'cone' fill, pathfinding, line of sight - * - * - utility functions: - * - SafeRatio(): don't divide by zero - * - SafeTruncate() for various types: check for input size before losing high bits - */ - #include #include -#include #if defined(_WIN32) #include @@ -34,27 +10,14 @@ #include #include #include +#include "aixlog.hpp" #include "hexgame.h" #include "hexlib.h" #include "renderer.h" -using std::string; -using std::stringstream; using std::vector; -// TODO: maybe switch to c-style strings for errors? working with stringstream -// is annoying and too verbose -void -debugLog(string error) -{ -#if defined(_WIN32) && !defined(__MINGW32__) - error.push_back('\n'); - OutputDebugString((LPCSTR) error.c_str()); -#else - std::cout << error << '\n'; -#endif -} // TODO: global variables v2i viewportDims(1280, 720); @@ -497,37 +460,30 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, int main(int argc, char* argv[]) #endif { + // init fancy new logger + AixLog::Log::init(AixLog::Severity::trace, AixLog::Type::normal); + LOG(INFO) << "Application started\n"; + hexInfoArray = new vector; createHexes(hexInfoArray); SDL_Handles handles; if (SDL_Init(SDL_INIT_VIDEO) != 0) { - stringstream ss; - ss << "Error, SDL_Init: " << SDL_GetError(); - debugLog(ss.str()); + LOG(ERROR) << "Error, SDL_Init: " << SDL_GetError() << "\n"; return 1; } if (!initRenderer(handles, viewportDims)) { - stringstream ss; - ss << "Unable to initialize graphics, exiting"; - debugLog(ss.str()); + LOG(ERROR) << "Unable to initialize graphics, exiting\n"; return 1; } createScene(hexInfoArray); -#if 0 - if (InitGooey(viewportDims) == false) - { - stringstream ss; - ss << "Unable to initialize gooey, exiting"; - debugLog(ss.str()); - return 1; - } -#endif - + + // TODO: rewrite gooey + enterLoop(handles); cleanUp(handles); delete hexInfoArray; diff --git a/src/hexgame.h b/src/hexgame.h index 5809eab..2d3100a 100644 --- a/src/hexgame.h +++ b/src/hexgame.h @@ -3,7 +3,6 @@ #define HEXGAME_H #include -#include #include #include diff --git a/src/renderer.h b/src/renderer.h index 9043b0e..808ca97 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -3,8 +3,6 @@ #define RENDERER_H #include -// TODO: remove for better logging -#include // std::cout #include #include @@ -82,16 +80,13 @@ initRenderer(SDL_Handles &handles, v2i vpDims) //glewExperimental = true; // Needed for core profile GLenum err = glewInit(); if (err != GLEW_OK) { - // TODO: better logging - std::cout << "Failed to initilize GLEW" << glewGetErrorString(err) << "\n"; + LOG(ERROR) << "Failed to initilize GLEW" << glewGetErrorString(err) << "\n"; return false; } - // TODO: better logging - // see what kind of context we got - std::cout << "opengl vendor: " << glGetString(GL_VENDOR) << "\n"; - std::cout << "opengl renderer: " << glGetString(GL_RENDERER) << "\n"; - std::cout << "opengl version: " << glGetString(GL_VERSION) << "\n"; + LOG(INFO) << "opengl vendor: " << glGetString(GL_VENDOR) << "\n"; + LOG(INFO)<< "opengl renderer: " << glGetString(GL_RENDERER) << "\n"; + LOG(INFO) << "opengl version: " << glGetString(GL_VERSION) << "\n"; // TODO: blending, these options break the http://www.opengl-tutorial.org tutorials atm // Setup render state: alpha-blending enabled, polygon fill @@ -385,8 +380,8 @@ void openglDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) { - // TODO: update error logging - std::cout << "openGLDebugCallback: " + LOG((type == GL_DEBUG_TYPE_ERROR) ? ERROR : DEBUG) + << "openGLDebugCallback: " << (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "") << ", type: " << type << ", severity: " << severity @@ -399,7 +394,9 @@ renderFrame(std::vector *hexes) glClearColor(g_clear_col.R, g_clear_col.G, g_clear_col.B, g_clear_col.A); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); -#if 1 + + // filled hexes + glUseProgram(g_hex_programID); // Send our transformation to the currently bound shader, in the "g_MVP" uniform glUniformMatrix4fv(g_matrixID, 1, GL_FALSE, &g_MVP[0][0]); @@ -419,9 +416,10 @@ renderFrame(std::vector *hexes) glDrawArrays(GL_TRIANGLES, 0, g_vertex_buffer_triangle_count); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); -#endif - -#if 1 + + + // hex lines + glUseProgram(g_line_programID); // Send our transformation to the currently bound shader, in the "g_MVP" uniform glUniformMatrix4fv(g_matrixID, 1, GL_FALSE, &g_MVP[0][0]); @@ -431,9 +429,7 @@ renderFrame(std::vector *hexes) glEnableVertexAttribArray(attrib_index); glBindBuffer(GL_ARRAY_BUFFER, g_hex_line_vertexbuffer); glVertexAttribPointer(attrib_index, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); - glDrawArrays(GL_LINES, 0, g_line_buf_size / 3); -#endif } void