From 84ce52ae4e7fe0ab2a6cbacd0ebd415ecaeb1ff8 Mon Sep 17 00:00:00 2001 From: TrulyNaN <52424023+TrulyNaN@users.noreply.github.com> Date: Mon, 11 Jul 2022 20:43:19 -0400 Subject: [PATCH] ovl_Bg_Ikana_Mirror OK and documented (#873) * test commit * undoing test commit * making sure this is the right repo * removing test file * init for OSH bombable wall started. put back Actor* in function declarations. * BgKin2Bombwall_Init is matching. * started z_bg_kin2_bombwall destroy function. One mismatch right now. * BgKin2Bombwall_Destroy matches. * BgKin2Bombwall_Draw matches. * Fixed BgKin2Bombwall_Init * BgKin2Bombwall_Init and BgKin2Bombwall_Destroy both match. Fixed s32 array in struct. * BgKin2Bombwall_Draw and BgKin2Bombwall_Update match. * Only func_80B6E020 and func_80B6E090 left to match in ovl_Bg_Kin2_Bombwall. * func_80B6E020 from ovl_Bg_Kin2_Bombwall matches. * Went from 8925 to about 5-6k diff score for func_80B6E090 in ovl_Bg_Kin2_Bombwall * Took func_80B6E090 from about 5300 diff score to about 4300 diff score in ovl_Bg_Kin2_Bombwall. * Diff score for ovl_Bg_Kin2_Bombwall func_80B6E090 went from 4k ish to 3277 * Diff score for ovl_Bg_Kin2_Bombwall func_80B6E090 went from 3277 to 2262. * Diff score for ovl_Bg_Kin2_Bombwall func_80B6E090 went from 2262 to 1589. * only slight progress on ovl_Bg_Kinw_Bombwall's func_80B6E090 * Got to 1473 diff score on ovl_Bg_Kinw_Bombwall's func_80B6E090 * Put in the changes made by EllipticEllipsis and hensldm for ovl_Bg_Kin2_Bombwall's func_8066E090. * renamed some symbols. Fake symbol removal makes nonzero diff, but rom OK's after make. * moving declarations around, ordering. * One.word.away. from importing data in ovl_Bg_Kin2_Bombwall. * ovl_Bg_Kin2_Bombwall data imported. Matching. * Edited spec for reloc of ovl_Bg_Kin2_Bombwall. * Removed extra comments for ovl_Bg_Kin2_Bombwall. * unpushed stuff. dunno. * forgot to save z_bg_kin2_bombwall.c * need to commit before make-ing in master. * Ported z_bg_kin2_bombwall's code. Data next. * Imported data for merging z_bg_kin2_bombwall. Yes, I yelled when it OK'd. * Added comments to remember what does what in z_bg_kin2_bombwall. * Some comments in z_bg_kin2_bombwall.c and function names ideas. * Added comments for function name ideas. Cleaned up temps in z_bg_kin2_bombwall except in func_80B6E090. * Renamed most functions and some variables in z_bg_kin2_bombwall. * Made a name suggestion for func_80B6E020 after testing in game. * Ran format.sh. * Update src/overlays/actors/ovl_Bg_Kin2_Bombwall/z_bg_kin2_bombwall.c 1 and 0 replaced by true and false in func_80B6E020. Co-authored-by: Isghj <42048411+isghj5@users.noreply.github.com> * Update src/overlays/actors/ovl_Bg_Kin2_Bombwall/z_bg_kin2_bombwall.c Bending to the x-- supremacy. Co-authored-by: Isghj <42048411+isghj5@users.noreply.github.com> * PR fixes (not done yet) including more consistent use of THIS, removing arg0 and arg1 variable names, standardizing params for z_bg_kin2_bombwall, turning some if-return to if-else, removing unnecessary casts. * Applied isghj5's and EllipticEllipsis' suggestions except for the object file in z_bg_kin2_bombwall. Object file next. * Screwd up formatting. * Thinking of playing with object_kin2_obj. * Documented most of object_kin2_obj based on bombwall, fence and shelf actors. * Had forgotten an arg1 in z_bg_kin2_bombwall.c * First commit for ovl_Bg_Ikana_Mirror branch. * Started decompiling ovl_Bg_Ikana_Mirror. Setup functions and _Update done matching. * Replaced a float by its fractional representation. I need to learn float magic. * Update src/overlays/actors/ovl_Bg_Kin2_Bombwall/z_bg_kin2_bombwall.c Co-authored-by: EllipticEllipsis * Update src/overlays/actors/ovl_Bg_Kin2_Bombwall/z_bg_kin2_bombwall.h Co-authored-by: EllipticEllipsis * Applied more formatting and naming remarks from PR about the C file. Assets and object stuff next. * Display lists and collision header in z_bg_kin2_bombwall.c renamed after their descriptive names in the object's XML file. Name for Ocean Spider House drawers chests left to change. * Working on BgIkanaMirror_Destroy. Stack and registers left essentially. * Update src/overlays/actors/ovl_Bg_Kin2_Bombwall/z_bg_kin2_bombwall.c Co-authored-by: Derek Hensley * One extra line in an if, collision naming convention applied and renamed Ocean Spider House nightstands to drawers chests. * Update src/overlays/actors/ovl_Bg_Kin2_Bombwall/z_bg_kin2_bombwall.c Co-authored-by: Derek Hensley * Changed drawers chest to chest of drawers in object_kin2_obj and z_bg_kin2_shelf. * Removed some unnecessary comment. * almost done with BgIkanaMirror_Destroy function. * Update src/overlays/actors/ovl_Bg_Kin2_Bombwall/z_bg_kin2_bombwall.c Co-authored-by: EllipticEllipsis * BgIkanaMirror_Destroy OK. * Almost done with BgIkanaMirror_Init. Mostly stack stuff left. * Registers and stack left to fix for BgIkanaMirror_Init. * BgIkanaMirror_Init matching. * Ran permuter to improve BgIkanaMirror_Draw's score. * Actually not mad at permuter for BgIkanaMirror_Draw headstart. * Matched func_80B7F730 in ovl_Bg_Ikana_Mirror. Progress on its _Init done too. * func_80B7FA9C in ovl_Bg_Ikana_Mirror is matching. _Init left then documentation. * Mistake in last commit message: actually, _Draw is left for ovl_Bg_Ikana_Mirror. * Going to do some groceries, so pushing. About 2/3 across func_80B7FBA4 in ovl_Bg_Ikana_Mirror. * func_80B7FBA4 in ovl_Bg_Ikana_Mirror is matching. _Draw then data left. * Need to switch branch. * Fixed BgKin2Bombwall_SpawnEffects after the Rand_Next() type update. * Switching branch. * Learning to decomp draw functions with BgIkanaMirror_Draw. YEP * Switching branch. * Went through the first wave of graphics macros attempts for BgIkanaMirror_Draw. * Removed some temps in BgIkanaMirror_Draw. * Second pass of macro attempts for BgIkanaMirror_Draw. * Diff score for BgIkanaMirror_Draw at 1873. Getting there. * BgIkanaMirror_Draw diff score down to 854. 4 instructions off and registers to fix. * Instructions are matching for BgIkanaMirror_Draw. Registers left. * BgIkanaMirror_Draw matches. Data next. Adding some co-authors * BgIkanaMirror_Draw matches. Data next. Adding some co-authors Co-authored-by: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Co-authored-by: Tom-Overton Co-authored-by: Isghj5 Co-authored-by: mzxrules Co-authored-by: Derek-Hensley * Data imported and OK. Co-authored-by: Maide Co-authored-by: mzxrules Co-authored-by: Derek-Hensley * Removed commented lines of unused code and useless externs. Documenting C file and object next. * Renamed fields in actor and variables in 3 functions for ovl_bg_ikana_mirror. Some conventions applied. * Renamed more variables in the struct and C file for ovl_bg_ikana_mirror. * More cleanups and naming in ovl_Bg_Ikana_Mirror. * Renamed some functions in ovl_Bg_Ikana_Mirror. More cleanups. Object documentation next once function names confirmed. * Renamed collision header, animated textures and display lists for ovl_Bg_Ikana_Mirror in ovl_Bg_Ikana_Mirror and object_ikana_obj. Some textures left to rename. * Renamed textures only used by ovl_Bg_Ikana_Mirror. Must go back through docs for conventions and styles plus an extra cleanup before PR. * Went through merging and review docs for extra cleanups. Adding co-authors for documentation. Co-authored-by: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Co-authored-by: Derek-Hensley * Creating branch to merge ovl_Bg_Ikana_Mirror. * Fixed the merge from zeldaret/mm. ovl_Bg_Ikana_Mirror OK and documented. PR-ready. * Applied first batch of fixes from PR comments. Adding co-authors for documentation and a function rewrite. Co-authored-by: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Co-authored-by: Derek-Hensley Co-authored-by: Kelebek1 * Renamed the colliders in ovl_Bg_Ikana_Mirror's struct and fixed naming in object file plus spacing cleanups. * Full rename for data and temps with respect to the mirror's and light rays' respective colliders. * Update src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.h Co-authored-by: EllipticEllipsis * Update src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.c Co-authored-by: EllipticEllipsis * Update src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.c Co-authored-by: EllipticEllipsis * Update src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.c Co-authored-by: EllipticEllipsis * Formatting needed to be applied after commiting suggestions. * Renamed more textures and removed unnecessary array sizes in the data. * Forgot to run formatter. Co-authored-by: Isghj <42048411+isghj5@users.noreply.github.com> Co-authored-by: EllipticEllipsis Co-authored-by: Derek Hensley Co-authored-by: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Co-authored-by: Isghj5 Co-authored-by: mzxrules Co-authored-by: Maide --- assets/xml/objects/object_ikana_obj.xml | 24 +- spec | 3 +- .../ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.c | 394 +++++++++++++++--- .../ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.h | 17 +- tools/disasm/functions.txt | 10 +- 5 files changed, 367 insertions(+), 81 deletions(-) diff --git a/assets/xml/objects/object_ikana_obj.xml b/assets/xml/objects/object_ikana_obj.xml index 6040495ab8..e0490a3495 100644 --- a/assets/xml/objects/object_ikana_obj.xml +++ b/assets/xml/objects/object_ikana_obj.xml @@ -17,15 +17,15 @@ - + - - + + - + - - + + @@ -39,7 +39,7 @@ - + @@ -51,11 +51,11 @@ - - - - - + + + + + diff --git a/spec b/spec index 251581be37..eda0cfe476 100644 --- a/spec +++ b/spec @@ -4137,8 +4137,7 @@ beginseg name "ovl_Bg_Ikana_Mirror" compress include "build/src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.o" - include "build/data/ovl_Bg_Ikana_Mirror/ovl_Bg_Ikana_Mirror.data.o" - include "build/data/ovl_Bg_Ikana_Mirror/ovl_Bg_Ikana_Mirror.reloc.o" + include "build/src/overlays/actors/ovl_Bg_Ikana_Mirror/ovl_Bg_Ikana_Mirror_reloc.o" endseg beginseg diff --git a/src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.c b/src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.c index 0a3b7b4456..cfa67eb1de 100644 --- a/src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.c +++ b/src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.c @@ -2,9 +2,15 @@ * File: z_bg_ikana_mirror.c * Overlay: ovl_Bg_Ikana_Mirror * Description: Stone Tower Temple - Mirror + * + * This mirror absorbs light reflected by the mirror shield or by another mirror of the same kind for a + * maximum of 400 frames (20 seconds) to then release light for the same number of frames it was charged. This number + * of frames is stored in the actor struct's lightRayCharge field and is updated in the BgIkanaMirror_Wait and + * BgIkanaMirror_EmitLight functions both described below. */ #include "z_bg_ikana_mirror.h" +#include "objects/object_ikana_obj/object_ikana_obj.h" #define FLAGS (ACTOR_FLAG_10) @@ -15,7 +21,11 @@ void BgIkanaMirror_Destroy(Actor* thisx, PlayState* play); void BgIkanaMirror_Update(Actor* thisx, PlayState* play); void BgIkanaMirror_Draw(Actor* thisx, PlayState* play); -#if 0 +void BgIkanaMirror_SetupWait(BgIkanaMirror* this); +void BgIkanaMirror_Wait(BgIkanaMirror* this, PlayState* play); +void BgIkanaMirror_SetupEmitLight(BgIkanaMirror* this); +void BgIkanaMirror_EmitLight(BgIkanaMirror* this, PlayState* play); + const ActorInit Bg_Ikana_Mirror_InitVars = { ACTOR_BG_IKANA_MIRROR, ACTORCAT_PROP, @@ -28,99 +38,371 @@ const ActorInit Bg_Ikana_Mirror_InitVars = { (ActorFunc)BgIkanaMirror_Draw, }; -// static ColliderTrisElementInit sTrisElementsInit[9] = { -static ColliderTrisElementInit D_80B7FF50[9] = { +static ColliderTrisElementInit sMirrorColliderElementsInit[] = { { - { ELEMTYPE_UNK4, { 0x00000000, 0x00, 0x00 }, { 0x00200000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_NONE, }, - { { { 0.0f, 21.600000381469727f, 13.699999809265137f }, { -25.299999237060547f, 6.0f, 8.399999618530273f }, { 25.299999237060547f, 6.0f, 8.399999618530273f } } }, + { + ELEMTYPE_UNK4, + { 0x00000000, 0x00, 0x00 }, + { 0x00200000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { { { 0.0f, 21.6f, 13.7f }, { -25.3f, 6.0f, 8.4f }, { 25.3f, 6.0f, 8.4f } } }, }, { - { ELEMTYPE_UNK4, { 0x00000000, 0x00, 0x00 }, { 0x00200000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_NONE, }, - { { { 0.0f, 45.0f, 13.699999809265137f }, { -25.299999237060547f, 6.0f, 8.399999618530273f }, { 0.0f, 21.600000381469727f, 13.699999809265137f } } }, + { + ELEMTYPE_UNK4, + { 0x00000000, 0x00, 0x00 }, + { 0x00200000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { { { 0.0f, 45.0f, 13.7f }, { -25.3f, 6.0f, 8.4f }, { 0.0f, 21.6f, 13.7f } } }, }, { - { ELEMTYPE_UNK4, { 0x00000000, 0x00, 0x00 }, { 0x00200000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_NONE, }, - { { { 0.0f, 45.0f, 13.699999809265137f }, { 0.0f, 21.600000381469727f, 13.699999809265137f }, { 25.299999237060547f, 6.0f, 8.399999618530273f } } }, + { + ELEMTYPE_UNK4, + { 0x00000000, 0x00, 0x00 }, + { 0x00200000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { { { 0.0f, 45.0f, 13.7f }, { 0.0f, 21.6f, 13.7f }, { 25.3f, 6.0f, 8.4f } } }, }, { - { ELEMTYPE_UNK4, { 0x00000000, 0x00, 0x00 }, { 0x00200000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_NONE, }, - { { { 0.0f, 45.0f, 13.699999809265137f }, { -25.299999237060547f, 45.0f, 8.399999618530273f }, { -25.299999237060547f, 6.0f, 8.399999618530273f } } }, + { + ELEMTYPE_UNK4, + { 0x00000000, 0x00, 0x00 }, + { 0x00200000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { { { 0.0f, 45.0f, 13.7f }, { -25.3f, 45.0f, 8.4f }, { -25.3f, 6.0f, 8.4f } } }, }, { - { ELEMTYPE_UNK4, { 0x00000000, 0x00, 0x00 }, { 0x00200000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_NONE, }, - { { { 0.0f, 45.0f, 13.699999809265137f }, { 25.299999237060547f, 6.0f, 8.399999618530273f }, { 25.299999237060547f, 45.0f, 8.399999618530273f } } }, + { + ELEMTYPE_UNK4, + { 0x00000000, 0x00, 0x00 }, + { 0x00200000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { { { 0.0f, 45.0f, 13.7f }, { 25.3f, 6.0f, 8.4f }, { 25.3f, 45.0f, 8.4f } } }, }, { - { ELEMTYPE_UNK4, { 0x00000000, 0x00, 0x00 }, { 0x00200000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_NONE, }, - { { { 0.0f, 45.0f, 13.699999809265137f }, { -17.899999618530273f, 64.0999984741211f, 8.399999618530273f }, { -25.299999237060547f, 45.0f, 8.399999618530273f } } }, + { + ELEMTYPE_UNK4, + { 0x00000000, 0x00, 0x00 }, + { 0x00200000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { { { 0.0f, 45.0f, 13.7f }, { -17.9f, 64.1f, 8.4f }, { -25.3f, 45.0f, 8.4f } } }, }, { - { ELEMTYPE_UNK4, { 0x00000000, 0x00, 0x00 }, { 0x00200000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_NONE, }, - { { { 0.0f, 45.0f, 13.699999809265137f }, { 25.299999237060547f, 45.0f, 8.399999618530273f }, { 17.899999618530273f, 64.0999984741211f, 8.399999618530273f } } }, + { + ELEMTYPE_UNK4, + { 0x00000000, 0x00, 0x00 }, + { 0x00200000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { { { 0.0f, 45.0f, 13.7f }, { 25.3f, 45.0f, 8.4f }, { 17.9f, 64.1f, 8.4f } } }, }, { - { ELEMTYPE_UNK4, { 0x00000000, 0x00, 0x00 }, { 0x00200000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_NONE, }, - { { { 0.0f, 45.0f, 13.699999809265137f }, { 0.0f, 72.0f, 8.399999618530273f }, { -17.899999618530273f, 64.0999984741211f, 8.399999618530273f } } }, + { + ELEMTYPE_UNK4, + { 0x00000000, 0x00, 0x00 }, + { 0x00200000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { { { 0.0f, 45.0f, 13.7f }, { 0.0f, 72.0f, 8.4f }, { -17.9f, 64.1f, 8.4f } } }, }, { - { ELEMTYPE_UNK4, { 0x00000000, 0x00, 0x00 }, { 0x00200000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_ON, OCELEM_NONE, }, - { { { 0.0f, 45.0f, 13.699999809265137f }, { 17.899999618530273f, 64.0999984741211f, 8.399999618530273f }, { 0.0f, 72.0f, 8.399999618530273f } } }, + { + ELEMTYPE_UNK4, + { 0x00000000, 0x00, 0x00 }, + { 0x00200000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_ON, + OCELEM_NONE, + }, + { { { 0.0f, 45.0f, 13.7f }, { 17.9f, 64.1f, 8.4f }, { 0.0f, 72.0f, 8.4f } } }, }, }; -// static ColliderTrisInit sTrisInit = { -static ColliderTrisInit D_80B8016C = { - { COLTYPE_NONE, AT_NONE, AC_ON | AC_TYPE_PLAYER | AC_TYPE_OTHER, OC1_NONE, OC2_NONE, COLSHAPE_TRIS, }, - 9, D_80B7FF50, // sTrisElementsInit, +static ColliderTrisInit sMirrorColliderInit = { + { + COLTYPE_NONE, + AT_NONE, + AC_ON | AC_TYPE_PLAYER | AC_TYPE_OTHER, + OC1_NONE, + OC2_NONE, + COLSHAPE_TRIS, + }, + ARRAY_COUNT(sMirrorColliderElementsInit), + sMirrorColliderElementsInit, }; -// static ColliderQuadInit sQuadInit = { -static ColliderQuadInit D_80B8017C = { - { COLTYPE_NONE, AT_ON | AT_TYPE_OTHER, AC_NONE, OC1_NONE, OC2_NONE, COLSHAPE_QUAD, }, - { ELEMTYPE_UNK0, { 0x00200000, 0x00, 0x00 }, { 0x00000000, 0x00, 0x00 }, TOUCH_ON | TOUCH_SFX_NONE, BUMP_NONE, OCELEM_NONE, }, - { { { 0.0f, 72.0f, 20.0f }, { 0.0f, 72.0f, 240.0f }, { 0.0f, 6.0f, 20.0f }, { 0.0f, 6.0f, 240.0f } } }, +static ColliderQuadInit sLightRaysCollidersInit[] = { + { + { + COLTYPE_NONE, + AT_ON | AT_TYPE_OTHER, + AC_NONE, + OC1_NONE, + OC2_NONE, + COLSHAPE_QUAD, + }, + { + ELEMTYPE_UNK0, + { 0x00200000, 0x00, 0x00 }, + { 0x00000000, 0x00, 0x00 }, + TOUCH_ON | TOUCH_SFX_NONE, + BUMP_NONE, + OCELEM_NONE, + }, + { { { 0.0f, 72.0f, 20.0f }, { 0.0f, 72.0f, 240.0f }, { 0.0f, 6.0f, 20.0f }, { 0.0f, 6.0f, 240.0f } } }, + }, + { + { + COLTYPE_NONE, + AT_ON | AT_TYPE_OTHER, + AC_NONE, + OC1_NONE, + OC2_NONE, + COLSHAPE_QUAD, + }, + { + ELEMTYPE_UNK0, + { 0x00200000, 0x00, 0x00 }, + { 0x00000000, 0x00, 0x00 }, + TOUCH_ON | TOUCH_SFX_NONE, + BUMP_NONE, + OCELEM_NONE, + }, + { { { 25.3f, 20.0f, 20.0f }, { 25.3f, 20.0f, 240.0f }, { -25.3f, 20.0f, 20.0f }, { -25.3f, 20.0f, 240.0f } } }, + } }; -// static ColliderQuadInit sQuadInit = { -static ColliderQuadInit D_80B801FC = { - { 0x41, AT_NONE | AT_TYPE_OTHER, AC_NONE, OC1_NONE, OC2_FIRST_ONLY | OC2_UNK1 | OC2_HIT_PLAYER, 0x70, }, - { 0xC1, { 0x41A00000, 0x41, 0xA0 }, { 0xC1CA6666, 0x41, 0xA0 }, TOUCH_ON | TOUCH_HIT | TOUCH_SFX_NORMAL | TOUCH_DREW_HITMARK, BUMP_NONE | BUMP_NO_DAMAGE | BUMP_NO_SWORD_SFX | BUMP_NO_HITMARK, OCELEM_NONE, }, - { { { -1.8339854079840734e-09f, -1.8626939990440405e-09f, -1.9208972190654094e-09f }, { 221185.5625f, 0.0f, 0.003921568859368563f }, { 0.0f, 0.0f, 0.0f }, { 2.8698592549372254e-42f, 1.0761972206014595e-42f, 2.2420775429197073e-44f } } }, -}; - -// static InitChainEntry sInitChain[] = { -static InitChainEntry D_80B8021C[] = { +static InitChainEntry sInitChain[] = { ICHAIN_F32(uncullZoneForward, 4000, ICHAIN_CONTINUE), ICHAIN_F32(uncullZoneScale, 220, ICHAIN_CONTINUE), ICHAIN_F32(uncullZoneDownward, 200, ICHAIN_CONTINUE), ICHAIN_VEC3F_DIV1000(scale, 100, ICHAIN_STOP), }; -#endif +void BgIkanaMirror_SetQuadVertices(BgIkanaMirror* this) { + ColliderQuadDimInit* dim; + ColliderQuad* lightRaysCollider; + Vec3f v0; + Vec3f v1; + Vec3f v2; + Vec3f v3; + s32 i; -extern ColliderTrisElementInit D_80B7FF50[9]; -extern ColliderTrisInit D_80B8016C; -extern ColliderQuadInit D_80B8017C; -extern ColliderQuadInit D_80B801FC; -extern InitChainEntry D_80B8021C[]; + Matrix_Push(); + Matrix_SetTranslateRotateYXZ(this->dyna.actor.world.pos.x, this->dyna.actor.world.pos.y, + this->dyna.actor.world.pos.z, &this->dyna.actor.shape.rot); + for (i = 0; i < ARRAY_COUNT(this->lightRaysColliders); i++) { + dim = &sLightRaysCollidersInit[i].dim; + Matrix_MultVec3f(&dim->quad[0], &v0); + Matrix_MultVec3f(&dim->quad[1], &v1); + Matrix_MultVec3f(&dim->quad[2], &v2); + Matrix_MultVec3f(&dim->quad[3], &v3); + lightRaysCollider = &this->lightRaysColliders[i]; + Collider_SetQuadVertices(lightRaysCollider, &v0, &v1, &v2, &v3); + } -extern UNK_TYPE D_06001E18; -extern UNK_TYPE D_06002358; + Matrix_Pop(); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Ikana_Mirror/func_80B7F730.s") +void BgIkanaMirror_Init(Actor* thisx, PlayState* play2) { + PlayState* play = play2; + BgIkanaMirror* this = THIS; + ColliderTrisElementInit* element; + Vec3f vertices[3]; + s32 i; + s32 j; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Ikana_Mirror/BgIkanaMirror_Init.s") + Actor_ProcessInitChain(&this->dyna.actor, sInitChain); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(play, &this->dyna, &gStoneTowerTempleMirrorCol); + Collider_InitTris(play, &this->mirrorCollider); + Collider_SetTris(play, &this->mirrorCollider, &this->dyna.actor, &sMirrorColliderInit, + this->mirrorColliderElements); + Matrix_SetTranslateRotateYXZ(this->dyna.actor.world.pos.x, this->dyna.actor.world.pos.y, + this->dyna.actor.world.pos.z, &this->dyna.actor.shape.rot); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Ikana_Mirror/BgIkanaMirror_Destroy.s") + for (i = 0; i < ARRAY_COUNT(sMirrorColliderElementsInit); i++) { + element = &sMirrorColliderInit.elements[i]; + for (j = 0; j < 3; j++) { + Matrix_MultVec3f(&element->dim.vtx[j], &vertices[j]); + } + Collider_SetTrisVertices(&this->mirrorCollider, i, &vertices[0], &vertices[1], &vertices[2]); + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Ikana_Mirror/func_80B7FA84.s") + for (i = 0; i < ARRAY_COUNT(this->lightRaysColliders); i++) { + Collider_InitQuad(play, &this->lightRaysColliders[i]); + Collider_SetQuad(play, &this->lightRaysColliders[i], &this->dyna.actor, &sLightRaysCollidersInit[i]); + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Ikana_Mirror/func_80B7FA9C.s") + BgIkanaMirror_SetQuadVertices(this); + this->lightAbsorptionTexScroll = Lib_SegmentedToVirtual(&gStoneTowerTempleMirrorLightAbsorptionTexAnim); + this->lightEmissionTexScroll = Lib_SegmentedToVirtual(&gStoneTowerTempleMirrorLightEmissionTexAnim); + BgIkanaMirror_SetupWait(this); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Ikana_Mirror/func_80B7FB84.s") +void BgIkanaMirror_Destroy(Actor* thisx, PlayState* play) { + BgIkanaMirror* this = THIS; + s32 i; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Ikana_Mirror/func_80B7FBA4.s") + DynaPoly_DeleteBgActor(play, &play->colCtx.dyna, this->dyna.bgId); + Collider_DestroyTris(play, &this->mirrorCollider); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Ikana_Mirror/BgIkanaMirror_Update.s") + for (i = 0; i < ARRAY_COUNT(this->lightRaysColliders); i++) { + Collider_DestroyQuad(play, &this->lightRaysColliders[i]); + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Bg_Ikana_Mirror/BgIkanaMirror_Draw.s") +void BgIkanaMirror_SetupWait(BgIkanaMirror* this) { + this->isEmittingLight = 0; + this->actionFunc = BgIkanaMirror_Wait; +} + +/** + * Charges the mirror with light, increment the alpha value for the light absorption textures and decrement the alpha + * value for the light emission textures. + */ +void BgIkanaMirror_Wait(BgIkanaMirror* this, PlayState* play) { + s8 isEmittingLight; + s32 startEmittingLight = false; + + // The light emission texture gradually fades. + if (this->lightEmissionAlpha > 100) { + this->lightEmissionAlpha -= 100; + } else { + this->lightEmissionAlpha = 0; + } + + // This checks if light is touching the mirror. + if (this->mirrorCollider.base.acFlags & AC_HIT) { + this->mirrorCollider.base.acFlags &= ~AC_HIT; + this->isEmittingLight = 0; + + if (this->lightRayCharge < 400) { + this->lightRayCharge++; + } + + if (this->lightAbsorptionAlpha < 195) { + this->lightAbsorptionAlpha += 60; + } else { + this->lightAbsorptionAlpha = 255; + } + + } else { + isEmittingLight = this->isEmittingLight; + + if (isEmittingLight > 0) { + startEmittingLight = true; + } else if (this->lightRayCharge > 0) { + this->isEmittingLight = isEmittingLight + 1; + } + } + + if (startEmittingLight) { + BgIkanaMirror_SetupEmitLight(this); + } else { + CollisionCheck_SetAC(play, &play->colChkCtx, &this->mirrorCollider.base); + } +} + +void BgIkanaMirror_SetupEmitLight(BgIkanaMirror* this) { + this->dyna.actor.flags |= ACTOR_FLAG_20; + this->actionFunc = BgIkanaMirror_EmitLight; +} + +/** + * Depletes the mirror's light and release it, increase alpha value for the light + * emission textures and decrease the alpha value for the light absorption textures. + */ +void BgIkanaMirror_EmitLight(BgIkanaMirror* this, PlayState* play) { + s32 i; + + for (i = 0; i < ARRAY_COUNT(this->lightRaysColliders); i++) { + if (this->lightRaysColliders[i].base.atFlags & AT_HIT) { + this->lightRaysColliders[i].base.atFlags &= ~AT_HIT; + } + } + + if (this->lightEmissionAlpha < 155) { + this->lightEmissionAlpha += 100; + } else { + this->lightEmissionAlpha = 255; + } + + if (this->lightAbsorptionAlpha > 60) { + this->lightAbsorptionAlpha -= 60; + } else { + this->lightAbsorptionAlpha = 0; + } + + if (this->lightRayCharge > 0) { + this->lightRayCharge--; + + for (i = 0; i < ARRAY_COUNT(this->lightRaysColliders); i++) { + CollisionCheck_SetAT(play, &play->colChkCtx, &this->lightRaysColliders[i].base); + } + + } else { + this->dyna.actor.flags &= ~ACTOR_FLAG_20; + BgIkanaMirror_SetupWait(this); + } +} + +void BgIkanaMirror_Update(Actor* thisx, PlayState* play) { + BgIkanaMirror* this = THIS; + + this->actionFunc(this, play); +} + +void BgIkanaMirror_Draw(Actor* thisx, PlayState* play) { + s32 pad; + BgIkanaMirror* this = THIS; + + OPEN_DISPS(play->state.gfxCtx); + func_8012C28C(play->state.gfxCtx); + func_8012C2DC(play->state.gfxCtx); + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(POLY_OPA_DISP++, gStoneTowerTempleMirrorDL); + + if (this->lightAbsorptionAlpha > 0) { + AnimatedMat_Draw(play, this->lightAbsorptionTexScroll); + gDPSetPrimColor(POLY_XLU_DISP++, 0, 0x80, 255, 255, 255, this->lightAbsorptionAlpha); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(POLY_XLU_DISP++, gStoneTowerTempleMirrorLightAbsorptionDL); + } + + if (this->lightEmissionAlpha > 0) { + f32 alphaFraction = this->lightEmissionAlpha * (1.0f / 255.0f); + s32 primColorAlpha = (s32)(alphaFraction * 123.0f); + s32 envColorAlpha = (s32)(alphaFraction * 185.0f); + + AnimatedMat_Draw(play, this->lightEmissionTexScroll); + gDPSetPrimColor(POLY_XLU_DISP++, 0, 0x80, 255, 255, 255, primColorAlpha); + gDPSetEnvColor(POLY_XLU_DISP++, 215, 215, 255, envColorAlpha); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(POLY_XLU_DISP++, gStoneTowerTempleMirrorLightEmissionDL); + } + + CLOSE_DISPS(play->state.gfxCtx); +} diff --git a/src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.h b/src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.h index c9f8812084..5bd2724804 100644 --- a/src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.h +++ b/src/overlays/actors/ovl_Bg_Ikana_Mirror/z_bg_ikana_mirror.h @@ -8,12 +8,17 @@ struct BgIkanaMirror; typedef void (*BgIkanaMirrorActionFunc)(struct BgIkanaMirror*, PlayState*); typedef struct BgIkanaMirror { - /* 0x0000 */ Actor actor; - /* 0x0144 */ char unk_144[0x474]; - /* 0x05B8 */ BgIkanaMirrorActionFunc actionFunc; - /* 0x05BC */ char unk_5BC[0x10]; + /* 0x000 */ DynaPolyActor dyna; + /* 0x15C */ ColliderTris mirrorCollider; + /* 0x17C */ ColliderTrisElement mirrorColliderElements[9]; + /* 0x4B8 */ ColliderQuad lightRaysColliders[2]; + /* 0x5B8 */ BgIkanaMirrorActionFunc actionFunc; + /* 0x5BC */ AnimatedMaterial* lightAbsorptionTexScroll; + /* 0x5C0 */ AnimatedMaterial* lightEmissionTexScroll; + /* 0x5C4 */ s16 lightRayCharge; + /* 0x5C6 */ u8 lightAbsorptionAlpha; + /* 0x5C7 */ u8 lightEmissionAlpha; + /* 0x5C8 */ s8 isEmittingLight; } BgIkanaMirror; // size = 0x5CC -extern const ActorInit Bg_Ikana_Mirror_InitVars; - #endif // Z_BG_IKANA_MIRROR_H diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index f861588a5f..2ad13737b6 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -14574,13 +14574,13 @@ 0x80B7F398:("func_80B7F398",), 0x80B7F474:("BgIkanaBlock_Update",), 0x80B7F564:("func_80B7F564",), - 0x80B7F730:("func_80B7F730",), + 0x80B7F730:("BgIkanaMirror_SetQuadVertices",), 0x80B7F850:("BgIkanaMirror_Init",), 0x80B7FA00:("BgIkanaMirror_Destroy",), - 0x80B7FA84:("func_80B7FA84",), - 0x80B7FA9C:("func_80B7FA9C",), - 0x80B7FB84:("func_80B7FB84",), - 0x80B7FBA4:("func_80B7FBA4",), + 0x80B7FA84:("BgIkanaMirror_SetupWait",), + 0x80B7FA9C:("BgIkanaMirror_Wait",), + 0x80B7FB84:("BgIkanaMirror_SetupEmitLight",), + 0x80B7FBA4:("BgIkanaMirror_EmitLight",), 0x80B7FCB8:("BgIkanaMirror_Update",), 0x80B7FCDC:("BgIkanaMirror_Draw",), 0x80B802E0:("func_80B802E0",),