diff --git a/include/BoundBox.h b/include/BoundBox.h index 17bc3f0c0..21574f71e 100644 --- a/include/BoundBox.h +++ b/include/BoundBox.h @@ -56,10 +56,10 @@ struct BoundBox { }; struct BoundBox2d { - f32 _00; - f32 _04; - f32 _08; - f32 _0C; + f32 mLeft; // _00 + f32 mBottom; // _04 + f32 mRight; // _08 + f32 mTop; // _0C }; #endif diff --git a/include/Game/cellPyramid.h b/include/Game/cellPyramid.h index acc772836..088c086de 100644 --- a/include/Game/cellPyramid.h +++ b/include/Game/cellPyramid.h @@ -192,13 +192,13 @@ struct CellPyramid : public SweepPrune::World { void drawCell(Graphics&); void dumpCount(int&, int&); - int mMemoryUsageMaybe; // _28 - int mLayerCount; // _2C - CellLayer* mLayers; // _30 - f32 _34; // _34 - f32 _38; // _38 - f32 _3C; // _3C - f32 _40; // _40 + int mFreeMemory; // _28 + int mLayerCount; // _2C + CellLayer* mLayers; // _30 + f32 mScale; // _34 + f32 mInverseScale; // _38 + f32 mLeft; // _3C + f32 mRight; // _40 /* * Incremented at the start of every resolve/search pass. * Passed on to CellObjects to prevent evaluating multiple times per pass. @@ -223,9 +223,9 @@ struct CellIteratorArg { Sys::Sphere mSphere; // _00 CellIteratorCondition* mCondition; // _10, this is a ptr to something with a vtable, and 0x8 of vtable returns a bool ._. - int _14; // _14, set to 0 and unused + int mUseCustomRadiusThreshold; // _14, UNUSED but a name is better than nothing CellPyramid* mCellMgr; // _18 - bool mIgnoreOverlap; // _1C, if false, will calc overlapping bounding spheres rather than just "in cell or no" + bool mIsCollSphereDisabled; // _1C, if false, will calc overlapping bounding spheres rather than just "in cell or no" u8 _1D; // _1D, set to 0 and unused }; diff --git a/src/plugProjectKandoU/aiBattle.cpp b/src/plugProjectKandoU/aiBattle.cpp index 23add896c..0b120f509 100644 --- a/src/plugProjectKandoU/aiBattle.cpp +++ b/src/plugProjectKandoU/aiBattle.cpp @@ -182,7 +182,7 @@ void ActBattle::init(PikiAI::ActionArg* arg) Vector3f midPoint = (mParent->getPosition() + mOther->getPosition()) * 0.5f; Sys::Sphere itSphere(midPoint, 10.0f); Game::CellIteratorArg citArg(itSphere); - citArg.mIgnoreOverlap = false; + citArg.mIsCollSphereDisabled = false; Game::CellIterator cellIt(citArg); CI_LOOP(cellIt) diff --git a/src/plugProjectKandoU/cellIterator.cpp b/src/plugProjectKandoU/cellIterator.cpp index a1d8a57cb..555ba47cb 100644 --- a/src/plugProjectKandoU/cellIterator.cpp +++ b/src/plugProjectKandoU/cellIterator.cpp @@ -9,16 +9,16 @@ namespace Game { */ CellIteratorArg::CellIteratorArg() { - mCondition = nullptr; - _14 = 0; + mCondition = nullptr; + mUseCustomRadiusThreshold = 0; mSphere.mPosition = Vector3f(0.0f); mSphere.mRadius = 0.0f; mCellMgr = cellMgr; - _1D = 0; - mIgnoreOverlap = false; + _1D = 0; + mIsCollSphereDisabled = false; } /* @@ -29,12 +29,12 @@ CellIteratorArg::CellIteratorArg() */ CellIteratorArg::CellIteratorArg(Sys::Sphere& sphere) { - mSphere = sphere; - mCondition = nullptr; - _14 = 0; - mCellMgr = Game::cellMgr; - _1D = 0; - mIgnoreOverlap = false; + mSphere = sphere; + mCondition = nullptr; + mUseCustomRadiusThreshold = 0; + mCellMgr = Game::cellMgr; + _1D = 0; + mIsCollSphereDisabled = false; } /* @@ -185,18 +185,18 @@ bool CellIterator::satisfy() CellObject* obj = mCurrLeg->mObject; Vector3f objPos = obj->getPosition(); - Sys::Sphere sphere; - obj->getBoundingSphere(sphere); + Sys::Sphere boundingSphere; + obj->getBoundingSphere(boundingSphere); - if (!mArg.mIgnoreOverlap) { - if (!mArg._14) { - f32 radius = mArg.mSphere.mRadius + sphere.mRadius; + if (!mArg.mIsCollSphereDisabled) { + if (!mArg.mUseCustomRadiusThreshold) { + f32 radius = mArg.mSphere.mRadius + boundingSphere.mRadius; radius *= radius; if (sqrDistanceXZ(objPos, mArg.mSphere.mPosition) > radius) { return false; } } else { - f32 radius = mArg.mSphere.mRadius + sphere.mRadius; + f32 radius = mArg.mSphere.mRadius + boundingSphere.mRadius; radius *= radius; if (sqrDistanceXZ(objPos, mArg.mSphere.mPosition) > radius) { return false; @@ -335,10 +335,10 @@ void CellIterator::calcExtent() f32 z = mArg.mSphere.mPosition.z; f32 x = mArg.mSphere.mPosition.x; - f32 a = mArg.mCellMgr->_40; - f32 b = mArg.mCellMgr->_3C; + f32 a = mArg.mCellMgr->mRight; + f32 b = mArg.mCellMgr->mLeft; - f32 norm = 1.0f / (mgr->_34 * mgr->mLayers[mCurrLayerIdx]._04); + f32 norm = 1.0f / (mgr->mScale * mgr->mLayers[mCurrLayerIdx]._04); mMinX = (x - r - a) * norm; mMinY = (z - r - b) * norm; diff --git a/src/plugProjectKandoU/cellPyramid.cpp b/src/plugProjectKandoU/cellPyramid.cpp index c0536ba51..4be72b38d 100644 --- a/src/plugProjectKandoU/cellPyramid.cpp +++ b/src/plugProjectKandoU/cellPyramid.cpp @@ -1292,8 +1292,8 @@ inline void CellLayer::drawCell(Graphics&, Vector3f&, int, int, float) const */ CellPyramid::CellPyramid() { - mLayerCount = 0; - mMemoryUsageMaybe = 0; + mLayerCount = 0; + mFreeMemory = 0; } /* @@ -1463,7 +1463,7 @@ void CellPyramid::entry(CellObject* object, Sys::Sphere& sphere) void CellPyramid::entry(CellObject* param_1, Sys::Sphere& param_2, int& param_3, Recti& param_4) { Cell::sCurrCellMgr = this; - float dVar19 = log10(param_2.mRadius * 2.0f * _38); + float dVar19 = log10(param_2.mRadius * 2.0f * mInverseScale); float dVar18 = log10(2.0f); float dVar17 = (dVar19 / dVar18); // if (dVar17 < 0.0) { @@ -1476,9 +1476,9 @@ void CellPyramid::entry(CellObject* param_1, Sys::Sphere& param_2, int& param_3, float fVar10 = param_2.mRadius; float fVar11 = (param_2.mPosition).x; float fVar1 = (param_2.mPosition).z; - float fVar2 = _40; - float fVar3 = _3C; - float fVar4 = 1.0f / ((mLayers[iVar9]._04) * _34); // <--- SHORT_TO_FLOAT + float fVar2 = mRight; + float fVar3 = mLeft; + float fVar4 = 1.0f / ((mLayers[iVar9]._04) * mScale); // <--- SHORT_TO_FLOAT param_4.p1.x = (int)(((fVar11 - fVar10) - fVar2) * fVar4); param_4.p1.y = (int)(((fVar1 - fVar10) - fVar3) * fVar4); param_4.p2.x = (int)(((fVar11 + fVar10) - fVar2) * fVar4); @@ -1964,41 +1964,51 @@ void CellPyramid::entry(CellObject* param_1, Sys::Sphere& param_2, int& param_3, * Address: 80158A0C * Size: 0002EC */ -void CellPyramid::create(BoundBox2d& box, float p2) +void CellPyramid::create(BoundBox2d& box, float scale) { - mMemoryUsageMaybe = JKRHeap::sCurrentHeap->getFreeSize(); - _3C = box._04; - _40 = box._00; - _34 = p2; - _38 = 1.0f / p2; - int uVar13 = (f32)ceil((FABS(box._08 - box._00) * _38)); - int uVar12 = (f32)ceil(FABS(box._0C - box._04) * _38); - if ((200 < uVar13) || (200 < uVar12)) { - _34 = p2 * 1.5f; - _38 = 1.0f / (p2 * 1.5f); - uVar13 = (f32)ceil((FABS(box._08 - box._00) * _38)); - uVar12 = (f32)ceil((FABS(box._0C - box._04) * _38)); + mFreeMemory = JKRHeap::sCurrentHeap->getFreeSize(); + + mLeft = box.mBottom; + mRight = box.mLeft; + mScale = scale; + mInverseScale = 1.0f / scale; + + // Calculate dimensions in pixels + int pixelWidth = (f32)ceil((FABS(box.mRight - box.mLeft) * mInverseScale)); + int pixelHeight = (f32)ceil(FABS(box.mTop - box.mBottom) * mInverseScale); + + if (pixelWidth > 200 || pixelHeight > 200) { + mScale = scale * 1.5f; + mInverseScale = 1.0f / (scale * 1.5f); + pixelWidth = (f32)ceil((FABS(box.mRight - box.mLeft) * mInverseScale)); + pixelHeight = (f32)ceil((FABS(box.mTop - box.mBottom) * mInverseScale)); } - int uVar14 = MAX(uVar12, uVar13); - int dVar18 = (f32)ceil((f32)log10((f32)uVar14) / (f32)log10(2.0f)); - pow(2.0, (double)dVar18); - mLayerCount = dVar18 + 1; + + int maxDimension = MAX(pixelHeight, pixelWidth); + + int layerCount = (f32)ceil((f32)log10((f32)maxDimension) / (f32)log10(2.0f)); + pow(2.0, (double)layerCount); + + mLayerCount = layerCount + 1; mLayers = new CellLayer[mLayerCount]; - mLayers[0].mSizeX = uVar13; - mLayers[0].mSizeY = uVar12; + mLayers[0].mSizeX = pixelWidth; + mLayers[0].mSizeY = pixelHeight; mLayers[0]._04 = 0; mLayers[0]._06 = 1; mLayers[0].mCells = new Cell[mLayers[0].mSizeX * mLayers[0].mSizeY]; mLayers[0].mCell._20 = nullptr; mLayers[0].mCell._24 = nullptr; + for (int i = 0; i < mLayers[0].mSizeX * mLayers[0].mSizeY; i++) { mLayers[0].mCells[i].clear(); mLayers[0].mCells[i]._28 = mLayers[0]._06; } + for (int i = 1; i < mLayerCount; i++) { mLayers[i].pileup(mLayers[i - 1]); } - mMemoryUsageMaybe = mMemoryUsageMaybe - JKRHeap::sCurrentHeap->getFreeSize(); + + mFreeMemory = mFreeMemory - JKRHeap::sCurrentHeap->getFreeSize(); /* .loc_0x0: stwu r1, -0x70(r1) diff --git a/src/plugProjectKandoU/navi_demoCheck.cpp b/src/plugProjectKandoU/navi_demoCheck.cpp index 4c14ddad9..0efa9f74c 100644 --- a/src/plugProjectKandoU/navi_demoCheck.cpp +++ b/src/plugProjectKandoU/navi_demoCheck.cpp @@ -2159,8 +2159,8 @@ FakePiki* Navi::checkDemoNaviAndPiki(Sys::Sphere& bounds) } CellIteratorArg arg; - arg.mSphere = bounds; - arg._14 = 1; + arg.mSphere = bounds; + arg.mUseCustomRadiusThreshold = 1; CellIterator cell(arg); CI_LOOP(cell) { diff --git a/src/plugProjectKandoU/piki.cpp b/src/plugProjectKandoU/piki.cpp index eacf7d42b..3b8c47b36 100644 --- a/src/plugProjectKandoU/piki.cpp +++ b/src/plugProjectKandoU/piki.cpp @@ -1522,7 +1522,7 @@ void Piki::do_updateLookCreature() Sys::Sphere sphere(mPosition3, 200.0f); CellIteratorArg iterArg(sphere); - iterArg._14 = 1; + iterArg.mUseCustomRadiusThreshold = 1; CellIterator iter(iterArg); int counter = 0; CI_LOOP(iter) diff --git a/src/plugProjectKandoU/pikiState.cpp b/src/plugProjectKandoU/pikiState.cpp index 24ee04b5b..db9d75762 100644 --- a/src/plugProjectKandoU/pikiState.cpp +++ b/src/plugProjectKandoU/pikiState.cpp @@ -2595,7 +2595,7 @@ void PikiHipDropState::exec(Piki* piki) Vector3f position = piki->getPosition(); Sys::Sphere sphere(position, 50.0f); CellIteratorArg iterArg(sphere); - iterArg._14 = 1; + iterArg.mUseCustomRadiusThreshold = 1; CellIterator iterator(iterArg); iterator.first(); @@ -3230,7 +3230,7 @@ void PikiHipDropState::earthquake(Piki* piki) f32 rad = pikiMgr->mParms->mPikiParms.mPoundAOERange.mValue; Sys::Sphere sphere(position, rad); CellIteratorArg iterArg(sphere); - iterArg._14 = 1; + iterArg.mUseCustomRadiusThreshold = 1; CellIterator iterator(iterArg); iterator.first(); diff --git a/src/plugProjectMorimuraU/bombState.cpp b/src/plugProjectMorimuraU/bombState.cpp index c980f05d0..4fb909b66 100644 --- a/src/plugProjectMorimuraU/bombState.cpp +++ b/src/plugProjectMorimuraU/bombState.cpp @@ -153,7 +153,7 @@ void StateBomb::exec(EnemyBase* enemy) sphere.mPosition = Vector3f(position); sphere.mRadius = parms->mGeneral.mAttackRadius.mValue; CellIteratorArg iteratorArg(sphere); - iteratorArg._14 = 1; + iteratorArg.mUseCustomRadiusThreshold = 1; CellIterator iterator(iteratorArg); CI_LOOP(iterator) diff --git a/src/plugProjectNishimuraU/BigTreasure.cpp b/src/plugProjectNishimuraU/BigTreasure.cpp index bbb75d82a..aa7d9e851 100644 --- a/src/plugProjectNishimuraU/BigTreasure.cpp +++ b/src/plugProjectNishimuraU/BigTreasure.cpp @@ -360,7 +360,7 @@ bool Obj::isAttackLimitTime() Sys::Sphere sphere(mPosition, 300.0f); CellIteratorArg iterArg(sphere); - iterArg.mIgnoreOverlap = true; + iterArg.mIsCollSphereDisabled = true; CellIterator iter(iterArg); diff --git a/src/plugProjectNishimuraU/BigTreasureAttack.cpp b/src/plugProjectNishimuraU/BigTreasureAttack.cpp index 657c62dac..c8d420ea0 100644 --- a/src/plugProjectNishimuraU/BigTreasureAttack.cpp +++ b/src/plugProjectNishimuraU/BigTreasureAttack.cpp @@ -102,7 +102,7 @@ bool BigTreasureFireAttack::update() Sys::Sphere sphere(pos, 25.0f); CellIteratorArg iterArg(sphere); - iterArg.mIgnoreOverlap = true; + iterArg.mIsCollSphereDisabled = true; CellIterator iter(iterArg); diff --git a/src/plugProjectNishimuraU/ElecHiba.cpp b/src/plugProjectNishimuraU/ElecHiba.cpp index 952cd7e67..342da7551 100644 --- a/src/plugProjectNishimuraU/ElecHiba.cpp +++ b/src/plugProjectNishimuraU/ElecHiba.cpp @@ -301,7 +301,7 @@ void Obj::interactDenkiAttack(Vector3f& position) // also some other constants pulled from parms CellIteratorArg iterArg(sphere); - iterArg.mIgnoreOverlap = true; + iterArg.mIsCollSphereDisabled = true; CellIterator iter(iterArg); diff --git a/src/plugProjectNishimuraU/Fart.cpp b/src/plugProjectNishimuraU/Fart.cpp index c5eb9fb02..c39200057 100644 --- a/src/plugProjectNishimuraU/Fart.cpp +++ b/src/plugProjectNishimuraU/Fart.cpp @@ -93,7 +93,7 @@ void Obj::interactFartGasAttack() sphere.mRadius = parms->mGeneral.mAttackRadius.mValue; CellIteratorArg arg(sphere); - arg.mIgnoreOverlap = true; + arg.mIsCollSphereDisabled = true; CellIterator iterator(arg); CI_LOOP(iterator) diff --git a/src/plugProjectNishimuraU/Fuefuki.cpp b/src/plugProjectNishimuraU/Fuefuki.cpp index 94eafbf98..69520be8e 100644 --- a/src/plugProjectNishimuraU/Fuefuki.cpp +++ b/src/plugProjectNishimuraU/Fuefuki.cpp @@ -465,7 +465,7 @@ bool Obj::isJumpAway() f32 privateDiameter = privRad * privRad; CellIteratorArg iterArg(sphere); - iterArg.mIgnoreOverlap = true; + iterArg.mIsCollSphereDisabled = true; CellIterator iter(iterArg); diff --git a/src/plugProjectNishimuraU/GasHiba.cpp b/src/plugProjectNishimuraU/GasHiba.cpp index edf5a749b..1cc5a9dca 100644 --- a/src/plugProjectNishimuraU/GasHiba.cpp +++ b/src/plugProjectNishimuraU/GasHiba.cpp @@ -168,7 +168,7 @@ void Obj::interactGasAttack() sphere.mRadius = parms->mGeneral.mAttackRadius.mValue; CellIteratorArg arg(sphere); - arg.mIgnoreOverlap = true; + arg.mIsCollSphereDisabled = true; CellIterator iterator(arg); CI_LOOP(iterator) diff --git a/src/plugProjectNishimuraU/Hiba.cpp b/src/plugProjectNishimuraU/Hiba.cpp index eeb88caab..8b05ce7a4 100644 --- a/src/plugProjectNishimuraU/Hiba.cpp +++ b/src/plugProjectNishimuraU/Hiba.cpp @@ -159,7 +159,7 @@ void Obj::interactFireAttack() sphere.mRadius = parms->mGeneral.mAttackRadius.mValue; CellIteratorArg arg(sphere); - arg.mIgnoreOverlap = true; + arg.mIsCollSphereDisabled = true; CellIterator iterator(arg); CI_LOOP(iterator) diff --git a/src/plugProjectNishimuraU/Kabuto.cpp b/src/plugProjectNishimuraU/Kabuto.cpp index a2e049287..eef2a647f 100644 --- a/src/plugProjectNishimuraU/Kabuto.cpp +++ b/src/plugProjectNishimuraU/Kabuto.cpp @@ -234,7 +234,7 @@ bool Obj::isAttackableTarget() sphere.mPosition = pos; CellIteratorArg iterArg(sphere); - iterArg.mIgnoreOverlap = true; + iterArg.mIsCollSphereDisabled = true; CellIterator iter(iterArg); CI_LOOP(iter) { diff --git a/src/plugProjectNishimuraU/OtakaraBase.cpp b/src/plugProjectNishimuraU/OtakaraBase.cpp index b56031b90..24fe0f43a 100644 --- a/src/plugProjectNishimuraU/OtakaraBase.cpp +++ b/src/plugProjectNishimuraU/OtakaraBase.cpp @@ -609,7 +609,7 @@ void Obj::attackTarget() sphere.mRadius = radius; CellIteratorArg iterArg(sphere); - iterArg.mIgnoreOverlap = true; + iterArg.mIsCollSphereDisabled = true; CellIterator iter(iterArg); CI_LOOP(iter) diff --git a/src/plugProjectNishimuraU/Queen.cpp b/src/plugProjectNishimuraU/Queen.cpp index c0cfc3a44..fed0607b0 100644 --- a/src/plugProjectNishimuraU/Queen.cpp +++ b/src/plugProjectNishimuraU/Queen.cpp @@ -298,7 +298,7 @@ void Obj::rollingAttack() Sys::Sphere sphere(mPosition, 250.0f); CellIteratorArg iterArg(sphere); - iterArg.mIgnoreOverlap = true; + iterArg.mIsCollSphereDisabled = true; CellIterator iter(iterArg); CI_LOOP(iter) diff --git a/src/plugProjectNishimuraU/Tank.cpp b/src/plugProjectNishimuraU/Tank.cpp index 9bdc85962..230d36b2a 100644 --- a/src/plugProjectNishimuraU/Tank.cpp +++ b/src/plugProjectNishimuraU/Tank.cpp @@ -289,7 +289,7 @@ bool Obj::isAttackable(bool check) sphere.mRadius = halfRatio; CellIteratorArg iterArg(sphere); - iterArg.mIgnoreOverlap = true; + iterArg.mIsCollSphereDisabled = true; CellIterator iter(iterArg);