diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 141 |
1 files changed, 89 insertions, 52 deletions
@@ -125,6 +125,8 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, UI->Warp_WantSetPos = false; } + // NOTE(fox): The only requirement for something that needs to happen before the sort is anything that creates/deletes layers. + // The requirement for something after the sort is things that depend on the sort. (obvious) if (!io.WantCaptureKeyboard) ImGui_ProcessInputs(File, State, UI, Memory, io); @@ -135,6 +137,11 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, 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); + + if (ImGui::IsKeyPressed(ImGuiKey_T)) { + Interact_Transform_Begin(File, Memory, State, io.MousePos, SortedCompArray, SortedLayerArray); + } + ImGui::DockSpaceOverViewport(); if (Debug.ToggleWindow) { @@ -143,8 +150,45 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui_DebugUndoTree(Memory, State); } - // if (State->Initializing == 3) - // Source_UICreateButton(File, State, Memory, SortedCompArray, SortedLayerArray); + if (State->Initializing == 3) { + Source_UICreateButton(File, State, Memory, SortedCompArray, SortedLayerArray); + 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_Add(Memory, Property, Point); + } + { + bezier_point Point = { 1, {20, 800, -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; + { + bezier_point Point = { 1, {0, 400, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + Bezier_Add(Memory, Property, Point); + } + { + bezier_point Point = { 1, {20, -500, -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_Add(Memory, Property, Point); + } + { + bezier_point Point = { 1, {20, 1, -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); @@ -162,11 +206,6 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::EndFrame(); } -static layer_transforms -Layer_GetTransforms(block_layer *Layer) { - return { Layer->x.CurrentValue, Layer->y.CurrentValue, Layer->ax.CurrentValue, Layer->ay.CurrentValue, Layer->rotation.CurrentValue, Layer->scale.CurrentValue }; -} - static void * Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io, sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, uint32 CompIndex) { @@ -189,7 +228,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io uint32 Index_Physical = SortEntry.Block_Layer_Index; block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical); if (Layer->Frame_Start <= State->Frame_Current && - Layer->Frame_End >= State->Frame_Current && Layer->IsVisible) + Layer->Frame_End > State->Frame_Current && Layer->IsVisible) { layer_bitmap_state *BitmapState = &State->Render.Bitmap[Index_Physical]; void *BitmapAddress = NULL; @@ -225,13 +264,11 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io } else { block_composition *Precomp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, Layer->Block_Source_Index); 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); - Layer->x.CurrentValue = (Layer->Block_Source_Index == 0) ? 200 : Comp->Width/2; - Layer->y.CurrentValue = Comp->Height/2; - Entry->CycleTime = GetTime() - Src_TimeStart; - } + // if (!Entry->IsCached) { + uint64 Src_TimeStart = GetTime(); + Render_Comp(File, State, Memory, io, SortedCompArray, SortedLayerArray, Layer->Block_Source_Index); + Entry->CycleTime = GetTime() - Src_TimeStart; + // } BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); } Assert(BitmapAddress); @@ -241,37 +278,38 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io // for (int a = 0; a < Layer->Block_Effect_Count; a++) { // } - property_channel *Property = &Layer->x; - - 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; - } else { - int KeyframeIndex = 0; + for (int h = 0; h < AmountOf(Layer->Property); h++) { + property_channel *Property = &Layer->Property[h]; + if (Property->Block_Bezier_Count) { + bezier_point *FirstPoint = Bezier_Lookup(Memory, Property, 0); + int k = 0; for (;;) { - bezier_point *Point = Bezier_Lookup(Memory, Property, KeyframeIndex + 1); - if (Point->Pos[0].x >= State->Frame_Current) + bezier_point *Point = Bezier_Lookup(Memory, Property, k); + if (!Point->Occupied) break; - KeyframeIndex++; + 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; + } else { + int KeyframeIndex = 0; + for (;;) { + bezier_point *Point = Bezier_Lookup(Memory, Property, KeyframeIndex + 1); + if (Point->Pos[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); } - 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); } } @@ -361,11 +399,12 @@ int main(int argc, char *argv[]) { Memory_InitTable(&GlobalMemory, &Memory, 40 * 1024 * 1024, P_MiscCache, "Misc persistent"); Memory_InitTable(&GlobalMemory, &Memory, sizeof(project_data), F_File, "File", sizeof(project_data)); - Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Precomps, "Precomps", sizeof(block_composition)); - Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Layers, "Layers", sizeof(block_layer)); - Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Sources, "Sources", sizeof(block_source)); - Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Bezier, "Bezier paths (keyframes, masks)", sizeof(block_bezier)); - Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Strings, "Strings", sizeof(block_string)); + Memory_InitTable(&GlobalMemory, &Memory, 1 * 1024 * 1024, F_Precomps, "Precomps", sizeof(block_composition)); + Memory_InitTable(&GlobalMemory, &Memory, 2 * 1024 * 1024, F_Layers, "Layers", sizeof(block_layer)); + Memory_InitTable(&GlobalMemory, &Memory, 1 * 1024 * 1024, F_Sources, "Sources", sizeof(block_source)); + Memory_InitTable(&GlobalMemory, &Memory, 2 * 1024 * 1024, F_Properties, "Properties", sizeof(property_channel)); + Memory_InitTable(&GlobalMemory, &Memory, 4 * 1024 * 1024, F_Bezier, "Bezier paths (keyframes, masks)", sizeof(block_bezier)); + Memory_InitTable(&GlobalMemory, &Memory, 4 * 1024 * 1024, F_Strings, "Strings", sizeof(block_string)); Memory_InitTable(&GlobalMemory, &Memory, (uint64)50 * 1024 * 1024, F_PrincipalBitmaps, "Principal bitmap data", BitmapBlockSize); Memory_InitTable(&GlobalMemory, &Memory, (uint64)64 * 1024 * 1024, B_ScratchSpace, "Scratch"); @@ -428,8 +467,6 @@ int main(int argc, char *argv[]) { Comp2->Name_String_Index = String_AddToFile(&Memory, "Another comp"); */ - File->Comp_Count = 1; - { uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/a.jpg"); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 0); @@ -528,7 +565,7 @@ int main(int argc, char *argv[]) { { uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/b.jpg"); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 1); - Source->IsSelected = true; + // Source->IsSelected = true; /* { Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); @@ -585,7 +622,7 @@ int main(int argc, char *argv[]) { { uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/c.jpg"); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 2); - Source->IsSelected = true; + // Source->IsSelected = true; /* { Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); |