From d7ff28a6f7df1bc69bc630546e221c39ac1a59ca Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 25 Oct 2023 01:02:42 -0700 Subject: [PATCH] dKyr_sun_move progress --- include/d/d_cc_mass_s.h | 1 + include/d/d_com_inf_game.h | 2 + include/d/d_drawlist.h | 2 + include/d/d_kankyo.h | 4 + include/d/d_kankyo_wether.h | 10 +- include/d/d_snap.h | 18 ++- src/d/d_kankyo_rain.cpp | 224 +++++++++++++++++++++++++++++++++++- src/d/d_snap.cpp | 14 +-- 8 files changed, 260 insertions(+), 15 deletions(-) diff --git a/include/d/d_cc_mass_s.h b/include/d/d_cc_mass_s.h index 5b665c90d..18b52c2a2 100644 --- a/include/d/d_cc_mass_s.h +++ b/include/d/d_cc_mass_s.h @@ -36,6 +36,7 @@ private: /* 0x0C */ f32 mCoHitLen; public: + virtual ~dCcMassS_HitInf() {} void ClearPointer(); void SetAreaHitObj(cCcD_Obj* obj) { mpArea = obj; } void SetCoHitObj(cCcD_Obj* obj) { mpCoObj = obj; } diff --git a/include/d/d_com_inf_game.h b/include/d/d_com_inf_game.h index d3b01bba5..9fae7c64e 100644 --- a/include/d/d_com_inf_game.h +++ b/include/d/d_com_inf_game.h @@ -2141,6 +2141,8 @@ inline MtxP dComIfGd_getViewRotMtx() { inline void dComIfGd_set2DOpa(dDlst_base_c* pBase) { g_dComIfG_gameInfo.drawlist.set2DOpa(pBase); } inline void dComIfGd_set2DXlu(dDlst_base_c* pBase) { g_dComIfG_gameInfo.drawlist.set2DXlu(pBase); } +inline void dComIfGd_peekZ(s16 x, s16 y, u32 * data) { g_dComIfG_gameInfo.drawlist.newPeekZdata(x, y, data); } + inline void dComIfGd_setWindow(dDlst_window_c* pWindow) { g_dComIfG_gameInfo.drawlist.setWindow(pWindow); } inline void dComIfGd_setViewPort(view_port_class* pViewPort) { g_dComIfG_gameInfo.drawlist.setViewPort(pViewPort); } inline void dComIfGd_setView(view_class* pView) { g_dComIfG_gameInfo.drawlist.setView(pView); } diff --git a/include/d/d_drawlist.h b/include/d/d_drawlist.h index bdc633e63..a3828ceca 100644 --- a/include/d/d_drawlist.h +++ b/include/d/d_drawlist.h @@ -397,6 +397,8 @@ public: static void offWipe() { mWipe = false; } + void newPeekZdata(s16 x, s16 y, u32 * data) { mPeekZ.newData(x, y, data); } + static bool mWipe; /* 0x00000 */ J3DDrawBuffer* mpOpaListSky; diff --git a/include/d/d_kankyo.h b/include/d/d_kankyo.h index 5bdd2a99b..070ad3561 100644 --- a/include/d/d_kankyo.h +++ b/include/d/d_kankyo.h @@ -412,6 +412,10 @@ void dKy_arrowcol_chg_on(cXyz*, int); void dKy_arrowcol_chg_move(); void dKy_setLight_init(); void GxXFog_set(); +void dKy_set_actcol_ratio(f32 ratio); +void dKy_set_bgcol_ratio(f32 ratio); +void dKy_set_fogcol_ratio(f32 ratio); +void dKy_set_vrboxcol_ratio(f32 ratio); void dKy_set_vrboxsoracol_ratio(f32 ratio); void dKy_set_vrboxkumocol_ratio(f32 ratio); cXyz dKy_get_orion_pos(); diff --git a/include/d/d_kankyo_wether.h b/include/d/d_kankyo_wether.h index f9325c592..1c62e2fd7 100644 --- a/include/d/d_kankyo_wether.h +++ b/include/d/d_kankyo_wether.h @@ -152,10 +152,14 @@ struct POISON_EFF { POISON_EFF(); ~POISON_EFF(); - /* 0x00 */ u8 mStatus; - /* 0x01 */ u8 field_0x1[0x2F]; + /* 0x00 */ s8 mStatus; + /* 0x04 */ cXyz mPos; + /* 0x10 */ u8 field_0x10[0x1E]; + /* 0x2E */ s16 field_0x2e; }; +STATIC_ASSERT(sizeof(POISON_EFF) == 0x30); + class dKankyo_poison_Packet : public J3DPacket { public: dKankyo_poison_Packet() {} @@ -164,7 +168,7 @@ public: virtual ~dKankyo_poison_Packet(); /* 0x0010 */ POISON_EFF mEff[1000]; - /* 0xBB90 */ u8 field_0xbb90[0xBB9C - 0xBB90]; + /* 0xBB90 */ cXyz field_0xbb90; /* 0xBB9C */ cXyz field_0xbb9c; /* 0xBBA8 */ u32 mCount; /* 0xBBAC */ u8* mpTexture; diff --git a/include/d/d_snap.h b/include/d/d_snap.h index 1489dfa32..fd1a95d74 100644 --- a/include/d/d_snap.h +++ b/include/d/d_snap.h @@ -3,7 +3,23 @@ #include "f_op/f_op_actor.h" -class dSnap_Obj; +class dSnap_Obj { +public: + /* 0x00 */ cXyz field_0x00; + /* 0x0C */ f32 field_0x0c; + /* 0x10 */ f32 field_0x10; + /* 0x14 */ s32 mBsPcId; + /* 0x18 */ u32 field_0x18[6]; + +public: + dSnap_Obj(); + virtual ~dSnap_Obj() {} + + void SetGeoSph(const Vec & c, f32 r); + void SetInf(u8, const fopAc_ac_c*, u8, u8, s16); +}; + +STATIC_ASSERT(sizeof(dSnap_Obj) == 0x34); void dSnap_PhotoIndex2TableIndex(int); void dSnap_GetFigRoomId(int); diff --git a/src/d/d_kankyo_rain.cpp b/src/d/d_kankyo_rain.cpp index ae5cc3a0a..efe914953 100644 --- a/src/d/d_kankyo_rain.cpp +++ b/src/d/d_kankyo_rain.cpp @@ -9,6 +9,7 @@ #include "d/d_com_inf_game.h" #include "d/d_kankyo.h" #include "d/d_kankyo_wether.h" +#include "d/d_snap.h" #include "f_op/f_op_camera_mng.h" #include "m_Do/m_Do_lib.h" #include "JSystem/JKernel/JKRHeap.h" @@ -178,6 +179,170 @@ BOOL dKyr_moon_arrival_check() { /* 8008C8B8-8008CF68 .text dKyr_sun_move__Fv */ void dKyr_sun_move() { /* Nonmatching */ + dKankyo_sun_Packet* pSunPkt = g_env_light.mpSunPacket; + dKankyo_sunlenz_Packet* pLenzPkt = g_env_light.mpSunlenzPacket; + camera_class* pCamera = dComIfGp_getCamera(0); + + f32 staringAtSunAmount = 0.0f; + u8 numPointsVisible = 0, numCenterPointsVisible = 0; + u32 stType = dStage_stagInfo_GetSTType(dComIfGp_getStageStagInfo()); + cXyz lightDir; + if (g_env_light.mBaseLightInfluence.mColor.r == 0 && stType != 2) { + dKyr_get_vectle_calc(&pCamera->mLookat.mEye, &g_env_light.mBaseLightInfluence.mPos, &lightDir); + } else { + dKyr_get_vectle_calc(&pCamera->mLookat.mEye, &g_env_light.mSunPos2, &lightDir); + } + + pSunPkt->mPos[0].x = pCamera->mLookat.mEye.x + lightDir.x * 8000.0f; + pSunPkt->mPos[0].y = pCamera->mLookat.mEye.y + lightDir.y * 8000.0f; + pSunPkt->mPos[0].z = pCamera->mLookat.mEye.z + lightDir.z * 8000.0f; + + f32 horizonY = (pSunPkt->mPos[0].y - pCamera->mLookat.mEye.y) / 8000.0f; + if (horizonY < 0.0f) + horizonY = 0.0f; + if (horizonY >= 1.0f) + horizonY = 1.0f; + horizonY = 1.0f - horizonY; + horizonY *= horizonY; + f32 pulsePos = 1.0f - horizonY; + + if (dComIfGp_getStageStagInfo() != NULL) { + dComIfGp_getStageStagInfo(); + } + + if (pSunPkt->field_0x3c != 0) + pSunPkt->field_0x3c--; + pSunPkt->field_0x3d = false; + + if (g_env_light.mCurTime > 95.7f && g_env_light.mCurTime < 292.5f) { + f32 borderY = 0.0f; + s32 numPointsCulled = 0; + + cLib_addCalc(&pSunPkt->mSunAlpha, 1.0f, 0.5f, 0.1f, 0.01f); + + if (pCamera != NULL) { + borderY = pCamera->mCamera.m5F8; + } + + cXyz projected; + mDoLib_project(pSunPkt->mPos, &projected); + + static const cXy sun_chkpnt[] = { + 0.0f, 0.0f, + -10.0f, -20.0f, + 10.0f, 20.0f, + -20.0f, 10.0f, + 20.0f, -10.0f, + }; + + for (s32 i = 0; i < 5; i++) { + f32 screenBottom = 490.0f - borderY; + cXyz chkpnt; + chkpnt.x = sun_chkpnt[i].x; + chkpnt.y = sun_chkpnt[i].y; + chkpnt.x = projected.x - chkpnt.x; + chkpnt.y = projected.y - chkpnt.y; + + if (chkpnt.x > 0.0f && chkpnt.x < 640.0 && chkpnt.y > borderY && chkpnt.y < screenBottom) { + if (pSunPkt->mVizChkData[i] >= 0xFFFFFF) { + numPointsVisible++; + if (i == 0) + numCenterPointsVisible++; + } + + dComIfGd_peekZ(chkpnt.x, chkpnt.y, &pSunPkt->mVizChkData[i]); + } else { + numPointsCulled++; + } + } + + if (numPointsCulled != 0 && numPointsVisible != 0 && numCenterPointsVisible != 0) { + numCenterPointsVisible = 1; + numPointsVisible = 5; + } + + if (numPointsVisible != 0) { + if (pSunPkt->field_0x3c < 5) + pSunPkt->field_0x3c += 2; + pSunPkt->field_0x3d = true; + } + + pLenzPkt->field_0x80 = pLenzPkt->field_0x88; + pLenzPkt->field_0x84 = pLenzPkt->field_0x8c; + pLenzPkt->field_0x88 = 1000000000.0f; + pLenzPkt->field_0x8c = 0.0f; + + cXyz center; + center.x = 320.0f; + center.y = 240.0f; + center.z = 0.0f; + pLenzPkt->mDistFalloff = center.abs(projected); + pLenzPkt->mDistFalloff /= 450.0f; + if (pLenzPkt->mDistFalloff > 1.0f) + pLenzPkt->mDistFalloff = 1.0f; + pLenzPkt->mDistFalloff = 1.0f - pLenzPkt->mDistFalloff; + staringAtSunAmount = (pLenzPkt->mDistFalloff * pLenzPkt->mDistFalloff); + pLenzPkt->mDistFalloff = 1.0f - staringAtSunAmount; + staringAtSunAmount = staringAtSunAmount * staringAtSunAmount; + } else { + cLib_addCalc(&pSunPkt->mSunAlpha, 0.0f, 0.5f, 0.1f, 0.01f); + numPointsVisible = 0; + pSunPkt->field_0x3c = 0; + pSunPkt->field_0x3d = false; + } + + if (g_env_light.mColpatWeather != 0 || (g_env_light.mColpatCurr != 0 && g_env_light.mColPatBlend > 0.5f)) { + numCenterPointsVisible = 0; + numPointsVisible = 0; + } + + if (stType == 2) { + numCenterPointsVisible = 0; + numPointsVisible = 0; + } + + if (g_env_light.mCurTime < 120.0f || g_env_light.mCurTime > 270.0f) { + numCenterPointsVisible = 0; + numPointsVisible = 0; + } + + if (numCenterPointsVisible != 0) { + if (numPointsVisible == 4) + cLib_addCalc(&pSunPkt->mVisibility, 1.0f, 0.1f, 0.1f, 0.001f); + if (numPointsVisible <= 3) + cLib_addCalc(&pSunPkt->mVisibility, 0.0f, 0.1f, 0.2f, 0.001f); + else + cLib_addCalc(&pSunPkt->mVisibility, 1.0f, 0.5f, 0.2f, 0.01f); + } else { + if (numPointsVisible < 3) + cLib_addCalc(&pSunPkt->mVisibility, 0.0f, 0.5f, 0.2f, 0.01f); + else + cLib_addCalc(&pSunPkt->mVisibility, 1.0f, 0.1f, 0.1f, 0.01f); + } + + if (numPointsVisible >= 2) { + g_env_light.mpSunlenzPacket->mbDrawLenzInSky = false; + } else { + g_env_light.mpSunlenzPacket->mbDrawLenzInSky = true; + } + + if (pSunPkt->mPos[0].y > 0.0f && !g_env_light.mpSunlenzPacket->mbDrawLenzInSky) { + dKy_set_actcol_ratio(1.0f - staringAtSunAmount * pSunPkt->mVisibility); + dKy_set_bgcol_ratio(1.0f - staringAtSunAmount * pSunPkt->mVisibility); + dKy_set_fogcol_ratio(pulsePos * staringAtSunAmount * pSunPkt->mVisibility * 0.5f + 1.0f); + dKy_set_vrboxcol_ratio(pulsePos * staringAtSunAmount * pSunPkt->mVisibility * 0.5f + 1.0f); + } + + if (dKyr_moon_arrival_check()) { + f32 alpha = (pSunPkt->mPos[0].y - pCamera->mLookat.mEye.y) / -8000.0f; + alpha *= alpha; + alpha *= 6.0f; + if (alpha > 1.0f) + alpha = 1.0f; + cLib_addCalc(&pSunPkt->mMoonAlpha, alpha, 0.2f, 0.01f, 0.001f); + } else { + cLib_addCalc(&pSunPkt->mMoonAlpha, 0.0f, 0.2f, 0.01f, 0.001f); + } } /* 8008CF68-8008D0B4 .text dKyr_rain_init__Fv */ @@ -337,8 +502,14 @@ void cloud_shadow_move() { } /* 80092294-80092310 .text light_at_hit_check__FP4cXyz */ -void light_at_hit_check(cXyz*) { - /* Nonmatching */ +BOOL light_at_hit_check(cXyz* pPos) { + dCcMassS_HitInf hitInfo; + bool ret = false; + fopAc_ac_c * pActor; + u32 res = dComIfG_Ccsp()->mMass_Mng.Chk(pPos, &pActor, &hitInfo); + if (((res & 1) != 0) && (hitInfo.GetAtHitObj()->GetAtType() & AT_TYPE_UNK800000) != 0) + ret = true; + return ret; } /* 80092310-80092330 .text dKyr_poison_live_check__Fv */ @@ -352,8 +523,30 @@ BOOL dKyr_poison_live_check() { /* 80092330-80092448 .text dKyr_poison_light_colision__Fv */ void dKyr_poison_light_colision() { /* Nonmatching */ + dKankyo_poison_Packet * pPkt = g_env_light.mpPoisonPacket; if (!dKyr_poison_live_check()) return; + + // inline should match, but doesn't +#if 0 + dComIfG_Ccsp()->mMass_Mng.SetAttr(220.0f, 140.0f, 0x0B, 0x03); +#else + dCcMassS_Mng * mass = &dComIfG_Ccsp()->mMass_Mng; + dComIfG_Ccsp()->mMass_Mng.mCylAttr.SetR(220.0f); + dComIfG_Ccsp()->mMass_Mng.mCylAttr.SetH(140.0f); + mass->field_0x200 = 0x0B; + mass->mResultCamBit = 0x03; +#endif + + f32 halfHeight = 70.0f; + for (s32 i = 0; i < g_env_light.mPoisonCount; i++) { + cXyz pos = pPkt->field_0xbb90 + pPkt->mEff[i].mPos; + pos.y -= halfHeight; + if (light_at_hit_check(&pos) && pPkt->mEff[i].mStatus == 1) { + pPkt->mEff[i].mStatus = 2; + pPkt->mEff[i].field_0x2e = 60; + } + } } /* 80092448-8009258C .text poison_init__Fv */ @@ -401,8 +594,31 @@ void dKy_wave_chan_init() { } /* 80094144-8009428C .text snap_sunmoon_proc__FP4cXyzi */ -void snap_sunmoon_proc(cXyz*, int) { - /* Nonmatching */ +void snap_sunmoon_proc(cXyz* pPos, int type) { + dSnap_Obj snapObj; + camera_class * pCamera = dComIfGp_getCamera(0); + + if (dComIfGp_checkPlayerStatus1(0, 0x08) != 0) { + cXyz pos; + pos.x = (pPos->x - pCamera->mLookat.mEye.x); + pos.y = (pPos->y - pCamera->mLookat.mEye.y); + pos.z = (pPos->z - pCamera->mLookat.mEye.z); + pos.x *= 10.0f; + pos.y *= 10.0f; + pos.z *= 10.0f; + pos.x += pCamera->mLookat.mEye.x; + pos.y += pCamera->mLookat.mEye.y; + pos.z += pCamera->mLookat.mEye.z; + + snapObj.SetGeoSph(pos, 8000.0f); + if (type == 9) + snapObj.SetInf(9, NULL, 0xFF, 4, 0x7FFF); + else if (type == 0) + snapObj.SetInf(7, NULL, 0xFF, 4, 0x7FFF); + else + snapObj.SetInf(8, NULL, 0xFF, 4, 0x7FFF); + dSnap_RegistSnapObj(snapObj); + } } /* 8009428C-8009514C .text dKyr_drawSun__FPA4_fP4cXyzR8GXColorPPUc */ diff --git a/src/d/d_snap.cpp b/src/d/d_snap.cpp index 9997f52bb..e0e5561c5 100644 --- a/src/d/d_snap.cpp +++ b/src/d/d_snap.cpp @@ -32,17 +32,17 @@ void dSnap_Obj::draw() { } /* 800CDAF8-800CDB2C .text SetGeo__9dSnap_ObjFRC3Vecffs */ -void dSnap_Obj::SetGeo(const Vec&, float, float, short) { +void dSnap_Obj::SetGeo(const Vec&, f32, f32, s16) { /* Nonmatching */ } /* 800CDB2C-800CDB68 .text SetGeoSph__9dSnap_ObjFRC3Vecf */ -void dSnap_Obj::SetGeoSph(const Vec&, float) { +void dSnap_Obj::SetGeoSph(const Vec&, f32) { /* Nonmatching */ } /* 800CDB68-800CDB94 .text SetInf__9dSnap_ObjFUcPC10fopAc_ac_cUcUcs */ -void dSnap_Obj::SetInf(unsigned char, const fopAc_ac_c*, unsigned char, unsigned char, short) { +void dSnap_Obj::SetInf(u8, const fopAc_ac_c*, u8, u8, s16) { /* Nonmatching */ } @@ -52,7 +52,7 @@ void dSnap_Obj::SetAreaClear() { } /* 800CDBB0-800CDC04 .text SetArea__9dSnap_ObjFss */ -void dSnap_Obj::SetArea(short, short) { +void dSnap_Obj::SetArea(s16, s16) { /* Nonmatching */ } @@ -62,7 +62,7 @@ void dSnap_Obj::ChkPhoto(int) { } /* 800CDC18-800CDC40 .text ChkSuccess__9dSnap_ObjFlf */ -void dSnap_Obj::ChkSuccess(long, float) { +void dSnap_Obj::ChkSuccess(long, f32) { /* Nonmatching */ } @@ -217,12 +217,12 @@ void dSnap_RegistSnapObj(dSnap_Obj&) { } /* 800CEDD0-800CEDF8 .text dSnap_RegistFig__FUcP10fopAc_ac_cfff */ -void dSnap_RegistFig(unsigned char, fopAc_ac_c*, float, float, float) { +void dSnap_RegistFig(u8, fopAc_ac_c*, f32, f32, f32) { /* Nonmatching */ } /* 800CEDF8-800CEFD4 .text dSnap_RegistFig__FUcP10fopAc_ac_cRC3Vecsfff */ -void dSnap_RegistFig(unsigned char, fopAc_ac_c*, const Vec&, short, float, float, float) { +void dSnap_RegistFig(u8, fopAc_ac_c*, const Vec&, s16, f32, f32, f32) { /* Nonmatching */ }