diff options
Diffstat (limited to 'createcalls.cpp')
-rw-r--r-- | createcalls.cpp | 328 |
1 files changed, 267 insertions, 61 deletions
diff --git a/createcalls.cpp b/createcalls.cpp index 145a58a..912917f 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -206,14 +206,14 @@ Bezier_EvaluateValue(project_state *State, bezier_point *PointAddress, v2 *Pos, static void -Bezier_Add(memory *Memory, property_channel *Property, bezier_point PointData, uint16 *ArrayLocation) +Bezier_Add(memory *Memory, memory_table_list TableName, property_channel *Property, bezier_point PointData, uint16 *ArrayLocation) { if (!Property->Block_Bezier_Count) { Property->Block_Bezier_Index[0] = Memory_Block_AllocateNew(Memory, F_Bezier); block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(Memory, F_Bezier, Property->Block_Bezier_Index[0], 0); Bezier->Occupied = true; // NOTE(fox): Effects will change this! - History_Action_Swap(Memory, F_Layers, sizeof(Property->Block_Bezier_Count), &Property->Block_Bezier_Count); + History_Action_Swap(Memory, TableName, sizeof(Property->Block_Bezier_Count), &Property->Block_Bezier_Count); Property->Block_Bezier_Count++; } // First check to see if the point to add overlaps an existing keyframe: @@ -234,7 +234,7 @@ Bezier_Add(memory *Memory, property_channel *Property, bezier_point PointData, u if (!Point->Occupied) { History_Action_Swap(Memory, F_Bezier, sizeof(*Point), Point); *Point = PointData; - History_Action_Swap(Memory, F_Layers, sizeof(Property->Keyframe_Count), &Property->Keyframe_Count); + History_Action_Swap(Memory, TableName, sizeof(Property->Keyframe_Count), &Property->Keyframe_Count); Property->Keyframe_Count++; return; } @@ -243,11 +243,11 @@ Bezier_Add(memory *Memory, property_channel *Property, bezier_point PointData, u } static void -Property_AddKeyframe(memory *Memory, property_channel *Property, int Frame, uint16 *ArrayLocation) +Property_AddKeyframe(memory *Memory, memory_table_list TableName, property_channel *Property, int Frame, uint16 *ArrayLocation) { History_Entry_Commit(Memory, "Add keyframe"); bezier_point Point = { 1, {(real32)Frame, Property->CurrentValue, -1, 0, 1, 0}, interpolation_type_linear, 0, {0, 0, 0}, 0 }; - Bezier_Add(Memory, Property, Point, ArrayLocation); + Bezier_Add(Memory, TableName, Property, Point, ArrayLocation); History_Entry_End(Memory); } @@ -257,9 +257,8 @@ Property_AddKeyframe(memory *Memory, property_channel *Property, int Frame, uint // } static property_channel -Property_InitFloat(char *Name, real32 Val, real32 ScrubVal, real32 MinVal = PROPERTY_REAL_MIN, real32 MaxVal = PROPERTY_REAL_MAX, bool32 AlwaysInteger = 0) { +Property_InitFloat(real32 Val, real32 ScrubVal, real32 MinVal = PROPERTY_REAL_MIN, real32 MaxVal = PROPERTY_REAL_MAX, bool32 AlwaysInteger = 0) { property_channel Property = {}; - Property.Name = Name; Property.CurrentValue = Val; Property.MinVal = MinVal; Property.MaxVal = MaxVal; @@ -331,7 +330,7 @@ Effect_Init(project_state *State, memory *Memory, uint32 EffectEntryIndex, int E property_channel *Property = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect->Block_Property_Index[e], 0); Property->Occupied = true; header_property PropertyHeader = State->Property[EffectHeader->PropertyStartIndex + e]; - Property->Name = PropertyHeader.Name; + Property->Identifier = -1; Property->CurrentValue = PropertyHeader.DefaultValue; Property->MinVal = PropertyHeader.MinVal; Property->MaxVal = PropertyHeader.MaxVal; @@ -373,13 +372,32 @@ Layer_UpdateMasksEffects(project_state *State, block_layer *Layer, memory *Memor header_effect *EffectEntry = Effect_EntryFromID(State, Effect.ID); if (Effect.IsToggled) { - real32 *Data = (real32 *)Memory_PushScratch(Memory, sizeof(real32) * 50); - for (int c = 0; c < EffectEntry->Property_Count; c++) { - property_channel *Property = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect.Block_Property_Index[c]); - Data[c] = Property->CurrentValue; + uint64 Size = (sizeof(real32) * MAX_PROPERTIES_PER_EFFECT) + (sizeof(real32) * 10); + real32 *Data; + if (EffectEntry->DisplayType == effect_display_type_curves) { + Data = (real32 *)Memory_PushScratch(Memory, Size); + uint16 SortedPointIndex[MAX_PROPERTIES_PER_EFFECT]; + v2 *SortedPointValues = (v2 *)(Data + 5); + for (int c = 0; c < 5; c++) { + *(Data + c) = Effect.ExtraData[c]; + uint32 Shift = MAX_PROPERTIES_PER_EFFECT / 5 * c; + uint16 *SortedPointIndexPlayhead = SortedPointIndex + Shift; + v2 *SortedPointValuesPlayhead = SortedPointValues + Shift; + Effect_Curves_Sort(Memory, &Effect, SortedPointIndexPlayhead, c); + for (int a = 0; a < Effect.ExtraData[c]; a++) { + *SortedPointValuesPlayhead = Effect_V2(Memory, &Effect, SortedPointIndexPlayhead[a]); + SortedPointValuesPlayhead++; + } + } + } else { + Data = (real32 *)Memory_PushScratch(Memory, Size); + for (int c = 0; c < EffectEntry->Property_Count; c++) { + property_channel *Property = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect.Block_Property_Index[c]); + Data[c] = Property->CurrentValue; + } } EffectEntry->func(Data, Width, Height, BytesPerPixel, EffectBitmapAddress, EffectEntry->GLShaderIndex); - Memory_PopScratch(Memory, sizeof(real32) * 50); + Memory_PopScratch(Memory, Size); } } /* @@ -457,9 +475,9 @@ Layer_LoopChannels(project_state *State, memory *Memory, sorted_property_info ** property_channel **Property, block_effect **EffectOut, int *h, int *c, int *p) { uint32 Amount = AmountOf(Layer->Property) + Layer->Block_Effect_Count; - Assert(Layer->Block_Effect_Count < 2); + // Assert(Layer->Block_Effect_Count < 2); while (*h < Amount) { - if (*h < AmountOf(Layer->Property)) { + if (*h < AmountOf(Layer->Property) && *c == 0) { *Property = &Layer->Property[*h]; if (*h != 0) { *SortedProperty += 1; @@ -477,12 +495,13 @@ Layer_LoopChannels(project_state *State, memory *Memory, sorted_property_info ** while (*c < EffectHeader->Property_Count) { // header_property ChannelHeader = State->Property[EffectHeader->PropertyStartIndex + c]; *Property = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect->Block_Property_Index[*c]); + *SortedProperty += 1; *SortedKeyframe += *p; *p = (**Property).Keyframe_Count; - *h += 1; *c += 1; return 1; } + *h += 1; *c = 0; } } @@ -490,6 +509,53 @@ Layer_LoopChannels(project_state *State, memory *Memory, sorted_property_info ** return 0; } +static void +Layer_ToggleAllChannels(project_state *State, memory *Memory, block_layer *Layer, + sorted_comp_info *SortedCompInfo, sorted_layer *SortedLayerInfo, + sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray) +{ + bool32 ToggleMode = 1; + { + sorted_property_info *InfoLocation = SortedPropertyInfo + SortedLayerInfo->SortedPropertyStart; + uint16 *ArrayLocation = SortedPropertyArray + SortedLayerInfo->SortedKeyframeStart; + int h = 0, c = 0, p = 0; + property_channel *Property = NULL; + block_effect *Effect = NULL; + while (Layer_LoopChannels(State, Memory, &InfoLocation, &ArrayLocation, Layer, &Property, &Effect, &h, &c, &p)) + { + if (Property->IsToggled) { + ToggleMode = 0; + break; + } + } + } + sorted_property_info *InfoLocation = SortedPropertyInfo + SortedLayerInfo->SortedPropertyStart; + uint16 *ArrayLocation = SortedPropertyArray + SortedLayerInfo->SortedKeyframeStart; + int h = 0, c = 0, p = 0; + property_channel *Property = NULL; + block_effect *Effect = NULL; + while (Layer_LoopChannels(State, Memory, &InfoLocation, &ArrayLocation, Layer, &Property, &Effect, &h, &c, &p)) + { + if (Property->Keyframe_Count) { + Property->IsToggled = ToggleMode; + } + } +} + +static void +Project_ToggleAllChannels(project_data *File, project_state *State, memory *Memory, + sorted_comp_info *SortedCompInfo, sorted_layer *SortedLayerInfo, + sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray) +{ + int h = 0, c = 0, i = 0; + while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) { + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); + if (Layer->IsSelected) { + Layer_ToggleAllChannels(State, Memory, Layer, SortedCompInfo, SortedLayerInfo, SortedPropertyInfo, SortedPropertyArray); + } + } +} + inline sorted_property_info * Property_GetSortedInfo(sorted_property_info *SortedPropertyInfo, int i, int h) { @@ -503,17 +569,36 @@ Property_GetSortedArray(uint16 *SortedPropertyArray, int i, int h) return SortedPropertyArray + (i * 8 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK); } +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; +} + static void -Bezier_Commit(project_data *File, project_state *State, memory *Memory, uint16 *SortedPropertyArray) { +Bezier_Commit(project_data *File, project_state *State, memory *Memory, + sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, + sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray) +{ History_Entry_Commit(Memory, "Move keyframe"); int h = 0, c = 0, i = 0; while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) { block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); + sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray, Layer->Block_Composition_Index); if ((State->TimelineMode == timeline_mode_graph) && !Layer->IsSelected) continue; - for (int h = 0; h < AmountOf(Layer->Property); h++) { - uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h); - property_channel *Property = &Layer->Property[h]; + sorted_property_info *InfoLocation = SortedPropertyInfo + SortedLayerInfo->SortedPropertyStart; + uint16 *ArrayLocation = SortedPropertyArray + SortedLayerInfo->SortedKeyframeStart; + int h = 0, c = 0, p = 0; + property_channel *Property = NULL; + block_effect *Effect = NULL; + while (Layer_LoopChannels(State, Memory, &InfoLocation, &ArrayLocation, Layer, &Property, &Effect, &h, &c, &p)) + { if ((State->TimelineMode != timeline_mode_graph) && !Property->IsToggled) continue; for (int p = 0; p < Property->Keyframe_Count; p++) { @@ -582,6 +667,8 @@ void Clipboard_Paste(project_data *File, project_state *State, memory *Memory, s break; // NOTE(fox): This loop assumes all layers and the clipboard have // channels laid out in the same way! + Assert(0); + /* for (int h = 0; h < AmountOf(Layer->Property); h++) { property_channel *Property = &Layer->Property[h]; if (Property->Name == Channel->Name) { @@ -589,7 +676,7 @@ void Clipboard_Paste(project_data *File, project_state *State, memory *Memory, s bezier_point PointData = *(bezier_point *)((uint8 *)State->ClipboardBuffer + ClipboardPos); PointData.Pos[0].x += State->Frame_Current; uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h); - Bezier_Add(Memory, Property, PointData, ArrayLocation); + Bezier_Add(Memory, F_Layers, Property, PointData, ArrayLocation); ClipboardPos += sizeof(bezier_point); } b++; @@ -603,6 +690,7 @@ void Clipboard_Paste(project_data *File, project_state *State, memory *Memory, s else b = 0; } + */ } } @@ -648,7 +736,8 @@ void Clipboard_Store(project_data *File, project_state *State, memory *Memory, s LocalOffset = i; Contents->ChannelCount++; Channel->LayerOffset = LocalOffset - i; - Channel->Name = Property->Name; + Assert(0); + // Channel->Name = Property->Name; } } } @@ -658,17 +747,6 @@ void Clipboard_Store(project_data *File, project_state *State, memory *Memory, s } } -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; -} - static void Layer_Select_Traverse(uint16 PrincipalCompIndex, memory *Memory, project_state *State, int32 IndexToFind, sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, int16 RecursionIdx[MAX_PRECOMP_RECURSIONS], int32 *Recursions) @@ -734,8 +812,22 @@ int32 Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_c block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, PrincipalIndex); sorted_comp_info SortedCompInfo = SortedCompArray[PrincipalIndex]; sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray, PrincipalIndex); + int SelectionCount = 0; + int SelectedLayerIndex = 0; + for (int i = SortedCompInfo.LayerCount - 1; i >= 0; i--) { + sorted_layer SortEntry = SortedLayerInfo[i]; + uint32 Index_Physical = SortEntry.Block_Layer_Index; + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical); + block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); + layer_transforms T = Layer_GetTransforms(Layer); + v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Source->Width, Source->Height, State->TempZoomRatio); + if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && Layer->IsSelected) + { + SelectionCount++; + SelectedLayerIndex = i; + } + } int32 LayerIndex = -1; - // for (int i = 0; i < SortedCompInfo.LayerCount; i++) { for (int i = SortedCompInfo.LayerCount - 1; i >= 0; i--) { sorted_layer SortEntry = SortedLayerInfo[i]; uint32 Index_Physical = SortEntry.Block_Layer_Index; @@ -745,8 +837,15 @@ int32 Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_c v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Source->Width, Source->Height, State->TempZoomRatio); if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && !Layer->IsSelected) { - LayerIndex = Index_Physical; - break; + if (SelectionCount == 1) { + if (i < SelectedLayerIndex) { + LayerIndex = Index_Physical; + break; + } + } else { + LayerIndex = Index_Physical; + break; + } } // if (Layer->IsPrecomp) { // Layer_RecursiveDeselect(Memory, SortedCompArray, SortedLayerArray, TargetIndex, Layer->Block_Source_Index); @@ -808,6 +907,55 @@ void Property_MinMax_Y(memory *Memory, project_state *State, property_channel *P } } +inline property_channel * +Effect_Property(memory *Memory, block_effect *Effect, int Offset) +{ + return (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect->Block_Property_Index[Offset]); +}; + +inline v2 Effect_V2(memory *Memory, block_effect *Effect, int Offset) +{ + property_channel *Property_X = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect->Block_Property_Index[Offset]); + property_channel *Property_Y = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect->Block_Property_Index[Offset + 1]); + return V2(Property_X->CurrentValue, Property_Y->CurrentValue); +} + +// TODO(fox): Merge with other sorting code. +void Effect_Curves_Sort(memory *Memory, block_effect *Effect, uint16 *SortedPointStart, uint16 Which) +{ + int i = 0; + int SortedPoints = 0; + for (;;) { + property_channel *CurrentProperty = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect->Block_Property_Index[i]); + v2 Point = Effect_V2(Memory, Effect, i); + uint32 SortedIndex_Playhead = 0; + if (CurrentProperty->Identifier == Which) { + while (SortedIndex_Playhead < SortedPoints) { + uint16 TestPointEntry = SortedPointStart[SortedIndex_Playhead]; + Assert(((property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect->Block_Property_Index[TestPointEntry]))->Identifier == Which); + v2 TestPoint = Effect_V2(Memory, Effect, TestPointEntry); + if (Point.x < TestPoint.x) { + break; + } else { + SortedIndex_Playhead += 1; + } + } + if (SortedIndex_Playhead != SortedPoints) { + uint8 *Address_Start = (uint8 *)(SortedPointStart + SortedIndex_Playhead); + uint8 *Address_End = (uint8 *)(SortedPointStart + SortedPoints) - 1; + Arbitrary_ShiftData(Address_Start, Address_End, sizeof(uint16), 1); + } + + uint16 *PointEntry = SortedPointStart + SortedIndex_Playhead; + *PointEntry = i; + SortedPoints++; + } + i += 2; + if (i > (MAX_PROPERTIES_PER_EFFECT - 1)) + break; + } +} + // The sorting algorithm is straightforward: read every point, evaluate it if // it's currently being interacted with by the user, record index in a sorted // list, and repeat, shiftig the list as necessary. @@ -816,15 +964,16 @@ void Property_SortAll(memory *Memory, project_state *State, property_channel *Pr { int h = 0, c = 0, i = 0; uint32 CurrentSortIndex = 0; - real32 MinY = FLT_MAX; - real32 MaxY = FLT_MIN; + real32 MinY = 1000000; + real32 MaxY = -1000000; int32 Offset = (State->Interact_Active == interact_type_keyframe_move) ? (int32)State->Interact_Offset[0] : 0; while (Block_Loop(Memory, Property, Property->Keyframe_Count, &h, &c, &i)) { v2 PointPos[3]; bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, i); - if (PointAddress->IsSelected) + if (PointAddress->IsSelected) { PropertyInfo->IsGraphSelected = true; + } Bezier_EvaluateValue(State, PointAddress, PointPos); @@ -861,16 +1010,23 @@ void Property_SortAll(memory *Memory, project_state *State, property_channel *Pr } } -void Property_DeselectAll(project_data *File, memory *Memory, uint16 *SortedPropertyArray) +void Property_DeselectAll(project_data *File, project_state *State, memory *Memory, + sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, + sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray) { int h = 0, c = 0, i = 0; while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) { block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); if (!Layer->IsSelected) continue; - 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); + sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray, Layer->Block_Composition_Index); + sorted_property_info *InfoLocation = SortedPropertyInfo + SortedLayerInfo->SortedPropertyStart; + uint16 *ArrayLocation = SortedPropertyArray + SortedLayerInfo->SortedKeyframeStart; + int h = 0, c = 0, p = 0; + property_channel *Property = NULL; + block_effect *Effect = NULL; + while (Layer_LoopChannels(State, Memory, &InfoLocation, &ArrayLocation, Layer, &Property, &Effect, &h, &c, &p)) + { for (int p = 0; p < Property->Keyframe_Count; p++) { int k = ArrayLocation[p]; bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, k); @@ -899,11 +1055,19 @@ void Layer_Sort_CheckPrev(memory *Memory, int i, int Direction, sorted_layer *So } } -void Layer_Evaluate_Display(block_layer *Layer, sorted_layer *LayerArrayStart, sorted_comp_info *CompStart, sorted_layer *SortedLayerInfo, int i, real32 *Offset) +void Layer_Evaluate_Display(project_state *State, memory *Memory, block_layer *Layer, + sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray, + sorted_layer *LayerArrayStart, sorted_comp_info *CompStart, sorted_layer *SortedLayerInfo, + int i, real32 *Offset) { int ExtraPad = 1; - for (int h = 0; h < AmountOf(Layer->Property); h++) { - property_channel *Property = &Layer->Property[h]; + sorted_property_info *InfoLocation = SortedPropertyInfo + SortedLayerInfo->SortedPropertyStart; + uint16 *ArrayLocation = SortedPropertyArray + SortedLayerInfo->SortedKeyframeStart; + int h = 0, c = 0, p = 0; + property_channel *Property = NULL; + block_effect *Effect = NULL; + while (Layer_LoopChannels(State, Memory, &InfoLocation, &ArrayLocation, Layer, &Property, &Effect, &h, &c, &p)) + { if (Property->IsToggled) { *Offset += 1 + ExtraPad; ExtraPad = 0; @@ -954,8 +1118,8 @@ void TempSource_SortAll(project_data *File, project_state *State, memory *Memory // second is for sorting the layers by offset, and the third is for applying // interactivity if the user is moving any layers. -void Layer_SortAll(project_data *File, project_state *State, memory *Memory, sorted_layer *LayerArrayStart, - sorted_comp_info *CompStart, sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray, +void Layer_SortAll(project_data *File, project_state *State, memory *Memory, + sorted_layer *LayerArrayStart, sorted_comp_info *CompStart, uint32 LayerCount, uint32 CompCount) { int h = 0, c = 0, i = 0; @@ -1029,6 +1193,45 @@ void Layer_SortAll(project_data *File, project_state *State, memory *Memory, sor } } +// NOTE(fox): We could be slightly more efficient and just allocate redundant data +// instead of having another loop. +void LayerProperty_Allocate(project_data *File, project_state *State, memory *Memory, sorted_layer *LayerArrayStart, + sorted_comp_info *CompStart, uint32 LayerCount, uint32 CompCount, + uint32 *TotalPropertyCount, uint32 *TotalKeyframeCount) +{ + uint32 SortedPropertyPlayhead = 0; + uint32 SortedKeyframePlayhead = 0; + for (int c = 0; c < CompCount; c++) { + sorted_comp_info SortedCompInfo = CompStart[c]; + sorted_layer *SortedLayerInfo = Layer_GetSortedArray(LayerArrayStart, CompStart, c); + for (int i = 0; i < SortedCompInfo.LayerCount; i++) { + sorted_layer *SortedLayer = &SortedLayerInfo[i]; + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, SortedLayer->Block_Layer_Index); + SortedLayer->SortedPropertyStart = SortedPropertyPlayhead; + SortedLayer->SortedKeyframeStart = SortedKeyframePlayhead; + for (int h = 0; h < AmountOf(Layer->Property); h++) { + property_channel *Property = &Layer->Property[h]; + if (Property->Keyframe_Count) { + SortedKeyframePlayhead += Property->Keyframe_Count; + } + SortedPropertyPlayhead++; + } + for (int i = 0; i < Layer->Block_Effect_Count; i++) { + block_effect Effect = *(block_effect *)Memory_Block_AddressAtIndex(Memory, F_Effects, Layer->Block_Effect_Index[i]); + header_effect *EffectHeader = Effect_EntryFromID(State, Effect.ID); + for (int h = 0; h < EffectHeader->Property_Count; h++) { + header_property ChannelHeader = State->Property[EffectHeader->PropertyStartIndex + h]; + property_channel *Property = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect.Block_Property_Index[h]); + if (Property->Keyframe_Count) { + SortedKeyframePlayhead += Property->Keyframe_Count; + } + SortedPropertyPlayhead++; + } + } + } + } +} + void LayerProperty_SortAll(project_data *File, project_state *State, memory *Memory, sorted_layer *LayerArrayStart, sorted_comp_info *CompStart, sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray, uint32 LayerCount, uint32 CompCount) @@ -1089,8 +1292,11 @@ sorted_file File_Sort_Push(project_data *File, project_state *State, memory *Mem Arbitrary_Zero((uint8 *)Source_SortedArray, Sorted.Source_SortSize); Sorted.SourceArray = (uint16 *)Source_SortedArray; - uint64 PropertyArraySize = sizeof(uint16) * 8 * MAX_KEYFRAMES_PER_BLOCK * File->Layer_Count; - uint64 PropertyInfoSize = sizeof(sorted_property_info) * 8 * File->Layer_Count; + uint32 TotalPropertyCount = 0; + uint32 TotalKeyframeCount = 0; + LayerProperty_Allocate(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, File->Layer_Count, File->Comp_Count, &TotalPropertyCount, &TotalKeyframeCount); + uint64 PropertyInfoSize = TotalPropertyCount * sizeof(sorted_property_info); + uint64 PropertyArraySize = TotalKeyframeCount * sizeof(uint16); Sorted.Property_SortSize = PropertyArraySize + PropertyInfoSize; void *Property_SortedArray = Memory_PushScratch(Memory, Sorted.Property_SortSize); Arbitrary_Zero((uint8 *)Property_SortedArray, Sorted.Property_SortSize); @@ -1098,7 +1304,7 @@ sorted_file File_Sort_Push(project_data *File, project_state *State, memory *Mem Sorted.PropertyArray = (uint16 *)((uint8 *)Property_SortedArray + PropertyInfoSize); TempSource_SortAll(File, State, Memory, Sorted.SourceArray, &Sorted.TempSourceCount); - Layer_SortAll(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, Sorted.PropertyInfo, Sorted.PropertyArray, File->Layer_Count, File->Comp_Count); + Layer_SortAll(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, File->Layer_Count, File->Comp_Count); LayerProperty_SortAll(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, Sorted.PropertyInfo, Sorted.PropertyArray, File->Layer_Count, File->Comp_Count); return Sorted; } @@ -1138,14 +1344,14 @@ block_layer * Layer_Init(project_data *File, memory *Memory) 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); - Layer->ax = Property_InitFloat("Anchor X", 0.5f, 0.005f); - Layer->ay = Property_InitFloat("Anchor Y", 0.5f, 0.005f); - Layer->scale = Property_InitFloat("Scale", 1.0f, 0.005f); - Layer->rotation = Property_InitFloat("Rotation", 0.0f, 1.0f); - 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, 1); + Layer->x = Property_InitFloat(0.0f, 1.0f); + Layer->y = Property_InitFloat(0.0f, 1.0f); + Layer->ax = Property_InitFloat(0.5f, 0.005f); + Layer->ay = Property_InitFloat(0.5f, 0.005f); + Layer->scale = Property_InitFloat(1.0f, 0.005f); + Layer->rotation = Property_InitFloat(0.0f, 1.0f); + Layer->opacity = Property_InitFloat(1.0f, 0.005f, 0.0f, 1.0f); + Layer->time = Property_InitFloat(0.0f, 1.0f, 0, 100000, 1); Layer->IsVisible = 1; @@ -1265,8 +1471,8 @@ void Precomp_UICreateButton(project_data *File, project_state *State, memory *Me block_layer *PrecompLayer = Layer_Init(File, Memory); bezier_point Point0 = { 1, {0, 0, 1, 0, 1, 0}, interpolation_type_linear, 0, {0, 0, 0}, 0 }; bezier_point Point1 = { 1, {(real32)NewComp->Frame_End, (real32)NewComp->Frame_End, 1, 0, 1, 0}, interpolation_type_linear, 0, {0, 0, 0}, 0 }; - Bezier_Add(Memory, &PrecompLayer->time, Point0, NULL); - Bezier_Add(Memory, &PrecompLayer->time, Point1, NULL); + Bezier_Add(Memory, F_Layers, &PrecompLayer->time, Point0, NULL); + Bezier_Add(Memory, F_Layers, &PrecompLayer->time, Point1, NULL); PrecompLayer->IsPrecomp = true; Layer_Select(Memory, State, Memory_Block_LazyIndexAtAddress(Memory, F_Layers, PrecompLayer)); PrecompLayer->Block_Source_Index = File->Comp_Count - 1; |