From dc0d4a23fdbddef51d5e026f2eefef1731c4e338 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Tue, 29 Nov 2022 21:04:09 -0500 Subject: effects integration halfway --- createcalls.cpp | 120 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 104 insertions(+), 16 deletions(-) (limited to 'createcalls.cpp') diff --git a/createcalls.cpp b/createcalls.cpp index a984454..145a58a 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -242,6 +242,15 @@ Bezier_Add(memory *Memory, property_channel *Property, bezier_point PointData, u } } +static void +Property_AddKeyframe(memory *Memory, 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); + History_Entry_End(Memory); +} + // static void // Property_InitFloat(char *Name, real32 Val, real32 ScrubVal, real32 MinVal = PROPERTY_REAL_MIN, real32 MaxVal = PROPERTY_REAL_MAX, bool32 AlwaysInteger = 0) { // { @@ -440,14 +449,57 @@ void Source_DeselectAll(project_data *File, memory *Memory) } } +// h: index of the total amount of properties and effects +// c: index of the amount of properties in a given effect +// p: prior property's keyframe count, so we can increment the sorted keyframe array properly +static bool32 +Layer_LoopChannels(project_state *State, memory *Memory, sorted_property_info **SortedProperty, uint16 **SortedKeyframe, block_layer *Layer, + 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); + while (*h < Amount) { + if (*h < AmountOf(Layer->Property)) { + *Property = &Layer->Property[*h]; + if (*h != 0) { + *SortedProperty += 1; + *SortedKeyframe += *p; + } + *h += 1; + *p = (**Property).Keyframe_Count; + return 1; + } else { + uint16 EffectIdx = Layer->Block_Effect_Index[*h - AmountOf(Layer->Property)]; + block_effect *Effect = (block_effect *)Memory_Block_AddressAtIndex(Memory, F_Effects, EffectIdx); + if (EffectOut) + *EffectOut = Effect; + header_effect *EffectHeader = Effect_EntryFromID(State, Effect->ID); + 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]); + *SortedKeyframe += *p; + *p = (**Property).Keyframe_Count; + *h += 1; + *c += 1; + return 1; + } + *c = 0; + } + } + Assert(*h != (Amount - 1)); + return 0; +} + inline sorted_property_info * Property_GetSortedInfo(sorted_property_info *SortedPropertyInfo, int i, int h) { + Assert(0); return SortedPropertyInfo + (i * 8) + h; } inline uint16 * Property_GetSortedArray(uint16 *SortedPropertyArray, int i, int h) { + Assert(0); return SortedPropertyArray + (i * 8 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK); } @@ -911,15 +963,6 @@ void Layer_SortAll(project_data *File, project_state *State, memory *Memory, sor 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 (int h = 0; h < AmountOf(Layer->Property); h++) { - property_channel *Property = &Layer->Property[h]; - if (Property->Block_Bezier_Count) { - sorted_property_info *InfoLocation = Property_GetSortedInfo(SortedPropertyInfo, i, h); - uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h); - Property_SortAll(Memory, State, Property, InfoLocation, ArrayLocation); - int x = 0; - } - } } h = 0, c = 0, i = 0; while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) { @@ -986,6 +1029,50 @@ void Layer_SortAll(project_data *File, project_state *State, memory *Memory, sor } } +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) +{ + 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) { + sorted_property_info *InfoLocation = SortedPropertyInfo + SortedPropertyPlayhead; + uint16 *ArrayLocation = SortedPropertyArray + SortedKeyframePlayhead; + Property_SortAll(Memory, State, Property, InfoLocation, ArrayLocation); + 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) { + sorted_property_info *InfoLocation = SortedPropertyInfo + SortedPropertyPlayhead; + uint16 *ArrayLocation = SortedPropertyArray + SortedKeyframePlayhead; + Property_SortAll(Memory, State, Property, InfoLocation, ArrayLocation); + SortedKeyframePlayhead += Property->Keyframe_Count; + } + SortedPropertyPlayhead++; + } + } + } + } + int a = 0; +} + sorted_file File_Sort_Push(project_data *File, project_state *State, memory *Memory) { sorted_file Sorted = {0}; @@ -996,6 +1083,12 @@ sorted_file File_Sort_Push(project_data *File, project_state *State, memory *Mem Sorted.CompArray = (sorted_comp_info *)Layer_SortedArray; Sorted.LayerArray = (sorted_layer *)((uint8 *)Layer_SortedArray + (sizeof(sorted_comp_info) * File->Comp_Count)); + uint64 SourceArraySize = sizeof(uint16) * File->Source_Count; + Sorted.Source_SortSize = SourceArraySize; + void *Source_SortedArray = Memory_PushScratch(Memory, Sorted.Source_SortSize); + 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; Sorted.Property_SortSize = PropertyArraySize + PropertyInfoSize; @@ -1004,21 +1097,16 @@ sorted_file File_Sort_Push(project_data *File, project_state *State, memory *Mem Sorted.PropertyInfo = (sorted_property_info *)Property_SortedArray; Sorted.PropertyArray = (uint16 *)((uint8 *)Property_SortedArray + PropertyInfoSize); - uint64 SourceArraySize = sizeof(uint16) * File->Source_Count; - Sorted.Source_SortSize = SourceArraySize; - void *Source_SortedArray = Memory_PushScratch(Memory, Sorted.Source_SortSize); - Arbitrary_Zero((uint8 *)Source_SortedArray, Sorted.Source_SortSize); - Sorted.SourceArray = (uint16 *)Source_SortedArray; - 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); + LayerProperty_SortAll(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, Sorted.PropertyInfo, Sorted.PropertyArray, File->Layer_Count, File->Comp_Count); return Sorted; } void File_Sort_Pop(memory *Memory, uint64 Layer_SortSize, uint64 Property_SortSize, uint64 Source_SortSize) { - Memory_PopScratch(Memory, Source_SortSize); Memory_PopScratch(Memory, Property_SortSize); + Memory_PopScratch(Memory, Source_SortSize); Memory_PopScratch(Memory, Layer_SortSize); } -- cgit v1.2.3