This seems a little more efficient
authornemo
Wed, 09 Dec 2009 17:35:42 +0000
changeset 2659 947fa21d5cd8
parent 2658 cd9ab1f5bfdb
child 2660 04c03640a7b0
This seems a little more efficient
hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Tue Dec 08 17:46:58 2009 +0000
+++ b/hedgewars/uGears.pas	Wed Dec 09 17:35:42 2009 +0000
@@ -1955,14 +1955,18 @@
 
 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
 
-	function CountNonZeroz(x, y, r: LongInt): LongInt;
+	function CountNonZeroz(x, y, r, c: LongInt): LongInt;
 	var i: LongInt;
 		Result: LongInt;
 	begin
 	Result:= 0;
 	if (y and LAND_HEIGHT_MASK) = 0 then
 		for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
-			if Land[y, i] <> 0 then inc(Result);
+			if Land[y, i] <> 0 then
+               begin
+               inc(Result);
+               if Result = c then exit(Result)
+               end;
 	CountNonZeroz:= Result
 	end;
 
@@ -1988,13 +1992,13 @@
 			begin
 			repeat
 				inc(y, 2);
-			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0);
+			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) = 0);
 
 			sy:= y;
 
 			repeat
 				inc(y);
-			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0);
+			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0);
 
 			if (y - sy > Gear^.Radius * 2)
 				and (y < LAND_HEIGHT)