diff --git a/configure.py b/configure.py index 64c20467a..5c51c7ae6 100755 --- a/configure.py +++ b/configure.py @@ -518,7 +518,7 @@ config.libs = [ Object(Matching, "d/d_event.cpp"), Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "d/d_event_data.cpp"), Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "d/d_event_manager.cpp"), - Object(NonMatching, "d/d_magma.cpp"), + Object(Matching, "d/d_magma.cpp"), Object(Matching, "d/d_boss_magma.cpp"), Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "d/d_grass.cpp"), Object(NonMatching, "d/d_tree.cpp"), diff --git a/include/d/d_magma.h b/include/d/d_magma.h index 8a201df96..2d95c2d0f 100644 --- a/include/d/d_magma.h +++ b/include/d/d_magma.h @@ -11,13 +11,12 @@ public: virtual ~dMagma_ball_c() {} virtual void calc(f32, u8, int) = 0; virtual void update() = 0; - virtual void setup(f32, u8, int) = 0; - void draw(); + void draw(); BOOL rangeCheck(cXyz&, f32*); -public: +protected: /* 0x04 */ cXyz mPos; /* 0x10 */ f32 mScale; /* 0x14 */ f32 mBaseY; @@ -35,7 +34,7 @@ public: virtual void update(); virtual void setup(f32, u8, int); -public: +private: /* 0x7C */ u8 mWaveTimer; }; @@ -47,7 +46,7 @@ public: virtual void update(); virtual void setup(f32, u8, int); -public: +private: /* 0x7C */ s16 field_0x7C; }; @@ -65,11 +64,13 @@ public: dMagma_floor_c* getNext() { return mpNext; } void setNext(dMagma_floor_c* v) { mpNext = v; } dMagma_ball_c** getBall() { return mpBalls; } - s32 getBallNum() { return mBallNum; } - cXyz& getPos() { return mPos; } + int getBallNum() { return mBallNum; } + cXyz* getPos() { return &mPos; } f32 getScaleX() { return mScaleX; } f32 getScaleZ() { return mScaleZ; } + void setYpos(f32 y) { mPos.y = y; } +private: /* 0x00 */ dMagma_ball_c** mpBalls; /* 0x04 */ u8 mBallNum; /* 0x05 */ u8 mPathNo; @@ -91,6 +92,7 @@ public: dMagma_room_c(); +private: /* 0x0 */ dMagma_floor_c* mpFirst; }; @@ -101,14 +103,14 @@ public: void update(); f32 checkYpos(cXyz&); dMagma_floor_c* newFloor(cXyz&, cXyz&, int, s16); - void deleteRoom(s32 roomNo) { mRoom[roomNo].deleteFloor(); } + void deleteRoom(int roomNo) { mRoom[roomNo].deleteFloor(); } virtual void draw(); virtual ~dMagma_packet_c(); - static GXTexObj& getKuroTexObj() { return mKuroTexObj; } - static GXTexObj& getColTexObj() { return mColTexObj; } - static Mtx& getKuroMtx() { return mKuroMtx; } + static GXTexObj* getKuroTexObj() { return &mKuroTexObj; } + static GXTexObj* getColTexObj() { return &mColTexObj; } + static MtxP getKuroMtx() { return mKuroMtx; } static GXTexObj mKuroTexObj; static Mtx mKuroMtx; @@ -116,10 +118,11 @@ public: static Mtx mBallMtx; static Mtx mFloorMtx; +private: /* 0x010 */ dMagma_floor_c mFloor[8]; /* 0x590 */ dMagma_room_c mRoom[64]; /* 0x690 */ GXColor mColor1; /* 0x694 */ f32 mTimer; }; -#endif /* D_MAGMA_H */ \ No newline at end of file +#endif /* D_MAGMA_H */ diff --git a/include/dolphin/gx/GXTexture.h b/include/dolphin/gx/GXTexture.h index 6da79b704..1cce7774e 100644 --- a/include/dolphin/gx/GXTexture.h +++ b/include/dolphin/gx/GXTexture.h @@ -17,8 +17,8 @@ void GXInitTexObjLOD(GXTexObj* obj, GXTexFilter min_filter, GXTexFilter max_filt f32 max_lod, f32 lod_bias, GXBool bias_clamp, GXBool edge_lod, GXAnisotropy aniso); void* GXGetTexObjData(GXTexObj* obj); -u16 GXGetTexObjWidth(GXTexObj* obj); -u16 GXGetTexObjHeight(GXTexObj* obj); +u16 GXGetTexObjWidth(const GXTexObj* obj); +u16 GXGetTexObjHeight(const GXTexObj* obj); GXTexFmt GXGetTexObjFmt(const GXTexObj* obj); GXTexWrapMode GXGetTexObjWrapS(GXTexObj* obj); GXTexWrapMode GXGetTexObjWrapT(GXTexObj* obj); diff --git a/src/d/actor/d_a_btd.cpp b/src/d/actor/d_a_btd.cpp index 3abf8af31..1e582f8ec 100644 --- a/src/d/actor/d_a_btd.cpp +++ b/src/d/actor/d_a_btd.cpp @@ -2400,7 +2400,7 @@ static BOOL daBtd_Execute(btd_class* i_this) { } i_this->m6E88 = 1; fVar12 = i_this->m6E80; - i_this->floor->getPos().y = fVar12; + i_this->floor->setYpos(fVar12); i_this->m6E7C += REG0_F(15) + 30.0f; if (i_this->m6E7C > REG0_F(18) + 2300.0f) { i_this->m6E7C = REG0_F(18) + 2300.0f; diff --git a/src/d/d_magma.cpp b/src/d/d_magma.cpp index 795808708..98e5cb4f6 100644 --- a/src/d/d_magma.cpp +++ b/src/d/d_magma.cpp @@ -13,11 +13,6 @@ Mtx l_kuroOrthoMtx; Mtx l_colOrthoMtx; -GXTexObj dMagma_packet_c::mKuroTexObj; -Mtx dMagma_packet_c::mKuroMtx; -GXTexObj dMagma_packet_c::mColTexObj; -Mtx dMagma_packet_c::mFloorMtx; -Mtx dMagma_packet_c::mBallMtx; Vec l_YfloorPos[] = { { -500.0f, -0.0f, 500.0f }, @@ -72,11 +67,20 @@ Vec l_YballPos[] = { void dMagma_ball_c::draw() { GXLoadTexMtxImm(mTexProjMtx, GX_TEXMTX2, GX_MTX3x4); GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX2, GX_FALSE, GX_PTTEXMTX0); - GXSetTexCoordScaleManually(GX_TEXCOORD0, GX_TRUE, GXGetTexObjWidth(&dMagma_packet_c::getKuroTexObj()), GXGetTexObjHeight(&dMagma_packet_c::getKuroTexObj())); +#if VERSION == VERSION_DEMO + // !@bug Copy paste error, using the height of ColTexObj instead of KuroTexObj. + GXSetTexCoordScaleManually(GX_TEXCOORD0, GX_TRUE, GXGetTexObjWidth(dMagma_packet_c::getKuroTexObj()), GXGetTexObjHeight(dMagma_packet_c::getColTexObj())); +#else + GXSetTexCoordScaleManually(GX_TEXCOORD0, GX_TRUE, GXGetTexObjWidth(dMagma_packet_c::getKuroTexObj()), GXGetTexObjHeight(dMagma_packet_c::getKuroTexObj())); +#endif +#if VERSION > VERSION_JPN GXSetTexCoordBias(GX_TEXCOORD0, GX_FALSE, GX_FALSE); +#endif GXSetTexCoordGen2(GX_TEXCOORD1, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX2, GX_FALSE, GX_PTTEXMTX1); - GXSetTexCoordScaleManually(GX_TEXCOORD1, GX_TRUE, GXGetTexObjWidth(&dMagma_packet_c::getColTexObj()), GXGetTexObjHeight(&dMagma_packet_c::getColTexObj())); + GXSetTexCoordScaleManually(GX_TEXCOORD1, GX_TRUE, GXGetTexObjWidth(dMagma_packet_c::getColTexObj()), GXGetTexObjHeight(dMagma_packet_c::getColTexObj())); +#if VERSION > VERSION_JPN GXSetTexCoordBias(GX_TEXCOORD1, GX_FALSE, GX_FALSE); +#endif GXLoadPosMtxImm(mPosMtx, GX_PNMTX0); GXCallDisplayList(l_YballDL, 0x60); } @@ -119,10 +123,8 @@ void dMagma_ballPath_c::update() { /* 800758B4-80075A6C .text setup__17dMagma_ballPath_cFfUci */ void dMagma_ballPath_c::setup(f32 offsY, u8 pathNo, int roomNo) { - /* Nonmatching */ dPath* path = dPath_GetRoomPath(pathNo, roomNo); - s32 ptNo = (s32)cM_rndF(path->m_num - 1); - dPnt* pt = &path->m_points[ptNo]; + dPnt* pt = &path->m_points[(int)cM_rndF(path->m_num - 1)]; mPos.x = pt->m_position.x + cM_rndFX(pt->mArg3 * 100.0f); mPos.z = pt->m_position.z + cM_rndFX(pt->mArg3 * 100.0f); mScale = cM_rndF(1.0f) + 1.0f; @@ -141,8 +143,15 @@ void dMagma_floor_c::draw() { GXLoadTexMtxImm(mTexMtx0, GX_TEXMTX2, GX_MTX3x4); GXLoadTexMtxImm(dMagma_packet_c::getKuroMtx(), (u32)GX_PTTEXMTX0, GX_MTX3x4); GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX2, GX_FALSE, GX_PTTEXMTX0); - GXSetTexCoordScaleManually(GX_TEXCOORD0, GX_TRUE, GXGetTexObjWidth(&dMagma_packet_c::getKuroTexObj()), GXGetTexObjHeight(&dMagma_packet_c::getKuroTexObj())); +#if VERSION == VERSION_DEMO + // !@bug Copy paste error, using the height of ColTexObj instead of KuroTexObj. + GXSetTexCoordScaleManually(GX_TEXCOORD0, GX_TRUE, GXGetTexObjWidth(dMagma_packet_c::getKuroTexObj()), GXGetTexObjHeight(dMagma_packet_c::getColTexObj())); +#else + GXSetTexCoordScaleManually(GX_TEXCOORD0, GX_TRUE, GXGetTexObjWidth(dMagma_packet_c::getKuroTexObj()), GXGetTexObjHeight(dMagma_packet_c::getKuroTexObj())); +#endif +#if VERSION > VERSION_JPN GXSetTexCoordBias(GX_TEXCOORD0, GX_FALSE, GX_FALSE); +#endif GXCallDisplayList(&l_YfloorMatDL, 0x40); GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); GXLoadPosMtxImm(mPosMtx, GX_PNMTX0); @@ -161,8 +170,8 @@ void dMagma_floor_c::draw() { GXCallDisplayList(l_YballMatDL, 0x40); GXLoadTexMtxImm(mPostMtx0, (u32)GX_PTTEXMTX1, GX_MTX3x4); - dMagma_ball_c** ball = getBall(); - for (s32 i = 0; i < getBallNum(); ball++, i++) + dMagma_ball_c** ball = mpBalls; + for (int i = 0; i < mBallNum; ball++, i++) (*ball)->draw(); } @@ -179,16 +188,16 @@ void dMagma_floor_c::calc(int i_roomNo) { else mDoMtx_stack_c::transM(0.0f, -(mPos.y + 30.0f), 0.0f); mDoMtx_concat(l_colOrthoMtx, mDoMtx_stack_c::get(), mPostMtx0); - dMagma_ball_c** ball = getBall(); - for (s32 i = 0; i < getBallNum(); ball++, i++) + dMagma_ball_c** ball = mpBalls; + for (int i = 0; i < mBallNum; ball++, i++) (*ball)->calc(mPos.y, mPathNo, i_roomNo); } /* 80075DD8-80075E50 .text update__14dMagma_floor_cFv */ void dMagma_floor_c::update() { mDoMtx_concat(j3dSys.getViewMtx(), mTexMtx0, mPosMtx); - dMagma_ball_c** ball = getBall(); - for (s32 i = 0; i < getBallNum(); ball++, i++) + dMagma_ball_c** ball = mpBalls; + for (int i = 0; i < mBallNum; ball++, i++) (*ball)->update(); } @@ -232,14 +241,16 @@ dMagma_ball_c** dMagma_floor_c::create(cXyz& pos, cXyz& scale, s16 pathNo, u8 ba mDoMtx_stack_c::transS(mPos); mDoMtx_stack_c::scaleM(mScaleX, 1.0f, mScaleZ); mDoMtx_copy(mDoMtx_stack_c::get(), mTexMtx0); +#if VERSION > VERSION_DEMO update(); +#endif return mpBalls; } /* 80076080-80076100 .text remove__14dMagma_floor_cFv */ void dMagma_floor_c::remove() { - dMagma_ball_c** ball = getBall(); - for (s32 i = 0; i < getBallNum(); ball++, i++) + dMagma_ball_c** ball = mpBalls; + for (int i = 0; i < mBallNum; ball++, i++) delete *ball; delete mpBalls; @@ -260,18 +271,24 @@ void dMagma_room_c::deleteFloor() { } } +GXTexObj dMagma_packet_c::mKuroTexObj; +Mtx dMagma_packet_c::mKuroMtx; +GXTexObj dMagma_packet_c::mColTexObj; +Mtx dMagma_packet_c::mFloorMtx; +Mtx dMagma_packet_c::mBallMtx; + /* 80076158-800762D0 .text __ct__15dMagma_packet_cFv */ dMagma_packet_c::dMagma_packet_c() { dComIfG_setObjectRes("Magma", JKRArchive::DEFAULT_MOUNT_DIRECTION, NULL); ResTIMG* kuro = (ResTIMG*)dComIfG_getObjectRes("Magma", MAGMA_BTI_MAG_KURO); - mDoLib_setResTimgObj(kuro, &getKuroTexObj(), 0, NULL); + mDoLib_setResTimgObj(kuro, &mKuroTexObj, 0, NULL); C_MTXLightOrtho(l_kuroOrthoMtx, 1.0f, -1.0f, -1.0f, 1.0f, 0.5f, -0.5f, 0.5f, 0.5f); mDoMtx_copy(l_kuroOrthoMtx, l_colOrthoMtx); ResTIMG* col = (ResTIMG*)dComIfG_getObjectRes("Magma", MAGMA_BTI_MAG_COL); - mDoLib_setResTimgObj(col, &getColTexObj(), 0, NULL); + mDoLib_setResTimgObj(col, &mColTexObj, 0, NULL); mDoMtx_identity(mFloorMtx); mDoMtx_identity(mBallMtx); mTimer = 0.0f; @@ -298,26 +315,35 @@ dMagma_packet_c::~dMagma_packet_c() { /* 800763CC-800764EC .text draw__15dMagma_packet_cFv */ void dMagma_packet_c::draw() { j3dSys.reinitGX(); +#if VERSION >= VERSION_USA GXSetNumIndStages(0); +#endif + GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); - GXLoadTexObj(&getKuroTexObj(), GX_TEXMAP0); - GXLoadTexObj(&getColTexObj(), GX_TEXMAP1); + GXLoadTexObj(&mKuroTexObj, GX_TEXMAP0); + GXLoadTexObj(&mColTexObj, GX_TEXMAP1); dKy_GxFog_set(); GXSetAlphaCompare(GX_GREATER, 0, GX_AOP_OR, GX_GREATER, 0); +#if VERSION == VERSION_JPN + GXSetNumIndStages(0); +#endif GXSetTevColor(GX_TEVREG1, mColor1); GXSetCurrentMtx(GX_PNMTX0); dMagma_floor_c* floor = &mFloor[0]; - for (s32 i = 0; i < 8; i++, floor++) { - if (floor->mpBalls != NULL) + for (int i = 0; i < 8; i++, floor++) { + if (floor->getBall() != NULL) floor->draw(); } GXSetTexCoordScaleManually(GX_TEXCOORD0, GX_FALSE, 0, 0); GXSetTexCoordScaleManually(GX_TEXCOORD1, GX_FALSE, 0, 0); + +#if VERSION > VERSION_DEMO J3DShape::resetVcdVatCache(); +#endif } /* 800764EC-800764FC .text morfCalc__Ffff */ @@ -327,7 +353,6 @@ f32 morfCalc(f32 min, f32 max, f32 v) { /* 800764FC-80076770 .text calc__15dMagma_packet_cFv */ void dMagma_packet_c::calc() { - /* Nonmatching - regalloc */ f32 f1 = l_kuroOrthoMtx[0][3]; f1 += 0.001f; if (f1 >= 1.5f) @@ -337,12 +362,12 @@ void dMagma_packet_c::calc() { mDoMtx_stack_c::scaleS(0.0022f, 0.0018f, 0.0017f); mDoMtx_stack_c::XrotM(0x4000); - mDoMtx_concat(l_kuroOrthoMtx, mDoMtx_stack_c::get(), getKuroMtx()); + mDoMtx_concat(l_kuroOrthoMtx, mDoMtx_stack_c::get(), mKuroMtx); dMagma_room_c* room = mRoom; - for (s32 i = 0; i < (s32)ARRAY_SIZE(mRoom); i++, room++) + for (int i = 0; i < (s32)ARRAY_SIZE(mRoom); i++, room++) for (dMagma_floor_c* floor = room->getFloor(); floor != NULL; floor = floor->getNext()) - if (floor->mpBalls != NULL) + if (floor->getBall() != NULL) floor->calc(i); mTimer += 1.0f; @@ -357,7 +382,7 @@ void dMagma_packet_c::calc() { GXColor* color = &l_keyColor[1]; f32 f3; - for (s32 i = 1; i < ARRAY_SIZE(l_keyColor); i++, color++) { + for (int i = 1; i < ARRAY_SIZE(l_keyColor); i++, color++) { f3 = color->a; if (mTimer < f3) break; @@ -376,8 +401,8 @@ void dMagma_packet_c::calc() { /* 80076770-800767E4 .text update__15dMagma_packet_cFv */ void dMagma_packet_c::update() { dMagma_floor_c* floor = mFloor; - for (s32 i = 0; i < 8; i++, floor++) { - if (floor->mpBalls != NULL) + for (int i = 0; i < 8; i++, floor++) { + if (floor->getBall() != NULL) floor->update(); } j3dSys.getDrawBuffer(0)->entryImm(this, 0); @@ -385,23 +410,30 @@ void dMagma_packet_c::update() { /* 800767E4-80076924 .text checkYpos__15dMagma_packet_cFR4cXyz */ f32 dMagma_packet_c::checkYpos(cXyz& pos) { - /* Nonmatching */ f32 ret = -1e8; dMagma_floor_c* floor = mFloor; - for (s32 i = 0; i < (s32)ARRAY_SIZE(mFloor); floor++, i++) { - if (floor->mpBalls == NULL) + for (int i = 0; i < (s32)ARRAY_SIZE(mFloor); floor++, i++) { + if (floor->getBall() == NULL) continue; - if (std::fabsf(pos.y - floor->getPos().y) <= 236.803879f && std::fabsf(pos.x - floor->getPos().x) <= floor->getScaleX() * 500.0f && std::fabsf(pos.z - floor->getPos().z) <= floor->getScaleZ() * 500.0f) { - dMagma_ball_c** ball = floor->getBall(); - for (s32 j = 0; j < floor->getBallNum(); ball++, j++) { - f32 y; - if ((*ball)->rangeCheck(pos, &y)) { - if (y < floor->getPos().y) - y = floor->getPos().y; + f32 f1 = pos.y - floor->getPos()->y; + if (std::fabsf(f1) <= 236.803879f) { + f1 = pos.x - floor->getPos()->x; + if (std::fabsf(f1) <= floor->getScaleX() * 500.0f) { + f1 = pos.z - floor->getPos()->z; + if (std::fabsf(f1) <= floor->getScaleZ() * 500.0f) { + dMagma_ball_c** ball = floor->getBall(); + for (int j = 0; j < floor->getBallNum(); ball++, j++) { + f32 y; + if ((*ball)->rangeCheck(pos, &y)) { + cXyz* pos = floor->getPos(); + if (y < pos->y) + y = pos->y; - if (y > ret) - ret = y; + if (y > ret) + ret = y; + } + } } } } @@ -412,12 +444,12 @@ f32 dMagma_packet_c::checkYpos(cXyz& pos) { /* 80076924-80076AA4 .text newFloor__15dMagma_packet_cFR4cXyzR4cXyzis */ dMagma_floor_c* dMagma_packet_c::newFloor(cXyz& p0, cXyz& p1, int i_roomNo, s16 i_pathNo) { - JUT_ASSERT(0x36e, 0 <= i_roomNo && i_roomNo < 64); + JUT_ASSERT(VERSION_SELECT(869, 875, 878, 878), 0 <= i_roomNo && i_roomNo < 64); dMagma_floor_c* floor = mFloor; - for (s32 i = 0; i < ARRAY_SIZE(mFloor); i++, floor++) { - if (floor->mpBalls == NULL) { - s32 param = 0; + for (int i = 0; i < ARRAY_SIZE(mFloor); i++, floor++) { + if (floor->getBall() == NULL) { + int param = 0; if (i_pathNo < 0) { param = -i_pathNo; } else { @@ -426,8 +458,8 @@ dMagma_floor_c* dMagma_packet_c::newFloor(cXyz& p0, cXyz& p1, int i_roomNo, s16 return NULL; dPnt* pnt = path->m_points; - for (s32 j = 0; j < path->m_num; j++) - param += (s32)(pnt->mArg3 * 4.0f); // bug? forgot to increment pnt + for (int j = 0; j < path->m_num; j++) + param += (int)(pnt->mArg3 * 4.0f); // bug? forgot to increment pnt } dMagma_ball_c** balls = floor->create(p0, p1, i_pathNo, param, i_roomNo); diff --git a/src/dolphin/gx/GXTexture.c b/src/dolphin/gx/GXTexture.c index beb0dbfae..20677d157 100644 --- a/src/dolphin/gx/GXTexture.c +++ b/src/dolphin/gx/GXTexture.c @@ -251,11 +251,11 @@ void GXInitTexObjLOD(GXTexObj* obj, GXTexFilter minFilter, GXTexFilter maxFilter GX_SET_REG(internal->texture_lod, reg2, 16, 23); } -u16 GXGetTexObjWidth(GXTexObj* obj) { +u16 GXGetTexObjWidth(const GXTexObj* obj) { return (obj->texture_size & 0x3ff) + 1; } -u16 GXGetTexObjHeight(GXTexObj* obj) { +u16 GXGetTexObjHeight(const GXTexObj* obj) { return ((obj->texture_size >> 10) & 0x3ff) + 1; }