Skip to content

Commit

Permalink
Engine: fixed a condition in movelist_handle_remainer()
Browse files Browse the repository at this point in the history
Should compare xpermove and ypermove using abs values, as they may have different signs.
  • Loading branch information
ivan-mogilko committed Oct 7, 2023
1 parent 03de6d3 commit 234db6d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Engine/main/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ static void movelist_handle_remainer(const fixed xpermove, const fixed ypermove,
const int xdistance, const float step_length, fixed &fin_ymove, float &fin_from_part)
{
// Walk along the remaining axis with the full walking speed
assert(xpermove != 0 && ypermove != 0);
assert(xpermove != 0 && ypermove != 0 && step_length >= 0.f);
fin_ymove = ypermove > 0 ? ftofix(step_length) : -ftofix(step_length);
fin_from_part = (float)xdistance / fixtof(xpermove);
assert(fin_from_part >= 0);
}

// Handle remaining move fixup, but only if necessary
Expand All @@ -119,11 +120,11 @@ static void movelist_handle_remainer(MoveList &m)
// Apply remainer to movelists where LONGER axis was completed, and SHORTER remains
if ((xpermove != 0) && (ypermove != 0))
{
if ((m.doneflag & kMoveListDone_XY) == kMoveListDone_X && (ypermove < xpermove))
movelist_handle_remainer(xpermove, ypermove, target.X - m.from.X,
if ((m.doneflag & kMoveListDone_XY) == kMoveListDone_X && (abs(ypermove) < abs(xpermove)))
movelist_handle_remainer(xpermove, ypermove, (target.X - m.from.X),
m.GetStepLength(), m.fin_move, m.fin_from_part);
else if ((m.doneflag & kMoveListDone_XY) == kMoveListDone_Y && (xpermove < ypermove))
movelist_handle_remainer(ypermove, xpermove, target.Y - m.from.Y,
else if ((m.doneflag & kMoveListDone_XY) == kMoveListDone_Y && (abs(xpermove) < abs(ypermove)))
movelist_handle_remainer(ypermove, xpermove, (target.Y - m.from.Y),
m.GetStepLength(), m.fin_move, m.fin_from_part);
}
}
Expand Down

0 comments on commit 234db6d

Please sign in to comment.