Log system over-hauled

core_refactor
Joey Pollack 4 years ago
parent 6c43f17c27
commit 46083c836c

@ -19,6 +19,36 @@ if (NO_EDITOR)
set(BUILD_NO_EDITOR 1) set(BUILD_NO_EDITOR 1)
endif () 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) configure_file(LunariumConfig.h.in LunariumConfig.h)
# Source Files # Source Files

@ -6,4 +6,6 @@
#define OPENGL_MAJOR_VERSION @OpenGL_MAJOR_VERSION@ #define OPENGL_MAJOR_VERSION @OpenGL_MAJOR_VERSION@
#define OPENGL_MINOR_VERSION @OpenGL_MINOR_VERSION@ #define OPENGL_MINOR_VERSION @OpenGL_MINOR_VERSION@
#define BUILD_NO_EDITOR @BUILD_NO_EDITOR@ #define BUILD_NO_EDITOR @BUILD_NO_EDITOR@
#define LOG_LEVEL @LOG_LEVEL@

@ -3,6 +3,8 @@ REM This script expects to be run from the parent directory
REM ex. scripts/cmconfig.bat REM ex. scripts/cmconfig.bat
@echo off @echo off
REM Check for log level options
IF "%~1" == "noedit" ( IF "%~1" == "noedit" (
echo "no editor build" 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 cmake -Wno-dev -DNO_EDITOR=ON -DGLFW_BUILD_DOCS=OFF -DBOX2D_BUILD_TESTBED=OFF -B build/ -S . -G "Visual Studio 17 2022" -A x64

@ -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_

@ -56,7 +56,7 @@ namespace lunarium
if (!mpInstance) if (!mpInstance)
return; return;
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!"); Logger::Info(LogCategory::CORE, "Lunarium is shutting down!");
int x, y; int x, y;
mpInstance->MainWindow().GetPosition(&x, &y); mpInstance->MainWindow().GetPosition(&x, &y);
@ -123,14 +123,18 @@ namespace lunarium
mErrorLogFile.open("Lunarium_Errors.log", std::ios_base::app); mErrorLogFile.open("Lunarium_Errors.log", std::ios_base::app);
mGraphicsLogFile.open("Lunarium_Graphics.log", std::ios_base::app);
mErrorLogFile << "\n\n"; mErrorLogFile << "\n\n";
if (mMasterLogFile.is_open()) if (mMasterLogFile.is_open())
Logger::GetInstance()->AddListener(new FileListener(mMasterLogFile)); Logger::GetInstance()->AddListener(new FileListener(mMasterLogFile));
if (mErrorLogFile.is_open()) if (mErrorLogFile.is_open())
Logger::GetInstance()->AddListener(new FileListener(mErrorLogFile, LogLevel::ERROR | LogLevel::FATAL_ERROR)); 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); Logger::GetInstance()->SetAllowRepeats(true);
@ -138,17 +142,17 @@ namespace lunarium
OpRes result; OpRes result;
mPanelIDs.CoreConsole = AddPanel(new CoreConsole); 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. // 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))) 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(); mState = State::CreateDefault();
} }
else 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 // Parse command line args -- None right now
@ -160,7 +164,7 @@ namespace lunarium
result = mpWindow->Initialize(mState); result = mpWindow->Initialize(mState);
if (Failed(result)) 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()); "Could not initialize the Window system: %s", result.Description.c_str());
return; return;
} }
@ -171,13 +175,13 @@ namespace lunarium
} }
else if (RenderSystem::VULKAN == mState.Display.Renderer) 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."); "Can not create Vulkan graphics system because it is not yet implemented. Must use OpenGL instead.");
return; return;
} }
else else
{ {
Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR, Logger::Fatal(LogCategory::CORE,
"Could not create graphics system: Unknown render framework specified."); "Could not create graphics system: Unknown render framework specified.");
return; return;
} }
@ -191,7 +195,7 @@ namespace lunarium
if (Failed(result)) if (Failed(result))
{ {
Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR, Logger::Fatal(LogCategory::CORE,
"Could not initialized the graphics system: %s", result.Description); "Could not initialized the graphics system: %s", result.Description);
return; return;
} }
@ -206,7 +210,7 @@ namespace lunarium
result = mGUI.Initialize(mpWindow->GetWindow()); result = mGUI.Initialize(mpWindow->GetWindow());
if (Failed(result)) if (Failed(result))
{ {
Logger::Log(LogCategory::CORE, LogLevel::WARNING, Logger::Warn(LogCategory::CORE,
"Could not initialized the main GUI system: %s", result.Description); "Could not initialized the main GUI system: %s", result.Description);
} }
@ -215,7 +219,7 @@ namespace lunarium
result = scriptMan.Initialize(); result = scriptMan.Initialize();
if (Failed(result)) if (Failed(result))
{ {
Logger::Log(LogCategory::CORE, LogLevel::WARNING, Logger::Warn(LogCategory::CORE,
"Could not initialized the LUA script manager: %s", result.Description); "Could not initialized the LUA script manager: %s", result.Description);
} }
@ -223,13 +227,13 @@ namespace lunarium
result = capi.Initialize(scriptMan); result = capi.Initialize(scriptMan);
if (Failed(result)) if (Failed(result))
{ {
Logger::Log(LogCategory::CORE, LogLevel::WARNING, Logger::Warn(LogCategory::CORE,
"Could not initialized the LUA Core API: %s", result.Description); "Could not initialized the LUA Core API: %s", result.Description);
} }
// RUN MODE // RUN MODE
const char* types[] = { "game", "editor", "test" }; 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) if (RunMode::MODE_TEST == mState.Mode)
{ {
mpRunMode = new TestBed; mpRunMode = new TestBed;
@ -238,7 +242,7 @@ namespace lunarium
else if (RunMode::MODE_EDITOR == mState.Mode) else if (RunMode::MODE_EDITOR == mState.Mode)
{ {
#if BUILD_NO_EDITOR #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; return;
#else #else
mpRunMode = new editor::Editor; mpRunMode = new editor::Editor;
@ -249,7 +253,7 @@ namespace lunarium
// Initialize the Run Mode // Initialize the Run Mode
if (Failed(mpRunMode->Initialize())) 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()); "Could not initialize the Run Mode: %s", result.Description.c_str());
return; return;
} }
@ -314,11 +318,11 @@ namespace lunarium
std::string command; std::string command;
if (con && con->GetNewCommand(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()); OpRes result = ScriptManager::RunScript(command.c_str());
if (Failed(result)) 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 // RENDER
if (mbMidTextureRender) 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(); EndRenderToTexture();
} }

