From aecd883bbce3963f9c7c81dc17cc701172764499 Mon Sep 17 00:00:00 2001 From: hatal175 Date: Mon, 31 Jan 2022 11:36:58 +0200 Subject: [PATCH] Document some z_actor.c functions (#1091) --- include/functions.h | 4 +- src/code/z_actor.c | 99 ++++++++++--------- src/code/z_lights.c | 10 +- src/code/z_malloc.c | 2 +- .../actors/ovl_player_actor/z_player.c | 4 +- 5 files changed, 60 insertions(+), 59 deletions(-) diff --git a/include/functions.h b/include/functions.h index 5dcf327879..6a3f86265d 100644 --- a/include/functions.h +++ b/include/functions.h @@ -347,7 +347,7 @@ void ActorShadow_DrawHorse(Actor* actor, Lights* lights, GlobalContext* globalCt void ActorShadow_DrawFeet(Actor* actor, Lights* lights, GlobalContext* globalCtx); void Actor_SetFeetPos(Actor* actor, s32 limbIndex, s32 leftFootIndex, Vec3f* leftFootPos, s32 rightFootIndex, Vec3f* rightFootPos); -void func_8002BE04(GlobalContext* globalCtx, Vec3f* arg1, Vec3f* arg2, f32* arg3); +void Actor_ProjectPos(GlobalContext* globalCtx, Vec3f* src, Vec3f* xyzDest, f32* cappedInvWDest); void func_8002C124(TargetContext* targetCtx, GlobalContext* globalCtx); s32 Flags_GetSwitch(GlobalContext* globalCtx, s32 flag); void Flags_SetSwitch(GlobalContext* globalCtx, s32 flag); @@ -369,7 +369,7 @@ void TitleCard_InitBossName(GlobalContext* globalCtx, TitleCardContext* titleCtx u8 height); void TitleCard_InitPlaceName(GlobalContext* globalCtx, TitleCardContext* titleCtx, void* texture, s32 x, s32 y, s32 width, s32 height, s32 delay); -s32 func_8002D53C(GlobalContext* globalCtx, TitleCardContext* titleCtx); +s32 TitleCard_Clear(GlobalContext* globalCtx, TitleCardContext* titleCtx); void Actor_Kill(Actor* actor); void Actor_SetFocus(Actor* actor, f32 offset); void Actor_SetScale(Actor* actor, f32 scale); diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 39db8cafa3..e3df1542cb 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -213,9 +213,9 @@ void Actor_SetFeetPos(Actor* actor, s32 limbIndex, s32 leftFootIndex, Vec3f* lef } } -void func_8002BE04(GlobalContext* globalCtx, Vec3f* arg1, Vec3f* arg2, f32* arg3) { - SkinMatrix_Vec3fMtxFMultXYZW(&globalCtx->viewProjectionMtxF, arg1, arg2, arg3); - *arg3 = (*arg3 < 1.0f) ? 1.0f : (1.0f / *arg3); +void Actor_ProjectPos(GlobalContext* globalCtx, Vec3f* src, Vec3f* xyzDest, f32* cappedInvWDest) { + SkinMatrix_Vec3fMtxFMultXYZW(&globalCtx->viewProjectionMtxF, src, xyzDest, cappedInvWDest); + *cappedInvWDest = (*cappedInvWDest < 1.0f) ? 1.0f : (1.0f / *cappedInvWDest); } typedef struct { @@ -266,7 +266,7 @@ void func_8002BE98(TargetContext* targetCtx, s32 actorCategory, GlobalContext* g } } -void func_8002BF60(TargetContext* targetCtx, Actor* actor, s32 actorCategory, GlobalContext* globalCtx) { +void Actor_SetNaviToActor(TargetContext* targetCtx, Actor* actor, s32 actorCategory, GlobalContext* globalCtx) { NaviColor* naviColor = &sNaviColorList[actorCategory]; targetCtx->naviRefPos.x = actor->focus.pos.x; targetCtx->naviRefPos.y = actor->focus.pos.y + (actor->targetArrowOffset * actor->scale.y); @@ -289,7 +289,7 @@ void func_8002C0C0(TargetContext* targetCtx, Actor* actor, GlobalContext* global targetCtx->bgmEnemy = NULL; targetCtx->unk_4B = 0; targetCtx->unk_4C = 0; - func_8002BF60(targetCtx, actor, actor->category, globalCtx); + Actor_SetNaviToActor(targetCtx, actor, actor->category, globalCtx); func_8002BE98(targetCtx, actor->category, globalCtx); } @@ -303,9 +303,9 @@ void func_8002C124(TargetContext* targetCtx, GlobalContext* globalCtx) { Player* player; s16 spCE; f32 temp1; - Vec3f spBC; + Vec3f projTargetCenter; s32 spB8; - f32 spB4; + f32 projTargetCappedInvW; s32 spB0; s32 spAC; f32 var1; @@ -334,22 +334,22 @@ void func_8002C124(TargetContext* targetCtx, GlobalContext* globalCtx) { spCE = targetCtx->unk_48; } - func_8002BE04(globalCtx, &targetCtx->targetCenterPos, &spBC, &spB4); + Actor_ProjectPos(globalCtx, &targetCtx->targetCenterPos, &projTargetCenter, &projTargetCappedInvW); - spBC.x = (160 * (spBC.x * spB4)) * var1; - spBC.x = CLAMP(spBC.x, -320.0f, 320.0f); + projTargetCenter.x = (160 * (projTargetCenter.x * projTargetCappedInvW)) * var1; + projTargetCenter.x = CLAMP(projTargetCenter.x, -320.0f, 320.0f); - spBC.y = (120 * (spBC.y * spB4)) * var1; - spBC.y = CLAMP(spBC.y, -240.0f, 240.0f); + projTargetCenter.y = (120 * (projTargetCenter.y * projTargetCappedInvW)) * var1; + projTargetCenter.y = CLAMP(projTargetCenter.y, -240.0f, 240.0f); - spBC.z = spBC.z * var1; + projTargetCenter.z = projTargetCenter.z * var1; targetCtx->unk_4C--; if (targetCtx->unk_4C < 0) { targetCtx->unk_4C = 2; } - func_8002BE64(targetCtx, targetCtx->unk_4C, spBC.x, spBC.y, spBC.z); + func_8002BE64(targetCtx, targetCtx->unk_4C, projTargetCenter.x, projTargetCenter.y, projTargetCenter.z); if ((!(player->stateFlags1 & PLAYER_STATE1_6)) || (actor != player->unk_664)) { OVERLAY_DISP = Gfx_CallSetupDL(OVERLAY_DISP, 0x39); @@ -414,8 +414,8 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Gl s32 pad; Actor* unkActor; s32 actorCategory; - Vec3f sp50; - f32 sp4C; + Vec3f projectedFocusPos; + f32 cappedInvWDest; f32 temp1; f32 temp2; f32 temp3; @@ -465,12 +465,12 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Gl targetCtx->naviRefPos.y += temp3 * temp1; targetCtx->naviRefPos.z += temp4 * temp1; } else { - func_8002BF60(targetCtx, unkActor, actorCategory, globalCtx); + Actor_SetNaviToActor(targetCtx, unkActor, actorCategory, globalCtx); } if ((actorArg != NULL) && (targetCtx->unk_4B == 0)) { - func_8002BE04(globalCtx, &actorArg->focus.pos, &sp50, &sp4C); - if (((sp50.z <= 0.0f) || (1.0f <= fabsf(sp50.x * sp4C))) || (1.0f <= fabsf(sp50.y * sp4C))) { + Actor_ProjectPos(globalCtx, &actorArg->focus.pos, &projectedFocusPos, &cappedInvWDest); + if (((projectedFocusPos.z <= 0.0f) || (1.0f <= fabsf(projectedFocusPos.x * cappedInvWDest))) || (1.0f <= fabsf(projectedFocusPos.y * cappedInvWDest))) { actorArg = NULL; } } @@ -655,7 +655,7 @@ void Flags_SetCollectible(GlobalContext* globalCtx, s32 flag) { } } -void func_8002CDE4(GlobalContext* globalCtx, TitleCardContext* titleCtx) { +void TitleCard_Init(GlobalContext* globalCtx, TitleCardContext* titleCtx) { titleCtx->durationTimer = titleCtx->delayTimer = titleCtx->intensity = titleCtx->alpha = 0; } @@ -701,48 +701,49 @@ void TitleCard_Update(GlobalContext* globalCtx, TitleCardContext* titleCtx) { } void TitleCard_Draw(GlobalContext* globalCtx, TitleCardContext* titleCtx) { - s32 spCC; - s32 spC8; - s32 unk1; - s32 spC0; - s32 sp38; - s32 spB8; - s32 spB4; - s32 spB0; + s32 width; + s32 height; + s32 unused; + s32 titleX; + s32 doubleWidth; + s32 titleY; + s32 titleSecondY; + s32 textureLanguageOffset; if (titleCtx->alpha != 0) { - spCC = titleCtx->width; - spC8 = titleCtx->height; - spC0 = (titleCtx->x * 4) - (spCC * 2); - spB8 = (titleCtx->y * 4) - (spC8 * 2); - sp38 = spCC * 2; + width = titleCtx->width; + height = titleCtx->height; + titleX = (titleCtx->x * 4) - (width * 2); + titleY = (titleCtx->y * 4) - (height * 2); + doubleWidth = width * 2; OPEN_DISPS(globalCtx->state.gfxCtx, "../z_actor.c", 2824); - spB0 = spCC * spC8 * gSaveContext.language; - spC8 = (spCC * spC8 > 0x1000) ? 0x1000 / spCC : spC8; - spB4 = spB8 + (spC8 * 4); + textureLanguageOffset = width * height * gSaveContext.language; + height = (width * height > 0x1000) ? 0x1000 / width : height; + titleSecondY = titleY + (height * 4); OVERLAY_DISP = func_80093808(OVERLAY_DISP); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, (u8)titleCtx->intensity, (u8)titleCtx->intensity, (u8)titleCtx->intensity, (u8)titleCtx->alpha); - gDPLoadTextureBlock(OVERLAY_DISP++, (s32)titleCtx->texture + spB0, G_IM_FMT_IA, G_IM_SIZ_8b, spCC, spC8, 0, + gDPLoadTextureBlock(OVERLAY_DISP++, (s32)titleCtx->texture + textureLanguageOffset, G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(OVERLAY_DISP++, spC0, spB8, ((sp38 * 2) + spC0) - 4, spB8 + (spC8 * 4) - 1, G_TX_RENDERTILE, + gSPTextureRectangle(OVERLAY_DISP++, titleX, titleY, ((doubleWidth * 2) + titleX) - 4, titleY + (height * 4) - 1, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); - spC8 = titleCtx->height - spC8; + height = titleCtx->height - height; - if (spC8 > 0) { - gDPLoadTextureBlock(OVERLAY_DISP++, (s32)titleCtx->texture + spB0 + 0x1000, G_IM_FMT_IA, G_IM_SIZ_8b, spCC, - spC8, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, + // If texture is bigger than 0x1000, display the rest + if (height > 0) { + gDPLoadTextureBlock(OVERLAY_DISP++, (s32)titleCtx->texture + textureLanguageOffset + 0x1000, G_IM_FMT_IA, G_IM_SIZ_8b, width, + height, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(OVERLAY_DISP++, spC0, spB4, ((sp38 * 2) + spC0) - 4, spB4 + (spC8 * 4) - 1, + gSPTextureRectangle(OVERLAY_DISP++, titleX, titleSecondY, ((doubleWidth * 2) + titleX) - 4, titleSecondY + (height * 4) - 1, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); } @@ -750,7 +751,7 @@ void TitleCard_Draw(GlobalContext* globalCtx, TitleCardContext* titleCtx) { } } -s32 func_8002D53C(GlobalContext* globalCtx, TitleCardContext* titleCtx) { +s32 TitleCard_Clear(GlobalContext* globalCtx, TitleCardContext* titleCtx) { if ((globalCtx->actorCtx.titleCtx.delayTimer != 0) || (globalCtx->actorCtx.titleCtx.alpha != 0)) { titleCtx->durationTimer = 0; titleCtx->delayTimer = 0; @@ -1550,11 +1551,11 @@ s8 func_8002F368(GlobalContext* globalCtx) { void Actor_GetScreenPos(GlobalContext* globalCtx, Actor* actor, s16* x, s16* y) { Vec3f projectedPos; - f32 w; + f32 cappedInvW; - func_8002BE04(globalCtx, &actor->focus.pos, &projectedPos, &w); - *x = projectedPos.x * w * (SCREEN_WIDTH / 2) + (SCREEN_WIDTH / 2); - *y = projectedPos.y * w * -(SCREEN_HEIGHT / 2) + (SCREEN_HEIGHT / 2); + Actor_ProjectPos(globalCtx, &actor->focus.pos, &projectedPos, &cappedInvW); + *x = projectedPos.x * cappedInvW * (SCREEN_WIDTH / 2) + (SCREEN_WIDTH / 2); + *y = projectedPos.y * cappedInvW * -(SCREEN_HEIGHT / 2) + (SCREEN_HEIGHT / 2); } u32 Actor_HasParent(Actor* actor, GlobalContext* globalCtx) { @@ -1977,7 +1978,7 @@ void func_800304DC(GlobalContext* globalCtx, ActorContext* actorCtx, ActorEntry* actorCtx->flags.clear = savedSceneFlags->clear; actorCtx->flags.collect = savedSceneFlags->collect; - func_8002CDE4(globalCtx, &actorCtx->titleCtx); + TitleCard_Init(globalCtx, &actorCtx->titleCtx); actorCtx->absoluteSpace = NULL; diff --git a/src/code/z_lights.c b/src/code/z_lights.c index 3067b712b1..f6cf5c7a82 100644 --- a/src/code/z_lights.c +++ b/src/code/z_lights.c @@ -321,7 +321,7 @@ void Lights_GlowCheck(GlobalContext* globalCtx) { LightPoint* params; Vec3f pos; Vec3f multDest; - f32 wDest; + f32 cappedInvWDest; f32 wX; f32 wY; s32 wZ; @@ -336,13 +336,13 @@ void Lights_GlowCheck(GlobalContext* globalCtx) { pos.x = params->x; pos.y = params->y; pos.z = params->z; - func_8002BE04(globalCtx, &pos, &multDest, &wDest); + Actor_ProjectPos(globalCtx, &pos, &multDest, &cappedInvWDest); params->drawGlow = false; - wX = multDest.x * wDest; - wY = multDest.y * wDest; + wX = multDest.x * cappedInvWDest; + wY = multDest.y * cappedInvWDest; if ((multDest.z > 1.0f) && (fabsf(wX) < 1.0f) && (fabsf(wY) < 1.0f)) { - wZ = (s32)((multDest.z * wDest) * 16352.0f) + 16352; + wZ = (s32)((multDest.z * cappedInvWDest) * 16352.0f) + 16352; zBuf = gZBuffer[(s32)((wY * -120.0f) + 120.0f)][(s32)((wX * 160.0f) + 160.0f)] * 4; if (1) {} if (1) {} diff --git a/src/code/z_malloc.c b/src/code/z_malloc.c index f9fa2f310e..1094627220 100644 --- a/src/code/z_malloc.c +++ b/src/code/z_malloc.c @@ -77,7 +77,7 @@ void* ZeldaArena_Calloc(u32 num, u32 size) { bzero(ret, n); } - ZeldaArena_CheckPointer(ret, n, "zelda_calloc", "確保"); + ZeldaArena_CheckPointer(ret, n, "zelda_calloc", "確保"); // "Secure" return ret; } diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 925d5ab06b..94c2f582cd 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2770,7 +2770,7 @@ void func_80835F44(GlobalContext* globalCtx, Player* this, s32 item) { (actionParam >= PLAYER_AP_BOTTLE_FISH)) { if (!func_8008E9C4(this) || ((actionParam >= PLAYER_AP_BOTTLE_POTION_RED) && (actionParam <= PLAYER_AP_BOTTLE_FAIRY))) { - func_8002D53C(globalCtx, &globalCtx->actorCtx.titleCtx); + TitleCard_Clear(globalCtx, &globalCtx->actorCtx.titleCtx); this->unk_6AD = 4; this->itemActionParam = actionParam; } @@ -5890,7 +5890,7 @@ s32 func_8083E5A8(Player* this, GlobalContext* globalCtx) { Actor* interactedActor; if (iREG(67) || (((interactedActor = this->interactRangeActor) != NULL) && - func_8002D53C(globalCtx, &globalCtx->actorCtx.titleCtx))) { + TitleCard_Clear(globalCtx, &globalCtx->actorCtx.titleCtx))) { if (iREG(67) || (this->getItemId > GI_NONE)) { if (iREG(67)) { this->getItemId = iREG(68);