diff --git a/CMakeLists.txt b/CMakeLists.txt index 37cebf9..a99f184 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,36 @@ if (NO_EDITOR) set(BUILD_NO_EDITOR 1) endif () +# Log level option +set(LOG_LEVEL 0) +option(LOG_LEVEL_ERROR "Log errors only" OFF) +option(LOG_LEVEL_INFO "Log errors, warnings and info" ON) +option(LOG_LEVEL_DEBUG "Log Everything (except internal graphics msgs)" OFF) +option(LOG_LEVEL_GINTERNAL_ERR "Log internal graphics error messages" OFF) +option(LOG_LEVEL_GINTERNAL_DEBUG "Log all internal graphics messages" OFF) + +if (LOG_LEVEL_ERROR) + set(LOG_LEVEL 1) +endif () + +if (LOG_LEVEL_INFO) + set(LOG_LEVEL 2) +endif () + +if (LOG_LEVEL_DEBUG) + set(LOG_LEVEL 3) +endif () + +if (LOG_LEVEL_GINTERNAL_ERR) + set(LOG_LEVEL 4) +endif () + +if (LOG_LEVEL_GINTERNAL_DEBUG) + set(LOG_LEVEL 5) +endif () + +message (STATUS "Setting log level to " ${LOG_LEVEL}) + configure_file(LunariumConfig.h.in LunariumConfig.h) # Source Files diff --git a/LunariumConfig.h.in b/LunariumConfig.h.in index 0a1a00c..c5c36ef 100644 --- a/LunariumConfig.h.in +++ b/LunariumConfig.h.in @@ -6,4 +6,6 @@ #define OPENGL_MAJOR_VERSION @OpenGL_MAJOR_VERSION@ #define OPENGL_MINOR_VERSION @OpenGL_MINOR_VERSION@ -#define BUILD_NO_EDITOR @BUILD_NO_EDITOR@ \ No newline at end of file +#define BUILD_NO_EDITOR @BUILD_NO_EDITOR@ + +#define LOG_LEVEL @LOG_LEVEL@ \ No newline at end of file diff --git a/scripts/config.bat b/scripts/config.bat index 0e8c621..6ac4ab2 100644 --- a/scripts/config.bat +++ b/scripts/config.bat @@ -3,6 +3,8 @@ REM This script expects to be run from the parent directory REM ex. scripts/cmconfig.bat @echo off +REM Check for log level options + IF "%~1" == "noedit" ( echo "no editor build" cmake -Wno-dev -DNO_EDITOR=ON -DGLFW_BUILD_DOCS=OFF -DBOX2D_BUILD_TESTBED=OFF -B build/ -S . -G "Visual Studio 17 2022" -A x64 diff --git a/src/core/common_defs.h b/src/core/common_defs.h new file mode 100644 index 0000000..e3c7944 --- /dev/null +++ b/src/core/common_defs.h @@ -0,0 +1,42 @@ +/****************************************************************************** +* File - common_defs.h +* Author - Joey Pollack +* Date - 2022/05/11 (y/m/d) +* Mod Date - 2022/05/11 (y/m/d) +* Description - Common definitions for the engine +******************************************************************************/ + +#ifndef LUNARIUM_COMMON_DEFS_H_ +#define LUNARIUM_COMMON_DEFS_H_ + +// intrinsic type short-hands +// The idea for this was taken from the KOHI engine +// https://github.com/travisvroman/kohi +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; + +typedef char i8; +typedef short i16; +typedef int i32; +typedef long long i64; + +typedef float f32; +typedef double f64; + +// verify the type sizes +static_assert(sizeof(u8) == 1, "Expected u8 to be 1 byte"); +static_assert(sizeof(u16) == 2, "Expected u16 to be 2 bytes"); +static_assert(sizeof(u32) == 4, "Expected u32 to be 4 bytes"); +static_assert(sizeof(u64) == 8, "Expected u64 to be 8 bytes"); + +static_assert(sizeof(i8) == 1, "Expected i8 to be 1 byte"); +static_assert(sizeof(i16) == 2, "Expected i16 to be 2 bytes"); +static_assert(sizeof(i32) == 4, "Expected i32 to be 4 bytes"); +static_assert(sizeof(i64) == 8, "Expected i64 to be 8 bytes"); + +static_assert(sizeof(f32) == 4, "Expected f32 to be 4 bytes"); +static_assert(sizeof(f64) == 8, "Expected f64 to be 8 bytes"); + +#endif // LUNARIUM_COMMON_DEFS_H_ \ No newline at end of file diff --git a/src/core/core.cpp b/src/core/core.cpp index f1ebc07..fbee2bc 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -56,7 +56,7 @@ namespace lunarium if (!mpInstance) return; - Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!"); + Logger::Info(LogCategory::CORE, "Lunarium is shutting down!"); int x, y; mpInstance->MainWindow().GetPosition(&x, &y); @@ -123,14 +123,18 @@ namespace lunarium mErrorLogFile.open("Lunarium_Errors.log", std::ios_base::app); + + mGraphicsLogFile.open("Lunarium_Graphics.log", std::ios_base::app); mErrorLogFile << "\n\n"; if (mMasterLogFile.is_open()) Logger::GetInstance()->AddListener(new FileListener(mMasterLogFile)); - if (mErrorLogFile.is_open()) Logger::GetInstance()->AddListener(new FileListener(mErrorLogFile, LogLevel::ERROR | LogLevel::FATAL_ERROR)); + + if (mGraphicsLogFile.is_open()) + Logger::GetInstance()->AddListener(new FileListener(mGraphicsLogFile, LogLevel::GRAPHICS_INTERNAL_DEBUG | LogLevel::GRAPHICS_INTERNAL_ERROR)); Logger::GetInstance()->SetAllowRepeats(true); @@ -138,17 +142,17 @@ namespace lunarium OpRes result; mPanelIDs.CoreConsole = AddPanel(new CoreConsole); - Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running Lunarium version %s", Version::GetVersion().ToString().c_str()); + Logger::Info(LogCategory::CORE, "Running Lunarium version %s", Version::GetVersion().ToString().c_str()); // Attempt to load the engine state file. This file should be placed in the same directory as the lunarium program. if (Failed(State::CreateFromFile("engine_state.xml", mState))) { - Logger::Log(LogCategory::CORE, LogLevel::WARNING, "Unable to load state file: engine_state.xml. Loading default state."); + Logger::Warn(LogCategory::CORE, "Unable to load state file: engine_state.xml. Loading default state."); mState = State::CreateDefault(); } else { - Logger::Log(LogCategory::CORE, LogLevel::INFO, "Loaded state file: engine_state.xml"); + Logger::Info(LogCategory::CORE, "Loaded state file: engine_state.xml"); } // Parse command line args -- None right now @@ -160,7 +164,7 @@ namespace lunarium result = mpWindow->Initialize(mState); if (Failed(result)) { - Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR, + Logger::Fatal(LogCategory::CORE, "Could not initialize the Window system: %s", result.Description.c_str()); return; } @@ -171,13 +175,13 @@ namespace lunarium } else if (RenderSystem::VULKAN == mState.Display.Renderer) { - Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR, + Logger::Fatal(LogCategory::CORE, "Can not create Vulkan graphics system because it is not yet implemented. Must use OpenGL instead."); return; } else { - Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR, + Logger::Fatal(LogCategory::CORE, "Could not create graphics system: Unknown render framework specified."); return; } @@ -191,7 +195,7 @@ namespace lunarium if (Failed(result)) { - Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR, + Logger::Fatal(LogCategory::CORE, "Could not initialized the graphics system: %s", result.Description); return; } @@ -206,7 +210,7 @@ namespace lunarium result = mGUI.Initialize(mpWindow->GetWindow()); if (Failed(result)) { - Logger::Log(LogCategory::CORE, LogLevel::WARNING, + Logger::Warn(LogCategory::CORE, "Could not initialized the main GUI system: %s", result.Description); } @@ -215,7 +219,7 @@ namespace lunarium result = scriptMan.Initialize(); if (Failed(result)) { - Logger::Log(LogCategory::CORE, LogLevel::WARNING, + Logger::Warn(LogCategory::CORE, "Could not initialized the LUA script manager: %s", result.Description); } @@ -223,13 +227,13 @@ namespace lunarium result = capi.Initialize(scriptMan); if (Failed(result)) { - Logger::Log(LogCategory::CORE, LogLevel::WARNING, + Logger::Warn(LogCategory::CORE, "Could not initialized the LUA Core API: %s", result.Description); } // RUN MODE const char* types[] = { "game", "editor", "test" }; - Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running in mode: %s", types[mState.Mode]); + Logger::Info(LogCategory::CORE, "Running in mode: %s", types[mState.Mode]); if (RunMode::MODE_TEST == mState.Mode) { mpRunMode = new TestBed; @@ -238,7 +242,7 @@ namespace lunarium else if (RunMode::MODE_EDITOR == mState.Mode) { #if BUILD_NO_EDITOR - Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR, "The Editor is not available with this build"); + Logger::Fatal(LogCategory::CORE, "The Editor is not available with this build"); return; #else mpRunMode = new editor::Editor; @@ -249,7 +253,7 @@ namespace lunarium // Initialize the Run Mode if (Failed(mpRunMode->Initialize())) { - Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR, + Logger::Fatal(LogCategory::CORE, "Could not initialize the Run Mode: %s", result.Description.c_str()); return; } @@ -314,11 +318,11 @@ namespace lunarium std::string command; if (con && con->GetNewCommand(command)) { - // Logger::Log(LogCategory::CORE, LogLevel::INFO, "New LUA command: %s", command.c_str()); + // Logger::Debug(LogCategory::SCRIPTING, "New LUA command: %s", command.c_str()); OpRes result = ScriptManager::RunScript(command.c_str()); if (Failed(result)) { - Logger::Log(LogCategory::CORE, LogLevel::INFO_VERBOSE, result.Description.c_str()); + Logger::Error(LogCategory::SCRIPTING, result.Description.c_str()); } } } @@ -342,7 +346,7 @@ namespace lunarium // RENDER if (mbMidTextureRender) { - Logger::Log(LogCategory::CORE, LogLevel::WARNING, "Render to texture was not ended!"); + Logger::Warn(LogCategory::CORE, "Render to texture was not ended!"); EndRenderToTexture(); } diff --git a/src/core/core.h b/src/core/core.h index 8f3f5c8..6e81d24 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -9,6 +9,7 @@ #ifndef CORE_H_ #define CORE_H_ +#include "common_defs.h" #include "state.h" #include "run_mode.h" #include @@ -68,6 +69,7 @@ namespace lunarium // Log Files std::ofstream mMasterLogFile; std::ofstream mErrorLogFile; + std::ofstream mGraphicsLogFile; private: // SUBSYSTEMS diff --git a/src/core/state.cpp b/src/core/state.cpp index 9d6e7b1..9d3c92d 100644 --- a/src/core/state.cpp +++ b/src/core/state.cpp @@ -93,7 +93,7 @@ namespace lunarium } else { - Logger::Log(LogCategory::CORE, LogLevel::WARNING, + Logger::Warn(LogCategory::CORE, "Can not find Run Mode in state file: %s, defaulting to MODE_TEST", filename.c_str()); state.Mode = RunMode::MODE_TEST; } @@ -162,7 +162,7 @@ namespace lunarium { LoadedFile = "UNNAMED_STATE.xml"; } - Logger::Log(LogCategory::CORE, LogLevel::INFO, "Saving state file: %s", LoadedFile.c_str()); + Logger::Info(LogCategory::CORE, "Saving state file: %s", LoadedFile.c_str()); return SaveToFile(LoadedFile); } diff --git a/src/graphics/internalFont.cpp b/src/graphics/internalFont.cpp index 5d9df1d..bdc96b1 100644 --- a/src/graphics/internalFont.cpp +++ b/src/graphics/internalFont.cpp @@ -21,7 +21,7 @@ namespace lunarium if (!ofs.is_open()) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::WARNING, "Could not generate the default font file at: %s", filename); + Logger::Warn(LogCategory::GRAPHICS, "Could not generate the default font file at: %s", filename); return false; } diff --git a/src/graphics/opengl/glGraphics.cpp b/src/graphics/opengl/glGraphics.cpp index 17b0451..ec7dbe1 100644 --- a/src/graphics/opengl/glGraphics.cpp +++ b/src/graphics/opengl/glGraphics.cpp @@ -29,19 +29,29 @@ namespace lunarium void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) { - uint32_t level = LogLevel::OGL_DEBUG; + if (type == GL_DEBUG_TYPE_ERROR) { - level = LogLevel::ERROR; + Logger::GIInfo(LogCategory::GRAPHICS, + "%s (type: %s, source: %s, severity: %s), message: %s", + (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), + OglGraphics::mDebugMsgSources[source].c_str(), + OglGraphics::mDebugMsgTypes[type].c_str(), + OglGraphics::mDebugMsgSeverity[severity].c_str(), + message); } - - Logger::Log(LogCategory::GRAPHICS, level, + else + { + Logger::GIDebug(LogCategory::GRAPHICS, "%s (type: %s, source: %s, severity: %s), message: %s", (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), OglGraphics::mDebugMsgSources[source].c_str(), OglGraphics::mDebugMsgTypes[type].c_str(), OglGraphics::mDebugMsgSeverity[severity].c_str(), message); + } + + } //////////////////////////////////////////////////////////// @@ -83,7 +93,7 @@ namespace lunarium OpRes res = mText.Initialize(); if (Failed(res)) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::WARNING, "Could not initialized the text renderer - %s", res.Description); + Logger::Warn(LogCategory::GRAPHICS, "Could not initialized the text renderer - %s", res.Description); } // Load the default internal font @@ -92,11 +102,11 @@ namespace lunarium mDefaultFont = mText.LoadFont(OpenFontData, OpenDataSize, font); if (mDefaultFont < 0) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::WARNING, "Unable to load the default font: %s", font); + Logger::Warn(LogCategory::GRAPHICS, "Unable to load the default font: %s", font); } else { - Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO, "Successfully created default font: %s", font); + Logger::Info(LogCategory::GRAPHICS, "Successfully created default font: %s", font); } return OpRes::OK(); @@ -219,7 +229,7 @@ namespace lunarium } else { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "OglGraphics::CreateRenderTexture failed - invalid channels value: %n", channels); + Logger::Error(LogCategory::GRAPHICS, "OglGraphics::CreateRenderTexture failed - invalid channels value: %n", channels); return -1; } @@ -252,7 +262,7 @@ namespace lunarium if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::WARNING, "Unable to initialize framebuffer for rendering to a texture"); + Logger::Warn(LogCategory::GRAPHICS, "Unable to initialize framebuffer for rendering to a texture"); glBindFramebuffer(GL_FRAMEBUFFER, 0); return -1; } @@ -635,7 +645,7 @@ namespace lunarium mImageShader.SetSource(glShader::TYPE_FRAGMENT, OGLDefaultShaders.DefaultSpriteFragment, false); if (!mImageShader.BuildProgram()) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "Unable to build default image shader program"); + Logger::Error(LogCategory::GRAPHICS, "Unable to build default image shader program"); } } @@ -669,47 +679,7 @@ namespace lunarium mShapeShader.SetSource(glShader::TYPE_FRAGMENT, OGLDefaultShaders.DefaultShapeFragment, false); if (!mShapeShader.BuildProgram()) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::WARNING, "Unable to build shape shader program."); + Logger::Error(LogCategory::GRAPHICS, "Unable to build shape shader program."); } } - - void OglGraphics::InitTextureFrameBuffer() - { - - // NOTE: METHOD IS NO LONGER NEEDED - - // Frame buffer - // glGenFramebuffers(1, &mFBO); - // glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - - // // Texture - // unsigned int id = -1; - // glGenTextures(1, &id); - // mpFBTexture->SetGLTextureID(id); - // glBindTexture(GL_TEXTURE_2D, mpFBTexture->GetGLTextureID()); - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mFBWidth, mFBHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - // glBindTexture(GL_TEXTURE_2D, 0); - - // // Attach texture - // glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mpFBTexture->GetGLTextureID(), 0); - - // // Render Buffer for depth/stencil testing - // glGenRenderbuffers(1, &mRBO); - // glBindRenderbuffer(GL_RENDERBUFFER, mRBO); - // glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mFBWidth, mFBHeight); - // glBindRenderbuffer(GL_RENDERBUFFER, 0); - - // // Atach the render buffer - // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mRBO); - - - // if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) - // { - // Logger::Log(LogCategory::GRAPHICS, LogLevel::WARNING, "Unable to initialize framebuffer for rendering to a texture"); - // } - - // glBindFramebuffer(GL_FRAMEBUFFER, 0); - } } \ No newline at end of file diff --git a/src/graphics/opengl/glShader.cpp b/src/graphics/opengl/glShader.cpp index c737e07..98d329c 100644 --- a/src/graphics/opengl/glShader.cpp +++ b/src/graphics/opengl/glShader.cpp @@ -118,7 +118,7 @@ namespace lunarium if (-1 == uniformLocation) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, + Logger::Error(LogCategory::GRAPHICS, "Unable to find uniform location. Uniform name: %s", uniformName); return false; } @@ -139,13 +139,13 @@ namespace lunarium int count = -1; glGetProgramiv(mProgram, GL_ACTIVE_UNIFORMS, &count); - Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO, "Active Uniforms: %d", count); + Logger::Debug(LogCategory::GRAPHICS, "Active Uniforms: %d", count); for (int i = 0; i < count; i++) { glGetActiveUniform(mProgram, (GLuint)i, bufSize, &length, &size, &type, name); - Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO, "Uniform #%d Type: %u Name: %s", i, type, name); + Logger::Debug(LogCategory::GRAPHICS, "Uniform #%d Type: %u Name: %s", i, type, name); } } @@ -153,7 +153,7 @@ namespace lunarium { if (sourceType < 0 || sourceType >= TYPE_COUNT) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, + Logger::Error(LogCategory::GRAPHICS, "Can not set shader source (%s) - Invalid Source Type (%d)", source, (int)sourceType); return false; } @@ -178,14 +178,14 @@ namespace lunarium { if (sourceType < 0 || sourceType >= TYPE_COUNT) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, + Logger::Error(LogCategory::GRAPHICS, "Can not compile source - Invalid Source Type: %d", (int)sourceType); return false; } if ("" == mShaders[sourceType].Source) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, + Logger::Error(LogCategory::GRAPHICS, "Can not compile %s shader source - Source is empty", TypeNames[sourceType]); return false; } @@ -207,7 +207,7 @@ namespace lunarium if (!success) { glGetShaderInfoLog(mShaders[sourceType].ID, 512, NULL, infoLog); - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, + Logger::Error(LogCategory::GRAPHICS, "Error compiling %s shader source: %s", TypeNames[sourceType], infoLog); return false; } @@ -220,7 +220,7 @@ namespace lunarium { if ("" == mShaders[TYPE_VERTEX].Source || "" == mShaders[TYPE_FRAGMENT].Source) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, + Logger::Error(LogCategory::GRAPHICS, "Cannot create shader program - vertex and fragment shader must be set!"); return false; } @@ -238,7 +238,7 @@ namespace lunarium { if (mShaders[i].Source == "") { - Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO_VERBOSE, + Logger::Trace(LogCategory::GRAPHICS, "Skipping compilation of %s shader source - source is empty", TypeNames[i]); } else @@ -268,7 +268,7 @@ namespace lunarium if (!success) { glGetProgramInfoLog(mProgram, 512, NULL, infoLog); - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, + Logger::Error(LogCategory::GRAPHICS, "Failed to link the shader program. Info Log: %s", infoLog); return false; } @@ -308,7 +308,7 @@ namespace lunarium if (!ifs.is_open()) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, + Logger::Error(LogCategory::GRAPHICS, "Failed to load shader source from file (file not found): %s", filename); return ""; } diff --git a/src/graphics/opengl/glText.cpp b/src/graphics/opengl/glText.cpp index 208ecc4..fff2efa 100644 --- a/src/graphics/opengl/glText.cpp +++ b/src/graphics/opengl/glText.cpp @@ -21,21 +21,21 @@ namespace lunarium { if (!mTextShader.IsBuilt()) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "Unable to load font because no text rendering shaders are loaded"); + Logger::Error(LogCategory::GRAPHICS, "Unable to load font because no text rendering shaders are loaded"); return -1; } FT_Library ft; if (FT_Init_FreeType(&ft)) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "FREETYPE: Could not init FreeType Library"); + Logger::Error(LogCategory::GRAPHICS,"FREETYPE: Could not init FreeType Library"); return -1; } FT_Face face; if (FT_New_Face(ft, fontFile, 0, &face)) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "FREETYPE: Failed to load font from file: %s", fontFile); + Logger::Error(LogCategory::GRAPHICS, "FREETYPE: Failed to load font from file: %s", fontFile); return -1; } @@ -46,21 +46,21 @@ namespace lunarium { if (!mTextShader.IsBuilt()) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "Unable to load font because no text rendering shaders are loaded"); + Logger::Error(LogCategory::GRAPHICS, "Unable to load font because no text rendering shaders are loaded"); return -1; } FT_Library ft; if (FT_Init_FreeType(&ft)) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "FREETYPE: Could not init FreeType Library"); + Logger::Error(LogCategory::GRAPHICS, "FREETYPE: Could not init FreeType Library"); return -1; } FT_Face face; if (FT_New_Memory_Face(ft, fontData, dataSize, 0, &face)) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "FREETYPE: Failed to load font from buffer. Font name: %s", name); + Logger::Error(LogCategory::GRAPHICS, "FREETYPE: Failed to load font from buffer. Font name: %s", name); return -1; } @@ -84,7 +84,7 @@ namespace lunarium // Load character glyph if (FT_Load_Char(face, c, FT_LOAD_RENDER)) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "FREETYTPE: Failed to load Glyph %c from font: %s", c, name); + Logger::Error(LogCategory::GRAPHICS, "FREETYTPE: Failed to load Glyph %c from font: %s", c, name); continue; } @@ -172,13 +172,13 @@ namespace lunarium { if (!mTextShader.IsBuilt()) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "Unable to draw string because no text rendering shaders are loaded"); + Logger::Error(LogCategory::GRAPHICS, "Unable to draw string because no text rendering shaders are loaded"); return; } if (fontID < 0 || fontID >= mFonts.size()) { - Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, "Invalid font ID specified for DrawString: %d", fontID); + Logger::Error(LogCategory::GRAPHICS, "Invalid font ID specified for DrawString: %d", fontID); return; } diff --git a/src/input/inputManager.cpp b/src/input/inputManager.cpp index 6113f98..fd7cf07 100644 --- a/src/input/inputManager.cpp +++ b/src/input/inputManager.cpp @@ -36,7 +36,7 @@ namespace lunarium { if (!mpWindow) { - Logger::Log(LogCategory::CORE, LogLevel::WARNING, "InputManager::PollKeys called but InputManager is not initialized!"); + Logger::Warn(LogCategory::CORE, "InputManager::PollKeys called but InputManager is not initialized!"); return mKeyEvents; } @@ -78,7 +78,7 @@ namespace lunarium // Ignore key presses for unknown keys if (KeyCode::KEY_UNKNOWN == key.Code) { - Logger::Log(LogCategory::CORE, LogLevel::INFO_VERBOSE, + Logger::Trace(LogCategory::CORE, "Input Manager skipping unknown key press: idx: %d, code: %d", i, KeyCodeList[i]); continue; } @@ -86,7 +86,7 @@ namespace lunarium // Key was just pressed this frame if (KEY_UP == mKeyboardState[KeyCodeList[i]]) { - //Logger::Log(LogCategory::CORE, LogLevel::INFO, "Key Down: %d, %s", KeyCodeList[i], key.Name.c_str()); + //Logger::Debug(LogCategory::CORE, "Key Down: %d, %s", KeyCodeList[i], key.Name.c_str()); mKeyboardState[KeyCodeList[i]] = KEY_DOWN; KeyPress kp; diff --git a/src/internal_libs/gui/CMakeLists.txt b/src/internal_libs/gui/CMakeLists.txt index 0c2517b..8b9633a 100644 --- a/src/internal_libs/gui/CMakeLists.txt +++ b/src/internal_libs/gui/CMakeLists.txt @@ -8,7 +8,7 @@ set(GUI_SRC ) add_library(gui ${GUI_SRC}) -target_link_libraries(gui utils assets dearimgui glfw) +target_link_libraries(gui assets dearimgui glfw) target_include_directories(gui PUBLIC "${PROJECT_BINARY_DIR}" diff --git a/src/internal_libs/gui/gui.cpp b/src/internal_libs/gui/gui.cpp index f6a5a97..1b9f81c 100644 --- a/src/internal_libs/gui/gui.cpp +++ b/src/internal_libs/gui/gui.cpp @@ -85,7 +85,7 @@ namespace lunarium ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); //mbShowDemo = true; - Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO, "ImGui setup"); + Logger::Info(LogCategory::GRAPHICS, "ImGui setup"); mbIsInit = true; return OpRes::OK(); } diff --git a/src/main.cpp b/src/main.cpp index 0468baf..c3ebad9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,9 +22,25 @@ int main(int argc, char** argv) path = lunarium::String::TrimFileNameFromPath(path); std::filesystem::current_path(path); + +// TODO: This could be made nicer... + u32 ll = lunarium::LogLevel::FATAL_ERROR | lunarium::LogLevel::ERROR; +#if LOG_LEVEL == 2 + ll = lunarium::LogLevel::FATAL_ERROR | lunarium::LogLevel::ERROR | lunarium::LogLevel::WARNING | lunarium::LogLevel::INFO; +#endif +#if LOG_LEVEL == 3 + ll = lunarium::LogLevel::ANY & ~(lunarium::LogLevel::GRAPHICS_INTERNAL_DEBUG | lunarium::LogLevel::GRAPHICS_INTERNAL_ERROR); +#endif +#if LOG_LEVEL == 4 + ll = lunarium::LogLevel::ANY & ~(lunarium::LogLevel::GRAPHICS_INTERNAL_ERROR); +#endif +#if LOG_LEVEL == 5 + ll = lunarium::LogLevel::ANY; +#endif + // All log messages will go to stdout lunarium::Logger::GetInstance()->AddListener(new lunarium::StandardListener( - lunarium::LogLevel::ANY & ~lunarium::LogLevel::OGL_DEBUG, lunarium::LogCategory::ANY)); + ll, lunarium::LogCategory::ANY)); lunarium::Core& core = lunarium::Core::GetInstance(); core.Initialize(argc, argv); diff --git a/src/run_modes/editor/CMakeLists.txt b/src/run_modes/editor/CMakeLists.txt index ea67262..9a9c338 100644 --- a/src/run_modes/editor/CMakeLists.txt +++ b/src/run_modes/editor/CMakeLists.txt @@ -21,7 +21,7 @@ set(EDITOR_SRC add_library(editor ${EDITOR_SRC}) -target_link_libraries(editor gui utils assets) +target_link_libraries(editor gui assets) target_include_directories(editor PUBLIC "${PROJECT_BINARY_DIR}" diff --git a/src/run_modes/editor/contents/tile_map.cpp b/src/run_modes/editor/contents/tile_map.cpp index 4e7afb9..3b008b0 100644 --- a/src/run_modes/editor/contents/tile_map.cpp +++ b/src/run_modes/editor/contents/tile_map.cpp @@ -169,7 +169,7 @@ namespace lunarium { namespace editor // Make sure the tileset exists if (mTileSets.find(id) == mTileSets.end()) { - Logger::Log(Editor::LogCat, LogLevel::WARNING, "Tile Map is missing tile set. No Tile Set with id: %d", id); + Logger::Warn(Editor::LogCat, "Tile Map is missing tile set. No Tile Set with id: %d", id); continue; } diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index e74309c..c88363c 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -28,7 +28,7 @@ using namespace lunarium::gui; // ERROR LOG MACRO -#define LOG_ERR_AND_RETURN(result) { if (Failed(result)) { Logger::Log(LogCat, LogLevel::ERROR, result.Description.c_str()); return result; } } +#define LOG_ERR_AND_RETURN(result) { if (Failed(result)) { Logger::Error(LogCat, result.Description.c_str()); return result; } } namespace lunarium { @@ -140,7 +140,7 @@ namespace editor } } - Logger::Log(LogCat, LogLevel::WARNING, "And unknown ToolType was passed into Editor::IsToolOpen: %n", type); + Logger::Warn(LogCat, "And unknown ToolType was passed into Editor::IsToolOpen: %n", type); return false; } @@ -199,20 +199,20 @@ namespace editor if (mFileBrowser.GetResult() == FileBrowser::Result::OK) { mpPath = mFileBrowser.GetSelectedItem(); - Logger::Log(LogCat, LogLevel::INFO, "Generating new project at %s", mpPath->string().c_str()); + Logger::Info(LogCat, "Generating new project at %s", mpPath->string().c_str()); // Generate new project at mpPath OpRes result = mProject.GenerateProject(mpPath->filename().string(), mpPath->parent_path()); if (Failed(result)) { - Logger::Log(LogCat, LogLevel::ERROR, "Could not create a new project: %s", result.Description); + Logger::Error(LogCat, "Could not create a new project: %s", result.Description); } ((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))->SetAssetDirectory(*mpPath / std::filesystem::path("contents/assets")); mDoNewProject = false; } else if (mFileBrowser.GetResult() == FileBrowser::Result::CANCEL) { - Logger::Log(LogCat, LogLevel::INFO, "New Project operation cancelled"); + Logger::Info(LogCat, "New Project operation cancelled"); mDoNewProject = false; } @@ -223,7 +223,7 @@ namespace editor if (mFileBrowser.GetResult() == FileBrowser::Result::OK) { mpPath = mFileBrowser.GetSelectedItem(); - Logger::Log(LogCat, LogLevel::INFO, "Opening project: %s", mpPath->string().c_str()); + Logger::Info(LogCat, "Opening project: %s", mpPath->string().c_str()); // Open project at mpPath if (Failed(mProject.LoadProject(*mpPath).LogIfFailed(Editor::LogCat))) @@ -236,7 +236,7 @@ namespace editor } else if (mFileBrowser.GetResult() == FileBrowser::Result::CANCEL) { - Logger::Log(LogCat, LogLevel::INFO, "Open Project operation cancelled"); + Logger::Info(LogCat, "Open Project operation cancelled"); mDoOpenProject = false; } @@ -283,7 +283,7 @@ namespace editor if (!mFileBrowser.OpenInDirectory("")) { mDoNewProject = false; - Logger::Log(LogCat, LogLevel::ERROR, "Could not open the File Browser"); + Logger::Error(LogCat, "Could not open the File Browser"); } } @@ -296,7 +296,7 @@ namespace editor if (!mFileBrowser.OpenInDirectory("")) { mDoOpenProject = false; - Logger::Log(LogCat, LogLevel::ERROR, "Could not open the File Browser"); + Logger::Error(LogCat, "Could not open the File Browser"); } } diff --git a/src/run_modes/editor/panel_manager.cpp b/src/run_modes/editor/panel_manager.cpp index 960eab6..0a45add 100644 --- a/src/run_modes/editor/panel_manager.cpp +++ b/src/run_modes/editor/panel_manager.cpp @@ -97,7 +97,7 @@ namespace lunarium { namespace editor return mPanels[id]; } - Logger::Log(mpEditor->GetLogCat(), LogLevel::WARNING, "Requested panel not found: %d", id); + Logger::Warn(mpEditor->GetLogCat(), "Requested panel not found: %d", id); return nullptr; } @@ -168,7 +168,7 @@ namespace lunarium { namespace editor mDockSpaceID = ImGui::DockSpace(ImGui::GetID(dock_name.c_str()), ImVec2(0, 0), 0, &mWindowClass); if (!ImGui::DockBuilderGetNode(mDockSpaceID) || mResetDockSpace) { - Logger::Log(mpEditor->GetLogCat(), LogLevel::INFO_VERBOSE, "Resetting Dockspace: %s", dock_name.c_str()); + Logger::Trace(mpEditor->GetLogCat(), "Resetting Dockspace: %s", dock_name.c_str()); mResetDockSpace = false; ImGui::DockBuilderRemoveNode(mDockSpaceID); diff --git a/src/run_modes/editor/tools/map_editor/map_editor.cpp b/src/run_modes/editor/tools/map_editor/map_editor.cpp index 4df34e4..c06e77c 100644 --- a/src/run_modes/editor/tools/map_editor/map_editor.cpp +++ b/src/run_modes/editor/tools/map_editor/map_editor.cpp @@ -227,7 +227,7 @@ namespace lunarium { namespace editor if (!mFileBrowser.OpenInDirectory("")) { mImportTileSet = false; - Logger::Log(Editor::LogCat, LogLevel::ERROR, "Could not open the File Browser"); + Logger::Error(Editor::LogCat, "Could not open the File Browser"); } } @@ -267,7 +267,7 @@ namespace lunarium { namespace editor if (mFileBrowser.GetResult() == FileBrowser::Result::OK) { auto path = mFileBrowser.GetSelectedItem(); - Logger::Log(Editor::LogCat, LogLevel::INFO, "Importing tile set: %s", path->string().c_str()); + Logger::Info(Editor::LogCat, "Importing tile set: %s", path->string().c_str()); uint64_t id = 0; ContentManager::GetInstance().ImportFile(*path, /*mpEditor->GetAssetBrowserLocation() / */ path->filename(), AssetType::EATYPE_TILE_SET, id).LogIfFailed(Editor::LogCat); @@ -289,7 +289,7 @@ namespace lunarium { namespace editor } else if (mFileBrowser.GetResult() == FileBrowser::Result::CANCEL) { - Logger::Log(Editor::LogCat, LogLevel::INFO, "New Project operation cancelled"); + Logger::Info(Editor::LogCat, "New Project operation cancelled"); mImportTileSet = false; } diff --git a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp index aa2d88b..e1e474f 100644 --- a/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp +++ b/src/run_modes/editor/tools/map_editor/panels/tile_set_view.cpp @@ -31,19 +31,14 @@ namespace lunarium { namespace editor { if (ImGui::GetIO().MouseDown[ImGuiMouseButton_Left] && !mMouseDown) { - mMouseDown = true; float x = ImGui::GetMousePos().x; float y = ImGui::GetMousePos().y; - //Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse clicked at (%f, %f)", x, y); - // Adjust for window pos x -= mWorkAreaPos.X; y -= mWorkAreaPos.Y; - //Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Pos Adjusted (%f, %f)", x, y); - // Check that it's within the window bool is_in_window = x >= 0.0f && x < mWorkAreaSize.X && y >= 0.0f && y < mWorkAreaSize.Y; @@ -53,14 +48,10 @@ namespace lunarium { namespace editor x += mScrollOffset.X; y += mScrollOffset.Y; - //Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Pos scrolled (%f, %f)", x, y); - // Find selected tile mSelectedTile.X = x / mpSelectedTileSet->GetTileSize().Width; mSelectedTile.Y = y / mpSelectedTileSet->GetTileSize().Height; - //Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Updating Tile Selection: tile (%d, %d)", mSelectedTile.X, mSelectedTile.Y); - // Notify the editor that the selected tile has changed mpEditor->ChangeSelectedTile({ mpSelectedTileSet->GetTileSetID(), mSelectedTile }); @@ -70,7 +61,6 @@ namespace lunarium { namespace editor if (!ImGui::GetIO().MouseDown[ImGuiMouseButton_Left] && mMouseDown) { - //Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Released"); mMouseDown = false; } @@ -83,8 +73,6 @@ namespace lunarium { namespace editor mFrameBuffer = Core::Graphics().CreateRenderTexture(mpSelectedTileSet->GetImage()->GetWidth(), mpSelectedTileSet->GetImage()->GetHeight(), 4); } - //Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Invalidating tile set window"); - Color prev = Core::Graphics().GetClearColor(); Core::Graphics().SetClearColor(Color::Transparent()); Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat); diff --git a/src/run_modes/testbed/CMakeLists.txt b/src/run_modes/testbed/CMakeLists.txt index fc98d19..c0a5b77 100644 --- a/src/run_modes/testbed/CMakeLists.txt +++ b/src/run_modes/testbed/CMakeLists.txt @@ -12,4 +12,4 @@ target_include_directories(testbed PUBLIC ../../../external/box2d/include ) -target_link_libraries(testbed box2d utils dearimgui) \ No newline at end of file +target_link_libraries(testbed box2d dearimgui) \ No newline at end of file diff --git a/src/run_modes/testbed/scenes/physicsScene.cpp b/src/run_modes/testbed/scenes/physicsScene.cpp index c9cce93..cd69256 100644 --- a/src/run_modes/testbed/scenes/physicsScene.cpp +++ b/src/run_modes/testbed/scenes/physicsScene.cpp @@ -26,7 +26,7 @@ namespace lunarium void PhysicsScene::OnLoad() { - Logger::Log(mLogCat, LogLevel::INFO, "Running Physics Test Scene"); + Logger::Info(mLogCat, "Running Physics Test Scene"); // Comments from the docs: https://box2d.org/documentation/md__d_1__git_hub_box2d_docs_hello.html diff --git a/src/run_modes/testbed/scenes/simpleRenderScene.cpp b/src/run_modes/testbed/scenes/simpleRenderScene.cpp index b40887a..755046f 100644 --- a/src/run_modes/testbed/scenes/simpleRenderScene.cpp +++ b/src/run_modes/testbed/scenes/simpleRenderScene.cpp @@ -31,7 +31,7 @@ namespace lunarium void SimpleRenderScene::OnLoad() { - Logger::Log(mLogCat, LogLevel::INFO, "Running Simple Render Test Scene"); + Logger::Info(mLogCat, "Running Simple Render Test Scene"); mTextBoxWidth = 500; @@ -133,11 +133,11 @@ namespace lunarium OpRes result = Core::GetInstance().BeginRenderToTexture(mFrameBufferTwo); if (Failed(result)) { - Logger::Log(mLogCat, LogLevel::WARNING, "Unable to render to texture: %s", result.Description.c_str()); + Logger::Warn(mLogCat, "Unable to render to texture: %s", result.Description.c_str()); return; } - Logger::Log(mLogCat, LogLevel::INFO, "Running transparent image test"); + Logger::Info(mLogCat, "Running transparent image test"); g.DrawFilledBox(Rectangle(500, 400, 300, 300), Color(0.5f, 0.0f, 0.75f, 1.0f)); g.DrawString("This is a test of rendering an image with transparency", @@ -158,7 +158,7 @@ namespace lunarium OpRes result = Core::GetInstance().BeginRenderToTexture(mFrameBufferOne); if (Failed(result)) { - Logger::Log(mLogCat, LogLevel::WARNING, "Unable to render to texture: %s", result.Description.c_str()); + Logger::Error(mLogCat, "Unable to render to texture: %s", result.Description.c_str()); return; } diff --git a/src/run_modes/testbed/testbed.cpp b/src/run_modes/testbed/testbed.cpp index e949e43..2076fc1 100644 --- a/src/run_modes/testbed/testbed.cpp +++ b/src/run_modes/testbed/testbed.cpp @@ -27,12 +27,12 @@ namespace lunarium { // return OpRes::Fail("Tester::Initialize not implemented"); - mLogCat = Logger::RegisterCategory("TESTER"); + mLogCat = Logger::RegisterCategory("TESTBED"); #if BUILD_NO_EDITOR - Logger::Log(mLogCat, LogLevel::INFO, "NO EDITOR!"); + Logger::Info(mLogCat, "NO EDITOR!"); #else - Logger::Log(mLogCat, LogLevel::INFO, "EDITOR DETECTED!"); + Logger::Info(mLogCat, "EDITOR DETECTED!"); #endif mpScene = new SimpleRenderScene(mLogCat); @@ -74,7 +74,7 @@ namespace lunarium if (Core::Input().IsKeyDown(KeyCode::MOUSE_LEFT_BUTTON, true)) { - Logger::Log(mLogCat, LogLevel::INFO_VERBOSE, "Left mouse button pressed!"); + Logger::Trace(mLogCat, "Left mouse button pressed!"); } mpScene->OnTick(delta); @@ -88,7 +88,7 @@ namespace lunarium void TestBed::OnKeyPress(InputManager::KeyPress kp) { - Logger::Log(mLogCat, LogLevel::INFO_VERBOSE, "Key Press Event: %s", kp.Key.Name.c_str()); + Logger::Trace(mLogCat, "Key Press Event: %s", kp.Key.Name.c_str()); } } diff --git a/src/scripting/coreAPI.cpp b/src/scripting/coreAPI.cpp index 46a267d..2d2a65c 100644 --- a/src/scripting/coreAPI.cpp +++ b/src/scripting/coreAPI.cpp @@ -56,6 +56,14 @@ namespace lunarium void CoreAPI::Log(int level, const char* msg) { - Logger::Log(mpInstance->mCat, level, msg); + switch (level) + { + case LogLevel::FATAL_ERROR: { Logger::Fatal(mpInstance->mCat, msg); break; } + case LogLevel::ERROR: { Logger::Error(mpInstance->mCat, msg); break; } + case LogLevel::WARNING: { Logger::Warn(mpInstance->mCat, msg); break; } + case LogLevel::INFO: { Logger::Info(mpInstance->mCat, msg); break; } + case LogLevel::DEBUG: { Logger::Debug(mpInstance->mCat, msg); break; } + default: { Logger::Trace(mpInstance->mCat, msg); break; } + } } } \ No newline at end of file diff --git a/src/scripting/scriptManager.cpp b/src/scripting/scriptManager.cpp index 107c6ec..85e08a6 100644 --- a/src/scripting/scriptManager.cpp +++ b/src/scripting/scriptManager.cpp @@ -56,7 +56,7 @@ namespace lunarium if (!result.valid()) { sol::error err = result; - Logger::Log(mpInstance->mCat, LogLevel::WARNING, "LUA script has errors"); + Logger::Warn(mpInstance->mCat, "LUA script has errors"); std::ostringstream oss; oss << "LUA code has error. CODE:\n" << code << "\nEND CODE -- ERROR: " << err.what(); return OpRes::Fail(oss.str().c_str()); diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp index b82e4d8..88e1d57 100644 --- a/src/utils/logger.cpp +++ b/src/utils/logger.cpp @@ -18,81 +18,6 @@ namespace lunarium { - //namespace LogLevel - //{ - // bool LevelIsSet(uint16_t buf, uint16_t mask) - // { - // return buf & mask; - // } - - // std::string FormatLevel(uint16_t level) - // { - // if (LevelIsSet(level, FATAL_ERROR)) - // { - // return "[FATAL ERROR] "; - // } - // else if (LevelIsSet(level, ERROR)) - // { - // return "[ERROR] "; - // } - // else if (LevelIsSet(level, WARNING)) - // { - // return "[WARNING] "; - // } - // else if (LevelIsSet(level, INFO)) - // { - // return "[INFO] "; - // } - // else if (LevelIsSet(level, INFO_VERBOSE)) - // { - // return "[INFO_VERBOSE] "; - // } - // else if (LevelIsSet(level, OGL_DEBUG)) - // { - // return "[OGL_DEBUG] "; - // } - // else - // { - // return "[UNKNOWN] "; - // } - // } - //} - - //namespace LogCategory - //{ - // bool CategoryIsSet(uint16_t buf, uint16_t mask) - // { - // return buf & mask; - // } - // std::string FormatCategory(uint16_t level) - // { - // if (CategoryIsSet(level, CORE)) - // { - // return "[CORE] "; - // } - // else if (CategoryIsSet(level, WINDOW_CONTROLLER)) - // { - // return "[WINDOW CONTROLLER] "; - // } - // else if (CategoryIsSet(level, GRAPHICS)) - // { - // return "[GRAPHICS] "; - // } - // else if (CategoryIsSet(level, UTILITIES)) - // { - // return "[UTILITIES] "; - // } - // else if (CategoryIsSet(level, USER_PROJECT)) - // { - // return "[USER PROJECT] "; - // } - // else - // { - // return "[UNKNOWN] "; - // } - // } - //} - LogListener::LogListener(uint32_t acceptedLogLevels, uint32_t acceptedLogCategories, const char* myName) : mAcceptedLogLevels(acceptedLogLevels), mAcceptedLogCategories(acceptedLogCategories), mMyName(myName) { @@ -211,18 +136,23 @@ namespace lunarium { mAllowRepeats = false; - // Register built-in levels - RegisterLevel("INFO"); - RegisterLevel("WARNING"); - RegisterLevel("ERROR"); - RegisterLevel("FATAL_ERROR"); - RegisterLevel("INFO_VERBOSE"); - RegisterLevel("OGL_DEBUG"); + Logger::mLevelNames[LogLevel::FATAL_ERROR] = "FATAL ERROR"; + Logger::mLevelNames[LogLevel::ERROR] = "ERROR"; + Logger::mLevelNames[LogLevel::WARNING] = "WARNING"; + Logger::mLevelNames[LogLevel::INFO] = "INFO"; + Logger::mLevelNames[LogLevel::DEBUG] = "DEBUG"; + Logger::mLevelNames[LogLevel::TRACE] = "TRACE"; + + Logger::mLevelNames[LogLevel::GRAPHICS_INTERNAL_DEBUG] = "GRAPHICS INTERNAL DEBUG"; + Logger::mLevelNames[LogLevel::GRAPHICS_INTERNAL_ERROR] = "GRAPHICS INTERNAL INFO"; RegisterCategory("CORE"); - RegisterCategory("WINDOW_CONTROLLER"); + RegisterCategory("PLATFORM"); RegisterCategory("GRAPHICS"); RegisterCategory("UTILITIES"); + RegisterCategory("SCRIPTING"); + RegisterCategory("UI"); + RegisterCategory("GAME_SYSTEM"); } Logger * Logger::GetInstance() @@ -256,14 +186,6 @@ namespace lunarium return id; } - uint32_t Logger::RegisterLevel(const char * name) - { - Logger::mLevelNames[mNextLevelID] = name; - uint32_t id = mNextLevelID; - mNextLevelID = mNextLevelID << 1; - return id; - } - std::string Logger::GetCategoryName(uint32_t id) { if (Logger::mCategoryNames.find(id) == Logger::mCategoryNames.end()) @@ -336,21 +258,85 @@ namespace lunarium mBacklog.clear(); } - void Logger::Log(uint32_t logCategory, uint32_t logLevel, const char* message, ...) + void Logger::Log(uint32_t logCategory, uint32_t logLevel, const char* message, va_list args) { // clear the buffer - memset(mInstance->mBuffer, 0, BUFFER_SIZE); + memset(mInstance->mBuffer, 0, LLOG_BUFFER_SIZE); - if (strlen(message) >= BUFFER_SIZE) + if (strlen(message) >= LLOG_BUFFER_SIZE) throw std::runtime_error("Log message size exceeds buffer size"); // Fill the buffer with the formatted message + // va_list args; + // va_start(args, message); + vsprintf(mInstance->mBuffer, message, args); + //va_end(args); + + mInstance->Log_buff(logCategory, logLevel); + } + + void Logger::Fatal(uint32_t LogCategory, const char* message, ...) + { va_list args; va_start(args, message); - vsprintf(mInstance->mBuffer, message, args); + Log(LogCategory, LogLevel::FATAL_ERROR, message, args); + va_end(args); + } + + void Logger::Error(uint32_t LogCategory, const char* message, ...) + { + va_list args; + va_start(args, message); + Log(LogCategory, LogLevel::ERROR, message, args); va_end(args); + } - mInstance->Log_buff(logCategory, logLevel); + void Logger::Warn(uint32_t LogCategory, const char* message, ...) + { + va_list args; + va_start(args, message); + Log(LogCategory, LogLevel::WARNING, message, args); + va_end(args); + } + + void Logger::Info(uint32_t LogCategory, const char* message, ...) + { + va_list args; + va_start(args, message); + Log(LogCategory, LogLevel::INFO, message, args); + va_end(args); + } + + void Logger::Debug(uint32_t LogCategory, const char* message, ...) + { + va_list args; + va_start(args, message); + Log(LogCategory, LogLevel::DEBUG, message, args); + va_end(args); + } + + void Logger::Trace(uint32_t LogCategory, const char* message, ...) + { + va_list args; + va_start(args, message); + Log(LogCategory, LogLevel::TRACE, message, args); + va_end(args); + } + + void Logger::GIInfo(uint32_t LogCategory, const char* message, ...) + { + va_list args; + va_start(args, message); + Log(LogCategory, LogLevel::GRAPHICS_INTERNAL_ERROR, message, args); + va_end(args); + } + + void Logger::GIDebug(uint32_t LogCategory, const char* message, ...) + { + va_list args; + va_start(args, message); + Log(LogCategory, LogLevel::GRAPHICS_INTERNAL_DEBUG, message, args); + va_end(args); } void Logger::Log_buff(uint32_t logCategory, uint32_t logLevel) diff --git a/src/utils/logger.h b/src/utils/logger.h index fcfcb3e..0f30b27 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -29,21 +29,26 @@ namespace lunarium namespace LogLevel { const uint16_t ANY = 0xFFFF; - const uint16_t INFO = 0x0001; - const uint16_t WARNING = 0x0002; - const uint16_t ERROR = 0x0004; - const uint16_t FATAL_ERROR = 0x0008; - const uint16_t INFO_VERBOSE = 0x0010; - const uint16_t OGL_DEBUG = 0x0020; + const uint16_t FATAL_ERROR = 0x0001; + const uint16_t ERROR = 0x0002; + const uint16_t WARNING = 0x0004; + const uint16_t INFO = 0x0008; + const uint16_t DEBUG = 0x0010; + const uint16_t TRACE = 0x0020; + const uint16_t GRAPHICS_INTERNAL_ERROR = 0x0040; + const uint16_t GRAPHICS_INTERNAL_DEBUG = 0x0080; } namespace LogCategory { const uint16_t ANY = 0xFFFF; const uint16_t CORE = 0x0001; - const uint16_t WINDOW_CONTROLLER = 0x0002; + const uint16_t PLATFORM = 0x0002; const uint16_t GRAPHICS = 0x0004; const uint16_t UTILITIES = 0x0008; + const uint16_t SCRIPTING = 0x0010; + const uint16_t UI = 0x0020; + const uint16_t GAME_SYSTEM = 0x0040; //const uint16_t USER_PROJECT = 0x0010; } @@ -103,7 +108,7 @@ namespace lunarium class ErrorListener : public LogListener { public: - ErrorListener(uint32_t acceptedLogLevels = LogLevel::ERROR | LogLevel::FATAL_ERROR, + ErrorListener(uint32_t acceptedLogLevels = LogLevel::ERROR | LogLevel::FATAL_ERROR | LogLevel::WARNING, uint32_t acceptedLogCategories = LogCategory::ANY, const char* myName = "ErrorListener"); bool Log(LogMessage& message); }; @@ -122,7 +127,9 @@ namespace lunarium std::ofstream& mOF; }; -#define BUFFER_SIZE 1024 +#ifndef LLOG_BUFFER_SIZE +#define LLOG_BUFFER_SIZE 1024 +#endif // //////////////////////////////////////////////////////////////////////// // ======================================================================== @@ -137,7 +144,6 @@ namespace lunarium static void FreeInstance(); static uint32_t RegisterCategory(const char* name); - static uint32_t RegisterLevel(const char* name); static std::string GetCategoryName(uint32_t id); static std::string GetLevelName(uint32_t id); LogListener* AddListener(LogListener* pl); @@ -157,7 +163,15 @@ namespace lunarium // The message argument and the variable argument list work just like // printf. Use the same formatters as printf when calling this function. // Messages must be shorter than 1024 bytes. - static void Log(uint32_t logCategory, uint32_t logLevel, const char* message, ...); + static void Log(uint32_t logCategory, uint32_t logLevel, const char* message, va_list args); + static void Fatal(uint32_t LogCategory, const char* message, ...); + static void Error(uint32_t LogCategory, const char* message, ...); + static void Warn(uint32_t LogCategory, const char* message, ...); + static void Info(uint32_t LogCategory, const char* message, ...); + static void Debug(uint32_t LogCategory, const char* message, ...); + static void Trace(uint32_t LogCategory, const char* message, ...); + static void GIInfo(uint32_t LogCategory, const char* message, ...); + static void GIDebug(uint32_t LogCategory, const char* message, ...); void Log_buff(uint32_t logCategory, uint32_t logLevel); const std::vector& GetBacklog() const; @@ -170,7 +184,7 @@ namespace lunarium static std::map mCategoryNames; std::list mListeners; std::vector mBacklog; - char mBuffer[BUFFER_SIZE]; + char mBuffer[LLOG_BUFFER_SIZE]; HighResTimer mTimer; bool mAllowRepeats; diff --git a/src/utils/opRes.cpp b/src/utils/opRes.cpp index b705c58..2cfeb4d 100644 --- a/src/utils/opRes.cpp +++ b/src/utils/opRes.cpp @@ -51,7 +51,7 @@ namespace lunarium msg = prepend_msg; } msg += Description; - Logger::Log(category, LogLevel::ERROR, msg.c_str()); + Logger::Error(category, msg.c_str()); } return *this; } diff --git a/src/window/window.cpp b/src/window/window.cpp index 1a4063e..454e715 100644 --- a/src/window/window.cpp +++ b/src/window/window.cpp @@ -53,7 +53,7 @@ namespace lunarium glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_MAJOR_VERSION); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_MINOR_VERSION); - Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO, + Logger::Info(LogCategory::PLATFORM, "Creating OpenGL Context version %d, %d and glsl %s", OPENGL_MAJOR_VERSION, OPENGL_MINOR_VERSION, System::GetGLSLVersionString().c_str()); @@ -86,7 +86,7 @@ namespace lunarium // Use glad2 to load extensions int version = gladLoadGL(glfwGetProcAddress); - Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO, + Logger::Info(LogCategory::GRAPHICS, "Glad2 Loaded version: %d.%d", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version)); } else