From da0ed4b78cf8a04b5f685c611d96a0799a656662 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Tue, 15 Apr 2025 20:34:11 -0400 Subject: [PATCH] Fix dCamera_c::BG struct --- include/d/d_camera.h | 20 +++++++------ src/d/actor/d_a_ship.cpp | 2 +- src/d/d_camera.cpp | 61 +++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/include/d/d_camera.h b/include/d/d_camera.h index 7796f881b..ec0c6701a 100644 --- a/include/d/d_camera.h +++ b/include/d/d_camera.h @@ -115,13 +115,17 @@ typedef bool (dCamera_c::*engine_fn)(s32); class dCamera_c { public: struct BG { - BG() {} - ~BG() {} - /* 0x00 */ u8 m00[0x04 - 0x00]; - /* 0x04 */ dBgS_CamGndChk m04; // dBgS_CamGndChk might be too large by 4 bytes - /* 0x58 */ f32 m58; - /* 0x5C */ dBgS_CamGndChk m5C; // This offset is wrong, needs to be at 0x60 - }; + struct { + /* 0x00 */ bool m00; + /* 0x04 */ dBgS_CamGndChk m04; + /* 0x58 */ f32 m58; + } m00; + struct { + /* 0x00 */ bool m00; + /* 0x04 */ dBgS_CamGndChk m04; + /* 0x58 */ f32 m58; + } m5C; + }; // Size: 0xB8 /* 0x000 */ camera_class* mpCamera; /* 0x004 */ u8 m004; @@ -235,8 +239,6 @@ public: /* 0x254 */ int m254; /* 0x258 */ int m258; /* 0x25C */ BG mBG; - /* 0x30C */ int m30C; - /* 0x310 */ f32 m310; /* 0x314 */ int m314; /* 0x318 */ f32 m318; /* 0x31C */ u8 m31C; diff --git a/src/d/actor/d_a_ship.cpp b/src/d/actor/d_a_ship.cpp index b78b10f06..30f87114b 100644 --- a/src/d/actor/d_a_ship.cpp +++ b/src/d/actor/d_a_ship.cpp @@ -830,7 +830,7 @@ f32 daShip_c::getWaterY() { m03F8 = mAcch.m_wtr.GetHeight(); } else { - m03F8 = -1e9f; + m03F8 = C_BG_MIN_HEIGHT; } if (daSea_ChkArea(current.pos.x, current.pos.z)) { waterY = daSea_calcWave(current.pos.x, current.pos.z); diff --git a/src/d/d_camera.cpp b/src/d/d_camera.cpp index 4b2e6300e..ef8c121f9 100644 --- a/src/d/d_camera.cpp +++ b/src/d/d_camera.cpp @@ -265,10 +265,10 @@ void dCamera_c::initialize(camera_class* camera, fopAc_ac_c* playerActor, u32 ca mEventData.field_0x0c = -1; mRoomNo = -1; m318 = -1e+09f; - m310 = -1e+09f; - mBG.m58 = -1e+09f; - mBG.m04.OffNormalGrp(); - mBG.m04.OnWaterGrp(); + mBG.m5C.m58 = C_BG_MIN_HEIGHT; + mBG.m00.m58 = C_BG_MIN_HEIGHT; + mBG.m00.m04.OffNormalGrp(); + mBG.m00.m04.OnWaterGrp(); m31D = 0; m31C = 0; m32C = cXyz::Zero; @@ -279,7 +279,7 @@ void dCamera_c::initialize(camera_class* camera, fopAc_ac_c* playerActor, u32 ca m350 = 0; m364 = 0; m368 = 0.0f; - m354 = -1e+09f; + m354 = C_BG_MIN_HEIGHT; mRoomMapToolCameraIdx = 0xFF; m608 = mCamSetup.mBGChk.WallUpDistance(); @@ -605,7 +605,6 @@ void dCamera_c::initMonitor() { /* 801627A4-801628DC .text updateMonitor__9dCamera_cFv */ void dCamera_c::updateMonitor() { - /* Nonmatching - Code 100%, mBG offset issue */ float playerMonitorHorizontalDist; cXyz playerPos; @@ -613,7 +612,7 @@ void dCamera_c::updateMonitor() { playerPos = positionOf(mpPlayerActor); if (m31D != 0) { - dComIfG_Bgsp()->MoveBgMatrixCrrPos(mBG.m5C, TRUE, &mMonitoringThings.mPos, NULL, NULL); + dComIfG_Bgsp()->MoveBgMatrixCrrPos(mBG.m5C.m04, TRUE, &mMonitoringThings.mPos, NULL, NULL); } playerMonitorHorizontalDist = dCamMath::xyzHorizontalDistance(playerPos, mMonitoringThings.mPos); @@ -1063,7 +1062,7 @@ int dCamera_c::nextMode(s32 i_curMode) { cXyz player_pos = positionOf(mpPlayerActor); if (!dComIfGp_evmng_cameraPlay()) { - if (mBG.m58 > player_pos.y) { + if (mBG.m00.m58 > player_pos.y) { m1AE = 0; } switch(i_curMode) { @@ -1724,12 +1723,11 @@ f32 dCamera_c::groundHeight(cXyz* param_0) { gndchk_wtr.SetPos(param_0); f32 wtr_y = dComIfG_Bgsp()->GroundCross(&gndchk_wtr); - f32 height = wtr_y; if (gnd_y >= wtr_y) { wtr_y = gnd_y; } - if (wtr_y == -1000000000.0f) { + if (wtr_y == C_BG_MIN_HEIGHT) { gnd_y = param_0->y; } else { @@ -2111,28 +2109,28 @@ void dCamera_c::checkGroundInfo() { f32 ground_y = dComIfG_Bgsp()->GroundCross(&gnd_chk); - mBG.m5C.SetCam(); - mBG.m5C.ClrObj(); + mBG.m00.m04.SetCam(); + mBG.m5C.m04.ClrObj(); - mBG.m5C.SetPos(&gnd_chk_pos); + mBG.m5C.m04.SetPos(&gnd_chk_pos); - m310 = dComIfG_Bgsp()->GroundCross(&mBG.m5C); + mBG.m5C.m58 = dComIfG_Bgsp()->GroundCross(&mBG.m5C.m04); - if (m310 < ground_y) { - m310 = ground_y; - mBG.m5C = gnd_chk; + if (mBG.m5C.m58 < ground_y) { + mBG.m5C.m58 = ground_y; + mBG.m5C.m04 = gnd_chk; } - //mBG.m5C = m310 != -1000000000.0f; // wshould be a bool at 0x5C and mBG.m5C should be at 0x6 + mBG.m5C.m00 = mBG.m5C.m58 != C_BG_MIN_HEIGHT; - mBG.m04.SetPos(&player_pos); + mBG.m00.m04.SetPos(&player_pos); - mBG.m58 = dComIfG_Bgsp()->GroundCross(&mBG.m04); + mBG.m00.m58 = dComIfG_Bgsp()->GroundCross(&mBG.m00.m04); - //mBG.m5C mBG.m58 != -1000000000.0f); // should be a bool at 0x00 + mBG.m00.m00 = mBG.m00.m58 != C_BG_MIN_HEIGHT; - m354 = mBG.m58; - if (mpPlayerActor->current.pos.y - m310 > mCamSetup.mBGChk.FloorMargin()) { + m354 = mBG.m00.m58; + if (mpPlayerActor->current.pos.y - mBG.m5C.m58 > mCamSetup.mBGChk.FloorMargin()) { m360 = 0; } else { @@ -2141,11 +2139,8 @@ void dCamera_c::checkGroundInfo() { m31D = 0; m33C = 0; - if (dComIfG_Bgsp()->ChkMoveBG(mBG.m5C)) { - m31C = 0; - } - else { - m33C = dComIfG_Bgsp()->GetActorPointer(mBG.m5C.GetBgIndex()); + if (dComIfG_Bgsp()->ChkMoveBG(mBG.m5C.m04)) { + m33C = dComIfG_Bgsp()->GetActorPointer(mBG.m5C.m04.GetBgIndex()); if (m33C) { cXyz pos = positionOf(m33C); cSAngle angle = directionOf(m33C); @@ -2166,17 +2161,19 @@ void dCamera_c::checkGroundInfo() { } if (m31D) { - dComIfG_Bgsp()->MoveBgMatrixCrrPos(mBG.m5C, true, &m044, NULL, NULL); - dComIfG_Bgsp()->MoveBgMatrixCrrPos(mBG.m5C, true, &m050, NULL, NULL); + dComIfG_Bgsp()->MoveBgMatrixCrrPos(mBG.m5C.m04, true, &m044, NULL, NULL); + dComIfG_Bgsp()->MoveBgMatrixCrrPos(mBG.m5C.m04, true, &m050, NULL, NULL); m03C.Val(m050 - m044); } m32C = pos; m33A = angle; } + } else { + m31C = 0; } - if (mBG.m58) { // wrong, there is a bool at 0x5C - m350 = dComIfG_Bgsp()->GetCamMoveBG(mBG.m5C); + if (mBG.m00.m00) { + m350 = dComIfG_Bgsp()->GetCamMoveBG(mBG.m5C.m04); } else { m350 = 0;