From 7804c6a96d26c2e757d09f1864eb73fb81eb280f Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Thu, 20 Oct 2022 20:45:37 -0400 Subject: precomp recursion! --- createcalls.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 4 deletions(-) (limited to 'createcalls.cpp') diff --git a/createcalls.cpp b/createcalls.cpp index 2c2df61..6a830b5 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -12,17 +12,17 @@ Source_Generate(project_data *File, project_state *State, memory *Memory, void * bool32 IsVideo = 0; if (AV_IsFileSupported((char *)TempString, &IsVideo)) { - uint16 Index = Memory_Block_AllocateNew(Memory, F_Strings); + uint16 Index = Memory_Block_AllocateNew(Memory, F_Sources); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Index); History_Entry_Commit(Memory, "Add source"); History_Action_Block_Swap(Memory, F_Sources, Source); Source->Occupied = 1; - Source->Block_String_Index = String_AddToFile(Memory, (char *)TempString); + Source->Path_String_Index = String_AddToFile(Memory, (char *)TempString); if (IsVideo) - Source->SourceType = source_type_video; + Source->Type = source_type_video; else - Source->SourceType = source_type_image; + Source->Type = source_type_image; History_Action_Swap(Memory, F_File, sizeof(File->Source_Count), &File->Source_Count); File->Source_Count++; @@ -45,6 +45,81 @@ Property_InitFloat(char *Name, real32 Val, real32 ScrubVal, real32 MinVal = PROP return Property; } +static void +Layer_Interact_Evaluate(memory *Memory, project_state *State, int32 *Frame_Start, int32 *Frame_End, real32 *Vertical_Offset) +{ + if (State->Interact_Active == interact_type_layer_move) { + *Frame_Start += (int32)(State->Interact_Offset[0] + 0); + *Frame_End += (int32)(State->Interact_Offset[0] + 0); + *Vertical_Offset += (int32)State->Interact_Offset[1]; + } else if (State->Interact_Active == interact_type_layer_timeadjust) { + int Side[2] = {0}; + Assert(State->Interact_Offset[1] == 0 || State->Interact_Offset[1] == 1); + Side[(int)State->Interact_Offset[1]] = 1; + *Frame_Start += (int32)(State->Interact_Offset[0] * Side[0]); + *Frame_End += (int32)(State->Interact_Offset[0] * Side[1]); + } +} + +// TODO(fox): Precomps! +void Layer_DeselectAll(memory *Memory, uint32 LayerCount) { + for (uint32 i = 0; i < LayerCount; i++) { + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); + if (Layer->IsSelected) + Layer->IsSelected = false; + } +} + +static sorted_layer * +Layer_GetSortedArray(sorted_layer *LayerArrayStart, sorted_comp_info *SortedCompStart, uint32 TargetComp) +{ + uint32 LayerOffset = 0; int s = 0; + while (s < TargetComp) { + LayerOffset += SortedCompStart[s].LayerCount; + s++; + } + return LayerArrayStart + LayerOffset; +} + +void Layer_SortAll(memory *Memory, sorted_layer *LayerArrayStart, sorted_comp_info *CompStart, uint32 LayerCount, uint32 CompCount) +{ + for (uint32 i = 0; i < LayerCount; i++) { + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); + Assert(Layer->Block_Composition_Index < CompCount); + CompStart[Layer->Block_Composition_Index].LayerCount++; + + } + for (uint32 i = 0; i < LayerCount; i++) { + // SortedLayerArray->Block_Layer_Index = 0; + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); + sorted_comp_info *SortedCompInfo = &CompStart[Layer->Block_Composition_Index]; + sorted_layer *SortedLayerInfo = Layer_GetSortedArray(LayerArrayStart, CompStart, Layer->Block_Composition_Index); + uint32 SortedIndex_Playhead = 0; + while (SortedIndex_Playhead < SortedCompInfo->CurrentSortIndex) { + sorted_layer LayerEntry = SortedLayerInfo[SortedIndex_Playhead]; + block_layer *TestLayer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, LayerEntry.Block_Layer_Index); + if (Layer->Vertical_Offset < TestLayer->Vertical_Offset) { + break; + } else { + SortedIndex_Playhead++; + } + } + if (SortedIndex_Playhead != SortedCompInfo->CurrentSortIndex) { + uint8 *Address_Start = (uint8 *)(SortedLayerInfo + SortedIndex_Playhead); + uint8 *Address_End = (uint8 *)(SortedLayerInfo + i); + Arbitrary_ShiftData(Address_Start, Address_End, sizeof(sorted_layer), 1); + } + sorted_layer *LayerEntry = SortedLayerInfo + SortedIndex_Playhead; + LayerEntry->Block_Layer_Index = i; + SortedCompInfo->CurrentSortIndex++; + } + Assert(CompStart[0].LayerCount == 2); + Assert(CompStart[1].LayerCount == 2); + // Assert(LayerArrayStart[0].Block_Layer_Index == 0); + // Assert(LayerArrayStart[1].Block_Layer_Index == 1); + // Assert(LayerArrayStart[2].Block_Layer_Index == 2); + // Assert(LayerArrayStart[3].Block_Layer_Index == 3); +} block_layer * Layer_Init(project_data *File, memory *Memory) { @@ -57,6 +132,7 @@ block_layer * Layer_Init(project_data *File, memory *Memory) Layer->Block_String_Index = Memory_Block_AllocateNew(Memory, F_Strings); block_string *String = (block_string *)Memory_Block_AddressAtIndex(Memory, F_Strings, Layer->Block_String_Index); sprintf(String->Char, "Layer %i", File->Layer_Count + 1); // CSbros... + String->Occupied = 1; Layer->x = Property_InitFloat("X Position", 0.0f, 1.0f); Layer->y = Property_InitFloat("Y Position", 0.0f, 1.0f); @@ -67,6 +143,8 @@ block_layer * Layer_Init(project_data *File, memory *Memory) Layer->opacity = Property_InitFloat("Opacity", 1.0f, 0.005f, 0.0f, 1.0f); Layer->time = Property_InitFloat("Frame Number", 0.0f, 1.0f, 0, 100000); + Layer->IsVisible = 1; + History_Action_Swap(Memory, F_File, sizeof(File->Layer_Count), &File->Layer_Count); File->Layer_Count++; -- cgit v1.2.3