From c27530c79fd135c499a52b222e9cec16aa1951ad Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Fri, 11 Nov 2022 21:55:34 -0500 Subject: graph improvements --- main.cpp | 100 ++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 47 insertions(+), 53 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 50f9cc5..31572b4 100644 --- a/main.cpp +++ b/main.cpp @@ -130,16 +130,10 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, if (!io.WantCaptureKeyboard) ImGui_ProcessInputs(File, State, UI, Memory, io); - uint64 SortSize = (sizeof(sorted_comp_info) * File->Comp_Count) + (sizeof(sorted_layer) * File->Layer_Count); - void *SortedArray = Memory_PushScratch(Memory, SortSize); - Arbitrary_Zero((uint8 *)SortedArray, SortSize); - sorted_comp_info *SortedCompArray = (sorted_comp_info *)SortedArray; - sorted_layer *SortedLayerArray = (sorted_layer *)((uint8 *)SortedArray + (sizeof(sorted_comp_info) * File->Comp_Count)); - Layer_SortAll(File, State, Memory, SortedLayerArray, SortedCompArray, File->Layer_Count, File->Comp_Count); - + sorted_file Sorted = File_Sort_Push(File, State, Memory); if (ImGui::IsKeyPressed(ImGuiKey_T)) { - Interact_Transform_Begin(File, Memory, State, io.MousePos, SortedCompArray, SortedLayerArray); + Interact_Transform_Begin(File, Memory, State, io.MousePos, Sorted.CompArray, Sorted.LayerArray); } ImGui::DockSpaceOverViewport(); @@ -151,22 +145,29 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, } if (State->Initializing == 3) { - Source_UICreateButton(File, State, Memory, SortedCompArray, SortedLayerArray); + Source_UICreateButton(File, State, Memory, Sorted.CompArray, Sorted.LayerArray); block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0); History_Entry_Commit(Memory, "Add keyframe"); property_channel *Property = &Layer->x; { - bezier_point Point = { 1, {0, 300, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {0, 800, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + Bezier_Add(Memory, Property, Point); + } + { + bezier_point Point = { 1, {20, 300, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + Bezier_Add(Memory, Property, Point); + } + { + bezier_point Point = { 1, {10, 200, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } { - bezier_point Point = { 1, {20, 800, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {15, 200, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } History_Entry_End(Memory); - bezier_point *Point2 = Bezier_Lookup(Memory, Property, 0); - + /* History_Entry_Commit(Memory, "Add keyframe"); Property = &Layer->y; { @@ -174,31 +175,33 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, Bezier_Add(Memory, Property, Point); } { - bezier_point Point = { 1, {20, -500, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {20, 400, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } Property = &Layer->opacity; { - bezier_point Point = { 1, {0, 0, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {0, 1, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } { - bezier_point Point = { 1, {20, 1, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {20, 0, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } + */ History_Entry_End(Memory); } - ImGui_Viewport(File, State, UI, Memory, io, textureID, SortedCompArray, SortedLayerArray); - ImGui_Timeline(File, State, Memory, UI, io, SortedCompArray, SortedLayerArray); - ImGui_File(File, State, Memory, io, SortedCompArray, SortedLayerArray); + ImGui_Viewport(File, State, UI, Memory, io, textureID, Sorted.CompArray, Sorted.LayerArray); + ImGui_Timeline(File, State, Memory, UI, io, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyArray); + ImGui_File(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray); ImGui_PropertiesPanel(File, State, UI, Memory, io); ImGui_ColorPanel(File, State, UI, Memory, io); ImGui_Menu(File, State, UI, Memory, io); - Memory_PopScratch(Memory, SortSize); + File_Sort_Pop(Memory, Sorted.Layer_SortSize, Sorted.Property_SortSize); + #if DEBUG Debug.Temp = {}; #endif @@ -207,7 +210,7 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, } static void * -Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io, sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, uint32 CompIndex) +Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io, sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, uint16 *SortedPropertyArray, uint32 CompIndex) { block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, CompIndex); cache_entry *Entry_Main = Memory_Cache_Search(State, Memory, cache_entry_type_comp, CompIndex, State->Frame_Current); @@ -266,7 +269,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io cache_entry *Entry = Memory_Cache_Search(State, Memory, cache_entry_type_comp, Layer->Block_Source_Index, State->Frame_Current); // if (!Entry->IsCached) { uint64 Src_TimeStart = GetTime(); - Render_Comp(File, State, Memory, io, SortedCompArray, SortedLayerArray, Layer->Block_Source_Index); + Render_Comp(File, State, Memory, io, SortedCompArray, SortedLayerArray, SortedPropertyArray, Layer->Block_Source_Index); Entry->CycleTime = GetTime() - Src_TimeStart; // } BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); @@ -278,37 +281,34 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io // for (int a = 0; a < Layer->Block_Effect_Count; a++) { // } + int32 Offset = (State->Interact_Active == interact_type_keyframe_move) ? (int32)State->Interact_Offset[0] : 0; for (int h = 0; h < AmountOf(Layer->Property); h++) { property_channel *Property = &Layer->Property[h]; + uint16 *ArrayLocation = SortedPropertyArray + (i * 7 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK); if (Property->Block_Bezier_Count) { - bezier_point *FirstPoint = Bezier_Lookup(Memory, Property, 0); - int k = 0; - for (;;) { - bezier_point *Point = Bezier_Lookup(Memory, Property, k); - if (!Point->Occupied) - break; - k++; - } - bezier_point *LastPoint = Bezier_Lookup(Memory, Property, k - 1); - if (FirstPoint->Pos[0].x >= State->Frame_Current) { - Property->CurrentValue = FirstPoint->Pos[0].y; - } else if (LastPoint->Pos[0].x <= State->Frame_Current) { - Property->CurrentValue = LastPoint->Pos[0].y; + v2 Min, Max; + Property_MinMax(Memory, State, Property, ArrayLocation, &Min, &Max); + if (Min.x >= State->Frame_Current) { + Property->CurrentValue = Min.y; + } else if (Max.x <= State->Frame_Current) { + Property->CurrentValue = Max.y; } else { int KeyframeIndex = 0; for (;;) { - bezier_point *Point = Bezier_Lookup(Memory, Property, KeyframeIndex + 1); - if (Point->Pos[0].x >= State->Frame_Current) + v2 PointPos[3]; + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); + Bezier_EvaluateValue(State, PointAddress, PointPos); + if (PointPos[0].x >= State->Frame_Current) break; KeyframeIndex++; } - bezier_point *Point = Bezier_Lookup(Memory, Property, KeyframeIndex); - bezier_point *NextPoint = Bezier_Lookup(Memory, Property, KeyframeIndex + 1); - v2 Pos_New[3] = { Point->Pos[0], Point->Pos[1], Point->Pos[2] }; - v2 NextPos_New[3] = { NextPoint->Pos[0], NextPoint->Pos[1], NextPoint->Pos[2] }; - Keyframe_Interact_Evaluate(Memory, State, Point->IsSelected, Point->Pos, Pos_New); - Keyframe_Interact_Evaluate(Memory, State, NextPoint->IsSelected, NextPoint->Pos, NextPos_New); - Property->CurrentValue = Bezier_SolveYForX(Pos_New[0], Pos_New[0] + Pos_New[2], NextPos_New[0] + NextPos_New[1], NextPos_New[0], State->Frame_Current); + v2 PointPos[3]; + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex]); + Bezier_EvaluateValue(State, PointAddress, PointPos); + v2 NextPointPos[3]; + bezier_point *NextPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); + Bezier_EvaluateValue(State, NextPointAddress, NextPointPos); + Property->CurrentValue = Bezier_SolveYForX(PointPos[0], PointPos[0] + PointPos[2], NextPointPos[0] + NextPointPos[1], NextPointPos[0], State->Frame_Current); } } } @@ -347,17 +347,11 @@ Main_Renderer(project_data *File, project_state *State, memory *Memory, SDL_Wind block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); - // NOTE(fox): All layers are given a slot here - uint64 SortSize = (sizeof(sorted_comp_info) * File->Comp_Count) + (sizeof(sorted_layer) * File->Layer_Count); - void *SortedArray = Memory_PushScratch(Memory, SortSize); - Arbitrary_Zero((uint8 *)SortedArray, SortSize); - sorted_comp_info *SortedCompArray = (sorted_comp_info *)SortedArray; - sorted_layer *SortedLayerArray = (sorted_layer *)((uint8 *)SortedArray + (sizeof(sorted_comp_info) * File->Comp_Count)); - Layer_SortAll(File, State, Memory, SortedLayerArray, SortedCompArray, File->Layer_Count, File->Comp_Count); + sorted_file Sorted = File_Sort_Push(File, State, Memory); - void *MainCompBuffer = Render_Comp(File, State, Memory, io, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex); + void *MainCompBuffer = Render_Comp(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyArray, File->PrincipalCompIndex); - Memory_PopScratch(Memory, SortSize); + File_Sort_Pop(Memory, Sorted.Layer_SortSize, Sorted.Property_SortSize); glBindTexture(GL_TEXTURE_2D, textureID); -- cgit v1.2.3