summaryrefslogtreecommitdiff
path: root/src/sorted.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sorted.cpp')
-rw-r--r--src/sorted.cpp73
1 files changed, 62 insertions, 11 deletions
diff --git a/src/sorted.cpp b/src/sorted.cpp
index 46b9549..08d9d3b 100644
--- a/src/sorted.cpp
+++ b/src/sorted.cpp
@@ -1,3 +1,7 @@
+#if SPECIAL
+#include "main.h"
+#endif
+
inline sorted_property_array *
Property_GetSortedInfo(sorted_property_array *SortedPropertyStart, int i, int h)
@@ -17,7 +21,7 @@ Sorted_GetLayerStart(sorted_layer_array *LayerArrayStart, sorted_comp_array *Sor
{
uint32 LayerOffset = 0; int s = 0;
while (s < TargetComp) {
- LayerOffset += SortedCompStart[s].LayerCount;
+ LayerOffset += SortedCompStart[s].LayerCount + SortedCompStart[s].FakeLayerCount;
s++;
}
return LayerArrayStart + LayerOffset;
@@ -80,7 +84,8 @@ Layer_Sort_DisplayOffset(project_state *State, memory *Memory,
sorted_comp_array *SortedCompStart, sorted_layer_array *SortedLayerStart)
{
int32 DisplayOffset = 0;
- for (int i = SortedCompStart->LayerCount - 1; i >= 0; i--)
+ int LayerCount = SortedCompStart->LayerCount + SortedCompStart->FakeLayerCount;
+ for (int i = LayerCount - 1; i >= 0; i--)
{
sorted_layer_array *SortEntry = &SortedLayerStart[i];
SortEntry->DisplayOffset = DisplayOffset;
@@ -107,7 +112,7 @@ Layer_Sort_DisplayOffset(project_state *State, memory *Memory,
DisplayOffset += InnerCompOffset;
}
}
- if (SortedCompStart->LayerCount > 1) {
+ if (LayerCount > 1) {
sorted_layer_array LayerEntry_Top = SortedLayerStart[SortedCompStart->LayerCount - 1];
sorted_layer_array LayerEntry_Bottom = SortedLayerStart[0];
real32 SmallestY = LayerEntry_Top.SortedOffset;
@@ -155,7 +160,11 @@ Layer_SortAll(project_state *State, memory *Memory,
while (Block_Loop(Memory, F_Layers, LayerCount, &h, &c, &i)) {
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
Assert(Layer->Block_Composition_Index < CompCount);
- CompArrayStart[Layer->Block_Composition_Index].LayerCount++;
+ sorted_comp_array *SortedCompStart = &CompArrayStart[Layer->Block_Composition_Index];
+ SortedCompStart->LayerCount++;
+ if (State->Interact_Active == interact_type_viewport_duplicate && Layer->IsSelected) {
+ SortedCompStart->FakeLayerCount++;
+ }
}
h = 0, c = 0, i = 0;
while (Block_Loop(Memory, F_Layers, LayerCount, &h, &c, &i)) {
@@ -220,12 +229,38 @@ Layer_SortAll(project_state *State, memory *Memory,
}
}
}
+ else if (State->Interact_Active == interact_type_viewport_duplicate) {
+ for (uint32 c = 0; c < CompCount; c++) {
+ sorted_comp_array *SortedCompStart = &CompArrayStart[c];
+ if (!SortedCompStart->LayerCount)
+ continue;
+ sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(LayerArrayStart, CompArrayStart, c);
+ int i = 0;
+ int FauxIncrement = 0;
+ while (i < SortedCompStart->LayerCount) {
+ int Idx = i + FauxIncrement;
+ sorted_layer_array *LayerEntry = &SortedLayerStart[Idx];
+ block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, LayerEntry->Block_Layer_Index);
+ if (Layer->IsSelected) {
+ uint8 *Address_Start = (uint8 *)(LayerEntry);
+ uint8 *Address_End = (uint8 *)(&SortedLayerStart[SortedCompStart->LayerCount + FauxIncrement]) - 1;
+ Assert(SortedCompStart->CurrentSortIndex != (SortedCompStart->LayerCount + SortedCompStart->FakeLayerCount));
+ Arbitrary_ShiftData(Address_Start, Address_End, sizeof(sorted_layer_array), 1);
+ sorted_layer_array *FakeLayerEntry = LayerEntry + 1;
+ Assert(FakeLayerEntry->Block_Layer_Index == LayerEntry->Block_Layer_Index);
+ FakeLayerEntry->IsFake = true;
+ FauxIncrement++;
+ }
+ i++;
+ }
+ }
+ }
}
// NOTE(fox): We could be slightly more efficient and just allocate redundant data
// instead of having another loop.
void LayerProperty_Count(project_data *File, project_state *State, memory *Memory, sorted_layer_array *LayerArrayStart,
- sorted_comp_array *CompStart, uint32 LayerCount, uint32 CompCount,
+ sorted_comp_array *CompStart, uint32 CompCount,
uint32 *TotalPropertyCount, uint32 *TotalKeyframeCount)
{
uint32 SortedPropertyPlayhead = 0;
@@ -233,8 +268,11 @@ void LayerProperty_Count(project_data *File, project_state *State, memory *Memor
for (int c = 0; c < CompCount; c++) {
sorted_comp_array SortedCompStart = CompStart[c];
sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(LayerArrayStart, CompStart, c);
- for (int i = 0; i < SortedCompStart.LayerCount; i++) {
+ int LayerCount = SortedCompStart.LayerCount + SortedCompStart.FakeLayerCount;
+ for (int i = 0; i < LayerCount; i++) {
sorted_layer_array *SortedLayer = &SortedLayerStart[i];
+ if (SortedLayer->IsFake)
+ continue;
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, SortedLayer->Block_Layer_Index);
SortedLayer->SortedPropertyStart = SortedPropertyPlayhead;
SortedLayer->SortedKeyframeStart = SortedKeyframePlayhead;
@@ -265,15 +303,18 @@ void LayerProperty_Count(project_data *File, project_state *State, memory *Memor
void LayerProperty_SortAll(project_data *File, project_state *State, memory *Memory, sorted_layer_array *LayerArrayStart,
sorted_comp_array *CompStart, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray,
- uint32 LayerCount, uint32 CompCount)
+ uint32 CompCount)
{
uint32 SortedPropertyPlayhead = 0;
uint32 SortedKeyframePlayhead = 0;
for (int c = 0; c < CompCount; c++) {
sorted_comp_array SortedCompStart = CompStart[c];
sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(LayerArrayStart, CompStart, c);
- for (int i = 0; i < SortedCompStart.LayerCount; i++) {
+ int LayerCount = SortedCompStart.LayerCount + SortedCompStart.FakeLayerCount;
+ for (int i = 0; i < LayerCount; i++) {
sorted_layer_array *SortedLayer = &SortedLayerStart[i];
+ if (SortedLayer->IsFake)
+ continue;
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, SortedLayer->Block_Layer_Index);
SortedLayer->SortedPropertyStart = SortedPropertyPlayhead;
SortedLayer->SortedKeyframeStart = SortedKeyframePlayhead;
@@ -341,8 +382,18 @@ static sorted_file
File_Sort_Push(project_data *File, project_state *State, memory *Memory)
{
sorted_file Sorted = {0};
+
+ int ExtraLayers = 0;
+ if (State->Interact_Active == interact_type_viewport_duplicate) {
+ 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 < File->Comp_Count);
+ ExtraLayers++;
+ }
+ }
Sorted.Layer_SortSize = (sizeof(sorted_comp_array) * File->Comp_Count) +
- (sizeof(sorted_layer_array) * File->Layer_Count);
+ (sizeof(sorted_layer_array) * (File->Layer_Count + ExtraLayers));
void *Layer_SortedArray = Memory_PushScratch(Memory, Sorted.Layer_SortSize);
Arbitrary_Zero((uint8 *)Layer_SortedArray, Sorted.Layer_SortSize);
Sorted.CompArray = (sorted_comp_array *)Layer_SortedArray;
@@ -361,7 +412,7 @@ File_Sort_Push(project_data *File, project_state *State, memory *Memory)
uint32 TotalPropertyCount = 0;
uint32 TotalKeyframeCount = 0;
- LayerProperty_Count(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, File->Layer_Count, File->Comp_Count, &TotalPropertyCount, &TotalKeyframeCount);
+ LayerProperty_Count(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, File->Comp_Count, &TotalPropertyCount, &TotalKeyframeCount);
uint64 PropertyStartSize = TotalPropertyCount * sizeof(sorted_property_array);
uint64 PropertyArraySize = TotalKeyframeCount * sizeof(uint16);
Sorted.Property_SortSize = PropertyArraySize + PropertyStartSize;
@@ -370,7 +421,7 @@ File_Sort_Push(project_data *File, project_state *State, memory *Memory)
Sorted.PropertyStart = (sorted_property_array *)Property_SortedArray;
Sorted.PropertyArray = (uint16 *)((uint8 *)Property_SortedArray + PropertyStartSize);
- LayerProperty_SortAll(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, Sorted.PropertyStart, Sorted.PropertyArray, File->Layer_Count, File->Comp_Count);
+ LayerProperty_SortAll(File, State, Memory, Sorted.LayerArray, Sorted.CompArray, Sorted.PropertyStart, Sorted.PropertyArray, File->Comp_Count);
sorted_comp_array *MainSortedCompStart = &Sorted.CompArray[File->PrincipalCompIndex];
sorted_layer_array *MainSortedLayerStart = Sorted_GetLayerStart(Sorted.LayerArray, Sorted.CompArray, File->PrincipalCompIndex);