mirror of https://github.com/zeldaret/mm.git
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,
|
s32 EnMttag_GetCurrentCheckpoint(Actor* actor, PlayState* play, s32* upcomingCheckpoint, f32* outPerpendicularPointX,
|
||||||
f32* outPerpendicularPointZ) {
|
f32* outPerpendicularPointZ) {
|
||||||
s32 curentCheckpoint = -1;
|
s32 currentCheckpoint = -1;
|
||||||
s32 hasSetCurrentCheckpointOnce = false;
|
s32 hasSetCurrentCheckpointOnce = false;
|
||||||
f32 minLineLengthSq = 0.0f;
|
f32 minLineLengthSq = 0.0f;
|
||||||
s32 sceneExitIndex;
|
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
|
// The Goron Racetrack is configured such that the sceneExitIndex for any given floor polygon
|
||||||
// gradually increases as you move forward through the racetrack.
|
// gradually increases as you move forward through the racetrack.
|
||||||
sceneExitIndex = SurfaceType_GetSceneExitIndex(&play->colCtx, actor->floorPoly, actor->floorBgId);
|
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)) {
|
if ((sceneExitIndex < 4) || (sceneExitIndex >= 19)) {
|
||||||
//! @bug - upcomingCheckpoint is not initialized here
|
//! @bug - upcomingCheckpoint is not initialized here
|
||||||
return -1;
|
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.
|
// Iterates through all possible checkpoints that are associated with this sceneExitIndex.
|
||||||
do {
|
do {
|
||||||
if (Math3D_PointDistToLine2D(
|
if (Math3D_PointDistToLine2D(
|
||||||
actor->world.pos.x, actor->world.pos.z, (&sCheckpointPositions[checkpointIterator])[-1].x,
|
actor->world.pos.x, actor->world.pos.z, sCheckpointPositions[checkpointIterator - 1].x,
|
||||||
(&sCheckpointPositions[checkpointIterator])[-1].z, (&sCheckpointPositions[checkpointIterator])[1].x,
|
sCheckpointPositions[checkpointIterator - 1].z, sCheckpointPositions[checkpointIterator + 1].x,
|
||||||
(&sCheckpointPositions[checkpointIterator])[1].z, &perpendicularPointX, &perpendicularPointZ,
|
sCheckpointPositions[checkpointIterator + 1].z, &perpendicularPointX, &perpendicularPointZ,
|
||||||
&lineLenSq) &&
|
&lineLenSq) &&
|
||||||
(!hasSetCurrentCheckpointOnce || ((curentCheckpoint + 1) == checkpointIterator) ||
|
(!hasSetCurrentCheckpointOnce || ((currentCheckpoint + 1) == checkpointIterator) ||
|
||||||
(lineLenSq < minLineLengthSq))) {
|
(lineLenSq < minLineLengthSq))) {
|
||||||
minLineLengthSq = lineLenSq;
|
minLineLengthSq = lineLenSq;
|
||||||
curentCheckpoint = checkpointIterator;
|
currentCheckpoint = checkpointIterator;
|
||||||
*outPerpendicularPointX = perpendicularPointX;
|
*outPerpendicularPointX = perpendicularPointX;
|
||||||
*outPerpendicularPointZ = perpendicularPointZ;
|
*outPerpendicularPointZ = perpendicularPointZ;
|
||||||
hasSetCurrentCheckpointOnce = true;
|
hasSetCurrentCheckpointOnce = true;
|
||||||
|
@ -170,8 +172,8 @@ s32 EnMttag_GetCurrentCheckpoint(Actor* actor, PlayState* play, s32* upcomingChe
|
||||||
checkpointIterator++;
|
checkpointIterator++;
|
||||||
} while (checkpointIterator < sStartingCheckpointPerSceneExitIndex[sceneExitIndex + 1]);
|
} while (checkpointIterator < sStartingCheckpointPerSceneExitIndex[sceneExitIndex + 1]);
|
||||||
|
|
||||||
*upcomingCheckpoint = curentCheckpoint + 1;
|
*upcomingCheckpoint = currentCheckpoint + 1;
|
||||||
return curentCheckpoint;
|
return currentCheckpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue