- Removed merge sort implementation

- Use a temporary array and QuickSort (TList.Sort) to sort the initial drawlist
- Clear the drawlist in the TLandscape.FillDrawList method
This commit is contained in:
Andreas Schneider 2009-08-04 18:02:39 +02:00
parent 1f1f5ac7b4
commit 28969d94f7
2 changed files with 11 additions and 54 deletions

View File

@ -224,7 +224,6 @@ type
function GetSerial: Cardinal; function GetSerial: Cardinal;
function Insert(AItem: TWorldItem): PBlockInfo; function Insert(AItem: TWorldItem): PBlockInfo;
function Iterate(var ABlockInfo: PBlockInfo): Boolean; function Iterate(var ABlockInfo: PBlockInfo): Boolean;
procedure Sort;
procedure UpdateShortcuts; procedure UpdateShortcuts;
function UpdateSortOrder(AItem: TWorldItem): PBlockInfo; function UpdateSortOrder(AItem: TWorldItem): PBlockInfo;
{ Events } { Events }
@ -852,7 +851,10 @@ var
drawMapCell: TMapCell; drawMapCell: TMapCell;
drawStatics: TList; drawStatics: TList;
i, x, y: Integer; i, x, y: Integer;
tempDrawList: TList;
begin begin
ADrawList.Clear;
tempDrawList := TList.Create;
for x := AX to AX + AWidth do for x := AX to AX + AWidth do
begin begin
for y := AY to AY + AWidth do for y := AY to AY + AWidth do
@ -868,7 +870,7 @@ begin
drawMapCell.Priority := GetEffectiveAltitude(drawMapCell); drawMapCell.Priority := GetEffectiveAltitude(drawMapCell);
drawMapCell.PriorityBonus := 0; drawMapCell.PriorityBonus := 0;
drawMapCell.PrioritySolver := 0; drawMapCell.PrioritySolver := 0;
ADrawList.Add(drawMapCell); tempDrawList.Add(drawMapCell);
end; end;
end; end;
end; end;
@ -885,12 +887,16 @@ begin
TStaticItem(drawStatics[i]).UpdatePriorities( TStaticItem(drawStatics[i]).UpdatePriorities(
ResMan.Tiledata.StaticTiles[TStaticItem(drawStatics[i]).TileID], ResMan.Tiledata.StaticTiles[TStaticItem(drawStatics[i]).TileID],
ADrawList.GetSerial); ADrawList.GetSerial);
ADrawList.Add(TWorldItem(drawStatics[i])); tempDrawList.Add(drawStatics[i]);
end; end;
end; end;
end; end;
end; end;
ADrawList.Sort;
tempDrawList.Sort(@CompareWorldItems);
for i := 0 to tempDrawList.Count - 1 do
ADrawList.Add(TWorldItem(tempDrawList[i]));
tempDrawList.Free;
end; end;
function TLandscape.GetEffectiveAltitude(ATile: TMapCell): ShortInt; function TLandscape.GetEffectiveAltitude(ATile: TMapCell): ShortInt;
@ -1301,55 +1307,6 @@ begin
Result := ABlockInfo <> nil; Result := ABlockInfo <> nil;
end; end;
//Mergesort
procedure TScreenBuffer.Sort;
function Merge(AHead1, AHead2: PBlockInfo): PBlockInfo;
begin
if AHead1 = nil then
Exit(AHead2);
if AHead2 = nil then
Exit(AHead1);
if CompareWorldItems(AHead1^.Item, AHead2^.Item) < 0 then
begin
Result := AHead1;
Result^.Next := Merge(Result^.Next, AHead2);
end else
begin
Result := AHead2;
Result^.Next := Merge(AHead1, Result^.Next);
end;
end;
function MergeSort(AHead: PBlockInfo): PBlockInfo;
var
head1, head2: PBlockInfo;
begin
if (AHead <> nil) and (AHead^.Next <> nil) then
begin
head1 := AHead;
head2 := AHead^.Next;
while (head2 <> nil) and (head2^.Next <> nil) do
begin
AHead := AHead^.Next;
head2 := AHead^.Next^.Next;
end;
head2 := AHead^.Next;
AHead^.Next := nil;
Result := Merge(MergeSort(head1), MergeSort(head2));
end else
Result := AHead;
end;
begin
if FShortCuts[0] <> nil then
FShortCuts[0] := MergeSort(FShortCuts[0]);
UpdateShortcuts;
end;
procedure TScreenBuffer.UpdateShortcuts; procedure TScreenBuffer.UpdateShortcuts;
var var
shortcut, step, nextStep, stepSize: Integer; shortcut, step, nextStep, stepSize: Integer;

View File

@ -2255,7 +2255,7 @@ begin
FLandscape.PrepareBlocks((FX + FLowOffsetX) div 8, (FY + FLowOffsetY) div 8, (FX + FHighOffsetX) div 8 + 1, (FY + FHighOffsetY) div 8 + 1); FLandscape.PrepareBlocks((FX + FLowOffsetX) div 8, (FY + FLowOffsetY) div 8, (FX + FHighOffsetX) div 8 + 1, (FY + FHighOffsetY) div 8 + 1);
PrepareVirtualLayer(FDrawDistance * 2 + 1, FDrawDistance * 2 + 1); PrepareVirtualLayer(FDrawDistance * 2 + 1, FDrawDistance * 2 + 1);
FScreenBuffer.Clear; //FScreenBuffer.Clear;
//TODO : Virtual Layer //TODO : Virtual Layer
FLandscape.FillDrawList(FScreenBuffer, FX + FLowOffsetX, FY + FLowOffsetY, FLandscape.FillDrawList(FScreenBuffer, FX + FLowOffsetX, FY + FLowOffsetY,
FRangeX, FRangeY, frmBoundaries.tbMinZ.Position, FRangeX, FRangeY, frmBoundaries.tbMinZ.Position,