@ -9,6 +9,7 @@
#ifndef CORE_H_ #ifndef CORE_H_
#define CORE_H_ #define CORE_H_
#include "common_defs.h"
#include "state.h" #include "state.h"
#include "run_mode.h" #include "run_mode.h"
#include <gui/panel.h> #include <gui/panel.h>
@ -68,6 +69,7 @@ namespace lunarium
// Log Files // Log Files
std::ofstream mMasterLogFile; std::ofstream mMasterLogFile;
std::ofstream mErrorLogFile; std::ofstream mErrorLogFile;
std::ofstream mGraphicsLogFile;
private: // SUBSYSTEMS private: // SUBSYSTEMS

@ -93,7 +93,7 @@ namespace lunarium
} }
else 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()); "Can not find Run Mode in state file: %s, defaulting to MODE_TEST", filename.c_str());
state.Mode = RunMode::MODE_TEST; state.Mode = RunMode::MODE_TEST;
} }
@ -162,7 +162,7 @@ namespace lunarium
{ {
LoadedFile = "UNNAMED_STATE.xml"; 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); return SaveToFile(LoadedFile);
} }

@ -21,7 +21,7 @@ namespace lunarium
if (!ofs.is_open()) 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; return false;
} }

@ -29,19 +29,29 @@ namespace lunarium
void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length, const GLchar* message, const void* userParam) GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
{ {
uint32_t level = LogLevel::OGL_DEBUG;
if (type == GL_DEBUG_TYPE_ERROR) 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);
} }
else
Logger::Log(LogCategory::GRAPHICS, level, {
Logger::GIDebug(LogCategory::GRAPHICS,
"%s (type: %s, source: %s, severity: %s), message: %s", "%s (type: %s, source: %s, severity: %s), message: %s",
(type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""),
OglGraphics::mDebugMsgSources[source].c_str(), OglGraphics::mDebugMsgSources[source].c_str(),
OglGraphics::mDebugMsgTypes[type].c_str(), OglGraphics::mDebugMsgTypes[type].c_str(),
OglGraphics::mDebugMsgSeverity[severity].c_str(), OglGraphics::mDebugMsgSeverity[severity].c_str(),
message); message);
}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -83,7 +93,7 @@ namespace lunarium
OpRes res = mText.Initialize(); OpRes res = mText.Initialize();
if (Failed(res)) 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 // Load the default internal font
@ -92,11 +102,11 @@ namespace lunarium
mDefaultFont = mText.LoadFont(OpenFontData, OpenDataSize, font); mDefaultFont = mText.LoadFont(OpenFontData, OpenDataSize, font);
if (mDefaultFont < 0) 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 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(); return OpRes::OK();
@ -219,7 +229,7 @@ namespace lunarium
} }
else 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; return -1;
} }
@ -252,7 +262,7 @@ namespace lunarium
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 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); glBindFramebuffer(GL_FRAMEBUFFER, 0);
return -1; return -1;
} }
@ -635,7 +645,7 @@ namespace lunarium
mImageShader.SetSource(glShader::TYPE_FRAGMENT, OGLDefaultShaders.DefaultSpriteFragment, false); mImageShader.SetSource(glShader::TYPE_FRAGMENT, OGLDefaultShaders.DefaultSpriteFragment, false);
if (!mImageShader.BuildProgram()) 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); mShapeShader.SetSource(glShader::TYPE_FRAGMENT, OGLDefaultShaders.DefaultShapeFragment, false);
if (!mShapeShader.BuildProgram()) 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);
}
} }

