Fixed Bugs
This commit is contained in:
parent
ccb4100814
commit
b36e6dfc6a
36
imgui.ini
36
imgui.ini
@ -10,24 +10,24 @@ Collapsed=1
|
||||
|
||||
[Window][WindowOverViewport_11111111]
|
||||
Pos=0,19
|
||||
Size=1920,1158
|
||||
Size=1280,701
|
||||
Collapsed=0
|
||||
|
||||
[Window][Inspector]
|
||||
Pos=1553,19
|
||||
Size=367,659
|
||||
Pos=913,19
|
||||
Size=367,202
|
||||
Collapsed=0
|
||||
DockId=0x00000018,0
|
||||
|
||||
[Window][Scene Tree]
|
||||
Pos=0,19
|
||||
Size=341,579
|
||||
Size=341,350
|
||||
Collapsed=0
|
||||
DockId=0x0000000F,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=343,19
|
||||
Size=1208,659
|
||||
Size=568,202
|
||||
Collapsed=0
|
||||
DockId=0x00000017,0
|
||||
|
||||
@ -36,14 +36,14 @@ Size=1280,19
|
||||
Collapsed=0
|
||||
|
||||
[Window][Performance Info]
|
||||
Pos=1628,680
|
||||
Size=292,268
|
||||
Pos=1107,223
|
||||
Size=173,268
|
||||
Collapsed=0
|
||||
DockId=0x00000019,0
|
||||
|
||||
[Window][Console]
|
||||
Pos=343,680
|
||||
Size=927,497
|
||||
Pos=343,223
|
||||
Size=549,497
|
||||
Collapsed=0
|
||||
DockId=0x0000001B,0
|
||||
|
||||
@ -78,8 +78,8 @@ Collapsed=0
|
||||
DockId=0x00000015,1
|
||||
|
||||
[Window][Color Correction]
|
||||
Pos=1628,950
|
||||
Size=292,227
|
||||
Pos=1107,493
|
||||
Size=173,227
|
||||
Collapsed=0
|
||||
DockId=0x0000001A,0
|
||||
|
||||
@ -113,8 +113,8 @@ Collapsed=0
|
||||
DockId=0x0000000E,0
|
||||
|
||||
[Window][Audio Output]
|
||||
Pos=1577,680
|
||||
Size=49,497
|
||||
Pos=1076,223
|
||||
Size=29,497
|
||||
Collapsed=0
|
||||
DockId=0x00000012,0
|
||||
|
||||
@ -125,8 +125,8 @@ Collapsed=0
|
||||
DockId=0x0000000D,0
|
||||
|
||||
[Window][Resources]
|
||||
Pos=0,600
|
||||
Size=341,577
|
||||
Pos=0,371
|
||||
Size=341,349
|
||||
Collapsed=0
|
||||
DockId=0x00000010,0
|
||||
|
||||
@ -136,8 +136,8 @@ Size=550,695
|
||||
Collapsed=0
|
||||
|
||||
[Window][Lua Globals]
|
||||
Pos=1272,680
|
||||
Size=303,497
|
||||
Pos=894,223
|
||||
Size=180,497
|
||||
Collapsed=0
|
||||
DockId=0x0000001C,0
|
||||
|
||||
@ -163,7 +163,7 @@ Column 0 Weight=1.0000
|
||||
Column 1 Width=120
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1920,1158 Split=X
|
||||
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 Split=X
|
||||
DockNode ID=0x00000005 Parent=0x11111111 SizeRef=989,1158 Split=X
|
||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=341,701 Split=Y Selected=0x12EF0F59
|
||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=342,637 Split=Y Selected=0x12EF0F59
|
||||
|
@ -1,3 +0,0 @@
|
||||
[COMPILE] g++ -std=c++20 -Wall -g -DGLM_ENABLE_EXPERIMENTAL -O2 -static -static-libstdc++ -static-libgcc -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -Isrc/vendor/xxhash -Isrc/vendor/miniaudio -Isrc/vendor/imguizmo -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\Engine.cpp -o src\build\Engine.o
|
||||
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\AnimationComponent.o src\build\Components\AudioPlayerComponent.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\ParticleComponent.o src\build\Components\PathFollowerComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\core\audio\AudioEngine.o src\build\core\functions\Prefab.o src\build\core\functions\ScenePacker.o src\build\core\scripts\LuaGlobalBridge.o src\build\core\scripts\ScriptCore.o src\build\core\utils\AssetManager.o src\build\core\utils\EngineConfig.o src\build\core\utils\ExceptionHandler.o src\build\core\utils\FileDialog.o src\build\core\utils\input.o src\build\core\utils\LoadingWindow.o src\build\core\utils\Logging.o src\build\core\utils\Popup.o src\build\core\utils\Profiler.o src\build\core\utils\Texture.o src\build\core\utils\utils.o src\build\editor\utils\Themes.o src\build\editor\windows\AssetBrowser.o src\build\editor\windows\AudioInfo.o src\build\editor\windows\Inspector.o src\build\editor\windows\LuaGlobals.o src\build\Entitys\Object.o src\build\utils\GameObjectsList.o src\build\utils\Shader.o src\build\utils\UID.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o src\build\xxhash.o src\build\miniaudio.o src\build\ImGuizmo.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto -ldbghelp -lz -lfreetype
|
||||
[ERROR] Interrupted by user.
|
@ -2,33 +2,23 @@ local obj = nil
|
||||
local light = nil
|
||||
local hue = 0.0
|
||||
|
||||
function HSVtoRGB(h, s, v)
|
||||
local i = math.floor(h * 6)
|
||||
local f = h * 6 - i
|
||||
local p = v * (1 - s)
|
||||
local q = v * (1 - f * s)
|
||||
local t = v * (1 - (1 - f) * s)
|
||||
i = i % 6
|
||||
|
||||
if i == 0 then return Vector3(v, t, p) end
|
||||
if i == 1 then return Vector3(q, v, p) end
|
||||
if i == 2 then return Vector3(p, v, t) end
|
||||
if i == 3 then return Vector3(p, q, v) end
|
||||
if i == 4 then return Vector3(t, p, v) end
|
||||
if i == 5 then return Vector3(v, p, q) end
|
||||
end
|
||||
|
||||
|
||||
function OnInit()
|
||||
obj = Engine.GetObjectByTag("Light")
|
||||
if obj then
|
||||
light = obj:GetComponent("LightComponent")
|
||||
end
|
||||
|
||||
for i = 1, 5 do
|
||||
local num = math.random(10000, 10000000)
|
||||
Engine.Log(Engine.Utils.ShortNumberFormat(num, 2), 2)
|
||||
end
|
||||
end
|
||||
|
||||
function OnUpdate(dt)
|
||||
if not light then return end
|
||||
|
||||
hue = (hue + dt * 0.2) % 1.0
|
||||
light:SetColor(HSVtoRGB(hue, 1.0, 1.0))
|
||||
|
||||
local rgb = Engine.Utils.HSVtoRGB(hue * 360.0, 1.0, 1.0)
|
||||
light:SetColor(rgb)
|
||||
end
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,6 +23,9 @@
|
||||
#include "../core/scripts/LuaGlobalBridge.h"
|
||||
#include "../core/scripts/ScriptCore.h"
|
||||
|
||||
|
||||
void PushVector3(lua_State* L, float x, float y, float z);
|
||||
|
||||
static int Lua_SetGlobal(lua_State *L)
|
||||
{
|
||||
const char *key = luaL_checkstring(L, 1);
|
||||
@ -636,6 +639,113 @@ static int Lua_Animation_Index(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_ShortNumberFormat(lua_State *L)
|
||||
{
|
||||
double num = 0.0;
|
||||
if (lua_isnumber(L, 1))
|
||||
num = lua_tonumber(L, 1);
|
||||
else if (lua_isstring(L, 1))
|
||||
num = std::strtod(lua_tostring(L, 1), nullptr);
|
||||
else
|
||||
return luaL_error(L, "Expected number or string as first argument");
|
||||
|
||||
int precision = 0;
|
||||
if (lua_gettop(L) >= 2 && lua_isnumber(L, 2))
|
||||
{
|
||||
precision = (int)lua_tointeger(L, 2);
|
||||
if (precision < 0)
|
||||
precision = 0;
|
||||
if (precision > 9)
|
||||
precision = 9;
|
||||
}
|
||||
|
||||
bool negative = false;
|
||||
if (num < 0)
|
||||
{
|
||||
negative = true;
|
||||
num = -num;
|
||||
}
|
||||
|
||||
static const char *suffixes[] = {"", "k", "M", "B", "T", "Q", "E", "Z", "Y"};
|
||||
int suffixIndex = 0;
|
||||
while (num >= 1000.0 && suffixIndex < 8)
|
||||
{
|
||||
num /= 1000.0;
|
||||
++suffixIndex;
|
||||
}
|
||||
|
||||
char fmt[16];
|
||||
std::snprintf(fmt, sizeof(fmt), "%%s%%.%df%%s", precision);
|
||||
|
||||
char out[64];
|
||||
std::snprintf(out, sizeof(out), fmt, negative ? "-" : "", num, suffixes[suffixIndex]);
|
||||
|
||||
lua_pushstring(L, out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_HSVtoRGB(lua_State *L)
|
||||
{
|
||||
float h = luaL_checknumber(L, 1);
|
||||
float s = luaL_checknumber(L, 2);
|
||||
float v = luaL_checknumber(L, 3);
|
||||
|
||||
float c = v * s;
|
||||
float x = c * (1 - std::fabs(fmod(h / 60.0f, 2) - 1));
|
||||
float m = v - c;
|
||||
float r = 0, g = 0, b = 0;
|
||||
|
||||
if (h < 60) { r = c; g = x; }
|
||||
else if (h < 120) { r = x; g = c; }
|
||||
else if (h < 180) { g = c; b = x; }
|
||||
else if (h < 240) { g = x; b = c; }
|
||||
else if (h < 300) { r = x; b = c; }
|
||||
else { r = c; b = x; }
|
||||
|
||||
PushVector3(L, r + m, g + m, b + m);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_RGBtoHSV(lua_State *L)
|
||||
{
|
||||
float r = luaL_checknumber(L, 1);
|
||||
float g = luaL_checknumber(L, 2);
|
||||
float b = luaL_checknumber(L, 3);
|
||||
|
||||
float max = std::fmax(r, std::fmax(g, b));
|
||||
float min = std::fmin(r, std::fmin(g, b));
|
||||
float d = max - min;
|
||||
|
||||
float h = 0.0f;
|
||||
if (d != 0)
|
||||
{
|
||||
if (max == r) h = fmod((g - b) / d, 6.0f);
|
||||
else if (max == g) h = ((b - r) / d) + 2.0f;
|
||||
else h = ((r - g) / d) + 4.0f;
|
||||
h *= 60.0f;
|
||||
if (h < 0) h += 360.0f;
|
||||
}
|
||||
|
||||
float s = (max == 0) ? 0 : d / max;
|
||||
float v = max;
|
||||
|
||||
PushVector3(L, h, s, v);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void RegisterUtils(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
lua_pushcfunction(L, l_ShortNumberFormat);
|
||||
lua_setfield(L, -2, "ShortNumberFormat");
|
||||
lua_pushcfunction(L, l_HSVtoRGB);
|
||||
lua_setfield(L, -2, "HSVtoRGB");
|
||||
lua_pushcfunction(L, l_RGBtoHSV);
|
||||
lua_setfield(L, -2, "RGBtoHSV");
|
||||
lua_setfield(L, -2, "Utils"); // Engine.Utils
|
||||
}
|
||||
|
||||
static int keycode_loader(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
@ -830,6 +940,17 @@ static core::types::Vec3 GetLuaVector3(lua_State *L, int index)
|
||||
return core::types::Vec3(0, 0, 0);
|
||||
}
|
||||
|
||||
void PushVector3(lua_State* L, float x, float y, float z)
|
||||
{
|
||||
LuaVector3* vec = (LuaVector3*)lua_newuserdata(L, sizeof(LuaVector3));
|
||||
vec->x = x;
|
||||
vec->y = y;
|
||||
vec->z = z;
|
||||
luaL_setmetatable(L, LUA_VECTOR3_MT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int Lua_Vector3_New(lua_State *L)
|
||||
{
|
||||
PROFILE_DEEP_SCOPE("Vector3()");
|
||||
@ -988,6 +1109,8 @@ void ScriptComponent::RegisterEngineBindings()
|
||||
lua_newtable(L);
|
||||
lua_pushcfunction(L, Lua_LogInfo);
|
||||
lua_setfield(L, -2, "LogInfo");
|
||||
lua_pushcfunction(L, Lua_LogInfo);
|
||||
lua_setfield(L, -2, "Log");
|
||||
lua_pushcfunction(L, Lua_LogError);
|
||||
lua_setfield(L, -2, "LogError");
|
||||
lua_pushcfunction(L, Lua_LogDebug);
|
||||
@ -1007,6 +1130,8 @@ void ScriptComponent::RegisterEngineBindings()
|
||||
lua_pushcfunction(L, Lua_GetGlobal);
|
||||
lua_setfield(L, -2, "GetGlobal");
|
||||
|
||||
RegisterUtils(L); // called here so its under Engine table
|
||||
|
||||
lua_setglobal(L, "Engine");
|
||||
}
|
||||
|
||||
@ -1026,7 +1151,7 @@ void ScriptComponent::ReloadScript()
|
||||
luaL_openlibs(L);
|
||||
lua_sethook(L, Hook, LUA_MASKCALL | LUA_MASKRET, 0);
|
||||
|
||||
ScriptCore::RegisterState(L, scriptPath, GetFilenameNoExtension(scriptPath));
|
||||
ScriptCore::RegisterState(L, scriptPath, GetFilenameNoExtension(scriptPath), this);
|
||||
|
||||
RegisterObjectType(L);
|
||||
RegisterVector2Type(L);
|
||||
|
@ -585,6 +585,8 @@ void Engine::Init()
|
||||
|
||||
Input::Init(window);
|
||||
|
||||
ScriptCore::Init();
|
||||
|
||||
// AssetManager::LoadAssetAsync("C:\\Users\\spenc\\Music\\creative-technology-showreel-241274.mp3", AssetType::Audio);
|
||||
|
||||
Logger::LogVerbose("Resverving Objects");
|
||||
|
@ -2,26 +2,34 @@
|
||||
#include "../../core/utils/Logging.h"
|
||||
#include "../../core/utils/ExceptionHandler.h"
|
||||
#include "../../core/utils/Profiler.h"
|
||||
#include "../../Components/ScriptComponent.h"
|
||||
|
||||
void ScriptCore::Init()
|
||||
{
|
||||
s_LuaStates.clear();
|
||||
s_LuaStates.reserve(5);
|
||||
Logger::LogOk("Script Core");
|
||||
}
|
||||
|
||||
void ScriptCore::RegisterState(lua_State* L, const std::string& scriptPath, const std::string& name)
|
||||
void ScriptCore::RegisterState(lua_State* L,
|
||||
const std::string& scriptPath,
|
||||
const std::string& name,
|
||||
ScriptComponent* component)
|
||||
{
|
||||
s_LuaStates.push_back({ L, scriptPath, name });
|
||||
Logger::LogVerbose("[ScriptCore] Registered Script Instace '%s'", name.c_str());
|
||||
s_LuaStates.push_back({ L, scriptPath, name, component });
|
||||
|
||||
|
||||
|
||||
Logger::LogVerbose("[ScriptCore] Registered Script Instance '%s'", name.c_str());
|
||||
}
|
||||
|
||||
void ScriptCore::UnregisterState(lua_State* L)
|
||||
{
|
||||
auto it = std::remove_if(s_LuaStates.begin(), s_LuaStates.end(),
|
||||
[L](const LuaScript& script) {
|
||||
return script.L == L;
|
||||
});
|
||||
[L](const LuaScript& script)
|
||||
{
|
||||
return script.L == L;
|
||||
});
|
||||
|
||||
if (it != s_LuaStates.end())
|
||||
{
|
||||
@ -34,16 +42,17 @@ void ScriptCore::UnregisterState(lua_State* L)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScriptCore::CallAllInits()
|
||||
{
|
||||
for (auto& script : s_LuaStates)
|
||||
{
|
||||
PROFILE_DEEP_SCOPE("ScriptCore::OnInit");
|
||||
|
||||
if (!script.L)
|
||||
if (!script.L || !script.component)
|
||||
continue;
|
||||
|
||||
script.component->ReloadScript();
|
||||
|
||||
lua_getglobal(script.L, "OnInit");
|
||||
if (lua_isfunction(script.L, -1))
|
||||
{
|
||||
@ -59,12 +68,14 @@ void ScriptCore::CallAllInits()
|
||||
lua_pop(script.L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ScriptCore::CallAllUpdates(float dt)
|
||||
{
|
||||
PROFILE_DEEP_SCOPE("ScriptCore::OnUpdate");
|
||||
|
||||
|
||||
for (auto& script : s_LuaStates)
|
||||
{
|
||||
PROFILE_SCOPE("Script: " + script.name);
|
||||
@ -89,3 +100,28 @@ void ScriptCore::CallAllUpdates(float dt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptCore::ReloadAllScripts()
|
||||
{
|
||||
Logger::LogVerbose("[ScriptCore] Reloading all Lua scripts...");
|
||||
for (auto& script : s_LuaStates)
|
||||
{
|
||||
if (script.component)
|
||||
{
|
||||
script.component->ReloadScript();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptCore::PrintScriptDiagnostics()
|
||||
{
|
||||
Logger::LogVerbose("[ScriptCore] Registered Scripts: %zu", s_LuaStates.size());
|
||||
for (const auto& script : s_LuaStates)
|
||||
{
|
||||
Logger::LogVerbose(" - Name: %s | Path: %s | Lua: %p | Component: %p",
|
||||
script.name.c_str(),
|
||||
script.scriptPath.c_str(),
|
||||
(void*)script.L,
|
||||
(void*)script.component);
|
||||
}
|
||||
}
|
||||
|
@ -3,23 +3,33 @@
|
||||
#include <string>
|
||||
#include <lua.hpp>
|
||||
|
||||
class ScriptComponent;
|
||||
|
||||
class ScriptCore
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void RegisterState(lua_State* L, const std::string& scriptPath, const std::string& name);
|
||||
|
||||
static void RegisterState(lua_State* L,
|
||||
const std::string& scriptPath,
|
||||
const std::string& name,
|
||||
ScriptComponent* component);
|
||||
|
||||
static void UnregisterState(lua_State* L);
|
||||
|
||||
static void CallAllInits();
|
||||
static void CallAllUpdates(float dt);
|
||||
|
||||
static void ReloadAllScripts();
|
||||
static void PrintScriptDiagnostics();
|
||||
|
||||
private:
|
||||
struct LuaScript
|
||||
{
|
||||
lua_State* L;
|
||||
std::string scriptPath;
|
||||
std::string name;
|
||||
|
||||
ScriptComponent* component;
|
||||
};
|
||||
|
||||
static inline std::vector<LuaScript> s_LuaStates;
|
||||
|
@ -457,13 +457,13 @@ void AssetManager::LoadFontInternal(const std::string& path, uint64_t uaid)
|
||||
|
||||
FT_Library ft;
|
||||
if (FT_Init_FreeType(&ft)) {
|
||||
std::cerr << "[AssetManager] Could not init FreeType\n";
|
||||
Logger::LogError("[AssetManager] Could not init FreeType\n");
|
||||
return;
|
||||
}
|
||||
|
||||
FT_Face face;
|
||||
if (FT_New_Face(ft, path.c_str(), 0, &face)) {
|
||||
std::cerr << "[AssetManager] Failed to load font: " << path << "\n";
|
||||
Logger::LogError("[AssetManager] Failed to load font: '%s'\n", path.c_str());
|
||||
FT_Done_FreeType(ft);
|
||||
return;
|
||||
}
|
||||
@ -711,6 +711,7 @@ void PrefabAssetInfo::Save(YAML::Emitter &out) const
|
||||
catch (const YAML::Exception &e)
|
||||
{
|
||||
Logger::LogError("[PrefabAssetInfo] Failed to parse prefabRoot YAML for saving: %s", e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
out << parsedInner;
|
||||
|
@ -12,7 +12,7 @@
|
||||
//! Macro Fuckery my Gz
|
||||
|
||||
EngineConfig g_engineConfig{
|
||||
.version = "0.8.4",
|
||||
.version = "0.10.3",
|
||||
.gl_version = "430",
|
||||
.gl_maxLight = 512,
|
||||
.settings = UserSettings{}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
#include "utils.h"
|
||||
// Logger.cpp or a logger helper header
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
@ -49,6 +49,7 @@ bool Logger::s_ShowWarning = true;
|
||||
bool Logger::s_ShowError = true;
|
||||
bool Logger::s_ShowDebug = false;
|
||||
bool Logger::s_ShowVerbose = false;
|
||||
bool Logger::s_PrintToTerminal = false;
|
||||
|
||||
const char *Logger::ToString(Level level)
|
||||
{
|
||||
@ -102,6 +103,7 @@ void Logger::Log(Level level, const char *fmt, ...)
|
||||
|
||||
void Logger::LogVA(Level level, const char *fmt, va_list args)
|
||||
{
|
||||
static bool has_Terminal = HasTerminal();
|
||||
char buffer[1024];
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||
s_Messages.push_back({buffer, level});
|
||||
@ -111,7 +113,10 @@ void Logger::LogVA(Level level, const char *fmt, va_list args)
|
||||
|
||||
std::string formatted = std::string("[Logger][") + levelStr + "] " + buffer;
|
||||
|
||||
std::cout << ansiColor << formatted << "\033[0m\n";
|
||||
if (s_PrintToTerminal && has_Terminal)
|
||||
{
|
||||
std::cout << ansiColor << formatted << "\033[0m\n";
|
||||
}
|
||||
|
||||
ScopedLogFileWriter logFile;
|
||||
auto &out = logFile.Get();
|
||||
@ -257,6 +262,9 @@ void Logger::Draw(const char *title)
|
||||
Clear();
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Auto-scroll", &s_AutoScroll);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("PrintLogs", &s_PrintToTerminal);
|
||||
ImGui::Separator();
|
||||
|
||||
// New Ok checkbox
|
||||
|
@ -58,6 +58,7 @@ private:
|
||||
static bool s_ShowError;
|
||||
static bool s_ShowDebug;
|
||||
static bool s_ShowVerbose;
|
||||
static bool s_PrintToTerminal;
|
||||
|
||||
static const char *ToString(Level level);
|
||||
static const char *GetAnsiColor(Level level);
|
||||
|
@ -21,6 +21,24 @@
|
||||
|
||||
#include "AssetManager.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <io.h>
|
||||
#define ISATTY _isatty
|
||||
#define FILENO _fileno
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define ISATTY isatty
|
||||
#define FILENO fileno
|
||||
#endif
|
||||
|
||||
static bool HasTerminal()
|
||||
{
|
||||
return ISATTY(FILENO(stdout)) != 0;
|
||||
}
|
||||
|
||||
|
||||
struct ImageCacheEntry {
|
||||
unsigned int textureID;
|
||||
glm::vec2 size;
|
||||
|
Loading…
Reference in New Issue
Block a user