mirror of
https://github.com/zeldaret/mm.git
synced 2025-02-17 03:57:46 +00:00
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:
parent
e6a69dfb2b
commit
27aa3f748b
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user