@ -118,7 +118,7 @@ namespace lunarium
if (-1 == uniformLocation) if (-1 == uniformLocation)
{ {
Logger::Log(LogCategory::GRAPHICS, LogLevel::ERROR, Logger::Error(LogCategory::GRAPHICS,
"Unable to find uniform location. Uniform name: %s", uniformName); "Unable to find uniform location. Uniform name: %s", uniformName);
return false; return false;
} }
@ -139,13 +139,13 @@ namespace lunarium
int count = -1; int count = -1;
glGetProgramiv(mProgram, GL_ACTIVE_UNIFORMS, &count); 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++) for (int i = 0; i < count; i++)
{ {
glGetActiveUniform(mProgram, (GLuint)i, bufSize, &length, &size, &type, name); 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) 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); "Can not set shader source (%s) - Invalid Source Type (%d)", source, (int)sourceType);
return false; return false;
} }
@ -178,14 +178,14 @@ namespace lunarium
{ {
if (sourceType < 0 || sourceType >= TYPE_COUNT) 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); "Can not compile source - Invalid Source Type: %d", (int)sourceType);
return false; return false;
} }
if ("" == mShaders[sourceType].Source) 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]); "Can not compile %s shader source - Source is empty", TypeNames[sourceType]);
return false; return false;
} }
@ -207,7 +207,7 @@ namespace lunarium
if (!success) if (!success)
{ {
glGetShaderInfoLog(mShaders[sourceType].ID, 512, NULL, infoLog); 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); "Error compiling %s shader source: %s", TypeNames[sourceType], infoLog);
return false; return false;
} }
@ -220,7 +220,7 @@ namespace lunarium
{ {
if ("" == mShaders[TYPE_VERTEX].Source || "" == mShaders[TYPE_FRAGMENT].Source) 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!"); "Cannot create shader program - vertex and fragment shader must be set!");
return false; return false;
} }
@ -238,7 +238,7 @@ namespace lunarium
{ {
if (mShaders[i].Source == "") 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]); "Skipping compilation of %s shader source - source is empty", TypeNames[i]);
} }
else else
@ -268,7 +268,7 @@ namespace lunarium
if (!success) if (!success)
{ {
glGetProgramInfoLog(mProgram, 512, NULL, infoLog); 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); "Failed to link the shader program. Info Log: %s", infoLog);
return false; return false;
} }
@ -308,7 +308,7 @@ namespace lunarium
if (!ifs.is_open()) 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); "Failed to load shader source from file (file not found): %s", filename);
return ""; return "";
} }

