From 804e0aaf9eba8f2ff7c60d7644a7e44b6b7042f5 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Mon, 2 Sep 2024 22:41:33 -0400 Subject: [PATCH] Fix JPABaseParticle position members being out of order --- include/JSystem/JParticle/JPAParticle.h | 12 +++++----- src/JSystem/JParticle/JPADrawVisitor.cpp | 28 ++++++++++++------------ src/JSystem/JParticle/JPAField.cpp | 8 +++---- src/JSystem/JParticle/JPAParticle.cpp | 22 +++++++++---------- src/d/actor/d_a_bomb2.cpp | 2 +- src/d/actor/d_a_bomb3.inc | 2 +- src/d/actor/d_a_player_particle.inc | 10 ++++----- src/d/d_particle.cpp | 19 ++++++++-------- 8 files changed, 52 insertions(+), 51 deletions(-) diff --git a/include/JSystem/JParticle/JPAParticle.h b/include/JSystem/JParticle/JPAParticle.h index 41e214027..9fb87a8c8 100644 --- a/include/JSystem/JParticle/JPAParticle.h +++ b/include/JSystem/JParticle/JPAParticle.h @@ -39,9 +39,10 @@ class JPABaseParticle { ~JPABaseParticle() {} JPABaseParticle() : mLink(this), mCurFrame(0.0f) {} - void setOffsetPosition(f32 x, f32 y, f32 z) { mGlobalPosition.set(x, y, z); } - void setOffsetPosition(const JGeometry::TVec3& pos) { mGlobalPosition.set(pos); } - void getOffsetPosition(JGeometry::TVec3& out) const { out.set(mPosition); } // XXX: something about this is wrong + void setOffsetPosition(f32 x, f32 y, f32 z) { mOffsetPosition.set(x, y, z); } + void setOffsetPosition(const JGeometry::TVec3& pos) { mOffsetPosition.set(pos); } + void getOffsetPosition(JGeometry::TVec3& out) const { out.set(mOffsetPosition); } + void getLocalPosition(JGeometry::TVec3& out) const { out.set(mLocalPosition); } void getGlobalPosition(JGeometry::TVec3& out) const { out.set(mGlobalPosition); } s32 getAge() const { return mCurFrame; } // TODO: Not sure about this one, especially the cast to s32; this could also be mCurNormTime? void calcCB(JPABaseEmitter* emtr) { if (mpCallBack2 != NULL) mpCallBack2->execute(emtr, this); } @@ -59,16 +60,15 @@ class JPABaseParticle { void getDrawParamPPtr() {} void getHeight() {} void getLifeTime() const {} - void getLocalPosition(JGeometry::TVec3&) const {} void getVelVec(JGeometry::TVec3&) const {} void getWidth() {} void setDeleteParticleFlag() {} public: /* 0x00 */ JSULink mLink; - /* 0x10 */ JGeometry::TVec3 mGlobalPosition; + /* 0x10 */ JGeometry::TVec3 mOffsetPosition; /* 0x1C */ JGeometry::TVec3 mLocalPosition; - /* 0x28 */ JGeometry::TVec3 mPosition; + /* 0x28 */ JGeometry::TVec3 mGlobalPosition; /* 0x34 */ JGeometry::TVec3 mVelocity; /* 0x40 */ JGeometry::TVec3 mBaseVel; /* 0x4C */ JGeometry::TVec3 mAccel; diff --git a/src/JSystem/JParticle/JPADrawVisitor.cpp b/src/JSystem/JParticle/JPADrawVisitor.cpp index 99e2b9c4b..93cf8e352 100644 --- a/src/JSystem/JParticle/JPADrawVisitor.cpp +++ b/src/JSystem/JParticle/JPADrawVisitor.cpp @@ -290,7 +290,7 @@ void JPADrawExecBillBoard::exec(const JPADrawContext* pDC, JPABaseParticle* ptcl scaleY *= (JPADrawContext::pcb->mGlobalScaleY + JPADrawContext::pcb->mPivotY); JGeometry::TVec3 pt; - pt.set(ptcl->mPosition); + ptcl->getGlobalPosition(pt); MTXMultVec(JPADrawContext::pcb->mDrawMtxPtr, pt, &pt); GXBegin(GX_QUADS, GX_VTXFMT0, 4); @@ -323,7 +323,7 @@ void JPADrawExecRotBillBoard::exec(const JPADrawContext* pDC, JPABaseParticle* p f32 y1 = -ptcl->mScaleY * (JPADrawContext::pcb->mGlobalScaleY - JPADrawContext::pcb->mPivotY); JGeometry::TVec3 pt; - pt.set(ptcl->mPosition); + ptcl->getGlobalPosition(pt); MTXMultVec(JPADrawContext::pcb->mDrawMtxPtr, pt, &pt); GXBegin(GX_QUADS, GX_VTXFMT0, 4); @@ -355,12 +355,12 @@ void dirTypeVel(JPABaseParticle* ptcl, JPABaseEmitter* emtr, JGeometry::TVec3 */ void dirTypePos(JPABaseParticle* ptcl, JPABaseEmitter* emtr, JGeometry::TVec3& out) { - out.set(ptcl->mLocalPosition); + ptcl->getLocalPosition(out); } /* 80261384-802613C4 .text dirTypePosInv__FP15JPABaseParticleP14JPABaseEmitterRQ29JGeometry8TVec3 */ void dirTypePosInv(JPABaseParticle* ptcl, JPABaseEmitter* emtr, JGeometry::TVec3& out) { - out.set(ptcl->mLocalPosition); + ptcl->getLocalPosition(out); out.negate(); } @@ -372,10 +372,10 @@ void dirTypeEmtrDir(JPABaseParticle* ptcl, JPABaseEmitter* emtr, JGeometry::TVec /* 802613E8-802614A8 .text dirTypePrevPtcl__FP15JPABaseParticleP14JPABaseEmitterRQ29JGeometry8TVec3 */ void dirTypePrevPtcl(JPABaseParticle* ptcl, JPABaseEmitter* emtr, JGeometry::TVec3& out) { JGeometry::TVec3 pos; - pos.set(ptcl->mPosition); + ptcl->getGlobalPosition(pos); JSULink* prev = ptcl->getLinkBufferPtr()->getPrev(); if (prev != NULL) { - out.set(prev->getObject()->mPosition); + prev->getObject()->getGlobalPosition(out); } else { emtr->calcEmitterGlobalPosition(out); } @@ -541,9 +541,9 @@ void JPADrawExecRotation::exec(const JPADrawContext* pDC, JPABaseParticle* ptcl) JPADrawContext::pcb->mRotTypeFunc(sin, cos, rotMtx); MTXMultVecArray(rotMtx, pt, pt, ARRAY_SIZE(pt)); - f32 x = ptcl->mPosition.x; - f32 y = ptcl->mPosition.y; - f32 z = ptcl->mPosition.z; + f32 x = ptcl->mGlobalPosition.x; + f32 y = ptcl->mGlobalPosition.y; + f32 z = ptcl->mGlobalPosition.z; GXBegin(GX_QUADS, GX_VTXFMT0, 4); GXPosition3f32(pt[0].x + x, pt[0].y + y, pt[0].z + z); @@ -589,9 +589,9 @@ void JPADrawExecRotationCross::exec(const JPADrawContext* pDC, JPABaseParticle* JPADrawContext::pcb->mRotTypeFunc(sin, cos, rotMtx); MTXMultVecArray(rotMtx, pt, pt, ARRAY_SIZE(pt)); - f32 x = ptcl->mPosition.x; - f32 y = ptcl->mPosition.y; - f32 z = ptcl->mPosition.z; + f32 x = ptcl->mGlobalPosition.x; + f32 y = ptcl->mGlobalPosition.y; + f32 z = ptcl->mGlobalPosition.z; GXBegin(GX_QUADS, GX_VTXFMT0, 8); GXPosition3f32(pt[0].x + x, pt[0].y + y, pt[0].z + z); @@ -619,7 +619,7 @@ void JPADrawExecPoint::exec(const JPADrawContext* pDC, JPABaseParticle* ptcl) { return; JGeometry::TVec3 pos; - pos.set(ptcl->mPosition); + ptcl->getGlobalPosition(pos); GXBegin(GX_POINTS, GX_VTXFMT0, 1); GXPosition3f32(pos.x, pos.y, pos.z); GXTexCoord2f32(0.0f, 0.0f); @@ -634,7 +634,7 @@ void JPADrawExecLine::exec(const JPADrawContext* pDC, JPABaseParticle* ptcl) { JGeometry::TVec3 pt0; JGeometry::TVec3 vel; - pt0.set(ptcl->mPosition); + ptcl->getGlobalPosition(pt0); vel.set(ptcl->mVelocity); if (!vel.isZero()) { vel.normalize(); diff --git a/src/JSystem/JParticle/JPAField.cpp b/src/JSystem/JParticle/JPAField.cpp index 8c19ef44c..42873bedc 100644 --- a/src/JSystem/JParticle/JPAField.cpp +++ b/src/JSystem/JParticle/JPAField.cpp @@ -134,7 +134,7 @@ void JPAAirField::calc(JPAFieldData* data, JPABaseParticle* ptcl) { if (data->mSttFlag & 0x01) { JGeometry::TVec3 vel; if (data->mSttFlag & 0x02) { - vel.sub(ptcl->mPosition, data->mWork0); + vel.sub(ptcl->mGlobalPosition, data->mWork0); } else { vel.sub(ptcl->mLocalPosition, data->mWork0); } @@ -169,7 +169,7 @@ void JPAMagnetField::preCalc(JPAFieldData* data) { /* 8025A788-8025A8AC .text calc__14JPAMagnetFieldFP12JPAFieldDataP15JPABaseParticle */ void JPAMagnetField::calc(JPAFieldData* data, JPABaseParticle* ptcl) { if (data->mSttFlag & 0x02) { - data->mVel.sub(data->mWork0, ptcl->mPosition); + data->mVel.sub(data->mWork0, ptcl->mGlobalPosition); } else { data->mVel.sub(data->mWork0, ptcl->mLocalPosition); } @@ -192,7 +192,7 @@ void JPANewtonField::preCalc(JPAFieldData* data) { /* 8025A954-8025ABB8 .text calc__14JPANewtonFieldFP12JPAFieldDataP15JPABaseParticle */ void JPANewtonField::calc(JPAFieldData* data, JPABaseParticle* ptcl) { if (data->mSttFlag & 0x02) { - data->mVel.sub(data->mWork0, ptcl->mPosition); + data->mVel.sub(data->mWork0, ptcl->mGlobalPosition); } else { data->mVel.sub(data->mWork0, ptcl->mLocalPosition); } @@ -413,7 +413,7 @@ void JPAFieldManager::calc(JPABaseParticle* ptcl) { for (JSULink* link = mList.getFirst(); link != NULL; link = link->getNext()) { JPAFieldData* data = link->getObject(); if (data->mSttFlag & 0x80) { - if (!data->mpBaseField->isItinRange(data, ptcl->mPosition.squared(data->mPos))) + if (!data->mpBaseField->isItinRange(data, ptcl->mGlobalPosition.squared(data->mPos))) continue; } data->mpBaseField->calc(data, ptcl); diff --git a/src/JSystem/JParticle/JPAParticle.cpp b/src/JSystem/JParticle/JPAParticle.cpp index 61a732c74..dcfdeff00 100644 --- a/src/JSystem/JParticle/JPAParticle.cpp +++ b/src/JSystem/JParticle/JPAParticle.cpp @@ -26,7 +26,7 @@ void JPABaseParticle::initParticle() { if ((emtr->mDataFlag & 0x08) != 0) setStatus(0x20); - mGlobalPosition.set(emtrInfo.mEmitterGlobalCenter); + mOffsetPosition.set(emtrInfo.mEmitterGlobalCenter); if (emtr->mInitialVelOmni) velOmni.setLength(emtrInfo.mVelOmni, emtr->mInitialVelOmni); @@ -82,10 +82,10 @@ void JPABaseParticle::initParticle() { mLifeTime = emtr->mLifeTime * (1.0f - emtr->mLifeTimeRndm * emtr->getRandomF()); mCurNormTime = 0.0f; - mPosition.set( - mGlobalPosition.x + mLocalPosition.x * emtrInfo.mPublicScale.x, - mGlobalPosition.y + mLocalPosition.y * emtrInfo.mPublicScale.y, - mGlobalPosition.z + mLocalPosition.z * emtrInfo.mPublicScale.z + mGlobalPosition.set( + mOffsetPosition.x + mLocalPosition.x * emtrInfo.mPublicScale.x, + mOffsetPosition.y + mLocalPosition.y * emtrInfo.mPublicScale.y, + mOffsetPosition.z + mLocalPosition.z * emtrInfo.mPublicScale.z ); setCallBackPtr(emtr->mpParticleCallBack); @@ -139,7 +139,7 @@ void JPABaseParticle::initChild(JPABaseParticle* parent) { if (emtr->checkEmDataFlag(0x10)) setStatus(0x20); - mGlobalPosition.set(parent->mGlobalPosition); + mOffsetPosition.set(parent->mOffsetPosition); mLocalPosition.set(parent->mLocalPosition); f32 posRndm = sweep->getPosRndm(); @@ -175,7 +175,7 @@ void JPABaseParticle::incFrame() { void JPABaseParticle::calcVelocity() { mFieldVel.zero(); if (checkStatus(0x20)) - mGlobalPosition.set(JPABaseEmitter::emtrInfo.mEmitterGlobalCenter); + mOffsetPosition.set(JPABaseEmitter::emtrInfo.mEmitterGlobalCenter); mBaseVel.add(mAccel); if (!checkStatus(0x40)) JPABaseEmitter::emtrInfo.mpCurEmitter->mFieldManager.calc(this); @@ -196,10 +196,10 @@ void JPABaseParticle::calcVelocity() { void JPABaseParticle::calcPosition() { mLocalPosition.add(mVelocity); - mPosition.set( - mLocalPosition.x * JPABaseEmitter::emtrInfo.mPublicScale.x + mGlobalPosition.x, - mLocalPosition.y * JPABaseEmitter::emtrInfo.mPublicScale.y + mGlobalPosition.y, - mLocalPosition.z * JPABaseEmitter::emtrInfo.mPublicScale.z + mGlobalPosition.z + mGlobalPosition.set( + mLocalPosition.x * JPABaseEmitter::emtrInfo.mPublicScale.x + mOffsetPosition.x, + mLocalPosition.y * JPABaseEmitter::emtrInfo.mPublicScale.y + mOffsetPosition.y, + mLocalPosition.z * JPABaseEmitter::emtrInfo.mPublicScale.z + mOffsetPosition.z ); } diff --git a/src/d/actor/d_a_bomb2.cpp b/src/d/actor/d_a_bomb2.cpp index 2397077d1..004f554b9 100644 --- a/src/d/actor/d_a_bomb2.cpp +++ b/src/d/actor/d_a_bomb2.cpp @@ -245,7 +245,7 @@ namespace daBomb2 { JSUPtrLink* next = link->getNext(); JPABaseParticle* ptcl = (JPABaseParticle*)link->getObjectPtr(); - ptcl->mGlobalPosition.set(x, y, z); + ptcl->setOffsetPosition(x, y, z); link = next; } diff --git a/src/d/actor/d_a_bomb3.inc b/src/d/actor/d_a_bomb3.inc index 0f199a1f1..6f1b20a48 100644 --- a/src/d/actor/d_a_bomb3.inc +++ b/src/d/actor/d_a_bomb3.inc @@ -124,7 +124,7 @@ void daBomb_fuseSparksEcallBack::execute(JPABaseEmitter* emitter) { JSUPtrLink* next = link->getNext(); JPABaseParticle* ptcl = (JPABaseParticle*)link->getObjectPtr(); - ptcl->mGlobalPosition.set(x, y, z); + ptcl->setOffsetPosition(x, y, z); link = next; } diff --git a/src/d/actor/d_a_player_particle.inc b/src/d/actor/d_a_player_particle.inc index bf839b3f4..941af4bd2 100644 --- a/src/d/actor/d_a_player_particle.inc +++ b/src/d/actor/d_a_player_particle.inc @@ -118,10 +118,10 @@ void daPy_swimTailEcallBack_c::execute(JPABaseEmitter* emitter) { JSULink* nextLink = link->getNext(); JPABaseParticle* particle = link->getObject(); - JGeometry::TVec3 sp14; - particle->getGlobalPosition(sp14); - getMaxWaterY(&sp14); - particle->setOffsetPosition(sp14); + JGeometry::TVec3 offsetPos; + particle->getOffsetPosition(offsetPos); + getMaxWaterY(&offsetPos); + particle->setOffsetPosition(offsetPos); link = nextLink; } @@ -370,7 +370,7 @@ void daPy_fanSwingEcallBack_c::execute(JPABaseEmitter* emitter) { void daPy_waterDropPcallBack_c::execute(JPABaseEmitter* emitter, JPABaseParticle* ptcl) { if (field_0x4) { JGeometry::TVec3 ptclPos; - ptcl->getOffsetPosition(ptclPos); + ptcl->getGlobalPosition(ptclPos); cXyz pos(ptclPos.x, ptclPos.y + 25.0f, ptclPos.z); mGndChk.SetPos(&pos); diff --git a/src/d/d_particle.cpp b/src/d/d_particle.cpp index 3004b756d..6582f306b 100644 --- a/src/d/d_particle.cpp +++ b/src/d/d_particle.cpp @@ -107,9 +107,9 @@ void dPa_J3DmodelEmitter_c::draw() { } // TODO: all the math - mtx1[0][3] = ptcl->mPosition.x; - mtx1[1][3] = ptcl->mPosition.y; - mtx1[2][3] = ptcl->mPosition.z; + mtx1[0][3] = ptcl->mGlobalPosition.x; + mtx1[1][3] = ptcl->mGlobalPosition.y; + mtx1[2][3] = ptcl->mGlobalPosition.z; g_env_light.setLightTevColorType(model, &tevStr); if (field_0x1c != NULL && field_0x20 != NULL) { @@ -409,12 +409,13 @@ void dPa_smokeEcallBack::end() { /* 8007BBD8-8007BC84 .text dPa_setWindPower__FP15JPABaseParticle */ void dPa_setWindPower(JPABaseParticle* ptcl) { - /* Nonmatching */ - cXyz pos(ptcl->mGlobalPosition); + JGeometry::TVec3 offsetPos; cXyz wind; f32 pow; - dKyw_get_AllWind_vec(&pos, &wind, &pow); - ptcl->mGlobalPosition.add(pos, wind * (pow * 8.0f)); + ptcl->getOffsetPosition(offsetPos); + dKyw_get_AllWind_vec((cXyz*)&offsetPos, &wind, &pow); + offsetPos += wind * (pow * 8.0f); + ptcl->setOffsetPosition(offsetPos); } /* 8007BC84-8007BCB4 .text execute__18dPa_smokePcallBackFP14JPABaseEmitterP15JPABaseParticle */ @@ -963,9 +964,9 @@ void dPa_singleRippleEcallBack::draw(JPABaseEmitter*) { void dPa_ripplePcallBack::execute(JPABaseEmitter* param_1, JPABaseParticle* ptcl) { /* Nonmatching */ f32 height; - cXyz pos(ptcl->mPosition.x, ptcl->mPosition.y, ptcl->mPosition.z); + cXyz pos(ptcl->mGlobalPosition.x, ptcl->mGlobalPosition.y, ptcl->mGlobalPosition.z); if (fopAcM_getWaterY(&pos, &height)) { - ptcl->mGlobalPosition.y = height; + ptcl->mOffsetPosition.y = height; } }