Skip to content

Commit

Permalink
Fix issue with waypoint update collisions accounting for Lua event ca…
Browse files Browse the repository at this point in the history
…ll potential impacts.
  • Loading branch information
lostsquirrel1 authored and lhog committed Jan 24, 2025
1 parent 194b9d0 commit 817bbd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 6 additions & 8 deletions rts/Sim/MoveTypes/GroundMoveType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ CR_REG_METADATA(CGroundMoveType, (
CR_MEMBER(atGoal),
CR_MEMBER(atEndOfPath),
CR_MEMBER(wantRepath),
CR_MEMBER(moveFailed),

CR_MEMBER(reversing),
CR_MEMBER(idling),
Expand Down Expand Up @@ -891,8 +890,8 @@ void CGroundMoveType::StartMovingRaw(const float3 moveGoalPos, float moveGoalRad
MoveTypes::CheckCollisionQuery collisionQuery(owner->moveDef, moveGoalPos);
extraRadius = deltaRadius * (1 - owner->moveDef->TestMoveSquare(collisionQuery, moveGoalPos, ZeroVector, true, true));

currWayPoint = goalPos;
nextWayPoint = goalPos;
earlyCurrWayPoint = currWayPoint = goalPos;
earlyNextWayPoint = nextWayPoint = goalPos;

atGoal = (moveGoalPos.SqDistance2D(owner->pos) < Square(goalRadius + extraRadius));
atEndOfPath = false;
Expand Down Expand Up @@ -991,7 +990,7 @@ void CGroundMoveType::StopMoving(bool callScript, bool hardStop, bool cancelRaw)
LOG_L(L_DEBUG, "[%s] stopping engine for unit %i", __func__, owner->id);

if (!atGoal)
goalPos = (currWayPoint = Here());
earlyCurrWayPoint = (goalPos = (currWayPoint = Here()));

// this gets called under a variety of conditions (see MobileCAI)
// the most common case is a CMD_STOP being issued which means no
Expand Down Expand Up @@ -2062,13 +2061,12 @@ unsigned int CGroundMoveType::GetNewPath()
atEndOfPath = false;
lastWaypoint = false;

currWayPoint = pathManager->NextWayPoint(owner, newPathID, 0, owner->pos, std::max(WAYPOINT_RADIUS, currentSpeed * 1.05f), true);
nextWayPoint = pathManager->NextWayPoint(owner, newPathID, 0, currWayPoint, std::max(WAYPOINT_RADIUS, currentSpeed * 1.05f), true);
earlyCurrWayPoint = currWayPoint = pathManager->NextWayPoint(owner, newPathID, 0, owner->pos, std::max(WAYPOINT_RADIUS, currentSpeed * 1.05f), true);
earlyNextWayPoint = nextWayPoint = pathManager->NextWayPoint(owner, newPathID, 0, currWayPoint, std::max(WAYPOINT_RADIUS, currentSpeed * 1.05f), true);

pathController.SetRealGoalPosition(newPathID, goalPos);
pathController.SetTempGoalPosition(newPathID, currWayPoint);
} else {
// moveFailed = true;
Fail(false);
}

Expand Down Expand Up @@ -3287,7 +3285,7 @@ bool CGroundMoveType::UpdateDirectControl()
float turnSign = 0.0f;

currWayPoint = owner->frontdir * XZVector * mix(100.0f, -100.0f, wantReverse);
currWayPoint = (owner->pos + currWayPoint).cClampInBounds();
earlyCurrWayPoint = currWayPoint = (owner->pos + currWayPoint).cClampInBounds();

if (unitCon.forward || unitCon.back) {
ChangeSpeed((maxSpeed * unitCon.forward) + (maxReverseSpeed * unitCon.back), wantReverse, true);
Expand Down
5 changes: 0 additions & 5 deletions rts/Sim/MoveTypes/GroundMoveType.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ class CGroundMoveType : public AMoveType
float GetGroundHeight(const float3&) const;

void SyncWaypoints() {
if (moveFailed){
Fail(false);
moveFailed = false;
}
// Synced vars trigger a checksum update on change, which is expensive so we should check
// that there has been a change before triggering an update to the checksum.
if (!currWayPoint.bitExactEquals(earlyCurrWayPoint))
Expand Down Expand Up @@ -296,7 +292,6 @@ class CGroundMoveType : public AMoveType
bool atGoal = true;
bool atEndOfPath = true;
bool wantRepath = false;
bool moveFailed = false;
bool lastWaypoint = false;

bool reversing = false;
Expand Down

0 comments on commit 817bbd9

Please sign in to comment.