diff --git a/src/app/editor/panels/foldhaus_panel_hierarchy.h b/src/app/editor/panels/foldhaus_panel_hierarchy.h index 7e616b2..8731660 100644 --- a/src/app/editor/panels/foldhaus_panel_hierarchy.h +++ b/src/app/editor/panels/foldhaus_panel_hierarchy.h @@ -30,7 +30,7 @@ PANEL_MODAL_OVERRIDE_CALLBACK(LoadAssemblyCallback) file_view_state* FileViewState = Panel_GetStateStruct(ReturningFrom, file_view_state); gs_file_info FileInfo = FileViewState->SelectedFile; - LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, FileInfo.Path, &State->GlobalLog); + LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, FileInfo.Path, GlobalLogBuffer); } GSMetaTag(panel_render); diff --git a/src/app/editor/panels/foldhaus_panel_message_log.h b/src/app/editor/panels/foldhaus_panel_message_log.h index dbabc5c..76d7d59 100644 --- a/src/app/editor/panels/foldhaus_panel_message_log.h +++ b/src/app/editor/panels/foldhaus_panel_message_log.h @@ -26,9 +26,9 @@ MessageLog_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* Render ui_interface* Interface = &State->Interface; ui_widget* Layout = ui_PushLayout(Interface, PanelBounds, LayoutDirection_TopDown, MakeString("Message Log Layout")); - ui_BeginList(Interface, MakeString("Message Log List"), 10, State->GlobalLog.EntriesCount); + ui_BeginList(Interface, MakeString("Message Log List"), 10, GlobalLogBuffer->EntriesCount); - log_buffer_iter Iter = Log_GetIter(&State->GlobalLog); + log_buffer_iter Iter = Log_GetIter(GlobalLogBuffer); while (true) { log_entry* At = Iter.At; diff --git a/src/app/engine/foldhaus_log.h b/src/app/engine/foldhaus_log.h index a369e13..8472701 100644 --- a/src/app/engine/foldhaus_log.h +++ b/src/app/engine/foldhaus_log.h @@ -67,24 +67,29 @@ Log_TakeNextEntry(log_buffer* Log) return Result; } +internal void +Log_PrintFVarArgs(log_buffer* Log, log_entry_type Type, char* Format, va_list Args) +{ + log_entry* NextEntry = Log_TakeNextEntry(Log); + NextEntry->String.Length = 0; + NextEntry->Type = Type; + PrintFArgsList(&NextEntry->String, Format, Args); + NullTerminate(&NextEntry->String); + +#if DEBUG + OutputDebugStringA(NextEntry->String.Str); +#endif +} + #define Log_Message(log, fmt, ...) Log_PrintF(log, LogEntry_Message, fmt, __VA_ARGS__) #define Log_Error(log, fmt, ...) Log_PrintF(log, LogEntry_Error, fmt, __VA_ARGS__) internal void Log_PrintF(log_buffer* Log, log_entry_type Type, char* Format, ...) { - log_entry* NextEntry = Log_TakeNextEntry(Log); - va_list Args; va_start(Args, Format); - NextEntry->String.Length = 0; - NextEntry->Type = Type; - PrintFArgsList(&NextEntry->String, Format, Args); - NullTerminate(&NextEntry->String); + Log_PrintFVarArgs(Log, Type, Format, Args); va_end(Args); - -#if DEBUG - OutputDebugStringA(NextEntry->String.Str); -#endif } internal log_buffer_iter diff --git a/src/app/foldhaus_app.cpp b/src/app/foldhaus_app.cpp index 652a0ac..89bf4fe 100644 --- a/src/app/foldhaus_app.cpp +++ b/src/app/foldhaus_app.cpp @@ -11,10 +11,10 @@ RELOAD_STATIC_DATA(ReloadStaticData) { GlobalDebugServices = DebugServices; + GlobalLogBuffer = LogBuffer; if (AppReady) { app_state* State = (app_state*)Context.MemoryBase; - GlobalLogBuffer = &State->GlobalLog; State->PanelSystem.PanelDefs = GlobalPanelDefs; State->PanelSystem.PanelDefsCount = GlobalPanelDefsCount; @@ -39,8 +39,6 @@ INITIALIZE_APPLICATION(InitializeApplication) State->Transient = Context->ThreadContext.Transient; State->Assemblies = AssemblyArray_Create(8, &State->Permanent); - State->GlobalLog = Log_Init(Context->ThreadContext.Allocator, 32); - State->CommandQueue = CommandQueue_Create(&State->Permanent, 32); animation_system_desc AnimSysDesc = {}; @@ -78,7 +76,7 @@ INITIALIZE_APPLICATION(InitializeApplication) State->Modes = OperationModeSystemInit(&State->Permanent, Context->ThreadContext); - ReloadStaticData(*Context, GlobalDebugServices, true); + ReloadStaticData(*Context, GlobalDebugServices, GlobalLogBuffer, true); US_CustomInit(&State->UserSpaceDesc, State, *Context); if (!Context->Headless) diff --git a/src/app/foldhaus_app.h b/src/app/foldhaus_app.h index 28227b7..4241794 100644 --- a/src/app/foldhaus_app.h +++ b/src/app/foldhaus_app.h @@ -60,7 +60,6 @@ struct app_state assembly_array Assemblies; assembly_debug_state AssemblyDebugState; animation_system AnimationSystem; - log_buffer GlobalLog; animation_pattern_array Patterns; // Interface @@ -92,7 +91,7 @@ LoadAssembly(gs_const_string Path, app_state* State, context Context) State->Transient, Context, Path, - &State->GlobalLog); + GlobalLogBuffer); } #include "engine/user_space.cpp" diff --git a/src/app/foldhaus_platform.h b/src/app/foldhaus_platform.h index adbc19a..0f80d4d 100644 --- a/src/app/foldhaus_platform.h +++ b/src/app/foldhaus_platform.h @@ -77,7 +77,7 @@ typedef INITIALIZE_APPLICATION(initialize_application); #define UPDATE_AND_RENDER(name) void name(context* Context, input_queue InputQueue, render_command_buffer* RenderBuffer, addressed_data_buffer_list* OutputData) typedef UPDATE_AND_RENDER(update_and_render); -#define RELOAD_STATIC_DATA(name) void name(context Context, debug_services* DebugServices, bool AppReady) +#define RELOAD_STATIC_DATA(name) void name(context Context, debug_services* DebugServices, log_buffer* LogBuffer, bool AppReady) typedef RELOAD_STATIC_DATA(reload_static_data); #define CLEANUP_APPLICATION(name) void name(context Context, addressed_data_buffer_list* OutputData) diff --git a/src/app/platform_win32/win32_foldhaus.cpp b/src/app/platform_win32/win32_foldhaus.cpp index 1e25934..bb3edde 100644 --- a/src/app/platform_win32/win32_foldhaus.cpp +++ b/src/app/platform_win32/win32_foldhaus.cpp @@ -332,8 +332,7 @@ DebugPrint (char* Format, ...) gs_string StringBuffer = MakeString(Buffer, 256); va_list Args; va_start(Args, Format); - PrintF(&StringBuffer, Format, Args); - OutputDebugStringA(Buffer); + Log_PrintFVarArgs(GlobalLogBuffer, LogEntry_Message, Format, Args); va_end(Args); } @@ -421,7 +420,7 @@ ReloadAndLinkDLL(win32_dll_refresh* DLL, context* Context, gs_work_queue* WorkQu if (HotLoadDLL(DLL)) { SetApplicationLinks(Context, *DLL, WorkQueue); - Context->ReloadStaticData(*Context, GlobalDebugServices, AppReady); + Context->ReloadStaticData(*Context, GlobalDebugServices, GlobalLogBuffer, AppReady); Success = true; Log_Message(GlobalLogBuffer, "Reloaded DLL\n"); } @@ -586,6 +585,8 @@ WinMain ( ) { gs_thread_context ThreadContext = Win32CreateThreadContext(); + GlobalLogBuffer = AllocatorAllocStruct(ThreadContext.Allocator, log_buffer); + *GlobalLogBuffer = Log_Init(ThreadContext.Allocator, 32); gs_allocator_debug AllocDebug = {}; AllocDebug.AllocationsCountMax = 4096; diff --git a/src/app/platform_win32/win32_foldhaus_utils.h b/src/app/platform_win32/win32_foldhaus_utils.h index 5392c9f..dc71929 100644 --- a/src/app/platform_win32/win32_foldhaus_utils.h +++ b/src/app/platform_win32/win32_foldhaus_utils.h @@ -54,8 +54,7 @@ PrintLastError_(char* File, u32 Line) char DebugStringData[256]; gs_string DebugString = MakeString(DebugStringData, 0, 256); u32 Error = GetLastError(); - PrintF(&DebugString, "%s Line %d: Win32 Error %d\n\0", File, Line, Error); - OutputDebugStringA(DebugString.Str); + Log_Error(GlobalLogBuffer, "%s Line %d: Win32 Error %d\n\0", File, Line, Error); } diff --git a/src/app/platform_win32/win32_foldhaus_work_queue.h b/src/app/platform_win32/win32_foldhaus_work_queue.h index 5f9ce27..f35259e 100644 --- a/src/app/platform_win32/win32_foldhaus_work_queue.h +++ b/src/app/platform_win32/win32_foldhaus_work_queue.h @@ -71,9 +71,7 @@ PUSH_WORK_ON_QUEUE(Win32PushWorkOnQueue) gs_string DebugString = MakeString((char*)malloc(256), 256); for (u32 i = 0; i < Queue->JobsCount; i++) { - PrintF(&DebugString, "%d %s\n", i, Queue->Jobs[i].JobName); - NullTerminate(&DebugString); - OutputDebugStringA(DebugString.Str); + Log_Message(GlobalLogBuffer, "%d %s \n", i, Queue->Jobs[i].JobName); } } #endif diff --git a/src/sculpture_gen/gen_blumen_lumen.cpp b/src/sculpture_gen/gen_blumen_lumen.cpp index a93f79d..d7f4cb6 100644 --- a/src/sculpture_gen/gen_blumen_lumen.cpp +++ b/src/sculpture_gen/gen_blumen_lumen.cpp @@ -10,6 +10,9 @@ #include "../gs_libs/gs_types.h" #include "../gs_libs/gs_types.cpp" +#include "../app/engine/foldhaus_log.h" +global log_buffer* GlobalLogBuffer; + #include "../app/platform_win32/win32_foldhaus_utils.h" #include "../app/platform_win32/win32_foldhaus_memory.h" #include "../app/platform_win32/win32_foldhaus_fileio.h" @@ -174,6 +177,8 @@ FlowerStripToChannel(u8 Flower, u8 Channel) int main(int ArgCount, char** Args) { gs_thread_context Ctx = Win32CreateThreadContext(); + GlobalLogBuffer = AllocatorAllocStruct(Ctx.Allocator, log_buffer); + *GlobalLogBuffer = Log_Init(Ctx.Allocator, 32); gs_string OutputBuffer0 = PushString(Ctx.Transient, MB(4)); gs_string OutputBuffer1 = PushString(Ctx.Transient, MB(4)); diff --git a/src/serial_monitor/first.cpp b/src/serial_monitor/first.cpp index 4ef8ccc..d2e47b0 100644 --- a/src/serial_monitor/first.cpp +++ b/src/serial_monitor/first.cpp @@ -6,13 +6,16 @@ #ifndef FIRST_CPP +#include +#include + #include "../gs_libs/gs_types.h" #include "../gs_libs/gs_types.cpp" +#include "../app/engine/foldhaus_log.h" +global log_buffer* GlobalLogBuffer; #define DEBUG_TRACK_FUNCTION -#include -#include //#include "../app/foldhaus_platform.h" //#include "../gs_libs/gs_win32.cpp" @@ -92,6 +95,8 @@ CreateMessage(gs_data* Data, u8 Count) int main(int ArgCount, char** Args) { gs_thread_context Ctx = Win32CreateThreadContext(); + GlobalLogBuffer = AllocatorAllocStruct(Ctx.Allocator, log_buffer); + *GlobalLogBuffer = Log_Init(Ctx.Allocator, 32); HANDLE SerialHandle = Win32SerialPort_Open("\\\\.\\COM9", Ctx.Transient); Win32SerialPort_SetState(SerialHandle, 2000000, 8, 0, 1);