From 6e161216723c46bf686167829f797987b39bb39e Mon Sep 17 00:00:00 2001 From: LDA Date: Sat, 7 Sep 2024 19:26:37 -0700 Subject: [PATCH 1/3] d_a_sail --- include/d/actor/d_a_sail.h | 28 +- include/d/d_kankyo.h | 1 + src/d/actor/d_a_sail.cpp | 509 +++++++++++++++++++++++++++++++++++-- 3 files changed, 508 insertions(+), 30 deletions(-) diff --git a/include/d/actor/d_a_sail.h b/include/d/actor/d_a_sail.h index 85f6137e8..ea8770fc6 100644 --- a/include/d/actor/d_a_sail.h +++ b/include/d/actor/d_a_sail.h @@ -31,7 +31,10 @@ class daSail_packet_c : public J3DPacket { virtual void draw(); public: - /* 0x0010 */ u8 m0010[0x00A4 - 0x0010]; + /* 0x0010 */ Mtx m0010; + /* 0x0040 */ Mtx m0040; + /* 0x0070 */ Mtx m0070; + /* 0x00A0 */ dKy_tevstr_c *mA0; /* 0x00A4 */ cXyz m00A4[0x54 * 2]; /* 0x0884 */ cXyz m0884[0x54]; /* 0x0C74 */ cXyz m0C74[0x54 * 2]; @@ -42,9 +45,25 @@ class daSail_packet_c : public J3DPacket { /* 0x1C3A */ u8 m1C3A; /* 0x1C3B */ u8 m1C3B; /* 0x1C3C */ J3DModel* m1C3C; - /* 0x1C40 */ u8 m1C40[0x1C44 - 0x1C40]; + /* 0x1C40 */ s32 m1C40; /* 0x1C44 */ f32 m1C44; /* 0x1C48 */ f32 m1C48; + /* 0x1C4C */ f32 m1C4C; + /* 0x1C50 */ s16 m1C50; + /* 0x1C52 */ s16 m1C52; + + inline Mtx *get_m0010() { return &this->m0010; } + inline Mtx *get_m0070() { return &this->m0070; } + + inline cXyz* get_pos(s32 idx) { + return this->m00A4 + 0x54 * this->m1C3A + 0x54 * idx; + } + inline cXyz* get_nrm1(s32 idx) { + return this->m0C74 + 0x54 * this->m1C3A + 0x54 * idx; + } + inline cXyz* get_nrm2(s32 idx) { + return this->m1454 + 0x54 * this->m1C3A + 0x54 * idx; + } }; class sail_class : public fopAc_ac_c { @@ -52,7 +71,6 @@ class sail_class : public fopAc_ac_c { /* 0x0290 */ request_of_phase_process_class mClothPhase; /* 0x0298 */ request_of_phase_process_class mKaizokusenPhase; /* 0x02A0 */ daSail_packet_c mSailPacket; - /* 0x1EEC */ u8 m1EEC[0x1EF4 - 0x1EEC]; }; class daSail_HIO_c : public JORReflexible { @@ -73,7 +91,9 @@ class daSail_HIO_c : public JORReflexible { /* 0x05 */ u8 m05; /* 0x06 */ u8 m06; /* 0x07 */ u8 m07; - /* 0x08 */ u8 m08[0x10 - 0x08]; + /* 0x08 */ u8 m08; + /* 0x09 */ u8 m09[0x0C - 0x09]; + /* 0x0C */ f32 m0C; /* 0x10 */ f32 m10; }; diff --git a/include/d/d_kankyo.h b/include/d/d_kankyo.h index 414ddddf8..c8d4acbea 100644 --- a/include/d/d_kankyo.h +++ b/include/d/d_kankyo.h @@ -396,6 +396,7 @@ void dKy_instant_rainchg(); SND_INFLUENCE * dKy_Sound_get(); void dKy_Sound_set(cXyz i_pos, int param_1, fpc_ProcID i_actorID, int param_3); void dKy_SordFlush_set(cXyz hitPos, int lightType); +cXyz dKy_FirstlightVec_get(cXyz* param_0); void dKy_itudemo_se(); void dKy_actor_addcol_set(s16, s16, s16, f32); void dKy_actor_addcol_amb_set(s16, s16, s16, f32); diff --git a/src/d/actor/d_a_sail.cpp b/src/d/actor/d_a_sail.cpp index 90ed1fe0d..51bab82cc 100644 --- a/src/d/actor/d_a_sail.cpp +++ b/src/d/actor/d_a_sail.cpp @@ -8,12 +8,30 @@ #include "d/res/res_cloth.h" #include "d/d_procname.h" #include "d/d_com_inf_game.h" +#include "d/d_kankyo_wether.h" #include "d/actor/d_a_obj_pirateship.h" #include "f_op/f_op_actor_mng.h" #include "m_Do/m_Do_mtx.h" #include "SSystem/SComponent/c_lib.h" -static u8 dummy_bss[0x4C]; +static Vec bss_3569; +// Not sure what these are, but they have size 1, and alignment 1 in the debug maps, but alignment 4 in the non-debug maps. +static u8 bss_1036 ALIGN_DECL(4); +static u8 bss_1034 ALIGN_DECL(4); +static u8 bss_1032 ALIGN_DECL(4); +static u8 bss_1031 ALIGN_DECL(4); +static u8 bss_1026 ALIGN_DECL(4); +static u8 bss_1024 ALIGN_DECL(4); +static u8 bss_1022 ALIGN_DECL(4); +static u8 bss_1021 ALIGN_DECL(4); +static u8 bss_984 ALIGN_DECL(4); +static u8 bss_982 ALIGN_DECL(4); +static u8 bss_980 ALIGN_DECL(4); +static u8 bss_979 ALIGN_DECL(4); +static u8 bss_941 ALIGN_DECL(4); +static u8 bss_939 ALIGN_DECL(4); +static u8 bss_937 ALIGN_DECL(4); +static u8 bss_936 ALIGN_DECL(4); // Needed for the .data section to match. static f32 dummy1[3] = {1.0f, 1.0f, 1.0f}; @@ -438,8 +456,39 @@ u8 l_AmastDL[] ALIGN_DECL(32) = { }; /* 000000EC-00000364 .text setCorrectNrmAngle__15daSail_packet_cFsf */ -void daSail_packet_c::setCorrectNrmAngle(short, float) { - /* Nonmatching */ +void daSail_packet_c::setCorrectNrmAngle(s16 param_0, f32 param_1) { + s16 rnd = 900 + (s32)cM_rndF(200.0f); + this->m1C38 += rnd; + + this->m1C34 = 300.0f * JMASSin(this->m1C38); + + s16 r28 = param_0 + 0x8000; + s32 r27 = param_0; + + s16 r26 = l_HIO.m10 * (1.0f - 0.5f * param_1); + s32 r0 = abs(r28); + s16 r30 = 1.25f * r26 * 182.04445f; + + if (r0 < r30) { + s16 r4; + if (r28 > 0) { + r4 = (s32)(-r26 * 182.04445f); + } else { + r4 = (s32)(r26 * 182.04445f); + } + cLib_addCalcAngleS2(&this->m1C36, r4, 5, 192); + } else if (abs(r27) < r30) { + s16 r4; + if ((s16)r27 > 0) { + r4 = (s32)(-r26 * 182.04445f); + } else { + r4 = (s32)(r26 * 182.04445f); + } + cLib_addCalcAngleS2(&this->m1C36, r4, 5, 192); + } else { + cLib_addCalcAngleS2(&this->m1C36, 0, 5, 192); + } + this->m1C34 += this->m1C36; } /* 00000364-00000398 .text setNrmMtx__15daSail_packet_cFv */ @@ -449,39 +498,446 @@ void daSail_packet_c::setNrmMtx() { /* 00000398-00000424 .text setBackNrm__15daSail_packet_cFv */ void daSail_packet_c::setBackNrm() { - /* Nonmatching */ + cXyz* nrm1 = this->get_nrm1(0); + cXyz* nrm2 = this->get_nrm2(0); + for (int i = 0; i < 0x54; i++) { + nrm2->setall(0.0f); + VECSubtract(nrm2, nrm1, nrm2); + nrm1++; + nrm2++; + } } /* 00000424-00000834 .text setNrmVtx__15daSail_packet_cFP4cXyzii */ -void daSail_packet_c::setNrmVtx(cXyz*, int, int) { - /* Nonmatching */ +void daSail_packet_c::setNrmVtx(cXyz* param_0, int param_1, int param_2) { + cXyz spF8; + cXyz spEC; + cXyz spE0; + cXyz spD4; + cXyz spC8; + cXyz* vtxPos = this->get_pos(0); + s32 idx = param_2 * 7; + spC8.set(vtxPos[param_1 + idx]); + spD4.setall(0.0f); + + if (param_1 != 0) { + spF8 = vtxPos[idx - 1 + param_1] - spC8; + if (param_2 != 0) { + spEC = vtxPos[(param_2 - 1) * 7 + param_1] - spC8; + spE0 = spEC.outprod(spF8); + spE0 = spE0.normZC(); + VECAdd(&spD4, &spE0, &spD4); + } + if (param_2 != 11) { + spEC = vtxPos[(param_2 + 1) * 7 + param_1] - spC8; + spE0 = spF8.outprod(spEC); + spE0 = spE0.normZC(); + VECAdd(&spD4, &spE0, &spD4); + } + } + if (param_1 != 6) { + spF8 = vtxPos[param_1 + 1 + idx] - spC8; + if (param_2 != 0) { + spEC = vtxPos[(param_2 - 1) * 7 + param_1] - spC8; + spE0 = spF8.outprod(spEC); + spE0 = spE0.normZC(); + VECAdd(&spD4, &spE0, &spD4); + } + if (param_2 != 11) { + spEC = vtxPos[(param_2 + 1) * 7 + param_1] - spC8; + spE0 = spEC.outprod(spF8); + spE0 = spE0.normZC(); + VECAdd(&spD4, &spE0, &spD4); + } + } + + spD4 = spD4.normZC(); + + MtxPush(); + mDoMtx_YrotM(*calc_mtx, JMASSin(-800 * (param_1 + param_2)) * 900.0f); + MtxPosition(&spD4, &spE0); + *param_0 = spE0.normZC(); + MtxPull(); } /* 00000870-000010D8 .text draw__15daSail_packet_cFv */ void daSail_packet_c::draw() { - /* Nonmatching */ - dComIfG_getObjectRes("Kaizokusen", KAIZOKUSEN_INDEX_BTI_TXA_KAIZOKU_HO); - dComIfG_getObjectRes("Cloth", CLOTH_BTI_CLOTHTOON); + j3dSys.reinitGX(); +#if VERSION != VERSION_JPN + GXSetNumIndStages(0); +#endif + + dKy_GxFog_tevstr_set(this->mA0); + + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_INDEX8); + GXSetVtxDesc(GX_VA_NRM, GX_INDEX8); + GXSetVtxDesc(GX_VA_TEX0, GX_INDEX8); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_POS_XY, GX_F32, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_POS_XYZ, GX_F32, 0); + + GXSetArray(GX_VA_POS, this->get_pos(0), sizeof(cXyz)); + GXSetArray(GX_VA_NRM, this->get_nrm1(0), sizeof(cXyz)); + GXSetArray(GX_VA_TEX0, l_texCoord, sizeof(*l_texCoord)); + + GXTexObj texObj; + + ResTIMG* kaizokusen = (ResTIMG*)dComIfG_getObjectRes("Kaizokusen", KAIZOKUSEN_INDEX_BTI_TXA_KAIZOKU_HO); + GXInitTexObj(&texObj, (u8*)kaizokusen + kaizokusen->imageOffset, kaizokusen->width, kaizokusen->height, + (GXTexFmt)kaizokusen->format, (GXTexWrapMode)kaizokusen->wrapS, (GXTexWrapMode)kaizokusen->wrapT, + kaizokusen->mipmapCount > 1); + GXInitTexObjLOD(&texObj, (GXTexFilter)kaizokusen->minFilter, (GXTexFilter)kaizokusen->magFilter, + kaizokusen->minLOD * 0.125f, kaizokusen->maxLOD * 0.125f, kaizokusen->LODBias * 0.01f, + kaizokusen->biasClamp, kaizokusen->doEdgeLOD, (GXAnisotropy)kaizokusen->maxAnisotropy); + GXLoadTexObj(&texObj, GX_TEXMAP0); + + ResTIMG* cloth = (ResTIMG*)dComIfG_getObjectRes("Cloth", CLOTH_BTI_CLOTHTOON); + GXInitTexObj(&texObj, (u8*)cloth + cloth->imageOffset, cloth->width, cloth->height, + (GXTexFmt)cloth->format, (GXTexWrapMode)cloth->wrapS, (GXTexWrapMode)cloth->wrapT, + cloth->mipmapCount > 1); + GXInitTexObjLOD(&texObj, (GXTexFilter)cloth->minFilter, (GXTexFilter)cloth->magFilter, + cloth->minLOD * 0.125f, cloth->maxLOD * 0.125f, cloth->LODBias * 0.01f, + cloth->biasClamp, cloth->doEdgeLOD, (GXAnisotropy)cloth->maxAnisotropy); + GXLoadTexObj(&texObj, GX_TEXMAP1); + + GXSetNumChans(1); + + u8 numTevStages, lightMask; + if (this->mA0->mColorK1.a != 0) { + numTevStages = 3; + lightMask = GX_LIGHT0 | GX_LIGHT1; + } else { + numTevStages = 2; + lightMask = GX_LIGHT0; + } + + if (l_HIO.m05 != 0) { + GXSetChanCtrl(GX_COLOR0, 1, GX_SRC_REG, GX_SRC_REG, lightMask, GX_DF_CLAMP, GX_AF_NONE); + GXSetNumTexGens(2); + GXLoadTexMtxImm(this->m0040, 30, GX_MTX3x4); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, 30, GX_FALSE, 125); + GXSetTexCoordGen2(GX_TEXCOORD1, GX_TG_SRTG, GX_TG_COLOR0, 60, GX_FALSE, 125); + GXSetNumTevStages(numTevStages); + GXSetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP1); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR0A0); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_C0, GX_CC_C1, GX_CC_TEXC, GX_CC_ZERO); + GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO); + GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevSwapMode(GX_TEVSTAGE1, GX_TEV_SWAP0, GX_TEV_SWAP0); + GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_TEXC, GX_CC_CPREV, GX_CC_ZERO); + GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA); + GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + if (numTevStages == 3) { + GXSetTevSwapMode(GX_TEVSTAGE2, GX_TEV_SWAP0, GX_TEV_SWAP2); + GXSetTevOrder(GX_TEVSTAGE2, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE2, GX_CC_ZERO, GX_CC_C2, GX_CC_TEXC, GX_CC_CPREV); + GXSetTevColorOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE2, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_APREV); + GXSetTevAlphaOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + } + } else { + GXSetChanCtrl(GX_COLOR0, 1, GX_SRC_REG, GX_SRC_REG, lightMask, GX_DF_CLAMP, GX_AF_NONE); + GXSetNumTexGens(1); + GXLoadTexMtxImm(this->m0040, 30, GX_MTX3x4); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, 30, GX_FALSE, 125); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, 60, GX_FALSE, 125); + GXSetNumTevStages(numTevStages); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP1, GX_TEV_SWAP0); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_C0, GX_CC_C1, GX_CC_RASC, GX_CC_ZERO); + GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO); + GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevSwapMode(GX_TEVSTAGE1, GX_TEV_SWAP0, GX_TEV_SWAP0); + GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_CPREV, GX_CC_TEXC, GX_CC_ZERO); + GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA); + GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + if (numTevStages == 3) { + GXSetTevSwapMode(GX_TEVSTAGE2, GX_TEV_SWAP2, GX_TEV_SWAP0); + GXSetTevOrder(GX_TEVSTAGE2, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE2, GX_CC_ZERO, GX_CC_C2, GX_CC_RASC, GX_CC_CPREV); + GXSetTevColorOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE2, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_APREV); + GXSetTevAlphaOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + } + } + + GXSetTevColorS10(GX_TEVREG0, this->mA0->mColorC0); + GXSetTevColor(GX_TEVREG1, this->mA0->mColorK0); + GXSetTevColor(GX_TEVREG2, this->mA0->mColorK1); + GXCallDisplayList(l_sail_matDL, 0x20); + + GXLoadPosMtxImm(this->m0010, 0); + GXLoadNrmMtxImm(this->m0010, 0); + + GXSetZCompLoc(GX_FALSE); + GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); + GXSetCullMode(GX_CULL_BACK); + GXCallDisplayList(l_sail_DL, 0x200); + + GXSetCullMode(GX_CULL_FRONT); + GXSetArray(GX_VA_NRM, this->get_nrm2(0), sizeof(cXyz)); + GXCallDisplayList(l_sail_DL, 0x200); + +#if VERSION != VERSION_JPN + J3DShape::sOldVcdVatCmd = NULL; +#endif } /* 000010D8-000013CC .text daSail_Draw__FP10sail_class */ static BOOL daSail_Draw(sail_class* i_this) { - /* Nonmatching */ + if (l_p_ship->m2CC == 0) { + return FALSE; + } + + i_this->tevStr = l_p_ship->tevStr; + + g_env_light.settingTevStruct(0, &i_this->current.pos, &i_this->tevStr); + g_env_light.setLightTevColorType(i_this->mSailPacket.m1C3C, &i_this->tevStr); + mDoExt_modelUpdateDL(i_this->mSailPacket.m1C3C); + + MtxTrans(i_this->current.pos.x, i_this->current.pos.y, i_this->current.pos.z, 0); + mDoMtx_YrotM(*calc_mtx, i_this->current.angle.y); + mDoMtx_XrotM(*calc_mtx, i_this->current.angle.x); + mDoMtx_ZrotM(*calc_mtx, i_this->current.angle.z); + + mDoMtx_concat(j3dSys.mViewMtx, *calc_mtx, *i_this->mSailPacket.get_m0010()); + + cXyz* vtxPos = i_this->mSailPacket.get_pos(1); + MtxTrans( + i_this->current.pos.x, + i_this->current.pos.y + vtxPos[-1].y, + i_this->current.pos.z, + 0 + ); + + mDoMtx_YrotM(*calc_mtx, i_this->current.angle.y); + mDoMtx_XrotM(*calc_mtx, i_this->current.angle.x); + mDoMtx_ZrotM(*calc_mtx, i_this->current.angle.z); + + mDoMtx_concat(j3dSys.mViewMtx, *calc_mtx, *i_this->mSailPacket.get_m0070()); + mDoMtx_copy(*calc_mtx, i_this->mSailPacket.m1C3C->mBaseTransformMtx); + + MtxTrans(0.0f, 0.0f, 0.0f, 0); + mDoMtx_copy(*calc_mtx, i_this->mSailPacket.m0040); + + i_this->mSailPacket.mA0 = &i_this->tevStr; + + j3dSys.getDrawBuffer(0)->entryImm(&i_this->mSailPacket, 0); + + return TRUE; } /* 000013CC-00001CEC .text sail_pos_move__FP10sail_class */ static void sail_pos_move(sail_class* i_this) { - /* Nonmatching */ + cXyz* windVec = dKyw_get_wind_vec(); + s16 windAngle = cM_atan2s(windVec->x, windVec->z); + mDoMtx_YrotS(*calc_mtx, -(i_this->current.angle.y - windAngle)); + + cXyz sp28; + cXyz sp1C; + cXyz sp10; + + sp28.set(0.0f, 0.0f, 0.064f); + MtxPosition(&sp28, &sp1C); + + f32 f31 = (0.9f * std::fabsf(sp1C.z)) + 0.02f + (0.064f / 10.0f); + sp28.x = 0.0f; + sp28.z = 1.0f; + MtxPosition(&sp28, &sp1C); + + f32 f25 = (0.9f * std::fabsf(sp1C.z)) + 0.1f; + f32 f0 = std::fabsf(sp1C.x); + + i_this->mSailPacket.m1C40 += (s32)((1.0f - (i_this->mSailPacket.m1C44 * 0.95f)) * 4000.0f) * ((f25 * 0.85f) + 0.15f); + i_this->mSailPacket.m1C50 = ((f0 * 1.5f) + 1.0f) * 7500.0f; + i_this->mSailPacket.m1C52 = ((f25 * 0.95f) + 0.05f) * 7200.0f; + + cXyz* vtxPos = i_this->mSailPacket.get_pos(0); + f32 sp6C[7] = {}; + f32 sp34[7] = {}; + + f25 *= 1.0f - (0.5f * i_this->mSailPacket.m1C44 * i_this->mSailPacket.m1C4C); + f0 *= 1.0f - (0.75f * i_this->mSailPacket.m1C44); + + f32 ELEVEN = 11.0f; + + for (int i = 0; i < 12; i++) { + f32 f12 = i - 6; + f32 f13 = i - 5.5f; + + sp10.z = f25 * (-ELEVEN * f12 * f12 + 396.0f); + + for (int j = 0; j < 7; j++, vtxPos++) { + f32 f24; + f32 f23 = j - 3; + f32 f22; + f32 f21; + f32 f20; + f32 f17 = i * 5.0f; + + u32 r22 = (i_this->mSailPacket.m1C50 * (s32)f23) + (i_this->mSailPacket.m1C52 * (s32)f12); + + f20 = 1750.0f * ((f0 * f0) + 0.05f) * JMASSin(-i_this->mSailPacket.m1C40 + r22) * f31; + f22 = 550.0f * ((f0 * f0) + 0.1f) * JMASCos(i_this->mSailPacket.m1C40 + r22) * f31; + f21 = std::sqrtf((f22 * f22) + (f20 * f20)) * 0.1f; + + f24 = (f25 * ((10.0f * f17) + (-f17 * f23 * f23))); + f24 += ((sp10.z * (18.0f - f23 * f23)) / 18.0f); + + f32 f15 = f24 - sp34[j]; + + f32 f16; + if (f15 > 100.0f) { + f16 = 100.0f; + sp34[j] += 100.0f; + } else { + f16 = -100.0f; + if (f15 < f16) { + sp34[j] -= 100.0f; + } else { + f16 = f15; + sp34[j] = f24; + } + } + + f32 f14 = 100.0f - std::sqrtf(15625.0f - (f16 * f16)); + sp6C[j] += f14 > -10.0f ? f14 : -10.0f; + + sp10.x = 0.0f; + sp10.y = 0.0f; + if (i < 3) { + f22 *= i * 0.33f; + f21 *= i * 0.33f; + f20 *= i * 0.33f; + } else if (i == 11 && std::fabsf(f23) == 3.0f) { + f22 = 0.0f; + f21 = 0.0f; + f20 = 0.0f; + } + + vtxPos->x = sp10.x + f22; + vtxPos->y = ((sp6C[j] + sp10.y + f21) - (i * 1.25f * (f23 * f23))); + vtxPos->z = f24 + f20; + + vtxPos->x += l_pos[i * 7 + j].x; + vtxPos->y += l_pos[i * 7 + j].y; + vtxPos->z += l_pos[i * 7 + j].z; + + vtxPos->y *= (1.0f - ((i_this->mSailPacket.m1C44 * (f13 * f13)) / 30.25f)); + vtxPos->y *= ((ELEVEN - (i_this->mSailPacket.m1C44 * i)) / ELEVEN); + vtxPos->z *= (1.0f - ((i_this->mSailPacket.m1C44 * (f13 * f13)) / 30.25f)); + vtxPos->z *= ((ELEVEN - (i_this->mSailPacket.m1C44 * i)) / ELEVEN); + + f32 f14_2 = i_this->mSailPacket.m1C44; + + if (f14_2 > 0.0f && i < 6) { + f32 f15_2 = i - 3; + f32 f20 = (9.0f - (f15_2 * f15_2)) / 9.0f; + vtxPos->z += (700.0f * f20 * f14_2); + vtxPos->y -= (150.0f * f20 * i_this->mSailPacket.m1C44); + } + + vtxPos->y *= (0.3f * (j & 1) * i_this->mSailPacket.m1C44) + (1.0f - i_this->mSailPacket.m1C44); + vtxPos->z *= (0.15f * (j & 1) * i_this->mSailPacket.m1C44) + (1.0f - i_this->mSailPacket.m1C44); + } + } } /* 00001CEC-00001DB0 .text demo_move__FP10sail_class */ -static void demo_move(sail_class* i_this) { - /* Nonmatching */ +static BOOL demo_move(sail_class* i_this) { + if (i_this->demoActorID == 0) { + return FALSE; + } + dDemo_actor_c* demo = g_dComIfG_gameInfo.play.mDemo->mDemoObj.getActor(i_this->demoActorID); + if (demo != NULL) { + if (demo->checkEnable(0x40)) { + f32 frame = demo->mAnimationFrame; + frame = 0.6f - (frame * 0.006f); + i_this->mSailPacket.m1C44 = frame; + i_this->mSailPacket.m1C44 = cLib_minMaxLimit(i_this->mSailPacket.m1C44, 0.0f, 0.6f); + } + return TRUE; + } + return FALSE; } /* 00001DB0-00002094 .text sail_move__FP10sail_class */ static void sail_move(sail_class* i_this) { - /* Nonmatching */ + cXyz* windVec = dKyw_get_wind_vec(); + if (l_HIO.m06 == 0 && i_this->mSailPacket.m1C44 < 0.6f) { + if (i_this->mSailPacket.m1C48 <= 0.0f) { + i_this->mSailPacket.m1C48 = 0.015f; + } else { + i_this->mSailPacket.m1C48 -= 0.001f; + } + cLib_addCalc(&i_this->mSailPacket.m1C44, 0.6f, 0.1f, i_this->mSailPacket.m1C48, 0.01f); + } else { + if (l_HIO.m06 == 1 && i_this->mSailPacket.m1C44 > 0.0f) { + i_this->mSailPacket.m1C48 += 0.0075f; + cLib_addCalc(&i_this->mSailPacket.m1C44, 0.0f, 0.3f, i_this->mSailPacket.m1C48, 0.01f); + } else { + i_this->mSailPacket.m1C48 = 0.0f; + } + } + + if (i_this->mSailPacket.m1C44 > 1.0f) { + i_this->mSailPacket.m1C44 = 1.0f; + } else if (i_this->mSailPacket.m1C44 < 0.0f) { + i_this->mSailPacket.m1C44 = 0.0f; + } + + if (!demo_move(i_this) && l_HIO.m08 != 0) { + i_this->mSailPacket.m1C44 = l_HIO.m0C; + } + i_this->mSailPacket.m1C4C = (i_this->mSailPacket.m1C44 - 0.6f) * 15.0f; + + s16 windAngle = cM_atan2s(windVec->x, windVec->z); + mDoMtx_YrotS(*calc_mtx, -(i_this->current.angle.y - windAngle)); + + cXyz sp2C(0.0f, 0.0f, 0.064f); + cXyz sp20; + MtxPosition(&sp2C, &sp20); + + sp2C.x = 0.0f; + sp2C.z = 1.0f; + MtxPosition(&sp2C, &sp20); + + f32 f31_1 = std::fabsf(sp20.z); + sail_pos_move(i_this); + f32 f31_2 = f31_1 * (1.0f - (i_this->mSailPacket.m1C44 * 0.5f * i_this->mSailPacket.m1C4C)); + + cXyz* vtxPos = i_this->mSailPacket.get_pos(3); + + s16 angleY = i_this->current.angle.y; + cXyz light; + dKy_FirstlightVec_get(&light); + s16 lightAngle = cM_atan2s(light.x, light.z); + + i_this->mSailPacket.setCorrectNrmAngle(lightAngle - angleY, f31_2); + + i_this->mSailPacket.setNrmMtx(); + for (int i = 0; i < 12; i++) { + for (int j = 0; j < 7; j++) { + i_this->mSailPacket.setNrmVtx(vtxPos, j, i); + vtxPos++; + } + } + i_this->mSailPacket.setBackNrm(); + +#if VERSION == VERSION_JPN + DCStoreRangeNoSync(i_this->mSailPacket.get_pos(0), 0x14ac0); +#else + DCStoreRangeNoSync(i_this->mSailPacket.get_pos(0), 0x03f0); + DCStoreRangeNoSync(i_this->mSailPacket.get_pos(3), 0x03f0); + DCStoreRangeNoSync(i_this->mSailPacket.get_pos(5), 0x03f0); +#endif } /* 00002094-00002154 .text daSail_Execute__FP10sail_class */ @@ -519,7 +975,7 @@ static BOOL daSail_checkCreateHeap(fopAc_ac_c* i_actor) { return FALSE; } i_this->mSailPacket.m1C3C = mDoExt_J3DModel__create(modelData, 0x00080000, 0x11000002); - if (i_this->mSailPacket.m1C3C) { + if (i_this->mSailPacket.m1C3C != NULL) { return TRUE; } else { return FALSE; @@ -528,20 +984,21 @@ static BOOL daSail_checkCreateHeap(fopAc_ac_c* i_actor) { /* 00002254-000024E4 .text daSail_Create__FP10fopAc_ac_c */ static s32 daSail_Create(fopAc_ac_c* i_actor) { - /* Nonmatching */ fopAcM_SetupActor(i_actor, sail_class); sail_class* i_this = (sail_class*)i_actor; - int phase_state = dComIfG_resLoad(&i_this->mClothPhase, "Cloth"); - if (phase_state != cPhs_COMPLEATE_e) { - return phase_state; - } - phase_state = dComIfG_resLoad(&i_this->mKaizokusenPhase, "Kaizokusen"); - if (phase_state != cPhs_COMPLEATE_e) { - return phase_state; + { + int phase_state = dComIfG_resLoad(&i_this->mClothPhase, "Cloth"); + if (phase_state != cPhs_COMPLEATE_e) { + return phase_state; + } + phase_state = dComIfG_resLoad(&i_this->mKaizokusenPhase, "Kaizokusen"); + if (phase_state != cPhs_COMPLEATE_e) { + return phase_state; + } } - phase_state = cPhs_COMPLEATE_e; + int phase_state = cPhs_COMPLEATE_e; if (fopAcM_entrySolidHeap(i_this, daSail_checkCreateHeap, 0x4C0)) { if (l_HIO.mChildID < 0) { l_HIO.mChildID = mDoHIO_root.m_subroot.createChild("海賊船の帆", &l_HIO); // "Pirate Ship's Sail" @@ -549,8 +1006,8 @@ static s32 daSail_Create(fopAc_ac_c* i_actor) { i_this->mSailPacket.m1C44 = 0.0f; i_this->mSailPacket.m1C48 = 0.0f; - cXyz* r6 = &i_this->mSailPacket.m0884[0]; - cXyz* r7 = &i_this->mSailPacket.m00A4[i_this->mSailPacket.m1C3A * 0x54]; // this is probably one of daSail_packet_c's inlines + cXyz* r6 = i_this->mSailPacket.m0884; + cXyz* r7 = i_this->mSailPacket.get_pos(0); for (int i = 0; i < ARRAY_SIZE(l_pos); i++, r6++, r7++) { r6->setall(0.0f); r7->set(l_pos[i]); From 86ed152aeae138c369fc2f135b8bb731b59f4710 Mon Sep 17 00:00:00 2001 From: LDA Date: Sat, 7 Sep 2024 20:24:06 -0700 Subject: [PATCH 2/3] add some comments --- src/d/actor/d_a_sail.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/d/actor/d_a_sail.cpp b/src/d/actor/d_a_sail.cpp index 51bab82cc..7eb48d530 100644 --- a/src/d/actor/d_a_sail.cpp +++ b/src/d/actor/d_a_sail.cpp @@ -563,6 +563,7 @@ void daSail_packet_c::setNrmVtx(cXyz* param_0, int param_1, int param_2) { /* 00000870-000010D8 .text draw__15daSail_packet_cFv */ void daSail_packet_c::draw() { j3dSys.reinitGX(); + #if VERSION != VERSION_JPN GXSetNumIndStages(0); #endif @@ -766,7 +767,7 @@ static void sail_pos_move(sail_class* i_this) { f25 *= 1.0f - (0.5f * i_this->mSailPacket.m1C44 * i_this->mSailPacket.m1C4C); f0 *= 1.0f - (0.75f * i_this->mSailPacket.m1C44); - f32 ELEVEN = 11.0f; + f32 ELEVEN = 11.0f; // this must be non-const for (int i = 0; i < 12; i++) { f32 f12 = i - 6; @@ -777,9 +778,7 @@ static void sail_pos_move(sail_class* i_this) { for (int j = 0; j < 7; j++, vtxPos++) { f32 f24; f32 f23 = j - 3; - f32 f22; - f32 f21; - f32 f20; + f32 f22, f21, f20; // these are xyz components f32 f17 = i * 5.0f; u32 r22 = (i_this->mSailPacket.m1C50 * (s32)f23) + (i_this->mSailPacket.m1C52 * (s32)f12); @@ -807,8 +806,8 @@ static void sail_pos_move(sail_class* i_this) { } } - f32 f14 = 100.0f - std::sqrtf(15625.0f - (f16 * f16)); - sp6C[j] += f14 > -10.0f ? f14 : -10.0f; + f32 f14 = 100.0f - std::sqrtf((125.0f * 125.0f) - (f16 * f16)); + sp6C[j] += f14 > -10.0f ? f14 : -10.0f; // this looks like cLib_minLimit but it does not match sp10.x = 0.0f; sp10.y = 0.0f; From 06e8f92d33bf3ad2d8d32f62185f521c1e5de82c Mon Sep 17 00:00:00 2001 From: LDA Date: Sun, 8 Sep 2024 16:28:06 -0700 Subject: [PATCH 3/3] d_a_sail amendment --- include/d/actor/d_a_sail.h | 43 +++++------- src/d/actor/d_a_sail.cpp | 134 +++++++++++++++++-------------------- 2 files changed, 78 insertions(+), 99 deletions(-) diff --git a/include/d/actor/d_a_sail.h b/include/d/actor/d_a_sail.h index ea8770fc6..ecbfc59c1 100644 --- a/include/d/actor/d_a_sail.h +++ b/include/d/actor/d_a_sail.h @@ -15,26 +15,27 @@ class daSail_packet_c : public J3DPacket { m1C36 = 0; m1C3B = 1; } - - void getMtx() {} - void getNrm() {} - void getPos() {} - void getPosSpd() {} - void getStickMtx() {} - void getTexMtx() {} - void setTevStr(dKy_tevstr_c*) {} + + Mtx* getMtx() { return &mMtx; } + cXyz* getNrm() { return m0C74 + (0x54 * m1C3A); } + cXyz* getPos() { return m00A4 + (0x54 * m1C3A); } + cXyz* getPosSpd() { return m0884; } + Mtx* getStickMtx() { return &mStickMtx; } + Mtx* getTexMtx() { return &mTexMtx; } + void setTevStr(dKy_tevstr_c* tevStr) { mTevStr = tevStr; } void setCorrectNrmAngle(s16, f32); void setNrmMtx(); void setBackNrm(); void setNrmVtx(cXyz*, int, int); virtual void draw(); + virtual ~daSail_packet_c() {} public: - /* 0x0010 */ Mtx m0010; - /* 0x0040 */ Mtx m0040; - /* 0x0070 */ Mtx m0070; - /* 0x00A0 */ dKy_tevstr_c *mA0; + /* 0x0010 */ Mtx mMtx; + /* 0x0040 */ Mtx mTexMtx; + /* 0x0070 */ Mtx mStickMtx; + /* 0x00A0 */ dKy_tevstr_c* mTevStr; /* 0x00A4 */ cXyz m00A4[0x54 * 2]; /* 0x0884 */ cXyz m0884[0x54]; /* 0x0C74 */ cXyz m0C74[0x54 * 2]; @@ -44,29 +45,19 @@ class daSail_packet_c : public J3DPacket { /* 0x1C38 */ s16 m1C38; /* 0x1C3A */ u8 m1C3A; /* 0x1C3B */ u8 m1C3B; - /* 0x1C3C */ J3DModel* m1C3C; + /* 0x1C3C */ J3DModel* mStickModel; /* 0x1C40 */ s32 m1C40; /* 0x1C44 */ f32 m1C44; /* 0x1C48 */ f32 m1C48; /* 0x1C4C */ f32 m1C4C; /* 0x1C50 */ s16 m1C50; /* 0x1C52 */ s16 m1C52; - - inline Mtx *get_m0010() { return &this->m0010; } - inline Mtx *get_m0070() { return &this->m0070; } - - inline cXyz* get_pos(s32 idx) { - return this->m00A4 + 0x54 * this->m1C3A + 0x54 * idx; - } - inline cXyz* get_nrm1(s32 idx) { - return this->m0C74 + 0x54 * this->m1C3A + 0x54 * idx; - } - inline cXyz* get_nrm2(s32 idx) { - return this->m1454 + 0x54 * this->m1C3A + 0x54 * idx; - } }; class sail_class : public fopAc_ac_c { +public: + sail_class() {} + public: /* 0x0290 */ request_of_phase_process_class mClothPhase; /* 0x0298 */ request_of_phase_process_class mKaizokusenPhase; diff --git a/src/d/actor/d_a_sail.cpp b/src/d/actor/d_a_sail.cpp index 7eb48d530..30ef953a2 100644 --- a/src/d/actor/d_a_sail.cpp +++ b/src/d/actor/d_a_sail.cpp @@ -457,38 +457,27 @@ u8 l_AmastDL[] ALIGN_DECL(32) = { /* 000000EC-00000364 .text setCorrectNrmAngle__15daSail_packet_cFsf */ void daSail_packet_c::setCorrectNrmAngle(s16 param_0, f32 param_1) { - s16 rnd = 900 + (s32)cM_rndF(200.0f); - this->m1C38 += rnd; + m1C38 += (s16)(900 + (s32)cM_rndF(200.0f)); - this->m1C34 = 300.0f * JMASSin(this->m1C38); + m1C34 = 300.0f * cM_ssin(m1C38); s16 r28 = param_0 + 0x8000; s32 r27 = param_0; s16 r26 = l_HIO.m10 * (1.0f - 0.5f * param_1); s32 r0 = abs(r28); - s16 r30 = 1.25f * r26 * 182.04445f; + s16 r30 = cAngle::d2s(1.25f * r26); if (r0 < r30) { - s16 r4; - if (r28 > 0) { - r4 = (s32)(-r26 * 182.04445f); - } else { - r4 = (s32)(r26 * 182.04445f); - } - cLib_addCalcAngleS2(&this->m1C36, r4, 5, 192); + s16 targetAngle = r28 > 0 ? (s16)cAngle::d2s(-r26) : (s16)cAngle::d2s(r26); + cLib_addCalcAngleS2(&m1C36, targetAngle, 5, 192); } else if (abs(r27) < r30) { - s16 r4; - if ((s16)r27 > 0) { - r4 = (s32)(-r26 * 182.04445f); - } else { - r4 = (s32)(r26 * 182.04445f); - } - cLib_addCalcAngleS2(&this->m1C36, r4, 5, 192); + s16 targetAngle = (s16)r27 > 0 ? (s16)cAngle::d2s(-r26) : (s16)cAngle::d2s(r26); + cLib_addCalcAngleS2(&m1C36, targetAngle, 5, 192); } else { - cLib_addCalcAngleS2(&this->m1C36, 0, 5, 192); + cLib_addCalcAngleS2(&m1C36, 0, 5, 192); } - this->m1C34 += this->m1C36; + m1C34 += m1C36; } /* 00000364-00000398 .text setNrmMtx__15daSail_packet_cFv */ @@ -498,13 +487,13 @@ void daSail_packet_c::setNrmMtx() { /* 00000398-00000424 .text setBackNrm__15daSail_packet_cFv */ void daSail_packet_c::setBackNrm() { - cXyz* nrm1 = this->get_nrm1(0); - cXyz* nrm2 = this->get_nrm2(0); + cXyz* vtxNrm1 = m0C74 + (0x54 * m1C3A); + cXyz* vtxNrm2 = m1454 + (0x54 * m1C3A); for (int i = 0; i < 0x54; i++) { - nrm2->setall(0.0f); - VECSubtract(nrm2, nrm1, nrm2); - nrm1++; - nrm2++; + vtxNrm2->setall(0.0f); + *vtxNrm2 -= *vtxNrm1; + vtxNrm1++; + vtxNrm2++; } } @@ -515,7 +504,7 @@ void daSail_packet_c::setNrmVtx(cXyz* param_0, int param_1, int param_2) { cXyz spE0; cXyz spD4; cXyz spC8; - cXyz* vtxPos = this->get_pos(0); + cXyz* vtxPos = getPos(); s32 idx = param_2 * 7; spC8.set(vtxPos[param_1 + idx]); spD4.setall(0.0f); @@ -526,13 +515,13 @@ void daSail_packet_c::setNrmVtx(cXyz* param_0, int param_1, int param_2) { spEC = vtxPos[(param_2 - 1) * 7 + param_1] - spC8; spE0 = spEC.outprod(spF8); spE0 = spE0.normZC(); - VECAdd(&spD4, &spE0, &spD4); + spD4 += spE0; } if (param_2 != 11) { spEC = vtxPos[(param_2 + 1) * 7 + param_1] - spC8; spE0 = spF8.outprod(spEC); spE0 = spE0.normZC(); - VECAdd(&spD4, &spE0, &spD4); + spD4 += spE0; } } if (param_1 != 6) { @@ -541,20 +530,20 @@ void daSail_packet_c::setNrmVtx(cXyz* param_0, int param_1, int param_2) { spEC = vtxPos[(param_2 - 1) * 7 + param_1] - spC8; spE0 = spF8.outprod(spEC); spE0 = spE0.normZC(); - VECAdd(&spD4, &spE0, &spD4); + spD4 += spE0; } if (param_2 != 11) { spEC = vtxPos[(param_2 + 1) * 7 + param_1] - spC8; spE0 = spEC.outprod(spF8); spE0 = spE0.normZC(); - VECAdd(&spD4, &spE0, &spD4); + spD4 += spE0; } } spD4 = spD4.normZC(); MtxPush(); - mDoMtx_YrotM(*calc_mtx, JMASSin(-800 * (param_1 + param_2)) * 900.0f); + mDoMtx_YrotM(*calc_mtx, cM_ssin(-800 * (param_1 + param_2)) * 900.0f); MtxPosition(&spD4, &spE0); *param_0 = spE0.normZC(); MtxPull(); @@ -568,7 +557,7 @@ void daSail_packet_c::draw() { GXSetNumIndStages(0); #endif - dKy_GxFog_tevstr_set(this->mA0); + dKy_GxFog_tevstr_set(mTevStr); GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); @@ -578,8 +567,8 @@ void daSail_packet_c::draw() { GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_POS_XY, GX_F32, 0); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_POS_XYZ, GX_F32, 0); - GXSetArray(GX_VA_POS, this->get_pos(0), sizeof(cXyz)); - GXSetArray(GX_VA_NRM, this->get_nrm1(0), sizeof(cXyz)); + GXSetArray(GX_VA_POS, getPos(), sizeof(cXyz)); + GXSetArray(GX_VA_NRM, getNrm(), sizeof(cXyz)); GXSetArray(GX_VA_TEX0, l_texCoord, sizeof(*l_texCoord)); GXTexObj texObj; @@ -605,7 +594,7 @@ void daSail_packet_c::draw() { GXSetNumChans(1); u8 numTevStages, lightMask; - if (this->mA0->mColorK1.a != 0) { + if (mTevStr->mColorK1.a != 0) { numTevStages = 3; lightMask = GX_LIGHT0 | GX_LIGHT1; } else { @@ -616,7 +605,7 @@ void daSail_packet_c::draw() { if (l_HIO.m05 != 0) { GXSetChanCtrl(GX_COLOR0, 1, GX_SRC_REG, GX_SRC_REG, lightMask, GX_DF_CLAMP, GX_AF_NONE); GXSetNumTexGens(2); - GXLoadTexMtxImm(this->m0040, 30, GX_MTX3x4); + GXLoadTexMtxImm(*getTexMtx(), 30, GX_MTX3x4); GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, 30, GX_FALSE, 125); GXSetTexCoordGen2(GX_TEXCOORD1, GX_TG_SRTG, GX_TG_COLOR0, 60, GX_FALSE, 125); GXSetNumTevStages(numTevStages); @@ -643,7 +632,7 @@ void daSail_packet_c::draw() { } else { GXSetChanCtrl(GX_COLOR0, 1, GX_SRC_REG, GX_SRC_REG, lightMask, GX_DF_CLAMP, GX_AF_NONE); GXSetNumTexGens(1); - GXLoadTexMtxImm(this->m0040, 30, GX_MTX3x4); + GXLoadTexMtxImm(*getTexMtx(), 30, GX_MTX3x4); GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, 30, GX_FALSE, 125); GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, 60, GX_FALSE, 125); GXSetNumTevStages(numTevStages); @@ -669,13 +658,13 @@ void daSail_packet_c::draw() { } } - GXSetTevColorS10(GX_TEVREG0, this->mA0->mColorC0); - GXSetTevColor(GX_TEVREG1, this->mA0->mColorK0); - GXSetTevColor(GX_TEVREG2, this->mA0->mColorK1); + GXSetTevColorS10(GX_TEVREG0, mTevStr->mColorC0); + GXSetTevColor(GX_TEVREG1, mTevStr->mColorK0); + GXSetTevColor(GX_TEVREG2, mTevStr->mColorK1); GXCallDisplayList(l_sail_matDL, 0x20); - GXLoadPosMtxImm(this->m0010, 0); - GXLoadNrmMtxImm(this->m0010, 0); + GXLoadPosMtxImm(*getMtx(), 0); + GXLoadNrmMtxImm(*getMtx(), 0); GXSetZCompLoc(GX_FALSE); GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); @@ -683,7 +672,7 @@ void daSail_packet_c::draw() { GXCallDisplayList(l_sail_DL, 0x200); GXSetCullMode(GX_CULL_FRONT); - GXSetArray(GX_VA_NRM, this->get_nrm2(0), sizeof(cXyz)); + GXSetArray(GX_VA_NRM, getNrm() + 2 * 0x54, sizeof(cXyz)); GXCallDisplayList(l_sail_DL, 0x200); #if VERSION != VERSION_JPN @@ -700,20 +689,20 @@ static BOOL daSail_Draw(sail_class* i_this) { i_this->tevStr = l_p_ship->tevStr; g_env_light.settingTevStruct(0, &i_this->current.pos, &i_this->tevStr); - g_env_light.setLightTevColorType(i_this->mSailPacket.m1C3C, &i_this->tevStr); - mDoExt_modelUpdateDL(i_this->mSailPacket.m1C3C); + g_env_light.setLightTevColorType(i_this->mSailPacket.mStickModel, &i_this->tevStr); + mDoExt_modelUpdateDL(i_this->mSailPacket.mStickModel); MtxTrans(i_this->current.pos.x, i_this->current.pos.y, i_this->current.pos.z, 0); mDoMtx_YrotM(*calc_mtx, i_this->current.angle.y); mDoMtx_XrotM(*calc_mtx, i_this->current.angle.x); mDoMtx_ZrotM(*calc_mtx, i_this->current.angle.z); - mDoMtx_concat(j3dSys.mViewMtx, *calc_mtx, *i_this->mSailPacket.get_m0010()); + mDoMtx_concat(j3dSys.mViewMtx, *calc_mtx, *i_this->mSailPacket.getMtx()); - cXyz* vtxPos = i_this->mSailPacket.get_pos(1); + cXyz* vtxPos = i_this->mSailPacket.getPos(); MtxTrans( i_this->current.pos.x, - i_this->current.pos.y + vtxPos[-1].y, + i_this->current.pos.y + vtxPos[0x53].y, i_this->current.pos.z, 0 ); @@ -722,13 +711,13 @@ static BOOL daSail_Draw(sail_class* i_this) { mDoMtx_XrotM(*calc_mtx, i_this->current.angle.x); mDoMtx_ZrotM(*calc_mtx, i_this->current.angle.z); - mDoMtx_concat(j3dSys.mViewMtx, *calc_mtx, *i_this->mSailPacket.get_m0070()); - mDoMtx_copy(*calc_mtx, i_this->mSailPacket.m1C3C->mBaseTransformMtx); + mDoMtx_concat(j3dSys.mViewMtx, *calc_mtx, *i_this->mSailPacket.getStickMtx()); + mDoMtx_copy(*calc_mtx, i_this->mSailPacket.mStickModel->mBaseTransformMtx); MtxTrans(0.0f, 0.0f, 0.0f, 0); - mDoMtx_copy(*calc_mtx, i_this->mSailPacket.m0040); + mDoMtx_copy(*calc_mtx, i_this->mSailPacket.mTexMtx); - i_this->mSailPacket.mA0 = &i_this->tevStr; + i_this->mSailPacket.setTevStr(&i_this->tevStr); j3dSys.getDrawBuffer(0)->entryImm(&i_this->mSailPacket, 0); @@ -760,7 +749,7 @@ static void sail_pos_move(sail_class* i_this) { i_this->mSailPacket.m1C50 = ((f0 * 1.5f) + 1.0f) * 7500.0f; i_this->mSailPacket.m1C52 = ((f25 * 0.95f) + 0.05f) * 7200.0f; - cXyz* vtxPos = i_this->mSailPacket.get_pos(0); + cXyz* vtxPos = i_this->mSailPacket.getPos(); f32 sp6C[7] = {}; f32 sp34[7] = {}; @@ -781,10 +770,11 @@ static void sail_pos_move(sail_class* i_this) { f32 f22, f21, f20; // these are xyz components f32 f17 = i * 5.0f; + // these explicit casts are necessary u32 r22 = (i_this->mSailPacket.m1C50 * (s32)f23) + (i_this->mSailPacket.m1C52 * (s32)f12); - f20 = 1750.0f * ((f0 * f0) + 0.05f) * JMASSin(-i_this->mSailPacket.m1C40 + r22) * f31; - f22 = 550.0f * ((f0 * f0) + 0.1f) * JMASCos(i_this->mSailPacket.m1C40 + r22) * f31; + f20 = 1750.0f * ((f0 * f0) + 0.05f) * cM_ssin(-i_this->mSailPacket.m1C40 + r22) * f31; + f22 = 550.0f * ((f0 * f0) + 0.1f) * cM_scos(i_this->mSailPacket.m1C40 + r22) * f31; f21 = std::sqrtf((f22 * f22) + (f20 * f20)) * 0.1f; f24 = (f25 * ((10.0f * f17) + (-f17 * f23 * f23))); @@ -807,7 +797,7 @@ static void sail_pos_move(sail_class* i_this) { } f32 f14 = 100.0f - std::sqrtf((125.0f * 125.0f) - (f16 * f16)); - sp6C[j] += f14 > -10.0f ? f14 : -10.0f; // this looks like cLib_minLimit but it does not match + sp6C[j] += f14 > -10.0f ? f14 : -10.0f; sp10.x = 0.0f; sp10.y = 0.0f; @@ -834,12 +824,10 @@ static void sail_pos_move(sail_class* i_this) { vtxPos->z *= (1.0f - ((i_this->mSailPacket.m1C44 * (f13 * f13)) / 30.25f)); vtxPos->z *= ((ELEVEN - (i_this->mSailPacket.m1C44 * i)) / ELEVEN); - f32 f14_2 = i_this->mSailPacket.m1C44; - - if (f14_2 > 0.0f && i < 6) { + if (i_this->mSailPacket.m1C44 > 0.0f && i < 6) { f32 f15_2 = i - 3; f32 f20 = (9.0f - (f15_2 * f15_2)) / 9.0f; - vtxPos->z += (700.0f * f20 * f14_2); + vtxPos->z += (700.0f * f20 * i_this->mSailPacket.m1C44); vtxPos->y -= (150.0f * f20 * i_this->mSailPacket.m1C44); } @@ -912,7 +900,7 @@ static void sail_move(sail_class* i_this) { sail_pos_move(i_this); f32 f31_2 = f31_1 * (1.0f - (i_this->mSailPacket.m1C44 * 0.5f * i_this->mSailPacket.m1C4C)); - cXyz* vtxPos = i_this->mSailPacket.get_pos(3); + cXyz* vtxPos = i_this->mSailPacket.getPos() + 3 * 0x54; s16 angleY = i_this->current.angle.y; cXyz light; @@ -931,11 +919,11 @@ static void sail_move(sail_class* i_this) { i_this->mSailPacket.setBackNrm(); #if VERSION == VERSION_JPN - DCStoreRangeNoSync(i_this->mSailPacket.get_pos(0), 0x14ac0); + DCStoreRangeNoSync(i_this->mSailPacket.getPos(), 0x14ac0); #else - DCStoreRangeNoSync(i_this->mSailPacket.get_pos(0), 0x03f0); - DCStoreRangeNoSync(i_this->mSailPacket.get_pos(3), 0x03f0); - DCStoreRangeNoSync(i_this->mSailPacket.get_pos(5), 0x03f0); + DCStoreRangeNoSync(i_this->mSailPacket.getPos() + 0 * 0x54, 0x03f0); + DCStoreRangeNoSync(i_this->mSailPacket.getPos() + 3 * 0x54, 0x03f0); + DCStoreRangeNoSync(i_this->mSailPacket.getPos() + 5 * 0x54, 0x03f0); #endif } @@ -973,8 +961,8 @@ static BOOL daSail_checkCreateHeap(fopAc_ac_c* i_actor) { if (modelData == NULL) { return FALSE; } - i_this->mSailPacket.m1C3C = mDoExt_J3DModel__create(modelData, 0x00080000, 0x11000002); - if (i_this->mSailPacket.m1C3C != NULL) { + i_this->mSailPacket.mStickModel = mDoExt_J3DModel__create(modelData, 0x00080000, 0x11000002); + if (i_this->mSailPacket.mStickModel != NULL) { return TRUE; } else { return FALSE; @@ -1005,11 +993,11 @@ static s32 daSail_Create(fopAc_ac_c* i_actor) { i_this->mSailPacket.m1C44 = 0.0f; i_this->mSailPacket.m1C48 = 0.0f; - cXyz* r6 = i_this->mSailPacket.m0884; - cXyz* r7 = i_this->mSailPacket.get_pos(0); - for (int i = 0; i < ARRAY_SIZE(l_pos); i++, r6++, r7++) { - r6->setall(0.0f); - r7->set(l_pos[i]); + cXyz* vtxPosSpd = i_this->mSailPacket.getPosSpd(); + cXyz* vtxPos = i_this->mSailPacket.getPos(); + for (int i = 0; i < ARRAY_SIZE(l_pos); i++, vtxPosSpd++, vtxPos++) { + vtxPosSpd->setall(0.0f); + vtxPos->set(l_pos[i]); } l_p_ship = (daObjPirateship::Act_c*)fopAcM_SearchByID(i_this->parentActorID);