- Replaced usages of UListSort with TList.Sort
- Removed now obsolete UListSort.pas - Removed GameResourceManager dependency from TStatics - Moved TSeperatedStaticBlock to the according ULandscape units - Cleanup some unnecessary <> nil checks
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
(*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* The contents of this file are subject to the terms of the
|
||||
* Common Development and Distribution License, Version 1.0 only
|
||||
* (the "License"). You may not use this file except in compliance
|
||||
* with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* http://www.opensource.org/licenses/cddl1.php.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL HEADER in each
|
||||
* file and include the License file at
|
||||
* http://www.opensource.org/licenses/cddl1.php. If applicable,
|
||||
* add the following below this CDDL HEADER, with the fields enclosed
|
||||
* by brackets "[]" replaced with your own identifying * information:
|
||||
* Portions Copyright [yyyy] [name of copyright owner]
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*
|
||||
*
|
||||
* Portions Copyright 2007 Andreas Schneider
|
||||
*)
|
||||
unit UListSort;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes;
|
||||
|
||||
type
|
||||
TListSortCompare = function(Left, Right: TObject): Integer of object;
|
||||
|
||||
procedure ListSort(List: TList; Compare: TListSortCompare);
|
||||
|
||||
implementation
|
||||
|
||||
procedure ListSort(List: TList; Compare: TListSortCompare);
|
||||
var
|
||||
iMin, iMax: Integer;
|
||||
Temp: Pointer;
|
||||
|
||||
procedure sift;
|
||||
var
|
||||
i, j: integer;
|
||||
begin
|
||||
i := iMin;
|
||||
j := 2 * i;
|
||||
Temp := Pointer(List[i]);
|
||||
while j <= iMax do
|
||||
begin
|
||||
if j < iMax then
|
||||
if Compare(TObject(List[j]), TObject(List[j + 1])) > 0 then inc(j);
|
||||
if Compare(TObject(Temp), TObject(List[j])) <= 0 then break;
|
||||
List[i] := Pointer(List[j]);
|
||||
i := j;
|
||||
j := 2 * i;
|
||||
end;
|
||||
List[i] := Temp;
|
||||
end;
|
||||
|
||||
begin
|
||||
if List.Count > 0 then
|
||||
begin
|
||||
iMax := List.Count - 1;
|
||||
iMin := iMax div 2 + 1;
|
||||
while iMin > 0 do
|
||||
begin
|
||||
dec(iMin);
|
||||
sift;
|
||||
end;
|
||||
while iMax > 0 do
|
||||
begin
|
||||
Temp := Pointer(List[iMin]);
|
||||
List[iMin] := Pointer(List[iMax]);
|
||||
List[iMax] := Temp;
|
||||
dec(iMax);
|
||||
sift;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -42,17 +42,19 @@ type
|
||||
{ Members }
|
||||
FHue: Word;
|
||||
FOrgHue: Word;
|
||||
|
||||
{ Methods }
|
||||
function HasChanged: Boolean; override;
|
||||
procedure SetHue(AHue: Word);
|
||||
public
|
||||
{ Fields }
|
||||
property Hue: Word read FHue write SetHue;
|
||||
|
||||
{ Methods }
|
||||
function Clone: TStaticItem; override;
|
||||
function GetSize: Integer; override;
|
||||
procedure InitOriginalState; override;
|
||||
procedure UpdatePriorities(ASolver: Integer);
|
||||
procedure UpdatePriorities(ATileData: TStaticTiledata; ASolver: Integer);
|
||||
procedure Write(AData: TStream); override;
|
||||
end;
|
||||
|
||||
@@ -68,6 +70,7 @@ type
|
||||
public
|
||||
{ Fields }
|
||||
property Items: TList read FItems write FItems;
|
||||
|
||||
{ Methods }
|
||||
function Clone: TStaticBlock; override;
|
||||
function GetSize: Integer; override;
|
||||
@@ -76,25 +79,8 @@ type
|
||||
procedure Write(AData: TStream); override;
|
||||
end;
|
||||
|
||||
{ TSeperatedStaticBlock }
|
||||
|
||||
TSeperatedStaticBlock = class(TStaticBlock)
|
||||
constructor Create(AData: TStream; AIndex: TGenericIndex; AX, AY: Word); overload;
|
||||
constructor Create(AData: TStream; AIndex: TGenericIndex); overload;
|
||||
destructor Destroy; override;
|
||||
public
|
||||
Cells: array[0..63] of TList;
|
||||
{ Methods }
|
||||
function Clone: TSeperatedStaticBlock; override;
|
||||
function GetSize: Integer; override;
|
||||
procedure RebuildList;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
UGameResources; //Used for priority calculation
|
||||
|
||||
{ TStaticItem }
|
||||
|
||||
constructor TStaticItem.Create(AOwner: TWorldBlock; AData: TStream; ABlockX, ABlockY: Word);
|
||||
@@ -153,15 +139,13 @@ begin
|
||||
inherited InitOriginalState;
|
||||
end;
|
||||
|
||||
procedure TStaticItem.UpdatePriorities(ASolver: Integer);
|
||||
var
|
||||
staticTileData: TStaticTileData;
|
||||
procedure TStaticItem.UpdatePriorities(ATileData: TStaticTiledata;
|
||||
ASolver: Integer);
|
||||
begin
|
||||
staticTileData := ResMan.Tiledata.StaticTiles[FTileID];
|
||||
FPriorityBonus := 0;
|
||||
if not ((staticTileData.Flags and tdfBackground) = tdfBackground) then
|
||||
if not ((ATileData.Flags and tdfBackground) = tdfBackground) then
|
||||
Inc(FPriorityBonus);
|
||||
if staticTileData.Height > 0 then
|
||||
if ATileData.Height > 0 then
|
||||
Inc(FPriorityBonus);
|
||||
FPriority := Z + FPriorityBonus;
|
||||
FPrioritySolver := ASolver;
|
||||
@@ -265,104 +249,5 @@ begin
|
||||
TStaticItem(FItems[i]).Write(AData);
|
||||
end;
|
||||
|
||||
{ TSeperatedStaticBlock }
|
||||
|
||||
constructor TSeperatedStaticBlock.Create(AData: TStream; AIndex: TGenericIndex; AX, AY: Word);
|
||||
var
|
||||
i: Integer;
|
||||
item: TStaticItem;
|
||||
block: TMemoryStream;
|
||||
begin
|
||||
inherited Create;
|
||||
FItems := TList.Create;
|
||||
|
||||
FX := AX;
|
||||
FY := AY;
|
||||
|
||||
for i := 0 to 63 do
|
||||
Cells[i] := TList.Create;
|
||||
|
||||
if (AData <> nil) and (AIndex.Lookup > 0) and (AIndex.Size > 0) then
|
||||
begin
|
||||
AData.Position := AIndex.Lookup;
|
||||
block := TMemoryStream.Create;
|
||||
block.CopyFrom(AData, AIndex.Size);
|
||||
block.Position := 0;
|
||||
for i := 1 to (AIndex.Size div 7) do
|
||||
begin
|
||||
item := TStaticItem.Create(Self, block, AX, AY);
|
||||
Cells[(item.Y mod 8) * 8 + (item.X mod 8)].Add(item);
|
||||
end;
|
||||
block.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TSeperatedStaticBlock.Create(AData: TStream; AIndex: TGenericIndex);
|
||||
begin
|
||||
Create(AData, AIndex, 0, 0);
|
||||
end;
|
||||
|
||||
destructor TSeperatedStaticBlock.Destroy;
|
||||
var
|
||||
i, j: Integer;
|
||||
begin
|
||||
if Assigned(FItems) then FreeAndNil(FItems);
|
||||
for i := 0 to 63 do
|
||||
begin
|
||||
if Cells[i] <> nil then
|
||||
begin
|
||||
for j := 0 to Cells[i].Count - 1 do
|
||||
begin
|
||||
if Cells[i][j] <> nil then
|
||||
begin
|
||||
TStaticItem(Cells[i][j]).Free;
|
||||
Cells[i][j] := nil;
|
||||
end;
|
||||
end;
|
||||
Cells[i].Free;
|
||||
Cells[i] := nil;
|
||||
end;
|
||||
end;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TSeperatedStaticBlock.RebuildList;
|
||||
var
|
||||
i, j, solver: Integer;
|
||||
begin
|
||||
FItems.Clear;
|
||||
solver := 0;
|
||||
for i := 0 to 63 do
|
||||
begin
|
||||
if Cells[i] <> nil then
|
||||
begin
|
||||
for j := 0 to Cells[i].Count - 1 do
|
||||
begin
|
||||
FItems.Add(Cells[i].Items[j]);
|
||||
TStaticItem(Cells[i].Items[j]).UpdatePriorities(solver);
|
||||
Inc(solver);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
Sort;
|
||||
end;
|
||||
|
||||
function TSeperatedStaticBlock.Clone: TSeperatedStaticBlock;
|
||||
var
|
||||
i, j: Integer;
|
||||
begin
|
||||
Result := TSeperatedStaticBlock.Create(nil, nil, FX, FY);
|
||||
|
||||
for i := 0 to 63 do
|
||||
for j := 0 to Cells[i].Count - 1 do
|
||||
Result.Cells[i].Add(TSeperatedStaticBlock(Cells[i].Items[j]).Clone);
|
||||
end;
|
||||
|
||||
function TSeperatedStaticBlock.GetSize: Integer;
|
||||
begin
|
||||
RebuildList;
|
||||
Result := inherited GetSize;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user