summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorpetrie911 <69443847+petrie911@users.noreply.github.com>2021-09-20 11:51:35 -0500
committerGitHub <noreply@github.com>2021-09-20 12:51:35 -0400
commite51f50f0ff9d79cd4c19fb6519183fd00445719c (patch)
tree2151497dd9464253f6f12f069256790e7eb5c37a /src/code
parent50095d427c21465b7560d7178906a3dee3eea090 (diff)
Decompile z_kankyo (#956)
* working * start color switch * progress * progress * progress on bgm func * progress * game over matched (except the rodata meme) * start update * progress * lightning docs done * progress * progress * progress * progress * progress * can compile at least * suns state, progress on kankyo_update * some new names * progress * progress * progress * new functions * cleanup * more matches * another match * now functional * format * better match * hugely improved update * cleanup/review * remove old changes * review2 * review3 * missed one * review4 * change asm filenames * update doorwarp1 * review5 * Kankyo_ -> Environment_ * format * merge master and format functions.h Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com> Co-authored-by: fig <fig02srl@gmail.com> Co-authored-by: petrie911 <pmontag@DESKTOP-LG8A167.localdomain>
Diffstat (limited to 'src/code')
-rw-r--r--src/code/z_actor.c24
-rw-r--r--src/code/z_camera.c22
-rw-r--r--src/code/z_common_data.c2
-rw-r--r--src/code/z_construct.c2
-rw-r--r--src/code/z_demo.c106
-rw-r--r--src/code/z_eff_ss_dead.c4
-rw-r--r--src/code/z_en_item00.c2
-rw-r--r--src/code/z_frame_advance.c2
-rw-r--r--src/code/z_game_over.c8
-rw-r--r--src/code/z_kankyo.c2491
-rw-r--r--src/code/z_lights.c22
-rw-r--r--src/code/z_map_exp.c6
-rw-r--r--src/code/z_parameter.c30
-rw-r--r--src/code/z_play.c153
-rw-r--r--src/code/z_rcp.c37
-rw-r--r--src/code/z_room.c2
-rw-r--r--src/code/z_scene.c71
-rw-r--r--src/code/z_scene_table.c8
-rw-r--r--src/code/z_sram.c16
-rw-r--r--src/code/z_vr_box.c66
-rw-r--r--src/code/z_vr_box_draw.c4
21 files changed, 2734 insertions, 344 deletions
diff --git a/src/code/z_actor.c b/src/code/z_actor.c
index 87686f852..83ccc2dd2 100644
--- a/src/code/z_actor.c
+++ b/src/code/z_actor.c
@@ -1355,9 +1355,9 @@ void func_8002EBCC(Actor* actor, GlobalContext* globalCtx, s32 flag) {
Gfx* displayListHead;
Gfx* displayList;
- lightDir.x = globalCtx->envCtx.unk_2A;
- lightDir.y = globalCtx->envCtx.unk_2B;
- lightDir.z = globalCtx->envCtx.unk_2C;
+ lightDir.x = globalCtx->envCtx.dirLight1.params.dir.x;
+ lightDir.y = globalCtx->envCtx.dirLight1.params.dir.y;
+ lightDir.z = globalCtx->envCtx.dirLight1.params.dir.z;
if (HREG(80) == 6) {
osSyncPrintf("z_actor.c 3637 game_play->view.eye=[%f(%f) %f %f]\n", globalCtx->view.eye.x,
@@ -1386,9 +1386,9 @@ void func_8002ED80(Actor* actor, GlobalContext* globalCtx, s32 flag) {
Gfx* displayListHead;
Gfx* displayList;
- lightDir.x = globalCtx->envCtx.unk_2A;
- lightDir.y = globalCtx->envCtx.unk_2B;
- lightDir.z = globalCtx->envCtx.unk_2C;
+ lightDir.x = globalCtx->envCtx.dirLight1.params.dir.x;
+ lightDir.y = globalCtx->envCtx.dirLight1.params.dir.y;
+ lightDir.z = globalCtx->envCtx.dirLight1.params.dir.z;
hilite = func_8002EB44(&actor->world.pos, &globalCtx->view.eye, &lightDir, globalCtx->state.gfxCtx);
@@ -3568,9 +3568,9 @@ void Actor_SetColorFilter(Actor* actor, s16 colorFlag, s16 colorIntensityMax, s1
Hilite* func_800342EC(Vec3f* object, GlobalContext* globalCtx) {
Vec3f lightDir;
- lightDir.x = globalCtx->envCtx.unk_2A;
- lightDir.y = globalCtx->envCtx.unk_2B;
- lightDir.z = globalCtx->envCtx.unk_2C;
+ lightDir.x = globalCtx->envCtx.dirLight1.params.dir.x;
+ lightDir.y = globalCtx->envCtx.dirLight1.params.dir.y;
+ lightDir.z = globalCtx->envCtx.dirLight1.params.dir.z;
return func_8002EABC(object, &globalCtx->view.eye, &lightDir, globalCtx->state.gfxCtx);
}
@@ -3578,9 +3578,9 @@ Hilite* func_800342EC(Vec3f* object, GlobalContext* globalCtx) {
Hilite* func_8003435C(Vec3f* object, GlobalContext* globalCtx) {
Vec3f lightDir;
- lightDir.x = globalCtx->envCtx.unk_2A;
- lightDir.y = globalCtx->envCtx.unk_2B;
- lightDir.z = globalCtx->envCtx.unk_2C;
+ lightDir.x = globalCtx->envCtx.dirLight1.params.dir.x;
+ lightDir.y = globalCtx->envCtx.dirLight1.params.dir.y;
+ lightDir.z = globalCtx->envCtx.dirLight1.params.dir.z;
return func_8002EB44(object, &globalCtx->view.eye, &lightDir, globalCtx->state.gfxCtx);
}
diff --git a/src/code/z_camera.c b/src/code/z_camera.c
index 77197662e..ece32d45a 100644
--- a/src/code/z_camera.c
+++ b/src/code/z_camera.c
@@ -547,7 +547,7 @@ f32 Camera_GetWaterSurface(Camera* camera, Vec3f* chkPos, s32* envProp) {
if (waterY < chkPos->y) {
// the water's y position is below the check position
- // the aka the position is NOT in the water.
+ // meaning the position is NOT in the water.
return BGCHECK_Y_MIN;
}
@@ -1778,7 +1778,7 @@ s32 Camera_Normal2(Camera* camera) {
if (camera->status == CAM_STAT_ACTIVE) {
bgChk.pos = *eyeNext;
- if ((camera->globalCtx->envCtx.skyDisabled == 0) || norm2->interfaceFlags & 0x10) {
+ if (!camera->globalCtx->envCtx.skyboxDisabled || norm2->interfaceFlags & 0x10) {
Camera_BGCheckInfo(camera, at, &bgChk);
*eye = bgChk.pos;
} else {
@@ -2110,7 +2110,7 @@ s32 Camera_Parallel1(Camera* camera) {
Camera_Vec3fVecSphGeoAdd(eyeNext, at, &spA8);
if (camera->status == CAM_STAT_ACTIVE) {
sp6C.pos = *eyeNext;
- if (camera->globalCtx->envCtx.skyDisabled == 0 || para1->interfaceFlags & 0x10) {
+ if (!camera->globalCtx->envCtx.skyboxDisabled || para1->interfaceFlags & 0x10) {
Camera_BGCheckInfo(camera, at, &sp6C);
*eye = sp6C.pos;
} else {
@@ -2903,7 +2903,7 @@ s32 Camera_Battle1(Camera* camera) {
Camera_Vec3fVecSphGeoAdd(eyeNext, at, &spB4);
spBC.pos = *eyeNext;
if (camera->status == CAM_STAT_ACTIVE) {
- if (camera->globalCtx->envCtx.skyDisabled == 0 || batt1->flags & 1) {
+ if (!camera->globalCtx->envCtx.skyboxDisabled || batt1->flags & 1) {
Camera_BGCheckInfo(camera, at, &spBC);
} else if (batt1->flags & 2) {
func_80043F94(camera, at, &spBC);
@@ -3225,7 +3225,7 @@ s32 Camera_KeepOn1(Camera* camera) {
Camera_Vec3fVecSphGeoAdd(eyeNext, at, &spD8);
sp8C.pos = *eyeNext;
if (camera->status == CAM_STAT_ACTIVE) {
- if ((camera->globalCtx->envCtx.skyDisabled == 0) || keep1->interfaceFlags & 1) {
+ if (!camera->globalCtx->envCtx.skyboxDisabled || keep1->interfaceFlags & 1) {
Camera_BGCheckInfo(camera, at, &sp8C);
} else if (keep1->interfaceFlags & 2) {
func_80043F94(camera, at, &sp8C);
@@ -4205,7 +4205,7 @@ s32 Camera_Subj3(Camera* camera) {
*eye = *eyeNext;
anim->animTimer--;
- if (camera->globalCtx->envCtx.skyDisabled == 0) {
+ if (!camera->globalCtx->envCtx.skyboxDisabled) {
Camera_BGCheck(camera, at, eye);
} else {
func_80044340(camera, at, eye);
@@ -7047,7 +7047,7 @@ void Camera_PrintSettings(Camera* camera) {
s32 Camera_CheckWater(Camera* camera) {
f32 waterY;
s16 newQuakeId;
- s32 waterBoxProp;
+ s32 waterLightsIndex;
s32* waterPrevCamSetting = &camera->waterPrevCamSetting;
s16 waterCamIdx;
s16* quakeId = (s16*)&camera->waterQuakeId;
@@ -7115,12 +7115,12 @@ s32 Camera_CheckWater(Camera* camera) {
}
}
- if (waterY = Camera_GetWaterSurface(camera, &camera->eye, &waterBoxProp), waterY != BGCHECK_Y_MIN) {
+ if (waterY = Camera_GetWaterSurface(camera, &camera->eye, &waterLightsIndex), waterY != BGCHECK_Y_MIN) {
camera->waterYPos = waterY;
if (!(camera->unk_14C & 0x100)) {
camera->unk_14C |= 0x100;
osSyncPrintf("kankyo changed water, sound on\n");
- func_80070600(camera->globalCtx, waterBoxProp);
+ Environment_EnableUnderwaterLights(camera->globalCtx, waterLightsIndex);
camera->unk_150 = 0x50;
}
@@ -7152,7 +7152,7 @@ s32 Camera_CheckWater(Camera* camera) {
if (camera->unk_14C & 0x100) {
camera->unk_14C &= ~0x100;
osSyncPrintf("kankyo changed water off, sound off\n");
- func_800706A0(camera->globalCtx);
+ Environment_DisableUnderwaterLights(camera->globalCtx);
if (*quakeId != 0) {
Quake_RemoveFromIdx(*quakeId);
}
@@ -7567,7 +7567,7 @@ void Camera_Finish(Camera* camera) {
camera->childCamIdx = camera->parentCamIdx = SUBCAM_FREE;
camera->timer = -1;
- camera->globalCtx->envCtx.unk_E1 = 0;
+ camera->globalCtx->envCtx.fillScreen = false;
Gameplay_ClearCamera(camera->globalCtx, camera->thisIdx);
}
diff --git a/src/code/z_common_data.c b/src/code/z_common_data.c
index 4923e56f1..43611d9d0 100644
--- a/src/code/z_common_data.c
+++ b/src/code/z_common_data.c
@@ -15,7 +15,7 @@ void SaveContext_Init(void) {
gSaveContext.cutsceneTrigger = 0;
gSaveContext.chamberCutsceneNum = 0;
gSaveContext.nextDayTime = 0xFFFF;
- gSaveContext.environmentTime = 0;
+ gSaveContext.skyboxTime = 0;
gSaveContext.dogIsLost = true;
gSaveContext.nextTransition = 0xFF;
gSaveContext.unk_13EE = 50;
diff --git a/src/code/z_construct.c b/src/code/z_construct.c
index 1d14c7c62..fb2241d2f 100644
--- a/src/code/z_construct.c
+++ b/src/code/z_construct.c
@@ -10,7 +10,7 @@ void func_801109B0(GlobalContext* globalCtx) {
u16 doActionOffset;
u8 temp;
- gSaveContext.unk_1422 = 0;
+ gSaveContext.sunsSongState = SUNSSONG_INACTIVE;
gSaveContext.unk_13E8 = gSaveContext.unk_13EA = 0;
View_Init(&interfaceCtx->view, globalCtx->state.gfxCtx);
diff --git a/src/code/z_demo.c b/src/code/z_demo.c
index 09ada3443..8b750641f 100644
--- a/src/code/z_demo.c
+++ b/src/code/z_demo.c
@@ -170,7 +170,7 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase*
return;
}
- temp = func_8006F93C(cmd->endFrame - 1, cmd->startFrame, csCtx->frames);
+ temp = Environment_LerpWeight(cmd->endFrame - 1, cmd->startFrame, csCtx->frames);
if (csCtx->frames == cmd->startFrame) {
sp3F = 1;
@@ -187,9 +187,9 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase*
case 2:
if (sp3F != 0) {
func_800F6D58(0xF, 0, 0);
- func_800753C4(globalCtx, 3);
+ Environment_AddLightningBolts(globalCtx, 3);
if (1) {}
- D_8015FD70 = 1;
+ gLightningStrike.state = LIGHTNING_STRIKE_START;
}
break;
case 3:
@@ -201,14 +201,14 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase*
}
break;
case 6:
- if (globalCtx->envCtx.unk_A0 < 0x3200) {
- globalCtx->envCtx.unk_A0 += 0x23;
+ if (globalCtx->envCtx.adjFogFar < 12800) {
+ globalCtx->envCtx.adjFogFar += 35;
}
break;
case 7:
if (sp3F != 0) {
globalCtx->envCtx.unk_19 = 1;
- globalCtx->envCtx.gloomySky = 1;
+ globalCtx->envCtx.unk_17 = 1;
globalCtx->envCtx.unk_18 = 0;
globalCtx->envCtx.unk_1A = 0x3C;
globalCtx->envCtx.unk_21 = 1;
@@ -279,12 +279,12 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase*
break;
case 18:
globalCtx->envCtx.unk_EE[0] = 0;
- globalCtx->envCtx.gloomySkyEvent = 2;
+ globalCtx->envCtx.gloomySkyMode = 2;
if (gSaveContext.dayTime < 0x4AAB) {
gSaveContext.dayTime += 30;
}
if (globalCtx->envCtx.unk_EE[1] == 0) {
- D_8011FB30 = 0;
+ gWeatherMode = 0;
func_800F6D58(14, 1, 0);
}
break;
@@ -331,16 +331,16 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase*
break;
case 27:
if (globalCtx->state.frames & 8) {
- if (globalCtx->envCtx.unk_8C[0][0] < 40) {
- globalCtx->envCtx.unk_8C[0][0] += 2;
- globalCtx->envCtx.unk_8C[1][1] -= 3;
- globalCtx->envCtx.unk_8C[1][2] -= 3;
+ if (globalCtx->envCtx.adjAmbientColor[0] < 40) {
+ globalCtx->envCtx.adjAmbientColor[0] += 2;
+ globalCtx->envCtx.adjLight1Color[1] -= 3;
+ globalCtx->envCtx.adjLight1Color[2] -= 3;
}
} else {
- if (globalCtx->envCtx.unk_8C[0][0] > 2) {
- globalCtx->envCtx.unk_8C[0][0] -= 2;
- globalCtx->envCtx.unk_8C[1][1] += 3;
- globalCtx->envCtx.unk_8C[1][2] += 3;
+ if (globalCtx->envCtx.adjAmbientColor[0] > 2) {
+ globalCtx->envCtx.adjAmbientColor[0] -= 2;
+ globalCtx->envCtx.adjLight1Color[1] += 3;
+ globalCtx->envCtx.adjLight1Color[2] += 3;
}
}
break;
@@ -358,18 +358,18 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase*
break;
case 32:
if (sp3F != 0) {
- globalCtx->envCtx.unk_E6 = 1;
+ globalCtx->envCtx.sandstormState = 1;
}
func_800788CC(NA_SE_EV_SAND_STORM - SFX_FLAG);
break;
case 33:
- gSaveContext.unk_1422 = 1;
+ gSaveContext.sunsSongState = SUNSSONG_START;
break;
case 34:
if (IS_DAY) {
- gSaveContext.dayTime -= D_8011FB40;
+ gSaveContext.dayTime -= gTimeIncrement;
} else {
- gSaveContext.dayTime -= D_8011FB40 * 2;
+ gSaveContext.dayTime -= gTimeIncrement * 2;
}
break;
case 35:
@@ -433,7 +433,7 @@ void func_80065134(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdDayTim
temp2 = (cmd->minute + 1) / (360.0f / 0x4000);
gSaveContext.dayTime = temp1 + temp2;
- gSaveContext.environmentTime = temp1 + temp2;
+ gSaveContext.skyboxTime = temp1 + temp2;
}
}
@@ -1174,7 +1174,7 @@ void Cutscene_Command_Terminator(GlobalContext* globalCtx, CutsceneContext* csCt
break;
case 119:
gSaveContext.dayTime = 0x8000;
- gSaveContext.environmentTime = 0x8000;
+ gSaveContext.skyboxTime = 0x8000;
globalCtx->nextEntranceIndex = 0x05F0;
globalCtx->sceneLoadFlag = 0x14;
globalCtx->fadeTransition = 3;
@@ -1188,17 +1188,17 @@ void Cutscene_Command_TransitionFX(GlobalContext* globalCtx, CutsceneContext* cs
f32 temp;
if ((csCtx->frames >= cmd->startFrame) && (csCtx->frames <= cmd->endFrame)) {
- globalCtx->envCtx.unk_E1 = 1;
- temp = func_8006F93C(cmd->endFrame, cmd->startFrame, csCtx->frames);
+ globalCtx->envCtx.fillScreen = true;
+ temp = Environment_LerpWeight(cmd->endFrame, cmd->startFrame, csCtx->frames);
switch (cmd->base) {
case 1:
case 5:
- globalCtx->envCtx.unk_E2[0] = 0xA0;
- globalCtx->envCtx.unk_E2[1] = 0xA0;
- globalCtx->envCtx.unk_E2[2] = 0xA0;
+ globalCtx->envCtx.screenFillColor[0] = 160;
+ globalCtx->envCtx.screenFillColor[1] = 160;
+ globalCtx->envCtx.screenFillColor[2] = 160;
if (cmd->base == 1) {
- globalCtx->envCtx.unk_E2[3] = 255.0f * temp;
+ globalCtx->envCtx.screenFillColor[3] = 255.0f * temp;
if ((temp == 0.0f) && (gSaveContext.entranceIndex == 0x006B)) {
Audio_PlaySoundGeneral(NA_SE_SY_WHITE_OUT_S, &D_801333D4, 4, &D_801333E0, &D_801333E0,
&D_801333E8);
@@ -1211,40 +1211,40 @@ void Cutscene_Command_TransitionFX(GlobalContext* globalCtx, CutsceneContext* cs
func_800788CC(NA_SE_EV_WHITE_OUT);
}
} else {
- globalCtx->envCtx.unk_E2[3] = (1.0f - temp) * 255.0f;
+ globalCtx->envCtx.screenFillColor[3] = (1.0f - temp) * 255.0f;
}
break;
case 2:
case 6:
- globalCtx->envCtx.unk_E2[0] = 0;
- globalCtx->envCtx.unk_E2[1] = 0;
- globalCtx->envCtx.unk_E2[2] = 0xFF;
+ globalCtx->envCtx.screenFillColor[0] = 0;
+ globalCtx->envCtx.screenFillColor[1] = 0;
+ globalCtx->envCtx.screenFillColor[2] = 255;
if (cmd->base == 2) {
- globalCtx->envCtx.unk_E2[3] = 255.0f * temp;
+ globalCtx->envCtx.screenFillColor[3] = 255.0f * temp;
} else {
- globalCtx->envCtx.unk_E2[3] = (1.0f - temp) * 255.0f;
+ globalCtx->envCtx.screenFillColor[3] = (1.0f - temp) * 255.0f;
}
break;
case 3:
case 7:
- globalCtx->envCtx.unk_E2[0] = 0xFF;
- globalCtx->envCtx.unk_E2[1] = 0;
- globalCtx->envCtx.unk_E2[2] = 0;
+ globalCtx->envCtx.screenFillColor[0] = 255;
+ globalCtx->envCtx.screenFillColor[1] = 0;
+ globalCtx->envCtx.screenFillColor[2] = 0;
if (cmd->base == 3) {
- globalCtx->envCtx.unk_E2[3] = (1.0f - temp) * 255.0f;
+ globalCtx->envCtx.screenFillColor[3] = (1.0f - temp) * 255.0f;
} else {
- globalCtx->envCtx.unk_E2[3] = 255.0f * temp;
+ globalCtx->envCtx.screenFillColor[3] = 255.0f * temp;
}
break;
case 4:
case 8:
- globalCtx->envCtx.unk_E2[0] = 0;
- globalCtx->envCtx.unk_E2[1] = 0xFF;
- globalCtx->envCtx.unk_E2[2] = 0;
+ globalCtx->envCtx.screenFillColor[0] = 0;
+ globalCtx->envCtx.screenFillColor[1] = 255;
+ globalCtx->envCtx.screenFillColor[2] = 0;
if (cmd->base == 4) {
- globalCtx->envCtx.unk_E2[3] = (1.0f - temp) * 255.0f;
+ globalCtx->envCtx.screenFillColor[3] = (1.0f - temp) * 255.0f;
} else {
- globalCtx->envCtx.unk_E2[3] = 255.0f * temp;
+ globalCtx->envCtx.screenFillColor[3] = 255.0f * temp;
}
break;
case 9:
@@ -1252,23 +1252,23 @@ void Cutscene_Command_TransitionFX(GlobalContext* globalCtx, CutsceneContext* cs
break;
case 10:
case 11:
- globalCtx->envCtx.unk_E2[0] = 0;
- globalCtx->envCtx.unk_E2[1] = 0;
- globalCtx->envCtx.unk_E2[2] = 0;
+ globalCtx->envCtx.screenFillColor[0] = 0;
+ globalCtx->envCtx.screenFillColor[1] = 0;
+ globalCtx->envCtx.screenFillColor[2] = 0;
if (cmd->base == 10) {
- globalCtx->envCtx.unk_E2[3] = (1.0f - temp) * 255.0f;
+ globalCtx->envCtx.screenFillColor[3] = (1.0f - temp) * 255.0f;
} else {
- globalCtx->envCtx.unk_E2[3] = 255.0f * temp;
+ globalCtx->envCtx.screenFillColor[3] = 255.0f * temp;
}
break;
case 12:
gSaveContext.unk_1410 = 255.0f - (155.0f * temp);
break;
case 13:
- globalCtx->envCtx.unk_E2[0] = 0;
- globalCtx->envCtx.unk_E2[1] = 0;
- globalCtx->envCtx.unk_E2[2] = 0;
- globalCtx->envCtx.unk_E2[3] = 255.0f - ((1.0f - temp) * 155.0f);
+ globalCtx->envCtx.screenFillColor[0] = 0;
+ globalCtx->envCtx.screenFillColor[1] = 0;
+ globalCtx->envCtx.screenFillColor[2] = 0;
+ globalCtx->envCtx.screenFillColor[3] = 255.0f - ((1.0f - temp) * 155.0f);
break;
}
}
diff --git a/src/code/z_eff_ss_dead.c b/src/code/z_eff_ss_dead.c
index aebee67b3..b3978547b 100644
--- a/src/code/z_eff_ss_dead.c
+++ b/src/code/z_eff_ss_dead.c
@@ -56,7 +56,7 @@ void func_80026608(GlobalContext* globalCtx) {
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 159);
gDPPipeSync(POLY_OPA_DISP++);
- POLY_OPA_DISP = func_800BC8A0(globalCtx, POLY_OPA_DISP);
+ POLY_OPA_DISP = Gameplay_SetFog(globalCtx, POLY_OPA_DISP);
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 164);
}
@@ -115,7 +115,7 @@ void func_80026A6C(GlobalContext* globalCtx) {
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 217);
gDPPipeSync(POLY_XLU_DISP++);
- POLY_XLU_DISP = func_800BC8A0(globalCtx, POLY_XLU_DISP);
+ POLY_XLU_DISP = Gameplay_SetFog(globalCtx, POLY_XLU_DISP);
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_eff_ss_dead.c", 222);
}
diff --git a/src/code/z_en_item00.c b/src/code/z_en_item00.c
index 35fd67387..f83bb8456 100644
--- a/src/code/z_en_item00.c
+++ b/src/code/z_en_item00.c
@@ -1036,7 +1036,7 @@ void EnItem00_DrawCollectible(EnItem00* this, GlobalContext* globalCtx) {
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_en_item00.c", 1594);
- POLY_OPA_DISP = func_800BC8A0(globalCtx, POLY_OPA_DISP);
+ POLY_OPA_DISP = Gameplay_SetFog(globalCtx, POLY_OPA_DISP);
if (this->actor.params == ITEM00_BOMBS_SPECIAL) {
texIndex = 1;
diff --git a/src/code/z_frame_advance.c b/src/code/z_frame_advance.c
index c8a2c64ff..930db59b3 100644
--- a/src/code/z_frame_advance.c
+++ b/src/code/z_frame_advance.c
@@ -7,7 +7,7 @@ void FrameAdvance_Init(FrameAdvanceContext* frameAdvCtx) {
/**
* Frame advance allows you to advance through the game one frame at a time on command.
- * To enable, hold R and press Dpad Down on the provided controller.
+ * To enable, hold R and press Dpad Down on the specified controller.
* To advance a frame, hold Z and press R.
* Holding Z and R will advance a frame every half second.
*
diff --git a/src/code/z_game_over.c b/src/code/z_game_over.c
index c978b69cf..c41a8e5b8 100644
--- a/src/code/z_game_over.c
+++ b/src/code/z_game_over.c
@@ -9,7 +9,7 @@ void GameOver_FadeInLights(GlobalContext* globalCtx) {
if ((gameOverCtx->state >= GAMEOVER_DEATH_WAIT_GROUND && gameOverCtx->state < GAMEOVER_REVIVE_START) ||
(gameOverCtx->state >= GAMEOVER_REVIVE_RUMBLE && gameOverCtx->state < GAMEOVER_REVIVE_FADE_OUT)) {
- Kankyo_FadeInGameOverLights(globalCtx);
+ Environment_FadeInGameOverLights(globalCtx);
}
}
@@ -74,7 +74,7 @@ void GameOver_Update(GlobalContext* globalCtx) {
gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED;
gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = 0;
- Kankyo_InitGameOverLights(globalCtx);
+ Environment_InitGameOverLights(globalCtx);
D_80153D80 = 20;
if (1) {}
v90 = VREG(90);
@@ -103,7 +103,7 @@ void GameOver_Update(GlobalContext* globalCtx) {
case GAMEOVER_REVIVE_START:
gameOverCtx->state++;
D_80153D80 = 0;
- Kankyo_InitGameOverLights(globalCtx);
+ Environment_InitGameOverLights(globalCtx);
ShrinkWindow_SetVal(0x20);
return;
@@ -139,7 +139,7 @@ void GameOver_Update(GlobalContext* globalCtx) {
break;
case GAMEOVER_REVIVE_FADE_OUT:
- Kankyo_FadeOutGameOverLights(globalCtx);
+ Environment_FadeOutGameOverLights(globalCtx);
D_80153D80--;
if (D_80153D80 == 0) {
diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c
index 61e9b2f78..ee0ab613b 100644
--- a/src/code/z_kankyo.c
+++ b/src/code/z_kankyo.c
@@ -1,94 +1,2499 @@
#include "global.h"
+#include "ultra64.h"
+#include "vt.h"
+#include "objects/gameplay_keep/gameplay_keep.h"
#include "objects/gameplay_field_keep/gameplay_field_keep.h"
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8006F0A0.s")
+typedef enum {
+ /* 0 */ LENS_FLARE_CIRCLE0,
+ /* 1 */ LENS_FLARE_CIRCLE1,
+ /* 2 */ LENS_FLARE_RING
+} LensFlareType;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8006F0D4.s")
+typedef enum {
+ /* 0x00 */ LIGHTNING_BOLT_START,
+ /* 0x01 */ LIGHTNING_BOLT_WAIT,
+ /* 0x02 */ LIGHTNING_BOLT_DRAW,
+ /* 0xFF */ LIGHTNING_BOLT_INACTIVE = 0xFF
+} LightningBoltState;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8006F0FC.s")
+typedef struct {
+ /* 0x00 */ u16 startTime;
+ /* 0x02 */ u16 endTime;
+ /* 0x04 */ u8 unk_04;
+ /* 0x05 */ u8 unk_05;
+} struct_8011FB48; // size = 0x6
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8006F140.s")
+typedef struct {
+ /* 0x00 */ u8 state;
+ /* 0x04 */ Vec3f offset;
+ /* 0x10 */ Vec3f pos;
+ /* 0x1C */ s8 pitch;
+ /* 0x1D */ s8 roll;
+ /* 0x1E */ u8 textureIndex;
+ /* 0x1F */ u8 delayTimer;
+} LightningBolt; // size = 0x20
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8006F93C.s")
+typedef struct {
+ /* 0x00 */ s32 unk0;
+ /* 0x04 */ s32 unk1;
+} Struct_8011FAF0; // size = 0x8
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8006F9BC.s")
+Struct_8011FAF0 D_8011FAF0[] = {
+ { 6, 0x00000000 }, { 5, 0x00020000 }, { 4, 0x00030000 }, { 3, 0x00038000 },
+ { 2, 0x0003C000 }, { 1, 0x0003E000 }, { 0, 0x0003F000 }, { 0, 0x0003F800 },
+};
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8006FB94.s")
+u8 gWeatherMode = 0; // "E_wether_flg"
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8006FC88.s")
+u8 D_8011FB34 = 0;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80070600.s")
+u8 D_8011FB38 = 0;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800706A0.s")
+u8 gSkyboxBlendingEnabled = false;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80070718.s")
+u16 gTimeIncrement = 0;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80070C24.s")
+u16 D_8011FB44 = 0xFFFC;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800730DC.s")
+struct_8011FB48 D_8011FB48[][7] = {
+ {
+ { 0x0000, 0x2AAC, 3, 3 },
+ { 0x2AAC, 0x4000, 3, 0 },
+ { 0x4000, 0x5556, 0, 1 },
+ { 0x5556, 0xAAAB, 1, 1 },
+ { 0xAAAB, 0xB556, 1, 2 },
+ { 0xB556, 0xCAAC, 2, 3 },
+ { 0xCAAC, 0xFFFF, 3, 3 },
+ },
+ {
+ { 0x0000, 0x2AAC, 7, 7 },
+ { 0x2AAC, 0x4000, 7, 4 },
+ { 0x4000, 0x5556, 4, 5 },
+ { 0x5556, 0xAAAB, 5, 5 },
+ { 0xAAAB, 0xB556, 5, 6 },
+ { 0xB556, 0xCAAC, 6, 7 },
+ { 0xCAAC, 0xFFFF, 7, 7 },
+ },
+ {
+ { 0x0000, 0x2AAC, 11, 11 },
+ { 0x2AAC, 0x4000, 11, 8 },
+ { 0x4000, 0x5556, 8, 9 },
+ { 0x5556, 0xAAAB, 9, 9 },
+ { 0xAAAB, 0xB556, 9, 10 },
+ { 0xB556, 0xCAAC, 10, 11 },
+ { 0xCAAC, 0xFFFF, 11, 11 },
+ },
+ {
+ { 0x0000, 0x2AAC, 15, 15 },
+ { 0x2AAC, 0x4000, 15, 12 },
+ { 0x4000, 0x5556, 12, 13 },
+ { 0x5556, 0xAAAB, 13, 13 },
+ { 0xAAAB, 0xB556, 13, 14 },
+ { 0xB556, 0xCAAC, 14, 15 },
+ { 0xCAAC, 0xFFFF, 15, 15 },
+ },
+ {
+ { 0x0000, 0x2AAC, 23, 23 },
+ { 0x2AAC, 0x4000, 23, 20 },
+ { 0x4000, 0x5556, 20, 21 },
+ { 0x5556, 0xAAAB, 21, 21 },
+ { 0xAAAB, 0xB556, 21, 22 },
+ { 0xB556, 0xCAAC, 22, 23 },
+ { 0xCAAC, 0xFFFF, 23, 23 },
+ },
+};
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80073988.s")
+struct_8011FC1C D_8011FC1C[][9] = {
+ {
+ { 0x0000, 0x2AAC, 0, 3, 3 },
+ { 0x2AAC, 0x3556, 1, 3, 0 },
+ { 0x3556, 0x4000, 0, 0, 0 },
+ { 0x4000, 0x5556, 1, 0, 1 },
+ { 0x5556, 0xAAAB, 0, 1, 1 },
+ { 0xAAAB, 0xB556, 1, 1, 2 },
+ { 0xB556, 0xC001, 0, 2, 2 },
+ { 0xC001, 0xCAAC, 1, 2, 3 },
+ { 0xCAAC, 0xFFFF, 0, 3, 3 },
+ },
+ {
+ { 0x0000, 0x2AAC, 0, 7, 7 },
+ { 0x2AAC, 0x3556, 1, 7, 4 },
+ { 0x3556, 0x4000, 0, 4, 4 },
+ { 0x4000, 0x5556, 1, 4, 5 },
+ { 0x5556, 0xAAAB, 0, 5, 5 },
+ { 0xAAAB, 0xB556, 1, 5, 6 },
+ { 0xB556, 0xC001, 0, 6, 6 },
+ { 0xC001, 0xCAAC, 1, 6, 7 },
+ { 0xCAAC, 0xFFFF, 0, 7, 7 },
+ },
+ {
+ { 0x0000, 0x1556, 0, 3, 3 },
+ { 0x1556, 0x2AAC, 1, 3, 0 },
+ { 0x2AAC, 0x5556, 0, 0, 0 },
+ { 0x5556, 0x6AAB, 1, 0, 1 },
+ { 0x6AAB, 0x9556, 0, 1, 1 },
+ { 0x9556, 0xAAAB, 1, 1, 2 },
+ { 0xAAAB, 0xD556, 0, 2, 2 },
+ { 0xD556, 0xEAAB, 1, 2, 3 },
+ { 0xEAAB, 0xFFFF, 0, 3, 3 },
+ },
+ {
+ { 0x0000, 0x3556, 0, 11, 11 },
+ { 0x3556, 0x4000, 1, 11, 8 },
+ { 0x4000, 0x4AAB, 0, 8, 8 },
+ { 0x4AAB, 0x5556, 1, 8, 9 },
+ { 0x5556, 0xAAAB, 0, 9, 9 },
+ { 0xAAAB, 0xB556, 1, 9, 10 },
+ { 0xB556, 0xC001, 0, 10, 10 },
+ { 0xC001, 0xCAAC, 1, 10, 11 },
+ { 0xCAAC, 0xFFFF, 0, 11, 11 },
+ },
+};
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80073A5C.s")
+SkyboxFile gSkyboxFiles[] = {
+ {
+ ROM_FILE(vr_fine0_static),
+ ROM_FILE(vr_fine0_pal_static),
+ },
+ {
+ ROM_FILE(vr_fine1_static),
+ ROM_FILE(vr_fine1_pal_static),
+ },
+ {
+ ROM_FILE(vr_fine2_static),
+ ROM_FILE(vr_fine2_pal_static),
+ },
+ {
+ ROM_FILE(vr_fine3_static),
+ ROM_FILE(vr_fine3_pal_static),
+ },
+ {
+ ROM_FILE(vr_cloud0_static),
+ ROM_FILE(vr_cloud0_pal_static),
+ },
+ {
+ ROM_FILE(vr_cloud1_static),
+ ROM_FILE(vr_cloud1_pal_static),
+ },
+ {
+ ROM_FILE(vr_cloud2_static),
+ ROM_FILE(vr_cloud2_pal_static),
+ },
+ {
+ ROM_FILE(vr_cloud3_static),
+ ROM_FILE(vr_cloud3_pal_static),
+ },
+ {
+ ROM_FILE(vr_holy0_static),
+ ROM_FILE(vr_holy0_pal_static),
+ },
+};
-f32 func_800746DC() {
+u8 D_8011FDCC = 0;
+u8 D_8011FDD0 = 0;
+f32 D_8011FDD4 = 0.0f;
+
+u8 gCustomLensFlareOn;
+Vec3f gCustomLensFlarePos;
+s16 D_8015FD04;
+s16 D_8015FD06;
+f32 D_8015FD08;
+s16 D_8015FD0C;
+LightningBolt sLightningBolts[3];
+LightningStrike gLightningStrike;
+s16 sLightningFlashAlpha;
+s16 D_8015FD7E;
+s16 D_8015FD80;
+LightNode* sNGameOverLightNode;
+LightInfo sNGameOverLightInfo;
+LightNode* sSGameOverLightNode;
+LightInfo sSGameOverLightInfo;
+u8 sGameOverLightsIntensity;
+u16 D_8015FDB0;
+
+s32 func_8006F0A0(s32 a0) {
+ s32 ret = ((a0 >> 4 & 0x7FF) << D_8011FAF0[a0 >> 15 & 7].unk0) + D_8011FAF0[a0 >> 15 & 7].unk1;
+
+ return ret;
+}
+
+u16 Environment_GetPixelDepth(s32 x, s32 y) {
+ s32 pixelDepth = gZBuffer[y][x];
+
+ return pixelDepth;
+}
+
+void Environment_GraphCallback(GraphicsContext* gfxCtx, void* param) {
+ GlobalContext* globalCtx = (GlobalContext*)param;
+
+ D_8011FB44 = Environment_GetPixelDepth(D_8015FD7E, D_8015FD80);
+ Lights_GlowCheck(globalCtx);
+}
+
+void Environment_Init(GlobalContext* globalCtx2, EnvironmentContext* envCtx, s32 unused) {
+ u8 i;
+ GlobalContext* globalCtx = globalCtx2;
+
+ gSaveContext.sunsSongState = SUNSSONG_INACTIVE;
+
+ if (((void)0, gSaveContext.dayTime) > 0xC000 || ((void)0, gSaveContext.dayTime) < 0x4555) {
+ ((void)0, gSaveContext.nightFlag = true);
+ } else {
+ ((void)0, gSaveContext.nightFlag = false);
+ }
+
+ globalCtx->state.gfxCtx->callback = Environment_GraphCallback;
+ globalCtx->state.gfxCtx->callbackParam = globalCtx;
+
+ Lights_DirectionalSetInfo(&envCtx->dirLight1, 80, 80, 80, 80, 80, 80);
+ LightContext_InsertLight(globalCtx, &globalCtx->lightCtx, &envCtx->dirLight1);
+
+ Lights_DirectionalSetInfo(&envCtx->dirLight2, 80, 80, 80, 80, 80, 80);
+ LightContext_InsertLight(globalCtx, &globalCtx->lightCtx, &envCtx->dirLight2);
+
+ envCtx->skybox1Index = 99;
+ envCtx->skybox2Index = 99;
+ envCtx->unk_19 = 0;
+ envCtx->unk_1A = 0;
+ envCtx->unk_21 = 0;
+ envCtx->unk_22 = 0;
+ envCtx->skyboxDmaState = SKYBOX_DMA_INACTIVE;
+ envCtx->unk_1F = 0;
+ envCtx->unk_20 = 0;
+ envCtx->unk_84 = 0.0f;
+ envCtx->unk_88 = 0.0f;
+ envCtx->unk_BD = 0;
+ envCtx->unk_BE = 0;
+ envCtx->unk_D8 = 1.0f;
+ envCtx->unk_DC = 0;
+ envCtx->gloomySkyMode = 0;
+ envCtx->unk_DE = 0;
+ envCtx->lightningMode = LIGHTNING_MODE_OFF;
+ envCtx->unk_E0 = 0;
+ envCtx->fillScreen = false;
+ envCtx->screenFillColor[0] = 0;
+ envCtx->screenFillColor[1] = 0;
+ envCtx->screenFillColor[2] = 0;
+ envCtx->screenFillColor[3] = 0;
+ envCtx->customSkyboxFilter = false;
+ envCtx->skyboxFilterColor[0] = 0;
+ envCtx->skyboxFilterColor[1] = 0;
+ envCtx->skyboxFilterColor[2] = 0;
+ envCtx->skyboxFilterColor[3] = 0;
+ envCtx->sandstormState = 0;
+ envCtx->sandstormPrimA = 0;
+ envCtx->sandstormEnvA = 0;
+
+ gLightningStrike.state = LIGHTNING_STRIKE_WAIT;
+ gLightningStrike.flashRed = 0;
+ gLightningStrike.flashGreen = 0;
+ gLightningStrike.flashBlue = 0;
+
+ sLightningFlashAlpha = 0;
+
+ gSaveContext.unk_1410 = 0;
+
+ envCtx->adjAmbientColor[0] = envCtx->adjAmbientColor[1] = envCtx->adjAmbientColor[2] = envCtx->adjLight1Color[0] =
+ envCtx->adjLight1Color[1] = envCtx->adjLight1Color[2] = envCtx->adjFogColor[0] = envCtx->adjFogColor[1] =
+ envCtx->adjFogColor[2] = envCtx->adjFogNear = envCtx->adjFogFar = 0;
+
+ envCtx->sunPos.x = -(Math_SinS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f) * 25.0f;
+ envCtx->sunPos.y = +(Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f) * 25.0f;
+ envCtx->sunPos.z = +(Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 20.0f) * 25.0f;
+
+ envCtx->windDirection.x = 80;
+ envCtx->windDirection.y = 80;
+ envCtx->windDirection.z = 80;
+
+ envCtx->blendIndoorLights = false;
+ envCtx->unk_BF = 0xFF;
+ envCtx->unk_D6 = 0xFFFF;
+ R_ENV_TIME_INCREMENT = gTimeIncrement = envCtx->timeIncrement = 0;
+ R_ENV_DISABLE_DBG = true;
+
+ if (CREG(3) != 0) {
+ gSaveContext.chamberCutsceneNum = CREG(3) - 1;
+ }
+
+ globalCtx->envCtx.unk_EE[0] = 0;
+ globalCtx->envCtx.unk_EE[1] = 0;
+ globalCtx->envCtx.unk_EE[2] = 0;
+ globalCtx->envCtx.unk_EE[3] = 0;
+
+ globalCtx->envCtx.unk_F2[0] = 0;
+
+ if (gSaveContext.unk_13C3 != 0) {
+ if (((void)0, gSaveContext.sceneSetupIndex) < 4) {
+ switch (gWeatherMode) {
+ case 1:
+ envCtx->unk_17 = 1;
+ envCtx->unk_18 = 1;
+ envCtx->unk_1F = 3;
+ envCtx->unk_20 = 3;
+ globalCtx->envCtx.unk_EE[3] = 0;
+ globalCtx->envCtx.unk_EE[2] = 0;
+ break;
+ case 2:
+ case 3:
+ case 4:
+ envCtx->unk_17 = 1;
+ envCtx->unk_18 = 1;
+ envCtx->unk_1F = 2;
+ envCtx->unk_20 = 2;
+ globalCtx->envCtx.unk_EE[3] = 0;
+ globalCtx->envCtx.unk_EE[2] = 0;
+ break;
+ case 5:
+ envCtx->unk_17 = 1;
+ envCtx->unk_18 = 1;
+ envCtx->unk_1F = 4;
+ envCtx->unk_20 = 4;
+ globalCtx->envCtx.unk_EE[3] = 0;
+ globalCtx->envCtx.unk_EE[2] = 0;
+ break;
+ default:
+ break;
+ }
+
+ if (globalCtx->skyboxId == SKYBOX_NORMAL_SKY) {
+ if (gWeatherMode == 3) {
+ globalCtx->envCtx.unk_EE[2] = globalCtx->envCtx.unk_EE[3] = 0x40;
+ } else if (gWeatherMode == 4) {
+ globalCtx->envCtx.unk_EE[0] = 0x14;
+ globalCtx->envCtx.unk_EE[1] = 0x14;
+ } else if (gWeatherMode == 5) {
+ globalCtx->envCtx.unk_EE[0] = 0x1E;
+ globalCtx->envCtx.unk_EE[1] = 0x1E;
+ }
+ }
+ }
+ } else {
+ gWeatherMode = 0;
+ }
+
+ D_8011FB38 = 0;
+ D_8011FB34 = 0;
+ gSkyboxBlendingEnabled = false;
+ gSaveContext.unk_13C3 = 0;
+ R_ENV_LIGHT1_DIR(0) = 80;
+ R_ENV_LIGHT1_DIR(1) = 80;
+ R_ENV_LIGHT1_DIR(2) = 80;
+ R_ENV_LIGHT2_DIR(0) = -80;
+ R_ENV_LIGHT2_DIR(1) = -80;
+ R_ENV_LIGHT2_DIR(2) = -80;
+ cREG(9) = 10;
+ cREG(10) = 0;
+ cREG(11) = 0;
+ cREG(12) = 0;
+ cREG(13) = 0;
+ cREG(14) = 0;
+ D_8015FCC8 = 1;
+
+ for (i = 0; i < ARRAY_COUNT(sLightningBolts); i++) {
+ sLightningBolts[i].state = LIGHTNING_BOLT_INACTIVE;
+ }
+
+ globalCtx->roomCtx.unk_74[0] = 0;
+ globalCtx->roomCtx.unk_74[1] = 0;
+
+ for (i = 0; i < ARRAY_COUNT(globalCtx->csCtx.npcActions); i++) {
+ globalCtx->csCtx.npcActions[i] = 0;
+ }
+
+ if (Object_GetIndex(&globalCtx->objectCtx, OBJECT_GAMEPLAY_FIELD_KEEP) < 0 && !globalCtx->envCtx.sunMoonDisabled) {
+ globalCtx->envCtx.sunMoonDisabled = true;
+ // "Sun setting other than field keep! So forced release!"
+ osSyncPrintf(VT_COL(YELLOW, BLACK) "\n\nフィールド常駐以外、太陽設定!よって強制解除!\n" VT_RST);
+ }
+
+ gCustomLensFlareOn = false;
+ func_800AA15C();
+}
+
+u8 Environment_SmoothStepToU8(u8* pvalue, u8 target, u8 scale, u8 step, u8 minStep) {
+ s16 stepSize = 0;
+ s16 diff = target - *pvalue;
+
+ if (target != *pvalue) {
+ stepSize = diff / scale;
+ if ((stepSize >= (s16)minStep) || ((s16)-minStep >= stepSize)) {
+ if ((s16)step < stepSize) {
+ stepSize = step;
+ }
+ if ((s16)-step > stepSize) {
+ stepSize = -step;
+ }
+ *pvalue += (u8)stepSize;
+ } else {
+ if (stepSize < (s16)minStep) {
+ stepSize = minStep;
+ *pvalue += (u8)stepSize;
+ if (target < *pvalue) {
+ *pvalue = target;
+ }
+ }
+ if ((s16)-minStep < stepSize) {
+ stepSize = -minStep;
+ *pvalue += (u8)stepSize;
+ if (*pvalue < target) {
+ *pvalue = target;
+ }
+ }
+ }
+ }
+ return diff;
+}
+
+u8 Environment_SmoothStepToS8(s8* pvalue, s8 target, u8 scale, u8 step, u8 minStep) {
+ s16 stepSize = 0;
+ s16 diff = target - *pvalue;
+
+ if (target != *pvalue) {
+ stepSize = diff / scale;
+ if ((stepSize >= (s16)minStep) || ((s16)-minStep >= stepSize)) {
+ if ((s16)step < stepSize) {
+ stepSize = step;
+ }
+ if ((s16)-step > stepSize) {
+ stepSize = -step;
+ }
+ *pvalue += (s8)stepSize;
+ } else {
+ if (stepSize < (s16)minStep) {
+ stepSize = minStep;
+ *pvalue += (s8)stepSize;
+ if (target < *pvalue) {
+ *pvalue = target;
+ }
+ }
+ if ((s16)-minStep < stepSize) {
+ stepSize = -minStep;
+ *pvalue += (s8)stepSize;
+ if (*pvalue < target) {
+ *pvalue = target;
+ }
+ }
+ }
+ }
+ return diff;
+}
+
+f32 Environment_LerpWeight(u16 max, u16 min, u16 val) {
+ f32 diff = max - min;
+ f32 ret;
+
+ if (diff != 0.0f) {
+ ret = 1.0f - (max - val) / diff;
+
+ if (!(ret >= 1.0f)) {
+ return ret;
+ }
+ }
+
+ return 1.0f;
+}
+
+f32 Environment_LerpWeightAccelDecel(u16 endFrame, u16 startFrame, u16 curFrame, u16 accelDuration, u16 decelDuration) {
+ f32 endFrameF;
+ f32 startFrameF;
+ f32 curFrameF;
+ f32 accelDurationF;
+ f32 decelDurationF;
+ f32 totalFrames;
+ f32 temp;
+ f32 framesElapsed;
+ f32 ret;
+
+ if (curFrame <= startFrame) {
+ return 0.0f;
+ }
+
+ if (curFrame >= endFrame) {
+ return 1.0f;
+ }
+
+ endFrameF = (s32)endFrame;
+ startFrameF = (s32)startFrame;
+ curFrameF = (s32)curFrame;
+ totalFrames = endFrameF - startFrameF;
+ framesElapsed = curFrameF - startFrameF;
+ accelDurationF = (s32)accelDuration;
+ decelDurationF = (s32)decelDuration;
+
+ if ((startFrameF >= endFrameF) || (accelDurationF + decelDurationF > totalFrames)) {
+ // "The frame relation between end_frame and start_frame is wrong!!!"
+ osSyncPrintf(VT_COL(RED, WHITE) "\nend_frameとstart_frameのフレーム関係がおかしい!!!" VT_RST);
+ osSyncPrintf(VT_COL(RED, WHITE) "\nby get_parcent_forAccelBrake!!!!!!!!!" VT_RST);
+
+ return 0.0f;
+ }
+
+ temp = 1.0f / ((totalFrames * 2.0f) - accelDurationF - decelDurationF);
+
+ if (accelDurationF != 0.0f) {
+ if (framesElapsed <= accelDurationF) {
+ return temp * framesElapsed * framesElapsed / accelDurationF;
+ }
+ ret = temp * accelDurationF;
+ } else {
+ ret = 0.0f;
+ }
+
+ if (framesElapsed <= totalFrames - decelDurationF) {
+ ret += 2.0f * temp * (framesElapsed - accelDurationF);
+ return ret;
+ }
+
+ ret += 2.0f * temp * (totalFrames - accelDurationF - decelDurationF);
+
+ if (decelDurationF != 0.0f) {
+ ret += temp * decelDurationF;
+ if (framesElapsed < totalFrames) {
+ ret -= temp * (totalFrames - framesElapsed) * (totalFrames - framesElapsed) / decelDurationF;
+ }
+ }
+
+ return ret;
+}
+
+void func_8006FB94(EnvironmentContext* envCtx, u8 unused) {
+ if (envCtx->gloomySkyMode != 0) {
+ switch (envCtx->unk_DE) {
+ case 0:
+ if ((envCtx->gloomySkyMode == 1) && !gSkyboxBlendingEnabled) {
+ envCtx->unk_19 = 1;
+ envCtx->unk_17 = 0;
+ envCtx->unk_18 = 1;
+ envCtx->unk_1A = 100;
+ envCtx->unk_21 = 1;
+ envCtx->unk_1F = 0;
+ envCtx->unk_20 = 2;
+ D_8011FB34 = 2;
+ envCtx->unk_22 = envCtx->unk_24 = 100;
+ envCtx->unk_DE++;
+ }
+ break;
+ case 1:
+ if (!gSkyboxBlendingEnabled && (envCtx->gloomySkyMode == 2)) {
+ gWeatherMode = 0;
+ envCtx->unk_19 = 1;
+ envCtx->unk_17 = 1;
+ envCtx->unk_18 = 0;
+ envCtx->unk_1A = 100;
+ envCtx->unk_21 = 1;
+ envCtx->unk_1F = 2;
+ envCtx->unk_20 = 0;
+ D_8011FB34 = 0;
+ envCtx->unk_22 = envCtx->unk_24 = 100;
+ envCtx->unk_EE[0] = 0;
+ envCtx->gloomySkyMode = 0;
+ envCtx->unk_DE = 0;
+ }
+ break;
+ }
+ }
+}
+
+#ifdef NON_MATCHING
+void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxContext* skyboxCtx) {
+ u32 size;
+ u8 i;
+ u8 newSkybox1Index = 0xFF;
+ u8 newSkybox2Index = 0xFF;
+ u8 skyboxBlend = 0;
+ struct_8011FC1C* entry;
+
+ if (skyboxId == SKYBOX_CUTSCENE_MAP) { // C18
+ envCtx->unk_17 = 3;
+
+ for (i = 0; i < ARRAY_COUNT(D_8011FC1C[envCtx->unk_17]); i++) {
+ entry = &D_8011FC1C[envCtx->unk_17][i];
+ if (((void)0, gSaveContext.skyboxTime) >= entry->startTime &&
+ (((void)0, gSaveContext.skyboxTime) < entry->endTime || entry->endTime == 0xFFFF)) {
+ if (entry->blend) {
+ envCtx->skyboxBlend =
+ Environment_LerpWeight(entry->endTime, entry->startTime, ((void)0, gSaveContext.skyboxTime)) *
+ 255;
+ } else {
+ envCtx->skyboxBlend = 0;
+ }
+ break;
+ }
+ }
+ } else if (skyboxId == SKYBOX_NORMAL_SKY && !envCtx->skyboxDisabled) { // d60 && d74
+ for (i = 0; i < ARRAY_COUNT(D_8011FC1C[envCtx->unk_17]); i++) {
+ entry = D_8011FC1C[envCtx->unk_17] + i;
+
+ if (((void)0, gSaveContext.skyboxTime) >= entry->startTime &&
+ (((void)0, gSaveContext.skyboxTime) < entry->endTime || entry->endTime == 0xFFFF)) {
+ gSkyboxBlendingEnabled = entry->blend;
+ newSkybox1Index = entry->skybox1Index;
+ newSkybox2Index = entry->skybox2Index;
+
+ if (entry->blend) {
+ entry = &D_8011FC1C[envCtx->unk_17][i];
+
+ skyboxBlend =
+ Environment_LerpWeight(entry->endTime, entry->startTime, ((void)0, gSaveContext.skyboxTime)) *
+ 255;
+ } else {
+ entry = &D_8011FC1C[envCtx->unk_17][i];
+ skyboxBlend =
+ Environment_LerpWeight(entry->endTime, entry->startTime, ((void)0, gSaveContext.skyboxTime)) *
+ 255;
+
+ skyboxBlend = (skyboxBlend < 0x80) ? 0xFF : 0;
+
+ if ((envCtx->unk_19 != 0) && (envCtx->unk_19 < 3)) {
+ envCtx->unk_19++;
+ skyboxBlend = 0;
+ }
+ }
+ break;
+ }
+ }
+
+ func_8006FB94(envCtx, skyboxBlend);
+
+ if (envCtx->unk_19 >= 3) {
+ newSkybox1Index = D_8011FC1C[envCtx->unk_17][i].skybox1Index;
+ newSkybox2Index = D_8011FC1C[envCtx->unk_18][i].skybox2Index;
+
+ skyboxBlend = ((f32)envCtx->unk_24 - envCtx->unk_1A--) / (f32)envCtx->unk_24 * 255;
+
+ if (envCtx->unk_1A <= 0) {
+ envCtx->unk_19 = 0;
+ envCtx->unk_17 = envCtx->unk_18;
+ }
+ }
+
+ if (newSkybox1Index == 0xFF) {
+ // "Environment VR data acquisition failed! Report to Sasaki!"
+ osSyncPrintf(VT_COL(RED, WHITE) "\n環境VRデータ取得失敗! ささきまでご報告を!" VT_RST);
+ }
+
+ if ((envCtx->skybox1Index != newSkybox1Index) && (envCtx->skyboxDmaState == SKYBOX_DMA_INACTIVE)) {
+ envCtx->skyboxDmaState = SKYBOX_DMA_FILE1_START;
+ size = gSkyboxFiles[newSkybox1Index].file.vromEnd - gSkyboxFiles[newSkybox1Index].file.vromStart;
+
+ osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
+ DmaMgr_SendRequest2(&envCtx->dmaRequest, (u32)skyboxCtx->staticSegments[0],
+ gSkyboxFiles[newSkybox1Index].file.vromStart, size, 0, &envCtx->loadQueue, NULL,
+ "../z_kankyo.c", 1264);
+ envCtx->skybox1Index = newSkybox1Index;
+ }
+
+ if ((envCtx->skybox2Index != newSkybox2Index) && (envCtx->skyboxDmaState == SKYBOX_DMA_INACTIVE)) {
+ envCtx->skyboxDmaState = SKYBOX_DMA_FILE2_START;
+ size = gSkyboxFiles[newSkybox2Index].file.vromEnd - gSkyboxFiles[newSkybox2Index].file.vromStart;
+
+ osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
+ DmaMgr_SendRequest2(&envCtx->dmaRequest, (u32)skyboxCtx->staticSegments[1],
+ gSkyboxFiles[newSkybox2Index].file.vromStart, size, 0, &envCtx->loadQueue, NULL,
+ "../z_kankyo.c", 1281);
+ envCtx->skybox2Index = newSkybox2Index;
+ }
+
+ if (envCtx->skyboxDmaState == SKYBOX_DMA_FILE1_DONE) {
+ envCtx->skyboxDmaState = SKYBOX_DMA_PAL1_START;
+
+ if (((newSkybox1Index & 4) >> 2) != (newSkybox1Index & 1)) { // & 1 at 12e8
+ size = gSkyboxFiles[newSkybox1Index].pallete.vromEnd - gSkyboxFiles[newSkybox1Index].pallete.vromStart;
+ osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
+ DmaMgr_SendRequest2(&envCtx->dmaRequest, (u32)skyboxCtx->staticSegments[2],
+ gSkyboxFiles[newSkybox1Index].pallete.vromStart, size, 0, &envCtx->loadQueue, NULL,
+ "../z_kankyo.c", 1307);
+ } else {
+ size = gSkyboxFiles[newSkybox1Index].pallete.vromEnd - gSkyboxFiles[newSkybox1Index].pallete.vromStart;
+ osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
+ DmaMgr_SendRequest2(&envCtx->dmaRequest, (u32)skyboxCtx->staticSegments[2] + size,
+ gSkyboxFiles[newSkybox1Index].pallete.vromStart, size, 0, &envCtx->loadQueue, NULL,
+ "../z_kankyo.c", 1320);
+ }
+ }
+
+ if (envCtx->skyboxDmaState == SKYBOX_DMA_FILE2_DONE) {
+ envCtx->skyboxDmaState = SKYBOX_DMA_PAL2_START;
+
+ if (((newSkybox2Index & 4) >> 2) != (newSkybox2Index & 1)) {
+ size = gSkyboxFiles[newSkybox2Index].pallete.vromEnd - gSkyboxFiles[newSkybox2Index].pallete.vromStart;
+ osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
+ DmaMgr_SendRequest2(&envCtx->dmaRequest, (u32)skyboxCtx->staticSegments[2],
+ gSkyboxFiles[newSkybox2Index].pallete.vromStart, size, 0, &envCtx->loadQueue, NULL,
+ "../z_kankyo.c", 1342);
+ } else {
+ size = gSkyboxFiles[newSkybox2Index].pallete.vromEnd - gSkyboxFiles[newSkybox2Index].pallete.vromStart;
+ osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1);
+ DmaMgr_SendRequest2(&envCtx->dmaRequest, (u32)skyboxCtx->staticSegments[2] + size,
+ gSkyboxFiles[newSkybox2Index].pallete.vromStart, size, 0, &envCtx->loadQueue, NULL,
+ "../z_kankyo.c", 1355);
+ }
+ }
+
+ if ((envCtx->skyboxDmaState == SKYBOX_DMA_FILE1_START) || (envCtx->skyboxDmaState == SKYBOX_DMA_FILE2_START)) {
+ if (osRecvMesg(&envCtx->loadQueue, 0, OS_MESG_NOBLOCK) == 0) {
+ envCtx->skyboxDmaState++;
+ }
+ } else if (envCtx->skyboxDmaState >= SKYBOX_DMA_FILE1_DONE) {
+ if (osRecvMesg(&envCtx->loadQueue, 0, OS_MESG_NOBLOCK) == 0) {
+ envCtx->skyboxDmaState = SKYBOX_DMA_INACTIVE;
+ }
+ }
+
+ envCtx->skyboxBlend = skyboxBlend;
+ }
+}
+#else
+#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Environment_UpdateSkybox.s")
+#endif
+
+void Environment_EnableUnderwaterLights(GlobalContext* globalCtx, s32 waterLightsIndex) {
+ if (waterLightsIndex == 0x1F) {
+ waterLightsIndex = 0;
+ // "Underwater color is not set in the water poly data!"
+ osSyncPrintf(VT_COL(YELLOW, BLACK) "\n水ポリゴンデータに水中カラーが設定されておりません!" VT_RST);
+ }
+
+ if (!globalCtx->envCtx.indoors) {
+ D_8011FB34 = globalCtx->envCtx.unk_20;
+
+ if (globalCtx->envCtx.unk_1F != waterLightsIndex) {
+ globalCtx->envCtx.unk_1F = waterLightsIndex;
+ globalCtx->envCtx.unk_20 = waterLightsIndex;
+ }
+ } else {
+ globalCtx->envCtx.blendIndoorLights = false; // instantly switch to water lights
+ globalCtx->envCtx.unk_BF = waterLightsIndex;
+ }
+}
+
+void Environment_DisableUnderwaterLights(GlobalContext* globalCtx) {
+ if (!globalCtx->envCtx.indoors) {
+ globalCtx->envCtx.unk_1F = D_8011FB34;
+ globalCtx->envCtx.unk_20 = D_8011FB34;
+ } else {
+ globalCtx->envCtx.blendIndoorLights = false; // instantly switch to previous lights
+ globalCtx->envCtx.unk_BF = 0xFF;
+ globalCtx->envCtx.unk_D8 = 1.0f;
+ }
+}
+
+void Environment_PrintDebugInfo(GlobalContext* globalCtx, Gfx** gfx) {
+ GfxPrint printer;
+ u32 time;
+ s32 pad;
+
+ GfxPrint_Init(&printer);
+ GfxPrint_Open(&printer, *gfx);
+
+ GfxPrint_SetPos(&printer, 22, 7);
+ GfxPrint_SetColor(&printer, 155, 155, 255, 64);
+ GfxPrint_Printf(&printer, "T%03d ", ((void)0, gSaveContext.totalDays));
+ GfxPrint_Printf(&printer, "E%03d", ((void)0, gSaveContext.bgsDayCount));
+
+ GfxPrint_SetColor(&printer, 255, 255, 55, 64);
+ GfxPrint_SetPos(&printer, 22, 8);
+ GfxPrint_Printf(&printer, "%s", "ZELDATIME ");
+
+ GfxPrint_SetColor(&printer, 255, 255, 255, 64);
+ time = gSaveContext.dayTime;
+ GfxPrint_Printf(&printer, "%02d", (u8)(24 * 60 / (f32)0x10000 * time / 60.0f));
+
+ if ((gSaveContext.dayTime & 0x1F) >= 0x10 || gTimeIncrement >= 6) {
+ GfxPrint_Printf(&printer, "%s", ":");
+ } else {
+ GfxPrint_Printf(&printer, "%s", " ");
+ }
+
+ time = gSaveContext.dayTime;
+ GfxPrint_Printf(&printer, "%02d", (s16)(24 * 60 / (f32)0x10000 * time) % 60);
+
+ GfxPrint_SetColor(&printer, 255, 255, 55, 64);
+ GfxPrint_SetPos(&printer, 22, 9);
+ GfxPrint_Printf(&printer, "%s", "VRBOXTIME ");
+
+ GfxPrint_SetColor(&printer, 255, 255, 255, 64);
+ time = ((void)0, gSaveContext.skyboxTime);
+ GfxPrint_Printf(&printer, "%02d", (u8)(24 * 60 / (f32)0x10000 * time / 60.0f));
+
+ if ((((void)0, gSaveContext.skyboxTime) & 0x1F) >= 0x10 || gTimeIncrement >= 6) {
+ GfxPrint_Printf(&printer, "%s", ":");
+ } else {
+ GfxPrint_Printf(&printer, "%s", " ");
+ }
+
+ time = ((void)0, gSaveContext.skyboxTime);
+ GfxPrint_Printf(&printer, "%02d", (s16)(45.0f / 2048.0f * time) % 60);
+
+ GfxPrint_SetColor(&printer, 55, 255, 255, 64);
+ GfxPrint_SetPos(&printer, 22, 6);
+
+ if (gSaveContext.nightFlag) {
+ GfxPrint_Printf(&printer, "%s", "YORU"); // "night"
+ } else {
+ GfxPrint_Printf(&printer, "%s", "HIRU"); // "day"
+ }
+
+ *gfx = GfxPrint_Close(&printer);
+ GfxPrint_Destroy(&printer);
+}
+
+#define TIME_ENTRY_1F_1 (D_8011FB48[envCtx->unk_1F] + i)
+#define TIME_ENTRY_1F_2 (&D_8011FB48[envCtx->unk_1F][i])
+#define TIME_ENTRY_20 (&D_8011FB48[envCtx->unk_20][i])
+
+void func_80075B44(GlobalContext* globalCtx);
+void func_800766C4(GlobalContext* globalCtx);
+
+#ifdef NON_MATCHING
+// Reordering in light color and fog near and far blends
+void Environment_Update(GlobalContext* globalCtx, EnvironmentContext* envCtx, LightContext* lightCtx,
+ PauseContext* pauseCtx, MessageContext* msgCtx, GameOverContext* gameOverCtx,
+ GraphicsContext* gfxCtx) {
+ f32 sp8C;
+ f32 sp88 = 0.0f;
+ u16 i;
+ u16 j;
+ s16 lightAdj;
+ u16 time;
+ EnvLightSettings* lightSettingsList = globalCtx->envCtx.lightSettingsList; // 7C
+ s32 adjustment;
+
+ if ((((void)0, gSaveContext.gameMode) != 0) && (((void)0, gSaveContext.gameMode) != 3)) {
+ func_800AA16C(globalCtx);
+ }
+
+ if (pauseCtx->state == 0) {
+ if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0)) {
+ if (globalCtx->skyboxId == SKYBOX_NORMAL_SKY) {
+ globalCtx->skyboxCtx.rot.y -= 0.001f;
+ } else if (globalCtx->skyboxId == SKYBOX_CUTSCENE_MAP) {
+ globalCtx->skyboxCtx.rot.y -= 0.005f;
+ }
+ }
+
+ func_800766C4(globalCtx); // increments or decrements unk_EE[1] depending on some condition
+ func_80075B44(globalCtx); // updates bgm/sfx and other things as the day progresses
+
+ if (((void)0, gSaveContext.nextDayTime) >= 0xFF00 && ((void)0, gSaveContext.nextDayTime) != 0xFFFF) {
+ gSaveContext.nextDayTime -= 0x10;
+ osSyncPrintf("\nnext_zelda_time=[%x]", ((void)0, gSaveContext.nextDayTime));
+
+ if (((void)0, gSaveContext.nextDayTime) == 0xFF0E) {
+ func_80078884(NA_SE_EV_CHICKEN_CRY_M);
+ gSaveContext.nextDayTime = 0xFFFF;
+ } else if (((void)0, gSaveContext.nextDayTime) == 0xFF0D) {
+ func_800788CC(NA_SE_EV_DOG_CRY_EVENING);
+ gSaveContext.nextDayTime = 0xFFFF;
+ }
+ }
+
+ if ((pauseCtx->state == 0) && (gameOverCtx->state == GAMEOVER_INACTIVE)) {
+ if (((msgCtx->unk_E300 == 0) && (msgCtx->msgMode == 0)) || (((void)0, gSaveContext.gameMode) == 3)) {
+ if ((envCtx->unk_1A == 0) && !FrameAdvance_IsEnabled(globalCtx) &&
+ (globalCtx->transitionMode == 0 || ((void)0, gSaveContext.gameMode) != 0)) {
+
+ if (!((void)0, gSaveContext.nightFlag) || gTimeIncrement >= 0x190) {
+ gSaveContext.dayTime += gTimeIncrement;
+ } else {
+ gSaveContext.dayTime += gTimeIncrement * 2; // time moves twice as fast at night
+ }
+ }
+ }
+ }
+
+ //! @bug `gTimeIncrement` is unsigned, it can't be negative
+ if (((((void)0, gSaveContext.sceneSetupIndex) >= 5 || gTimeIncrement != 0) &&
+ ((void)0, gSaveContext.dayTime) > ((void)0, gSaveContext.skyboxTime)) ||
+ (((void)0, gSaveContext.dayTime) < 0xAAB || gTimeIncrement < 0)) {
+
+ gSaveContext.skyboxTime = ((void)0, gSaveContext.dayTime);
+ }
+ time = gSaveContext.dayTime;
+
+ if (time > 0xC000 || time < 0x4555) {
+ gSaveContext.nightFlag = true;
+ } else {
+ gSaveContext.nightFlag = false;
+ }
+
+ if (SREG(0) != 0 || CREG(2) != 0) {
+ Gfx* displayList;
+ Gfx* prevDisplayList;
+
+ OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 1682);
+
+ prevDisplayList = POLY_OPA_DISP;
+ displayList = Graph_GfxPlusOne(POLY_OPA_DISP);
+ gSPDisplayList(OVERLAY_DISP++, displayList);
+ Environment_PrintDebugInfo(globalCtx, &displayList);
+ gSPEndDisplayList(displayList++);
+ Graph_BranchDlist(prevDisplayList, displayList);
+ POLY_OPA_DISP = displayList;
+ if (1) {}
+ CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 1690);
+ }
+
+ if ((envCtx->unk_BF != 0xFF) && (envCtx->unk_DC != 2) && (envCtx->unk_BD != envCtx->unk_BF) &&
+ (envCtx->unk_D8 >= 1.0f) && (envCtx->unk_BF < 0x20)) {
+ envCtx->unk_BE = envCtx->unk_BD;
+ envCtx->unk_BD = envCtx->unk_BF;
+ envCtx->unk_D8 = 0.0f;
+ }
+
+ if (envCtx->unk_BF != 0xFE) {
+ if (!envCtx->indoors && (envCtx->unk_BF == 0xFF)) {
+ for (i = 0; i < ARRAY_COUNT(D_8011FB48[envCtx->unk_1F]); i++) {
+ if ((((void)0, gSaveContext.skyboxTime) >= TIME_ENTRY_1F_1->startTime) &&
+ ((((void)0, gSaveContext.skyboxTime) < TIME_ENTRY_1F_1->endTime) ||
+ TIME_ENTRY_1F_1->endTime == 0xFFFF)) {
+ u8 blend8[2];
+ s16 blend16[2];
+
+ sp8C = Environment_LerpWeight(TIME_ENTRY_1F_1->endTime, TIME_ENTRY_1F_1->startTime,
+ ((void)0, gSaveContext.skyboxTime));
+
+ D_8011FDCC = TIME_ENTRY_1F_2->unk_04 & 3;
+ D_8011FDD0 = TIME_ENTRY_1F_2->unk_05 & 3;
+ D_8011FDD4 = sp8C;
+
+ if (envCtx->unk_21) {
+ sp88 = ((f32)envCtx->unk_24 - envCtx->unk_22) / envCtx->unk_24;
+ envCtx->unk_22--;
+
+ if (envCtx->unk_22 <= 0) {
+ envCtx->unk_21 = 0;
+ envCtx->unk_1F = envCtx->unk_20;
+ }
+ }
+
+ for (j = 0; j < 3; j++) {
+ // blend ambient color
+ blend8[0] = LERP(lightSettingsList[TIME_ENTRY_1F_2->unk_04].ambientColor[j],
+ lightSettingsList[TIME_ENTRY_1F_2->unk_05].ambientColor[j], sp8C);
+ blend8[1] = LERP(lightSettingsList[TIME_ENTRY_20->unk_04].ambientColor[j],
+ lightSettingsList[TIME_ENTRY_20->unk_05].ambientColor[j], sp8C);
+ envCtx->lightSettings.ambientColor[j] = LERP(blend8[0], blend8[1], sp88);
+ }
+
+ // set light1 direction for the sun
+ envCtx->lightSettings.light1Dir[0] =
+ -(Math_SinS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f);
+ envCtx->lightSettings.light1Dir[1] =
+ Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f;
+ envCtx->lightSettings.light1Dir[2] =
+ (Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 20.0f);
+
+ // set light2 direction for the moon
+ envCtx->lightSettings.light2Dir[0] = -envCtx->lightSettings.light1Dir[0];
+ envCtx->lightSettings.light2Dir[1] = -envCtx->lightSettings.light1Dir[1];
+ envCtx->lightSettings.light2Dir[2] = -envCtx->lightSettings.light1Dir[2];
+
+ for (j = 0; j < 3; j++) {
+ // blend light1Color
+ blend8[0] = LERP(lightSettingsList[TIME_ENTRY_1F_2->unk_04].light1Color[j],
+ lightSettingsList[TIME_ENTRY_1F_2->unk_05].light1Color[j], sp8C);
+ blend8[1] = LERP(lightSettingsList[TIME_ENTRY_20->unk_04].light1Color[j],
+ lightSettingsList[TIME_ENTRY_20->unk_05].light1Color[j], sp8C);
+ envCtx->lightSettings.light1Color[j] = LERP(blend8[0], blend8[1], sp88);
+
+ // blend light2Color
+ blend8[0] = LERP(lightSettingsList[TIME_ENTRY_1F_2->unk_04].light2Color[j],
+ lightSettingsList[TIME_ENTRY_1F_2->unk_05].light2Color[j], sp8C);
+ blend8[1] = LERP(lightSettingsList[TIME_ENTRY_20->unk_04].light2Color[j],
+ lightSettingsList[TIME_ENTRY_20->unk_05].light2Color[j], sp8C);
+ envCtx->lightSettings.light2Color[j] = LERP(blend8[0], blend8[1], sp88);
+ }
+
+ // blend fogColor
+ for (j = 0; j < 3; j++) {
+ blend8[0] = LERP(lightSettingsList[TIME_ENTRY_1F_2->unk_04].fogColor[j],
+ lightSettingsList[TIME_ENTRY_1F_2->unk_05].fogColor[j], sp8C);
+ blend8[1] = LERP(lightSettingsList[TIME_ENTRY_20->unk_04].fogColor[j],
+ lightSettingsList[TIME_ENTRY_20->unk_05].fogColor[j], sp8C);
+ envCtx->lightSettings.fogColor[j] = LERP(blend8[0], blend8[1], sp88);
+ }
+
+ blend16[0] = LERP32(lightSettingsList[TIME_ENTRY_1F_2->unk_04].fogNear & 0x3FF,
+ lightSettingsList[TIME_ENTRY_1F_2->unk_05].fogNear & 0x3FF, sp8C);
+ blend16[1] = LERP32(lightSettingsList[TIME_ENTRY_20->unk_04].fogNear & 0x3FF,
+ lightSettingsList[TIME_ENTRY_20->unk_05].fogNear & 0x3FF, sp8C);
+
+ envCtx->lightSettings.fogNear = LERP32(blend16[0], blend16[1], sp88);
+
+ blend16[0] = LERP32(lightSettingsList[TIME_ENTRY_1F_2->unk_04].fogFar,
+ lightSettingsList[TIME_ENTRY_1F_2->unk_05].fogFar, sp8C);
+ blend16[1] = LERP32(lightSettingsList[TIME_ENTRY_20->unk_04].fogFar,
+ lightSettingsList[TIME_ENTRY_20->unk_05].fogFar, sp8C);
+
+ envCtx->lightSettings.fogFar = LERP32(blend16[0], blend16[1], sp88);
+
+ if (TIME_ENTRY_20->unk_05 >= envCtx->numLightSettings) {
+ // "The color palette setting seems to be wrong!"
+ osSyncPrintf(VT_COL(RED, WHITE) "\nカラーパレットの設定がおかしいようです!" VT_RST);
+
+ // "Palette setting = [] Last palette number = []"
+ osSyncPrintf(VT_COL(RED, WHITE) "\n設定パレット=[%d] 最後パレット番号=[%d]\n" VT_RST,
+ TIME_ENTRY_20->unk_05, envCtx->numLightSettings - 1);
+ }
+ break;
+ }
+ }
+ } else {
+ // 3200 (l 1608)
+ if (!envCtx->blendIndoorLights) {
+ for (i = 0; i < 3; i++) {
+ envCtx->lightSettings.ambientColor[i] = lightSettingsList[envCtx->unk_BD].ambientColor[i];
+ envCtx->lightSettings.light1Dir[i] = lightSettingsList[envCtx->unk_BD].light1Dir[i];
+ envCtx->lightSettings.light1Color[i] = lightSettingsList[envCtx->unk_BD].light1Color[i];
+ envCtx->lightSettings.light2Dir[i] = lightSettingsList[envCtx->unk_BD].light2Dir[i];
+ envCtx->lightSettings.light2Color[i] = lightSettingsList[envCtx->unk_BD].light2Color[i];
+ envCtx->lightSettings.fogColor[i] = lightSettingsList[envCtx->unk_BD].fogColor[i];
+ }
+
+ envCtx->lightSettings.fogNear = lightSettingsList[envCtx->unk_BD].fogNear & 0x3FF;
+ envCtx->lightSettings.fogFar = lightSettingsList[envCtx->unk_BD].fogFar;
+ envCtx->unk_D8 = 1.0f;
+ } else {
+ // 3344 (l 1689)
+ u8 blendRate = (lightSettingsList[envCtx->unk_BD].fogNear >> 0xA) * 4;
+
+ if (blendRate == 0) {
+ blendRate++;
+ }
+
+ if (envCtx->unk_D6 != 0xFFFF) {
+ blendRate = envCtx->unk_D6;
+ }
+
+ if (envCtx->unk_DC == 0) {
+ envCtx->unk_D8 += blendRate / 255.0f;
+ }
+
+ if (envCtx->unk_D8 > 1.0f) {
+ envCtx->unk_D8 = 1.0f;
+ }
+
+ for (j = 0; j < 3; j++) {
+ envCtx->lightSettings.ambientColor[j] =
+ LERP(lightSettingsList[envCtx->unk_BE].ambientColor[j],
+ lightSettingsList[envCtx->unk_BD].ambientColor[j], envCtx->unk_D8);
+ envCtx->lightSettings.light1Dir[j] =
+ LERP32(lightSettingsList[envCtx->unk_BE].light1Dir[j],
+ lightSettingsList[envCtx->unk_BD].light1Dir[j], envCtx->unk_D8);
+ envCtx->lightSettings.light1Color[j] =
+ LERP(lightSettingsList[envCtx->unk_BE].light1Color[j],
+ lightSettingsList[envCtx->unk_BD].light1Color[j], envCtx->unk_D8);
+ envCtx->lightSettings.light2Dir[j] =
+ LERP32(lightSettingsList[envCtx->unk_BE].light2Dir[j],
+ lightSettingsList[envCtx->unk_BD].light2Dir[j], envCtx->unk_D8);
+ envCtx->lightSettings.light2Color[j] =
+ LERP(lightSettingsList[envCtx->unk_BE].light2Color[j],
+ lightSettingsList[envCtx->unk_BD].light2Color[j], envCtx->unk_D8);
+ envCtx->lightSettings.fogColor[j] =
+ LERP(lightSettingsList[envCtx->unk_BE].fogColor[j],
+ lightSettingsList[envCtx->unk_BD].fogColor[j], envCtx->unk_D8);
+ }
+ envCtx->lightSettings.fogNear =
+ LERP32(lightSettingsList[envCtx->unk_BE].fogNear & 0x3FF,
+ lightSettingsList[envCtx->unk_BD].fogNear & 0x3FF, envCtx->unk_D8);
+ envCtx->lightSettings.fogFar = LERP32(lightSettingsList[envCtx->unk_BE].fogFar,
+ lightSettingsList[envCtx->unk_BD].fogFar, envCtx->unk_D8);
+ }
+
+ if (envCtx->unk_BD >= envCtx->numLightSettings) {
+ // "The color palette seems to be wrong!"
+ osSyncPrintf(VT_FGCOL(RED) "\nカラーパレットがおかしいようです!");
+
+ // "Palette setting = [] Last palette number = []"
+ osSyncPrintf(VT_FGCOL(YELLOW) "\n設定パレット=[%d] パレット数=[%d]\n" VT_RST, envCtx->unk_BD,
+ envCtx->numLightSettings);
+ }
+ }
+ }
+
+ envCtx->blendIndoorLights = true;
+
+ // Apply lighting adjustments
+ for (i = 0; i < 3; i++) {
+ lightAdj = envCtx->lightSettings.ambientColor[i] + envCtx->adjAmbientColor[i];
+
+ if (lightAdj > 255) {
+ lightCtx->ambientColor[i] = 255;
+ } else if (lightAdj < 0) {
+ lightCtx->ambientColor[i] = 0;
+ } else {
+ lightCtx->ambientColor[i] = lightAdj;
+ }
+
+ lightAdj = envCtx->lightSettings.light1Color[i] + envCtx->adjLight1Color[i];
+
+ if (lightAdj > 255) {
+ envCtx->dirLight1.params.dir.color[i] = 255;
+ } else if (lightAdj < 0) {
+ envCtx->dirLight1.params.dir.color[i] = 0;
+ } else {
+ envCtx->dirLight1.params.dir.color[i] = lightAdj;
+ }
+
+ lightAdj = envCtx->lightSettings.light2Color[i] + envCtx->adjLight1Color[i];
+
+ if (lightAdj > 255) {
+ envCtx->dirLight2.params.dir.color[i] = 255;
+ } else if (lightAdj < 0) {
+ envCtx->dirLight2.params.dir.color[i] = 0;
+ } else {
+ envCtx->dirLight2.params.dir.color[i] = lightAdj;
+ }
+
+ lightAdj = envCtx->lightSettings.fogColor[i] + envCtx->adjFogColor[i];
+
+ if (lightAdj > 255) {
+ lightCtx->fogColor[i] = 255;
+ } else if (lightAdj < 0) {
+ lightCtx->fogColor[i] = 0;
+ } else {
+ lightCtx->fogColor[i] = lightAdj;
+ }
+ }
+
+ // Set both directional light directions
+ envCtx->dirLight1.params.dir.x = envCtx->lightSettings.light1Dir[0];
+ envCtx->dirLight1.params.dir.y = envCtx->lightSettings.light1Dir[1];
+ envCtx->dirLight1.params.dir.z = envCtx->lightSettings.light1Dir[2];
+
+ envCtx->dirLight2.params.dir.x = envCtx->lightSettings.light2Dir[0];
+ envCtx->dirLight2.params.dir.y = envCtx->lightSettings.light2Dir[1];
+ envCtx->dirLight2.params.dir.z = envCtx->lightSettings.light2Dir[2];
+
+ // Adjust fog near and far if necessary
+ adjustment = envCtx->lightSettings.fogNear + envCtx->adjFogNear;
+
+ if (adjustment <= 996) {
+ lightCtx->fogNear = adjustment;
+ } else {
+ lightCtx->fogNear = 996;
+ }
+
+ adjustment = envCtx->lightSettings.fogFar + envCtx->adjFogFar;
+
+ if (adjustment <= 12800) {
+ lightCtx->fogFar = adjustment;
+ } else {
+ lightCtx->fogFar = 12800;
+ }
+
+ // When environment debug is enabled, various environment related variables can be configured via the reg editor
+ if (R_ENV_DISABLE_DBG) {
+ R_ENV_AMBIENT_COLOR(0) = lightCtx->ambientColor[0];
+ R_ENV_AMBIENT_COLOR(1) = lightCtx->ambientColor[1];
+ R_ENV_AMBIENT_COLOR(2) = lightCtx->ambientColor[2];
+
+ R_ENV_LIGHT1_COLOR(0) = envCtx->dirLight1.params.dir.color[0];
+ R_ENV_LIGHT1_COLOR(1) = envCtx->dirLight1.params.dir.color[1];
+ R_ENV_LIGHT1_COLOR(2) = envCtx->dirLight1.params.dir.color[2];
+
+ R_ENV_LIGHT2_COLOR(0) = envCtx->dirLight2.params.dir.color[0];
+ R_ENV_LIGHT2_COLOR(1) = envCtx->dirLight2.params.dir.color[1];
+ R_ENV_LIGHT2_COLOR(2) = envCtx->dirLight2.params.dir.color[2];
+
+ R_ENV_FOG_COLOR(0) = lightCtx->fogColor[0];
+ R_ENV_FOG_COLOR(1) = lightCtx->fogColor[1];
+ R_ENV_FOG_COLOR(2) = lightCtx->fogColor[2];
+
+ R_ENV_FOG_FAR = lightCtx->fogFar;
+ R_ENV_FOG_NEAR = lightCtx->fogNear;
+
+ R_ENV_LIGHT1_DIR(0) = envCtx->dirLight1.params.dir.x;
+ R_ENV_LIGHT1_DIR(1) = envCtx->dirLight1.params.dir.y;
+ R_ENV_LIGHT1_DIR(2) = envCtx->dirLight1.params.dir.z;
+
+ R_ENV_LIGHT2_DIR(0) = envCtx->dirLight2.params.dir.x;
+ R_ENV_LIGHT2_DIR(1) = envCtx->dirLight2.params.dir.y;
+ R_ENV_LIGHT2_DIR(2) = envCtx->dirLight2.params.dir.z;
+
+ R_ENV_WIND_DIR(0) = envCtx->windDirection.x;
+ R_ENV_WIND_DIR(1) = envCtx->windDirection.y;
+ R_ENV_WIND_DIR(2) = envCtx->windDirection.z;
+ R_ENV_WIND_SPEED = envCtx->windSpeed;
+ } else {
+ lightCtx->ambientColor[0] = R_ENV_AMBIENT_COLOR(0);
+ lightCtx->ambientColor[1] = R_ENV_AMBIENT_COLOR(1);
+ lightCtx->ambientColor[2] = R_ENV_AMBIENT_COLOR(2);
+
+ envCtx->dirLight1.params.dir.color[0] = R_ENV_LIGHT1_COLOR(0);
+ envCtx->dirLight1.params.dir.color[1] = R_ENV_LIGHT1_COLOR(1);
+ envCtx->dirLight1.params.dir.color[2] = R_ENV_LIGHT1_COLOR(2);
+
+ envCtx->dirLight2.params.dir.color[0] = R_ENV_LIGHT2_COLOR(0);
+ envCtx->dirLight2.params.dir.color[1] = R_ENV_LIGHT2_COLOR(1);
+ envCtx->dirLight2.params.dir.color[2] = R_ENV_LIGHT2_COLOR(2);
+ lightCtx->fogColor[0] = R_ENV_FOG_COLOR(0);
+ lightCtx->fogColor[1] = R_ENV_FOG_COLOR(1);
+ lightCtx->fogColor[2] = R_ENV_FOG_COLOR(2);
+ lightCtx->fogNear = R_ENV_FOG_NEAR;
+ lightCtx->fogFar = R_ENV_FOG_FAR;
+
+ if (cREG(14)) {
+ R_ENV_LIGHT1_DIR(0) = Math_CosS(cREG(10)) * Math_CosS(cREG(11)) * 120.0f;
+ envCtx->dirLight1.params.dir.x = R_ENV_LIGHT1_DIR(0);
+ R_ENV_LIGHT1_DIR(1) = Math_CosS(cREG(10)) * Math_SinS(cREG(11)) * 120.0f;
+ envCtx->dirLight1.params.dir.y = R_ENV_LIGHT1_DIR(1);
+ R_ENV_LIGHT1_DIR(2) = Math_SinS(cREG(11)) * 120.0f;
+ envCtx->dirLight1.params.dir.z = R_ENV_LIGHT1_DIR(2);
+
+ R_ENV_LIGHT2_DIR(0) = Math_CosS(cREG(12)) * Math_CosS(cREG(13)) * 120.0f;
+ envCtx->dirLight2.params.dir.x = R_ENV_LIGHT2_DIR(0);
+ R_ENV_LIGHT2_DIR(1) = Math_CosS(cREG(12)) * Math_SinS(cREG(13)) * 120.0f;
+ envCtx->dirLight2.params.dir.y = R_ENV_LIGHT2_DIR(1);
+ R_ENV_LIGHT2_DIR(2) = Math_SinS(cREG(13)) * 120.0f;
+ envCtx->dirLight2.params.dir.z = R_ENV_LIGHT2_DIR(2);
+ } else {
+ envCtx->dirLight1.params.dir.x = R_ENV_LIGHT1_DIR(0);
+ envCtx->dirLight1.params.dir.y = R_ENV_LIGHT1_DIR(1);
+ envCtx->dirLight1.params.dir.z = R_ENV_LIGHT1_DIR(2);
+
+ envCtx->dirLight2.params.dir.x = R_ENV_LIGHT2_DIR(0);
+ envCtx->dirLight2.params.dir.y = R_ENV_LIGHT2_DIR(1);
+ envCtx->dirLight2.params.dir.z = R_ENV_LIGHT2_DIR(2);
+ }
+
+ envCtx->windDirection.x = R_ENV_WIND_DIR(0);
+ envCtx->windDirection.y = R_ENV_WIND_DIR(1);
+ envCtx->windDirection.z = R_ENV_WIND_DIR(2);
+ envCtx->windSpeed = R_ENV_WIND_SPEED;
+ }
+
+ if ((envCtx->dirLight1.params.dir.x == 0) && (envCtx->dirLight1.params.dir.y == 0) &&
+ (envCtx->dirLight1.params.dir.z == 0)) {
+ envCtx->dirLight1.params.dir.x = 1;
+ }
+
+ if ((envCtx->dirLight2.params.dir.x == 0) && (envCtx->dirLight2.params.dir.y == 0) &&
+ (envCtx->dirLight2.params.dir.z == 0)) {
+ envCtx->dirLight2.params.dir.x = 1;
+ }
+ }
+}
+#else
+#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Environment_Update.s")
+#endif
+
+void Environment_DrawSunAndMoon(GlobalContext* globalCtx) {
+ f32 alpha;
+ f32 color;
+ f32 y;
+ f32 scale;
+ f32 temp;
+
+ OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 2266);
+
+ if (globalCtx->csCtx.state != 0) {
+ Math_SmoothStepToF(&globalCtx->envCtx.sunPos.x,
+ -(Math_SinS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f) * 25.0f, 1.0f, 0.8f, 0.8f);
+ Math_SmoothStepToF(&globalCtx->envCtx.sunPos.y,
+ (Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f) * 25.0f, 1.0f, 0.8f, 0.8f);
+ //! @bug This should be z.
+ Math_SmoothStepToF(&globalCtx->envCtx.sunPos.y,
+ (Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 20.0f) * 25.0f, 1.0f, 0.8f, 0.8f);
+ } else {
+ globalCtx->envCtx.sunPos.x = -(Math_SinS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f) * 25.0f;
+ globalCtx->envCtx.sunPos.y = +(Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f) * 25.0f;
+ globalCtx->envCtx.sunPos.z = +(Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 20.0f) * 25.0f;
+ }
+
+ if (gSaveContext.entranceIndex != 0xCD || ((void)0, gSaveContext.sceneSetupIndex) != 5) {
+ Matrix_Translate(globalCtx->view.eye.x + globalCtx->envCtx.sunPos.x,
+ globalCtx->view.eye.y + globalCtx->envCtx.sunPos.y,
+ globalCtx->view.eye.z + globalCtx->envCtx.sunPos.z, MTXMODE_NEW);
+
+ y = globalCtx->envCtx.sunPos.y / 25.0f;
+ temp = y / 80.0f;
+
+ alpha = temp * 255.0f;
+ if (alpha < 0.0f) {
+ alpha = 0.0f;
+ }
+ if (alpha > 255.0f) {
+ alpha = 255.0f;
+ }
+
+ alpha = 255.0f - alpha;
+
+ color = temp;
+ if (color < 0.0f) {
+ color = 0.0f;
+ }
+
+ if (color > 1.0f) {
+ color = 1.0f;
+ }
+
+ gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, (u8)(color * 75.0f) + 180, (u8)(color * 155.0f) + 100, 255);
+ gDPSetEnvColor(POLY_OPA_DISP++, 255, (u8)(color * 255.0f), (u8)(color * 255.0f), alpha);
+
+ scale = (color * 2.0f) + 10.0f;
+ Matrix_Scale(scale, scale, scale, MTXMODE_APPLY);
+ gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_kankyo.c", 2364), G_MTX_LOAD);
+ func_80093AD0(globalCtx->state.gfxCtx);
+ gSPDisplayList(POLY_OPA_DISP++, gSunDL);
+
+ Matrix_Translate(globalCtx->view.eye.x - globalCtx->envCtx.sunPos.x,
+ globalCtx->view.eye.y - globalCtx->envCtx.sunPos.y,
+ globalCtx->view.eye.z - globalCtx->envCtx.sunPos.z, MTXMODE_NEW);
+
+ color = -y / 120.0f;
+ color = CLAMP_MIN(color, 0.0f);
+
+ scale = -15.0f * color + 25.0f;
+ Matrix_Scale(scale, scale, scale, MTXMODE_APPLY);
+
+ temp = -y / 80.0f;
+ temp = CLAMP_MAX(temp, 1.0f);
+
+ alpha = temp * 255.0f;
+
+ if (alpha > 0.0f) {
+ gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_kankyo.c", 2406), G_MTX_LOAD);
+ func_8009398C(globalCtx->state.gfxCtx);
+ gDPPipeSync(POLY_OPA_DISP++);
+ gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 240, 255, 180, alpha);
+ gDPSetEnvColor(POLY_OPA_DISP++, 80, 70, 20, alpha);
+ gSPDisplayList(POLY_OPA_DISP++, gMoonDL);
+ }
+ }
+
+ CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 2429);
+}
+
+void Environment_DrawSunLensFlare(GlobalContext* globalCtx, EnvironmentContext* envCtx, View* view,
+ GraphicsContext* gfxCtx, Vec3f pos, s32 unused) {
+ if ((globalCtx->envCtx.unk_EE[1] == 0) && (globalCtx->envCtx.unk_17 == 0)) {
+ Environment_DrawLensFlare(globalCtx, &globalCtx->envCtx, &globalCtx->view, globalCtx->state.gfxCtx, pos, 2000,
+ 370, Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f, 400, 1);
+ }
+}
+
+#ifdef NON_MATCHING
+// isOffScreen shouldn't be on the stack
+void Environment_DrawLensFlare(GlobalContext* globalCtx, EnvironmentContext* envCtx, View* view,
+ GraphicsContext* gfxCtx, Vec3f pos, s32 unused, s16 arg6, f32 arg7, s16 arg8, u8 arg9) {
+ static f32 lensFlareScales[] = { 23.0f, 12.0f, 7.0f, 5.0f, 3.0f, 10.0f, 6.0f, 2.0f, 3.0f, 1.0f };
+
+ s16 i;
+ f32 tempX;
+ f32 tempY;
+ f32 tempZ; // 1A0 //
+ f32 lookDirX; // 19C
+ f32 lookDirY; // 198
+ f32 lookDirZ;
+ f32 tempX2; // 190 //
+ f32 tempY2;
+ f32 tempZ2;
+ f32 posDirX; // 184
+ f32 posDirY; // 180
+ f32 posDirZ; // 17C
+ f32 length;
+ f32 dist;
+ f32 halfPosX; // 170
+ f32 halfPosY; // 16C
+ f32 halfPosZ; // 168
+ f32 cosAngle; // 164
+ f32 pad160; // 160 //
+ f32 unk88Target; // 15C
+ u32 isOffScreen = false;
+ f32 alpha;
+ f32 scale; // 150 //
+ Vec3f screenPos; // 144
+ f32 fogInfluence; // 140 //
+ f32 temp; // 13C
+ f32 alphaScale;
+ Color_RGB8 lensFlareColors[] = {
+ // 118
+ { 155, 205, 255 }, // blue
+ { 255, 255, 205 }, // yellow
+ { 255, 255, 205 }, // yellow
+ { 255, 255, 205 }, // yellow
+ { 155, 255, 205 }, // green
+ { 205, 255, 255 }, // light blue
+ { 155, 155, 255 }, // dark blue
+ { 205, 175, 255 }, // purple
+ { 175, 255, 205 }, // light green
+ { 255, 155, 235 }, // pink
+ };
+ u32 lensFlareAlphas[] = {
+ // F0
+ 50, 10, 25, 40, 70, 30, 50, 70, 50, 40,
+ };
+ u32 lensFlareTypes[] = {
+ // C8
+ LENS_FLARE_RING, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1,
+ LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1,
+ };
+
+ OPEN_DISPS(gfxCtx, "../z_kankyo.c", 2516); // C4
+
+ dist = Math3D_Vec3f_DistXYZ(&pos, &view->eye) / 12.0f;
+
+ // compute a unit vector in the look direction
+ tempX = view->lookAt.x - view->eye.x;
+ tempY = view->lookAt.y - view->eye.y;
+ tempZ = view->lookAt.z - view->eye.z;
+
+ length = sqrtf(SQ(tempX) + SQ(tempY) + SQ(tempZ));
+
+ lookDirX = tempX / length;
+ lookDirY = tempY / length;
+ lookDirZ = tempZ / length;
+
+ // compute a position along the look vector half as far as pos
+ halfPosX = view->eye.x + lookDirX * (dist * 6.0f);
+ halfPosY = view->eye.y + lookDirY * (dist * 6.0f);
+ halfPosZ = view->eye.z + lookDirZ * (dist * 6.0f);
+
+ // compute a unit vector in the direction from halfPos to pos
+ tempX2 = pos.x - halfPosX;
+ tempY2 = pos.y - halfPosY;
+ tempZ2 = pos.z - halfPosZ;
+
+ length = sqrtf(SQ(tempX2) + SQ(tempY2) + SQ(tempZ2));
+
+ posDirX = tempX2 / length;
+ posDirY = tempY2 / length;
+ posDirZ = tempZ2 / length;
+
+ // compute the cosine of the angle between lookDir and posDir
+ cosAngle = (lookDirX * posDirX + lookDirY * posDirY + lookDirZ * posDirZ) /
+ sqrtf((SQ(lookDirX) + SQ(lookDirY) + SQ(lookDirZ)) * (SQ(posDirX) + SQ(posDirY) + SQ(posDirZ)));
+
+ unk88Target = cosAngle * 3.5f;
+ unk88Target = CLAMP_MAX(unk88Target, 1.0f);
+
+ if (arg9 == 0) {
+ unk88Target = cosAngle;
+ }
+
+ if (cosAngle < 0.0f) {
+
+ } else {
+ if (arg9) {
+ func_800C016C(globalCtx, &pos, &screenPos);
+ D_8015FD7E = (s16)screenPos.x;
+ D_8015FD80 = (s16)screenPos.y - 5.0f;
+ if (D_8011FB44 != 0xFFFC || screenPos.x < 0.0f || screenPos.y < 0.0f || screenPos.x > SCREEN_WIDTH ||
+ screenPos.y > SCREEN_HEIGHT) {
+ isOffScreen = true;
+ }
+ }
+
+ for (i = 0; i < ARRAY_COUNT(lensFlareTypes); i++) {
+ Matrix_Translate(pos.x, pos.y, pos.z, MTXMODE_NEW);
+
+ if (arg9) {
+ temp = Environment_LerpWeight(60, 15, globalCtx->view.fovy);
+ }
+
+ Matrix_Translate(-posDirX * i * dist, -posDirY * i * dist, -posDirZ * i * dist, MTXMODE_APPLY);
+ scale = lensFlareScales[i] * cosAngle;
+
+ if (arg9) {
+ scale *= 0.001 * (arg6 + 630.0f * temp);
+ } else {
+ scale *= 0.0001f * arg6 * (2.0f * dist);
+ }
+
+ Matrix_Scale(scale, scale, scale, MTXMODE_APPLY);
+
+ alpha = arg7 / 10.0f;
+ alpha = CLAMP_MAX(alpha, 1.0f);
+ alpha = alpha * lensFlareAlphas[i];
+ alpha = CLAMP_MIN(alpha, 0.0f);
+
+ fogInfluence = (996 - globalCtx->lightCtx.fogNear) / 50.0f;
+
+ fogInfluence = CLAMP_MAX(fogInfluence, 1.0f);
+
+ alpha *= 1.0f - fogInfluence;
+
+ if (!isOffScreen) { // 5088
+ Math_SmoothStepToF(&envCtx->unk_88, unk88Target, 0.5f, 0.05f, 0.001f);
+ } else {
+ Math_SmoothStepToF(&envCtx->unk_88, 0.0f, 0.5f, 0.05f, 0.001f);
+ }
+
+ POLY_XLU_DISP = func_800947AC(POLY_XLU_DISP++);
+ gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, lensFlareColors[i].r, lensFlareColors[i].g, lensFlareColors[i].b,
+ alpha * envCtx->unk_88);
+ gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx, "../z_kankyo.c", 2662),
+ G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
+ gDPSetCombineLERP(POLY_XLU_DISP++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0,
+ 0, PRIMITIVE, 0);
+ gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_DISABLE);
+ gDPSetColorDither(POLY_XLU_DISP++, G_CD_DISABLE);
+ gSPMatrix(POLY_XLU_DISP++, &D_01000000, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
+
+ switch (lensFlareTypes[i]) {
+ case LENS_FLARE_CIRCLE0:
+ case LENS_FLARE_CIRCLE1:
+ gSPDisplayList(POLY_XLU_DISP++, gLensFlareCircleDL);
+ break;
+ case LENS_FLARE_RING:
+ gSPDisplayList(POLY_XLU_DISP++, gLensFlareRingDL);
+ break;
+ }
+ }
+
+ alphaScale = cosAngle - (1.5f - cosAngle);
+
+ if (arg8) {
+ if (alphaScale > 0.0f) {
+ POLY_XLU_DISP = func_800937C0(POLY_XLU_DISP);
+
+ alpha = arg7 / 10.0f;
+ alpha = CLAMP_MAX(alpha, 1.0f);
+ alpha = alpha * arg8;
+ alpha = CLAMP_MIN(alpha, 0.0f);
+
+ fogInfluence = (996 - globalCtx->lightCtx.fogNear) / 50.0f;
+
+ fogInfluence = CLAMP_MAX(fogInfluence, 1.0f);
+
+ alpha *= 1.0f - fogInfluence;
+
+ gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_DISABLE);
+ gDPSetColorDither(POLY_XLU_DISP++, G_CD_DISABLE);
+
+ if (!isOffScreen) {
+ Math_SmoothStepToF(&envCtx->unk_84, alpha * alphaScale, 0.5f, 50.0f, 0.1f);
+ } else {
+ Math_SmoothStepToF(&envCtx->unk_84, 0.0f, 0.5f, 50.0f, 0.1f);
+ }
+
+ temp = arg7 / 120.0f;
+ temp = CLAMP_MIN(temp, 0.0f);
+
+ gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, (u8)(temp * 75.0f) + 180, (u8)(temp * 155.0f) + 100,
+ envCtx->unk_84);
+ gDPFillRectangle(POLY_XLU_DISP++, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
+ } else {
+ envCtx->unk_84 = 0.0f;
+ }
+ }
+ }
+
+ CLOSE_DISPS(gfxCtx, "../z_kankyo.c", 2750);
+}
+#else
+f32 D_8011FDD8[] = { 23.0f, 12.0f, 7.0f, 5.0f, 3.0f, 10.0f, 6.0f, 2.0f, 3.0f, 1.0f };
+Color_RGB8 D_8011FE00[] = {
+ { 155, 205, 255 }, { 255, 255, 205 }, { 255, 255, 205 }, { 255, 255, 205 }, { 155, 255, 205 },
+ { 205, 255, 255 }, { 155, 155, 255 }, { 205, 175, 255 }, { 175, 255, 205 }, { 255, 155, 235 },
+};
+u32 D_8011FE20[] = { 0x32, 0xA, 0x19, 0x28, 0x46, 0x1E, 0x32, 0x46, 0x32, 0x28 };
+u32 D_8011FE48[] = { 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
+#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Environment_DrawLensFlare.s")
+#endif
+
+f32 func_800746DC(void) {
return Rand_ZeroOne() - 0.5f;
}
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80074704.s")
+#ifdef NON_MATCHING
+// float regalloc, but appears to be equivalent
+void Environment_DrawRain(GlobalContext* globalCtx, View* view, GraphicsContext* gfxCtx) {
+ s16 i;
+ Vec3f vec;
+ f32 length;
+ Vec3f norm;
+ f32 rotX;
+ f32 rotY;
+ f32 tempY;
+ f32 x50;
+ f32 y50;
+ f32 z50;
+ f32 x280;
+ f32 z280;
+ f32 temp;
+ f32 temp2;
+ Vec3f unused = { 0.0f, 0.0f, 0.0f };
+ Vec3f windDirection = { 0.0f, 0.0f, 0.0f };
+ Player* player = GET_PLAYER(globalCtx);
+
+ if (!(globalCtx->cameraPtrs[0]->unk_14C & 0x100) && (globalCtx->envCtx.unk_EE[2] == 0)) {
+ OPEN_DISPS(gfxCtx, "../z_kankyo.c", 2799);
+
+ vec.x = view->lookAt.x - view->eye.x;
+ vec.y = view->lookAt.y - view->eye.y;
+ vec.z = view->lookAt.z - view->eye.z;
+
+ length = sqrtf(SQXYZ(vec));
+
+ norm.x = vec.x / length;
+ norm.y = vec.y / length;
+ norm.z = vec.z / length;
+
+ x50 = view->eye.x + norm.x * 50.0f;
+ y50 = view->eye.y + norm.y * 50.0f;
+ z50 = view->eye.z + norm.z * 50.0f;
+
+ x280 = view->eye.x + norm.x * 280.0f;
+ z280 = view->eye.z + norm.z * 280.0f;
+
+ if (globalCtx->envCtx.unk_EE[1]) {
+ gDPPipeSync(POLY_XLU_DISP++);
+ gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 150, 255, 255, 30);
+ POLY_XLU_DISP = Gfx_CallSetupDL(POLY_XLU_DISP, 20);
+ }
+
+ // draw rain drops
+ for (i = 0; i < globalCtx->envCtx.unk_EE[1]; i++) {
+ vec.x = Rand_ZeroOne();
+ vec.y = Rand_ZeroOne();
+ vec.z = Rand_ZeroOne();
+
+ Matrix_Translate((vec.x - 0.7f) * 100.0f + x50, (vec.y - 0.7f) * 100.0f + y50,
+ (vec.z - 0.7f) * 100.0f + z50, MTXMODE_NEW);
+
+ temp = windDirection.x = globalCtx->envCtx.windDirection.x;
+ windDirection.y = globalCtx->envCtx.windDirection.y;
+ temp2 = windDirection.z = globalCtx->envCtx.windDirection.z;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80074CE8.s")
+ tempY = windDirection.y + 500.0f + Rand_ZeroOne() * 200.0f;
+ // float regalloc is bad around here.
+ z50 = temp2;
+ length = sqrtf(SQ(temp) + SQ(z50));
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80074D6C.s")
+ gSPMatrix(POLY_XLU_DISP++, &D_01000000, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
+ rotX = Math_Atan2F(length, -tempY);
+ rotY = Math_Atan2F(z50, temp);
+ Matrix_RotateY(-rotY, MTXMODE_APPLY);
+ Matrix_RotateX(M_PI / 2 - rotX, MTXMODE_APPLY);
+ Matrix_Scale(0.4f, 1.2f, 0.4f, MTXMODE_APPLY);
+ gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx, "../z_kankyo.c", 2887),
+ G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
+ gSPDisplayList(POLY_XLU_DISP++, gRaindropDL);
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80074FF4.s")
+ // draw droplet rings on the ground
+ if (player->actor.world.pos.y < view->eye.y) {
+ u8 firstDone = false;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800750C0.s")
+ for (i = 0; i < globalCtx->envCtx.unk_EE[1]; i++) {
+ if (!firstDone) {
+ func_80093D84(gfxCtx);
+ gDPSetEnvColor(POLY_XLU_DISP++, 155, 155, 155, 0);
+ gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, 255, 255, 120);
+ firstDone++;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800753C4.s")
+ Matrix_Translate(func_800746DC() * 280.0f + x280, player->actor.world.pos.y + 2.0f,
+ func_800746DC() * 280.0f + z280, MTXMODE_NEW);
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8007542C.s")
+ if ((LINK_IS_ADULT && ((player->actor.world.pos.y + 2.0f - view->eye.y) > -48.0f)) ||
+ (!LINK_IS_ADULT && ((player->actor.world.pos.y + 2.0f - view->eye.y) > -30.0f))) {
+ Matrix_Scale(0.02f, 0.02f, 0.02f, MTXMODE_APPLY);
+ } else {
+ Matrix_Scale(0.1f, 0.1f, 0.1f, MTXMODE_APPLY);
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800758AC.s")
+ gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx, "../z_kankyo.c", 2940),
+ G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
+ gSPDisplayList(POLY_XLU_DISP++, gEffShockwaveDL);
+ }
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80075B44.s")
+ CLOSE_DISPS(gfxCtx, "../z_kankyo.c", 2946);
+ }
+}
+#else
+Vec3f D_8011FE70 = { 0.0f, 0.0f, 0.0f };
+Vec3f D_8011FE7C = { 0.0f, 0.0f, 0.0f };
+#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Environment_DrawRain.s")
+#endif
+
+void func_80074CE8(GlobalContext* globalCtx, u32 arg1) {
+ if ((globalCtx->envCtx.unk_BD != arg1) && (globalCtx->envCtx.unk_D8 >= 1.0f) &&
+ (globalCtx->envCtx.unk_BF == 0xFF)) {
+ if (arg1 > 30) {
+ arg1 = 0;
+ }
+
+ globalCtx->envCtx.unk_D8 = 0.0f;
+ globalCtx->envCtx.unk_BE = globalCtx->envCtx.unk_BD;
+ globalCtx->envCtx.unk_BD = arg1;
+ }
+}
+
+/**
+ * Draw color filters over the skybox. There are two filters.
+ * The first uses the global fog color, and an alpha calculated with `fogNear`.
+ * This filter draws unconditionally for skybox 29 at full alpha.
+ * (note: skybox 29 is unused in the original game)
+ * For the rest of the skyboxes it will draw if fogNear is less than 980.
+ *
+ * The second filter uses a custom color specified in `skyboxFilterColor`
+ * and can be enabled with `customSkyboxFilter`.
+ *
+ * An example usage of a filter is to dim the skybox in cloudy conditions.
+ */
+void Environment_DrawSkyboxFilters(GlobalContext* globalCtx) {
+ if (((globalCtx->skyboxId != SKYBOX_NONE) && (globalCtx->lightCtx.fogNear < 980)) ||
+ (globalCtx->skyboxId == SKYBOX_UNSET_1D)) {
+ f32 alpha;
+
+ OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 3032);
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80075E68.s")
+ func_800938B4(globalCtx->state.gfxCtx);
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Kankyo_InitGameOverLights.s")
+ alpha = (1000 - globalCtx->lightCtx.fogNear) * 0.02f;
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Kankyo_FadeInGameOverLights.s")
+ if (globalCtx->skyboxId == SKYBOX_UNSET_1D) {
+ alpha = 1.0f;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Kankyo_FadeOutGameOverLights.s")
+ if (alpha > 1.0f) {
+ alpha = 1.0f;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800766C4.s")
+ gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, globalCtx->lightCtx.fogColor[0], globalCtx->lightCtx.fogColor[1],
+ globalCtx->lightCtx.fogColor[2], 255.0f * alpha);
+ gDPFillRectangle(POLY_OPA_DISP++, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_8007672C.s")
+ CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 3043);
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80076934.s")
+ if (globalCtx->envCtx.customSkyboxFilter) {
+ OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 3048);
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800773A8.s")
+ func_800938B4(globalCtx->state.gfxCtx);
+ gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, globalCtx->envCtx.skyboxFilterColor[0],
+ globalCtx->envCtx.skyboxFilterColor[1], globalCtx->envCtx.skyboxFilterColor[2],
+ globalCtx->envCtx.skyboxFilterColor[3]);
+ gDPFillRectangle(POLY_OPA_DISP++, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
-s32 func_800775CC() {
- return gSaveContext.unk_18;
+ CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 3056);
+ }
}
-void func_800775D8() {
- gSaveContext.unk_18 = 0;
+void Environment_DrawLightningFlash(GlobalContext* globalCtx, u8 red, u8 green, u8 blue, u8 alpha) {
+ OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 3069);
+
+ func_800938B4(globalCtx->state.gfxCtx);
+ gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, red, green, blue, alpha);
+ gDPFillRectangle(POLY_OPA_DISP++, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
+
+ CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 3079);
}
-s32 func_800775E4() {
- return gSaveContext.numDays;
+void Environment_UpdateLightningStrike(GlobalContext* globalCtx) {
+ if (globalCtx->envCtx.lightningMode != LIGHTNING_MODE_OFF) {
+ switch (gLightningStrike.state) {
+ case LIGHTNING_STRIKE_WAIT:
+ // every frame theres a 10% chance of the timer advancing 50 units
+ if (Rand_ZeroOne() < 0.1f) {
+ gLightningStrike.delayTimer += 50.0f;
+ }
+
+ gLightningStrike.delayTimer += Rand_ZeroOne();
+
+ if (gLightningStrike.delayTimer > 500.0f) {
+ gLightningStrike.flashRed = 200;
+ gLightningStrike.flashGreen = 200;
+ gLightningStrike.flashBlue = 255;
+ gLightningStrike.flashAlphaTarget = 200;
+
+ gLightningStrike.delayTimer = 0.0f;
+ Environment_AddLightningBolts(globalCtx,
+ (u8)(Rand_ZeroOne() * (ARRAY_COUNT(sLightningBolts) - 0.1f)) + 1);
+ sLightningFlashAlpha = 0;
+ gLightningStrike.state++;
+ }
+ break;
+ case LIGHTNING_STRIKE_START:
+ gLightningStrike.flashRed = 200;
+ gLightningStrike.flashGreen = 200;
+ gLightningStrike.flashBlue = 255;
+
+ globalCtx->envCtx.adjAmbientColor[0] += 80;
+ globalCtx->envCtx.adjAmbientColor[1] += 80;
+ globalCtx->envCtx.adjAmbientColor[2] += 100;
+
+ sLightningFlashAlpha += 100;
+
+ if (sLightningFlashAlpha >= gLightningStrike.flashAlphaTarget) {
+ func_800F6D58(15, 0, 0);
+ gLightningStrike.state++;
+ gLightningStrike.flashAlphaTarget = 0;
+ }
+ break;
+ case LIGHTNING_STRIKE_END:
+ if (globalCtx->envCtx.adjAmbientColor[0] > 0) {
+ globalCtx->envCtx.adjAmbientColor[0] -= 10;
+ globalCtx->envCtx.adjAmbientColor[1] -= 10;
+ }
+
+ if (globalCtx->envCtx.adjAmbientColor[2] > 0) {
+ globalCtx->envCtx.adjAmbientColor[2] -= 10;
+ }
+
+ sLightningFlashAlpha -= 10;
+
+ if (sLightningFlashAlpha <= gLightningStrike.flashAlphaTarget) {
+ globalCtx->envCtx.adjAmbientColor[0] = 0;
+ globalCtx->envCtx.adjAmbientColor[1] = 0;
+ globalCtx->envCtx.adjAmbientColor[2] = 0;
+
+ gLightningStrike.state = LIGHTNING_STRIKE_WAIT;
+
+ if (globalCtx->envCtx.lightningMode == LIGHTNING_MODE_LAST) {
+ globalCtx->envCtx.lightningMode = LIGHTNING_MODE_OFF;
+ }
+ }
+ break;
+ }
+ }
+
+ if (gLightningStrike.state != LIGHTNING_STRIKE_WAIT) {
+ Environment_DrawLightningFlash(globalCtx, gLightningStrike.flashRed, gLightningStrike.flashGreen,
+ gLightningStrike.flashBlue, sLightningFlashAlpha);
+ }
+}
+
+/**
+ * Request the number of lightning bolts specified by `num`
+ * Note: only 3 lightning bolts can be active at the same time.
+ */
+void Environment_AddLightningBolts(GlobalContext* globalCtx, u8 num) {
+ s16 boltsAdded = 0;
+ s16 i;
+
+ for (i = 0; i < ARRAY_COUNT(sLightningBolts); i++) {
+ if (sLightningBolts[i].state == LIGHTNING_BOLT_INACTIVE) {
+ sLightningBolts[i].state = LIGHTNING_BOLT_START;
+ boltsAdded++;
+
+ if (boltsAdded >= num) {
+ break;
+ }
+ }
+ }
+}
+
+/**
+ * Draw any active lightning bolt entries contained in `sLightningBolts`
+ */
+void Environment_DrawLightning(GlobalContext* globalCtx, s32 unused) {
+ static void* lightningTextures[] = {
+ gEffLightning1Tex, gEffLightning2Tex, gEffLightning3Tex,
+ gEffLightning4Tex, gEffLightning5Tex, gEffLightning6Tex,
+ gEffLightning7Tex, gEffLightning8Tex, NULL,
+ };
+ s16 i;
+ f32 dx;
+ f32 dz;
+ f32 x;
+ f32 z;
+ s32 pad[2];
+ Vec3f unused1 = { 0.0f, 0.0f, 0.0f };
+ Vec3f unused2 = { 0.0f, 0.0f, 0.0f };
+
+ OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 3253);
+
+ for (i = 0; i < ARRAY_COUNT(sLightningBolts); i++) {
+ switch (sLightningBolts[i].state) {
+ case LIGHTNING_BOLT_START:
+ dx = globalCtx->view.lookAt.x - globalCtx->view.eye.x;
+ dz = globalCtx->view.lookAt.z - globalCtx->view.eye.z;
+
+ x = dx / sqrtf(SQ(dx) + SQ(dz));
+ z = dz / sqrtf(SQ(dx) + SQ(dz));
+
+ sLightningBolts[i].pos.x = globalCtx->view.eye.x + x * 9500.0f;
+ sLightningBolts[i].pos.y = Rand_ZeroOne() * 1000.0f + 4000.0f;
+ sLightningBolts[i].pos.z = globalCtx->view.eye.z + z * 9500.0f;
+
+ sLightningBolts[i].offset.x = (Rand_ZeroOne() - 0.5f) * 5000.0f;
+ sLightningBolts[i].offset.y = 0.0f;
+ sLightningBolts[i].offset.z = (Rand_ZeroOne() - 0.5f) * 5000.0f;
+
+ sLightningBolts[i].textureIndex = 0;
+ sLightningBolts[i].pitch = (Rand_ZeroOne() - 0.5f) * 40.0f;
+ sLightningBolts[i].roll = (Rand_ZeroOne() - 0.5f) * 40.0f;
+ sLightningBolts[i].delayTimer = 3 * (i + 1);
+ sLightningBolts[i].state++;
+ break;
+ case LIGHTNING_BOLT_WAIT:
+ sLightningBolts[i].delayTimer--;
+
+ if (sLightningBolts[i].delayTimer <= 0) {
+ sLightningBolts[i].state++;
+ }
+ break;
+ case LIGHTNING_BOLT_DRAW:
+ if (sLightningBolts[i].textureIndex < 7) {
+ sLightningBolts[i].textureIndex++;
+ } else {
+ sLightningBolts[i].state = LIGHTNING_BOLT_INACTIVE;
+ }
+ break;
+ }
+
+ if (sLightningBolts[i].state == LIGHTNING_BOLT_DRAW) {
+ Matrix_Translate(sLightningBolts[i].pos.x + sLightningBolts[i].offset.x,
+ sLightningBolts[i].pos.y + sLightningBolts[i].offset.y,
+ sLightningBolts[i].pos.z + sLightningBolts[i].offset.z, MTXMODE_NEW);
+ Matrix_RotateX(sLightningBolts[i].pitch * (M_PI / 180.0f), MTXMODE_APPLY);
+ Matrix_RotateZ(sLightningBolts[i].roll * (M_PI / 180.0f), MTXMODE_APPLY);
+ Matrix_Scale(22.0f, 100.0f, 22.0f, MTXMODE_APPLY);
+ gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, 255, 255, 128);
+ gDPSetEnvColor(POLY_XLU_DISP++, 0, 255, 255, 128);
+ gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_kankyo.c", 3333),
+ G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
+ gSPSegment(POLY_XLU_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(lightningTextures[sLightningBolts[i].textureIndex]));
+ func_80094C50(globalCtx->state.gfxCtx);
+ gSPMatrix(POLY_XLU_DISP++, &D_01000000, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
+ gSPDisplayList(POLY_XLU_DISP++, gEffLightningDL);
+ }
+ }
+
+ CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 3353);
+}
+
+void func_800758AC(GlobalContext* globalCtx) {
+ globalCtx->envCtx.unk_E0 = 0xFF;
+
+ // both lost woods exits on the bridge from kokiri to hyrule field
+ if (((void)0, gSaveContext.entranceIndex) == 0x4DE || ((void)0, gSaveContext.entranceIndex) == 0x5E0) {
+ func_800F6FB4(4);
+ } else if (((void)0, gSaveContext.unk_140E) != 0) {
+ if (!func_80077600()) {
+ Audio_QueueSeqCmd((s32)((void)0, gSaveContext.unk_140E));
+ }
+ gSaveContext.unk_140E = 0;
+ } else if (globalCtx->soundCtx.seqIndex == 0x7F) {
+ if (globalCtx->soundCtx.nightSeqIndex == 0x13) {
+ return;
+ }
+ if (((void)0, gSaveContext.nightSeqIndex) != globalCtx->soundCtx.nightSeqIndex) {
+ func_800F6FB4(globalCtx->soundCtx.nightSeqIndex);
+ }
+ } else if (globalCtx->soundCtx.nightSeqIndex == 0x13) {
+ // "BGM Configuration"
+ osSyncPrintf("\n\n\nBGM設定game_play->sound_info.BGM=[%d] old_bgm=[%d]\n\n", globalCtx->soundCtx.seqIndex,
+ ((void)0, gSaveContext.seqIndex));
+ if (((void)0, gSaveContext.seqIndex) != globalCtx->soundCtx.seqIndex) {
+ func_800F5550(globalCtx->soundCtx.seqIndex);
+ }
+ } else if (((void)0, gSaveContext.dayTime) > 0x4AAA && ((void)0, gSaveContext.dayTime) < 0xB71D) {
+ if (((void)0, gSaveContext.seqIndex) != globalCtx->soundCtx.seqIndex) {
+ func_800F5550(globalCtx->soundCtx.seqIndex);
+ }
+
+ globalCtx->envCtx.unk_E0 = 1;
+ } else {
+ if (((void)0, gSaveContext.nightSeqIndex) != globalCtx->soundCtx.nightSeqIndex) {
+ func_800F6FB4(globalCtx->soundCtx.nightSeqIndex);
+ }
+
+ if (((void)0, gSaveContext.dayTime) > 0xB71C && ((void)0, gSaveContext.dayTime) < 0xCAAC) {
+ globalCtx->envCtx.unk_E0 = 3;
+ } else if (((void)0, gSaveContext.dayTime) > 0xCAAC || ((void)0, gSaveContext.dayTime) < 0x4555) {
+ globalCtx->envCtx.unk_E0 = 5;
+ } else {
+ globalCtx->envCtx.unk_E0 = 7;
+ }
+ }
+
+ osSyncPrintf("\n-----------------\n", ((void)0, gSaveContext.unk_140E));
+ osSyncPrintf("\n 強制BGM=[%d]", ((void)0, gSaveContext.unk_140E)); // "Forced BGM"
+ osSyncPrintf("\n BGM=[%d]", globalCtx->soundCtx.seqIndex);
+ osSyncPrintf("\n エンブ=[%d]", globalCtx->soundCtx.nightSeqIndex);
+ osSyncPrintf("\n status=[%d]", globalCtx->envCtx.unk_E0);
+
+ Audio_SetEnvReverb(globalCtx->roomCtx.curRoom.echo);
+}
+
+// updates bgm/sfx and other things as the day progresses
+void func_80075B44(GlobalContext* globalCtx) {
+ switch (globalCtx->envCtx.unk_E0) {
+ case 0:
+ func_800F6D58(86, 1, 0);
+ if (globalCtx->envCtx.unk_EE[0] == 0 && globalCtx->envCtx.unk_F2[0] == 0) {
+ osSyncPrintf("\n\n\nNa_StartMorinigBgm\n\n");
+ func_800F5510(globalCtx->soundCtx.seqIndex);
+ }
+ globalCtx->envCtx.unk_E0++;
+ break;
+ case 1:
+ if (gSaveContext.dayTime > 0xB71C) {
+ if (globalCtx->envCtx.unk_EE[0] == 0 && globalCtx->envCtx.unk_F2[0] == 0) {
+ Audio_QueueSeqCmd(0x10F000FF);
+ }
+ globalCtx->envCtx.unk_E0++;
+ }
+ break;
+ case 2:
+ if (gSaveContext.dayTime > 0xC000) {
+ func_800788CC(NA_SE_EV_DOG_CRY_EVENING);
+ globalCtx->envCtx.unk_E0++;
+ }
+ break;
+ case 3:
+ if (globalCtx->envCtx.unk_EE[0] == 0 && globalCtx->envCtx.unk_F2[0] == 0) {
+ func_800F6FB4(globalCtx->soundCtx.nightSeqIndex);
+ func_800F6D58(1, 1, 1);
+ }
+ globalCtx->envCtx.unk_E0++;
+ break;
+ case 4:
+ if (gSaveContext.dayTime > 0xCAAB) {
+ globalCtx->envCtx.unk_E0++;
+ }
+ break;
+ case 5:
+ func_800F6D58(1, 1, 0);
+ if (globalCtx->envCtx.unk_EE[0] == 0 && globalCtx->envCtx.unk_F2[0] == 0) {
+ func_800F6D58(36, 1, 1);
+ }
+ globalCtx->envCtx.unk_E0++;
+ break;
+ case 6:
+ if ((gSaveContext.dayTime < 0xCAAC) && (gSaveContext.dayTime > 0x4555)) {
+ gSaveContext.totalDays++;
+ gSaveContext.bgsDayCount++;
+ gSaveContext.dogIsLost = true;
+ func_80078884(NA_SE_EV_CHICKEN_CRY_M);
+ if ((Inventory_ReplaceItem(globalCtx, ITEM_WEIRD_EGG, ITEM_CHICKEN) ||
+ Inventory_ReplaceItem(globalCtx, ITEM_POCKET_EGG, ITEM_POCKET_CUCCO)) &&
+ globalCtx->csCtx.state == 0 && !Player_InCsMode(globalCtx)) {
+ func_8010B680(globalCtx, 0x3066, NULL);
+ }
+ globalCtx->envCtx.unk_E0++;
+ }
+ break;
+ case 7:
+ func_800F6D58(36, 1, 0);
+ if (globalCtx->envCtx.unk_EE[0] == 0 && globalCtx->envCtx.unk_F2[0] == 0) {
+ func_800F6D58(86, 1, 1);
+ }
+ globalCtx->envCtx.unk_E0++;
+ break;
+ case 8:
+ if (gSaveContext.dayTime > 0x4AAB) {
+ globalCtx->envCtx.unk_E0 = 0;
+ }
+ break;
+ }
+}
+
+void Environment_DrawCustomLensFlare(GlobalContext* globalCtx) {
+ Vec3f pos;
+
+ if (gCustomLensFlareOn) {
+ pos.x = gCustomLensFlarePos.x;
+ pos.y = gCustomLensFlarePos.y;
+ pos.z = gCustomLensFlarePos.z;
+
+ Environment_DrawLensFlare(globalCtx, &globalCtx->envCtx, &globalCtx->view, globalCtx->state.gfxCtx, pos,
+ D_8015FD04, D_8015FD06, D_8015FD08, D_8015FD0C, 0);
+ }
+}
+
+void Environment_InitGameOverLights(GlobalContext* globalCtx) {
+ s32 pad;
+ Player* player = GET_PLAYER(globalCtx);
+
+ sGameOverLightsIntensity = 0;
+
+ Lights_PointNoGlowSetInfo(&sNGameOverLightInfo, (s16)player->actor.world.pos.x - 10.0f,
+ (s16)player->actor.world.pos.y + 10.0f, (s16)player->actor.world.pos.z - 10.0f, 0, 0, 0,
+ 255);
+ sNGameOverLightNode = LightContext_InsertLight(globalCtx, &globalCtx->lightCtx, &sNGameOverLightInfo);
+
+ Lights_PointNoGlowSetInfo(&sSGameOverLightInfo, (s16)player->actor.world.pos.x + 10.0f,
+ (s16)player->actor.world.pos.y + 10.0f, (s16)player->actor.world.pos.z + 10.0f, 0, 0, 0,
+ 255);
+ sSGameOverLightNode = LightContext_InsertLight(globalCtx, &globalCtx->lightCtx, &sSGameOverLightInfo);
+}
+
+void Environment_FadeInGameOverLights(GlobalContext* globalCtx) {
+ Player* player = GET_PLAYER(globalCtx);
+ s16 i;
+
+ Lights_PointNoGlowSetInfo(&sNGameOverLightInfo, (s16)player->actor.world.pos.x - 10.0f,
+ (s16)player->actor.world.pos.y + 10.0f, (s16)player->actor.world.pos.z - 10.0f,
+ sGameOverLightsIntensity, sGameOverLightsIntensity, sGameOverLightsIntensity, 255);
+ Lights_PointNoGlowSetInfo(&sSGameOverLightInfo, (s16)player->actor.world.pos.x + 10.0f,
+ (s16)player->actor.world.pos.y + 10.0f, (s16)player->actor.world.pos.z + 10.0f,
+ sGameOverLightsIntensity, sGameOverLightsIntensity, sGameOverLightsIntensity, 255);
+
+ if (sGameOverLightsIntensity < 254) {
+ sGameOverLightsIntensity += 2;
+ }
+
+ if (func_800C0CB8(globalCtx)) {
+ for (i = 0; i < 3; i++) {
+ if (globalCtx->envCtx.adjAmbientColor[i] > -255) {
+ globalCtx->envCtx.adjAmbientColor[i] -= 12;
+ globalCtx->envCtx.adjLight1Color[i] -= 12;
+ }
+ globalCtx->envCtx.adjFogColor[i] = -255;
+ }
+
+ if (globalCtx->envCtx.lightSettings.fogFar + globalCtx->envCtx.adjFogFar > 900) {
+ globalCtx->envCtx.adjFogFar -= 100;
+ }
+
+ if (globalCtx->envCtx.lightSettings.fogNear + globalCtx->envCtx.adjFogNear > 950) {
+ globalCtx->envCtx.adjFogNear -= 10;
+ }
+ } else {
+ globalCtx->envCtx.fillScreen = true;
+ globalCtx->envCtx.screenFillColor[0] = 0;
+ globalCtx->envCtx.screenFillColor[1] = 0;
+ globalCtx->envCtx.screenFillColor[2] = 0;
+ globalCtx->envCtx.screenFillColor[3] = sGameOverLightsIntensity;
+ }
+}
+
+void Environment_FadeOutGameOverLights(GlobalContext* globalCtx) {
+ Player* player = GET_PLAYER(globalCtx);
+ s16 i;
+
+ if (sGameOverLightsIntensity >= 3) {
+ sGameOverLightsIntensity -= 3;
+ } else {
+ sGameOverLightsIntensity = 0;
+ }
+
+ if (sGameOverLightsIntensity == 1) {
+ LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, sNGameOverLightNode);
+ LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, sSGameOverLightNode);
+ } else if (sGameOverLightsIntensity >= 2) {
+ Lights_PointNoGlowSetInfo(&sNGameOverLightInfo, (s16)player->actor.world.pos.x - 10.0f,
+ (s16)player->actor.world.pos.y + 10.0f, (s16)player->actor.world.pos.z - 10.0f,
+ sGameOverLightsIntensity, sGameOverLightsIntensity, sGameOverLightsIntensity, 255);
+ Lights_PointNoGlowSetInfo(&sSGameOverLightInfo, (s16)player->actor.world.pos.x + 10.0f,
+ (s16)player->actor.world.pos.y + 10.0f, (s16)player->actor.world.pos.z + 10.0f,
+ sGameOverLightsIntensity, sGameOverLightsIntensity, sGameOverLightsIntensity, 255);
+ }
+
+ if (func_800C0CB8(globalCtx)) {
+ for (i = 0; i < 3; i++) {
+ Math_SmoothStepToS(&globalCtx->envCtx.adjAmbientColor[i], 0, 5, 12, 1);
+ Math_SmoothStepToS(&globalCtx->envCtx.adjLight1Color[i], 0, 5, 12, 1);
+ globalCtx->envCtx.adjFogColor[i] = 0;
+ }
+ globalCtx->envCtx.adjFogFar = 0;
+ globalCtx->envCtx.adjFogNear = 0;
+ } else {
+ globalCtx->envCtx.fillScreen = true;
+ globalCtx->envCtx.screenFillColor[0] = 0;
+ globalCtx->envCtx.screenFillColor[1] = 0;
+ globalCtx->envCtx.screenFillColor[2] = 0;
+ globalCtx->envCtx.screenFillColor[3] = sGameOverLightsIntensity;
+ if (sGameOverLightsIntensity == 0) {
+ globalCtx->envCtx.fillScreen = false;
+ }
+ }
+}
+
+void func_800766C4(GlobalContext* globalCtx) {
+ u8 max = MAX(globalCtx->envCtx.unk_EE[0], globalCtx->envCtx.unk_F2[0]);
+
+ if (globalCtx->envCtx.unk_EE[1] != max && ((globalCtx->state.frames % 8) == 0)) {
+ if (globalCtx->envCtx.unk_EE[1] < max) {
+ globalCtx->envCtx.unk_EE[1] += 2;
+ } else {
+ globalCtx->envCtx.unk_EE[1] -= 2;
+ }
+ }
+}
+
+void Environment_FillScreen(GraphicsContext* gfxCtx, u8 red, u8 green, u8 blue, u8 alpha, u8 drawFlags) {
+ if (alpha != 0) {
+ OPEN_DISPS(gfxCtx, "../z_kankyo.c", 3835);
+
+ if (drawFlags & FILL_SCREEN_OPA) {
+ POLY_OPA_DISP = func_800937C0(POLY_OPA_DISP);
+ gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, red, green, blue, alpha);
+ gDPSetAlphaDither(POLY_OPA_DISP++, G_AD_DISABLE);
+ gDPSetColorDither(POLY_OPA_DISP++, G_CD_DISABLE);
+ gDPFillRectangle(POLY_OPA_DISP++, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
+ }
+
+ if (drawFlags & FILL_SCREEN_XLU) {
+ POLY_XLU_DISP = func_800937C0(POLY_XLU_DISP);
+ gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, red, green, blue, alpha);
+
+ if ((u32)alpha == 255) {
+ gDPSetRenderMode(POLY_XLU_DISP++, G_RM_OPA_SURF, G_RM_OPA_SURF2);
+ }
+
+ gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_DISABLE);
+ gDPSetColorDither(POLY_XLU_DISP++, G_CD_DISABLE);
+ gDPFillRectangle(POLY_XLU_DISP++, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
+ }
+
+ CLOSE_DISPS(gfxCtx, "../z_kankyo.c", 3863);
+ }
+}
+
+Color_RGB8 sSandstormPrimColors[] = {
+ { 210, 156, 85 },
+ { 255, 200, 100 },
+ { 225, 160, 50 },
+ { 105, 90, 40 },
+};
+
+Color_RGB8 sSandstormEnvColors[] = {
+ { 155, 106, 35 },
+ { 200, 150, 50 },
+ { 170, 110, 0 },
+ { 50, 40, 0 },
+};
+
+void Environment_DrawSandstorm(GlobalContext* globalCtx, u8 sandstormState) {
+ s32 primA1;
+ s32 envA1;
+ s32 primA = globalCtx->envCtx.sandstormPrimA;
+ s32 envA = globalCtx->envCtx.sandstormEnvA;
+ Color_RGBA8 primColor;
+ Color_RGBA8 envColor;
+ s32 pad;
+ f32 sp98;
+ u16 sp96;
+ u16 sp94;
+ u16 sp92;
+
+ switch (sandstormState) {
+ case 3:
+ if ((globalCtx->sceneNum == SCENE_SPOT13) && (globalCtx->roomCtx.curRoom.num == 0)) {
+ envA1 = 0;
+ primA1 = (globalCtx->envCtx.sandstormEnvA > 128) ? 255 : globalCtx->envCtx.sandstormEnvA >> 1;
+ } else {
+ primA1 = globalCtx->state.frames % 128;
+ if (primA1 > 64) {
+ primA1 = 128 - primA1;
+ }
+ primA1 += 73;
+ envA1 = 128;
+ }
+ break;
+ case 1:
+ primA1 = 255;
+ envA1 = (globalCtx->envCtx.sandstormPrimA >= 255) ? 255 : 128;
+ break;
+ case 2:
+ envA1 = 128;
+ if (globalCtx->envCtx.sandstormEnvA > 128) {
+ primA1 = 0xFF;
+ } else {
+ primA1 = globalCtx->state.frames % 128;
+ if (primA1 > 64) {
+ primA1 = 128 - primA1;
+ }
+ primA1 += 73;
+ }
+ if ((primA1 >= primA) && (primA1 != 255)) {
+ globalCtx->envCtx.sandstormState = 3;
+ }
+ break;
+ case 4:
+ envA1 = 0;
+ primA1 = (globalCtx->envCtx.sandstormEnvA > 128) ? 255 : globalCtx->envCtx.sandstormEnvA >> 1;
+
+ if (primA == 0) {
+ globalCtx->envCtx.sandstormState = 0;
+ }
+ break;
+ }
+
+ if (ABS(primA - primA1) < 9) {
+ primA = primA1;
+ } else if (primA1 < primA) {
+ primA = primA - 9;
+ } else {
+ primA = primA + 9;
+ }
+ if (ABS(envA - envA1) < 9) {
+ envA = envA1;
+ } else if (envA1 < envA) {
+ envA = envA - 9;
+ } else {
+ envA = envA + 9;
+ }
+ globalCtx->envCtx.sandstormPrimA = primA;
+ globalCtx->envCtx.sandstormEnvA = envA;
+
+ sp98 = (512.0f - (primA + envA)) * (3.0f / 128.0f);
+ if (sp98 > 6.0f) {
+ sp98 = 6.0f;
+ }
+ if (globalCtx->envCtx.indoors || (globalCtx->envCtx.unk_BF != 0xFF)) {
+ primColor.r = sSandstormPrimColors[1].r;
+ primColor.g = sSandstormPrimColors[1].g;
+ primColor.b = sSandstormPrimColors[1].b;
+ envColor.r = sSandstormEnvColors[1].r;
+ envColor.g = sSandstormEnvColors[1].g;
+ envColor.b = sSandstormEnvColors[1].b;
+ } else if (D_8011FDCC == D_8011FDD0) {
+ primColor.r = sSandstormPrimColors[D_8011FDCC].r;
+ primColor.g = sSandstormPrimColors[D_8011FDCC].g;
+ primColor.b = sSandstormPrimColors[D_8011FDCC].b;
+ envColor.r = sSandstormEnvColors[D_8011FDCC].r;
+ envColor.g = sSandstormEnvColors[D_8011FDCC].g;
+ envColor.b = sSandstormEnvColors[D_8011FDCC].b;
+ } else {
+ primColor.r = (s32)F32_LERP(sSandstormPrimColors[D_8011FDCC].r, sSandstormPrimColors[D_8011FDD0].r, D_8011FDD4);
+ primColor.g = (s32)F32_LERP(sSandstormPrimColors[D_8011FDCC].g, sSandstormPrimColors[D_8011FDD0].g, D_8011FDD4);
+ primColor.b = (s32)F32_LERP(sSandstormPrimColors[D_8011FDCC].b, sSandstormPrimColors[D_8011FDD0].b, D_8011FDD4);
+ envColor.r = (s32)F32_LERP(sSandstormEnvColors[D_8011FDCC].r, sSandstormEnvColors[D_8011FDD0].r, D_8011FDD4);
+ envColor.g = (s32)F32_LERP(sSandstormEnvColors[D_8011FDCC].g, sSandstormEnvColors[D_8011FDD0].g, D_8011FDD4);
+ envColor.b = (s32)F32_LERP(sSandstormEnvColors[D_8011FDCC].b, sSandstormEnvColors[D_8011FDD0].b, D_8011FDD4);
+ }
+
+ envColor.r = ((envColor.r * sp98) + ((6.0f - sp98) * primColor.r)) * (1.0f / 6.0f);
+ envColor.g = ((envColor.g * sp98) + ((6.0f - sp98) * primColor.g)) * (1.0f / 6.0f);
+ envColor.b = ((envColor.b * sp98) + ((6.0f - sp98) * primColor.b)) * (1.0f / 6.0f);
+
+ sp96 = (s32)(D_8015FDB0 * (11.0f / 6.0f));
+ sp94 = (s32)(D_8015FDB0 * (9.0f / 6.0f));
+ sp92 = (s32)(D_8015FDB0 * (6.0f / 6.0f));
+
+ OPEN_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 4044);
+
+ POLY_XLU_DISP = func_80093F34(POLY_XLU_DISP);
+ gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_NOISE);
+ gDPSetColorDither(POLY_XLU_DISP++, G_CD_NOISE);
+ gDPSetPrimColor(POLY_XLU_DISP++, 0, 0x80, primColor.r, primColor.g, primColor.b, globalCtx->envCtx.sandstormPrimA);
+ gDPSetEnvColor(POLY_XLU_DISP++, envColor.r, envColor.g, envColor.b, globalCtx->envCtx.sandstormEnvA);
+ gSPSegment(POLY_XLU_DISP++, 0x08,
+ Gfx_TwoTexScroll(globalCtx->state.gfxCtx, 0, (u32)sp96 % 0x1000, 0, 0x200, 0x20, 1, (u32)sp94 % 0x1000,
+ 0xFFF - ((u32)sp92 % 0x1000), 0x100, 0x40));
+ gDPSetTextureLUT(POLY_XLU_DISP++, G_TT_NONE);
+ gSPDisplayList(POLY_XLU_DISP++, gFieldSandstormDL);
+
+ CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_kankyo.c", 4068);
+
+ D_8015FDB0 += (s32)sp98;
+}
+
+void Environment_AdjustLights(GlobalContext* globalCtx, f32 arg1, f32 arg2, f32 arg3, f32 arg4) {
+ f32 temp;
+ s32 i;
+
+ if (globalCtx->roomCtx.curRoom.unk_03 != 5 && func_800C0CB8(globalCtx)) {
+ arg1 = CLAMP_MIN(arg1, 0.0f);
+ arg1 = CLAMP_MAX(arg1, 1.0f);
+
+ temp = arg1 - arg3;
+ if (arg1 < arg3) {
+ temp = 0.0f;
+ }
+
+ globalCtx->envCtx.adjFogNear = (arg2 - globalCtx->envCtx.lightSettings.fogNear) * temp;
+
+ if (arg1 == 0.0f) {
+ for (i = 0; i < 3; i++) {
+ globalCtx->envCtx.adjFogColor[i] = 0;
+ }
+ } else {
+ temp = arg1 * 5.0f;
+ temp = CLAMP_MAX(temp, 1.0f);
+
+ for (i = 0; i < 3; i++) {
+ globalCtx->envCtx.adjFogColor[i] = -(s16)(globalCtx->envCtx.lightSettings.fogColor[i] * temp);
+ }
+ }
+
+ if (arg4 <= 0.0f) {
+ return;
+ }
+
+ arg1 *= arg4;
+
+ for (i = 0; i < 3; i++) {
+ globalCtx->envCtx.adjAmbientColor[i] = -(s16)(globalCtx->envCtx.lightSettings.ambientColor[i] * arg1);
+ globalCtx->envCtx.adjLight1Color[i] = -(s16)(globalCtx->envCtx.lightSettings.light1Color[i] * arg1);
+ }
+ }
+}
+
+s32 Environment_GetBgsDayCount(void) {
+ return gSaveContext.bgsDayCount;
+}
+
+void Environment_ClearBgsDayCount(void) {
+ gSaveContext.bgsDayCount = 0;
+}
+
+s32 Environment_GetTotalDays(void) {
+ return gSaveContext.totalDays;
}
void func_800775F0(u16 arg0) {
gSaveContext.unk_140E = arg0;
}
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80077600.s")
+s32 func_80077600(void) {
+ s32 ret = false;
+
+ if (gSaveContext.unk_140E == 0xFFFF) {
+ ret = true;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80077624.s")
+ return ret;
+}
+
+void func_80077624(GlobalContext* globalCtx) {
+ if (globalCtx->soundCtx.nightSeqIndex == 19) {
+ func_800F6FB4(5);
+ } else {
+ func_800F6FB4(globalCtx->soundCtx.nightSeqIndex);
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_80077684.s")
+ func_800F6D58(14, 1, 1);
+ func_800F6D58(15, 1, 1);
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/func_800776E4.s")
+void func_80077684(GlobalContext* globalCtx) {
+ func_800F6D58(14, 1, 0);
+ func_800F6D58(15, 1, 0);
+
+ if (func_800FA0B4(0) == 1) {
+ gSaveContext.seqIndex = 0x80;
+ func_800758AC(globalCtx);
+ }
+}
+
+void Environment_WarpSongLeave(GlobalContext* globalCtx) {
+ gWeatherMode = 0;
+ gSaveContext.cutsceneIndex = 0;
+ gSaveContext.respawnFlag = -3;
+ globalCtx->nextEntranceIndex = gSaveContext.respawn[RESPAWN_MODE_RETURN].entranceIndex;
+ globalCtx->sceneLoadFlag = 0x14;
+ globalCtx->fadeTransition = 3;
+ gSaveContext.nextTransition = 3;
+
+ switch (globalCtx->nextEntranceIndex) {
+ case 0x147:
+ Flags_SetEventChkInf(0xB9);
+ break;
+ case 0x0102:
+ Flags_SetEventChkInf(0xB1);
+ break;
+ case 0x0123:
+ Flags_SetEventChkInf(0xB8);
+ break;
+ case 0x00E4:
+ Flags_SetEventChkInf(0xB6);
+ break;
+ case 0x0053:
+ Flags_SetEventChkInf(0xA7);
+ break;
+ case 0x00FC:
+ break;
+ }
+}
diff --git a/src/code/z_lights.c b/src/code/z_lights.c
index 8ea295524..3067b712b 100644
--- a/src/code/z_lights.c
+++ b/src/code/z_lights.c
@@ -198,29 +198,29 @@ s32 Lights_FreeNode(LightNode* light) {
void LightContext_Init(GlobalContext* globalCtx, LightContext* lightCtx) {
LightContext_InitList(globalCtx, lightCtx);
LightContext_SetAmbientColor(lightCtx, 80, 80, 80);
- func_8007A698(lightCtx, 0, 0, 0, 0x3E4, 0x3200);
+ LightContext_SetFog(lightCtx, 0, 0, 0, 996, 12800);
bzero(&sLightsBuffer, sizeof(sLightsBuffer));
}
void LightContext_SetAmbientColor(LightContext* lightCtx, u8 r, u8 g, u8 b) {
- lightCtx->ambient.r = r;
- lightCtx->ambient.g = g;
- lightCtx->ambient.b = b;
+ lightCtx->ambientColor[0] = r;
+ lightCtx->ambientColor[1] = g;
+ lightCtx->ambientColor[2] = b;
}
-void func_8007A698(LightContext* lightCtx, u8 arg1, u8 arg2, u8 arg3, s16 numLights, s16 arg5) {
- lightCtx->unk_07 = arg1;
- lightCtx->unk_08 = arg2;
- lightCtx->unk_09 = arg3;
- lightCtx->unk_0A = numLights;
- lightCtx->unk_0C = arg5;
+void LightContext_SetFog(LightContext* lightCtx, u8 r, u8 g, u8 b, s16 fogNear, s16 fogFar) {
+ lightCtx->fogColor[0] = r;
+ lightCtx->fogColor[1] = g;
+ lightCtx->fogColor[2] = b;
+ lightCtx->fogNear = fogNear;
+ lightCtx->fogFar = fogFar;
}
/**
* Allocate a new Lights group and initilize the ambient color with that provided by LightContext
*/
Lights* LightContext_NewLights(LightContext* lightCtx, GraphicsContext* gfxCtx) {
- return Lights_New(gfxCtx, lightCtx->ambient.r, lightCtx->ambient.g, lightCtx->ambient.b);
+ return Lights_New(gfxCtx, lightCtx->ambientColor[0], lightCtx->ambientColor[1], lightCtx->ambientColor[2]);
}
void LightContext_InitList(GlobalContext* globalCtx, LightContext* lightCtx) {
diff --git a/src/code/z_map_exp.c b/src/code/z_map_exp.c
index fe13ea767..0aedbe8cd 100644
--- a/src/code/z_map_exp.c
+++ b/src/code/z_map_exp.c
@@ -212,8 +212,8 @@ void Map_InitRoomData(GlobalContext* globalCtx, s16 room) {
interfaceCtx->mapRoomNum = 0;
}
- if (gSaveContext.unk_1422 != 2) {
- gSaveContext.unk_1422 = 0;
+ if (gSaveContext.sunsSongState != SUNSSONG_SPEED_TIME) {
+ gSaveContext.sunsSongState = SUNSSONG_INACTIVE;
}
}
@@ -559,7 +559,7 @@ void Map_Update(GlobalContext* globalCtx) {
osSyncPrintf("階層切替=%x\n", interfaceCtx->mapRoomNum);
osSyncPrintf(VT_RST);
Map_InitData(globalCtx, interfaceCtx->mapRoomNum);
- gSaveContext.unk_1422 = 0;
+ gSaveContext.sunsSongState = SUNSSONG_INACTIVE;
Map_SavePlayerInitialInfo(globalCtx);
}
}
diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c
index 8e3dda4c8..e896cddcc 100644
--- a/src/code/z_parameter.c
+++ b/src/code/z_parameter.c
@@ -3789,7 +3789,7 @@ void Interface_Draw(GlobalContext* globalCtx) {
void Interface_Update(GlobalContext* globalCtx) {
static u8 D_80125B60 = 0;
- static s16 D_80125B64 = 0;
+ static s16 sPrevTimeIncrement = 0;
MessageContext* msgCtx = &globalCtx->msgCtx;
InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx;
Player* player = GET_PLAYER(globalCtx);
@@ -4098,30 +4098,32 @@ void Interface_Update(GlobalContext* globalCtx) {
}
}
- if (gSaveContext.unk_1422 != 0) {
- if ((msgCtx->unk_E3F0 != 0x31) && (gSaveContext.unk_1422 == 1)) {
+ if (gSaveContext.sunsSongState != SUNSSONG_INACTIVE) {
+ // exit out of ocarina mode after suns song finishes playing
+ if ((msgCtx->unk_E3F0 != 0x31) && (gSaveContext.sunsSongState == SUNSSONG_START)) {
globalCtx->msgCtx.unk_E3EE = 4;
}
- if (globalCtx->envCtx.unk_02 != 0) {
- if (gSaveContext.unk_1422 != 2) {
+ // handle suns song in areas where time moves
+ if (globalCtx->envCtx.timeIncrement != 0) {
+ if (gSaveContext.sunsSongState != SUNSSONG_SPEED_TIME) {
D_80125B60 = 0;
if ((gSaveContext.dayTime >= 0x4555) && (gSaveContext.dayTime <= 0xC001)) {
D_80125B60 = 1;
}
- gSaveContext.unk_1422 = 2;
- D_80125B64 = D_8011FB40;
- D_8011FB40 = 400;
+ gSaveContext.sunsSongState = SUNSSONG_SPEED_TIME;
+ sPrevTimeIncrement = gTimeIncrement;
+ gTimeIncrement = 400;
} else if (D_80125B60 == 0) {
if ((gSaveContext.dayTime >= 0x4555) && (gSaveContext.dayTime <= 0xC001)) {
- gSaveContext.unk_1422 = 0;
- D_8011FB40 = D_80125B64;
+ gSaveContext.sunsSongState = SUNSSONG_INACTIVE;
+ gTimeIncrement = sPrevTimeIncrement;
globalCtx->msgCtx.unk_E3EE = 4;
}
} else if (gSaveContext.dayTime > 0xC001) {
- gSaveContext.unk_1422 = 0;
- D_8011FB40 = D_80125B64;
+ gSaveContext.sunsSongState = SUNSSONG_INACTIVE;
+ gTimeIncrement = sPrevTimeIncrement;
globalCtx->msgCtx.unk_E3EE = 4;
}
} else if ((globalCtx->roomCtx.curRoom.unk_03 != 1) && (interfaceCtx->restrictions.sunsSong != 3)) {
@@ -4145,12 +4147,12 @@ void Interface_Update(GlobalContext* globalCtx) {
gSaveContext.respawnFlag = -2;
globalCtx->nextEntranceIndex = gSaveContext.entranceIndex;
globalCtx->sceneLoadFlag = 0x14;
- gSaveContext.unk_1422 = 0;
+ gSaveContext.sunsSongState = SUNSSONG_INACTIVE;
func_800F6964(30);
gSaveContext.seqIndex = 0xFF;
gSaveContext.nightSeqIndex = 0xFF;
} else {
- gSaveContext.unk_1422 = 3;
+ gSaveContext.sunsSongState = SUNSSONG_SPECIAL;
}
}
}
diff --git a/src/code/z_play.c b/src/code/z_play.c
index 52f72c83d..6d45532ae 100644
--- a/src/code/z_play.c
+++ b/src/code/z_play.c
@@ -135,9 +135,9 @@ void func_800BC88C(GlobalContext* globalCtx) {
globalCtx->transitionCtx.transitionType = -1;
}
-Gfx* func_800BC8A0(GlobalContext* globalCtx, Gfx* gfx) {
- return Gfx_SetFog2(gfx, globalCtx->lightCtx.unk_07, globalCtx->lightCtx.unk_08, globalCtx->lightCtx.unk_09, 0,
- globalCtx->lightCtx.unk_0A, 1000);
+Gfx* Gameplay_SetFog(GlobalContext* globalCtx, Gfx* gfx) {
+ return Gfx_SetFog2(gfx, globalCtx->lightCtx.fogColor[0], globalCtx->lightCtx.fogColor[1],
+ globalCtx->lightCtx.fogColor[2], 0, globalCtx->lightCtx.fogNear, 1000);
}
void Gameplay_Destroy(GameState* thisx) {
@@ -246,7 +246,7 @@ void Gameplay_Init(GameState* thisx) {
if (gSaveContext.nextDayTime != 0xFFFFU) {
gSaveContext.dayTime = gSaveContext.nextDayTime;
- gSaveContext.environmentTime = gSaveContext.nextDayTime;
+ gSaveContext.skyboxTime = gSaveContext.nextDayTime;
}
if (gSaveContext.dayTime > 0xC000 || gSaveContext.dayTime < 0x4555) {
@@ -306,8 +306,8 @@ void Gameplay_Init(GameState* thisx) {
if (gSaveContext.nextDayTime != 0xFFFF) {
if (gSaveContext.nextDayTime == 0x8001) {
- gSaveContext.numDays++;
- gSaveContext.unk_18++;
+ gSaveContext.totalDays++;
+ gSaveContext.bgsDayCount++;
gSaveContext.dogIsLost = true;
if (Inventory_ReplaceItem(globalCtx, ITEM_WEIRD_EGG, ITEM_CHICKEN) ||
Inventory_ReplaceItem(globalCtx, ITEM_POCKET_EGG, ITEM_POCKET_CUCCO)) {
@@ -606,21 +606,21 @@ void Gameplay_Update(GlobalContext* globalCtx) {
switch (globalCtx->transitionMode) {
case 4:
D_801614C8 = 0;
- globalCtx->envCtx.unk_E1 = 1;
- globalCtx->envCtx.unk_E2[0] = 0xA0;
- globalCtx->envCtx.unk_E2[1] = 0xA0;
- globalCtx->envCtx.unk_E2[2] = 0xA0;
+ globalCtx->envCtx.fillScreen = true;
+ globalCtx->envCtx.screenFillColor[0] = 160;
+ globalCtx->envCtx.screenFillColor[1] = 160;
+ globalCtx->envCtx.screenFillColor[2] = 160;
if (globalCtx->sceneLoadFlag != -0x14) {
- globalCtx->envCtx.unk_E2[3] = 0;
+ globalCtx->envCtx.screenFillColor[3] = 0;
globalCtx->transitionMode = 5;
} else {
- globalCtx->envCtx.unk_E2[3] = 0xFF;
+ globalCtx->envCtx.screenFillColor[3] = 255;
globalCtx->transitionMode = 6;
}
break;
case 5:
- globalCtx->envCtx.unk_E2[3] = (D_801614C8 / 20.0f) * 255.0f;
+ globalCtx->envCtx.screenFillColor[3] = (D_801614C8 / 20.0f) * 255.0f;
if (D_801614C8 >= 20 && 1) {
globalCtx->state.running = 0;
SET_NEXT_GAMESTATE(&globalCtx->state, Gameplay_Init, GlobalContext);
@@ -633,13 +633,13 @@ void Gameplay_Update(GlobalContext* globalCtx) {
break;
case 6:
- globalCtx->envCtx.unk_E2[3] = (1 - D_801614C8 / 20.0f) * 255.0f;
+ globalCtx->envCtx.screenFillColor[3] = (1 - D_801614C8 / 20.0f) * 255.0f;
if (D_801614C8 >= 20 && 1) {
gTrnsnUnkState = 0;
R_UPDATE_RATE = 3;
globalCtx->sceneLoadFlag = 0;
globalCtx->transitionMode = 0;
- globalCtx->envCtx.unk_E1 = 0;
+ globalCtx->envCtx.fillScreen = false;
} else {
D_801614C8++;
}
@@ -647,15 +647,15 @@ void Gameplay_Update(GlobalContext* globalCtx) {
case 7:
D_801614C8 = 0;
- globalCtx->envCtx.unk_E1 = 1;
- globalCtx->envCtx.unk_E2[0] = 0xAA;
- globalCtx->envCtx.unk_E2[1] = 0xA0;
- globalCtx->envCtx.unk_E2[2] = 0x96;
+ globalCtx->envCtx.fillScreen = true;
+ globalCtx->envCtx.screenFillColor[0] = 170;
+ globalCtx->envCtx.screenFillColor[1] = 160;
+ globalCtx->envCtx.screenFillColor[2] = 150;
if (globalCtx->sceneLoadFlag != -0x14) {
- globalCtx->envCtx.unk_E2[3] = 0;
+ globalCtx->envCtx.screenFillColor[3] = 0;
globalCtx->transitionMode = 5;
} else {
- globalCtx->envCtx.unk_E2[3] = 0xFF;
+ globalCtx->envCtx.screenFillColor[3] = 255;
globalCtx->transitionMode = 6;
}
break;
@@ -683,12 +683,12 @@ void Gameplay_Update(GlobalContext* globalCtx) {
case 12:
if (globalCtx->sceneLoadFlag != -0x14) {
- globalCtx->envCtx.unk_E6 = 1;
+ globalCtx->envCtx.sandstormState = 1;
globalCtx->transitionMode = 13;
} else {
- globalCtx->envCtx.unk_E6 = 2;
- globalCtx->envCtx.unk_E7 = 0xFF;
- globalCtx->envCtx.unk_E8 = 0xFF;
+ globalCtx->envCtx.sandstormState = 2;
+ globalCtx->envCtx.sandstormPrimA = 255;
+ globalCtx->envCtx.sandstormEnvA = 255;
globalCtx->transitionMode = 13;
}
break;
@@ -697,14 +697,14 @@ void Gameplay_Update(GlobalContext* globalCtx) {
Audio_PlaySoundGeneral(NA_SE_EV_SAND_STORM - SFX_FLAG, &D_801333D4, 4, &D_801333E0, &D_801333E0,
&D_801333E8);
if (globalCtx->sceneLoadFlag == -0x14) {
- if (globalCtx->envCtx.unk_E7 < 0x6E) {
+ if (globalCtx->envCtx.sandstormPrimA < 110) {
gTrnsnUnkState = 0;
R_UPDATE_RATE = 3;
globalCtx->sceneLoadFlag = 0;
globalCtx->transitionMode = 0;
}
} else {
- if (globalCtx->envCtx.unk_E8 == 0xFF) {
+ if (globalCtx->envCtx.sandstormEnvA == 255) {
globalCtx->state.running = 0;
SET_NEXT_GAMESTATE(&globalCtx->state, Gameplay_Init, GlobalContext);
gSaveContext.entranceIndex = globalCtx->nextEntranceIndex;
@@ -716,9 +716,9 @@ void Gameplay_Update(GlobalContext* globalCtx) {
case 14:
if (globalCtx->sceneLoadFlag == -0x14) {
- globalCtx->envCtx.unk_E6 = 4;
- globalCtx->envCtx.unk_E7 = 0xFF;
- globalCtx->envCtx.unk_E8 = 0xFF;
+ globalCtx->envCtx.sandstormState = 4;
+ globalCtx->envCtx.sandstormPrimA = 255;
+ globalCtx->envCtx.sandstormEnvA = 255;
// "It's here!!!!!!!!!"
LOG_STRING("来た!!!!!!!!!!!!!!!!!!!!!", "../z_play.c", 3471);
globalCtx->transitionMode = 15;
@@ -731,7 +731,7 @@ void Gameplay_Update(GlobalContext* globalCtx) {
Audio_PlaySoundGeneral(NA_SE_EV_SAND_STORM - SFX_FLAG, &D_801333D4, 4, &D_801333E0, &D_801333E0,
&D_801333E8);
if (globalCtx->sceneLoadFlag == -0x14) {
- if (globalCtx->envCtx.unk_E7 <= 0) {
+ if (globalCtx->envCtx.sandstormPrimA <= 0) {
gTrnsnUnkState = 0;
R_UPDATE_RATE = 3;
globalCtx->sceneLoadFlag = 0;
@@ -742,17 +742,17 @@ void Gameplay_Update(GlobalContext* globalCtx) {
case 16:
D_801614C8 = 0;
- globalCtx->envCtx.unk_E1 = 1;
- globalCtx->envCtx.unk_E2[0] = 0;
- globalCtx->envCtx.unk_E2[1] = 0;
- globalCtx->envCtx.unk_E2[2] = 0;
- globalCtx->envCtx.unk_E2[3] = 0xFF;
+ globalCtx->envCtx.fillScreen = true;
+ globalCtx->envCtx.screenFillColor[0] = 0;
+ globalCtx->envCtx.screenFillColor[1] = 0;
+ globalCtx->envCtx.screenFillColor[2] = 0;
+ globalCtx->envCtx.screenFillColor[3] = 255;
globalCtx->transitionMode = 17;
break;
case 17:
if (gSaveContext.unk_1410 != 0) {
- globalCtx->envCtx.unk_E2[3] = gSaveContext.unk_1410;
+ globalCtx->envCtx.screenFillColor[3] = gSaveContext.unk_1410;
if (gSaveContext.unk_1410 < 0x65) {
gTrnsnUnkState = 0;
R_UPDATE_RATE = 3;
@@ -813,11 +813,12 @@ void Gameplay_Update(GlobalContext* globalCtx) {
osSyncPrintf("FINISH=%d\n", globalCtx->actorCtx.freezeFlashTimer);
if ((globalCtx->actorCtx.freezeFlashTimer > 0) &&
((globalCtx->actorCtx.freezeFlashTimer % 2) != 0)) {
- globalCtx->envCtx.unk_E1 = 1;
- globalCtx->envCtx.unk_E2[0] = globalCtx->envCtx.unk_E2[1] = globalCtx->envCtx.unk_E2[2] = 150;
- globalCtx->envCtx.unk_E2[3] = 80;
+ globalCtx->envCtx.fillScreen = true;
+ globalCtx->envCtx.screenFillColor[0] = globalCtx->envCtx.screenFillColor[1] =
+ globalCtx->envCtx.screenFillColor[2] = 150;
+ globalCtx->envCtx.screenFillColor[3] = 80;
} else {
- globalCtx->envCtx.unk_E1 = 0;
+ globalCtx->envCtx.fillScreen = false;
}
} else {
if (1 && HREG(63)) {
@@ -1031,8 +1032,8 @@ skip:
LOG_NUM("1", 1, "../z_play.c", 3816);
}
- func_80070C24(globalCtx, &globalCtx->envCtx, &globalCtx->lightCtx, &globalCtx->pauseCtx, &globalCtx->msgCtx,
- &globalCtx->gameOverCtx, globalCtx->state.gfxCtx);
+ Environment_Update(globalCtx, &globalCtx->envCtx, &globalCtx->lightCtx, &globalCtx->pauseCtx, &globalCtx->msgCtx,
+ &globalCtx->gameOverCtx, globalCtx->state.gfxCtx);
}
void Gameplay_DrawOverlayElements(GlobalContext* globalCtx) {
@@ -1081,10 +1082,10 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
func_80095248(gfxCtx, 0, 0, 0);
if ((HREG(80) != 10) || (HREG(82) != 0)) {
- POLY_OPA_DISP = func_800BC8A0(globalCtx, POLY_OPA_DISP);
- POLY_XLU_DISP = func_800BC8A0(globalCtx, POLY_XLU_DISP);
+ POLY_OPA_DISP = Gameplay_SetFog(globalCtx, POLY_OPA_DISP);
+ POLY_XLU_DISP = Gameplay_SetFog(globalCtx, POLY_XLU_DISP);
- func_800AA460(&globalCtx->view, globalCtx->view.fovy, globalCtx->view.zNear, globalCtx->lightCtx.unk_0C);
+ func_800AA460(&globalCtx->view, globalCtx->view.fovy, globalCtx->view.zNear, globalCtx->lightCtx.fogFar);
func_800AAA50(&globalCtx->view, 15);
Matrix_MtxToMtxF(&globalCtx->view.viewing, &globalCtx->mf_11DA0);
@@ -1092,12 +1093,8 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
Matrix_Mult(&globalCtx->mf_11D60, MTXMODE_NEW);
Matrix_Mult(&globalCtx->mf_11DA0, MTXMODE_APPLY);
Matrix_Get(&globalCtx->mf_11D60);
- globalCtx->mf_11DA0.mf[3][2] = 0.0f;
- globalCtx->mf_11DA0.mf[3][1] = 0.0f;
- globalCtx->mf_11DA0.mf[3][0] = 0.0f;
- globalCtx->mf_11DA0.mf[2][3] = 0.0f;
- globalCtx->mf_11DA0.mf[1][3] = 0.0f;
- globalCtx->mf_11DA0.mf[0][3] = 0.0f;
+ globalCtx->mf_11DA0.mf[0][3] = globalCtx->mf_11DA0.mf[1][3] = globalCtx->mf_11DA0.mf[2][3] =
+ globalCtx->mf_11DA0.mf[3][0] = globalCtx->mf_11DA0.mf[3][1] = globalCtx->mf_11DA0.mf[3][2] = 0.0f;
Matrix_Transpose(&globalCtx->mf_11DA0);
globalCtx->unk_11DE0 = Matrix_MtxFToMtx(Matrix_CheckFloats(&globalCtx->mf_11DA0, "../z_play.c", 4005),
Graph_Alloc(gfxCtx, sizeof(Mtx)));
@@ -1165,12 +1162,12 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
if ((HREG(80) != 10) || (HREG(83) != 0)) {
if (globalCtx->skyboxId && (globalCtx->skyboxId != SKYBOX_UNSET_1D) &&
- !globalCtx->envCtx.skyDisabled) {
+ !globalCtx->envCtx.skyboxDisabled) {
if ((globalCtx->skyboxId == SKYBOX_NORMAL_SKY) ||
(globalCtx->skyboxId == SKYBOX_CUTSCENE_MAP)) {
- func_8006FC88(globalCtx->skyboxId, &globalCtx->envCtx, &globalCtx->skyboxCtx);
+ Environment_UpdateSkybox(globalCtx->skyboxId, &globalCtx->envCtx, &globalCtx->skyboxCtx);
SkyboxDraw_Draw(&globalCtx->skyboxCtx, gfxCtx, globalCtx->skyboxId,
- globalCtx->envCtx.unk_13, globalCtx->view.eye.x, globalCtx->view.eye.y,
+ globalCtx->envCtx.skyboxBlend, globalCtx->view.eye.x, globalCtx->view.eye.y,
globalCtx->view.eye.z);
} else if (globalCtx->skyboxCtx.unk_140 == 0) {
SkyboxDraw_Draw(&globalCtx->skyboxCtx, gfxCtx, globalCtx->skyboxId, 0,
@@ -1181,17 +1178,17 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
if ((HREG(80) != 10) || (HREG(90) & 2)) {
if (!globalCtx->envCtx.sunMoonDisabled) {
- func_800730DC(globalCtx);
+ Environment_DrawSunAndMoon(globalCtx);
}
}
if ((HREG(80) != 10) || (HREG(90) & 1)) {
- func_80074D6C(globalCtx);
+ Environment_DrawSkyboxFilters(globalCtx);
}
if ((HREG(80) != 10) || (HREG(90) & 4)) {
- func_800750C0(globalCtx);
- func_8007542C(globalCtx, 0);
+ Environment_UpdateLightningStrike(globalCtx);
+ Environment_DrawLightning(globalCtx, 0);
}
if ((HREG(80) != 10) || (HREG(90) & 8)) {
@@ -1226,11 +1223,11 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
}
if (globalCtx->envCtx.unk_EE[1] != 0) {
- func_80074704(globalCtx, &globalCtx->view, gfxCtx);
+ Environment_DrawRain(globalCtx, &globalCtx->view, gfxCtx);
}
if ((HREG(80) != 10) || (HREG(84) != 0)) {
- func_8007672C(gfxCtx, 0, 0, 0, globalCtx->unk_11E18, 1);
+ Environment_FillScreen(gfxCtx, 0, 0, 0, globalCtx->unk_11E18, FILL_SCREEN_OPA);
}
if ((HREG(80) != 10) || (HREG(85) != 0)) {
@@ -1239,23 +1236,26 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
if ((HREG(80) != 10) || (HREG(86) != 0)) {
if (!globalCtx->envCtx.sunMoonDisabled) {
- sp21C.x = globalCtx->view.eye.x + globalCtx->envCtx.unk_04.x;
- sp21C.y = globalCtx->view.eye.y + globalCtx->envCtx.unk_04.y;
- sp21C.z = globalCtx->view.eye.z + globalCtx->envCtx.unk_04.z;
- func_80073988(globalCtx, &globalCtx->envCtx, &globalCtx->view, gfxCtx, sp21C, 0);
+ sp21C.x = globalCtx->view.eye.x + globalCtx->envCtx.sunPos.x;
+ sp21C.y = globalCtx->view.eye.y + globalCtx->envCtx.sunPos.y;
+ sp21C.z = globalCtx->view.eye.z + globalCtx->envCtx.sunPos.z;
+ Environment_DrawSunLensFlare(globalCtx, &globalCtx->envCtx, &globalCtx->view, gfxCtx, sp21C, 0);
}
- func_80075E68(globalCtx);
+ Environment_DrawCustomLensFlare(globalCtx);
}
if ((HREG(80) != 10) || (HREG(87) != 0)) {
if (MREG(64) != 0) {
- func_8007672C(gfxCtx, MREG(65), MREG(66), MREG(67), MREG(68), 3);
+ Environment_FillScreen(gfxCtx, MREG(65), MREG(66), MREG(67), MREG(68),
+ FILL_SCREEN_OPA | FILL_SCREEN_XLU);
}
- switch (globalCtx->envCtx.unk_E1) {
+ switch (globalCtx->envCtx.fillScreen) {
case 1:
- func_8007672C(gfxCtx, globalCtx->envCtx.unk_E2[0], globalCtx->envCtx.unk_E2[1],
- globalCtx->envCtx.unk_E2[2], globalCtx->envCtx.unk_E2[3], 3);
+ Environment_FillScreen(
+ gfxCtx, globalCtx->envCtx.screenFillColor[0], globalCtx->envCtx.screenFillColor[1],
+ globalCtx->envCtx.screenFillColor[2], globalCtx->envCtx.screenFillColor[3],
+ FILL_SCREEN_OPA | FILL_SCREEN_XLU);
break;
default:
break;
@@ -1263,8 +1263,8 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
}
if ((HREG(80) != 10) || (HREG(88) != 0)) {
- if (globalCtx->envCtx.unk_E6 != 0) {
- func_80076934(globalCtx, globalCtx->envCtx.unk_E6);
+ if (globalCtx->envCtx.sandstormState != 0) {
+ Environment_DrawSandstorm(globalCtx, globalCtx->envCtx.sandstormState);
}
}
@@ -1274,7 +1274,6 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
if ((R_PAUSE_MENU_MODE == 1) || (gTrnsnUnkState == 1)) {
Gfx* sp70 = OVERLAY_DISP;
- s32 pad[4];
globalCtx->pauseBgPreRender.fbuf = gfxCtx->curFrameBuffer;
globalCtx->pauseBgPreRender.fbufSave = (u16*)gZBuffer;
@@ -1303,7 +1302,7 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
Camera_Update(GET_ACTIVE_CAM(globalCtx));
func_800AB944(&globalCtx->view);
globalCtx->view.unk_124 = 0;
- if (globalCtx->skyboxId && (globalCtx->skyboxId != SKYBOX_UNSET_1D) && !globalCtx->envCtx.skyDisabled) {
+ if (globalCtx->skyboxId && (globalCtx->skyboxId != SKYBOX_UNSET_1D) && !globalCtx->envCtx.skyboxDisabled) {
SkyboxDraw_UpdateMatrix(&globalCtx->skyboxCtx, globalCtx->view.eye.x, globalCtx->view.eye.y,
globalCtx->view.eye.z);
}
@@ -1439,9 +1438,9 @@ void* Gameplay_LoadFile(GlobalContext* globalCtx, RomFile* file) {
return allocp;
}
-void Gameplay_InitSkybox(GlobalContext* globalCtx, s16 skyboxId) {
+void Gameplay_InitEnvironment(GlobalContext* globalCtx, s16 skyboxId) {
Skybox_Init(globalCtx, &globalCtx->skyboxCtx, skyboxId);
- func_8006F140(globalCtx, &globalCtx->envCtx, 0);
+ Environment_Init(globalCtx, &globalCtx->envCtx, 0);
}
void Gameplay_InitScene(GlobalContext* globalCtx, s32 spawn) {
@@ -1460,7 +1459,7 @@ void Gameplay_InitScene(GlobalContext* globalCtx, s32 spawn) {
YREG(15) = 0;
gSaveContext.worldMapArea = 0;
Scene_ExecuteCommands(globalCtx, globalCtx->sceneSegment);
- Gameplay_InitSkybox(globalCtx, globalCtx->skyboxId);
+ Gameplay_InitEnvironment(globalCtx, globalCtx->skyboxId);
}
void Gameplay_SpawnScene(GlobalContext* globalCtx, s32 sceneNum, s32 spawn) {
diff --git a/src/code/z_rcp.c b/src/code/z_rcp.c
index d0709b44f..c2410f563 100644
--- a/src/code/z_rcp.c
+++ b/src/code/z_rcp.c
@@ -847,51 +847,52 @@ Gfx gEmptyDL[] = {
gsSPEndDisplayList(),
};
-Gfx* Gfx_SetFog(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 n, s32 f) {
- if (f == n) {
- f++;
+Gfx* Gfx_SetFog(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far) {
+ if (far == near) {
+ far++;
}
- ASSERT(n != f, "n != f", "../z_rcp.c", 1155);
+
+ ASSERT(near != far, "n != f", "../z_rcp.c", 1155);
gDPSetFogColor(gfx++, r, g, b, a);
- if (n >= 1000) {
+ if (near >= 1000) {
gSPFogFactor(gfx++, 0, 0);
- } else if (n >= 997) {
+ } else if (near >= 997) {
gSPFogFactor(gfx++, 0x7FFF, 0x8100);
- } else if (n < 0) {
+ } else if (near < 0) {
gSPFogFactor(gfx++, 0, 255);
} else {
- gSPFogPosition(gfx++, n, f);
+ gSPFogPosition(gfx++, near, far);
}
return gfx;
}
-Gfx* Gfx_SetFogWithSync(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 n, s32 f) {
- if (f == n) {
- f++;
+Gfx* Gfx_SetFogWithSync(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far) {
+ if (far == near) {
+ far++;
}
- ASSERT(n != f, "n != f", "../z_rcp.c", 1187);
+ ASSERT(near != far, "n != f", "../z_rcp.c", 1187);
gDPPipeSync(gfx++);
gDPSetFogColor(gfx++, r, g, b, a);
- if (n >= 1000) {
+ if (near >= 1000) {
gSPFogFactor(gfx++, 0, 0);
- } else if (n >= 997) {
+ } else if (near >= 997) {
gSPFogFactor(gfx++, 0x7FFF, 0x8100);
- } else if (n < 0) {
+ } else if (near < 0) {
gSPFogFactor(gfx++, 0, 255);
} else {
- gSPFogPosition(gfx++, n, f);
+ gSPFogPosition(gfx++, near, far);
}
return gfx;
}
-Gfx* Gfx_SetFog2(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 n, s32 f) {
- return Gfx_SetFog(gfx, r, g, b, a, n, f);
+Gfx* Gfx_SetFog2(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 near, s32 far) {
+ return Gfx_SetFog(gfx, r, g, b, a, near, far);
}
Gfx* Gfx_CallSetupDLImpl(Gfx* gfx, u32 i) {
diff --git a/src/code/z_room.c b/src/code/z_room.c
index acad1905a..80e724368 100644
--- a/src/code/z_room.c
+++ b/src/code/z_room.c
@@ -131,7 +131,7 @@ void func_80095D04(GlobalContext* globalCtx, Room* room, u32 flags) {
SkinMatrix_Vec3fMtxFMultXYZW(&globalCtx->mf_11D60, &sp90, &sp84, &sp80);
if (-(f32)polygonDlist->unk_06 < sp84.z) {
temp_f2 = sp84.z - polygonDlist->unk_06;
- if (temp_f2 < globalCtx->lightCtx.unk_0C) {
+ if (temp_f2 < globalCtx->lightCtx.fogFar) {
phi_v0 = spB4;
spA4->unk_00 = polygonDlist;
spA4->unk_04 = temp_f2;
diff --git a/src/code/z_scene.c b/src/code/z_scene.c
index 370a0eb0b..572cb488c 100644
--- a/src/code/z_scene.c
+++ b/src/code/z_scene.c
@@ -343,67 +343,63 @@ void func_80098CC8(GlobalContext* globalCtx, SceneCmd* cmd) {
// Scene Command 0x11: Skybox Settings
void func_80098D1C(GlobalContext* globalCtx, SceneCmd* cmd) {
globalCtx->skyboxId = cmd->skyboxSettings.skyboxId;
- globalCtx->envCtx.gloomySky = globalCtx->envCtx.unk_18 = cmd->skyboxSettings.unk_05;
- globalCtx->envCtx.unk_1E = cmd->skyboxSettings.unk_06;
+ globalCtx->envCtx.unk_17 = globalCtx->envCtx.unk_18 = cmd->skyboxSettings.unk_05;
+ globalCtx->envCtx.indoors = cmd->skyboxSettings.unk_06;
}
// Scene Command 0x12: Skybox Disables
void func_80098D5C(GlobalContext* globalCtx, SceneCmd* cmd) {
- globalCtx->envCtx.skyDisabled = cmd->skyboxDisables.unk_04;
+ globalCtx->envCtx.skyboxDisabled = cmd->skyboxDisables.unk_04;
globalCtx->envCtx.sunMoonDisabled = cmd->skyboxDisables.unk_05;
}
// Scene Command 0x10: Time Settings
void func_80098D80(GlobalContext* globalCtx, SceneCmd* cmd) {
- u32 dayTime;
-
if ((cmd->timeSettings.hour != 0xFF) && (cmd->timeSettings.min != 0xFF)) {
- gSaveContext.environmentTime = gSaveContext.dayTime =
- ((cmd->timeSettings.hour + (cmd->timeSettings.min / 60.0f)) * 60.0f) / (360.0f / 0x4000);
+ gSaveContext.skyboxTime = gSaveContext.dayTime =
+ ((cmd->timeSettings.hour + (cmd->timeSettings.min / 60.0f)) * 60.0f) / ((f32)(24 * 60) / 0x10000);
}
if (cmd->timeSettings.unk_06 != 0xFF) {
- globalCtx->envCtx.unk_02 = cmd->timeSettings.unk_06;
+ globalCtx->envCtx.timeIncrement = cmd->timeSettings.unk_06;
} else {
- globalCtx->envCtx.unk_02 = 0;
+ globalCtx->envCtx.timeIncrement = 0;
}
- if (gSaveContext.unk_1422 == 0) {
- D_8011FB40 = globalCtx->envCtx.unk_02;
+ if (gSaveContext.sunsSongState == SUNSSONG_INACTIVE) {
+ gTimeIncrement = globalCtx->envCtx.timeIncrement;
}
- dayTime = gSaveContext.dayTime;
- globalCtx->envCtx.unk_04.x = -(Math_SinS(dayTime - 0x8000) * 120.0f) * 25.0f;
- dayTime = gSaveContext.dayTime;
- globalCtx->envCtx.unk_04.y = (Math_CosS(dayTime - 0x8000) * 120.0f) * 25.0f;
- dayTime = gSaveContext.dayTime;
- globalCtx->envCtx.unk_04.z = (Math_CosS(dayTime - 0x8000) * 20.0f) * 25.0f;
+ globalCtx->envCtx.sunPos.x = -(Math_SinS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f) * 25.0f;
+ globalCtx->envCtx.sunPos.y = (Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 120.0f) * 25.0f;
+ globalCtx->envCtx.sunPos.z = (Math_CosS(((void)0, gSaveContext.dayTime) - 0x8000) * 20.0f) * 25.0f;
- if (((globalCtx->envCtx.unk_02 == 0) && (gSaveContext.cutsceneIndex < 0xFFF0)) ||
+ if (((globalCtx->envCtx.timeIncrement == 0) && (gSaveContext.cutsceneIndex < 0xFFF0)) ||
(gSaveContext.entranceIndex == 0x0604)) {
- gSaveContext.environmentTime = gSaveContext.dayTime;
- if ((gSaveContext.environmentTime >= 0x2AAC) && (gSaveContext.environmentTime < 0x4555)) {
- gSaveContext.environmentTime = 0x3556;
- } else if ((gSaveContext.environmentTime >= 0x4555) && (gSaveContext.environmentTime < 0x5556)) {
- gSaveContext.environmentTime = 0x5556;
- } else if ((gSaveContext.environmentTime >= 0xAAAB) && (gSaveContext.environmentTime < 0xB556)) {
- gSaveContext.environmentTime = 0xB556;
- } else if ((gSaveContext.environmentTime >= 0xC001) && (gSaveContext.environmentTime < 0xCAAC)) {
- gSaveContext.environmentTime = 0xCAAC;
+ gSaveContext.skyboxTime = ((void)0, gSaveContext.dayTime);
+ if ((gSaveContext.skyboxTime >= 0x2AAC) && (gSaveContext.skyboxTime < 0x4555)) {
+ gSaveContext.skyboxTime = 0x3556;
+ } else if ((gSaveContext.skyboxTime >= 0x4555) && (gSaveContext.skyboxTime < 0x5556)) {
+ gSaveContext.skyboxTime = 0x5556;
+ } else if ((gSaveContext.skyboxTime >= 0xAAAB) && (gSaveContext.skyboxTime < 0xB556)) {
+ gSaveContext.skyboxTime = 0xB556;
+ } else if ((gSaveContext.skyboxTime >= 0xC001) && (gSaveContext.skyboxTime < 0xCAAC)) {
+ gSaveContext.skyboxTime = 0xCAAC;
}
}
}
// Scene Command 0x05: Wind Settings
void func_80099090(GlobalContext* globalCtx, SceneCmd* cmd) {
- s8 temp1 = cmd->windSettings.unk_04;
- s8 temp2 = cmd->windSettings.unk_05;
- s8 temp3 = cmd->windSettings.unk_06;
+ s8 x = cmd->windSettings.x;
+ s8 y = cmd->windSettings.y;
+ s8 z = cmd->windSettings.z;
+
+ globalCtx->envCtx.windDirection.x = x;
+ globalCtx->envCtx.windDirection.y = y;
+ globalCtx->envCtx.windDirection.z = z;
- globalCtx->envCtx.unk_A8 = temp1;
- globalCtx->envCtx.unk_AA = temp2;
- globalCtx->envCtx.unk_AC = temp3;
- globalCtx->envCtx.unk_B0 = cmd->windSettings.unk_07;
+ globalCtx->envCtx.windSpeed = cmd->windSettings.unk_07;
}
// Scene Command 0x13: Exit List
@@ -501,13 +497,6 @@ void (*gSceneCmdHandlers[])(GlobalContext*, SceneCmd*) = {
func_80099140, func_8009918C, func_8009934C, func_800991A0, func_800993C0,
};
-#define ROM_FILE(name) \
- { (u32) _##name##SegmentRomStart, (u32)_##name##SegmentRomEnd }
-#define ROM_FILE_EMPTY(name) \
- { (u32) _##name##SegmentRomStart, (u32)_##name##SegmentRomStart }
-#define ROM_FILE_UNSET \
- { 0 }
-
RomFile sNaviMsgFiles[] = {
ROM_FILE(elf_message_field),
ROM_FILE(elf_message_ydan),
diff --git a/src/code/z_scene_table.c b/src/code/z_scene_table.c
index 38fe6c95a..44bb75e2b 100644
--- a/src/code/z_scene_table.c
+++ b/src/code/z_scene_table.c
@@ -1088,10 +1088,10 @@ void func_80099BD8(GlobalContext* globalCtx) {
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_scene_table.c", 5145);
if (gSaveContext.sceneSetupIndex == 5) {
- D_8015FCF0 = 1;
- D_8015FCF8.x = -20.0f;
- D_8015FCF8.y = 1220.0f;
- D_8015FCF8.z = -684.0f;
+ gCustomLensFlareOn = true;
+ gCustomLensFlarePos.x = -20.0f;
+ gCustomLensFlarePos.y = 1220.0f;
+ gCustomLensFlarePos.z = -684.0f;
D_8015FD06 = 10;
D_8015FD08 = 8.0f;
D_8015FD0C = 200;
diff --git a/src/code/z_sram.c b/src/code/z_sram.c
index a9312c061..356ffee17 100644
--- a/src/code/z_sram.c
+++ b/src/code/z_sram.c
@@ -63,8 +63,8 @@ typedef struct {
/* 0x08 */ s32 cutsceneIndex;
/* 0x0C */ u16 dayTime; // "zelda_time"
/* 0x10 */ s32 nightFlag;
- /* 0x14 */ s32 numDays;
- /* 0x18 */ s32 unk_18; // increments with numDays, gets reset by goron for bgs and one other use
+ /* 0x14 */ s32 totalDays;
+ /* 0x18 */ s32 unk_18; // increments with totalDays, gets reset by goron for bgs and one other use
/* 0x1C */ SaveInfo info; // "information"
} Save; // size = 0x1354
@@ -161,8 +161,8 @@ void Sram_InitNewSave(void) {
SaveContext* temp = &gSaveContext;
bzero(&SAVE_INFO, sizeof(SaveInfo));
- gSaveContext.numDays = 0;
- gSaveContext.unk_18 = 0;
+ gSaveContext.totalDays = 0;
+ gSaveContext.bgsDayCount = 0;
SAVE_PLAYER_DATA = sNewSavePlayerData;
gSaveContext.equips = sNewSaveEquips;
@@ -250,8 +250,8 @@ void Sram_InitDebugSave(void) {
SaveContext* temp = &gSaveContext;
bzero(&SAVE_INFO, sizeof(SaveInfo));
- gSaveContext.numDays = 0;
- gSaveContext.unk_18 = 0;
+ gSaveContext.totalDays = 0;
+ gSaveContext.bgsDayCount = 0;
SAVE_PLAYER_DATA = sDebugSavePlayerData;
gSaveContext.equips = sDebugSaveEquips;
@@ -561,8 +561,8 @@ void Sram_VerifyAndLoadAllSaves(FileChooseContext* fileChooseCtx, SramContext* s
// note that gSaveContext.dayTime is not actually the sizeof(s32)
bzero(&gSaveContext.dayTime, sizeof(s32));
bzero(&gSaveContext.nightFlag, sizeof(s32));
- bzero(&gSaveContext.numDays, sizeof(s32));
- bzero(&gSaveContext.unk_18, sizeof(s32));
+ bzero(&gSaveContext.totalDays, sizeof(s32));
+ bzero(&gSaveContext.bgsDayCount, sizeof(s32));
if (!slotNum) {
Sram_InitDebugSave();
diff --git a/src/code/z_vr_box.c b/src/code/z_vr_box.c
index 2400152f7..b1755f2b6 100644
--- a/src/code/z_vr_box.c
+++ b/src/code/z_vr_box.c
@@ -1,5 +1,6 @@
#include "global.h"
#include "vt.h"
+#include "z64environment.h"
typedef struct {
/* 0x000 */ s32 unk_0;
@@ -11,17 +12,7 @@ typedef struct {
extern Struct_8012AF0C D_8012AF0C[6];
extern Struct_8012AF0C D_8012AEBC[4];
-
-typedef struct {
- /* 0x00 */ u16 unk_0; // start
- /* 0x02 */ u16 unk_2; // end
- /* 0x04 */ u8 unk_4;
- /* 0x05 */ u8 unk_5; // img idx 1
- /* 0x06 */ u8 unk_6; // img idx 2
- /* 0x07 */ char unk_7[0x1];
-} Struct_8011FC1C; // size = 0x8
-
-extern Struct_8011FC1C D_8011FC1C[8][9];
+extern struct_8011FC1C D_8011FC1C[][9];
typedef struct {
/* 0x00 */ u32 unk_0; // start
@@ -30,8 +21,6 @@ typedef struct {
/* 0x0C */ u32 unk_C; // pal end
} Struct_8011FD3C; // size = 0x10
-extern Struct_8011FD3C D_8011FD3C[];
-
s32 func_800ADBB0(SkyboxContext* skyboxCtx, Vtx* roomVtx, s32, UNK_TYPE, UNK_TYPE, UNK_TYPE, UNK_TYPE, UNK_TYPE, s32,
s32);
#pragma GLOBAL_ASM("asm/non_matchings/code/z_vr_box/func_800ADBB0.s")
@@ -85,64 +74,69 @@ void Skybox_Setup(GlobalContext* globalCtx, SkyboxContext* skyboxCtx, s16 skybox
switch (skyboxId) {
case SKYBOX_NORMAL_SKY:
phi_v1 = 0;
- if (gSaveContext.unk_13C3 != 0 && gSaveContext.sceneSetupIndex < 4 && D_8011FB30 > 0 && D_8011FB30 < 6) {
+ if (gSaveContext.unk_13C3 != 0 && gSaveContext.sceneSetupIndex < 4 && gWeatherMode > 0 &&
+ gWeatherMode < 6) {
phi_v1 = 1;
}
for (i = 0; i < 9; i++) {
- if (gSaveContext.environmentTime >= D_8011FC1C[phi_v1][i].unk_0 &&
- (gSaveContext.environmentTime < D_8011FC1C[phi_v1][i].unk_2 ||
- D_8011FC1C[phi_v1][i].unk_2 == 0xFFFF)) {
- globalCtx->envCtx.unk_10 = sp41 = D_8011FC1C[phi_v1][i].unk_5;
- globalCtx->envCtx.unk_11 = sp40 = D_8011FC1C[phi_v1][i].unk_6;
- if (D_8011FC1C[phi_v1][i].unk_4 != 0) {
- globalCtx->envCtx.unk_13 =
- func_8006F93C(D_8011FC1C[phi_v1][i].unk_2, D_8011FC1C[phi_v1][i].unk_0,
- ((void)0, gSaveContext.environmentTime)) *
+ if (gSaveContext.skyboxTime >= D_8011FC1C[phi_v1][i].startTime &&
+ (gSaveContext.skyboxTime < D_8011FC1C[phi_v1][i].endTime ||
+ D_8011FC1C[phi_v1][i].endTime == 0xFFFF)) {
+ globalCtx->envCtx.skybox1Index = sp41 = D_8011FC1C[phi_v1][i].skybox1Index;
+ globalCtx->envCtx.skybox2Index = sp40 = D_8011FC1C[phi_v1][i].skybox2Index;
+ if (D_8011FC1C[phi_v1][i].blend != 0) {
+ globalCtx->envCtx.skyboxBlend =
+ Environment_LerpWeight(D_8011FC1C[phi_v1][i].endTime, D_8011FC1C[phi_v1][i].startTime,
+ ((void)0, gSaveContext.skyboxTime)) *
255.0f;
} else {
- globalCtx->envCtx.unk_13 = 0;
+ globalCtx->envCtx.skyboxBlend = 0;
}
break;
}
}
- size = D_8011FD3C[sp41].unk_4 - D_8011FD3C[sp41].unk_0;
+ size = gSkyboxFiles[sp41].file.vromEnd - gSkyboxFiles[sp41].file.vromStart;
skyboxCtx->staticSegments[0] = GameState_Alloc(&globalCtx->state, size, "../z_vr_box.c", 1054);
ASSERT(skyboxCtx->staticSegments[0] != NULL, "vr_box->vr_box_staticSegment[0] != NULL", "../z_vr_box.c",
1055);
- DmaMgr_SendRequest1(skyboxCtx->staticSegments[0], D_8011FD3C[sp41].unk_0, size, "../z_vr_box.c", 1058);
+ DmaMgr_SendRequest1(skyboxCtx->staticSegments[0], gSkyboxFiles[sp41].file.vromStart, size, "../z_vr_box.c",
+ 1058);
- size = D_8011FD3C[sp40].unk_4 - D_8011FD3C[sp40].unk_0;
+ size = gSkyboxFiles[sp40].file.vromEnd - gSkyboxFiles[sp40].file.vromStart;
skyboxCtx->staticSegments[1] = GameState_Alloc(&globalCtx->state, size, "../z_vr_box.c", 1060);
ASSERT(skyboxCtx->staticSegments[1] != NULL, "vr_box->vr_box_staticSegment[1] != NULL", "../z_vr_box.c",
1061);
- DmaMgr_SendRequest1(skyboxCtx->staticSegments[1], D_8011FD3C[sp40].unk_0, size, "../z_vr_box.c", 1064);
+ DmaMgr_SendRequest1(skyboxCtx->staticSegments[1], gSkyboxFiles[sp40].file.vromStart, size, "../z_vr_box.c",
+ 1064);
// reorderings in the rest of this case
if (((u8)(sp41 & 4) >> 2) != (sp41 & 1)) {
- size = D_8011FD3C[sp41].unk_C - D_8011FD3C[sp41].unk_8;
+ size = gSkyboxFiles[sp41].pallete.vromEnd - gSkyboxFiles[sp41].pallete.vromStart;
skyboxCtx->staticSegments[2] = GameState_Alloc(&globalCtx->state, size * 2, "../z_vr_box.c", 1072);
ASSERT(skyboxCtx->staticSegments[2] != NULL, "vr_box->vr_box_staticSegment[2] != NULL", "../z_vr_box.c",
1073);
- DmaMgr_SendRequest1(skyboxCtx->staticSegments[2], D_8011FD3C[sp41].unk_8, size, "../z_vr_box.c", 1075);
- DmaMgr_SendRequest1((u32)skyboxCtx->staticSegments[2] + size, D_8011FD3C[sp40].unk_8, size,
- "../z_vr_box.c", 1077);
+ DmaMgr_SendRequest1(skyboxCtx->staticSegments[2], gSkyboxFiles[sp41].pallete.vromStart, size,
+ "../z_vr_box.c", 1075);
+ DmaMgr_SendRequest1((u32)skyboxCtx->staticSegments[2] + size, gSkyboxFiles[sp40].pallete.vromStart,
+ size, "../z_vr_box.c", 1077);
} else {
- size = D_8011FD3C[sp41].unk_C - D_8011FD3C[sp41].unk_8;
+ size = gSkyboxFiles[sp41].pallete.vromEnd - gSkyboxFiles[sp41].pallete.vromStart;
skyboxCtx->staticSegments[2] = GameState_Alloc(&globalCtx->state, size * 2, "../z_vr_box.c", 1085);
ASSERT(skyboxCtx->staticSegments[2] != NULL, "vr_box->vr_box_staticSegment[2] != NULL", "../z_vr_box.c",
1086);
- DmaMgr_SendRequest1(skyboxCtx->staticSegments[2], D_8011FD3C[sp40].unk_8, size, "../z_vr_box.c", 1088);
- DmaMgr_SendRequest1((u32)skyboxCtx->staticSegments[2] + size, D_8011FD3C[sp41].unk_8, size,
- "../z_vr_box.c", 1090);
+ DmaMgr_SendRequest1(skyboxCtx->staticSegments[2], gSkyboxFiles[sp40].pallete.vromStart, size,
+ "../z_vr_box.c", 1088);
+ DmaMgr_SendRequest1((u32)skyboxCtx->staticSegments[2] + size, gSkyboxFiles[sp41].pallete.vromStart,
+ size, "../z_vr_box.c", 1090);
}
break;
diff --git a/src/code/z_vr_box_draw.c b/src/code/z_vr_box_draw.c
index b1f1c1bc3..14ad03d66 100644
--- a/src/code/z_vr_box_draw.c
+++ b/src/code/z_vr_box_draw.c
@@ -11,7 +11,7 @@ Mtx* SkyboxDraw_UpdateMatrix(SkyboxContext* skyboxCtx, f32 x, f32 y, f32 z) {
return Matrix_ToMtx(sSkyboxDrawMatrix, "../z_vr_box_draw.c", 42);
}
-void SkyboxDraw_Draw(SkyboxContext* skyboxCtx, GraphicsContext* gfxCtx, s16 skyboxId, s16 alpha, f32 x, f32 y, f32 z) {
+void SkyboxDraw_Draw(SkyboxContext* skyboxCtx, GraphicsContext* gfxCtx, s16 skyboxId, s16 blend, f32 x, f32 y, f32 z) {
OPEN_DISPS(gfxCtx, "../z_vr_box_draw.c", 52);
func_800945A0(gfxCtx);
@@ -20,7 +20,7 @@ void SkyboxDraw_Draw(SkyboxContext* skyboxCtx, GraphicsContext* gfxCtx, s16 skyb
gSPSegment(POLY_OPA_DISP++, 0x8, skyboxCtx->staticSegments[1]);
gSPSegment(POLY_OPA_DISP++, 0x9, skyboxCtx->staticSegments[2]);
- gDPSetPrimColor(POLY_OPA_DISP++, 0x00, 0x00, 0, 0, 0, alpha);
+ gDPSetPrimColor(POLY_OPA_DISP++, 0x00, 0x00, 0, 0, 0, blend);
gSPTexture(POLY_OPA_DISP++, 0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON);
sSkyboxDrawMatrix = Graph_Alloc(gfxCtx, sizeof(Mtx));