# HG changeset patch # User nemo # Date 1260380142 0 # Node ID 947fa21d5cd8239cb08fd3b818b7bcecb8525612 # Parent cd9ab1f5bfdbb7783f09a2970b8cc7ccd4c972a1 This seems a little more efficient diff -r cd9ab1f5bfdb -r 947fa21d5cd8 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)