diff options
| author | Roman971 <32455037+Roman971@users.noreply.github.com> | 2020-05-18 20:24:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-18 14:24:00 -0400 |
| commit | e29b77919bd98375e31760ed082cf014c58dbef8 (patch) | |
| tree | e0e7c454be393eaba1b1bb52036191d41fa98af2 /src/code | |
| parent | 785011c33c2a95222dd88a57f43808bcdc1cff91 (diff) | |
Decompile most effect files in "code" (#144)
- `z_effect`: Matched and essentially all documented.
- `z_eff_spark.c`: Decompiled (1 non matching left) and mostly documented.
- `z_eff_shield_particle.c`: Matched and mostly documented.
- `z_eff_blure.c`: Decompiled (5 non matchings left) and partially documented.
- `z_effect_soft_sprite.c`: Matched and mostly documented.
- `z_eff_ss_dead.c`: Matched but not documented.
- `z_effect_soft_sprite_dlftbls.c`: "Matched" (only data, contains the effect ss overlay table).
- `z_effect_soft_sprite_old_init.c`: Not decompiled, but functions are categorized by effect ss overlay. And they should be decompiled at the same time as their corresponding effect ss in the future.
Other changes:
- Added a lot of types/enums to `z64effect.h`and moved+renamed some structs from `z64.h` to this header
- Added effect ss overlay segments to `segment_symbols.h` and effect ss init vars to `initvars.h`
- Added a macro called `VTX_T` to generate a `Vtx_t` in the same style as `VTX`
- Fixed `flg_set.c` .bss to be in the right file
- Removed `tools/overlayhelpers/batchdisasm` since it's no longer relevant
- Removed unused leftover asm from recent PRs
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/code_800FD970.c | 4 | ||||
| -rw-r--r-- | src/code/z_actor.c | 12 | ||||
| -rw-r--r-- | src/code/z_actor_dlftbls.c | 14 | ||||
| -rw-r--r-- | src/code/z_collision_check.c | 111 | ||||
| -rw-r--r-- | src/code/z_eff_blure.c | 1109 | ||||
| -rw-r--r-- | src/code/z_eff_shield_particle.c | 226 | ||||
| -rw-r--r-- | src/code/z_eff_spark.c | 286 | ||||
| -rw-r--r-- | src/code/z_eff_ss_dead.c | 138 | ||||
| -rw-r--r-- | src/code/z_effect.c | 264 | ||||
| -rw-r--r-- | src/code/z_effect_soft_sprite.c | 360 | ||||
| -rw-r--r-- | src/code/z_effect_soft_sprite_dlftbls.c | 55 | ||||
| -rw-r--r-- | src/code/z_effect_soft_sprite_old_init.c | 75 | ||||
| -rw-r--r-- | src/code/z_lights.c | 2 | ||||
| -rw-r--r-- | src/code/z_play.c | 12 |
14 files changed, 2475 insertions, 193 deletions
diff --git a/src/code/code_800FD970.c b/src/code/code_800FD970.c index b99281774..f5b61740c 100644 --- a/src/code/code_800FD970.c +++ b/src/code/code_800FD970.c @@ -22,8 +22,8 @@ void Math_Rand_Seed(u32 seed) { } /** - * Returns a pseudo-random floating-point number between 0.0f and 1.0f, by generating - * the next integer and masking it to an IEEE-754 compliant floating-point number + * Returns a pseudo-random floating-point number between 0.0f and 1.0f, by generating + * the next integer and masking it to an IEEE-754 compliant floating-point number * between 1.0f and 2.0f, returning the result subtract 1.0f. */ f32 Math_Rand_ZeroOne() { diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 97cd22c7c..5ac02fefc 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1795,7 +1795,7 @@ void func_8002FA60(GlobalContext* globalCtx) { Lights_InitType0PositionalLight(&D_8015BC00, lightPos.x, lightPos.y, lightPos.z, 0xFF, 0xFF, 0xFF, -1); - D_8015BC10 = Lights_Insert(globalCtx, &globalCtx->lightCtx, (LightInfo*)&D_8015BC00); + D_8015BC10 = Lights_Insert(globalCtx, &globalCtx->lightCtx, &D_8015BC00); D_8015BC14 = 0; D_8015BC18 = 0.0f; } @@ -2038,7 +2038,7 @@ void Actor_UpdateAll(GlobalContext* globalCtx, ActorContext* actorCtx) { if (0) { // This assert is optimized out but it exists due to its presence in rodata - if (gMaxProfile != ACTOR_DLF_MAX) { + if (gMaxActorId != ACTOR_ID_MAX) { __assert("MaxProfile == ACTOR_DLF_MAX", "../z_actor.c", UNK_LINE); } } @@ -2459,11 +2459,11 @@ void func_800315AC(GlobalContext* globalCtx, ActorContext* actorCtx) { } if ((HREG(64) != 1) || (HREG(73) != 0)) { - func_80026E74(globalCtx->state.gfxCtx); + Effect_DrawAll(globalCtx->state.gfxCtx); } if ((HREG(64) != 1) || (HREG(74) != 0)) { - func_80027BDC(globalCtx); + EffectSs_DrawAll(globalCtx); } if ((HREG(64) != 1) || (HREG(72) != 0)) { @@ -2683,7 +2683,7 @@ Actor* Actor_Spawn(ActorContext* actorCtx, GlobalContext* globalCtx, s16 actorId overlayEntry = &gActorOverlayTable[actorId]; - if (actorId >= ACTOR_DLF_MAX) { + if (actorId >= ACTOR_ID_MAX) { __assert("profile < ACTOR_DLF_MAX", "../z_actor.c", 6883); } @@ -3134,7 +3134,7 @@ void func_80032E24(struct_80032E24* arg0, s32 arg1, GlobalContext* globalCtx) { } void func_80032F54(struct_80032E24* arg0, s32 arg1, s32 arg2, s32 arg3, u32 arg4, s32* arg5, s16 arg6) { - GlobalContext* globalCtx = func_80026B00(); + GlobalContext* globalCtx = Effect_GetGlobalCtx(); if ((globalCtx->actorCtx.unk_00 == 0) && (arg0->unk_10 > 0)) { if ((arg1 >= arg2) && (arg3 >= arg1) && (*arg5 != 0)) { diff --git a/src/code/z_actor_dlftbls.c b/src/code/z_actor_dlftbls.c index 29a18cf99..42a153113 100644 --- a/src/code/z_actor_dlftbls.c +++ b/src/code/z_actor_dlftbls.c @@ -488,7 +488,7 @@ ActorOverlay gActorOverlayTable[] = { ACTOR_OVERLAY(Obj_Warp2block, ALLOCTYPE_NORMAL), }; -s32 gMaxProfile = 0; +s32 gMaxActorId = 0; static FaultClient sFaultClient; @@ -496,10 +496,10 @@ void ActorOverlayTable_LogPrint(void) { ActorOverlay* overlayEntry; u32 i; - osSyncPrintf("actor_dlftbls %u\n", gMaxProfile); + osSyncPrintf("actor_dlftbls %u\n", gMaxActorId); osSyncPrintf("RomStart RomEnd SegStart SegEnd allocp profile segname\n"); - for (i = 0, overlayEntry = &gActorOverlayTable[0]; i < gMaxProfile; i++, overlayEntry++) { + for (i = 0, overlayEntry = &gActorOverlayTable[0]; i < gMaxActorId; i++, overlayEntry++) { osSyncPrintf("%08x %08x %08x %08x %08x %08x %s\n", overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart, overlayEntry->vramEnd, overlayEntry->loadedRamAddr, &overlayEntry->initInfo->id, overlayEntry->name != NULL ? overlayEntry->name : "?"); @@ -513,10 +513,10 @@ void ActorOverlayTable_FaultPrint(void* arg0, void* arg1) { FaultDrawer_SetCharPad(-2, 0); - FaultDrawer_Printf("actor_dlftbls %u\n", gMaxProfile); + FaultDrawer_Printf("actor_dlftbls %u\n", gMaxActorId); FaultDrawer_Printf("No. RamStart- RamEnd cn Name\n"); - for (i = 0, overlayEntry = &gActorOverlayTable[0]; i < gMaxProfile; i++, overlayEntry++) { + for (i = 0, overlayEntry = &gActorOverlayTable[0]; i < gMaxActorId; i++, overlayEntry++) { overlaySize = (u32)overlayEntry->vramEnd - (u32)overlayEntry->vramStart; if (overlayEntry->loadedRamAddr != NULL) { FaultDrawer_Printf("%3d %08x-%08x %3d %s\n", i, overlayEntry->loadedRamAddr, @@ -527,11 +527,11 @@ void ActorOverlayTable_FaultPrint(void* arg0, void* arg1) { } void ActorOverlayTable_Init(void) { - gMaxProfile = ACTOR_DLF_MAX; + gMaxActorId = ACTOR_ID_MAX; Fault_AddClient(&sFaultClient, ActorOverlayTable_FaultPrint, NULL, NULL); } void ActorOverlayTable_Cleanup(void) { Fault_RemoveClient(&sFaultClient); - gMaxProfile = 0; + gMaxActorId = 0; } diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index a8bd723a4..9a49c3f28 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -1232,17 +1232,17 @@ void func_8005DF9C(GlobalContext* globalCtx, Collider* collider, Vec3f* v) { } #ifdef NON_MATCHING -// Blue EffSpark -//.bss problems +// Blue EffectSpark +// .bss problems void func_8005DFAC(GlobalContext* globalCtx, Collider* collider, Vec3f* v) { + static EffectSparkInit D_8015D8A0; s32 sp24; - static EffSparkParams D_8015D8A0; D_8015D8A0.position.x = (s32)v->x; D_8015D8A0.position.y = (s32)v->y; D_8015D8A0.position.z = (s32)v->z; - D_8015D8A0.particleFactor1 = 5; - D_8015D8A0.particleFactor2 = 5; + D_8015D8A0.uDiv = 5; + D_8015D8A0.vDiv = 5; D_8015D8A0.colorStart[0].r = 0x0A; D_8015D8A0.colorStart[0].g = 0x0A; D_8015D8A0.colorStart[0].b = 0xC8; @@ -1275,11 +1275,12 @@ void func_8005DFAC(GlobalContext* globalCtx, Collider* collider, Vec3f* v) { D_8015D8A0.colorEnd[3].g = 0x00; D_8015D8A0.colorEnd[3].b = 0x40; D_8015D8A0.colorEnd[3].a = 0x00; - D_8015D8A0.age = 0; + D_8015D8A0.timer = 0; D_8015D8A0.duration = 16; - D_8015D8A0.velocity = 8.0f; + D_8015D8A0.speed = 8.0f; D_8015D8A0.gravity = -1.0f; - Effect_Add(globalCtx, &sp24, 0, 0, 1, &D_8015D8A0); + + Effect_Add(globalCtx, &sp24, EFFECT_SPARK, 0, 1, &D_8015D8A0); } #else void func_8005DFAC(GlobalContext* globalCtx, Collider* collider, Vec3f* v); @@ -1287,17 +1288,17 @@ void func_8005DFAC(GlobalContext* globalCtx, Collider* collider, Vec3f* v); #endif // NON_MATCHING #ifdef NON_MATCHING -// Green EffSpark -//.bss problems +// Green EffectSpark +// .bss problems void func_8005E10C(GlobalContext* globalCtx, Collider* collider, Vec3f* v) { + static EffectSparkInit D_8015DD68; s32 sp24; - static EffSparkParams D_8015DD68; - // D_8015DD68 + D_8015DD68.position.x = (s32)v->x; D_8015DD68.position.y = (s32)v->y; D_8015DD68.position.z = (s32)v->z; - D_8015DD68.particleFactor1 = 5; - D_8015DD68.particleFactor2 = 5; + D_8015DD68.uDiv = 5; + D_8015DD68.vDiv = 5; D_8015DD68.colorStart[0].r = 0x0A; D_8015DD68.colorStart[0].g = 0xC8; D_8015DD68.colorStart[0].b = 0x0A; @@ -1330,11 +1331,12 @@ void func_8005E10C(GlobalContext* globalCtx, Collider* collider, Vec3f* v) { D_8015DD68.colorEnd[3].g = 0x40; D_8015DD68.colorEnd[3].b = 0x00; D_8015DD68.colorEnd[3].a = 0x00; - D_8015DD68.age = 0; + D_8015DD68.timer = 0; D_8015DD68.duration = 16; - D_8015DD68.velocity = 8.0f; + D_8015DD68.speed = 8.0f; D_8015DD68.gravity = -1.0f; - Effect_Add(globalCtx, &sp24, 0, 0, 1, &D_8015DD68); + + Effect_Add(globalCtx, &sp24, EFFECT_SPARK, 0, 1, &D_8015DD68); } #else void func_8005E10C(GlobalContext* globalCtx, Collider* collider, Vec3f* v); @@ -2936,17 +2938,17 @@ void func_800628A4(s32 arg0, ColliderJntSph* collider) { #endif // NON_MATCHING #ifdef NON_MATCHING -// Purple EffSpark -//.bss section problems +// Purple EffectSpark +// .bss section problems void func_80062A28(GlobalContext* globalCtx, Vec3f* v) { + static EffectSparkInit D_8015CF10; s32 sp24; - static EffSparkParams D_8015CF10; D_8015CF10.position.x = (s32)v->x; D_8015CF10.position.y = (s32)v->y; D_8015CF10.position.z = (s32)v->z; - D_8015CF10.particleFactor1 = 5; - D_8015CF10.particleFactor2 = 5; + D_8015CF10.uDiv = 5; + D_8015CF10.vDiv = 5; D_8015CF10.colorStart[0].r = 0x80; D_8015CF10.colorStart[0].g = 0x00; D_8015CF10.colorStart[0].b = 0x40; @@ -2979,28 +2981,29 @@ void func_80062A28(GlobalContext* globalCtx, Vec3f* v) { D_8015CF10.colorEnd[3].g = 0x00; D_8015CF10.colorEnd[3].b = 0x40; D_8015CF10.colorEnd[3].a = 0x00; - D_8015CF10.age = 0; + D_8015CF10.timer = 0; D_8015CF10.duration = 16; - D_8015CF10.velocity = 8.0f; + D_8015CF10.speed = 8.0f; D_8015CF10.gravity = -1.0f; - Effect_Add(globalCtx, &sp24, 0, 0, 1, &D_8015CF10); + + Effect_Add(globalCtx, &sp24, EFFECT_SPARK, 0, 1, &D_8015CF10); } #else #pragma GLOBAL_ASM("asm/non_matchings/code/z_collision_check/func_80062A28.s") #endif // NON_MATCHING #ifdef NON_MATCHING -// White EffSpark (Bubbles?) -//.bss section problems +// White EffectSpark (Bubbles?) +// .bss section problems void func_80062B80(GlobalContext* globalCtx, Vec3f* v) { + static EffectSparkInit D_8015D3D8; s32 sp24; - static EffSparkParams D_8015D3D8; D_8015D3D8.position.x = (s32)v->x; D_8015D3D8.position.y = (s32)v->y; D_8015D3D8.position.z = (s32)v->z; - D_8015D3D8.particleFactor1 = 5; - D_8015D3D8.particleFactor2 = 5; + D_8015D3D8.uDiv = 5; + D_8015D3D8.vDiv = 5; D_8015D3D8.colorStart[0].r = 0xFF; D_8015D3D8.colorStart[0].g = 0xFF; D_8015D3D8.colorStart[0].b = 0xFF; @@ -3033,27 +3036,27 @@ void func_80062B80(GlobalContext* globalCtx, Vec3f* v) { D_8015D3D8.colorEnd[3].g = 0x00; D_8015D3D8.colorEnd[3].b = 0x00; D_8015D3D8.colorEnd[3].a = 0x00; - D_8015D3D8.age = 0; + D_8015D3D8.timer = 0; D_8015D3D8.duration = 16; - D_8015D3D8.velocity = 8.0f; + D_8015D3D8.speed = 8.0f; D_8015D3D8.gravity = -1.0f; - Effect_Add(globalCtx, &sp24, 0, 0, 1, &D_8015D3D8); + + Effect_Add(globalCtx, &sp24, EFFECT_SPARK, 0, 1, &D_8015D3D8); } #else #pragma GLOBAL_ASM("asm/non_matchings/code/z_collision_check/func_80062B80.s") #endif // NON_MATCHING void func_80062CD4(GlobalContext* globalCtx, Vec3f* v) { - s32 sp24; - static EffShieldParticleInit init = { + static EffectShieldParticleInit init = { 16, - { 0, 0, 0 }, - { { 0x00, 0xC8, 0xFF, 0xFF } }, - { { 0xFF, 0xFF, 0xFF, 0xFF } }, - { { 0xFF, 0xFF, 0x80, 0xFF } }, - { { 0xFF, 0xFF, 0x00, 0xFF } }, - { { 0xFF, 0x40, 0x00, 0xC8 } }, - { { 0xFF, 0x00, 0x00, 0xFF } }, + { 0.0f, 0.0f, 0.0f }, + { 0x00, 0xC8, 0xFF, 0xFF }, + { 0xFF, 0xFF, 0xFF, 0xFF }, + { 0xFF, 0xFF, 0x80, 0xFF }, + { 0xFF, 0xFF, 0x00, 0xFF }, + { 0xFF, 0x40, 0x00, 0xC8 }, + { 0xFF, 0x00, 0x00, 0xFF }, 2.1f, 35.0f, 30.0f, @@ -3061,6 +3064,7 @@ void func_80062CD4(GlobalContext* globalCtx, Vec3f* v) { { 0, 0, 0, 0x00, 0x80, 0xFF, 0x00, 300 }, 1, }; + s32 sp24; init.position.x = (s32)v->x; init.position.y = (s32)v->y; @@ -3068,7 +3072,8 @@ void func_80062CD4(GlobalContext* globalCtx, Vec3f* v) { init.lightParams.posX = init.position.x; init.lightParams.posY = init.position.y; init.lightParams.posZ = init.position.z; - Effect_Add(globalCtx, &sp24, 3, 0, 1, &init); + + Effect_Add(globalCtx, &sp24, EFFECT_SHIELD_PARTICLE, 0, 1, &init); } void func_80062D60(GlobalContext* globalCtx, Vec3f* v) { @@ -3086,16 +3091,15 @@ void func_80062DF4(GlobalContext* globalCtx, Vec3f* v) { } void func_80062E14(GlobalContext* globalCtx, Vec3f* v, Vec3f* arg2) { - s32 sp24; - static EffShieldParticleInit init = { + static EffectShieldParticleInit init = { 16, - { 0, 0, 0 }, - { { 0x00, 0xC8, 0xFF, 0xFF } }, - { { 0xFF, 0xFF, 0xFF, 0xFF } }, - { { 0xFF, 0xFF, 0x80, 0xFF } }, - { { 0xFF, 0xFF, 0x00, 0xFF } }, - { { 0xFF, 0x40, 0x00, 0xC8 } }, - { { 0xFF, 0x00, 0x00, 0xFF } }, + { 0.0f, 0.0f, 0.0f }, + { 0x00, 0xC8, 0xFF, 0xFF }, + { 0xFF, 0xFF, 0xFF, 0xFF }, + { 0xFF, 0xFF, 0x80, 0xFF }, + { 0xFF, 0xFF, 0x00, 0xFF }, + { 0xFF, 0x40, 0x00, 0xC8 }, + { 0xFF, 0x00, 0x00, 0xFF }, 2.1f, 35.0f, 30.0f, @@ -3103,6 +3107,7 @@ void func_80062E14(GlobalContext* globalCtx, Vec3f* v, Vec3f* arg2) { { 0, 0, 0, 0x00, 0x80, 0xFF, 0x00, 300 }, 0, }; + s32 sp24; init.position.x = (s32)v->x; init.position.y = (s32)v->y; @@ -3111,7 +3116,7 @@ void func_80062E14(GlobalContext* globalCtx, Vec3f* v, Vec3f* arg2) { init.lightParams.posY = init.position.y; init.lightParams.posZ = init.position.z; - Effect_Add(globalCtx, &sp24, 3, 0, 1, &init); + Effect_Add(globalCtx, &sp24, EFFECT_SHIELD_PARTICLE, 0, 1, &init); Audio_PlaySoundGeneral(NA_SE_IT_REFLECTION_WOOD, arg2, 4, &D_801333E0, &D_801333E0, &D_801333E8); } diff --git a/src/code/z_eff_blure.c b/src/code/z_eff_blure.c index 21f2bc75a..8ec1d6da3 100644 --- a/src/code/z_eff_blure.c +++ b/src/code/z_eff_blure.c @@ -1,30 +1,1115 @@ #include <ultra64.h> #include <global.h> -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/func_8001FDF0.s") +void EffectBlure_AddVertex(EffectBlure* this, Vec3f* p1, Vec3f* p2) { + EffectBlureElement* elem; + s32 numElements; + Vec3f sp16C; + Vec3f sp160; + Vec3f sp154; + f32 scale; + MtxF sp110; + MtxF spD0; + MtxF sp90; + MtxF sp50; + Vec3f sp44; + Vec3f sp38; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/func_80020184.s") + if (this != NULL) { + numElements = this->numElements; + if (numElements >= 16) { + // Translates to: "Blure vertex addition processing: Table over %d" + osSyncPrintf("ブラ─頂点追加処理:テーブルオーバー %d\n", numElements); + return; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/func_800208E0.s") + elem = &this->elements[numElements]; + elem->state = 1; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/func_80020A50.s") + if (!(this->flags & 2)) { + elem->p1.x = p1->x; + elem->p1.y = p1->y; + elem->p1.z = p1->z; + elem->p2.x = p2->x; + elem->p2.y = p2->y; + elem->p2.z = p2->z; + } else { + sp16C.x = ((f32)(elem - 1)->p2.x + (f32)(elem - 1)->p1.x) * 0.5f; + sp16C.y = ((f32)(elem - 1)->p2.y + (f32)(elem - 1)->p1.y) * 0.5f; + sp16C.z = ((f32)(elem - 1)->p2.z + (f32)(elem - 1)->p1.z) * 0.5f; + sp160.x = (p1->x + p2->x) * 0.5f; + sp160.y = (p1->y + p2->y) * 0.5f; + sp160.z = (p1->z + p2->z) * 0.5f; -void func_80020F60(u32 unused, GraphicsContext* gfxCtx) { + Math_Vec3f_Diff(&sp160, &sp16C, &sp154); + scale = Math3D_Vec3fMagnitude(&sp154); + if (!(fabsf(scale) < 0.008f)) { + scale = 1.0f / scale; + Math_Vec3f_Scale(&sp154, scale); + + func_800A7A24(&sp110, sp160.x, sp160.y, sp160.z); + func_800A7EC0(&spD0, this->addAngle, sp154.x, sp154.y, sp154.z); + func_800A6FA0(&sp110, &spD0, &sp90); + func_800A7A24(&sp110, -sp160.x, -sp160.y, -sp160.z); + func_800A6FA0(&sp90, &sp110, &sp50); + func_800A6EF4(&sp50, p1, &sp38); + func_800A6EF4(&sp50, p2, &sp44); + + elem->p1.x = sp38.x; + elem->p1.y = sp38.y; + elem->p1.z = sp38.z; + elem->p2.x = sp44.x; + elem->p2.y = sp44.y; + elem->p2.z = sp44.z; + } + } + + elem->timer = 1; + this->numElements++; + } +} + +void EffectBlure_AddSpace(EffectBlure* this) { + EffectBlureElement* elem; + s32 numElements; + + if (this != NULL) { + numElements = this->numElements; + if (numElements >= 16) { + // Translates to: "Blure space addition processing: Table over %d" + osSyncPrintf("ブラ─空白追加処理:テーブルオーバー %d\n", numElements); + return; + } + + elem = &this->elements[numElements]; + elem->state = 0; + elem->timer = 1; + + this->numElements++; + } +} + +void EffectBlure_InitElements(EffectBlure* this) { + EffectBlureElement* elem; + s32 i; + + this->numElements = 0; + + for (i = 0; i < 16; i++) { + elem = &this->elements[i]; + + elem->state = 2; + elem->p1.x = 0; + elem->p1.y = 0; + elem->p1.z = 0; + elem->p2.x = 0; + elem->p2.y = 0; + elem->p2.z = 0; + elem->timer = 0; + elem->flags = 0; + } +} + +void EffectBlure_Init1(void* thisx, void* initParamsx) { + EffectBlure* this = (EffectBlure*)thisx; + EffectBlureInit1* initParams = (EffectBlureInit1*)initParamsx; + + if ((this != NULL) && (initParams != NULL)) { + EffectBlure_InitElements(this); + this->p1StartColor.r = initParams->p1StartColor.r; + this->p2StartColor.r = initParams->p2StartColor.r; + this->p1EndColor.r = initParams->p1EndColor.r; + this->p2EndColor.r = initParams->p2EndColor.r; + this->p1StartColor.g = initParams->p1StartColor.g; + this->p2StartColor.g = initParams->p2StartColor.g; + this->p1EndColor.g = initParams->p1EndColor.g; + this->p2EndColor.g = initParams->p2EndColor.g; + this->p1StartColor.b = initParams->p1StartColor.b; + this->p2StartColor.b = initParams->p2StartColor.b; + this->p1EndColor.b = initParams->p1EndColor.b; + this->p2EndColor.b = initParams->p2EndColor.b; + this->p1StartColor.a = initParams->p1StartColor.a; + this->p2StartColor.a = initParams->p2StartColor.a; + this->p1EndColor.a = initParams->p1EndColor.a; + this->p2EndColor.a = initParams->p2EndColor.a; + this->elemDuration = initParams->elemDuration; + this->unkFlag = initParams->unkFlag; + this->calcMode = initParams->calcMode; + this->flags = 0; + this->addAngleChange = 0; + this->addAngle = 0; + this->drawMode = 0; + this->altPrimColor.r = 0x00; + this->altPrimColor.g = 0x00; + this->altPrimColor.b = 0x00; + this->altPrimColor.a = 0x00; + this->altEnvColor.r = 0x00; + this->altEnvColor.g = 0x00; + this->altEnvColor.b = 0x00; + this->altEnvColor.a = 0x00; + this->mode4Param = 1.0f; + } +} + +void EffectBlure_Init2(void* thisx, void* initParamsx) { + EffectBlure* this = (EffectBlure*)thisx; + EffectBlureInit2* initParams = (EffectBlureInit2*)initParamsx; + + if ((this != NULL) && (initParams != NULL)) { + EffectBlure_InitElements(this); + this->p1StartColor.r = initParams->p1StartColor.r; + this->p2StartColor.r = initParams->p2StartColor.r; + this->p1EndColor.r = initParams->p1EndColor.r; + this->p2EndColor.r = initParams->p2EndColor.r; + this->p1StartColor.g = initParams->p1StartColor.g; + this->p2StartColor.g = initParams->p2StartColor.g; + this->p1EndColor.g = initParams->p1EndColor.g; + this->p2EndColor.g = initParams->p2EndColor.g; + this->p1StartColor.b = initParams->p1StartColor.b; + this->p2StartColor.b = initParams->p2StartColor.b; + this->p1EndColor.b = initParams->p1EndColor.b; + this->p2EndColor.b = initParams->p2EndColor.b; + this->p1StartColor.a = initParams->p1StartColor.a; + this->p2StartColor.a = initParams->p2StartColor.a; + this->p1EndColor.a = initParams->p1EndColor.a; + this->p2EndColor.a = initParams->p2EndColor.a; + this->elemDuration = initParams->elemDuration; + this->unkFlag = initParams->unkFlag; + this->calcMode = initParams->calcMode; + this->flags = initParams->flags; + this->drawMode = initParams->drawMode; + this->addAngleChange = initParams->addAngleChange; + this->addAngle = 0; + this->mode4Param = initParams->mode4Param; + this->altPrimColor = initParams->altPrimColor; + this->altEnvColor = initParams->altEnvColor; + } +} + +void EffectBlure_Destroy(void* thisx) { +} + +#ifdef NON_MATCHING +// single register swap (saved vs temp register) +s32 EffectBlure_Update(void* thisx) { + EffectBlure* this = (EffectBlure*)thisx; + s32 i; + + if (this == NULL) { + return 0; + } + + if (this->numElements == 0) { + return 0; + } + + while (true) { + if (this->elements[0].state != 0) { + break; + } + + for (i = 0; i < 15; i++) { + this->elements[i] = this->elements[i + 1]; + } + + this->elements[i].state = 2; + this->elements[i].p1.x = 0; + this->elements[i].p1.y = 0; + this->elements[i].p1.z = 0; + this->elements[i].p2.x = 0; + this->elements[i].p2.y = 0; + this->elements[i].p2.z = 0; + this->elements[i].flags = 0; + this->elements[i].timer = 0; + + this->numElements--; + if (this->numElements <= 0) { + this->numElements = 0; + return 0; + } + } + + if (this->elements[0].state == 2) { + return 0; + } + + for (i = 0; i < this->numElements; i++) { + this->elements[i].timer++; + } + + if (this->elemDuration < this->elements[0].timer) { + for (i = 0; i < 15; i++) { + this->elements[i] = this->elements[i + 1]; + } + + this->elements[i].state = 2; + this->elements[i].p1.x = 0; + this->elements[i].p1.y = 0; + this->elements[i].p1.z = 0; + this->elements[i].p2.x = 0; + this->elements[i].p2.y = 0; + this->elements[i].p2.z = 0; + this->elements[i].flags = 0; + this->elements[i].timer = 0; + + this->numElements--; + if (this->numElements <= 0) { + this->numElements = 0; + return 0; + } + return 0; + } + + this->addAngle += this->addAngleChange; + return 0; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/EffectBlure_Update.s") +#endif + +void EffectBlure_UpdateFlags(EffectBlureElement* elem) { + Vec3f sp64; + Vec3f sp58; + Vec3f sp4C; + Vec3f sp40; + + if (((elem - 1)->state == 0) || ((elem + 1)->state == 0)) { + elem->flags &= ~3; + elem->flags |= 2; + } else { + EffectBlureElement* prev = elem - 1; + EffectBlureElement* next = elem + 1; + f32 sp34; + f32 sp30; + f32 sp2C; + + if (1) {} // Necessary to match + + Math_Vec3s_DiffToVec3f(&sp64, &elem->p1, &prev->p1); + Math_Vec3s_DiffToVec3f(&sp58, &elem->p2, &prev->p2); + Math_Vec3s_DiffToVec3f(&sp4C, &next->p1, &elem->p1); + Math_Vec3s_DiffToVec3f(&sp40, &next->p2, &elem->p2); + + if (func_800CB010(&sp64, &sp4C, &sp34) || func_800CB010(&sp58, &sp40, &sp30) || + func_800CB010(&sp4C, &sp40, &sp2C)) { + elem->flags &= ~3; + elem->flags |= 0; + } else if ((sp34 <= -0.5f) || (sp30 <= -0.5f) || (sp2C <= 0.7071f)) { + elem->flags &= ~3; + elem->flags |= 0; + } else { + elem->flags &= ~3; + elem->flags |= 1; + } + } +} + +#ifdef NON_MATCHING +// regalloc and saved register usage differences +void EffectBlure_GetComputedValues(EffectBlure* this, s32 index, f32 ratio, Vec3s* vec1, Vec3s* vec2, + Color_RGBA8* color1, Color_RGBA8* color2) { + Vec3s sp30; + EffectBlureElement* elem; + f32 mode4Param; + + elem = &this->elements[index]; + + switch (this->calcMode) { + case 1: + vec1->x = func_80027E34(elem->p1.x, elem->p2.x, ratio); + vec1->y = func_80027E34(elem->p1.y, elem->p2.y, ratio); + vec1->z = func_80027E34(elem->p1.z, elem->p2.z, ratio); + vec2->x = elem->p2.x; + vec2->y = elem->p2.y; + vec2->z = elem->p2.z; + break; + + case 2: + vec1->x = elem->p1.x; + vec1->y = elem->p1.y; + vec1->z = elem->p1.z; + vec2->x = func_80027E34(elem->p2.x, elem->p1.x, ratio); + vec2->y = func_80027E34(elem->p2.y, elem->p1.y, ratio); + vec2->z = func_80027E34(elem->p2.z, elem->p1.z, ratio); + break; + + case 3: + ratio = ratio * 0.5f; + vec1->x = func_80027E34(elem->p1.x, elem->p2.x, ratio); + vec1->y = func_80027E34(elem->p1.y, elem->p2.y, ratio); + vec1->z = func_80027E34(elem->p1.z, elem->p2.z, ratio); + vec2->x = func_80027E34(elem->p2.x, elem->p1.x, ratio); + vec2->y = func_80027E34(elem->p2.y, elem->p1.y, ratio); + vec2->z = func_80027E34(elem->p2.z, elem->p1.z, ratio); + ratio = ratio + ratio; + break; + + case 4: + sp30.x = elem->p1.x - elem->p2.x; + sp30.y = elem->p1.y - elem->p2.y; + sp30.z = elem->p1.z - elem->p2.z; + mode4Param = this->mode4Param; + + vec1->x = (sp30.x * 0.5f * (mode4Param - 1.0f) * ratio) + elem->p1.x; + vec1->y = (sp30.y * 0.5f * (mode4Param - 1.0f) * ratio) + elem->p1.y; + vec1->z = (sp30.z * 0.5f * (mode4Param - 1.0f) * ratio) + elem->p1.z; + vec2->x = -(sp30.x * 0.5f * (mode4Param - 1.0f) * ratio) + elem->p2.x; + vec2->y = -(sp30.y * 0.5f * (mode4Param - 1.0f) * ratio) + elem->p2.y; + vec2->z = -(sp30.z * 0.5f * (mode4Param - 1.0f) * ratio) + elem->p2.z; + break; + + case 0: + default: + vec1->x = elem->p1.x; + vec1->y = elem->p1.y; + vec1->z = elem->p1.z; + vec2->x = elem->p2.x; + vec2->y = elem->p2.y; + vec2->z = elem->p2.z; + break; + } + + sp30 = sp30; // Optimized out but seems necessary to match stack usage + + if (this->flags & 0x10) { + color1->a = 0xFF; + color1->b = 0xFF; + color1->g = 0xFF; + color1->r = 0xFF; + color2->r = 0xFF; + color2->g = 0xFF; + color2->b = 0xFF; + color2->a = 0xFF; + } else { + color1->r = func_80027E84(this->p1StartColor.r, this->p1EndColor.r, ratio); + color1->g = func_80027E84(this->p1StartColor.g, this->p1EndColor.g, ratio); + color1->b = func_80027E84(this->p1StartColor.b, this->p1EndColor.b, ratio); + color1->a = func_80027E84(this->p1StartColor.a, this->p1EndColor.a, ratio); + color2->r = func_80027E84(this->p2StartColor.r, this->p2EndColor.r, ratio); + color2->g = func_80027E84(this->p2StartColor.g, this->p2EndColor.g, ratio); + color2->b = func_80027E84(this->p2StartColor.b, this->p2EndColor.b, ratio); + color2->a = func_80027E84(this->p2StartColor.a, this->p2EndColor.a, ratio); + } +} +#else +void EffectBlure_GetComputedValues(EffectBlure* this, s32 index, f32 ratio, Vec3s* vec1, Vec3s* vec2, + Color_RGBA8* color1, Color_RGBA8* color2); +#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/EffectBlure_GetComputedValues.s") +#endif + +void EffectBlure_SetupSmooth(EffectBlure* this, GraphicsContext* gfxCtx) { + Gfx* dispRefs[5]; + + Graph_OpenDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 809); + + gfxCtx->polyXlu.p = Gfx_CallSetupDL(gfxCtx->polyXlu.p, 0x26); + + Graph_CloseDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 813); +} + +// original name: "SQ_NoInterpolate_disp" +void EffectBlure_DrawElemNoInterpolation(EffectBlure* this, EffectBlureElement* elem, s32 index, + GraphicsContext* gfxCtx) { + static Vtx_t baseVtx = VTX_T(0, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF); + Vtx_t* vtx; + Vec3s sp8C; + Vec3s sp84; + f32 ratio; + Color_RGBA8 sp7C; + Color_RGBA8 sp78; + Vec3f sp6C; + Vec3f sp60; + Vec3f sp54; + Gfx* dispRefs[5]; + + Graph_OpenDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 838); + + Math_Vec3s_ToVec3f(&sp6C, &this->elements[0].p2); + + vtx = Graph_Alloc(gfxCtx, sizeof(Vtx_t[4])); + if (vtx == NULL) { + // Translates to: "Vertices cannot be secured." + osSyncPrintf("z_eff_blure.c::SQ_NoInterpolate_disp() 頂点確保できず。\n"); + } else { + vtx[0] = baseVtx; + vtx[1] = baseVtx; + vtx[2] = baseVtx; + vtx[3] = baseVtx; + + ratio = (f32)elem->timer / (f32)this->elemDuration; + EffectBlure_GetComputedValues(this, index, ratio, &sp8C, &sp84, &sp7C, &sp78); + + sp60.x = sp84.x; + sp60.y = sp84.y; + sp60.z = sp84.z; + Math_Vec3f_Diff(&sp60, &sp6C, &sp54); + Math_Vec3f_Scale(&sp54, 10.0f); + vtx[0].ob[0] = sp54.x; + vtx[0].ob[1] = sp54.y; + vtx[0].ob[2] = sp54.z; + vtx[0].cn[0] = sp78.r; + vtx[0].cn[1] = sp78.g; + vtx[0].cn[2] = sp78.b; + vtx[0].cn[3] = sp78.a; + + if (1) {} // Necessary to match + + sp60.x = sp8C.x; + sp60.y = sp8C.y; + sp60.z = sp8C.z; + Math_Vec3f_Diff(&sp60, &sp6C, &sp54); + Math_Vec3f_Scale(&sp54, 10.0f); + vtx[1].ob[0] = sp54.x; + vtx[1].ob[1] = sp54.y; + vtx[1].ob[2] = sp54.z; + vtx[1].cn[0] = sp7C.r; + vtx[1].cn[1] = sp7C.g; + vtx[1].cn[2] = sp7C.b; + vtx[1].cn[3] = sp7C.a; + + ratio = (f32)(elem + 1)->timer / (f32)this->elemDuration; + EffectBlure_GetComputedValues(this, index + 1, ratio, &sp8C, &sp84, &sp7C, &sp78); + + sp60.x = sp8C.x; + sp60.y = sp8C.y; + sp60.z = sp8C.z; + Math_Vec3f_Diff(&sp60, &sp6C, &sp54); + Math_Vec3f_Scale(&sp54, 10.0f); + vtx[2].ob[0] = sp54.x; + vtx[2].ob[1] = sp54.y; + vtx[2].ob[2] = sp54.z; + vtx[2].cn[0] = sp7C.r; + vtx[2].cn[1] = sp7C.g; + vtx[2].cn[2] = sp7C.b; + vtx[2].cn[3] = sp7C.a; + + if (1) {} // Necessary to match + + sp60.x = sp84.x; + sp60.y = sp84.y; + sp60.z = sp84.z; + Math_Vec3f_Diff(&sp60, &sp6C, &sp54); + Math_Vec3f_Scale(&sp54, 10.0f); + vtx[3].ob[0] = sp54.x; + vtx[3].ob[1] = sp54.y; + vtx[3].ob[2] = sp54.z; + vtx[3].cn[0] = sp78.r; + vtx[3].cn[1] = sp78.g; + vtx[3].cn[2] = sp78.b; + vtx[3].cn[3] = sp78.a; + + gSPVertex(gfxCtx->polyXlu.p++, vtx, 4, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 0, 1, 2, 0, 0, 2, 3, 0); + } + + Graph_CloseDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 932); +} + +// original name: "SQ_HermiteInterpolate_disp" +#ifdef NON_MATCHING +void EffectBlure_DrawElemHermiteInterpolation(EffectBlure* this, EffectBlureElement* elem, s32 index, + GraphicsContext* gfxCtx) { + static Vtx_t baseVtx = VTX_T(0, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF); + Vtx_t* vtx; + Vec3s sp1EC; + Vec3s sp1E4; + f32 ratio; + Color_RGBA8 sp1DC; + Color_RGBA8 sp1D8; + Vec3f sp1CC; + Vec3f sp1C0; + Vec3f sp1B4; + Vec3f sp1A8; + Color_RGBA8 sp1A4; + Color_RGBA8 sp1A0; + Color_RGBA8 sp19C; + Color_RGBA8 sp198; + Vec3f sp18C; + Vec3f sp180; + Vec3f sp174; + Vec3f sp168; + Vec3f sp158; + Vec3f sp14C; + Color_RGBA8 sp148; + Color_RGBA8 sp144; + Vec3f sp138; + Gfx* dispRefs[5]; + Vec3f sp118; + Vec3f sp10C; + Vec3f sp100; + Vec3f spF4; + s32 j1; + s32 j2; + Vec3f spE0; + s32 i; + + Graph_OpenDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 971); + + Math_Vec3s_ToVec3f(&sp138, &this->elements[0].p2); + + ratio = (f32)elem->timer / (f32)this->elemDuration; + EffectBlure_GetComputedValues(this, index, ratio, &sp1EC, &sp1E4, &sp1A4, &sp1A0); + Math_Vec3s_ToVec3f(&sp1CC, &sp1EC); + Math_Vec3s_ToVec3f(&sp1C0, &sp1E4); + + ratio = (f32)(elem + 1)->timer / (f32)this->elemDuration; + EffectBlure_GetComputedValues(this, index + 1, ratio, &sp1EC, &sp1E4, &sp19C, &sp198); + Math_Vec3s_ToVec3f(&sp18C, &sp1EC); + Math_Vec3s_ToVec3f(&sp180, &sp1E4); + + if ((elem->flags & 3) == 2) { + Math_Vec3f_Diff(&sp18C, &sp1CC, &sp1B4); + Math_Vec3f_Diff(&sp180, &sp1C0, &sp1A8); + } else { + if (index - 1 < 0) { + __assert("index - 1 >= 0", "../z_eff_blure.c", 1005); + } + + ratio = (f32)(elem - 1)->timer / (f32)this->elemDuration; + EffectBlure_GetComputedValues(this, index - 1, ratio, &sp1EC, &sp1E4, &sp1DC, &sp1D8); + Math_Vec3s_ToVec3f(&sp118, &sp1EC); + Math_Vec3s_ToVec3f(&sp10C, &sp1E4); + Math_Vec3f_Diff(&sp18C, &sp118, &sp1B4); + Math_Vec3f_Diff(&sp180, &sp10C, &sp1A8); + } + + Math_Vec3f_Scale(&sp1B4, 0.5f); + Math_Vec3f_Scale(&sp1A8, 0.5f); + + if (((elem + 1)->flags & 3) == 2) { + Math_Vec3f_Diff(&sp18C, &sp1CC, &sp174); + Math_Vec3f_Diff(&sp180, &sp1C0, &sp168); + } else { + if (index + 2 >= this->numElements) { + __assert("index + 2 < this2->now_edge_num", "../z_eff_blure.c", 1032); + } + + ratio = (f32)(elem + 2)->timer / (f32)this->elemDuration; + EffectBlure_GetComputedValues(this, index + 2, ratio, &sp1EC, &sp1E4, &sp1DC, &sp1D8); + Math_Vec3s_ToVec3f(&sp100, &sp1EC); + Math_Vec3s_ToVec3f(&spF4, &sp1E4); + Math_Vec3f_Diff(&sp100, &sp1CC, &sp174); + Math_Vec3f_Diff(&spF4, &sp1C0, &sp168); + } + + Math_Vec3f_Scale(&sp174, 0.5f); + Math_Vec3f_Scale(&sp168, 0.5f); + + vtx = Graph_Alloc(gfxCtx, sizeof(Vtx_t[16])); + if (vtx == NULL) { + // Translates to: "Vertices cannot be secured." + osSyncPrintf("z_eff_blure.c::SQ_HermiteInterpolate_disp() 頂点確保できず。\n"); + } else { + Math_Vec3f_Diff(&sp1CC, &sp138, &sp158); + Math_Vec3f_Scale(&sp158, 10.0f); + Math_Vec3f_Diff(&sp1C0, &sp138, &sp14C); + Math_Vec3f_Scale(&sp14C, 10.0f); + + Color_RGBA8_Copy(&sp148, &sp1A4); + Color_RGBA8_Copy(&sp144, &sp1A0); + + vtx[0] = baseVtx; + vtx[1] = baseVtx; + + vtx[0].ob[0] = Math_nearbyintf(sp158.x); + vtx[0].ob[1] = Math_nearbyintf(sp158.y); + vtx[0].ob[2] = Math_nearbyintf(sp158.z); + vtx[0].cn[0] = sp148.r; + vtx[0].cn[1] = sp148.g; + vtx[0].cn[2] = sp148.b; + vtx[0].cn[3] = sp148.a; + vtx[1].ob[0] = Math_nearbyintf(sp14C.x); + vtx[1].ob[1] = Math_nearbyintf(sp14C.y); + vtx[1].ob[2] = Math_nearbyintf(sp14C.z); + vtx[1].cn[0] = sp144.r; + vtx[1].cn[1] = sp144.g; + vtx[1].cn[2] = sp144.b; + vtx[1].cn[3] = sp144.a; + + for (i = 1, j1 = 2, j2 = 3; i < 8; i++, j1 += 2, j2 += 2) { + f32 temp_f28 = i / 7.0f; // t + f32 temp_f0 = temp_f28 * temp_f28; // t^2 + f32 temp_f2 = temp_f0 * temp_f28; // t^3 + f32 temp_f14 = temp_f0 * 3.0f; // 3t^2 + f32 temp_f12 = temp_f2 + temp_f2; // 2t^3 + f32 temp_f26 = temp_f14 - temp_f12; // 3t^2 - 2t^3 + f32 temp_f24 = temp_f12 - temp_f14 + 1.0f; // 2t^3 - 3t^2 + 1 + f32 temp_f22 = temp_f2 - (temp_f0 + temp_f0) + temp_f28; // t^3 - 2t^2 + t + f32 temp_f20 = temp_f2 - temp_f0; // t^3 - t^2 + + // p = (2t^3 - 3t^2 + 1)p0 + (3t^2 - 2t^3)p1 + (t^3 - 2t^2 + t)m0 + (t^3 - t^2)m1 + spE0.x = (temp_f24 * sp1CC.x) + (temp_f26 * sp18C.x) + (temp_f22 * sp1B4.x) + (temp_f20 * sp174.x); + spE0.y = (temp_f24 * sp1CC.y) + (temp_f26 * sp18C.y) + (temp_f22 * sp1B4.y) + (temp_f20 * sp174.y); + spE0.z = (temp_f24 * sp1CC.z) + (temp_f26 * sp18C.z) + (temp_f22 * sp1B4.z) + (temp_f20 * sp174.z); + Math_Vec3f_Diff(&spE0, &sp138, &sp158); + Math_Vec3f_Scale(&sp158, 10.0f); + + spE0.x = (temp_f24 * sp1C0.x) + (temp_f26 * sp180.x) + (temp_f22 * sp1A8.x) + (temp_f20 * sp168.x); + spE0.y = (temp_f24 * sp1C0.y) + (temp_f26 * sp180.y) + (temp_f22 * sp1A8.y) + (temp_f20 * sp168.y); + spE0.z = (temp_f24 * sp1C0.z) + (temp_f26 * sp180.z) + (temp_f22 * sp1A8.z) + (temp_f20 * sp168.z); + Math_Vec3f_Diff(&spE0, &sp138, &sp14C); + Math_Vec3f_Scale(&sp14C, 10.0f); + + vtx[j1] = baseVtx; + vtx[j2] = baseVtx; + + vtx[j1].ob[0] = Math_nearbyintf(sp158.x); + vtx[j1].ob[1] = Math_nearbyintf(sp158.y); + vtx[j1].ob[2] = Math_nearbyintf(sp158.z); + vtx[j1].cn[0] = func_80027E84(sp1A4.r, sp19C.r, temp_f28); + vtx[j1].cn[1] = func_80027E84(sp1A4.g, sp19C.g, temp_f28); + vtx[j1].cn[2] = func_80027E84(sp1A4.b, sp19C.b, temp_f28); + vtx[j1].cn[3] = func_80027E84(sp1A4.a, sp19C.a, temp_f28); + + vtx[j2].ob[0] = Math_nearbyintf(sp14C.x); + vtx[j2].ob[1] = Math_nearbyintf(sp14C.y); + vtx[j2].ob[2] = Math_nearbyintf(sp14C.z); + vtx[j2].cn[0] = func_80027E84(sp1A0.r, sp198.r, temp_f28); + vtx[j2].cn[1] = func_80027E84(sp1A0.g, sp198.g, temp_f28); + vtx[j2].cn[2] = func_80027E84(sp1A0.b, sp198.b, temp_f28); + vtx[j2].cn[3] = func_80027E84(sp1A0.a, sp198.a, temp_f28); + } + + gSPVertex(gfxCtx->polyXlu.p++, vtx, 16, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 0, 1, 3, 0, 0, 3, 2, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 2, 3, 5, 0, 2, 5, 4, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 4, 5, 7, 0, 4, 7, 6, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 6, 7, 9, 0, 6, 9, 8, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 8, 9, 11, 0, 8, 11, 10, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 10, 11, 13, 0, 10, 13, 12, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 12, 13, 15, 0, 12, 15, 14, 0); + } + + Graph_CloseDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 1184); +} +#else +Vtx D_80115770 = VTX(0, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF); +#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/EffectBlure_DrawElemHermiteInterpolation.s") +#endif + +#ifdef NON_MATCHING +// missing extra load instructions and saved register/stack usage differences +void EffectBlure_DrawSmooth(EffectBlure* this, GraphicsContext* gfxCtx) { + EffectBlureElement* elem; + s32 i; + MtxF spDC; + MtxF sp9C; + MtxF sp5C; + Mtx* mtx; + Gfx* dispRefs[5]; + + Graph_OpenDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 1201); + + if (this->numElements < 2) { + return; + } + + this->elements[0].flags &= ~3; + this->elements[0].flags |= 2; + + for (elem = &this->elements[1]; elem < &this->elements[this->numElements - 1]; elem++) { + EffectBlure_UpdateFlags(elem); + } + + this->elements[this->numElements - 1].flags &= ~3; + this->elements[this->numElements - 1].flags |= 2; + + EffectBlure_SetupSmooth(this, gfxCtx); + func_800A7A24(&spDC, this->elements[0].p2.x, this->elements[0].p2.y, this->elements[0].p2.z); + func_800A76A4(&sp9C, 0.1f, 0.1f, 0.1f); + func_800A6FA0(&spDC, &sp9C, &sp5C); + + mtx = func_800A7E70(gfxCtx, &sp5C); + if (mtx == NULL) { + return; + } + + gSPMatrix(gfxCtx->polyXlu.p++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + for (i = 0, elem = &this->elements[0]; elem < &this->elements[this->numElements - 1]; elem++, i++) { + if ((elem->state == 0) || ((elem + 1)->state == 0)) { + continue; + } + + if ((((elem->flags & 3) == 0) && (((elem + 1)->flags & 3) == 0)) || + (((elem->flags & 3) == 2) && (((elem + 1)->flags & 3) == 0)) || + (((elem->flags & 3) == 0) && (((elem + 1)->flags & 3) == 2)) || + (((elem->flags & 3) == 2) && (((elem + 1)->flags & 3) == 2))) { + EffectBlure_DrawElemNoInterpolation(this, elem, i, gfxCtx); + } else { + EffectBlure_DrawElemHermiteInterpolation(this, elem, i, gfxCtx); + } + } + + Graph_CloseDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 1263); +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/EffectBlure_DrawSmooth.s") +#endif + +// EffectBlure_SetupSimple +void EffectBlure_SetupSimple(GraphicsContext* gfxCtx, EffectBlure* this, Vtx_t* vtx) { + Gfx* dispRefs[5]; + + Graph_OpenDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 1280); + + gfxCtx->polyXlu.p = Gfx_CallSetupDL(gfxCtx->polyXlu.p, 0x26); + + Graph_CloseDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 1285); +} + +void EffectBlure_SetupSimpleAlt(GraphicsContext* gfxCtx, EffectBlure* this, Vtx_t* vtx) { Gfx* dispRefs[5]; - Graph_OpenDisps(dispRefs, gfxCtx, D_80135180, 809); + Graph_OpenDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 1294); + gDPPipeSync(gfxCtx->polyXlu.p++); gfxCtx->polyXlu.p = Gfx_CallSetupDL(gfxCtx->polyXlu.p, 0x26); - Graph_CloseDisps(dispRefs, gfxCtx, D_80135194, 813); + gDPSetCycleType(gfxCtx->polyXlu.p++, G_CYC_2CYCLE); + gDPSetTextureLUT(gfxCtx->polyXlu.p++, G_TT_NONE); + gSPTexture(gfxCtx->polyXlu.p++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); + + gDPLoadTextureBlock(gfxCtx->polyXlu.p++, D_04006020, G_IM_FMT_I, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_WRAP, 6, 5, G_TX_NOLOD, G_TX_NOLOD); + + gDPSetCombineLERP(gfxCtx->polyXlu.p++, TEXEL0, PRIMITIVE, PRIM_LOD_FRAC, TEXEL0, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, + ENVIRONMENT, COMBINED, ENVIRONMENT, 0, 0, 0, COMBINED); + gDPSetRenderMode(gfxCtx->polyXlu.p++, G_RM_PASS, G_RM_ZB_CLD_SURF2); + gSPClearGeometryMode(gfxCtx->polyXlu.p++, G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR); + gSPSetGeometryMode(gfxCtx->polyXlu.p++, G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH); + gDPPipeSync(gfxCtx->polyXlu.p++); + + gDPSetEnvColor(gfxCtx->polyXlu.p++, this->altEnvColor.r, this->altEnvColor.g, this->altEnvColor.b, + this->altEnvColor.a); + + Graph_CloseDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 1329); } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/func_80020FC0.s") +void (*sSetupHandlers[])(GraphicsContext* gfxCtx, EffectBlure* this, Vtx_t* vtx) = { + EffectBlure_SetupSimple, + EffectBlure_SetupSimpleAlt, +}; + +s32 D_80115788 = 0; // unused + +// original name: "EffectBlureInfo2_disp_makeDisplayList" +void EffectBlure_DrawSimpleVertices(GraphicsContext* gfxCtx, EffectBlure* this, Vtx_t* vtx) { + f32 alphaRatio; + Gfx* dispRefs[5]; + f32 scale; + Vec3f sp1B0; + Vec3f sp1A4; + Vec3f sp198; + Mtx* mtx; + MtxF sp154; + MtxF sp114; + MtxF spD4; + MtxF sp94; + s32 i; + s32 j; + + Graph_OpenDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 1356); -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/func_800214D0.s") + sSetupHandlers[this->drawMode](gfxCtx, this, vtx); + gDPPipeSync(gfxCtx->polyXlu.p++); -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/func_80021F00.s") + j = 0; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/func_800224F4.s") + for (i = 0; i < this->numElements - 1; i++) { + if (this->drawMode == 1) { + alphaRatio = (f32)this->elements[i].timer / (f32)this->elemDuration; + gDPSetPrimColor(gfxCtx->polyXlu.p++, 0x00, 0x80, this->altPrimColor.r, this->altPrimColor.g, + this->altPrimColor.b, this->altPrimColor.a * (1.0f - alphaRatio)); + gDPPipeSync(gfxCtx->polyXlu.p++); + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/func_80022A10.s") + if (1) {} // Necessary to match + + gSPVertex(gfxCtx->polyXlu.p++, &vtx[j], 4, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 0, 1, 3, 0, 0, 3, 2, 0); + + if (this->flags & 4) { + sp1B0.x = ((f32)vtx[4 * i + 0].ob[0] + (f32)vtx[4 * i + 1].ob[0]) * 0.5f; + sp1B0.y = ((f32)vtx[4 * i + 0].ob[1] + (f32)vtx[4 * i + 1].ob[1]) * 0.5f; + sp1B0.z = ((f32)vtx[4 * i + 0].ob[2] + (f32)vtx[4 * i + 1].ob[2]) * 0.5f; + sp1A4.x = ((f32)vtx[4 * i + 2].ob[0] + (f32)vtx[4 * i + 3].ob[0]) * 0.5f; + sp1A4.y = ((f32)vtx[4 * i + 2].ob[1] + (f32)vtx[4 * i + 3].ob[1]) * 0.5f; + sp1A4.z = ((f32)vtx[4 * i + 2].ob[2] + (f32)vtx[4 * i + 3].ob[2]) * 0.5f; + + Math_Vec3f_Diff(&sp1A4, &sp1B0, &sp198); + scale = sqrtf(SQ(sp198.x) + SQ(sp198.y) + SQ(sp198.z)); + + if (fabsf(scale) > 0.0005f) { + scale = 1.0f / scale; + Math_Vec3f_Scale(&sp198, scale); + + func_800A7A24(&sp154, sp1B0.x, sp1B0.y, sp1B0.z); + func_800A7EC0(&sp114, 0x3FFF, sp198.x, sp198.y, sp198.z); + func_800A6FA0(&sp154, &sp114, &spD4); + func_800A7A24(&sp154, -sp1B0.x, -sp1B0.y, -sp1B0.z); + func_800A6FA0(&spD4, &sp154, &sp94); + + mtx = func_800A7E70(gfxCtx, &sp94); + if (mtx == NULL) { + // Translates to: "Forced termination because a matrix cannot be taken" + osSyncPrintf("EffectBlureInfo2_disp_makeDisplayList()マトリックス取れないので,強制終了\n"); + break; + } + + gSPMatrix(gfxCtx->polyXlu.p++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPVertex(gfxCtx->polyXlu.p++, &vtx[j], 4, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 0, 1, 3, 0, 0, 3, 2, 0); + gSPMatrix(gfxCtx->polyXlu.p++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + } + } + + j += 4; + } + + Graph_CloseDisps(dispRefs, gfxCtx, "../z_eff_blure.c", 1452); +} + +Vtx_t D_8011578C[] = { + VTX_T(0, 0, 0, 0, 1024, 0xFF, 0xFF, 0xFF, 0xFF), + VTX_T(0, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF), + VTX_T(0, 0, 0, 2048, 1024, 0xFF, 0xFF, 0xFF, 0xFF), + VTX_T(0, 0, 0, 2048, 0, 0xFF, 0xFF, 0xFF, 0xFF), +}; + +Vtx_t D_801157CC[] = { + VTX_T(0, 0, 0, 2048, 1024, 0xFF, 0xFF, 0xFF, 0xFF), + VTX_T(0, 0, 0, 2048, 0, 0xFF, 0xFF, 0xFF, 0xFF), + VTX_T(0, 0, 0, 2048, 1024, 0xFF, 0xFF, 0xFF, 0xFF), + VTX_T(0, 0, 0, 2048, 0, 0xFF, 0xFF, 0xFF, 0xFF), +}; + +#ifdef NON_MATCHING +void EffectBlure_DrawSimple(EffectBlure* this, GraphicsContext* gfxCtx) { + Vtx_t* vtx; + Vtx_t* vtxIter; + EffectBlureElement* elem; + s32 vtxCount; + s32 i; + s32 j1; + s32 j2; + s32 j3; + Vec3s sp74; + Vec3s sp6C; + f32 ratio; + Color_RGBA8 sp64; + Color_RGBA8 sp60; + + vtxCount = this->numElements * 4; + + if (this->numElements >= 2) { + vtx = Graph_Alloc(gfxCtx, vtxCount * sizeof(Vtx_t)); + if (vtx == NULL) { + // Translates to: "Vertices cannot be secured. Forced termination" + osSyncPrintf("ブラ─表示:頂点確保できず。強制終了\n"); + return; + } + + vtxIter = vtx; + vtxIter[0] = D_8011578C[0]; + vtxIter[1] = D_8011578C[1]; + vtxIter[2] = D_8011578C[2]; + vtxIter[3] = D_8011578C[3]; + vtxIter = vtx + 4; + + if (this->numElements >= 2) { + for (elem = &this->elements[1]; elem < &this->elements[this->numElements - 2]; elem++) { + vtxIter[0] = D_801157CC[0]; + vtxIter[1] = D_801157CC[1]; + vtxIter[2] = D_801157CC[2]; + vtxIter[3] = D_801157CC[3]; + vtxIter += 4; + } + } + + j1 = -2; + j2 = -1; + for (i = 0; i < this->numElements; i++) { + elem = &this->elements[i]; + + ratio = (f32)elem->timer / (f32)this->elemDuration; + EffectBlure_GetComputedValues(this, i, ratio, &sp74, &sp6C, &sp64, &sp60); + + if (j1 >= 0) { + vtx[j1].ob[0] = sp74.x; + vtx[j1].ob[1] = sp74.y; + vtx[j1].ob[2] = sp74.z; + vtx[j1].cn[0] = sp64.r; + vtx[j1].cn[1] = sp64.g; + vtx[j1].cn[2] = sp64.b; + vtx[j1].cn[3] = sp64.a; + } + + j3 = j2; + if (j3 >= 0) { + vtx[j3].ob[0] = sp6C.x; + vtx[j3].ob[1] = sp6C.y; + vtx[j3].ob[2] = sp6C.z; + vtx[j3].cn[0] = sp60.r; + vtx[j3].cn[1] = sp60.g; + vtx[j3].cn[2] = sp60.b; + vtx[j3].cn[3] = sp60.a; + } + + j3++; + if (vtxCount >= j3) { + vtx[j3].ob[0] = sp74.x; + vtx[j3].ob[1] = sp74.y; + vtx[j3].ob[2] = sp74.z; + vtx[j3].cn[0] = sp64.r; + vtx[j3].cn[1] = sp64.g; + vtx[j3].cn[2] = sp64.b; + vtx[j3].cn[3] = sp64.a; + } + + j3++; + if (vtxCount >= j3) { + vtx[j3].ob[0] = sp6C.x; + vtx[j3].ob[1] = sp6C.y; + vtx[j3].ob[2] = sp6C.z; + vtx[j3].cn[0] = sp60.r; + vtx[j3].cn[1] = sp60.g; + vtx[j3].cn[2] = sp60.b; + vtx[j3].cn[3] = sp60.a; + } + + j1 += 4; + j2 += 4; + } + + EffectBlure_DrawSimpleVertices(gfxCtx, this, vtx); + } +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_blure/EffectBlure_DrawSimple.s") +#endif + +void EffectBlure_Draw(void* thisx, GraphicsContext* gfxCtx) { + EffectBlure* this = (EffectBlure*)thisx; + Vtx_t* vtx; + EffectBlureElement* elem; + s32 i; + s32 j; + s32 phi_t2; + Gfx* sp74[5]; + f32 ratio; + + Graph_OpenDisps(sp74, gfxCtx, "../z_eff_blure.c", 1596); + + gSPMatrix(gfxCtx->polyXlu.p++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + if (this->numElements != 0) { + if (this->flags == 0) { + func_800942F0(gfxCtx); + gDPPipeSync(gfxCtx->polyXlu.p++); + + vtx = Graph_Alloc(gfxCtx, sizeof(Vtx_t[32])); + if (vtx == NULL) { + // Translates to: "Blure display: Vertex table could not be secured" + osSyncPrintf("ブラ─表示:頂点テーブル確保できず\n"); + } else { + j = 0; + for (i = 0; i < this->numElements; i++) { + elem = &this->elements[i]; + + if (elem->state == 1) { + ratio = (f32)elem->timer / (f32)this->elemDuration; + + switch (this->calcMode) { + case 1: + vtx[j].ob[0] = func_80027E34(elem->p1.x, elem->p2.x, ratio); + vtx[j].ob[1] = func_80027E34(elem->p1.y, elem->p2.y, ratio); + vtx[j].ob[2] = func_80027E34(elem->p1.z, elem->p2.z, ratio); + vtx[j + 1].ob[0] = elem->p2.x; + vtx[j + 1].ob[1] = elem->p2.y; + vtx[j + 1].ob[2] = elem->p2.z; + break; + case 2: + vtx[j].ob[0] = elem->p1.x; + vtx[j].ob[1] = elem->p1.y; + vtx[j].ob[2] = elem->p1.z; + vtx[j + 1].ob[0] = func_80027E34(elem->p2.x, elem->p1.x, ratio); + vtx[j + 1].ob[1] = func_80027E34(elem->p2.y, elem->p1.y, ratio); + vtx[j + 1].ob[2] = func_80027E34(elem->p2.z, elem->p1.z, ratio); + break; + case 3: + ratio = ratio * 0.5f; + vtx[j].ob[0] = func_80027E34(elem->p1.x, elem->p2.x, ratio); + vtx[j].ob[1] = func_80027E34(elem->p1.y, elem->p2.y, ratio); + vtx[j].ob[2] = func_80027E34(elem->p1.z, elem->p2.z, ratio); + vtx[j + 1].ob[0] = func_80027E34(elem->p2.x, elem->p1.x, ratio); + vtx[j + 1].ob[1] = func_80027E34(elem->p2.y, elem->p1.y, ratio); + vtx[j + 1].ob[2] = func_80027E34(elem->p2.z, elem->p1.z, ratio); + ratio = ratio + ratio; + break; + case 0: + default: + vtx[j].ob[0] = elem->p1.x; + vtx[j].ob[1] = elem->p1.y; + vtx[j].ob[2] = elem->p1.z; + vtx[j + 1].ob[0] = elem->p2.x; + vtx[j + 1].ob[1] = elem->p2.y; + vtx[j + 1].ob[2] = elem->p2.z; + break; + } + + vtx[j].flag = 0; + vtx[j].tc[0] = 0; + vtx[j].tc[1] = 0; + vtx[j].cn[0] = func_80027E84(this->p1StartColor.r, this->p1EndColor.r, ratio); + vtx[j].cn[1] = func_80027E84(this->p1StartColor.g, this->p1EndColor.g, ratio); + vtx[j].cn[2] = func_80027E84(this->p1StartColor.b, this->p1EndColor.b, ratio); + vtx[j].cn[3] = func_80027E84(this->p1StartColor.a, this->p1EndColor.a, ratio); + j++; + + vtx[j].flag = 0; + vtx[j].tc[0] = 0; + vtx[j].tc[1] = 0; + vtx[j].cn[0] = func_80027E84(this->p2StartColor.r, this->p2EndColor.r, ratio); + vtx[j].cn[1] = func_80027E84(this->p2StartColor.g, this->p2EndColor.g, ratio); + vtx[j].cn[2] = func_80027E84(this->p2StartColor.b, this->p2EndColor.b, ratio); + vtx[j].cn[3] = func_80027E84(this->p2StartColor.a, this->p2EndColor.a, ratio); + j++; + } + } + + j = 0; + + gSPVertex(gfxCtx->polyXlu.p++, vtx, 32, 0); + + phi_t2 = 0; + for (i = 0; i < this->numElements; i++) { + elem = &this->elements[i]; + + if (elem->state == 0) { + phi_t2 = 0; + } else { + if (phi_t2 == 0) { + phi_t2 = 1; + } else { + gSP1Quadrangle(gfxCtx->polyXlu.p++, j - 2, j - 1, j + 1, j, 0); + + if (1) {} // Necessary to match + + if (this->unkFlag == 1) { + phi_t2 = 0; + } + } + j += 2; + } + } + } + } else if (this->drawMode < 2) { + EffectBlure_DrawSimple(this, gfxCtx); + } else { + EffectBlure_DrawSmooth(this, gfxCtx); + } + } + + Graph_CloseDisps(sp74, gfxCtx, "../z_eff_blure.c", 1823); +} diff --git a/src/code/z_eff_shield_particle.c b/src/code/z_eff_shield_particle.c index d3f2591f8..b3be66f79 100644 --- a/src/code/z_eff_shield_particle.c +++ b/src/code/z_eff_shield_particle.c @@ -1,10 +1,228 @@ #include <ultra64.h> #include <global.h> +#include <vt.h> -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_shield_particle/func_80023450.s") +static Vtx sVertices[5] = { + VTX(-32, -32, 0, 0, 1024, 0xFF, 0xFF, 0xFF, 0xFF), + VTX(32, 32, 0, 1024, 0, 0xFF, 0xFF, 0xFF, 0xFF), + VTX(-32, 32, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF), + VTX(32, -32, 0, 1024, 1024, 0xFF, 0xFF, 0xFF, 0xFF), +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_shield_particle/func_800236B4.s") +// original name: "EffectShieldParticle_ct" +void EffectShieldParticle_Init(void* thisx, void* initParamsx) { + EffectShieldParticle* this = (EffectShieldParticle*)thisx; + EffectShieldParticleInit* initParams = (EffectShieldParticleInit*)initParamsx; + EffectShieldParticleElement* elem; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_shield_particle/func_8002389C.s") + if ((this != NULL) && (initParams != NULL)) { + this->numElements = initParams->numElements; + if (this->numElements > ARRAY_COUNT(this->elements)) { + osSyncPrintf(VT_FGCOL(RED)); + osSyncPrintf("EffectShieldParticle_ct():パーティクル数がオーバしてます。\n"); + osSyncPrintf(VT_RST); + return; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_shield_particle/func_800245BC.s") + this->position = initParams->position; + this->primColorStart = initParams->primColorStart; + this->envColorStart = initParams->envColorStart; + this->primColorMid = initParams->primColorMid; + this->envColorMid = initParams->envColorMid; + this->primColorEnd = initParams->primColorEnd; + this->envColorEnd = initParams->envColorEnd; + this->deceleration = initParams->deceleration; + this->maxInitialSpeed = initParams->maxInitialSpeed; + this->lengthCutoff = initParams->lengthCutoff; + this->duration = initParams->duration; + this->timer = 0; + + for (elem = &this->elements[0]; elem < &this->elements[this->numElements]; elem++) { + elem->initialSpeed = + (Math_Rand_ZeroOne() * (this->maxInitialSpeed * 0.5f)) + (this->maxInitialSpeed * 0.5f); + elem->endX = 0.0f; + elem->startXChange = 0.0f; + elem->startX = 0.0f; + elem->endXChange = elem->initialSpeed; + elem->yaw = Math_Rand_ZeroOne() * 65534.0f; + elem->pitch = Math_Rand_ZeroOne() * 65534.0f; + } + + this->lightDecay = initParams->lightDecay; + if (this->lightDecay == true) { + this->lightInfo.type = 0; + this->lightInfo.params = initParams->lightParams; + this->light = Lights_Insert(Effect_GetGlobalCtx(), &Effect_GetGlobalCtx()->lightCtx, &this->lightInfo); + } else { + this->light = NULL; + } + } +} + +void EffectShieldParticle_Destroy(void* thisx) { + EffectShieldParticle* this = (EffectShieldParticle*)thisx; + + if ((this != NULL) && (this->lightDecay == true)) { + if (this->light == Effect_GetGlobalCtx()->lightCtx.lightsHead) { + Effect_GetGlobalCtx()->lightCtx.lightsHead = this->light->next; + } + Lights_Remove(Effect_GetGlobalCtx(), &Effect_GetGlobalCtx()->lightCtx, this->light); + } +} + +s32 EffectShieldParticle_Update(void* thisx) { + EffectShieldParticle* this = (EffectShieldParticle*)thisx; + EffectShieldParticleElement* elem; + + if (this == NULL) { + return 0; + } + + for (elem = &this->elements[0]; elem < &this->elements[this->numElements]; elem++) { + elem->endXChange -= this->deceleration; + if (elem->endXChange < 0.0f) { + elem->endXChange = 0.0f; + } + + if (elem->startXChange > 0.0f) { + elem->startXChange -= this->deceleration; + if (elem->startXChange < 0.0f) { + elem->startXChange = 0.0f; + } + } + + elem->endX += elem->endXChange; + elem->startX += elem->startXChange; + + if ((elem->startXChange == 0.0f) && (this->lengthCutoff < (elem->endX - elem->startX))) { + elem->startXChange = elem->initialSpeed; + } + } + + if (this->lightDecay == true) { + this->lightInfo.params.radius /= 2; + } + + this->timer++; + + if (this->duration < this->timer) { + return 1; + } + + return 0; +} + +void EffectShieldParticle_GetColors(EffectShieldParticle* this, Color_RGBA8_n* primColor, Color_RGBA8_n* envColor) { + s32 halfDuration; + f32 ratio; + + halfDuration = this->duration * 0.5f; + if (halfDuration == 0) { + primColor->r = this->primColorStart.r; + primColor->g = this->primColorStart.g; + primColor->b = this->primColorStart.b; + primColor->a = this->primColorStart.a; + envColor->r = this->envColorStart.r; + envColor->g = this->envColorStart.g; + envColor->b = this->envColorStart.b; + envColor->a = this->envColorStart.a; + } else if (this->timer < halfDuration) { + ratio = this->timer / (f32)halfDuration; + primColor->r = this->primColorStart.r + (this->primColorMid.r - this->primColorStart.r) * ratio; + primColor->g = this->primColorStart.g + (this->primColorMid.g - this->primColorStart.g) * ratio; + primColor->b = this->primColorStart.b + (this->primColorMid.b - this->primColorStart.b) * ratio; + primColor->a = this->primColorStart.a + (this->primColorMid.a - this->primColorStart.a) * ratio; + envColor->r = this->envColorStart.r + (this->envColorMid.r - this->envColorStart.r) * ratio; + envColor->g = this->envColorStart.g + (this->envColorMid.g - this->envColorStart.g) * ratio; + envColor->b = this->envColorStart.b + (this->envColorMid.b - this->envColorStart.b) * ratio; + envColor->a = this->envColorStart.a + (this->envColorMid.a - this->envColorStart.a) * ratio; + } else { + ratio = (this->timer - halfDuration) / (f32)halfDuration; + primColor->r = this->primColorMid.r + (this->primColorEnd.r - this->primColorMid.r) * ratio; + primColor->g = this->primColorMid.g + (this->primColorEnd.g - this->primColorMid.g) * ratio; + primColor->b = this->primColorMid.b + (this->primColorEnd.b - this->primColorMid.b) * ratio; + primColor->a = this->primColorMid.a + (this->primColorEnd.a - this->primColorMid.a) * ratio; + envColor->r = this->envColorMid.r + (this->envColorEnd.r - this->envColorMid.r) * ratio; + envColor->g = this->envColorMid.g + (this->envColorEnd.g - this->envColorMid.g) * ratio; + envColor->b = this->envColorMid.b + (this->envColorEnd.b - this->envColorMid.b) * ratio; + envColor->a = this->envColorMid.a + (this->envColorEnd.a - this->envColorMid.a) * ratio; + } +} + +void EffectShieldParticle_Draw(void* thisx, GraphicsContext* gfxCtx) { + EffectShieldParticle* this = (EffectShieldParticle*)thisx; + EffectShieldParticleElement* elem; + Color_RGBA8_n primColor; + Color_RGBA8_n envColor; + Gfx* dispRefs[5]; + Mtx* mtx; + + Graph_OpenDisps(dispRefs, gfxCtx, "../z_eff_shield_particle.c", 272); + + if (this != NULL) { + gfxCtx->polyXlu.p = Gfx_CallSetupDL(gfxCtx->polyXlu.p, 0x26); + + gDPSetCycleType(gfxCtx->polyXlu.p++, G_CYC_2CYCLE); + gDPPipeSync(gfxCtx->polyXlu.p++); + gSPTexture(gfxCtx->polyXlu.p++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); + + gDPLoadTextureBlock(gfxCtx->polyXlu.p++, D_04038FB0, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 5, 5, G_TX_NOLOD, G_TX_NOLOD); + + if (1) {} // Both necessary to match + if (1) {} + + gDPSetCombineLERP(gfxCtx->polyXlu.p++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, PRIMITIVE, 0, TEXEL0, 0, 0, + 0, 0, COMBINED, 0, 0, 0, COMBINED); + gDPSetRenderMode(gfxCtx->polyXlu.p++, G_RM_PASS, G_RM_ZB_CLD_SURF2); + gSPClearGeometryMode(gfxCtx->polyXlu.p++, + G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR); + gSPSetGeometryMode(gfxCtx->polyXlu.p++, G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH); + + if (1) {} // Also necessary to match + + EffectShieldParticle_GetColors(this, &primColor, &envColor); + + gDPSetPrimColor(gfxCtx->polyXlu.p++, 0, 0, primColor.r, primColor.g, primColor.b, primColor.a); + gDPSetEnvColor(gfxCtx->polyXlu.p++, envColor.r, envColor.g, envColor.b, envColor.a); + gDPPipeSync(gfxCtx->polyXlu.p++); + + for (elem = &this->elements[0]; elem < &this->elements[this->numElements]; elem++) { + MtxF sp104; + MtxF spC4; + MtxF sp84; + f32 temp1; + f32 temp2; + f32 temp3; + + temp1 = (s16)((elem->endX + elem->startX) * 0.5f); + + temp2 = elem->endX - elem->startX; + temp3 = (s16)((temp2 * (1.0f / 64.0f)) / 0.02f); + if (temp3 < 1.0f) { + temp3 = 1.0f; + } + + func_800A7A24(&spC4, this->position.x, this->position.y, this->position.z); + func_800A7704(&sp104, 0, elem->yaw, 0); + func_800A6FA0(&spC4, &sp104, &sp84); + func_800A7704(&sp104, 0, 0, elem->pitch); + func_800A6FA0(&sp84, &sp104, &spC4); + func_800A7A24(&sp104, temp1, 0.0f, 0.0f); + func_800A6FA0(&spC4, &sp104, &sp84); + func_800A76A4(&sp104, temp3 * 0.02f, 0.02f, 0.02f); + func_800A6FA0(&sp84, &sp104, &spC4); + + mtx = func_800A7E70(gfxCtx, &spC4); + if (mtx == NULL) { + break; + } + + gSPMatrix(gfxCtx->polyXlu.p++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPVertex(gfxCtx->polyXlu.p++, sVertices, 4, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 0, 1, 2, 0, 0, 3, 1, 0); + } + } + + Graph_CloseDisps(dispRefs, gfxCtx, "../z_eff_shield_particle.c", 359); +} diff --git a/src/code/z_eff_spark.c b/src/code/z_eff_spark.c index 5f7c2a65f..08d123893 100644 --- a/src/code/z_eff_spark.c +++ b/src/code/z_eff_spark.c @@ -1,11 +1,289 @@ #include <ultra64.h> #include <global.h> -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_spark/func_80024B00.s") +// original name: "spark" +void EffectSpark_Init(void* thisx, void* initParamsx) { + EffectSpark* this = (EffectSpark*)thisx; + EffectSparkInit* initParams = (EffectSparkInit*)initParamsx; + EffectSparkElement* elem; + f32 velocityNorm; + s32 i; -void func_80024F0C(UNK_TYPE arg0) { + if ((this != NULL) && (initParams != NULL)) { + if ((initParams->uDiv == 0) || (initParams->vDiv == 0)) { + // Translates to: "u_div,v_div 0 is not good." + osSyncPrintf("spark():u_div,v_div 0では困る。\n"); + return; + } + + this->position = initParams->position; + this->speed = initParams->speed; + this->gravity = initParams->gravity; + this->uDiv = initParams->uDiv; + this->vDiv = initParams->vDiv; + this->colorStart[0].r = initParams->colorStart[0].r; + this->colorStart[0].g = initParams->colorStart[0].g; + this->colorStart[0].b = initParams->colorStart[0].b; + this->colorStart[0].a = initParams->colorStart[0].a; + this->colorStart[1].r = initParams->colorStart[1].r; + this->colorStart[1].g = initParams->colorStart[1].g; + this->colorStart[1].b = initParams->colorStart[1].b; + this->colorStart[1].a = initParams->colorStart[1].a; + this->colorStart[2].r = initParams->colorStart[2].r; + this->colorStart[2].g = initParams->colorStart[2].g; + this->colorStart[2].b = initParams->colorStart[2].b; + this->colorStart[2].a = initParams->colorStart[2].a; + this->colorStart[3].r = initParams->colorStart[3].r; + this->colorStart[3].g = initParams->colorStart[3].g; + this->colorStart[3].b = initParams->colorStart[3].b; + this->colorStart[3].a = initParams->colorStart[3].a; + this->colorEnd[0].r = initParams->colorEnd[0].r; + this->colorEnd[0].g = initParams->colorEnd[0].g; + this->colorEnd[0].b = initParams->colorEnd[0].b; + this->colorEnd[0].a = initParams->colorEnd[0].a; + this->colorEnd[1].r = initParams->colorEnd[1].r; + this->colorEnd[1].g = initParams->colorEnd[1].g; + this->colorEnd[1].b = initParams->colorEnd[1].b; + this->colorEnd[1].a = initParams->colorEnd[1].a; + this->colorEnd[2].r = initParams->colorEnd[2].r; + this->colorEnd[2].g = initParams->colorEnd[2].g; + this->colorEnd[2].b = initParams->colorEnd[2].b; + this->colorEnd[2].a = initParams->colorEnd[2].a; + this->colorEnd[3].r = initParams->colorEnd[3].r; + this->colorEnd[3].g = initParams->colorEnd[3].g; + this->colorEnd[3].b = initParams->colorEnd[3].b; + this->colorEnd[3].a = initParams->colorEnd[3].a; + this->duration = initParams->duration; + + this->numElements = (this->uDiv * this->vDiv) + 2; + if (this->numElements > ARRAY_COUNT(this->elements)) { + osSyncPrintf("table_sizeオーバー\n"); // "over table_size" + return; + } + + for (i = 0; i < this->numElements; i++) { + elem = &this->elements[i]; + + elem->position.x = this->position.x; + elem->position.y = this->position.y; + elem->position.z = this->position.z; + elem->velocity.x = Math_Rand_ZeroOne() - 0.5f; + elem->velocity.y = Math_Rand_ZeroOne() - 0.5f; + elem->velocity.z = Math_Rand_ZeroOne() - 0.5f; + + velocityNorm = sqrtf(SQ(elem->velocity.x) + SQ(elem->velocity.y) + SQ(elem->velocity.z)); + + if (!(fabsf(velocityNorm) < 0.008f)) { + elem->velocity.x *= this->speed * (1.0f / velocityNorm); + elem->velocity.y *= this->speed * (1.0f / velocityNorm); + elem->velocity.z *= this->speed * (1.0f / velocityNorm); + } else { + elem->velocity.x = elem->velocity.z = 0.0f; + elem->velocity.y = this->speed; + } + + elem->unkVelocity.x = 30000.0f - Math_Rand_ZeroOne() * 15000.0f; + elem->unkVelocity.y = 30000.0f - Math_Rand_ZeroOne() * 15000.0f; + elem->unkVelocity.z = 30000.0f - Math_Rand_ZeroOne() * 15000.0f; + elem->unkPosition.x = Math_Rand_ZeroOne() * 65534.0f; + elem->unkPosition.y = Math_Rand_ZeroOne() * 65534.0f; + elem->unkPosition.z = Math_Rand_ZeroOne() * 65534.0f; + } + + this->timer = 0; + } +} + +void EffectSpark_Destroy(void* thisx) { } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_spark/func_80024F14.s") +// original name: "EffectSparkInfo_proc" +s32 EffectSpark_Update(void* thisx) { + EffectSpark* this = (EffectSpark*)thisx; + EffectSparkElement* elem; + s32 i; + + if (this == NULL) { + osSyncPrintf("EffectSparkInfo_proc():Spark Pointer is NULL\n"); + } + + for (i = 0; i < this->numElements; i++) { + elem = &this->elements[i]; + + elem->position.x += elem->velocity.x; + elem->position.y += elem->velocity.y; + elem->position.z += elem->velocity.z; + elem->velocity.y += this->gravity; + elem->unkPosition.x += elem->unkVelocity.x; + elem->unkPosition.y += elem->unkVelocity.y; + elem->unkPosition.z += elem->unkVelocity.z; + } + + this->timer++; + + if (this->duration < this->timer) { + return 1; + } else { + return 0; + } +} + +// original name: "EffectSparkInfo_disp" +#ifdef NON_MATCHING +// minor ordering and saved register usage differences +void EffectSpark_Draw(void* thisx, GraphicsContext* gfxCtx) { + Vtx* vertices; + EffectSpark* this = (EffectSpark*)thisx; // sp1E0 + EffectSparkElement* elem; + GlobalContext* globalCtx; + f32 ratio; + u8 sp1D3; + u8 sp1D2; + u8 sp1D1; + u8 sp1D0; + u8 sp1CF; + u8 sp1CE; + u8 sp1CD; + u8 sp1CC; + u8 sp1CB; + u8 sp1CA; + u8 sp1C9; + u8 sp1C8; + u8 sp1C7; + u8 sp1C6; + u8 sp1C5; + u8 sp1C4; + s32 i; + s32 j; + Gfx* dispRefs[4]; // sp1AC + + globalCtx = Effect_GetGlobalCtx(); + Graph_OpenDisps(dispRefs, gfxCtx, "../z_eff_spark.c", 293); + + if (this != NULL) { + gSPMatrix(gfxCtx->polyXlu.p++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_spark/func_80025000.s") + gfxCtx->polyXlu.p = Gfx_CallSetupDL(gfxCtx->polyXlu.p, 0x26); + gDPSetCycleType(gfxCtx->polyXlu.p++, G_CYC_2CYCLE); + gDPPipeSync(gfxCtx->polyXlu.p++); + + gSPTexture(gfxCtx->polyXlu.p++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); + gDPLoadTextureBlock(gfxCtx->polyXlu.p++, D_04038FB0, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 5, 5, G_TX_NOLOD, G_TX_NOLOD); + + gDPSetCombineMode(gfxCtx->polyXlu.p++, G_CC_SHADEDECALA, G_CC_PASS2); + gDPSetRenderMode(gfxCtx->polyXlu.p++, G_RM_PASS, G_RM_ZB_CLD_SURF2); + gSPClearGeometryMode(gfxCtx->polyXlu.p++, + G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR); + gSPSetGeometryMode(gfxCtx->polyXlu.p++, G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH); + gDPPipeSync(gfxCtx->polyXlu.p++); + + vertices = Graph_Alloc(gfxCtx, this->numElements * sizeof(Vtx[4])); + if (vertices == NULL) { + // Translates to: "Memory Allocation Failure graph_malloc" + osSyncPrintf("EffectSparkInfo_disp():メモリー確保失敗 graph_malloc\n"); + return; + } + + j = 0; + + ratio = (f32)this->timer / (f32)this->duration; + sp1D3 = this->colorStart[0].r + ((f32)this->colorEnd[0].r - (f32)this->colorStart[0].r) * ratio; + sp1D2 = this->colorStart[0].g + ((f32)this->colorEnd[0].g - (f32)this->colorStart[0].g) * ratio; + sp1D1 = this->colorStart[0].b + ((f32)this->colorEnd[0].b - (f32)this->colorStart[0].b) * ratio; + sp1D0 = this->colorStart[0].a + ((f32)this->colorEnd[0].a - (f32)this->colorStart[0].a) * ratio; + sp1CF = this->colorStart[1].r + ((f32)this->colorEnd[1].r - (f32)this->colorStart[1].r) * ratio; + sp1CE = this->colorStart[1].g + ((f32)this->colorEnd[1].g - (f32)this->colorStart[1].g) * ratio; + sp1CD = this->colorStart[1].b + ((f32)this->colorEnd[1].b - (f32)this->colorStart[1].b) * ratio; + sp1CC = this->colorStart[1].a + ((f32)this->colorEnd[1].a - (f32)this->colorStart[1].a) * ratio; + sp1CB = this->colorStart[2].r + ((f32)this->colorEnd[2].r - (f32)this->colorStart[2].r) * ratio; + sp1CA = this->colorStart[2].g + ((f32)this->colorEnd[2].g - (f32)this->colorStart[2].g) * ratio; + sp1C9 = this->colorStart[2].b + ((f32)this->colorEnd[2].b - (f32)this->colorStart[2].b) * ratio; + sp1C8 = this->colorStart[2].a + ((f32)this->colorEnd[2].a - (f32)this->colorStart[2].a) * ratio; + sp1C7 = this->colorStart[3].r + ((f32)this->colorEnd[3].r - (f32)this->colorStart[3].r) * ratio; + sp1C6 = this->colorStart[3].g + ((f32)this->colorEnd[3].g - (f32)this->colorStart[3].g) * ratio; + sp1C5 = this->colorStart[3].b + ((f32)this->colorEnd[3].b - (f32)this->colorStart[3].b) * ratio; + sp1C4 = this->colorStart[3].a + ((f32)this->colorEnd[3].a - (f32)this->colorStart[3].a) * ratio; + + for (i = 0; i < this->numElements; i++) { + MtxF sp12C; + MtxF spEC; + MtxF spAC; + MtxF sp6C; + Mtx* mtx; + f32 temp; + + elem = &this->elements[i]; + + func_800A7A24(&spEC, elem->position.x, elem->position.y, elem->position.z); + temp = ((Math_Rand_ZeroOne() * 2.5f) + 1.5f) * 0.015625f; + func_800A76A4(&spAC, temp, temp, 1.0f); + func_800A6FA0(&spEC, &globalCtx->mf_11DA0, &sp6C); + func_800A6FA0(&sp6C, &spAC, &sp12C); + + vertices[j].v.ob[0] = -32; + vertices[j].v.ob[1] = -32; + vertices[j].v.ob[2] = 0; + vertices[j].v.cn[0] = sp1D3; + vertices[j].v.cn[1] = sp1D2; + vertices[j].v.cn[2] = sp1D1; + vertices[j].v.cn[3] = sp1D0; + vertices[j].v.tc[0] = 0; + vertices[j].v.tc[1] = 1024; + vertices[j].v.flag = 0; + + vertices[j + 1].v.ob[0] = 32; + vertices[j + 1].v.ob[1] = 32; + vertices[j + 1].v.ob[2] = 0; + vertices[j + 1].v.cn[0] = sp1CF; + vertices[j + 1].v.cn[1] = sp1CE; + vertices[j + 1].v.cn[2] = sp1CD; + vertices[j + 1].v.cn[3] = sp1CC; + vertices[j + 1].v.tc[0] = 1024; + vertices[j + 1].v.tc[1] = 0; + vertices[j + 1].v.flag = 0; + + vertices[j + 2].v.ob[0] = -32; + vertices[j + 2].v.ob[1] = 32; + vertices[j + 2].v.ob[2] = 0; + vertices[j + 2].v.cn[0] = sp1CB; + vertices[j + 2].v.cn[1] = sp1CA; + vertices[j + 2].v.cn[2] = sp1C9; + vertices[j + 2].v.cn[3] = sp1C8; + vertices[j + 2].v.tc[0] = 0; + vertices[j + 2].v.tc[1] = 0; + vertices[j + 2].v.flag = 0; + + vertices[j + 3].v.ob[0] = 32; + vertices[j + 3].v.ob[1] = -32; + vertices[j + 3].v.ob[2] = 0; + vertices[j + 3].v.cn[0] = sp1C7; + vertices[j + 3].v.cn[1] = sp1C6; + vertices[j + 3].v.cn[2] = sp1C5; + vertices[j + 3].v.cn[3] = sp1C4; + vertices[j + 3].v.tc[0] = 1024; + vertices[j + 3].v.tc[1] = 1024; + vertices[j + 3].v.flag = 0; + + j += 4; + + if (this) {} + + mtx = func_800A7E70(gfxCtx, &sp12C); + if (mtx == NULL) { + break; + } + + gSPMatrix(gfxCtx->polyXlu.p++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPVertex(gfxCtx->polyXlu.p++, &vertices[4 * i], 4, 0); + gSP2Triangles(gfxCtx->polyXlu.p++, 2, 0, 3, 0, 2, 3, 1, 0); + } + + gDPPipeSync(gfxCtx->polyXlu.p++); + } + + Graph_CloseDisps(dispRefs, gfxCtx, "../z_eff_spark.c", 498); +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_spark/EffectSpark_Draw.s") +#endif diff --git a/src/code/z_eff_ss_dead.c b/src/code/z_eff_ss_dead.c index f203e81e4..05e60bdcd 100644 --- a/src/code/z_eff_ss_dead.c +++ b/src/code/z_eff_ss_dead.c @@ -1,14 +1,140 @@ #include <ultra64.h> #include <global.h> -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_ss_dead/func_80026230.s") +void func_80026230(GlobalContext* globalCtx, Color_RGBA8* color, s16 arg2, s16 arg3) { + f32 cos; + Gfx* displayListHead; + f32 absCos; + GraphicsContext* gfxCtx; + Gfx* dispRefs[4]; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_ss_dead/func_80026400.s") + gfxCtx = globalCtx->state.gfxCtx; + Graph_OpenDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 113); -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_ss_dead/func_80026608.s") + displayListHead = gfxCtx->polyOpa.p; + cos = Math_Coss((0x8000 / arg3) * arg2); + absCos = ABS(cos); -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_ss_dead/func_80026690.s") + gDPPipeSync(displayListHead++); -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_ss_dead/func_80026860.s") + if (color == NULL) { + gDPSetFogColor(displayListHead++, 0xFF, 0x00, 0x00, 0x00); + } else { + gDPSetFogColor(displayListHead++, color->r, color->g, color->b, color->a); + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_eff_ss_dead/func_80026A6C.s") + gSPFogPosition(displayListHead++, 0, (s16)(absCos * 3000.0f) + 1500); + + gfxCtx->polyOpa.p = displayListHead; + + if (1) {} // Necessary to match + + Graph_CloseDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 129); +} + +void func_80026400(GlobalContext* globalCtx, Color_RGBA8* color, s16 arg2, s16 arg3) { + Gfx* displayListHead; + f32 cos; + GraphicsContext* gfxCtx; + Gfx* dispRefs[4]; + + if (arg3 != 0) { + gfxCtx = globalCtx->state.gfxCtx; + Graph_OpenDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 141); + + cos = Math_Coss((0x4000 / arg3) * arg2); + displayListHead = gfxCtx->polyOpa.p; + + gDPPipeSync(displayListHead++); + gDPSetFogColor(displayListHead++, color->r, color->g, color->b, color->a); + gSPFogPosition(displayListHead++, 0, (s16)(2800.0f * ABS(cos)) + 1700); + + gfxCtx->polyOpa.p = displayListHead; + + if (1) {} // Necessary to match + + Graph_CloseDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 153); + } +} + +void func_80026608(GlobalContext* globalCtx) { + s32 pad; + GraphicsContext* gfxCtx; + Gfx* dispRefs[4]; + + gfxCtx = globalCtx->state.gfxCtx; + Graph_OpenDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 159); + + gDPPipeSync(gfxCtx->polyOpa.p++); + gfxCtx->polyOpa.p = func_800BC8A0(globalCtx, gfxCtx->polyOpa.p); + + Graph_CloseDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 164); +} + +void func_80026690(GlobalContext* globalCtx, Color_RGBA8* color, s16 arg2, s16 arg3) { + f32 cos; + Gfx* displayListHead; + f32 absCos; + GraphicsContext* gfxCtx; + Gfx* dispRefs[4]; + + gfxCtx = globalCtx->state.gfxCtx; + Graph_OpenDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 178); + + displayListHead = gfxCtx->polyXlu.p; + cos = Math_Coss((0x8000 / arg3) * arg2); + absCos = ABS(cos); + + gDPPipeSync(displayListHead++); + + if (color == NULL) { + gDPSetFogColor(displayListHead++, 0xFF, 0x00, 0x00, 0x00); + } else { + gDPSetFogColor(displayListHead++, color->r, color->g, color->b, color->a); + } + + gSPFogPosition(displayListHead++, 0, (s16)(absCos * 3000.0f) + 1500); + + gfxCtx->polyXlu.p = displayListHead; + + if (1) {} // Necessary to match + + Graph_CloseDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 194); +} + +void func_80026860(GlobalContext* globalCtx, Color_RGBA8* color, s16 arg2, s16 arg3) { + f32 cos; + Gfx* displayListHead; + GraphicsContext* gfxCtx; + Gfx* dispRefs[4]; + + gfxCtx = globalCtx->state.gfxCtx; + Graph_OpenDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 201); + + displayListHead = gfxCtx->polyXlu.p; + cos = Math_Coss((0x4000 / arg3) * arg2); + + gDPPipeSync(displayListHead++); + gDPSetFogColor(displayListHead++, color->r, color->g, color->b, color->a); + gSPFogPosition(displayListHead++, 0, (s16)(2800.0f * ABS(cos)) + 1700); + + gfxCtx->polyXlu.p = displayListHead; + + if (1) {} // Necessary to match + + Graph_CloseDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 212); +} + +void func_80026A6C(GlobalContext* globalCtx) { + s32 pad; + GraphicsContext* gfxCtx; + Gfx* dispRefs[4]; + + gfxCtx = globalCtx->state.gfxCtx; + Graph_OpenDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 217); + + gDPPipeSync(gfxCtx->polyXlu.p++); + gfxCtx->polyXlu.p = func_800BC8A0(globalCtx, gfxCtx->polyXlu.p); + + Graph_CloseDisps(dispRefs, globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 222); +} diff --git a/src/code/z_effect.c b/src/code/z_effect.c index dfe367d13..a1077c13a 100644 --- a/src/code/z_effect.c +++ b/src/code/z_effect.c @@ -1,26 +1,264 @@ #include <ultra64.h> #include <global.h> -GlobalContext* func_80026B00(void) { - return D_80157DA0; +EffectContext sEffectContext; + +EffectInfo sEffectInfoTable[] = { + { + sizeof(EffectSpark), + EffectSpark_Init, + EffectSpark_Destroy, + EffectSpark_Update, + EffectSpark_Draw, + }, + { + sizeof(EffectBlure), + EffectBlure_Init1, + EffectBlure_Destroy, + EffectBlure_Update, + EffectBlure_Draw, + }, + { + sizeof(EffectBlure), + EffectBlure_Init2, + EffectBlure_Destroy, + EffectBlure_Update, + EffectBlure_Draw, + }, + { + sizeof(EffectShieldParticle), + EffectShieldParticle_Init, + EffectShieldParticle_Destroy, + EffectShieldParticle_Update, + EffectShieldParticle_Draw, + }, +}; + +GlobalContext* Effect_GetGlobalCtx(void) { + return sEffectContext.globalCtx; +} + +void* Effect_GetByIndex(s32 index) { + if (index == TOTAL_EFFECT_COUNT) { + return NULL; + } + + if (index < SPARK_COUNT) { + if (sEffectContext.sparks[index].status.active == true) { + return &sEffectContext.sparks[index].effect; + } else { + return NULL; + } + } + + index -= SPARK_COUNT; + if (index < BLURE_COUNT) { + if (sEffectContext.blures[index].status.active == true) { + return &sEffectContext.blures[index].effect; + } else { + return NULL; + } + } + + index -= BLURE_COUNT; + if (index < SHIELD_PARTICLE_COUNT) { + if (sEffectContext.shieldParticles[index].status.active == true) { + return &sEffectContext.shieldParticles[index].effect; + } else { + return NULL; + } + } + + return NULL; +} + +void Effect_InitStatus(EffectStatus* status) { + status->active = false; + status->unk_01 = 0; + status->unk_02 = 0; +} + +void Effect_InitContext(GlobalContext* globalCtx) { + s32 i; + + for (i = 0; i < SPARK_COUNT; i++) { + Effect_InitStatus(&sEffectContext.sparks[i].status); + } + + for (i = 0; i < BLURE_COUNT; i++) { + Effect_InitStatus(&sEffectContext.blures[i].status); + } + + for (i = 0; i < SHIELD_PARTICLE_COUNT; i++) { + //! @bug This is supposed to initialize shieldParticles, not blures again + Effect_InitStatus(&sEffectContext.blures[i].status); + } + + sEffectContext.globalCtx = globalCtx; +} + +void Effect_Add(GlobalContext* globalCtx, s32* pIndex, s32 type, u8 arg3, u8 arg4, void* initParams) { + s32 i; + u32 slotFound; + void* effect; + EffectStatus* status; + + effect = NULL; + status = NULL; + *pIndex = TOTAL_EFFECT_COUNT; + + if (func_800C0D28(globalCtx) != 1) { + slotFound = false; + switch (type) { + case EFFECT_SPARK: + for (i = 0; i < SPARK_COUNT; i++) { + if (sEffectContext.sparks[i].status.active == false) { + slotFound = true; + *pIndex = i; + effect = &sEffectContext.sparks[i].effect; + status = &sEffectContext.sparks[i].status; + break; + } + } + break; + case EFFECT_BLURE1: + case EFFECT_BLURE2: + for (i = 0; i < BLURE_COUNT; i++) { + if (sEffectContext.blures[i].status.active == false) { + slotFound = true; + *pIndex = i + SPARK_COUNT; + effect = &sEffectContext.blures[i].effect; + status = &sEffectContext.blures[i].status; + break; + } + } + break; + case EFFECT_SHIELD_PARTICLE: + for (i = 0; i < SHIELD_PARTICLE_COUNT; i++) { + if (sEffectContext.shieldParticles[i].status.active == false) { + slotFound = true; + *pIndex = i + SPARK_COUNT + BLURE_COUNT; + effect = &sEffectContext.shieldParticles[i].effect; + status = &sEffectContext.shieldParticles[i].status; + break; + } + } + break; + } + + if (!slotFound) { + // Translates to: "EffectAdd(): I cannot secure it. Be careful. Type %d" + osSyncPrintf("EffectAdd():確保できません。注意してください。Type%d\n", type); + // Translates to: "Exit without adding the effect." + osSyncPrintf("エフェクト追加せずに終了します。\n"); + } else { + sEffectInfoTable[type].init(effect, initParams); + status->unk_02 = arg3; + status->unk_01 = arg4; + status->active = true; + } + } } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_80026B0C.s") +void Effect_DrawAll(GraphicsContext* gfxCtx) { + s32 i; + + for (i = 0; i < SPARK_COUNT; i++) { + if (sEffectContext.sparks[i].status.active) { + sEffectInfoTable[EFFECT_SPARK].draw(&sEffectContext.sparks[i].effect, gfxCtx); + } + } -void func_80026C1C(u8* arg0) { - arg0[0] = 0; - arg0[1] = 0; - arg0[2] = 0; + for (i = 0; i < BLURE_COUNT; i++) { + do { + if (1) {} // Necessary to match + if (sEffectContext.blures[i].status.active) { + sEffectInfoTable[EFFECT_BLURE1].draw(&sEffectContext.blures[i].effect, gfxCtx); + } + } while (0); // Necessary to match + } + + for (i = 0; i < SHIELD_PARTICLE_COUNT; i++) { + if (sEffectContext.shieldParticles[i].status.active) { + if (gfxCtx) {} // Necessary to match + sEffectInfoTable[EFFECT_SHIELD_PARTICLE].draw(&sEffectContext.shieldParticles[i].effect, gfxCtx); + } + } } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_80026C2C.s") +void Effect_UpdateAll(GlobalContext* globalCtx) { + s32 i; + + for (i = 0; i < SPARK_COUNT; i++) { + if (sEffectContext.sparks[i].status.active) { + if (sEffectInfoTable[EFFECT_SPARK].update(&sEffectContext.sparks[i].effect) == 1) { + Effect_Delete(globalCtx, i); + } + } + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/Effect_Add.s") + for (i = 0; i < BLURE_COUNT; i++) { + if (sEffectContext.blures[i].status.active) { + if (sEffectInfoTable[EFFECT_BLURE1].update(&sEffectContext.blures[i].effect) == 1) { + Effect_Delete(globalCtx, i + SPARK_COUNT); + } + } + } + + for (i = 0; i < SHIELD_PARTICLE_COUNT; i++) { + if (sEffectContext.shieldParticles[i].status.active) { + if (sEffectInfoTable[EFFECT_SHIELD_PARTICLE].update(&sEffectContext.shieldParticles[i].effect) == 1) { + Effect_Delete(globalCtx, i + SPARK_COUNT + BLURE_COUNT); + } + } + } +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_80026E74.s") +void Effect_Delete(GlobalContext* globalCtx, s32 index) { + if (index == TOTAL_EFFECT_COUNT) { + return; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_80026F70.s") + if (index < SPARK_COUNT) { + sEffectContext.sparks[index].status.active = false; + sEffectInfoTable[EFFECT_SPARK].destroy(&sEffectContext.sparks[index].effect); + return; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_8002709C.s") + index -= SPARK_COUNT; + if (index < BLURE_COUNT) { + sEffectContext.blures[index].status.active = false; + sEffectInfoTable[EFFECT_BLURE1].destroy(&sEffectContext.blures[index].effect); + return; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_800271A8.s") + index -= BLURE_COUNT; + if (index < SHIELD_PARTICLE_COUNT) { + sEffectContext.shieldParticles[index].status.active = false; + sEffectInfoTable[EFFECT_SHIELD_PARTICLE].destroy(&sEffectContext.shieldParticles[index].effect); + return; + } +} + +void Effect_DeleteAll(GlobalContext* globalCtx) { + s32 i; + + osSyncPrintf("エフェクト総て解放\n"); // "All effect release" + + for (i = 0; i < SPARK_COUNT; i++) { + sEffectContext.sparks[i].status.active = false; + sEffectInfoTable[EFFECT_SPARK].destroy(&sEffectContext.sparks[i].effect); + } + + for (i = 0; i < BLURE_COUNT; i++) { + sEffectContext.blures[i].status.active = false; + sEffectInfoTable[EFFECT_BLURE1].destroy(&sEffectContext.blures[i].effect); + } + + for (i = 0; i < SHIELD_PARTICLE_COUNT; i++) { + sEffectContext.shieldParticles[i].status.active = false; + sEffectInfoTable[EFFECT_SHIELD_PARTICLE].destroy(&sEffectContext.shieldParticles[i].effect); + } + + osSyncPrintf("エフェクト総て解放 終了\n"); // "All effects release End" +} diff --git a/src/code/z_effect_soft_sprite.c b/src/code/z_effect_soft_sprite.c index c5c9a7864..bc9afa476 100644 --- a/src/code/z_effect_soft_sprite.c +++ b/src/code/z_effect_soft_sprite.c @@ -1,139 +1,343 @@ #include <ultra64.h> #include <global.h> +#include <vt.h> -extern ParticleOverlay sParticleOverlayTable[37]; +EffectSsInfo sEffectSsInfo = { 0 }; // "EffectSS2Info" -void Effect_SS_Delete(LoadedParticleEntry* particle); +void EffectSs_InitInfo(GlobalContext* globalCtx, s32 tableSize) { + u32 i; + EffectSs* effectSs; + EffectSsOverlay* overlay; + + for (i = 0; i < ARRAY_COUNT(gEffectSsOverlayTable); i++) { + overlay = &gEffectSsOverlayTable[i]; + osSyncPrintf("effect index %3d:size=%6dbyte romsize=%6dbyte\n", i, + (u32)overlay->vramEnd - (u32)overlay->vramStart, overlay->vromEnd - overlay->vromStart); + } + + sEffectSsInfo.table = + GameState_AllocEnd(&globalCtx->state, tableSize * sizeof(EffectSs), "../z_effect_soft_sprite.c", 289); + if (sEffectSsInfo.table == NULL) { + __assert("EffectSS2Info.data_table != NULL", "../z_effect_soft_sprite.c", 290); + } + + sEffectSsInfo.searchStartIndex = 0; + sEffectSsInfo.tableSize = tableSize; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_800272B0.s") + for (effectSs = &sEffectSsInfo.table[0]; effectSs < &sEffectSsInfo.table[sEffectSsInfo.tableSize]; effectSs++) { + EffectSs_Reset(effectSs); + } -void Effect_SS_Clear(GlobalContext* globalCtx) { + overlay = &gEffectSsOverlayTable[0]; + for (i = 0; i < ARRAY_COUNT(gEffectSsOverlayTable); i++) { + overlay->loadedRamAddr = NULL; + overlay++; + } +} + +void EffectSs_ClearAll(GlobalContext* globalCtx) { u32 i; - LoadedParticleEntry* iter; - ParticleOverlay* iter2; + EffectSs* effectSs; + EffectSsOverlay* overlay; void* addr; - EffectSS2Info.data_table = NULL; - EffectSS2Info.searchIndex = 0; - EffectSS2Info.size = 0; + sEffectSsInfo.table = NULL; + sEffectSsInfo.searchStartIndex = 0; + sEffectSsInfo.tableSize = 0; - for (iter = EffectSS2Info.data_table; iter < EffectSS2Info.data_table + EffectSS2Info.size; iter++) { - Effect_SS_Delete(iter); + // This code doesn't actually work, since table was just set to NULL and tableSize to 0 + for (effectSs = &sEffectSsInfo.table[0]; effectSs < &sEffectSsInfo.table[sEffectSsInfo.tableSize]; effectSs++) { + EffectSs_Delete(effectSs); } - // Free memory from loaded particle overlays - iter2 = &sParticleOverlayTable[0]; - for (i = 0; i < ARRAY_COUNT(sParticleOverlayTable); i++) { - addr = iter2->loadedRamAddr; + overlay = &gEffectSsOverlayTable[0]; + for (i = 0; i < ARRAY_COUNT(gEffectSsOverlayTable); i++) { + addr = overlay->loadedRamAddr; if (addr != NULL) { - ZeldaArena_FreeDebug(addr, D_801357DC, 337); + ZeldaArena_FreeDebug(addr, "../z_effect_soft_sprite.c", 337); } - (iter2++)->loadedRamAddr = NULL; + overlay->loadedRamAddr = NULL; + overlay++; } } -void Effect_SS_Delete(LoadedParticleEntry* particle) { - if (particle->flags & 2) { - func_800F89E8(&particle->position); +void EffectSs_Delete(EffectSs* effectSs) { + if (effectSs->flags & 2) { + func_800F89E8(&effectSs->pos); } - if (particle->flags & 4) { - func_800F89E8(&particle->unk_2C); + if (effectSs->flags & 4) { + func_800F89E8(&effectSs->unk_2C); } - Effect_SS_ResetEntry(particle); + EffectSs_Reset(effectSs); } -void Effect_SS_ResetEntry(LoadedParticleEntry* particle) { +void EffectSs_Reset(EffectSs* effectSs) { u32 i; - particle->type = 0x25; - particle->acceleration.z = 0; - particle->acceleration.y = 0; - particle->acceleration.x = 0; - particle->velocity.z = 0; - particle->velocity.y = 0; - particle->velocity.x = 0; - particle->unk_34 = 0; - particle->unk_30 = 0; - particle->unk_2C = 0; - particle->position.z = 0; - particle->position.y = 0; - particle->position.x = 0; - particle->life = -1; - particle->flags = 0; - particle->priority = 128; - particle->draw = NULL; - particle->update = NULL; - particle->unk_38 = 0; - particle->unk_3C = 0; - - for (i = 0; i != 13; i++) { - particle->unk_40[i] = 0; + effectSs->type = EFFECT_SS_TYPE_MAX; + effectSs->accel.x = effectSs->accel.y = effectSs->accel.z = 0; + effectSs->velocity.x = effectSs->velocity.y = effectSs->velocity.z = 0; + effectSs->unk_2C.x = effectSs->unk_2C.y = effectSs->unk_2C.z = 0; + effectSs->pos.x = effectSs->pos.y = effectSs->pos.z = 0; + effectSs->life = -1; + effectSs->flags = 0; + effectSs->priority = 128; + effectSs->draw = NULL; + effectSs->update = NULL; + effectSs->unk_38 = 0; + effectSs->unk_3C = 0; + + for (i = 0; i < ARRAY_COUNT(effectSs->regs); i++) { + effectSs->regs[i] = 0; + } +} + +s32 EffectSs_FindSlot(s32 priority, s32* pIndex) { + s32 foundFree; + s32 i; + + if (sEffectSsInfo.searchStartIndex >= sEffectSsInfo.tableSize) { + sEffectSsInfo.searchStartIndex = 0; + } + + // Search for a free slot + i = sEffectSsInfo.searchStartIndex; + foundFree = false; + while (true) { + if (sEffectSsInfo.table[i].life == -1) { + foundFree = true; + break; + } + + i++; + + if (i >= sEffectSsInfo.tableSize) { + i = 0; // Loop around the whole table + } + + // After a full loop, break out + if (i == sEffectSsInfo.searchStartIndex) { + break; + } + } + + if (foundFree == true) { + *pIndex = i; + return 0; + } + + // If all slots are in use, search for a slot with a lower priority + // Note that a lower priority is representend by a higher value + i = sEffectSsInfo.searchStartIndex; + while (true) { + // Equal priority should only be considered "lower" if flag 0 is set + if ((priority <= sEffectSsInfo.table[i].priority) && + !((priority == sEffectSsInfo.table[i].priority) && (sEffectSsInfo.table[i].flags & 1))) { + break; + } + + i++; + + if (i >= sEffectSsInfo.tableSize) { + i = 0; // Loop around the whole table + } + + // After a full loop, return 1 to indicate that we failed to find a suitable slot + if (i == sEffectSsInfo.searchStartIndex) { + return 1; + } } + + *pIndex = i; + return 0; } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_800275D0.s") +void EffectSs_Insert(GlobalContext* globalCtx, EffectSs* effectSs) { + s32 index; + + if (func_800C0D28(globalCtx) != 1) { + if (EffectSs_FindSlot(effectSs->priority, &index) == 0) { + sEffectSsInfo.searchStartIndex = index + 1; + sEffectSsInfo.table[index] = *effectSs; + } + } +} + +// original name: "EffectSoftSprite2_makeEffect" +void EffectSs_Spawn(GlobalContext* globalCtx, s32 type, s32 priority, void* initParams) { + s32 index; + u32 overlaySize; + EffectSsOverlay* overlayEntry; + EffectSsInit* initInfo; + + overlayEntry = &gEffectSsOverlayTable[type]; + + if (type >= EFFECT_SS_TYPE_MAX) { + __assert("type < EFFECT_SS2_TYPE_LAST_LABEL", "../z_effect_soft_sprite.c", 556); + } + + if (EffectSs_FindSlot(priority, &index) != 0) { + // Abort because we couldn't find a suitable slot to add this effect in + return; + } + + sEffectSsInfo.searchStartIndex = index + 1; + overlaySize = (u32)overlayEntry->vramEnd - (u32)overlayEntry->vramStart; + + if (overlayEntry->vramStart == NULL) { + // Translates to: "Not an overlay" + osSyncPrintf("EffectSoftSprite2_makeEffect():オーバーレイではありません。\n"); + initInfo = overlayEntry->initInfo; + } else { + if (overlayEntry->loadedRamAddr == NULL) { + overlayEntry->loadedRamAddr = ZeldaArena_MallocRDebug(overlaySize, "../z_effect_soft_sprite.c", 585); + + if (overlayEntry->loadedRamAddr == NULL) { + osSyncPrintf(VT_FGCOL(RED)); + // Translates to: "The memory of %d byte cannot be secured. Therefore, the program cannot be loaded. + // What a dangerous situation! Naturally, effects will not produced either." + osSyncPrintf("EffectSoftSprite2_makeEffect():zelda_malloc_r()により,%" + "dbyteのメモリ確保ができま\nせん。そのため、プログラムのロードも\n出来ません。ただいま危険" + "な状態です!\nもちろん,エフェクトも出ません。\n", + overlaySize); + osSyncPrintf(VT_RST); + return; + } + + Overlay_Load(overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart, overlayEntry->vramEnd, + overlayEntry->loadedRamAddr); + + osSyncPrintf(VT_FGCOL(GREEN)); + osSyncPrintf("EFFECT SS OVL:SegRom %08x %08x, Seg %08x %08x, RamStart %08x, type: %d\n", + overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart, overlayEntry->vramEnd, + overlayEntry->loadedRamAddr, type); + osSyncPrintf(VT_RST); + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_80027704.s") + initInfo = (void*)(u32)((overlayEntry->initInfo != NULL) + ? (void*)((u32)overlayEntry->initInfo - + (s32)((u32)overlayEntry->vramStart - (u32)overlayEntry->loadedRamAddr)) + : NULL); + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_80027798.s") + if (initInfo->init == NULL) { + // Translates to: "Effects have already been loaded, but the constructor is NULL so the addition will not occur. + // Please fix this. (Waste of memory) %08x %d" + osSyncPrintf("EffectSoftSprite2_makeEffect():すでにエフェクトはロード済みで\nすが," + "コンストラクターがNULLなので追加をやめます。\n直してください。(メモリーの無駄) %08x %d\n", + initInfo, type); + return; + } -void Effect_SS_UpdateParticle(GlobalContext* globalCtx, s32 index) { - LoadedParticleEntry* particle = &EffectSS2Info.data_table[index]; + // Delete the previous effect in the slot, in case the slot wasn't free + EffectSs_Delete(&sEffectSsInfo.table[index]); + + sEffectSsInfo.table[index].type = type; + sEffectSsInfo.table[index].priority = priority; + + if (initInfo->init(globalCtx, index, &sEffectSsInfo.table[index], initParams) == 0) { + osSyncPrintf(VT_FGCOL(GREEN)); + // Translates to: "Construction failed for some reason. The constructor returned an error. + // Ceasing effect addition." + osSyncPrintf("EffectSoftSprite2_makeEffect():" + "何らかの理由でコンストラクト失敗。コンストラクターがエラーを返しました。エフェクトの追加を中" + "止します。\n"); + osSyncPrintf(VT_RST); + EffectSs_Reset(&sEffectSsInfo.table[index]); + } +} - if (particle->update != NULL) { - particle->velocity.x += particle->acceleration.x; - particle->velocity.y += particle->acceleration.y; - particle->velocity.z += particle->acceleration.z; +void EffectSs_Update(GlobalContext* globalCtx, s32 index) { + EffectSs* effectSs = &sEffectSsInfo.table[index]; - particle->position.x += particle->velocity.x; - particle->position.y += particle->velocity.y; - particle->position.z += particle->velocity.z; + if (effectSs->update != NULL) { + effectSs->velocity.x += effectSs->accel.x; + effectSs->velocity.y += effectSs->accel.y; + effectSs->velocity.z += effectSs->accel.z; - particle->update(globalCtx, index, particle); + effectSs->pos.x += effectSs->velocity.x; + effectSs->pos.y += effectSs->velocity.y; + effectSs->pos.z += effectSs->velocity.z; + + effectSs->update(globalCtx, index, effectSs); } } -void Effect_SS_UpdateAllParticles(GlobalContext* globalCtx) { +void EffectSs_UpdateAll(GlobalContext* globalCtx) { s32 i; - for (i = 0; i < EffectSS2Info.size; i++) { - if (EffectSS2Info.data_table[i].life > -1) { - EffectSS2Info.data_table[i].life--; + for (i = 0; i < sEffectSsInfo.tableSize; i++) { + if (sEffectSsInfo.table[i].life > -1) { + sEffectSsInfo.table[i].life--; - if (EffectSS2Info.data_table[i].life < 0) { - Effect_SS_Delete(&EffectSS2Info.data_table[i]); + if (sEffectSsInfo.table[i].life < 0) { + EffectSs_Delete(&sEffectSsInfo.table[i]); } } - if (EffectSS2Info.data_table[i].life > -1) { - Effect_SS_UpdateParticle(globalCtx, i); + if (sEffectSsInfo.table[i].life > -1) { + EffectSs_Update(globalCtx, i); } } } -void Effect_SS_DrawParticle(GlobalContext* globalCtx, s32 index) { - LoadedParticleEntry* particle = &EffectSS2Info.data_table[index]; +void EffectSs_Draw(GlobalContext* globalCtx, s32 index) { + EffectSs* effectSs = &sEffectSsInfo.table[index]; - if (particle->draw != NULL) { - particle->draw(globalCtx, index, particle); + if (effectSs->draw != NULL) { + effectSs->draw(globalCtx, index, effectSs); } } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_80027BDC.s") +// original name: "EffectSoftSprite2_disp" +void EffectSs_DrawAll(GlobalContext* globalCtx) { + LightMapper* lightMapper; + s32 i; + + lightMapper = Lights_CreateMapper(&globalCtx->lightCtx, globalCtx->state.gfxCtx); + func_8007A474(lightMapper, globalCtx->lightCtx.lightsHead, 0); + func_80079EFC(lightMapper, globalCtx->state.gfxCtx); + + for (i = 0; i < sEffectSsInfo.tableSize; i++) { + if (sEffectSsInfo.table[i].life > -1) { + if ((sEffectSsInfo.table[i].pos.x > 32000.0f) || (sEffectSsInfo.table[i].pos.x < -32000.0f) || + (sEffectSsInfo.table[i].pos.y > 32000.0f) || (sEffectSsInfo.table[i].pos.y < -32000.0f) || + (sEffectSsInfo.table[i].pos.z > 32000.0f) || (sEffectSsInfo.table[i].pos.z < -32000.0f)) { + osSyncPrintf(VT_FGCOL(RED)); + // Translates to: "Since the position is outside the area, delete it. + // Effect label No. %d: Please respond by the program. + // Here is ==> pos (%f, %f, %f) and the label is in z_effect_soft_sprite_dlftbls.decl." + osSyncPrintf("EffectSoftSprite2_disp():位置が領域外のため " + "削除します。エフェクトラベルNo.%d:プログラムの方で対応をお願いします。ここです ==> " + "pos(%f, %f, %f)で、ラベルはz_effect_soft_sprite_dlftbls.declにあります。\n", + sEffectSsInfo.table[i].type, sEffectSsInfo.table[i].pos.x, sEffectSsInfo.table[i].pos.y, + sEffectSsInfo.table[i].pos.z); + osSyncPrintf(VT_FGCOL(GREEN)); + // Translates to: "If you are using pos for something else, consult me." + osSyncPrintf("もし、posを別のことに使っている場合相談に応じます。\n"); + osSyncPrintf(VT_RST); + + EffectSs_Delete(&sEffectSsInfo.table[i]); + } else { + EffectSs_Draw(globalCtx, i); + } + } + } +} s16 func_80027DD4(s16 arg0, s16 arg1, s32 arg2) { - s16 ret = !arg2 ? arg1 : (arg0 + (s32)((f32)(arg1 - arg0) / arg2)); + s16 ret = (arg2 == 0) ? arg1 : (arg0 + (s32)((arg1 - arg0) / (f32)arg2)); return ret; } -s16 func_80027E34(s16 a0, s16 a1, f32 a2) { - return (a1 - a0) * a2 + a0; +s16 func_80027E34(s16 arg0, s16 arg1, f32 arg2) { + return (arg1 - arg0) * arg2 + arg0; } -u8 func_80027E84(u8 a0, u8 a1, f32 a2) { - return a2 * ((f32)a1 - (f32)a0) + a0; +u8 func_80027E84(u8 arg0, u8 arg1, f32 arg2) { + return arg2 * ((f32)arg1 - (f32)arg0) + arg0; } diff --git a/src/code/z_effect_soft_sprite_dlftbls.c b/src/code/z_effect_soft_sprite_dlftbls.c new file mode 100644 index 000000000..8ecba2e1b --- /dev/null +++ b/src/code/z_effect_soft_sprite_dlftbls.c @@ -0,0 +1,55 @@ +#include <ultra64.h> +#include <global.h> +#include <initvars.h> + +#define EFFECT_SS_OVERLAY(name) \ + { \ + (u32) _ovl_##name##SegmentRomStart, (u32)_ovl_##name##SegmentRomEnd, _ovl_##name##SegmentStart, \ + _ovl_##name##SegmentEnd, NULL, &name##_InitVars, 1, \ + } + +#define EFFECT_SS_OVERLAY_INTERNAL(name) \ + { 0, 0, NULL, NULL, NULL, &name##_InitVars, 1 } + +#define EFFECT_SS_OVERLAY_UNSET \ + { 0 } + +EffectSsOverlay gEffectSsOverlayTable[] = { + EFFECT_SS_OVERLAY(Effect_Ss_Dust), + EFFECT_SS_OVERLAY(Effect_Ss_KiraKira), + EFFECT_SS_OVERLAY(Effect_Ss_Bomb), + EFFECT_SS_OVERLAY(Effect_Ss_Bomb2), + EFFECT_SS_OVERLAY(Effect_Ss_Blast), + EFFECT_SS_OVERLAY(Effect_Ss_G_Spk), + EFFECT_SS_OVERLAY(Effect_Ss_D_Fire), + EFFECT_SS_OVERLAY(Effect_Ss_Bubble), + EFFECT_SS_OVERLAY_UNSET, + EFFECT_SS_OVERLAY(Effect_Ss_G_Ripple), + EFFECT_SS_OVERLAY(Effect_Ss_G_Splash), + EFFECT_SS_OVERLAY(Effect_Ss_G_Magma), + EFFECT_SS_OVERLAY(Effect_Ss_G_Fire), + EFFECT_SS_OVERLAY(Effect_Ss_Lightning), + EFFECT_SS_OVERLAY(Effect_Ss_Dt_Bubble), + EFFECT_SS_OVERLAY(Effect_Ss_Hahen), + EFFECT_SS_OVERLAY(Effect_Ss_Stick), + EFFECT_SS_OVERLAY(Effect_Ss_Sibuki), + EFFECT_SS_OVERLAY(Effect_Ss_Sibuki2), + EFFECT_SS_OVERLAY(Effect_Ss_G_Magma2), + EFFECT_SS_OVERLAY(Effect_Ss_Stone1), + EFFECT_SS_OVERLAY(Effect_Ss_HitMark), + EFFECT_SS_OVERLAY(Effect_Ss_Fhg_Flash), + EFFECT_SS_OVERLAY(Effect_Ss_K_Fire), + EFFECT_SS_OVERLAY(Effect_Ss_Solder_Srch_Ball), + EFFECT_SS_OVERLAY(Effect_Ss_Kakera), + EFFECT_SS_OVERLAY(Effect_Ss_Ice_Piece), + EFFECT_SS_OVERLAY(Effect_Ss_En_Ice), + EFFECT_SS_OVERLAY(Effect_Ss_Fire_Tail), + EFFECT_SS_OVERLAY(Effect_Ss_En_Fire), + EFFECT_SS_OVERLAY(Effect_Ss_Extra), + EFFECT_SS_OVERLAY(Effect_Ss_Fcircle), + EFFECT_SS_OVERLAY(Effect_Ss_Dead_Db), + EFFECT_SS_OVERLAY(Effect_Ss_Dead_Dd), + EFFECT_SS_OVERLAY(Effect_Ss_Dead_Ds), + EFFECT_SS_OVERLAY(Effect_Ss_Dead_Sound), + EFFECT_SS_OVERLAY(Effect_Ss_Ice_Smoke), +}; diff --git a/src/code/z_effect_soft_sprite_old_init.c b/src/code/z_effect_soft_sprite_old_init.c index 847e25e2f..ee5559039 100644 --- a/src/code/z_effect_soft_sprite_old_init.c +++ b/src/code/z_effect_soft_sprite_old_init.c @@ -1,8 +1,11 @@ #include <ultra64.h> #include <global.h> +// Draw utility for some G effects #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80027F80.s") +// EffectSsDust Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_800281E8.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002829C.s") @@ -41,6 +44,8 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80028A54.s") +// EffectSsKiraKira Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80028B18.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80028B74.s") @@ -49,12 +54,18 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80028CEC.s") +// EffectSsBomb Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80028DC4.s") +// EffectSsBomb2 Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80028E1C.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80028E84.s") +// EffectSsBlast Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80028EF4.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80028F84.s") @@ -63,6 +74,8 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029024.s") +// EffectSsGSpk Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029060.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_800290F0.s") @@ -73,94 +86,154 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_800292DC.s") +// EffectSsDFire Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029320.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_800293A0.s") +// EffectSsBubble Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_800293E4.s") +// EffectSsGRipple Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029444.s") +// EffectSsGSplash Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002949C.s") +// EffectSsGMagma Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029530.s") +// EffectSsGFire Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029568.s") +// EffectSsLightning Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_800295A0.s") +// EffectSsDtBubble Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029618.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029694.s") +// EffectSsHahen Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029724.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_800297A4.s") +// EffectSsStick Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_800298EC.s") +// EffectSsSibuki Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002993C.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_800299AC.s") +// EffectSsSibuki2 Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029B30.s") +// EffectSsGMagma2 Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029B90.s") +// EffectSsStone1 Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029C00.s") +// EffectSsHitMark Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029C50.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029CA4.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029CC8.s") +// EffectSsFhgFlash Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029CF0.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029D5C.s") +// EffectSsKFire Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029DBC.s") +// EffectSsSolderSrchBall Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029E24.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/Effect_SpawnFragment.s") +// EffectSsKakera Spawn Functions + +#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029E8C.s") + +// EffectSsIcePiece Spawn Functions #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029F44.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_80029FAC.s") +// EffectSsEnIce Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A140.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A1DC.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A2A4.s") +// EffectSsFireTail Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A32C.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A3C4.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A484.s") +// EffectSsEnFire Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A4D4.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A54C.s") +// EffectSsExtra Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A5F4.s") +// EffectSsFCircle Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A65C.s") +// EffectSsDeadBb Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A6B8.s") +// EffectSsDeadDd Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A770.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A824.s") +// EffectSsDeadDs Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A894.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A90C.s") +// EffectSsDeadSound Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A95C.s") #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002A9F4.s") +// EffectSsIceSmoke Spawn Functions + #pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite_old_init/func_8002AA44.s") diff --git a/src/code/z_lights.c b/src/code/z_lights.c index 46e61fa25..1bca397c5 100644 --- a/src/code/z_lights.c +++ b/src/code/z_lights.c @@ -151,7 +151,7 @@ void Lights_RemoveAll(GlobalContext* globalCtx, LightingContext* lightCtx) { } } -z_Light* Lights_Insert(GlobalContext* globalCtx, LightingContext* lightCtx, LightInfo* info) { +z_Light* Lights_Insert(GlobalContext* globalCtx, LightingContext* lightCtx, void* info) { z_Light* light; light = Lights_FindFreeSlot(); diff --git a/src/code/z_play.c b/src/code/z_play.c index 1ee3e00b4..c99b2cd30 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -157,8 +157,8 @@ void Gameplay_Destroy(GlobalContext* globalCtx) { R_PAUSE_MENU_MODE = 0; func_800C0F08(&globalCtx->preRenderCtx); - func_800271A8(globalCtx); - Effect_SS_Clear(globalCtx); + Effect_DeleteAll(globalCtx); + EffectSs_ClearAll(globalCtx); CollisionCheck_DestroyContext(globalCtx, &globalCtx->colChkCtx); if (gTrnsnUnkState == 3) { @@ -240,8 +240,8 @@ void Gameplay_Init(GlobalContext* globalCtx) { func_80110F68(globalCtx); func_80110450(globalCtx); func_8006BA00(globalCtx); - func_80026C2C(globalCtx); - func_800272B0(globalCtx, 0x55); + Effect_InitContext(globalCtx); + EffectSs_InitInfo(globalCtx, 0x55); func_8005D3BC(globalCtx, &globalCtx->colChkCtx); SkelAnime_AnimationCtxReset(&globalCtx->animationCtx); func_8006450C(globalCtx, &globalCtx->csCtx); @@ -891,13 +891,13 @@ void Gameplay_Update(GlobalContext* globalCtx) { LOG_NUM("1", 1, "../z_play.c", 3651); } - func_80026F70(globalCtx); + Effect_UpdateAll(globalCtx); if (1 && HREG(63)) { LOG_NUM("1", 1, "../z_play.c", 3657); } - Effect_SS_UpdateAllParticles(globalCtx); + EffectSs_UpdateAll(globalCtx); if (1 && HREG(63)) { LOG_NUM("1", 1, "../z_play.c", 3662); |
