Abort SimFlight if no more movement can occur (#914)

In no-gravity situations, SimFlight would enter an endless
loop when trying to project an unmoving object, waiting for
a collision that would never happen.

Similarly, in negative gravity, SimFlight would continue
calculating objects that left the top boundary of the land-
scape, only aborting the simulation once the coordinates
underflowed to values below the landscape.
Controls
Nicolas Hake 2013-01-30 14:00:08 +01:00
parent 3c3621072c
commit d20ee02ad6
1 changed files with 8 additions and 1 deletions

View File

@ -627,12 +627,19 @@ bool SimFlight(C4Real &x, C4Real &y, C4Real &xdir, C4Real &ydir, int32_t iDensit
do
{
if (!--i) {hitOnTime = false; break;}
// If the object isn't moving and there is no gravity either, abort
if (xdir == 0 && ydir == 0 && GravAccel == 0)
return false;
// If the object is above the landscape flying upwards in no/negative gravity, abort
if (ydir <= 0 && GravAccel <= 0 && cy < 0)
return false;
// Set target position by momentum
x+=xdir; y+=ydir;
// Movement to target
ctcox=fixtoi(x); ctcoy=fixtoi(y);
// Bounds
if (!Inside<int32_t>(ctcox,0,GBackWdt) || (ctcoy>=GBackHgt)) return false;
if (!Inside<int32_t>(ctcox,0,GBackWdt) || (ctcoy>=GBackHgt))
return false;
// Move to target
do
{