Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
authorunc0rr
Thu, 22 Jan 2009 17:53:39 +0000
changeset 1738 00e8dadce69a
parent 1736 9ae3cd2204d3
child 1740 0d69ff7b5fbf
Add nemo's depixeling patch. Still needs some polishing for the case when we delete pixel on which hedgehog stays
hedgewars/uGears.pas
hedgewars/uLand.pas
hedgewars/uLandGraphics.pas
--- a/hedgewars/uGears.pas	Tue Jan 20 20:26:09 2009 +0000
+++ b/hedgewars/uGears.pas	Thu Jan 22 17:53:39 2009 +0000
@@ -423,6 +423,7 @@
 function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs
 var Gear: PGear;
 begin
+SweepDirty; // convenient place to clean up pixels after damage is run 
 CheckNoDamage:= true;
 Gear:= GearsList;
 while Gear <> nil do
--- a/hedgewars/uLand.pas	Tue Jan 20 20:26:09 2009 +0000
+++ b/hedgewars/uLand.pas	Thu Jan 22 17:53:39 2009 +0000
@@ -22,10 +22,12 @@
 {$include options.inc}
 type TLandArray = packed array[0..1023, 0..2047] of LongWord;
      TPreview = packed array[0..127, 0..31] of byte;
+     TDirtyTag = packed array[0..31, 0..63] of byte;
 
 var  Land: TLandArray;
      LandPixels: TLandArray;
      LandTexture: PTexture = nil;
+     LandDirty: TDirtyTag;
 
 procedure GenMap;
 function  GenPreview: TPreview;
--- a/hedgewars/uLandGraphics.pas	Tue Jan 20 20:26:09 2009 +0000
+++ b/hedgewars/uLandGraphics.pas	Thu Jan 22 17:53:39 2009 +0000
@@ -26,6 +26,8 @@
                                    Left, Right: LongInt;
                                    end;
 
+procedure SweepDirty;
+function Despeckle(X, Y: LongInt): boolean;
 procedure DrawExplosion(X, Y, Radius: LongInt);
 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
@@ -138,16 +140,36 @@
 begin
 if ((y + dy) and $FFFFFC00) = 0 then
    for i:= max(x - dx, 0) to min(x + dx, 2047) do
-       if Land[y + dy, i] = COLOR_LAND then LandPixels[y + dy, i]:= cExplosionBorderColor;
+       if Land[y + dy, i] = COLOR_LAND then 
+          begin
+          LandPixels[y + dy, i]:= cExplosionBorderColor;
+//          Despeckle(y + dy, i);
+          LandDirty[(y + dy) div 32, i div 32]:= 1;
+          end;
 if ((y - dy) and $FFFFFC00) = 0 then
    for i:= max(x - dx, 0) to min(x + dx, 2047) do
-       if Land[y - dy, i] = COLOR_LAND then LandPixels[y - dy, i]:= cExplosionBorderColor;
+       if Land[y - dy, i] = COLOR_LAND then
+          begin
+          LandPixels[y - dy, i]:= cExplosionBorderColor;
+//          Despeckle(y - dy, i);
+          LandDirty[(y - dy) div 32, i div 32]:= 1;
+          end;
 if ((y + dx) and $FFFFFC00) = 0 then
    for i:= max(x - dy, 0) to min(x + dy, 2047) do
-       if Land[y + dx, i] = COLOR_LAND then LandPixels[y + dx, i]:= cExplosionBorderColor;
+       if Land[y + dx, i] = COLOR_LAND then
+           begin
+           LandPixels[y + dx, i]:= cExplosionBorderColor;
+//           Despeckle(y + dx, i);
+           LandDirty[(y + dx) div 32, i div 32]:= 1;
+           end;
 if ((y - dx) and $FFFFFC00) = 0 then
    for i:= max(x - dy, 0) to min(x + dy, 2047) do
-       if Land[y - dx, i] = COLOR_LAND then LandPixels[y - dx, i]:= cExplosionBorderColor;
+       if Land[y - dx, i] = COLOR_LAND then
+          begin
+          LandPixels[y - dx, i]:= cExplosionBorderColor;
+//          Despeckle(y - dx, i);
+          LandDirty[(y - dx) div 32, i div 32]:= 1;
+          end;
 end;
 
 procedure DrawExplosion(X, Y, Radius: LongInt);
@@ -211,7 +233,10 @@
     for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do
         for tx:= max(0, ar^[i].Left - Radius) to min(2047, ar^[i].Right + Radius) do
             if Land[ty, tx] = $FFFFFF then
-                  LandPixels[ty, tx]:= cExplosionBorderColor;
+                begin
+                LandPixels[ty, tx]:= cExplosionBorderColor;
+                LandDirty[trunc((y + dy)/32), trunc(i/32)]:= 1;
+                end;
     inc(y, dY)
     end;
 
@@ -349,5 +374,65 @@
 UpdateLandTexture(y, h)
 end;
 
+// was experimenting with applying as damage occurred.
+function Despeckle(X, Y: LongInt): boolean;
+var nx, ny, i, j, c: LongInt;
+begin
+if Land[Y, X] <> 0 then // check neighbours
+	begin
+	c:= 0;
+	for i:= -1 to 1 do
+		for j:= -1 to 1 do
+			if (i <> 0) or (j <> 0) then
+				begin
+				ny:= Y + i;
+				nx:= X + j;
+				if ((ny and $FFFFFC00) = 0) and ((nx and $FFFFF800) = 0) then
+					if Land[ny, nx] <> 0 then
+						inc(c);
+				end;
+
+	if c < 4 then // 0-3 neighbours
+		begin
+		LandPixels[Y, X]:= 0;
+		Land[Y, X]:= 0;
+		exit(true);
+		end;
+	end;
+Despeckle:= false
+end;
+
+procedure SweepDirty;
+var x, y, xx, yy: LongInt;
+    updatedRow, updatedCell: boolean;
+begin
+for y:= 0 to 31 do
+	begin
+	updatedRow:= false;
+	
+	for x:= 0 to 63 do
+		begin
+			repeat
+			updatedCell:= false;
+			if LandDirty[y, x] <> 0 then
+				begin
+				updatedRow:= true;
+				// testing. should make black squares
+				for yy:= y * 32 to y * 32 + 31 do
+					for xx:= x * 32 to x * 32 + 31 do
+						if Despeckle(xx, yy) then updatedCell:= true;
+				end;
+			if updatedCell then updatedRow:= true
+			until not updatedCell;
+		LandDirty[y, x]:= 0;
+		end;
+	
+	if updatedRow then
+		if y = 31 then
+			UpdateLandTexture(992, 31)
+		else
+			UpdateLandTexture(y*32, 32);
+	end;
+end;
 
 end.