diff --git a/src/app/editor/interface.h b/src/app/editor/interface.h index 244e85d..854c3dc 100644 --- a/src/app/editor/interface.h +++ b/src/app/editor/interface.h @@ -1562,9 +1562,10 @@ ui_BeginList(ui_interface* Interface, gs_string Text, u32 ViewportRows, u32 Elem s32 ScrollableElements = Max(0, ElementCount - ViewportRows); ui_widget_retained_state* ViewportState = ui_GetOrCreateRetainedState(Interface, ViewportLayout); ViewportState->ChildrenDrawOffset.x = 0; - r32 BaseOffset = Rect2Height(ViewportLayout->Bounds) - ViewportLayout->RowHeight; + r32 BaseOffset = 0; r32 ScrollPct = 1.0 - State->InitialValueR32; - r32 ScrollOffset = ScrollPct * ViewportLayout->RowHeight * ScrollableElements; + r32 RowsOffset = ScrollPct * ScrollableElements; + r32 ScrollOffset = (ViewportLayout->RowHeight - (Interface->Style.Margin.y)) * RowsOffset; ViewportState->ChildrenDrawOffset.y = BaseOffset + ScrollOffset; } diff --git a/src/app/editor/panels/foldhaus_panel_hierarchy.h b/src/app/editor/panels/foldhaus_panel_hierarchy.h index 7979512..7e616b2 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, &State->GlobalLog); } 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 new file mode 100644 index 0000000..dbabc5c --- /dev/null +++ b/src/app/editor/panels/foldhaus_panel_message_log.h @@ -0,0 +1,46 @@ +/* date = April 12th 2021 4:47 pm */ + +#ifndef FOLDHAUS_PANEL_MESSAGE_LOG_H +#define FOLDHAUS_PANEL_MESSAGE_LOG_H + +GSMetaTag(panel_init); +GSMetaTag(panel_type_file_view); +internal void +MessageLog_Init(panel* Panel, app_state* State, context Context) +{ +} + +GSMetaTag(panel_cleanup); +GSMetaTag(panel_type_file_view); +internal void +MessageLog_Cleanup(panel* Panel, app_state* State) +{ + +} + +GSMetaTag(panel_render); +GSMetaTag(panel_type_file_view); +internal void +MessageLog_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context) +{ + 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); + + log_buffer_iter Iter = Log_GetIter(&State->GlobalLog); + while (true) + { + log_entry* At = Iter.At; + ui_Label(Interface, At->String); + if (!LogIter_CanAdvance(Iter)) + { + break; + } + LogIter_Advance(&Iter); + } + ui_EndList(Interface); + + ui_PopLayout(Interface, MakeString("Message Log Layout")); +} +#endif //FOLDHAUS_PANEL_MESSAGE_LOG_H diff --git a/src/app/editor/panels/foldhaus_panel_types.cpp b/src/app/editor/panels/foldhaus_panel_types.cpp index ea56618..db28c35 100644 --- a/src/app/editor/panels/foldhaus_panel_types.cpp +++ b/src/app/editor/panels/foldhaus_panel_types.cpp @@ -4,7 +4,7 @@ // Creation Date: 2020-10-17 // #ifndef FOLDHAUS_PANEL_TYPES_CPP -global s32 GlobalPanelDefsCount = 7; +global s32 GlobalPanelDefsCount = 8; global panel_definition GlobalPanelDefs[] = { { "File View", 9, FileView_Init, FileView_Cleanup, FileView_Render, FileView_Commands, FileView_CommandsCount }, { "Sculpture View", 14, SculptureView_Init, SculptureView_Cleanup, SculptureView_Render, SculptureView_Commands, SculptureView_CommandsCount }, @@ -13,6 +13,7 @@ global panel_definition GlobalPanelDefs[] = { { "Hierarchy", 9, HierarchyView_Init, HierarchyView_Cleanup, HierarchyView_Render, HierarchyView_Commands, HierarchyView_CommandsCount }, { "Profiler", 8, ProfilerView_Init, ProfilerView_Cleanup, ProfilerView_Render, ProfilerView_Commands, ProfilerView_CommandsCount }, { "Assembly Debug", 14, AssemblyDebug_Init, AssemblyDebug_Cleanup, AssemblyDebug_Render, 0, 0 }, + { "Message Log", 11, MessageLog_Init, MessageLog_Cleanup, MessageLog_Render, 0, 0 }, }; #define FOLDHAUS_PANEL_TYPES_CPP #endif // FOLDHAUS_PANEL_TYPES_CPP \ No newline at end of file diff --git a/src/app/editor/panels/foldhaus_panel_types.h b/src/app/editor/panels/foldhaus_panel_types.h index 9177cdd..559bc43 100644 --- a/src/app/editor/panels/foldhaus_panel_types.h +++ b/src/app/editor/panels/foldhaus_panel_types.h @@ -12,6 +12,7 @@ enum panel_type { PanelType_HierarchyView, PanelType_ProfilerView, PanelType_AssemblyDebug, + PanelType_MessageLog }; #define FOLDHAUS_PANEL_TYPES_H #endif // FOLDHAUS_PANEL_TYPES_H \ No newline at end of file diff --git a/src/app/engine/assembly/foldhaus_assembly.cpp b/src/app/engine/assembly/foldhaus_assembly.cpp index 6264b0e..840fddc 100644 --- a/src/app/engine/assembly/foldhaus_assembly.cpp +++ b/src/app/engine/assembly/foldhaus_assembly.cpp @@ -196,7 +196,7 @@ ConstructAssemblyFromDefinition (assembly* Assembly, led_system* LedSystem) } internal assembly* -LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, gs_memory_arena* Scratch, context Context, gs_const_string Path, event_log* GlobalLog) +LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, gs_memory_arena* Scratch, context Context, gs_const_string Path, log_buffer* GlobalLog) { assembly* NewAssembly = 0; @@ -232,7 +232,7 @@ LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, gs_memory_arena } else { - LogError(GlobalLog, "Unable to load assembly file"); + Log_Error(GlobalLog, "Unable to load assembly file"); } return NewAssembly; diff --git a/src/app/engine/foldhaus_log.h b/src/app/engine/foldhaus_log.h new file mode 100644 index 0000000..a369e13 --- /dev/null +++ b/src/app/engine/foldhaus_log.h @@ -0,0 +1,116 @@ +/* date = April 12th 2021 4:25 pm */ + +#ifndef FOLDHAUS_LOG_H +#define FOLDHAUS_LOG_H + +enum log_entry_type +{ + LogEntry_Message, + LogEntry_Error, +}; + +struct log_entry +{ + log_entry_type Type; + gs_string String; +}; + +struct log_buffer +{ + gs_allocator Allocator; + + u64 EntriesCount; + u64 NextEntry; + log_entry* Entries; +}; + +struct log_buffer_iter +{ + log_buffer* Buffer; + u64 Start; + u64 IndexAt; + log_entry* At; +}; + +internal log_buffer +Log_Init(gs_allocator Allocator, u64 Count) +{ + log_buffer Result = {}; + Result.Allocator = Allocator; + Result.EntriesCount = Count; + Result.Entries = AllocatorAllocArray(Allocator, log_entry, Result.EntriesCount); + + for (u32 i = 0; i < Result.EntriesCount; i++) + { + Result.Entries[i].String = AllocatorAllocString(Allocator, 512); + } + + return Result; +} + +internal u64 +Log_GetNextIndex(log_buffer Log, u64 At) +{ + u64 Result = At + 1; + if (Result >= Log.EntriesCount) + { + Result = 0; + } + return Result; +} + +internal log_entry* +Log_TakeNextEntry(log_buffer* Log) +{ + log_entry* Result = Log->Entries + Log->NextEntry; + Log->NextEntry = Log_GetNextIndex(*Log, Log->NextEntry); + return Result; +} + +#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); + va_end(Args); + +#if DEBUG + OutputDebugStringA(NextEntry->String.Str); +#endif +} + +internal log_buffer_iter +Log_GetIter(log_buffer* Buffer) +{ + log_buffer_iter Result = {}; + Result.Buffer = Buffer; + Result.Start = Buffer->NextEntry; + Result.IndexAt = Result.Start; + Result.At = Result.Buffer->Entries + Result.IndexAt; + return Result; +} + +internal bool +LogIter_CanAdvance(log_buffer_iter Iter) +{ + u64 Next = Log_GetNextIndex(*Iter.Buffer, Iter.IndexAt); + bool Result = Next != Iter.Start; + return Result; +} + +internal void +LogIter_Advance(log_buffer_iter* Iter) +{ + Iter->IndexAt = Log_GetNextIndex(*Iter->Buffer, Iter->IndexAt); + Iter->At = Iter->Buffer->Entries + Iter->IndexAt; +} + +#endif //FOLDHAUS_LOG_H diff --git a/src/app/foldhaus_app.cpp b/src/app/foldhaus_app.cpp index e71f40b..652a0ac 100644 --- a/src/app/foldhaus_app.cpp +++ b/src/app/foldhaus_app.cpp @@ -11,10 +11,10 @@ RELOAD_STATIC_DATA(ReloadStaticData) { GlobalDebugServices = DebugServices; - if (AppReady) { app_state* State = (app_state*)Context.MemoryBase; + GlobalLogBuffer = &State->GlobalLog; State->PanelSystem.PanelDefs = GlobalPanelDefs; State->PanelSystem.PanelDefsCount = GlobalPanelDefsCount; @@ -39,7 +39,7 @@ INITIALIZE_APPLICATION(InitializeApplication) State->Transient = Context->ThreadContext.Transient; State->Assemblies = AssemblyArray_Create(8, &State->Permanent); - State->GlobalLog = PushStruct(&State->Permanent, event_log); + State->GlobalLog = Log_Init(Context->ThreadContext.Allocator, 32); State->CommandQueue = CommandQueue_Create(&State->Permanent, 32); @@ -97,7 +97,7 @@ INITIALIZE_APPLICATION(InitializeApplication) SplitPanel(LeftPanel, .5f, PanelSplit_Vertical, &State->PanelSystem, State, *Context); panel* Profiler = LeftPanel->Right; - Panel_SetType(Profiler, &State->PanelSystem, PanelType_ProfilerView, State, *Context); + Panel_SetType(Profiler, &State->PanelSystem, PanelType_MessageLog, State, *Context); panel* Hierarchy = LeftPanel->Left; Panel_SetType(Hierarchy, &State->PanelSystem, PanelType_AssemblyDebug, State, *Context); diff --git a/src/app/foldhaus_app.h b/src/app/foldhaus_app.h index c0e425d..3a7f70c 100644 --- a/src/app/foldhaus_app.h +++ b/src/app/foldhaus_app.h @@ -11,7 +11,7 @@ #include "engine/foldhaus_serializer.h" #include "../gs_libs/gs_font.h" -#include "foldhaus_log.h" +#include "engine/foldhaus_log.h" #include "editor/interface.h" @@ -48,6 +48,8 @@ typedef struct panel panel; #include "ss_blumen_lumen/phrase_hue_map.h" #include "ss_blumen_lumen/blumen_lumen.h" +global log_buffer* GlobalLogBuffer; + struct app_state { gs_memory_arena Permanent; @@ -61,7 +63,7 @@ struct app_state assembly_array Assemblies; assembly_debug_state AssemblyDebugState; animation_system AnimationSystem; - event_log* GlobalLog; + log_buffer GlobalLog; animation_pattern_array Patterns; // Interface @@ -93,7 +95,7 @@ LoadAssembly(gs_const_string Path, app_state* State, context Context) State->Transient, Context, Path, - State->GlobalLog); + &State->GlobalLog); } #include "engine/user_space.cpp" @@ -117,6 +119,7 @@ EndCurrentOperationMode(app_state* State) #include "editor/panels/foldhaus_panel_animation_timeline.h" #include "editor/panels/foldhaus_panel_hierarchy.h" #include "editor/panels/foldhaus_panel_assembly_debug.h" +#include "editor/panels/foldhaus_panel_message_log.h" #include "editor/panels/foldhaus_panel_types.cpp" diff --git a/src/app/foldhaus_log.h b/src/app/foldhaus_log.h index 5d1c936..dea66da 100644 --- a/src/app/foldhaus_log.h +++ b/src/app/foldhaus_log.h @@ -42,8 +42,5 @@ PushLogEntry(event_log* Log, gs_string Message, log_entry_type Type) NewEntry->Type = Type; } - - - #define FOLDHAUS_LOG_H #endif // FOLDHAUS_LOG_H \ No newline at end of file diff --git a/src/app/ss_blumen_lumen/blumen_lumen.cpp b/src/app/ss_blumen_lumen/blumen_lumen.cpp index fc21fa3..25c1c5f 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.cpp +++ b/src/app/ss_blumen_lumen/blumen_lumen.cpp @@ -69,14 +69,11 @@ DEBUG_AppendText(gs_string Str, gs_thread_context Ctx) internal void DEBUG_SentMotorCommand(motor_packet Packet, gs_thread_context Ctx) { - gs_string Str = PushStringF(Ctx.Transient, 256, "Motor Command Sent\nRequested Positions: %d %d %d\n", - Packet.FlowerPositions[0], - Packet.FlowerPositions[1], - Packet.FlowerPositions[2]); - DEBUG_AppendText(Str, Ctx); - - NullTerminate(&Str); - OutputDebugStringA(Str.Str); + Log_Message(GlobalLogBuffer, + "Motor Command Sent\nRequested Positions: %d %d %d\n", + Packet.FlowerPositions[0], + Packet.FlowerPositions[1], + Packet.FlowerPositions[2]); } internal void @@ -90,25 +87,20 @@ DEBUG_ReceivedMotorPositions(motor_packet NewPos, if (PosChanged) { - gs_string Str = PushStringF(Ctx.Transient, 256, "Motor Status Received\nCurrent Positions: %d %d %d\n", - NewPos.FlowerPositions[0], - NewPos.FlowerPositions[1], - NewPos.FlowerPositions[2]); - DEBUG_AppendText(Str, Ctx); - - NullTerminate(&Str); - OutputDebugStringA(Str.Str); + Log_Message(GlobalLogBuffer, + "Motor Status Received\nCurrent Positions: %d %d %d\n", + NewPos.FlowerPositions[0], + NewPos.FlowerPositions[1], + NewPos.FlowerPositions[2]); } } internal void DEBUG_ReceivedTemperature(temp_packet Temp, gs_thread_context Ctx) { - gs_string TempStr = PushStringF(Ctx.Transient, 256, - "\nTemperature: %d\n", - Temp.Temperature); - NullTerminate(&TempStr); - OutputDebugStringA(TempStr.Str); + Log_Message(GlobalLogBuffer, + "\nTemperature: %d\n", + Temp.Temperature); } internal void @@ -136,13 +128,13 @@ BlumenLumen_MicListenJob(gs_thread_context* Ctx, u8* UserData) Data->IsConnected = false; if (SocketHandleIsValid(ListenSocket)) { - OutputDebugStringA("Disconnected from Python Server\n"); + Log_Message(GlobalLogBuffer, "Disconnected from Python Server\n"); CloseSocket(Data->SocketManager, ListenSocket); } ListenSocket = CreateSocket(Data->SocketManager, "127.0.0.1", "20185"); if (ListenSocket.Index != 0) { - OutputDebugStringA("Connected to Python Server\n"); + Log_Message(GlobalLogBuffer, "Connected to Python Server\n"); Data->IsConnected = true; } }