Skip to content

Commit 228e531

Browse files
committed
LimbPath::ReportProgress - remove needless checks, improve comments
1 parent c0c0d1d commit 228e531

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

Source/Entities/LimbPath.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ void LimbPath::ReportProgress(const Vector& limbPos) {
337337
// This rest of the code will be working in local space, so convert input limb pos to that.
338338
Vector limbPosLocal = ToLocalSpace(limbPos);
339339

340-
//
340+
341341
// Iterate over all segments and find one whose target is closest to the limb position.
342-
//
342+
343343

344344
// Segment positions are accumulative, so keep an accumulator.
345345
Vector currentSegmentStartPos = GetCurrentSegStartLocal(); // Will be needed later.
@@ -350,12 +350,27 @@ void LimbPath::ReportProgress(const Vector& limbPos) {
350350
std::deque<Vector>::iterator closestSegment = m_CurrentSegment;
351351

352352
for (std::deque<Vector>::iterator itr = m_CurrentSegment; itr != m_Segments.end(); ++itr) {
353-
if (itr != m_CurrentSegment) {
353+
354+
// We want to find a closest segment to work off of, but we don't want to
355+
// snap from collision-enabled segments to collision-disabled segments,
356+
// because doing so tends to produce erratic foot behavior.
357+
358+
// If the current segment of the limbpath is collision-enabled...
359+
if (!FootCollisionsShouldBeDisabled()) {
360+
// If the currently looked at segment is collision-disabled...
354361
if (m_FootCollisionsDisabledSegment >= 0 &&
355362
m_Segments.size() - (itr - m_Segments.begin()) <= m_FootCollisionsDisabledSegment) {
356-
// We've already picked a segment (at least the current one),
357-
// and the remaining ones are ones with collisions disabled.
358-
// Ignore these.
363+
364+
// ...Then break.
365+
366+
// Note: if the first of the above two checks has passed,
367+
// this means that the current segment is collision-enabled.
368+
// And, since this iterator starts with it, this means that
369+
// *at least* the current segment was picked as closest already.
370+
//
371+
// In other words, if this break was hit, then closest segment vars have
372+
// been properly initialized already. Therefore, it's safe to break.
373+
359374
break;
360375
}
361376
}
@@ -369,16 +384,13 @@ void LimbPath::ReportProgress(const Vector& limbPos) {
369384
closestSegmentStartPos = thisSegmentStartPos;
370385
closestSegmentTargetDistanceSqr = thisSegmentDistanceSqr;
371386
closestSegment = itr;
372-
} else {
373-
// This one is *farther* than the last one.
374-
// Assuming next segments will be only farther and farther, just break now.
375-
break;
376387
}
377388
}
378389

379-
// We will want to compute progress to whatever the new segment is.
380-
float distanceToCurrentSegmentTargetSqr;
381390

391+
// Branches below will determine the new current segment and write the distance to it here.
392+
// We need this distance to compute progress towards it, whatever it ends up being.
393+
float distanceToCurrentSegmentTargetSqr;
382394

383395
if (closestSegmentTargetDistanceSqr < m_SegmentEndedThreshold * m_SegmentEndedThreshold) {
384396
// We're sufficiently close to this segment's target to go on.

0 commit comments

Comments
 (0)