--- a/hedgewars/uLandGraphics.pas Mon Sep 12 20:53:56 2011 -0400
+++ b/hedgewars/uLandGraphics.pas Tue Sep 13 00:13:01 2011 -0400
@@ -29,7 +29,7 @@
function addBgColor(OldColor, NewColor: LongWord): LongWord;
function SweepDirty: boolean;
-function Despeckle(X, Y: LongInt; gfxOnly: boolean): LongWord;
+function Despeckle(X, Y: LongInt): Boolean;
procedure Smooth(X, Y: LongInt);
function CheckLandValue(X, Y: LongInt; LandFlag: Word): boolean;
function DrawExplosion(X, Y, Radius: LongInt): Longword;
@@ -721,8 +721,7 @@
UpdateLandTexture(x, w, y, h)
end;
-// was experimenting with applying as damage occurred.
-function Despeckle(X, Y: LongInt; gfxOnly: boolean): LongWord;
+function Despeckle(X, Y: LongInt): boolean;
var nx, ny, i, j, c, xx, yy: LongInt;
pixelsweep: boolean;
begin
@@ -737,8 +736,7 @@
yy:= Y div 2;
end;
pixelsweep:= ((Land[Y, X] and $FF00) = 0) and (LandPixels[yy, xx] <> 0);
-if not pixelsweep and gfxOnly then exit(0);
-if ((Land[Y, X] > 255) and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then
+if (((Land[Y, X] and lfDamaged) <> 0) and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then
begin
c:= 0;
for i:= -1 to 1 do
@@ -761,8 +759,8 @@
else if Land[ny, nx] > 255 then inc(c);
end
end;
- if (c < 2) or
- ((c < 4) and (((Land[Y, X] and lfDamaged) <> 0) or pixelsweep)) then
+
+ if c < 4 then // 0-3 neighbours
begin
if ((Land[Y, X] and lfBasic) <> 0) and not disableLandBack then
LandPixels[yy, xx]:= LandBackPixel(X, Y)
@@ -770,11 +768,10 @@
LandPixels[yy, xx]:= 0;
Land[Y, X]:= 0;
- if not pixelsweep then exit(1)
- else exit(2)
+ if not pixelsweep then exit(true);
end;
end;
-Despeckle:= 0
+Despeckle:= false
end;
procedure Smooth(X, Y: LongInt);
@@ -827,12 +824,21 @@
end;
function SweepDirty: boolean;
-var x, y, xx, yy, ty, tx, d: LongInt;
- bRes, updateBlock, resweepCol, resweepGfx, gfxOnly, recheck, firstpass: boolean;
+var x, y, xx, yy, ty, tx: LongInt;
+ bRes, updateBlock, resweep, recheck: boolean;
begin
bRes:= false;
reCheck:= true;
-d:= 0;
+for y:= 0 to LAND_HEIGHT div 32 - 1 do
+ for x:= 0 to LAND_WIDTH div 32 - 1 do
+ if LandDirty[y, x] <> 0 then
+ begin
+ ty:= y * 32;
+ tx:= x * 32;
+ for yy:= ty to ty + 31 do
+ for xx:= tx to tx + 31 do
+ Smooth(xx,yy)
+ end;
while recheck do
begin
@@ -844,51 +850,40 @@
if LandDirty[y, x] <> 0 then
begin
updateBlock:= false;
- resweepCol:= true;
- resweepGfx:= true;
- firstpass:= true;
+ resweep:= true;
ty:= y * 32;
tx:= x * 32;
- while(resweepCol or resweepGfx) do
+ while(resweep) do
begin
- gfxOnly:= resweepGfx and not resweepCol;
- resweepCol:= false;
- resweepGfx:= false;
+ resweep:= false;
for yy:= ty to ty + 31 do
for xx:= tx to tx + 31 do
- begin
- d:= Despeckle(xx, yy, gfxOnly);
- if d <> 0 then
+ if Despeckle(xx, yy) then
begin
bRes:= true;
updateBlock:= true;
- if d = 1 then resweepCol:= true
- else resweepGfx:= true;
- if d = 1 then
- if (yy = ty) and (y > 0) then
- begin
- LandDirty[y-1, x]:= 1;
- recheck:= true;
- end
- else if (yy = ty+31) and (y < LAND_HEIGHT div 32 - 1) then
- begin
- LandDirty[y+1, x]:= 1;
- recheck:= true;
- end;
- if (xx = tx) and (x > 0) then
- begin
- LandDirty[y, x-1]:= 1;
- recheck:= true;
- end
- else if (xx = tx+31) and (x < LAND_WIDTH div 32 - 1) then
- begin
- LandDirty[y, x+1]:= 1;
- recheck:= true;
- end
+ resweep:= true;
+ if (yy = ty) and (y > 0) then
+ begin
+ LandDirty[y-1, x]:= 1;
+ recheck:= true;
+ end
+ else if (yy = ty+31) and (y < LAND_HEIGHT div 32 - 1) then
+ begin
+ LandDirty[y+1, x]:= 1;
+ recheck:= true;
+ end;
+ if (xx = tx) and (x > 0) then
+ begin
+ LandDirty[y, x-1]:= 1;
+ recheck:= true;
+ end
+ else if (xx = tx+31) and (x < LAND_WIDTH div 32 - 1) then
+ begin
+ LandDirty[y, x+1]:= 1;
+ recheck:= true;
+ end
end;
- if firstpass then Smooth(xx,yy);
- end;
- firstpass:= false
end;
if updateBlock then UpdateLandTexture(tx, 32, ty, 32);
LandDirty[y, x]:= 0;
@@ -900,6 +895,7 @@
SweepDirty:= bRes;
end;
+
// Return true if outside of land or not the value tested, used right now for some X/Y movement that does not use normal hedgehog movement in GSHandlers.inc
function CheckLandValue(X, Y: LongInt; LandFlag: Word): boolean;
begin