@ -21,21 +21,21 @@ namespace lunarium
{ {
if (!mTextShader.IsBuilt()) 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; return -1;
} }
FT_Library ft; FT_Library ft;
if (FT_Init_FreeType(&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; return -1;
} }
FT_Face face; FT_Face face;
if (FT_New_Face(ft, fontFile, 0, &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; return -1;
} }
@ -46,21 +46,21 @@ namespace lunarium
{ {
if (!mTextShader.IsBuilt()) 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; return -1;
} }
FT_Library ft; FT_Library ft;
if (FT_Init_FreeType(&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; return -1;
} }
FT_Face face; FT_Face face;
if (FT_New_Memory_Face(ft, fontData, dataSize, 0, &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; return -1;
} }
@ -84,7 +84,7 @@ namespace lunarium
// Load character glyph // Load character glyph
if (FT_Load_Char(face, c, FT_LOAD_RENDER)) 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; continue;
} }
@ -172,13 +172,13 @@ namespace lunarium
{ {
if (!mTextShader.IsBuilt()) 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; return;
} }
if (fontID < 0 || fontID >= mFonts.size()) 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; return;
} }

@ -36,7 +36,7 @@ namespace lunarium
{ {
if (!mpWindow) 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; return mKeyEvents;
} }
@ -78,7 +78,7 @@ namespace lunarium
// Ignore key presses for unknown keys // Ignore key presses for unknown keys
if (KeyCode::KEY_UNKNOWN == key.Code) 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]); "Input Manager skipping unknown key press: idx: %d, code: %d", i, KeyCodeList[i]);
continue; continue;
} }
@ -86,7 +86,7 @@ namespace lunarium
// Key was just pressed this frame // Key was just pressed this frame
if (KEY_UP == mKeyboardState[KeyCodeList[i]]) 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; mKeyboardState[KeyCodeList[i]] = KEY_DOWN;
KeyPress kp; KeyPress kp;

@ -8,7 +8,7 @@ set(GUI_SRC
) )
add_library(gui ${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 target_include_directories(gui
PUBLIC "${PROJECT_BINARY_DIR}" PUBLIC "${PROJECT_BINARY_DIR}"

@ -85,7 +85,7 @@ namespace lunarium
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
//mbShowDemo = true; //mbShowDemo = true;
Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO, "ImGui setup"); Logger::Info(LogCategory::GRAPHICS, "ImGui setup");
mbIsInit = true; mbIsInit = true;
return OpRes::OK(); return OpRes::OK();
} }

