* the DrawnList structure (used by FloodFill) is now dynamically allocated

before a FloodFill and freed afterwards, so it doesn't waste memory, while
  not in use

git-svn-id: trunk@25729 -
This commit is contained in:
nickysn 2013-10-09 20:27:04 +00:00
parent 6fef9a2c80
commit d69a3447cd

View File

@ -283,10 +283,11 @@ type
y : smallint; y : smallint;
end; end;
PDrawnList = ^TDrawnList;
TDrawnList = Array[0..(MaxYRes - 1) div YResDiv] of PFloodLine; TDrawnList = Array[0..(MaxYRes - 1) div YResDiv] of PFloodLine;
var var
DrawnList : TDrawnList; DrawnList : PDrawnList;
Buffer : Record { Union for byte and word addressing of buffer } Buffer : Record { Union for byte and word addressing of buffer }
ByteIndex : Word; ByteIndex : Word;
WordIndex : Word; WordIndex : Word;
@ -352,8 +353,8 @@ var
temp^.x1 := x1; temp^.x1 := x1;
temp^.x2 := x2; temp^.x2 := x2;
temp^.y := y; temp^.y := y;
temp^.next := DrawnList[y div YResDiv]; temp^.next := DrawnList^[y div YResDiv];
DrawnList[y div YResDiv] := temp; DrawnList^[y div YResDiv] := temp;
end; end;
{********************************************************} {********************************************************}
@ -373,7 +374,7 @@ var
temp : PFloodLine; temp : PFloodLine;
begin begin
AlreadyDrawn := false; AlreadyDrawn := false;
temp := DrawnList[y div YResDiv]; temp := DrawnList^[y div YResDiv];
while assigned(temp) do while assigned(temp) do
begin begin
if (temp^.y = y) and if (temp^.y = y) and
@ -395,12 +396,12 @@ var
{********************************************************} {********************************************************}
Procedure CleanUpDrawnList; Procedure CleanUpDrawnList;
var var
l: longint; l: smallint;
temp1, temp2: PFloodLine; temp1, temp2: PFloodLine;
begin begin
for l := 0 to high(DrawnList) do for l := 0 to ViewHeight div YResDiv do
begin begin
temp1 := DrawnList[l]; temp1 := DrawnList^[l];
while assigned(temp1) do while assigned(temp1) do
begin begin
temp2 := temp1; temp2 := temp1;
@ -428,7 +429,8 @@ var
BackupColor : Word; BackupColor : Word;
x1, x2, prevy: smallint; x1, x2, prevy: smallint;
Begin Begin
FillChar(DrawnList,sizeof(DrawnList),0); GetMem(DrawnList,sizeof(PFloodLine)*((ViewHeight div YResDiv) + 1));
FillChar(DrawnList^,sizeof(PFloodLine)*((ViewHeight div YResDiv) + 1),0);
{ init prevy } { init prevy }
prevy := 32767; prevy := 32767;
{ Save current drawing color } { Save current drawing color }
@ -533,6 +535,7 @@ var
System.FreeMem (s2,(ViewWidth+1)*2); System.FreeMem (s2,(ViewWidth+1)*2);
System.FreeMem (s3,(ViewWidth+1)*2); System.FreeMem (s3,(ViewWidth+1)*2);
CleanUpDrawnList; CleanUpDrawnList;
System.FreeMem(DrawnList,sizeof(PFloodLine)*((ViewHeight div YResDiv) + 1));
CurrentColor := BackUpColor; CurrentColor := BackUpColor;
End; End;