From 85f7aab6214986746c129a9f7507bc999f8ce62a Mon Sep 17 00:00:00 2001 From: PS Date: Sat, 24 Oct 2020 13:28:10 -0700 Subject: [PATCH] Animation loading --- .../foldhaus_panel_animation_timeline.h | 12 +++++--- .../editor/panels/foldhaus_panel_file_view.h | 28 +++++++++++++------ src/app/engine/animation/foldhaus_animation.h | 3 +- .../foldhaus_animation_serializer.cpp | 13 ++++++--- src/app/foldhaus_app.cpp | 1 - 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/app/editor/panels/foldhaus_panel_animation_timeline.h b/src/app/editor/panels/foldhaus_panel_animation_timeline.h index 91f01fa..47404d4 100644 --- a/src/app/editor/panels/foldhaus_panel_animation_timeline.h +++ b/src/app/editor/panels/foldhaus_panel_animation_timeline.h @@ -494,7 +494,7 @@ DrawAnimationTimeline (animation_system* AnimationSystem, animation_timeline_sta handle Result = SelectedBlockHandle; // TODO(pjs): Animation Selection - animation CurrAnimation = AnimationSystem->Animations.Values[0]; + animation CurrAnimation = *AnimationSystem_GetActiveAnimation(AnimationSystem); rect2 LayerMenuBounds, TimelineBounds; RectVSplitAtDistanceFromLeft(PanelBounds, 256, &LayerMenuBounds, &TimelineBounds); @@ -579,6 +579,13 @@ PANEL_MODAL_OVERRIDE_CALLBACK(LoadAnimationFileCallback) Assert(ReturningFrom->TypeIndex == PanelType_FileView); file_view_state* FileViewState = Panel_GetStateStruct(ReturningFrom, file_view_state); gs_file_info FileInfo = FileViewState->SelectedFile; + + gs_file AnimFile = ReadEntireFile(Context.ThreadContext.FileHandler, FileInfo.Path); + gs_string AnimFileString = MakeString((char*)AnimFile.Data.Memory, AnimFile.Data.Size); + animation NewAnim = AnimParser_Parse(AnimFileString, State->AnimationSystem.Storage, GlobalAnimationClipsCount, GlobalAnimationClips); + + u32 NewAnimIndex = AnimationArray_Push(&State->AnimationSystem.Animations, NewAnim); + State->AnimationSystem.ActiveAnimationIndex = NewAnimIndex; } internal void @@ -637,9 +644,6 @@ AnimationTimeline_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* { panel_entry* FileBrowser = PanelSystem_PushPanel(&State->PanelSystem, PanelType_FileView, State, Context); Panel_PushModalOverride(Panel, FileBrowser, LoadAnimationFileCallback); - // TODO(pjs): I think we want to be able to specify a return command that gets called when the - // pushed panel state returns to this one - // something like: AnimPanel_HandleLoadedAnimationFile } } ui_EndRow(&TitleBarLayout); diff --git a/src/app/editor/panels/foldhaus_panel_file_view.h b/src/app/editor/panels/foldhaus_panel_file_view.h index 78cbd47..e369e7f 100644 --- a/src/app/editor/panels/foldhaus_panel_file_view.h +++ b/src/app/editor/panels/foldhaus_panel_file_view.h @@ -14,7 +14,19 @@ struct file_view_state gs_file_info SelectedFile; }; -input_command* FileView_Commands = 0; +internal void +FileView_Exit_(panel* FileViewPanel, app_state* State, context Context) +{ + Assert(FileViewPanel->IsModalOverrideFor != 0); + panel* ReturnTo = FileViewPanel->IsModalOverrideFor; + if (ReturnTo->ModalOverrideCB) + { + ReturnTo->ModalOverrideCB(FileViewPanel, State, Context); + } + Panel_PopModalOverride(ReturnTo, &State->PanelSystem); +} + +global input_command* FileView_Commands = 0; s32 FileView_CommandsCount = 0; internal void @@ -78,6 +90,11 @@ FileView_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* RenderBu file_view_state* FileViewState = Panel_GetStateStruct(Panel, file_view_state); ui_layout Layout = ui_CreateLayout(State->Interface, PanelBounds); + if (ui_LayoutButton(&State->Interface, &Layout, MakeString("Exit"))) + { + FileView_Exit_(Panel, State, Context); + } + // Header ui_LayoutDrawString(&State->Interface, &Layout, FileViewState->WorkingDirectory, v4{0, 1, 0, 1}); @@ -99,14 +116,7 @@ FileView_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* RenderBu else { FileViewState->SelectedFile = File; - - Assert(Panel->IsModalOverrideFor != 0); - panel* ReturnTo = Panel->IsModalOverrideFor; - if (ReturnTo->ModalOverrideCB) - { - ReturnTo->ModalOverrideCB(Panel, State, Context); - } - Panel_PopModalOverride(ReturnTo, &State->PanelSystem); + FileView_Exit_(Panel, State, Context); } } } diff --git a/src/app/engine/animation/foldhaus_animation.h b/src/app/engine/animation/foldhaus_animation.h index cb564a7..81e2080 100644 --- a/src/app/engine/animation/foldhaus_animation.h +++ b/src/app/engine/animation/foldhaus_animation.h @@ -94,6 +94,7 @@ struct animation_system // NOTE(Peter): The frame currently being displayed/processed. you // can see which frame you're on by looking at the time slider on the timeline // panel + u32 ActiveAnimationIndex; s32 CurrentFrame; s32 LastUpdatedFrame; r32 SecondsPerFrame; @@ -401,7 +402,7 @@ internal animation* AnimationSystem_GetActiveAnimation(animation_system* System) { // TODO(pjs): need a way to specify the active animation - return System->Animations.Values + 0; + return System->Animations.Values + System->ActiveAnimationIndex; } internal animation_frame diff --git a/src/app/engine/animation/foldhaus_animation_serializer.cpp b/src/app/engine/animation/foldhaus_animation_serializer.cpp index 57d6221..ac9954e 100644 --- a/src/app/engine/animation/foldhaus_animation_serializer.cpp +++ b/src/app/engine/animation/foldhaus_animation_serializer.cpp @@ -70,7 +70,7 @@ AnimSerializer_Serialize(animation Anim, animation_clip* GlobalClips, gs_memory_ } internal animation -AnimParser_Parse(gs_string File, animation_clip* GlobalClips, gs_memory_arena* Arena, u32 AnimClipsCount, animation_clip* AnimClips) +AnimParser_Parse(gs_string File, gs_memory_arena* Arena, u32 AnimClipsCount, animation_clip* AnimClips) { animation Result = {0}; @@ -88,14 +88,19 @@ AnimParser_Parse(gs_string File, animation_clip* GlobalClips, gs_memory_arena* A Result.Layers.CountMax = Parser_ReadU32Value(&Parser, AnimField_LayersCount); Result.Layers.Values = PushArray(Arena, anim_layer, Result.Layers.CountMax); - // TODO(pjs): We're not using this now because Blocks are built on gs_list or something, - // but I want to replace that eventually, so this is here to preallocate the blocks we need - u32 BlocksCount = Parser_ReadU32Value(&Parser, AnimField_BlocksCount); + Result.Blocks_.CountMax = Parser_ReadU32Value(&Parser, AnimField_BlocksCount); + Result.Blocks_.Generations = PushArray(Arena, u32, Result.Blocks_.CountMax); + Result.Blocks_.Values = PushArray(Arena, animation_block, Result.Blocks_.CountMax); if (Parser_ReadOpenStruct(&Parser, AnimField_PlayableRange)) { Result.PlayableRange.Min = Parser_ReadU32Value(&Parser, AnimField_PlayableRangeMin); Result.PlayableRange.Max = Parser_ReadU32Value(&Parser, AnimField_PlayableRangeMax); + + if (Parser_ReadCloseStruct(&Parser)) + { + // TODO(pjs): Error + } } else { diff --git a/src/app/foldhaus_app.cpp b/src/app/foldhaus_app.cpp index b578796..af0c7ae 100644 --- a/src/app/foldhaus_app.cpp +++ b/src/app/foldhaus_app.cpp @@ -155,7 +155,6 @@ INITIALIZE_APPLICATION(InitializeApplication) Animation_AddBlock(&Anim, 22, 123, 2, 0); AnimationArray_Push(&State->AnimationSystem.Animations, Anim); - } // End Animation Playground