@ -22,9 +22,25 @@ int main(int argc, char** argv)
path = lunarium::String::TrimFileNameFromPath(path); path = lunarium::String::TrimFileNameFromPath(path);
std::filesystem::current_path(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 // All log messages will go to stdout
lunarium::Logger::GetInstance()->AddListener(new lunarium::StandardListener( 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(); lunarium::Core& core = lunarium::Core::GetInstance();
core.Initialize(argc, argv); core.Initialize(argc, argv);

@ -21,7 +21,7 @@ set(EDITOR_SRC
add_library(editor ${EDITOR_SRC}) add_library(editor ${EDITOR_SRC})
target_link_libraries(editor gui utils assets) target_link_libraries(editor gui assets)
target_include_directories(editor target_include_directories(editor
PUBLIC "${PROJECT_BINARY_DIR}" PUBLIC "${PROJECT_BINARY_DIR}"

@ -169,7 +169,7 @@ namespace lunarium { namespace editor
// Make sure the tileset exists // Make sure the tileset exists
if (mTileSets.find(id) == mTileSets.end()) 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; continue;
} }

@ -28,7 +28,7 @@
using namespace lunarium::gui; using namespace lunarium::gui;
// ERROR LOG MACRO // 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 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; return false;
} }
@ -199,20 +199,20 @@ namespace editor
if (mFileBrowser.GetResult() == FileBrowser::Result::OK) if (mFileBrowser.GetResult() == FileBrowser::Result::OK)
{ {
mpPath = mFileBrowser.GetSelectedItem(); 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 // Generate new project at mpPath
OpRes result = mProject.GenerateProject(mpPath->filename().string(), mpPath->parent_path()); OpRes result = mProject.GenerateProject(mpPath->filename().string(), mpPath->parent_path());
if (Failed(result)) 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")); ((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))->SetAssetDirectory(*mpPath / std::filesystem::path("contents/assets"));
mDoNewProject = false; mDoNewProject = false;
} }
else if (mFileBrowser.GetResult() == FileBrowser::Result::CANCEL) 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; mDoNewProject = false;
} }
@ -223,7 +223,7 @@ namespace editor
if (mFileBrowser.GetResult() == FileBrowser::Result::OK) if (mFileBrowser.GetResult() == FileBrowser::Result::OK)
{ {
mpPath = mFileBrowser.GetSelectedItem(); 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 // Open project at mpPath
if (Failed(mProject.LoadProject(*mpPath).LogIfFailed(Editor::LogCat))) if (Failed(mProject.LoadProject(*mpPath).LogIfFailed(Editor::LogCat)))
@ -236,7 +236,7 @@ namespace editor
} }
else if (mFileBrowser.GetResult() == FileBrowser::Result::CANCEL) 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; mDoOpenProject = false;
} }
@ -283,7 +283,7 @@ namespace editor
if (!mFileBrowser.OpenInDirectory("")) if (!mFileBrowser.OpenInDirectory(""))
{ {
mDoNewProject = false; 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("")) if (!mFileBrowser.OpenInDirectory(""))
{ {
mDoOpenProject = false; mDoOpenProject = false;
Logger::Log(LogCat, LogLevel::ERROR, "Could not open the File Browser"); Logger::Error(LogCat, "Could not open the File Browser");
} }
} }

