Skip to content

Commit

Permalink
More Cleanup (re: @HeartPiece44)
Browse files Browse the repository at this point in the history
  • Loading branch information
intns committed Sep 11, 2023
1 parent 6ff7925 commit 88798ce
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 76 deletions.
8 changes: 4 additions & 4 deletions include/BoundBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions include/Game/cellPyramid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
};

Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectKandoU/aiBattle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 19 additions & 19 deletions src/plugProjectKandoU/cellIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand All @@ -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;
}

/*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
62 changes: 36 additions & 26 deletions src/plugProjectKandoU/cellPyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,8 @@ inline void CellLayer::drawCell(Graphics&, Vector3f&, int, int, float) const
*/
CellPyramid::CellPyramid()
{
mLayerCount = 0;
mMemoryUsageMaybe = 0;
mLayerCount = 0;
mFreeMemory = 0;
}

/*
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/plugProjectKandoU/navi_demoCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectKandoU/piki.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/plugProjectKandoU/pikiState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectMorimuraU/bombState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/BigTreasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/BigTreasureAttack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/ElecHiba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/Fart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/Fuefuki.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ bool Obj::isJumpAway()
f32 privateDiameter = privRad * privRad;

CellIteratorArg iterArg(sphere);
iterArg.mIgnoreOverlap = true;
iterArg.mIsCollSphereDisabled = true;

CellIterator iter(iterArg);

Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/GasHiba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/Hiba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/Kabuto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/OtakaraBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/Queen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/plugProjectNishimuraU/Tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ bool Obj::isAttackable(bool check)
sphere.mRadius = halfRatio;

CellIteratorArg iterArg(sphere);
iterArg.mIgnoreOverlap = true;
iterArg.mIsCollSphereDisabled = true;

CellIterator iter(iterArg);

Expand Down

0 comments on commit 88798ce

Please sign in to comment.