diff options
| author | fig02 <fig02srl@gmail.com> | 2024-09-01 16:02:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-01 16:02:13 -0400 |
| commit | 2b25c31588facab999256bbd12927e6295f00cf9 (patch) | |
| tree | 6409cca77ade740b92f05cf1332a69373d82569a /src/code | |
| parent | a21a59c4b5a0e1ac16ca98cdf9d9aaa0fab7bf6c (diff) | |
Document Target_Draw [Target Docs 2/?] (#2115)
* document Target_Draw
Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
* fix missed renames
* retail fix
* another fix
---------
Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/z_actor.c | 160 | ||||
| -rw-r--r-- | src/code/z_parameter.c | 2 |
2 files changed, 87 insertions, 75 deletions
diff --git a/src/code/z_actor.c b/src/code/z_actor.c index ff44339c2..d0b81e49a 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -275,10 +275,10 @@ void Target_InitReticle(TargetContext* targetCtx, s32 actorCategory, PlayState* TargetColor* reticleColor = &sTargetColorList[actorCategory]; s32 i; - Math_Vec3f_Copy(&targetCtx->targetCenterPos, &play->view.eye); + Math_Vec3f_Copy(&targetCtx->lockOnPos, &play->view.eye); targetCtx->reticleRadius = 500.0f; - targetCtx->unk_48 = 256; + targetCtx->reticleFadeAlphaControl = 256; reticle = &targetCtx->lockOnReticles[0]; @@ -310,97 +310,107 @@ void Target_SetNaviState(TargetContext* targetCtx, Actor* actor, s32 actorCatego } void Target_Init(TargetContext* targetCtx, Actor* actor, PlayState* play) { - targetCtx->arrowPointedActor = targetCtx->targetedActor = targetCtx->unk_8C = targetCtx->bgmEnemy = NULL; + targetCtx->arrowPointedActor = targetCtx->lockOnActor = targetCtx->unk_8C = targetCtx->bgmEnemy = NULL; - targetCtx->unk_4B = 0; - targetCtx->unk_4C = 0; + targetCtx->reticleSpinCounter = 0; + targetCtx->curReticle = 0; targetCtx->unk_40 = 0.0f; Target_SetNaviState(targetCtx, actor, actor->category, play); Target_InitReticle(targetCtx, actor->category, play); } -void func_8002C124(TargetContext* targetCtx, PlayState* play) { - Actor* actor = targetCtx->targetedActor; +void Target_Draw(TargetContext* targetCtx, PlayState* play) { + Actor* actor = targetCtx->lockOnActor; OPEN_DISPS(play->state.gfxCtx, "../z_actor.c", 2029); - if (targetCtx->unk_48 != 0) { - LockOnReticle* entry; - Player* player; - s16 spCE; - f32 var1; - Vec3f projTargetCenter; - s32 spB8; - f32 projTargetCappedInvW; - s32 spB0; - s32 spAC; - f32 var2; + if (targetCtx->reticleFadeAlphaControl != 0) { + LockOnReticle* reticle; + Player* player = GET_PLAYER(play); + s16 alpha; + f32 projectdPosScale; + Vec3f projectedPos; + s32 numReticles; + f32 invW; s32 i; + s32 curReticle; + f32 lockOnScaleX; + s32 triangleIndex; - player = GET_PLAYER(play); + alpha = 255; + projectdPosScale = 1.0f; - spCE = 0xFF; - var1 = 1.0f; - - if (targetCtx->unk_4B != 0) { - spB8 = 1; + if (targetCtx->reticleSpinCounter != 0) { + // Reticle is spinning so it is active, only need to draw one + numReticles = 1; } else { - spB8 = 3; + // Use multiple reticles for the motion blur effect from the reticle + // quickly zooming in on an actor from off screen + numReticles = ARRAY_COUNT(targetCtx->lockOnReticles); } if (actor != NULL) { - Math_Vec3f_Copy(&targetCtx->targetCenterPos, &actor->focus.pos); - var1 = (500.0f - targetCtx->reticleRadius) / 420.0f; + Math_Vec3f_Copy(&targetCtx->lockOnPos, &actor->focus.pos); + projectdPosScale = (500.0f - targetCtx->reticleRadius) / 420.0f; } else { - targetCtx->unk_48 -= 120; - if (targetCtx->unk_48 < 0) { - targetCtx->unk_48 = 0; + // Not locked on, start fading out + targetCtx->reticleFadeAlphaControl -= 120; + + if (targetCtx->reticleFadeAlphaControl < 0) { + targetCtx->reticleFadeAlphaControl = 0; } - spCE = targetCtx->unk_48; + + // `reticleFadeAlphaControl` is only used as an alpha when fading out. + // Otherwise it defaults to 255, set above. + alpha = targetCtx->reticleFadeAlphaControl; } - Actor_ProjectPos(play, &targetCtx->targetCenterPos, &projTargetCenter, &projTargetCappedInvW); + Actor_ProjectPos(play, &targetCtx->lockOnPos, &projectedPos, &invW); - projTargetCenter.x = (160 * (projTargetCenter.x * projTargetCappedInvW)) * var1; - projTargetCenter.x = CLAMP(projTargetCenter.x, -320.0f, 320.0f); + projectedPos.x = ((SCREEN_WIDTH / 2) * (projectedPos.x * invW)) * projectdPosScale; + projectedPos.x = CLAMP(projectedPos.x, -SCREEN_WIDTH, SCREEN_WIDTH); - projTargetCenter.y = (120 * (projTargetCenter.y * projTargetCappedInvW)) * var1; - projTargetCenter.y = CLAMP(projTargetCenter.y, -240.0f, 240.0f); + projectedPos.y = ((SCREEN_HEIGHT / 2) * (projectedPos.y * invW)) * projectdPosScale; + projectedPos.y = CLAMP(projectedPos.y, -SCREEN_HEIGHT, SCREEN_HEIGHT); - projTargetCenter.z = projTargetCenter.z * var1; + projectedPos.z *= projectdPosScale; - targetCtx->unk_4C--; - if (targetCtx->unk_4C < 0) { - targetCtx->unk_4C = 2; + targetCtx->curReticle--; + + if (targetCtx->curReticle < 0) { + targetCtx->curReticle = ARRAY_COUNT(targetCtx->lockOnReticles) - 1; } - Target_SetReticlePos(targetCtx, targetCtx->unk_4C, projTargetCenter.x, projTargetCenter.y, projTargetCenter.z); + Target_SetReticlePos(targetCtx, targetCtx->curReticle, projectedPos.x, projectedPos.y, projectedPos.z); if (!(player->stateFlags1 & PLAYER_STATE1_6) || (actor != player->unk_664)) { OVERLAY_DISP = Gfx_SetupDL(OVERLAY_DISP, SETUPDL_57); - for (spB0 = 0, spAC = targetCtx->unk_4C; spB0 < spB8; spB0++, spAC = (spAC + 1) % 3) { - entry = &targetCtx->lockOnReticles[spAC]; + for (i = 0, curReticle = targetCtx->curReticle; i < numReticles; + i++, curReticle = (curReticle + 1) % ARRAY_COUNT(targetCtx->lockOnReticles)) { + reticle = &targetCtx->lockOnReticles[curReticle]; - if (entry->radius < 500.0f) { - if (entry->radius <= 120.0f) { - var2 = 0.15f; + if (reticle->radius < 500.0f) { + if (reticle->radius <= 120.0f) { + lockOnScaleX = 0.15f; } else { - var2 = ((entry->radius - 120.0f) * 0.001f) + 0.15f; + lockOnScaleX = ((reticle->radius - 120.0f) * 0.001f) + 0.15f; } - Matrix_Translate(entry->pos.x, entry->pos.y, 0.0f, MTXMODE_NEW); - Matrix_Scale(var2, 0.15f, 1.0f, MTXMODE_APPLY); + Matrix_Translate(reticle->pos.x, reticle->pos.y, 0.0f, MTXMODE_NEW); + Matrix_Scale(lockOnScaleX, 0.15f, 1.0f, MTXMODE_APPLY); - gDPSetPrimColor(OVERLAY_DISP++, 0, 0, entry->color.r, entry->color.g, entry->color.b, (u8)spCE); + gDPSetPrimColor(OVERLAY_DISP++, 0, 0, reticle->color.r, reticle->color.g, reticle->color.b, + (u8)alpha); - Matrix_RotateZ((targetCtx->unk_4B & 0x7F) * (M_PI / 64), MTXMODE_APPLY); + Matrix_RotateZ((targetCtx->reticleSpinCounter & 0x7F) * (M_PI / 64), MTXMODE_APPLY); - for (i = 0; i < 4; i++) { + // Draw the 4 triangles that make up the reticle + for (triangleIndex = 0; triangleIndex < 4; triangleIndex++) { Matrix_RotateZ(M_PI / 2, MTXMODE_APPLY); Matrix_Push(); - Matrix_Translate(entry->radius, entry->radius, 0.0f, MTXMODE_APPLY); + Matrix_Translate(reticle->radius, reticle->radius, 0.0f, MTXMODE_APPLY); gSPMatrix(OVERLAY_DISP++, MATRIX_NEW(play->state.gfxCtx, "../z_actor.c", 2116), G_MTX_MODELVIEW | G_MTX_LOAD); gSPDisplayList(OVERLAY_DISP++, gZTargetLockOnTriangleDL); @@ -408,17 +418,19 @@ void func_8002C124(TargetContext* targetCtx, PlayState* play) { } } - spCE -= 0xFF / 3; - if (spCE < 0) { - spCE = 0; + alpha -= 255 / ARRAY_COUNT(targetCtx->lockOnReticles); + + if (alpha < 0) { + alpha = 0; } } } } - actor = targetCtx->unk_94; + actor = targetCtx->arrowHoverActor; + if ((actor != NULL) && !(actor->flags & ACTOR_FLAG_27)) { - TargetColor* naviColor = &sTargetColorList[actor->category]; + TargetColor* arrowColor = &sTargetColorList[actor->category]; POLY_XLU_DISP = Gfx_SetupDL(POLY_XLU_DISP, SETUPDL_7); @@ -427,7 +439,7 @@ void func_8002C124(TargetContext* targetCtx, PlayState* play) { Matrix_RotateY(BINANG_TO_RAD((u16)(play->gameplayFrames * 3000)), MTXMODE_APPLY); Matrix_Scale((iREG(27) + 35) / 1000.0f, (iREG(28) + 60) / 1000.0f, (iREG(29) + 50) / 1000.0f, MTXMODE_APPLY); - gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, naviColor->inner.r, naviColor->inner.g, naviColor->inner.b, 255); + gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, arrowColor->inner.r, arrowColor->inner.g, arrowColor->inner.b, 255); gSPMatrix(POLY_XLU_DISP++, MATRIX_NEW(play->state.gfxCtx, "../z_actor.c", 2153), G_MTX_MODELVIEW | G_MTX_LOAD); gSPDisplayList(POLY_XLU_DISP++, gZTargetArrowDL); } @@ -446,10 +458,10 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Pl if ((player->unk_664 != NULL) && (player->controlStickDirections[player->controlStickDataIndex] == PLAYER_STICK_DIR_BACKWARD)) { - targetCtx->unk_94 = NULL; + targetCtx->arrowHoverActor = NULL; } else { func_80032AF0(play, &play->actorCtx, &unkActor, player); - targetCtx->unk_94 = unkActor; + targetCtx->arrowHoverActor = unkActor; } if (targetCtx->unk_8C != NULL) { @@ -489,7 +501,7 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Pl Target_SetNaviState(targetCtx, unkActor, actorCategory, play); } - if ((actorArg != NULL) && (targetCtx->unk_4B == 0)) { + if ((actorArg != NULL) && (targetCtx->reticleSpinCounter == 0)) { Actor_ProjectPos(play, &actorArg->focus.pos, &projectedFocusPos, &cappedInvWDest); if (((projectedFocusPos.z <= 0.0f) || (1.0f <= fabsf(projectedFocusPos.x * cappedInvWDest))) || (1.0f <= fabsf(projectedFocusPos.y * cappedInvWDest))) { @@ -498,14 +510,14 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Pl } if (actorArg != NULL) { - if (actorArg != targetCtx->targetedActor) { + if (actorArg != targetCtx->lockOnActor) { s32 lockOnSfxId; Target_InitReticle(targetCtx, actorArg->category, play); - targetCtx->targetedActor = actorArg; + targetCtx->lockOnActor = actorArg; if (actorArg->id == ACTOR_EN_BOOM) { - targetCtx->unk_48 = 0; + targetCtx->reticleFadeAlphaControl = 0; } lockOnSfxId = CHECK_FLAG_ALL(actorArg->flags, ACTOR_FLAG_0 | ACTOR_FLAG_2) ? NA_SE_SY_LOCK_ON @@ -513,23 +525,23 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Pl Sfx_PlaySfxCentered(lockOnSfxId); } - targetCtx->targetCenterPos.x = actorArg->world.pos.x; - targetCtx->targetCenterPos.y = actorArg->world.pos.y - (actorArg->shape.yOffset * actorArg->scale.y); - targetCtx->targetCenterPos.z = actorArg->world.pos.z; + targetCtx->lockOnPos.x = actorArg->world.pos.x; + targetCtx->lockOnPos.y = actorArg->world.pos.y - (actorArg->shape.yOffset * actorArg->scale.y); + targetCtx->lockOnPos.z = actorArg->world.pos.z; - if (targetCtx->unk_4B == 0) { + if (targetCtx->reticleSpinCounter == 0) { f32 temp5 = (500.0f - targetCtx->reticleRadius) * 3.0f; f32 temp6 = (temp5 < 30.0f) ? 30.0f : ((100.0f < temp5) ? 100.0f : temp5); if (Math_StepToF(&targetCtx->reticleRadius, 80.0f, temp6) != 0) { - targetCtx->unk_4B++; + targetCtx->reticleSpinCounter++; } } else { - targetCtx->unk_4B = (targetCtx->unk_4B + 3) | 0x80; + targetCtx->reticleSpinCounter = (targetCtx->reticleSpinCounter + 3) | 0x80; targetCtx->reticleRadius = 120.0f; } } else { - targetCtx->targetedActor = NULL; + targetCtx->lockOnActor = NULL; Math_StepToF(&targetCtx->reticleRadius, 500.0f, 80.0f); } } @@ -2313,8 +2325,8 @@ void Actor_UpdateAll(PlayState* play, ActorContext* actorCtx) { if ((actor == NULL) || (player->unk_66C < 5)) { actor = NULL; - if (actorCtx->targetCtx.unk_4B != 0) { - actorCtx->targetCtx.unk_4B = 0; + if (actorCtx->targetCtx.reticleSpinCounter != 0) { + actorCtx->targetCtx.reticleSpinCounter = 0; Sfx_PlaySfxCentered(NA_SE_SY_LOCK_OFF); } } diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index d4c9825a7..40060d000 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -3272,7 +3272,7 @@ void Interface_Draw(PlayState* play) { if ((R_PAUSE_BG_PRERENDER_STATE != PAUSE_BG_PRERENDER_PROCESS) && (R_PAUSE_BG_PRERENDER_STATE != PAUSE_BG_PRERENDER_READY)) { - func_8002C124(&play->actorCtx.targetCtx, play); // Draw Z-Target + Target_Draw(&play->actorCtx.targetCtx, play); } Gfx_SetupDL_39Overlay(play->state.gfxCtx); |
