diff options
Diffstat (limited to 'src/sorted.cpp')
-rw-r--r-- | src/sorted.cpp | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/src/sorted.cpp b/src/sorted.cpp index 3ecd69e..c039c08 100644 --- a/src/sorted.cpp +++ b/src/sorted.cpp @@ -292,36 +292,66 @@ Layer_SortAll(project_state *State, memory *Memory, if (!SortedCompStart->LayerCount) continue; sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(LayerArrayStart, CompArrayStart, c); - int i = 0; + int Direction = (State->DuplicateMode & sortflag_up) ? 1 : -1; + int Furthest = (State->DuplicateMode & sortflag_furthest) ? 1 : 0; + if (Furthest) { Direction *= -1; } + int i = (Direction > 0) ? 0 : SortedCompStart->LayerCount - 1; int FauxIncrement = 0; - while (i < SortedCompStart->LayerCount) { - int Idx = i + FauxIncrement; + int FurthestMark = -1; + for (;;) { + int Idx = i + ((Direction > 0) ? FauxIncrement : 0); + if (FauxIncrement && Furthest && (Direction > 0)) { + Idx = i + SortedCompStart->FakeLayerCount; + } sorted_layer_array *LayerEntry = &SortedLayerStart[Idx]; block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, LayerEntry->Block_Layer_Index); if (Layer->IsSelected & 0x01) { - // Sort_OffsetDupes(Memory, SortedLayerStart, Layer, LayerEntry, i, FauxIncrement, SortedCompStart->LayerCount, 1); - 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; - FakeLayerEntry->SortedOffset -= 1; - Assert(FakeLayerEntry->Block_Layer_Index == LayerEntry->Block_Layer_Index); - FakeLayerEntry->IsFake = true; - FauxIncrement++; - - sorted_layer_array *PrevLayerEntry = FakeLayerEntry; - for (int a = i+1; a < SortedCompStart->LayerCount; a++) { - int NextIdx = a + FauxIncrement; - sorted_layer_array *NextLayerEntry = &SortedLayerStart[NextIdx]; - if (NextLayerEntry->SortedOffset == PrevLayerEntry->SortedOffset) - NextLayerEntry->SortedOffset -= 1; - else - break; - PrevLayerEntry = NextLayerEntry; + if (Furthest) { + if (FauxIncrement == 0) { + 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) * SortedCompStart->FakeLayerCount, 1); + FurthestMark = i + ((Direction > 0) ? 0 : -Direction); + } + sorted_layer_array *FakeLayerEntry = &SortedLayerStart[FurthestMark + (FauxIncrement * ((Direction > 0) ? 1 : -Direction))]; + *FakeLayerEntry = *LayerEntry; + FakeLayerEntry->IsFake = true; + FauxIncrement++; + } else { + 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 + ((Direction > 0) ? 1 : 0); + Assert(FakeLayerEntry->Block_Layer_Index == LayerEntry->Block_Layer_Index); + FakeLayerEntry->IsFake = true; + FauxIncrement++; } } - i++; + if ((Direction > 0) ? !(i < SortedCompStart->LayerCount) : (i <= 0)) + break; + i += Direction; + } + if (Furthest) { Direction *= -1; } + i = FauxIncrement = 0; + int LayerCount = SortedCompStart->LayerCount + SortedCompStart->FakeLayerCount; + FurthestMark = -1; + i = (Direction > 0) ? 0 : LayerCount - 1; + for (;;) { + sorted_layer_array *LayerEntry = &SortedLayerStart[i]; + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, LayerEntry->Block_Layer_Index); + if (LayerEntry->IsFake) { + if (FurthestMark == -1) + FurthestMark = Layer->Vertical_Offset; + if (Furthest) + LayerEntry->SortedOffset = FurthestMark; + FauxIncrement += Direction; + } + LayerEntry->SortedOffset -= FauxIncrement; + if ((Direction > 0) ? !(i < LayerCount) : (i <= 0)) + break; + i += Direction; } } } |