hedgewars/uGearsRender.pas
changeset 14924 e28ff0f1aca2
parent 14783 bbec6b28d072
child 14949 8b53cb1c0ada
--- a/hedgewars/uGearsRender.pas	Sat May 11 23:40:24 2019 +0200
+++ b/hedgewars/uGearsRender.pas	Sun May 12 03:27:43 2019 +0200
@@ -506,7 +506,7 @@
                 hy:= ty;
                 wraps:= 0;
                 inWorldBounds := ((ty and LAND_HEIGHT_MASK) or (tx and LAND_WIDTH_MASK)) = 0;
-                while inWorldBounds and ((Land[ty, tx] and lfAll) = 0) do
+                while (inWorldBounds and ((Land[ty, tx] and lfAll) = 0)) or (not inWorldBounds) do
                     begin
                     if wraps > cMaxLaserSightWraps then
                         break;
@@ -515,7 +515,7 @@
                     tx:= round(lx);
                     ty:= round(ly);
                     // reached edge of land.
-                    if ((ty and LAND_HEIGHT_MASK) <> 0) then
+                    if ((ty and LAND_HEIGHT_MASK) <> 0) and (((ty < LAND_HEIGHT) and (ay < 0)) or ((ty >= TopY) and (ay > 0))) then
                         begin
                         // assume infinite beam. Extend it way out past camera
                         tx:= round(lx + ax * (max(LAND_WIDTH,4096) div 2));
@@ -538,7 +538,7 @@
                             // just stop
                             break;
 
-                    if ((tx and LAND_WIDTH_MASK) <> 0) then
+                    if ((tx and LAND_WIDTH_MASK) <> 0) and (((ax > 0) and (tx >= RightX)) or ((ax < 0) and (tx <= LeftX))) then
                         begin
                         if (WorldEdge <> weWrap) and (WorldEdge <> weBounce) then
                             // assume infinite beam. Extend it way out past camera
@@ -548,6 +548,7 @@
                             end;
                         break;
                         end;
+                    inWorldBounds := ((ty and LAND_HEIGHT_MASK) or (tx and LAND_WIDTH_MASK)) = 0;
                     end;
 
                 DrawLineWrapped(hx, hy, tx, ty, 1.0, (sign*m) < 0, wraps, $FF, $00, $00, $C0);