Finished replacing logging with the new system

This commit is contained in:
PS 2021-04-12 21:27:25 -10:00
parent a983644f6b
commit 495e760306
11 changed files with 40 additions and 30 deletions

View File

@ -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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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);
}

View File

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

View File

@ -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));

View File

@ -6,13 +6,16 @@
#ifndef FIRST_CPP
#include <windows.h>
#include <stdio.h>
#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 <windows.h>
#include <stdio.h>
//#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);