From 18bef60ba1e2286f3ec91ca3a22fc8b40cfb6fa5 Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Tue, 30 Mar 2021 22:04:05 -0700 Subject: [PATCH] Trying to reduce memory usage --- src/app/engine/animation/foldhaus_animation.h | 5 ++- src/app/foldhaus_app.cpp | 40 ++++++++++--------- src/app/foldhaus_platform.h | 2 +- src/app/platform_win32/win32_foldhaus.cpp | 4 +- src/gs_libs/gs_types.cpp | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/app/engine/animation/foldhaus_animation.h b/src/app/engine/animation/foldhaus_animation.h index 4bcad4a..2385238 100644 --- a/src/app/engine/animation/foldhaus_animation.h +++ b/src/app/engine/animation/foldhaus_animation.h @@ -801,7 +801,10 @@ AnimationSystem_FadeToPlaylist(animation_system* System, animation_handle_array System->Playlist = Playlist; System->PlaylistAt = 0; - AnimationFadeGroup_FadeTo(&System->ActiveFadeGroup, Playlist.Handles[0], System->PlaylistFadeTime); + if (System->Playlist.Count > 0) + { + AnimationFadeGroup_FadeTo(&System->ActiveFadeGroup, Playlist.Handles[0], System->PlaylistFadeTime); + } } inline bool diff --git a/src/app/foldhaus_app.cpp b/src/app/foldhaus_app.cpp index dc19ab6..0712c40 100644 --- a/src/app/foldhaus_app.cpp +++ b/src/app/foldhaus_app.cpp @@ -30,11 +30,13 @@ RELOAD_STATIC_DATA(ReloadStaticData) INITIALIZE_APPLICATION(InitializeApplication) { - app_state* State = (app_state*)Context.MemoryBase; + Context->MemorySize = sizeof(app_state); + Context->MemoryBase = AllocatorAlloc(Context->ThreadContext.Allocator, Context->MemorySize).Memory; + app_state* State = (app_state*)Context->MemoryBase; *State = {}; - State->Permanent = CreateMemoryArena(Context.ThreadContext.Allocator, "Permanent"); - State->Transient = Context.ThreadContext.Transient; + State->Permanent = CreateMemoryArena(Context->ThreadContext.Allocator, "Permanent"); + State->Transient = Context->ThreadContext.Transient; State->Assemblies = AssemblyArray_Create(8, &State->Permanent); State->GlobalLog = PushStruct(&State->Permanent, event_log); @@ -47,7 +49,7 @@ INITIALIZE_APPLICATION(InitializeApplication) AnimSysDesc.SecondsPerFrame = 1.0f / 24.0f; State->AnimationSystem = AnimationSystem_Init(AnimSysDesc); - if (!Context.Headless) + if (!Context->Headless) { interface_config IConfig = {0}; IConfig.FontSize = 14; @@ -61,50 +63,50 @@ INITIALIZE_APPLICATION(InitializeApplication) IConfig.ListBGHover = v4{ .22f, .22f, .22f, 1.f }; IConfig.ListBGSelected = v4{ .44f, .44f, .44f, 1.f }; IConfig.Margin = v2{5, 5}; - State->Interface = ui_InterfaceCreate(Context, IConfig, &State->Permanent); + State->Interface = ui_InterfaceCreate(*Context, IConfig, &State->Permanent); PanelSystem_Init(&State->PanelSystem, GlobalPanelDefs, GlobalPanelDefsCount, &State->Permanent); } - State->SACN = SACN_Initialize(Context); + State->SACN = SACN_Initialize(*Context); - State->LedSystem = LedSystem_Create(Context.ThreadContext.Allocator, 128); + State->LedSystem = LedSystem_Create(Context->ThreadContext.Allocator, 128); State->AssemblyDebugState = AssemblyDebug_Create(&State->Permanent); State->AssemblyDebugState.Brightness = 255; State->AssemblyDebugState.Override = ADS_Override_None; - State->Modes = OperationModeSystemInit(&State->Permanent, Context.ThreadContext); + State->Modes = OperationModeSystemInit(&State->Permanent, Context->ThreadContext); - ReloadStaticData(Context, GlobalDebugServices, true); - US_CustomInit(&State->UserSpaceDesc, State, Context); + ReloadStaticData(*Context, GlobalDebugServices, true); + US_CustomInit(&State->UserSpaceDesc, State, *Context); GlobalDebugServices->Interface.RenderSculpture = true; - if (!Context.Headless) + if (!Context->Headless) { // NOTE(pjs): This just sets up the default panel layout - panel* RootPanel = PanelSystem_PushPanel(&State->PanelSystem, PanelType_SculptureView, State, Context); - SplitPanel(RootPanel, .25f, PanelSplit_Horizontal, &State->PanelSystem, State, Context); + panel* RootPanel = PanelSystem_PushPanel(&State->PanelSystem, PanelType_SculptureView, State, *Context); + SplitPanel(RootPanel, .25f, PanelSplit_Horizontal, &State->PanelSystem, State, *Context); panel* AnimPanel = RootPanel->Bottom; - Panel_SetType(AnimPanel, &State->PanelSystem, PanelType_AnimationTimeline, State, Context); + Panel_SetType(AnimPanel, &State->PanelSystem, PanelType_AnimationTimeline, State, *Context); panel* TopPanel = RootPanel->Top; - SplitPanel(TopPanel, .5f, PanelSplit_Vertical, &State->PanelSystem, State, Context); + SplitPanel(TopPanel, .5f, PanelSplit_Vertical, &State->PanelSystem, State, *Context); panel* LeftPanel = TopPanel->Left; - SplitPanel(LeftPanel, .5f, PanelSplit_Vertical, &State->PanelSystem, State, Context); + 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_ProfilerView, State, *Context); panel* Hierarchy = LeftPanel->Left; - Panel_SetType(Hierarchy, &State->PanelSystem, PanelType_AssemblyDebug, State, Context); + Panel_SetType(Hierarchy, &State->PanelSystem, PanelType_AssemblyDebug, State, *Context); } - State->RunEditor = !Context.Headless; + State->RunEditor = !Context->Headless; } internal void diff --git a/src/app/foldhaus_platform.h b/src/app/foldhaus_platform.h index 1009001..76eb968 100644 --- a/src/app/foldhaus_platform.h +++ b/src/app/foldhaus_platform.h @@ -68,7 +68,7 @@ struct packet_ringbuffer u32 WriteHead; }; -#define INITIALIZE_APPLICATION(name) void name(context Context) +#define INITIALIZE_APPLICATION(name) void name(context* Context) 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) diff --git a/src/app/platform_win32/win32_foldhaus.cpp b/src/app/platform_win32/win32_foldhaus.cpp index 3957f03..f8bc0cd 100644 --- a/src/app/platform_win32/win32_foldhaus.cpp +++ b/src/app/platform_win32/win32_foldhaus.cpp @@ -612,8 +612,6 @@ WinMain ( context Context = {}; Context.ThreadContext = ThreadContext; - Context.MemorySize = MB(64); - Context.MemoryBase = (u8*)Win32Alloc(Context.MemorySize, 0); gs_const_string Args = ConstString((char*)CmdLineArgs); if (StringsEqual(Args, ConstString("-headless"))) @@ -680,7 +678,7 @@ WinMain ( addressed_data_buffer_list OutputData = AddressedDataBufferList_Create(ThreadContext); - Context.InitializeApplication(Context); + Context.InitializeApplication(&Context); system_time StartTime = Win32GetSystemTime(); diff --git a/src/gs_libs/gs_types.cpp b/src/gs_libs/gs_types.cpp index 8a6d074..1098c92 100644 --- a/src/gs_libs/gs_types.cpp +++ b/src/gs_libs/gs_types.cpp @@ -2607,7 +2607,7 @@ CreateMemoryArena_(arena_type ArenaType, gs_allocator Allocator, u64 ChunkSize, } internal gs_memory_arena -CreateMemoryArena(gs_allocator Allocator, char* Name, u64 ChunkSize = KB(32), u64 Alignment = Bytes(8)) +CreateMemoryArena(gs_allocator Allocator, char* Name, u64 ChunkSize = KB(4), u64 Alignment = Bytes(8)) { return CreateMemoryArena_(Arena_BaseArena, Allocator, ChunkSize, Alignment, 0, Name); }