hedgewars/uLandGraphics.pas
branchhedgeroid
changeset 5932 5164d17b6374
parent 5895 212d3b459658
child 6011 519f8a58c021
--- a/hedgewars/uLandGraphics.pas	Fri Sep 16 17:36:05 2011 +0200
+++ b/hedgewars/uLandGraphics.pas	Fri Sep 16 18:17:16 2011 +0200
@@ -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;
@@ -528,8 +528,11 @@
        (((Land[ty, tx] and lfBasic) <> 0) or
        ((Land[ty, tx] and lfObject) <> 0)) then
         begin
-        Land[ty, tx]:= Land[ty, tx] or lfDamaged;
-        if despeckle then LandDirty[ty div 32, tx div 32]:= 1;
+        if despeckle then 
+            begin
+            Land[ty, tx]:= Land[ty, tx] or lfDamaged;
+            LandDirty[ty div 32, tx div 32]:= 1
+            end;
         if (cReducedQuality and rqBlurryLand) = 0 then
             LandPixels[ty, tx]:= cExplosionBorderColor
         else LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
@@ -721,8 +724,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 +739,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 +762,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 +771,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,8 +827,8 @@
 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;
@@ -840,65 +840,67 @@
         begin
         for x:= 0 to LAND_WIDTH div 32 - 1 do
             begin
-            if LandDirty[y, x] <> 0 then
+            if LandDirty[y, x] = 1 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;
+                LandDirty[y, x]:= 2;
                 end;
             end;
         end;
      end;
 
+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
+            LandDirty[y, x]:= 0;
+            ty:= y * 32;
+            tx:= x * 32;
+            for yy:= ty to ty + 31 do
+                for xx:= tx to tx + 31 do
+                    Smooth(xx,yy)
+            end;
+
 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