diff --git a/docs/recommended_todo.md b/docs/recommended_todo.md index 95e458850..8233daf3a 100644 --- a/docs/recommended_todo.md +++ b/docs/recommended_todo.md @@ -65,7 +65,7 @@ | efx2dEffect.cpp | 10340 | ebi2DCallBack.cpp | 10457 | | efxObject.cpp | 11240 | particleMgr.cpp | 12851 | | ebiP2Title.cpp | 23731 | efxPikmin.cpp | 33209 | -| efxBase.cpp | 35235 | efxEnemy.cpp | 39166 | +| efxBase.cpp | 33997 | efxEnemy.cpp | 39166 | | ebiScreenMemoryCard.cpp | 48588 | | | ###
plugProjectHikinoU
@@ -84,7 +84,7 @@ | itemHoney.cpp | 12289 | aiBreakGate.cpp | 13962 | | texCaster.cpp | 16071 | gameCaveInfo.cpp | 16103 | | singleGS_CaveResult.cpp | 19624 | itemCave.cpp | 20160 | -| pathfinder.cpp | 20316 | dynCreature.cpp | 21624 | +| pathfinder.cpp | 20318 | dynCreature.cpp | 21624 | | gameDynamics.cpp | 24672 | gameCPlate.cpp | 26452 | | itemPikihead.cpp | 26530 | vsCardMgr.cpp | 30652 | | singleGS_MainGame.cpp | 31879 | itemBridge.cpp | 32134 | diff --git a/include/Vector3.h b/include/Vector3.h index 85c4b4c7a..bff067fc2 100644 --- a/include/Vector3.h +++ b/include/Vector3.h @@ -240,6 +240,10 @@ struct Vector3 { this->normalise(); } + static inline f32 distance(Vector3& a, Vector3& b) { return (a - b).length(); } + + inline void sub(Vector3& a, Vector3& b) { set(a.x - b.x, a.y - b.y, a.z - b.z); } + /** * Sets the flat direction from one vector to another. * The resulting vector will have a zero y-component. @@ -438,12 +442,6 @@ inline f32 _lengthXZ(Vector3f& vec) return _sqrtf(a.x * a.x + a.z * a.z); } -inline f32 _distanceBetween(Vector3f& me, Vector3f& them) -{ - Vector3f sep = me - them; - return _length(sep); -} - inline f32 _normalise2(Vector3f& diff) { f32 dist = _length(diff); diff --git a/include/efx/TSyncGroup.h b/include/efx/TSyncGroup.h index f7b5ecf86..034a2131e 100644 --- a/include/efx/TSyncGroup.h +++ b/include/efx/TSyncGroup.h @@ -13,8 +13,8 @@ namespace efx { struct TSyncGroup##N : TBase { \ /* VTABLE */ \ virtual bool create(Arg* arg); \ - virtual void forceKill(); \ virtual void fade(); \ + virtual void forceKill(); \ virtual void startDemoDrawOff(); \ virtual void endDemoDrawOn(); \ /* VTABLE END */ \ @@ -35,42 +35,6 @@ DEF_SYNC_GROUP(4); DEF_SYNC_GROUP(5); DEF_SYNC_GROUP(6); -/* -virtual bool create(Arg* arg) -{ - for (u32 i = 0; i < N; i++) { - if (!mItems[i].create(arg)) { - return false; - } - } - return true; -} -virtual void forceKill() -{ - for (u32 i = 0; i < N; i++) { - mItems[i].forceKill(); - } -} -virtual void fade() -{ - for (u32 i = 0; i < N; i++) { - mItems[i].fade(); - } -} -virtual void startDemoDrawOff() -{ - for (u32 i = 0; i < N; i++) { - mItems[i].startDemoDrawOff(); - } -} -virtual void endDemoDrawOn() -{ - for (u32 i = 0; i < N; i++) { - mItems[i].endDemoDrawOn(); - } -} -*/ - } // namespace efx #endif diff --git a/src/plugProjectEbisawaU/efxBase.cpp b/src/plugProjectEbisawaU/efxBase.cpp index c521f72a1..a07b87695 100644 --- a/src/plugProjectEbisawaU/efxBase.cpp +++ b/src/plugProjectEbisawaU/efxBase.cpp @@ -12,6 +12,7 @@ #include "efx/TSyncGroup.h" namespace efx { + TCallBack_StaticClipping TBase::mCallBack_StaticClipping; /** @@ -581,24 +582,32 @@ void TChasePosPos::doExecuteEmitterOperation(JPABaseEmitter* emitter) * @note Address: 0x803AFC80 * @note Size: 0xF8 */ -#pragma dont_inline on void makeMtxZAxisAlongPosPos(Mtx mtx, Vector3f& p2, Vector3f& p3) { - Vector3f diff = p3 - p2; - diff.normalise(); - // some cross product/outer product to generate Mtx - mtx[0][0] = diff.x; - mtx[0][1] = diff.y; - mtx[0][2] = diff.z; - mtx[0][3] = diff.x; - mtx[1][0] = diff.x; - mtx[1][1] = diff.x; - mtx[1][2] = diff.x; - mtx[1][3] = diff.x; - mtx[2][0] = diff.x; - mtx[2][1] = diff.x; - mtx[2][2] = diff.x; - mtx[2][3] = diff.x; + Vector3f zVec(p3.x - p2.x, p3.y - p2.y, p3.z - p2.z); + Vector3f midPt(p2.x + p3.x, p2.y + p3.y, p2.z + p3.z); + midPt *= 0.5f; + + zVec.normalise(); + + Vector3f yAxis(0.0f, 1.0f, 0.0f); + Vector3f xVec = cross(yAxis, zVec); + Vector3f yVec = cross(zVec, xVec); + + mtx[0][0] = xVec.x; + mtx[0][1] = yVec.x; + mtx[0][2] = zVec.x; + mtx[0][3] = midPt.x; + + mtx[1][0] = xVec.y; + mtx[1][1] = yVec.y; + mtx[1][2] = zVec.y; + mtx[1][3] = midPt.y; + + mtx[2][0] = xVec.z; + mtx[2][1] = yVec.z; + mtx[2][2] = zVec.z; + mtx[2][3] = midPt.z; /* lfs f0, 4(r4) @@ -671,7 +680,6 @@ lbl_803AFD10: blr */ } -#pragma dont_inline reset /** * doExecuteEmitterOperation__Q23efx23TChasePosPosLocalZScaleFP14JPABaseEmitter @@ -686,103 +694,10 @@ void TChasePosPosLocalZScale::doExecuteEmitterOperation(JPABaseEmitter* emitter) Vector3f vec1 = *mPosPtrA; Vector3f vec2 = *mPosPtrB; makeMtxZAxisAlongPosPos(mtxZ, vec1, vec2); - f32 dist = _distanceBetween(vec2, vec1); + f32 dist = Vector3f::distance(vec2, vec1); emitter->setGlobalRTMatrix(mtxZ); - emitter->mLocalScl.z = dist / _18; - - /* - stwu r1, -0x70(r1) - mflr r0 - stw r0, 0x74(r1) - stfd f31, 0x60(r1) - psq_st f31, 104(r1), 0, qr0 - stw r31, 0x5c(r1) - stw r30, 0x58(r1) - mr r30, r3 - mr r31, r4 - lwz r0, 0x10(r3) - cmplwi r0, 0 - bne lbl_803AFDC4 - lis r3, lbl_80495880@ha - lis r5, lbl_8049588C@ha - addi r3, r3, lbl_80495880@l - li r4, 0x350 - addi r5, r5, lbl_8049588C@l - crclr 6 - bl panic_f__12JUTExceptionFPCciPCce - -lbl_803AFDC4: - lwz r0, 0x14(r30) - cmplwi r0, 0 - bne lbl_803AFDEC - lis r3, lbl_80495880@ha - lis r5, lbl_8049588C@ha - addi r3, r3, lbl_80495880@l - li r4, 0x351 - addi r5, r5, lbl_8049588C@l - crclr 6 - bl panic_f__12JUTExceptionFPCciPCce - -lbl_803AFDEC: - lwz r6, 0x10(r30) - addi r3, r1, 0x20 - addi r4, r1, 0x14 - addi r5, r1, 8 - lfs f0, 0(r6) - stfs f0, 0x14(r1) - lfs f0, 4(r6) - stfs f0, 0x18(r1) - lfs f0, 8(r6) - stfs f0, 0x1c(r1) - lwz r6, 0x14(r30) - lfs f0, 0(r6) - stfs f0, 8(r1) - lfs f0, 4(r6) - stfs f0, 0xc(r1) - lfs f0, 8(r6) - stfs f0, 0x10(r1) - bl "makeMtxZAxisAlongPosPos__3efxFPA4_fR10Vector3R10Vector3" - lfs f1, 0xc(r1) - lfs f0, 0x18(r1) - lfs f3, 0x10(r1) - fsubs f4, f1, f0 - lfs f2, 0x1c(r1) - lfs f1, 8(r1) - lfs f0, 0x14(r1) - fsubs f2, f3, f2 - fmuls f3, f4, f4 - fsubs f1, f1, f0 - lfs f0, lbl_8051F614@sda21(r2) - fmuls f2, f2, f2 - fmadds f1, f1, f1, f3 - fadds f31, f2, f1 - fcmpo cr0, f31, f0 - ble lbl_803AFE84 - ble lbl_803AFE88 - frsqrte f0, f31 - fmuls f31, f0, f31 - b lbl_803AFE88 - -lbl_803AFE84: - fmr f31, f0 - -lbl_803AFE88: - addi r3, r1, 0x20 - addi r4, r31, 0x68 - addi r5, r31, 0xa4 - bl "JPASetRMtxTVecfromMtx__FPA4_CfPA4_fPQ29JGeometry8TVec3" - lfs f0, 0x18(r30) - fdivs f2, f31, f0 - stfs f2, 8(r31) - psq_l f31, 104(r1), 0, qr0 - lwz r0, 0x74(r1) - lfd f31, 0x60(r1) - lwz r31, 0x5c(r1) - lwz r30, 0x58(r1) - mtlr r0 - addi r1, r1, 0x70 - blr - */ + dist /= _18; + emitter->mLocalScl.set(emitter->mLocalScl.x, emitter->mLocalScl.y, dist); } /** @@ -792,108 +707,17 @@ lbl_803AFE88: */ void TChasePosPosLocalYScale::doExecuteEmitterOperation(JPABaseEmitter* emitter) { + f32 newY; P2ASSERTLINE(880, _10); P2ASSERTLINE(881, _14); Mtx mtxZ; Vector3f vec1 = *_10; Vector3f vec2 = *_14; makeMtxZAxisAlongPosPos(mtxZ, vec1, vec2); - f32 dist = _distanceBetween(vec2, vec1); + f32 dist = Vector3f::distance(vec2, vec1); emitter->setGlobalRTMatrix(mtxZ); - emitter->mLocalScl.y = dist / _18; - /* - stwu r1, -0x70(r1) - mflr r0 - stw r0, 0x74(r1) - stfd f31, 0x60(r1) - psq_st f31, 104(r1), 0, qr0 - stw r31, 0x5c(r1) - stw r30, 0x58(r1) - mr r30, r3 - mr r31, r4 - lwz r0, 0x10(r3) - cmplwi r0, 0 - bne lbl_803AFF10 - lis r3, lbl_80495880@ha - lis r5, lbl_8049588C@ha - addi r3, r3, lbl_80495880@l - li r4, 0x370 - addi r5, r5, lbl_8049588C@l - crclr 6 - bl panic_f__12JUTExceptionFPCciPCce - -lbl_803AFF10: - lwz r0, 0x14(r30) - cmplwi r0, 0 - bne lbl_803AFF38 - lis r3, lbl_80495880@ha - lis r5, lbl_8049588C@ha - addi r3, r3, lbl_80495880@l - li r4, 0x371 - addi r5, r5, lbl_8049588C@l - crclr 6 - bl panic_f__12JUTExceptionFPCciPCce - -lbl_803AFF38: - lwz r6, 0x10(r30) - addi r3, r1, 0x20 - addi r4, r1, 0x14 - addi r5, r1, 8 - lfs f0, 0(r6) - stfs f0, 0x14(r1) - lfs f0, 4(r6) - stfs f0, 0x18(r1) - lfs f0, 8(r6) - stfs f0, 0x1c(r1) - lwz r6, 0x14(r30) - lfs f0, 0(r6) - stfs f0, 8(r1) - lfs f0, 4(r6) - stfs f0, 0xc(r1) - lfs f0, 8(r6) - stfs f0, 0x10(r1) - bl "makeMtxZAxisAlongPosPos__3efxFPA4_fR10Vector3R10Vector3" - lfs f1, 0xc(r1) - lfs f0, 0x18(r1) - lfs f3, 0x10(r1) - fsubs f4, f1, f0 - lfs f2, 0x1c(r1) - lfs f1, 8(r1) - lfs f0, 0x14(r1) - fsubs f2, f3, f2 - fmuls f3, f4, f4 - fsubs f1, f1, f0 - lfs f0, lbl_8051F614@sda21(r2) - fmuls f2, f2, f2 - fmadds f1, f1, f1, f3 - fadds f31, f2, f1 - fcmpo cr0, f31, f0 - ble lbl_803AFFD0 - ble lbl_803AFFD4 - frsqrte f0, f31 - fmuls f31, f0, f31 - b lbl_803AFFD4 - -lbl_803AFFD0: - fmr f31, f0 - -lbl_803AFFD4: - addi r3, r1, 0x20 - addi r4, r31, 0x68 - addi r5, r31, 0xa4 - bl "JPASetRMtxTVecfromMtx__FPA4_CfPA4_fPQ29JGeometry8TVec3" - lfs f0, 0x18(r30) - fdivs f2, f31, f0 - stfs f2, 4(r31) - psq_l f31, 104(r1), 0, qr0 - lwz r0, 0x74(r1) - lfd f31, 0x60(r1) - lwz r31, 0x5c(r1) - lwz r30, 0x58(r1) - mtlr r0 - addi r1, r1, 0x70 - blr - */ + dist /= _18; + emitter->mLocalScl.set(emitter->mLocalScl.x, dist, emitter->mLocalScl.z); } /** @@ -1478,4 +1302,181 @@ void TChasePosPosLocalZScale3::setPosptr(Vector3f* p1, Vector3f* p2) } } +///////// TSYNCGROUP DEFINITIONS ///////// +// N = 2 +template +bool TSyncGroup2::create(Arg* arg) +{ + for (u32 i = 0; i < 2; i++) { + if (!mItems[i].create(arg)) { + return false; + } + } + return true; +} + +template +void TSyncGroup2::fade() +{ + for (u32 i = 0; i < 2; i++) { + mItems[i].fade(); + } +} + +template +void TSyncGroup2::forceKill() +{ + for (u32 i = 0; i < 2; i++) { + mItems[i].forceKill(); + } +} + +template +void TSyncGroup2::startDemoDrawOff() +{ + for (u32 i = 0; i < 2; i++) { + mItems[i].startDemoDrawOff(); + } +} + +template +void TSyncGroup2::endDemoDrawOn() +{ + for (u32 i = 0; i < 2; i++) { + mItems[i].endDemoDrawOn(); + } +} + +// N = 3 +template +bool TSyncGroup3::create(Arg* arg) +{ + for (u32 i = 0; i < 3; i++) { + if (!mItems[i].create(arg)) { + return false; + } + } + return true; +} + +template +void TSyncGroup3::fade() +{ + for (u32 i = 0; i < 3; i++) { + mItems[i].fade(); + } +} + +template +void TSyncGroup3::forceKill() +{ + for (u32 i = 0; i < 3; i++) { + mItems[i].forceKill(); + } +} + +template +void TSyncGroup3::startDemoDrawOff() +{ + for (u32 i = 0; i < 3; i++) { + mItems[i].startDemoDrawOff(); + } +} + +template +void TSyncGroup3::endDemoDrawOn() +{ + for (u32 i = 0; i < 3; i++) { + mItems[i].endDemoDrawOn(); + } +} + +// N = 4 +template +bool TSyncGroup4::create(Arg* arg) +{ + for (u32 i = 0; i < 4; i++) { + if (!mItems[i].create(arg)) { + return false; + } + } + return true; +} + +template +void TSyncGroup4::fade() +{ + for (u32 i = 0; i < 4; i++) { + mItems[i].fade(); + } +} + +template +void TSyncGroup4::forceKill() +{ + for (u32 i = 0; i < 4; i++) { + mItems[i].forceKill(); + } +} + +template +void TSyncGroup4::startDemoDrawOff() +{ + for (u32 i = 0; i < 4; i++) { + mItems[i].startDemoDrawOff(); + } +} + +template +void TSyncGroup4::endDemoDrawOn() +{ + for (u32 i = 0; i < 4; i++) { + mItems[i].endDemoDrawOn(); + } +} + +// N = 6 +template +bool TSyncGroup6::create(Arg* arg) +{ + for (u32 i = 0; i < 6; i++) { + if (!mItems[i].create(arg)) { + return false; + } + } + return true; +} + +template +void TSyncGroup6::fade() +{ + for (u32 i = 0; i < 6; i++) { + mItems[i].fade(); + } +} + +template +void TSyncGroup6::forceKill() +{ + for (u32 i = 0; i < 6; i++) { + mItems[i].forceKill(); + } +} + +template +void TSyncGroup6::startDemoDrawOff() +{ + for (u32 i = 0; i < 6; i++) { + mItems[i].startDemoDrawOff(); + } +} + +template +void TSyncGroup6::endDemoDrawOn() +{ + for (u32 i = 0; i < 6; i++) { + mItems[i].endDemoDrawOn(); + } +} + } // namespace efx diff --git a/src/plugProjectEbisawaU/efxEnemyBoss.cpp b/src/plugProjectEbisawaU/efxEnemyBoss.cpp index a9da5f381..7c8ae0765 100644 --- a/src/plugProjectEbisawaU/efxEnemyBoss.cpp +++ b/src/plugProjectEbisawaU/efxEnemyBoss.cpp @@ -208,7 +208,7 @@ bool TOootaBombLeg::create(Arg* arg) if (TSimple1::create(arg)) { Matrixf mtx; makeMtxZAxisAlongPosPos(mtx.mMatrix.mtxView, pos1, pos2); - f32 dist = _distanceBetween(pos2, pos1); + f32 dist = Vector3f::distance(pos2, pos1); dist /= 100.0f; mEmitters[0]->setGlobalRTMatrix(mtx.mMatrix.mtxView); mEmitters[0]->mLocalScl.y *= dist; @@ -922,7 +922,7 @@ bool THdamaDeadHahen1::create(efx::Arg* arg) if (TSimple1::create(arg)) { Matrixf mtx; makeMtxZAxisAlongPosPos(mtx.mMatrix.mtxView, pos1, pos2); - f32 dist = _distanceBetween(pos2, pos1); + f32 dist = Vector3f::distance(pos2, pos1); dist /= 100.0f; mEmitters[0]->setGlobalRTMatrix(mtx.mMatrix.mtxView); mEmitters[0]->mLocalScl.y *= dist; @@ -1054,7 +1054,7 @@ bool THdamaDeadHahen2::create(efx::Arg* arg) if (TSimple2::create(arg)) { Matrixf mtx; makeMtxZAxisAlongPosPos(mtx.mMatrix.mtxView, pos1, pos2); - f32 dist = _distanceBetween(pos2, pos1); + f32 dist = Vector3f::distance(pos2, pos1); dist /= 100.0f; for (int i = 0; i < 2; i++) { mEmitters[i]->setGlobalRTMatrix(mtx.mMatrix.mtxView); diff --git a/src/plugProjectKandoU/gameFootmark.cpp b/src/plugProjectKandoU/gameFootmark.cpp index 61afd6b82..5cc3716bf 100644 --- a/src/plugProjectKandoU/gameFootmark.cpp +++ b/src/plugProjectKandoU/gameFootmark.cpp @@ -50,7 +50,7 @@ void Footmarks::add(Footmark& mark) int adjIndex = ((mCurrentIndex + mCount) - 1) % mCount; // (_04 + (mCount - 1) % mCount); Footmark* currMark = &mMarks[adjIndex]; - f32 dist = _distanceBetween(currMark->mPosition, mark.mPosition); + f32 dist = Vector3f::distance(currMark->mPosition, mark.mPosition); if (dist < 20.0f) { return; } diff --git a/src/plugProjectKandoU/itemTreasure.cpp b/src/plugProjectKandoU/itemTreasure.cpp index c85fc92e0..0f21a99d2 100644 --- a/src/plugProjectKandoU/itemTreasure.cpp +++ b/src/plugProjectKandoU/itemTreasure.cpp @@ -272,7 +272,7 @@ bool Item::getVectorField(Sys::Sphere& bounds, Vector3f& pos) */ f32 Item::getWorkDistance(Sys::Sphere& bounds) { - f32 dist = _distanceBetween(mPosition, bounds.mPosition); + f32 dist = Vector3f::distance(mPosition, bounds.mPosition); return dist - getWorkRadius(); } diff --git a/src/plugProjectKandoU/pathfinder.cpp b/src/plugProjectKandoU/pathfinder.cpp index 2fc1acf2d..d11535cea 100644 --- a/src/plugProjectKandoU/pathfinder.cpp +++ b/src/plugProjectKandoU/pathfinder.cpp @@ -961,7 +961,7 @@ f32 AStarPathfinder::estimate(s16 wpID1, s16 wpID2) Vector3f pos1 = wp1->getPosition(); Vector3f pos2 = wp2->getPosition(); - return _distanceBetween(pos1, pos2); + return Vector3f::distance(pos1, pos2); } /**