diff options
Diffstat (limited to 'createcalls.cpp')
-rw-r--r-- | createcalls.cpp | 195 |
1 files changed, 122 insertions, 73 deletions
diff --git a/createcalls.cpp b/createcalls.cpp index 176fc2f..01f1caa 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -67,13 +67,37 @@ Source_Generate(project_data *File, project_state *State, memory *Memory, void * } static bezier_point * -Bezier_Lookup(memory *Memory, property_channel *Property, uint16 Index) +Bezier_LookupAddress(memory *Memory, property_channel *Property, uint16 Index) { Assert(Index < MAX_KEYFRAMES_PER_BLOCK); block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(Memory, F_Bezier, Property->Block_Bezier_Index[0]); return &Bezier->Point[Index]; } +/* +if (State->Interact_Active == interact_type_keyframe_rotate) { + ImVec2 Keyframe_LocalPos_Ratio = (V2(Keyframe_LocalPos_[0]) - ImVec2(0, GraphInfo.MinVal)) * ImVec2(Increment.x, Y_Increment); + ImVec2 Keyframe_ScreenPos = Layer_ScreenPos_Min + ((ImVec2(1, -1) * Keyframe_LocalPos_Ratio + ImVec2(0, 0.5)) * TimelineZoomSize) + ImVec2(0, Layer_ScreenSize.y/2); + real32 Slope_Old = (Keyframe_ScreenPos.y - State->Interact_Offset[3]) / (Keyframe_ScreenPos.x - State->Interact_Offset[2]); + real32 Slope_New = (Keyframe_ScreenPos.y - io.MousePos.y) / (Keyframe_ScreenPos.x - io.MousePos.x); + State->Interact_Offset[0] = atan((Slope_Old - Slope_New) / (1 + Slope_Old * Slope_New)); + DebugWatchVar("Rotation: ", &State->Interact_Offset[0], d_float); +} +*/ +// Keyframe_Interact_Evaluate(Memory, State, Point->IsSelected, Point->Pos, Keyframe_LocalPos_); + + +static void +Bezier_EvaluateValue(project_state *State, bezier_point *PointAddress, v2 *Pos) +{ + Pos[0] = PointAddress->Pos[0]; + Pos[1] = PointAddress->Pos[1]; + Pos[2] = PointAddress->Pos[2]; + if (State->Interact_Active == interact_type_keyframe_move && PointAddress->IsSelected) { + Pos[0].x += (int32)State->Interact_Offset[0]; + } +} + static void Bezier_Add(memory *Memory, property_channel *Property, bezier_point PointData) { @@ -87,7 +111,7 @@ Bezier_Add(memory *Memory, property_channel *Property, bezier_point PointData) } int k = 0; for (;;) { - bezier_point *Point = Bezier_Lookup(Memory, Property, k); + bezier_point *Point = Bezier_LookupAddress(Memory, Property, k); if (!Point->Occupied) { History_Action_Swap(Memory, F_Bezier, sizeof(*Point), Point); *Point = PointData; @@ -110,45 +134,6 @@ Property_InitFloat(char *Name, real32 Val, real32 ScrubVal, real32 MinVal = PROP return Property; } -// static property_info -// Property_Sort(memory *Memory, property_channel *Property) -// { -// } - -static property_info -Property_GetInfo(memory *Memory, property_channel *Property) -{ - property_info PropertyInfo = {}; - int h = 0, c = 0, i = 0; - while (Block_Loop(Memory, Property, Property->Keyframe_Count, &h, &c, &i)) { - bezier_point *Point = Bezier_Lookup(Memory, Property, i); - PropertyInfo.MinVal = (Point->Pos[0].y < PropertyInfo.MinVal) ? Point->Pos[0].y : PropertyInfo.MinVal; - PropertyInfo.MaxVal = (Point->Pos[0].y > PropertyInfo.MaxVal) ? Point->Pos[0].y : PropertyInfo.MaxVal; - } - return PropertyInfo; -} - -static graph_info -Graph_GetInfo(project_data *File, memory *Memory) -{ - graph_info GraphInfo = {}; - for (int a = 0; a < File->Layer_Count; a++) { - block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, a); - if (!Layer->IsSelected) - continue; - for (int h = 0; h < AmountOf(Layer->Property); h++) { - property_channel *Property = &Layer->Property[h]; - if (Property->Block_Bezier_Count) { - property_info PropertyInfo = Property_GetInfo(Memory, Property); - GraphInfo.MinVal = (PropertyInfo.MinVal < GraphInfo.MinVal) ? PropertyInfo.MinVal : GraphInfo.MinVal; - GraphInfo.MaxVal = (PropertyInfo.MaxVal > GraphInfo.MaxVal) ? PropertyInfo.MaxVal : GraphInfo.MaxVal; - } - } - GraphInfo.LowestOffset = (Layer->Vertical_Offset > GraphInfo.LowestOffset) ? Layer->Vertical_Offset : GraphInfo.LowestOffset; - } - return GraphInfo; -} - static void Keyframe_Interact_Evaluate(memory *Memory, project_state *State, uint8 IsSelected, v2 Pos_Initial[3], v2 Pos_New[3]) { @@ -303,63 +288,98 @@ void Layer_RecursiveDeselect(memory *Memory, sorted_comp_info *SortedCompArray, } } -void Layer_Sort_CheckPrev(memory *Memory, int i, int Direction, sorted_layer *SortedLayerInfo, sorted_comp_info SortedCompInfo, int *EntriesPassed, sorted_layer *LayerEntry) +void Property_MinMax(memory *Memory, project_state *State, property_channel *Property, uint16 *ArrayLocation, v2 *Min, v2 *Max) { - int PrevOffsetIndex = i + Direction + (*EntriesPassed * Direction); - bool32 OutOfBounds = (Direction > 0) ? (PrevOffsetIndex > (SortedCompInfo.LayerCount - 1)) : (PrevOffsetIndex < 0); - if (!OutOfBounds) { - sorted_layer *PrevLayerEntry = &SortedLayerInfo[PrevOffsetIndex]; - // block_layer *PrevLayer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, PrevLayerEntry->Block_Layer_Index); - // real32 PrevOffset = PrevLayer->Vertical_Offset; - real32 PrevOffset = PrevLayerEntry->SortedOffset; - if (PrevOffset == (LayerEntry->SortedOffset - Direction)) { - LayerEntry->SortedOffset -= Direction; - (*EntriesPassed)++; - Layer_Sort_CheckPrev(Memory, i, Direction, SortedLayerInfo, SortedCompInfo, EntriesPassed, LayerEntry); - } + v2 FirstPointPos[3]; + bezier_point *FirstPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[0]); + Bezier_EvaluateValue(State, FirstPointAddress, FirstPointPos); + Min->x = FirstPointPos[0].x; + v2 LastPointPos[3]; + bezier_point *LastPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[Property->Keyframe_Count - 1]); + Bezier_EvaluateValue(State, LastPointAddress, LastPointPos); + Max->x = LastPointPos[0].x; + int32 Offset = (State->Interact_Active == interact_type_keyframe_move) ? (int32)State->Interact_Offset[0] : 0; + real32 MinY = FLT_MAX; + real32 MaxY = FLT_MIN; + for (int p = 0; p < Property->Keyframe_Count; p++) { + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[p]); + MinY = (MinY < PointAddress->Pos[0].y) ? MinY : PointAddress->Pos[0].y; + MaxY = (MaxY > PointAddress->Pos[0].y) ? MaxY : PointAddress->Pos[0].y; } + Min->y = MinY; + Max->y = MaxY; } -// TODO(fox): This _could_ be generalized with the layer sorting code... +// 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. -/* -Bezier_SortAll() +void Property_SortAll(memory *Memory, project_state *State, property_channel *Property, uint16 *PropertyArrayStart) { - 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_comp_info *SortedCompInfo = &CompStart[Layer->Block_Composition_Index]; - sorted_layer *SortedLayerInfo = Layer_GetSortedArray(LayerArrayStart, CompStart, Layer->Block_Composition_Index); + int h = 0, c = 0, i = 0; + uint32 CurrentSortIndex = 0; + 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); + Bezier_EvaluateValue(State, PointAddress, PointPos); uint32 SortedIndex_Playhead = 0; while (SortedIndex_Playhead < 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) { + uint16 TestPointEntry = PropertyArrayStart[SortedIndex_Playhead]; + v2 TestPointPos[3]; + bezier_point *TestPointAddress = Bezier_LookupAddress(Memory, Property, TestPointEntry); + Bezier_EvaluateValue(State, TestPointAddress, TestPointPos); + if (PointPos[0].x < TestPointPos[0].x ) { break; } else { SortedIndex_Playhead++; } } if (SortedIndex_Playhead != CurrentSortIndex) { - uint8 *Address_Start = (uint8 *)(SortedLayerInfo + SortedIndex_Playhead); - uint8 *Address_End = (uint8 *)(SortedLayerInfo + CurrentSortIndex) - 1; - Assert(CurrentSortIndex != SortedCompInfo->LayerCount); - Arbitrary_ShiftData(Address_Start, Address_End, sizeof(sorted_layer), 1); + uint8 *Address_Start = (uint8 *)(PropertyArrayStart + SortedIndex_Playhead); + uint8 *Address_End = (uint8 *)(PropertyArrayStart + CurrentSortIndex) - 1; + Assert(CurrentSortIndex != Property->Keyframe_Count); + Arbitrary_ShiftData(Address_Start, Address_End, sizeof(uint16), 1); } - sorted_layer *LayerEntry = SortedLayerInfo + SortedIndex_Playhead; - LayerEntry->Block_Layer_Index = i; - LayerEntry->SortedOffset = Layer->Vertical_Offset; + uint16 *PointEntry = PropertyArrayStart + SortedIndex_Playhead; + *PointEntry = i; CurrentSortIndex++; } } -*/ -void Layer_SortAll(project_data *File, project_state *State, memory *Memory, sorted_layer *LayerArrayStart, sorted_comp_info *CompStart, uint32 LayerCount, uint32 CompCount) +void Layer_Sort_CheckPrev(memory *Memory, int i, int Direction, sorted_layer *SortedLayerInfo, sorted_comp_info SortedCompInfo, int *EntriesPassed, sorted_layer *LayerEntry) +{ + int PrevOffsetIndex = i + Direction + (*EntriesPassed * Direction); + bool32 OutOfBounds = (Direction > 0) ? (PrevOffsetIndex > (SortedCompInfo.LayerCount - 1)) : (PrevOffsetIndex < 0); + if (!OutOfBounds) { + sorted_layer *PrevLayerEntry = &SortedLayerInfo[PrevOffsetIndex]; + real32 PrevOffset = PrevLayerEntry->SortedOffset; + if (PrevOffset == (LayerEntry->SortedOffset - Direction)) { + LayerEntry->SortedOffset -= Direction; + (*EntriesPassed)++; + Layer_Sort_CheckPrev(Memory, i, Direction, SortedLayerInfo, SortedCompInfo, EntriesPassed, LayerEntry); + } + } +} + +// The first loop is for counting how many layers are in each precomp, the +// 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, uint16 *SortedPropertyArray, uint32 LayerCount, uint32 CompCount) { 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); 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) { + uint16 *ArrayLocation = SortedPropertyArray + (i * 7 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK); + Property_SortAll(Memory, State, Property, ArrayLocation); + } + } } h = 0, c = 0, i = 0; uint32 CurrentSortIndex = 0; @@ -427,6 +447,35 @@ void Layer_SortAll(project_data *File, project_state *State, memory *Memory, sor } } +sorted_file File_Sort_Push(project_data *File, project_state *State, memory *Memory) +{ + sorted_file Sorted = {0}; + Sorted.Layer_SortSize = (sizeof(sorted_comp_info) * File->Comp_Count) + + (sizeof(sorted_layer) * File->Layer_Count); + void *Layer_SortedArray = Memory_PushScratch(Memory, Sorted.Layer_SortSize); + Arbitrary_Zero((uint8 *)Layer_SortedArray, Sorted.Layer_SortSize); + Sorted.CompArray = (sorted_comp_info *)Layer_SortedArray; + Sorted.LayerArray = (sorted_layer *)((uint8 *)Layer_SortedArray + (sizeof(sorted_comp_info) * File->Comp_Count)); + + uint64 PropertyArraySize = sizeof(uint16) * 7 * MAX_KEYFRAMES_PER_BLOCK * File->Layer_Count; + uint64 PropertyInfoSize = sizeof(sorted_property_info) * 7 * File->Layer_Count; + Sorted.Property_SortSize = PropertyArraySize + PropertyInfoSize; + void *Property_SortedArray = Memory_PushScratch(Memory, Sorted.Property_SortSize); + Arbitrary_Zero((uint8 *)Property_SortedArray, Sorted.Property_SortSize); + Sorted.PropertyInfo = (sorted_property_info *)Property_SortedArray; + Sorted.PropertyArray = (uint16 *)((uint8 *)Property_SortedArray + PropertyInfoSize); + + Layer_SortAll(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, Sorted.PropertyArray, File->Layer_Count, File->Comp_Count); + return Sorted; +} + +void File_Sort_Pop(memory *Memory, uint64 Layer_SortSize, uint64 Property_SortSize) +{ + Memory_PopScratch(Memory, Property_SortSize); + Memory_PopScratch(Memory, Layer_SortSize); +} + + static void Layer_Delete(project_data *File, memory *Memory, uint32 Index) { |