@ -97,7 +97,7 @@ namespace lunarium { namespace editor
return mPanels[id]; 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; return nullptr;
} }
@ -168,7 +168,7 @@ namespace lunarium { namespace editor
mDockSpaceID = ImGui::DockSpace(ImGui::GetID(dock_name.c_str()), ImVec2(0, 0), 0, &mWindowClass); mDockSpaceID = ImGui::DockSpace(ImGui::GetID(dock_name.c_str()), ImVec2(0, 0), 0, &mWindowClass);
if (!ImGui::DockBuilderGetNode(mDockSpaceID) || mResetDockSpace) 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; mResetDockSpace = false;
ImGui::DockBuilderRemoveNode(mDockSpaceID); ImGui::DockBuilderRemoveNode(mDockSpaceID);

@ -227,7 +227,7 @@ namespace lunarium { namespace editor
if (!mFileBrowser.OpenInDirectory("")) if (!mFileBrowser.OpenInDirectory(""))
{ {
mImportTileSet = false; 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) if (mFileBrowser.GetResult() == FileBrowser::Result::OK)
{ {
auto path = mFileBrowser.GetSelectedItem(); 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; uint64_t id = 0;
ContentManager::GetInstance().ImportFile(*path, /*mpEditor->GetAssetBrowserLocation() / */ path->filename(), AssetType::EATYPE_TILE_SET, id).LogIfFailed(Editor::LogCat); 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) 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; mImportTileSet = false;
} }

@ -31,19 +31,14 @@ namespace lunarium { namespace editor
{ {
if (ImGui::GetIO().MouseDown[ImGuiMouseButton_Left] && !mMouseDown) if (ImGui::GetIO().MouseDown[ImGuiMouseButton_Left] && !mMouseDown)
{ {
mMouseDown = true; mMouseDown = true;
float x = ImGui::GetMousePos().x; float x = ImGui::GetMousePos().x;
float y = ImGui::GetMousePos().y; float y = ImGui::GetMousePos().y;
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse clicked at (%f, %f)", x, y);
// Adjust for window pos // Adjust for window pos
x -= mWorkAreaPos.X; x -= mWorkAreaPos.X;
y -= mWorkAreaPos.Y; y -= mWorkAreaPos.Y;
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Pos Adjusted (%f, %f)", x, y);
// Check that it's within the window // Check that it's within the window
bool is_in_window = x >= 0.0f && x < mWorkAreaSize.X && y >= 0.0f && y < mWorkAreaSize.Y; 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; x += mScrollOffset.X;
y += mScrollOffset.Y; y += mScrollOffset.Y;
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Pos scrolled (%f, %f)", x, y);
// Find selected tile // Find selected tile
mSelectedTile.X = x / mpSelectedTileSet->GetTileSize().Width; mSelectedTile.X = x / mpSelectedTileSet->GetTileSize().Width;
mSelectedTile.Y = y / mpSelectedTileSet->GetTileSize().Height; 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 // Notify the editor that the selected tile has changed
mpEditor->ChangeSelectedTile({ mpSelectedTileSet->GetTileSetID(), mSelectedTile }); mpEditor->ChangeSelectedTile({ mpSelectedTileSet->GetTileSetID(), mSelectedTile });
@ -70,7 +61,6 @@ namespace lunarium { namespace editor
if (!ImGui::GetIO().MouseDown[ImGuiMouseButton_Left] && mMouseDown) if (!ImGui::GetIO().MouseDown[ImGuiMouseButton_Left] && mMouseDown)
{ {
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Released");
mMouseDown = false; mMouseDown = false;
} }
@ -83,8 +73,6 @@ namespace lunarium { namespace editor
mFrameBuffer = Core::Graphics().CreateRenderTexture(mpSelectedTileSet->GetImage()->GetWidth(), mpSelectedTileSet->GetImage()->GetHeight(), 4); 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(); Color prev = Core::Graphics().GetClearColor();
Core::Graphics().SetClearColor(Color::Transparent()); Core::Graphics().SetClearColor(Color::Transparent());
Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat); Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat);

@ -12,4 +12,4 @@ target_include_directories(testbed
PUBLIC ../../../external/box2d/include PUBLIC ../../../external/box2d/include
) )
target_link_libraries(testbed box2d utils dearimgui) target_link_libraries(testbed box2d dearimgui)

@ -26,7 +26,7 @@ namespace lunarium
void PhysicsScene::OnLoad() 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 // Comments from the docs: https://box2d.org/documentation/md__d_1__git_hub_box2d_docs_hello.html

@ -31,7 +31,7 @@ namespace lunarium
void SimpleRenderScene::OnLoad() void SimpleRenderScene::OnLoad()
{ {
Logger::Log(mLogCat, LogLevel::INFO, "Running Simple Render Test Scene"); Logger::Info(mLogCat, "Running Simple Render Test Scene");
mTextBoxWidth = 500; mTextBoxWidth = 500;
@ -133,11 +133,11 @@ namespace lunarium
OpRes result = Core::GetInstance().BeginRenderToTexture(mFrameBufferTwo); OpRes result = Core::GetInstance().BeginRenderToTexture(mFrameBufferTwo);
if (Failed(result)) 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; 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.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", g.DrawString("This is a test of rendering an image with transparency",
@ -158,7 +158,7 @@ namespace lunarium
OpRes result = Core::GetInstance().BeginRenderToTexture(mFrameBufferOne); OpRes result = Core::GetInstance().BeginRenderToTexture(mFrameBufferOne);
if (Failed(result)) 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; return;
} }

@ -27,12 +27,12 @@ namespace lunarium
{ {
// return OpRes::Fail("Tester::Initialize not implemented"); // return OpRes::Fail("Tester::Initialize not implemented");
mLogCat = Logger::RegisterCategory("TESTER"); mLogCat = Logger::RegisterCategory("TESTBED");
#if BUILD_NO_EDITOR #if BUILD_NO_EDITOR
Logger::Log(mLogCat, LogLevel::INFO, "NO EDITOR!"); Logger::Info(mLogCat, "NO EDITOR!");
#else #else
Logger::Log(mLogCat, LogLevel::INFO, "EDITOR DETECTED!"); Logger::Info(mLogCat, "EDITOR DETECTED!");
#endif #endif
mpScene = new SimpleRenderScene(mLogCat); mpScene = new SimpleRenderScene(mLogCat);
@ -74,7 +74,7 @@ namespace lunarium
if (Core::Input().IsKeyDown(KeyCode::MOUSE_LEFT_BUTTON, true)) 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); mpScene->OnTick(delta);
@ -88,7 +88,7 @@ namespace lunarium
void TestBed::OnKeyPress(InputManager::KeyPress kp) 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());
} }
} }

@ -56,6 +56,14 @@ namespace lunarium
void CoreAPI::Log(int level, const char* msg) 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; }
}
} }
} }

