Document Bug in EnMttag_GetCurrentCheckpoint and Cleanup (#1622)

* Document bug in EnMttag_GetCurrentCheckpoint and cleanup

* correct func name

* clarify bug message

* format

* address review
This commit is contained in:
inspectredc 2024-05-17 05:22:59 +01:00 committed by GitHub
parent e6a69dfb2b
commit 27aa3f748b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -133,7 +133,7 @@ s32 EnMttag_AreFourRaceGoronsPresent(EnMttag* this, PlayState* play) {
*/
s32 EnMttag_GetCurrentCheckpoint(Actor* actor, PlayState* play, s32* upcomingCheckpoint, f32* outPerpendicularPointX,
f32* outPerpendicularPointZ) {
s32 curentCheckpoint = -1;
s32 currentCheckpoint = -1;
s32 hasSetCurrentCheckpointOnce = false;
f32 minLineLengthSq = 0.0f;
s32 sceneExitIndex;
@ -145,6 +145,8 @@ s32 EnMttag_GetCurrentCheckpoint(Actor* actor, PlayState* play, s32* upcomingChe
// The Goron Racetrack is configured such that the sceneExitIndex for any given floor polygon
// gradually increases as you move forward through the racetrack.
sceneExitIndex = SurfaceType_GetSceneExitIndex(&play->colCtx, actor->floorPoly, actor->floorBgId);
//! @bug - sStartingCheckpointPerSceneExitIndex is indexed out of bounds when sceneExitIndex is 18, due to the
//! `sceneExitIndex + 1` access.
if ((sceneExitIndex < 4) || (sceneExitIndex >= 19)) {
//! @bug - upcomingCheckpoint is not initialized here
return -1;
@ -155,14 +157,14 @@ s32 EnMttag_GetCurrentCheckpoint(Actor* actor, PlayState* play, s32* upcomingChe
// Iterates through all possible checkpoints that are associated with this sceneExitIndex.
do {
if (Math3D_PointDistToLine2D(
actor->world.pos.x, actor->world.pos.z, (&sCheckpointPositions[checkpointIterator])[-1].x,
(&sCheckpointPositions[checkpointIterator])[-1].z, (&sCheckpointPositions[checkpointIterator])[1].x,
(&sCheckpointPositions[checkpointIterator])[1].z, &perpendicularPointX, &perpendicularPointZ,
actor->world.pos.x, actor->world.pos.z, sCheckpointPositions[checkpointIterator - 1].x,
sCheckpointPositions[checkpointIterator - 1].z, sCheckpointPositions[checkpointIterator + 1].x,
sCheckpointPositions[checkpointIterator + 1].z, &perpendicularPointX, &perpendicularPointZ,
&lineLenSq) &&
(!hasSetCurrentCheckpointOnce || ((curentCheckpoint + 1) == checkpointIterator) ||
(!hasSetCurrentCheckpointOnce || ((currentCheckpoint + 1) == checkpointIterator) ||
(lineLenSq < minLineLengthSq))) {
minLineLengthSq = lineLenSq;
curentCheckpoint = checkpointIterator;
currentCheckpoint = checkpointIterator;
*outPerpendicularPointX = perpendicularPointX;
*outPerpendicularPointZ = perpendicularPointZ;
hasSetCurrentCheckpointOnce = true;
@ -170,8 +172,8 @@ s32 EnMttag_GetCurrentCheckpoint(Actor* actor, PlayState* play, s32* upcomingChe
checkpointIterator++;
} while (checkpointIterator < sStartingCheckpointPerSceneExitIndex[sceneExitIndex + 1]);
*upcomingCheckpoint = curentCheckpoint + 1;
return curentCheckpoint;
*upcomingCheckpoint = currentCheckpoint + 1;
return currentCheckpoint;
}
/**