@ -56,7 +56,7 @@ namespace lunarium
if (!result.valid()) if (!result.valid())
{ {
sol::error err = result; 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; std::ostringstream oss;
oss << "LUA code has error. CODE:\n" << code << "\nEND CODE -- ERROR: " << err.what(); oss << "LUA code has error. CODE:\n" << code << "\nEND CODE -- ERROR: " << err.what();
return OpRes::Fail(oss.str().c_str()); return OpRes::Fail(oss.str().c_str());

@ -18,81 +18,6 @@
namespace lunarium 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) LogListener::LogListener(uint32_t acceptedLogLevels, uint32_t acceptedLogCategories, const char* myName)
: mAcceptedLogLevels(acceptedLogLevels), mAcceptedLogCategories(acceptedLogCategories), mMyName(myName) : mAcceptedLogLevels(acceptedLogLevels), mAcceptedLogCategories(acceptedLogCategories), mMyName(myName)
{ {
@ -211,18 +136,23 @@ namespace lunarium
{ {
mAllowRepeats = false; mAllowRepeats = false;
// Register built-in levels Logger::mLevelNames[LogLevel::FATAL_ERROR] = "FATAL ERROR";
RegisterLevel("INFO"); Logger::mLevelNames[LogLevel::ERROR] = "ERROR";
RegisterLevel("WARNING"); Logger::mLevelNames[LogLevel::WARNING] = "WARNING";
RegisterLevel("ERROR"); Logger::mLevelNames[LogLevel::INFO] = "INFO";
RegisterLevel("FATAL_ERROR"); Logger::mLevelNames[LogLevel::DEBUG] = "DEBUG";
RegisterLevel("INFO_VERBOSE"); Logger::mLevelNames[LogLevel::TRACE] = "TRACE";
RegisterLevel("OGL_DEBUG");
Logger::mLevelNames[LogLevel::GRAPHICS_INTERNAL_DEBUG] = "GRAPHICS INTERNAL DEBUG";
Logger::mLevelNames[LogLevel::GRAPHICS_INTERNAL_ERROR] = "GRAPHICS INTERNAL INFO";
RegisterCategory("CORE"); RegisterCategory("CORE");
RegisterCategory("WINDOW_CONTROLLER"); RegisterCategory("PLATFORM");
RegisterCategory("GRAPHICS"); RegisterCategory("GRAPHICS");
RegisterCategory("UTILITIES"); RegisterCategory("UTILITIES");
RegisterCategory("SCRIPTING");
RegisterCategory("UI");
RegisterCategory("GAME_SYSTEM");
} }
Logger * Logger::GetInstance() Logger * Logger::GetInstance()
@ -256,14 +186,6 @@ namespace lunarium
return id; 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) std::string Logger::GetCategoryName(uint32_t id)
{ {
if (Logger::mCategoryNames.find(id) == Logger::mCategoryNames.end()) if (Logger::mCategoryNames.find(id) == Logger::mCategoryNames.end())
@ -336,21 +258,85 @@ namespace lunarium
mBacklog.clear(); 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 // 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"); throw std::runtime_error("Log message size exceeds buffer size");
// Fill the buffer with the formatted message // 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_list args;
va_start(args, message); 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); 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) void Logger::Log_buff(uint32_t logCategory, uint32_t logLevel)

@ -29,21 +29,26 @@ namespace lunarium
namespace LogLevel namespace LogLevel
{ {
const uint16_t ANY = 0xFFFF; const uint16_t ANY = 0xFFFF;
const uint16_t INFO = 0x0001; const uint16_t FATAL_ERROR = 0x0001;
const uint16_t WARNING = 0x0002; const uint16_t ERROR = 0x0002;
const uint16_t ERROR = 0x0004; const uint16_t WARNING = 0x0004;
const uint16_t FATAL_ERROR = 0x0008; const uint16_t INFO = 0x0008;
const uint16_t INFO_VERBOSE = 0x0010; const uint16_t DEBUG = 0x0010;
const uint16_t OGL_DEBUG = 0x0020; const uint16_t TRACE = 0x0020;
const uint16_t GRAPHICS_INTERNAL_ERROR = 0x0040;
const uint16_t GRAPHICS_INTERNAL_DEBUG = 0x0080;
} }
namespace LogCategory namespace LogCategory
{ {
const uint16_t ANY = 0xFFFF; const uint16_t ANY = 0xFFFF;
const uint16_t CORE = 0x0001; const uint16_t CORE = 0x0001;
const uint16_t WINDOW_CONTROLLER = 0x0002; const uint16_t PLATFORM = 0x0002;
const uint16_t GRAPHICS = 0x0004; const uint16_t GRAPHICS = 0x0004;
const uint16_t UTILITIES = 0x0008; 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; //const uint16_t USER_PROJECT = 0x0010;
} }
@ -103,7 +108,7 @@ namespace lunarium
class ErrorListener : public LogListener class ErrorListener : public LogListener
{ {
public: 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"); uint32_t acceptedLogCategories = LogCategory::ANY, const char* myName = "ErrorListener");
bool Log(LogMessage& message); bool Log(LogMessage& message);
}; };
@ -122,7 +127,9 @@ namespace lunarium
std::ofstream& mOF; 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 void FreeInstance();
static uint32_t RegisterCategory(const char* name); static uint32_t RegisterCategory(const char* name);
static uint32_t RegisterLevel(const char* name);
static std::string GetCategoryName(uint32_t id); static std::string GetCategoryName(uint32_t id);
static std::string GetLevelName(uint32_t id); static std::string GetLevelName(uint32_t id);
LogListener* AddListener(LogListener* pl); LogListener* AddListener(LogListener* pl);
@ -157,7 +163,15 @@ namespace lunarium
// The message argument and the variable argument list work just like // The message argument and the variable argument list work just like
// printf. Use the same formatters as printf when calling this function. // printf. Use the same formatters as printf when calling this function.
// Messages must be shorter than 1024 bytes. // 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); void Log_buff(uint32_t logCategory, uint32_t logLevel);
const std::vector<LogMessage>& GetBacklog() const; const std::vector<LogMessage>& GetBacklog() const;
@ -170,7 +184,7 @@ namespace lunarium
static std::map<uint32_t, std::string> mCategoryNames; static std::map<uint32_t, std::string> mCategoryNames;
std::list<LogListener*> mListeners; std::list<LogListener*> mListeners;
std::vector<LogMessage> mBacklog; std::vector<LogMessage> mBacklog;
char mBuffer[BUFFER_SIZE]; char mBuffer[LLOG_BUFFER_SIZE];
HighResTimer mTimer; HighResTimer mTimer;
bool mAllowRepeats; bool mAllowRepeats;

@ -51,7 +51,7 @@ namespace lunarium
msg = prepend_msg; msg = prepend_msg;
} }
msg += Description; msg += Description;
Logger::Log(category, LogLevel::ERROR, msg.c_str()); Logger::Error(category, msg.c_str());
} }
return *this; return *this;
} }

@ -53,7 +53,7 @@ namespace lunarium
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_MAJOR_VERSION); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_MAJOR_VERSION);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_MINOR_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", "Creating OpenGL Context version %d, %d and glsl %s",
OPENGL_MAJOR_VERSION, OPENGL_MINOR_VERSION, System::GetGLSLVersionString().c_str()); OPENGL_MAJOR_VERSION, OPENGL_MINOR_VERSION, System::GetGLSLVersionString().c_str());
@ -86,7 +86,7 @@ namespace lunarium
// Use glad2 to load extensions // Use glad2 to load extensions
int version = gladLoadGL(glfwGetProcAddress); 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)); "Glad2 Loaded version: %d.%d", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
} }
else else

Loading…
Cancel
Save