Skip to content

Commit

Permalink
JPA work
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Jul 15, 2024
1 parent af11fc7 commit bae8aa6
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 73 deletions.
7 changes: 4 additions & 3 deletions include/JSystem/JParticle/JPAEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ class JPABaseEmitter {
stopCreateParticle();
}

bool isZDraw() { return mDraw.isZDraw(); }

void setEmitterCallBackPtr(JPACallBackBase<JPABaseEmitter*>* callback) {
mpEmitterCallBack = callback;
}
Expand All @@ -274,6 +276,8 @@ class JPABaseEmitter {
}
void setParticleList(JSUList<JPABaseParticle>* list) { mpPtclVacList = list; }
void setFieldList(JSUList<JPAFieldData>* list) { mFieldManager.mVacList = list; }
JSUList<JPABaseParticle>* getParticleList() { return &mActiveParticles; }
JSUList<JPABaseParticle>* getChildParticleList() { return &mChildParticles; }
JSULink<JPABaseEmitter>* getLinkBufferPtr() { return &mLink; }
void initDrawMgr(JPATextureResource* texRes) { mDraw.initialize(this, texRes); }
void draw(MtxP cameraMtxP) { mDraw.draw(cameraMtxP); }
Expand All @@ -294,15 +298,12 @@ class JPABaseEmitter {
void getBaseEnvColor(GXColor&) {}
void getBasePrmColor(GXColor&) {}
void getCamMtxPtr() {}
JSUList<JPABaseParticle>* getChildParticleList() { return &mChildParticles; }
void getCurrentCreateNumber() const {}
void getFrame() {}
void getGlobalParticleScale(JGeometry::TVec3<f32>&) const {}
JSUList<JPABaseParticle>* getParticleList() { return &mActiveParticles; }
void getgReRDirection(JGeometry::TVec3<f32>&) {}
void isChildDraw() {}
void isContinuousParticle() {}
bool isZDraw() { return mDraw.isZDraw(); }
void loadTexture(u8, GXTexMapID) {}
void setEmitterRotation(const JGeometry::TVec3<s16>&) {}
void setGlobalParticleHeightScale(f32) {}
Expand Down
20 changes: 11 additions & 9 deletions include/JSystem/JParticle/JPAParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ template<typename T, typename U>
class JPACallBackBase2;

enum JPAParticleStatus {
JPAPtclStts_FirstFrame = 0x01,
JPAPtlcStts_Child = 0x04,
JPAPtclStts_Invisible = 0x08,
};

Expand All @@ -40,15 +42,18 @@ class JPABaseParticle {
void setOffsetPosition(f32 x, f32 y, f32 z) { mGlobalPosition.set(x, y, z); }
void setOffsetPosition(const JGeometry::TVec3<f32>& pos) { mGlobalPosition.set(pos); }
void getGlobalPosition(JGeometry::TVec3<f32>& 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); }
void drawCB(JPABaseEmitter* emtr) { if (mpCallBack2 != NULL) mpCallBack2->draw(emtr, this); }
void setCallBackPtr(JPACallBackBase2<JPABaseEmitter*, JPABaseParticle*>* cb) { mpCallBack2 = cb; }

bool checkStatus(u32 flag) { return mStatus & flag; }
void initStatus(u32 flag) { mStatus = flag; }
void setStatus(u32 flag) { mStatus |= flag; }
void clearStatus(u32 flag) { mStatus &= ~flag; }
bool isInvisibleParticle() { return checkStatus(JPAPtclStts_Invisible); }
void setInvisibleParticleFlag() { mStatus |= JPAPtclStts_Invisible; }
void setInvisibleParticleFlag() { setStatus(JPAPtclStts_Invisible); }

void calcCB(JPABaseEmitter*) {}
void clearStatus(u32) {}
void drawCB(JPABaseEmitter*) {}
void getAge() const {}
void getDrawParamCPtr() {}
void getDrawParamPPtr() {}
void getHeight() {}
Expand All @@ -57,10 +62,7 @@ class JPABaseParticle {
void getOffsetPosition(JGeometry::TVec3<f32>&) const {}
void getVelVec(JGeometry::TVec3<f32>&) const {}
void getWidth() {}
void initStatus(u32) {}
void setCallBackPtr(JPACallBackBase2<JPABaseEmitter*, JPABaseParticle*>*) {}
void setDeleteParticleFlag() {}
void setStatus(u32) {}

public:
/* 0x00 */ JSULink<JPABaseParticle> mLink;
Expand Down Expand Up @@ -91,7 +93,7 @@ class JPABaseParticle {
/* 0xBC */ GXColor mEnvColor;
/* 0xC0 */ u16 mRotateAngle;
/* 0xC2 */ s16 mRotateSpeed;
/* 0xC4 */ u8 field_0xC4[0xC6 - 0xC4];
/* 0xC4 */ u16 field_0xC4;
/* 0xC6 */ u16 mTexIdx;
/* 0xC8 */ JPACallBackBase2<JPABaseEmitter*, JPABaseParticle*>* mpCallBack2;
/* 0xCC */ u32 mStatus;
Expand Down
15 changes: 5 additions & 10 deletions src/JSystem/JParticle/JPADrawVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,7 @@ void JPADrawExecCallBack::exec(const JPADrawContext* pDC) {
/* 80264C4C-80264C88 .text exec__19JPADrawExecCallBackFPC14JPADrawContextP15JPABaseParticle */
void JPADrawExecCallBack::exec(const JPADrawContext* pDC, JPABaseParticle* ptcl) {
JPABaseEmitter* pbe = pDC->pbe;
if (ptcl->mpCallBack2 != NULL)
ptcl->mpCallBack2->draw(pbe, ptcl);
ptcl->drawCB(pbe);
}

/* 80264C88-80264DB8 .text calc__17JPADrawCalcScaleXFPC14JPADrawContextP15JPABaseParticle */
Expand Down Expand Up @@ -890,19 +889,15 @@ void JPADrawCalcScaleAnmTimingRepeatY::calc(const JPADrawContext* pDC, JPABasePa

/* 80265444-80265588 .text calc__33JPADrawCalcScaleAnmTimingReverseXFPC14JPADrawContextP15JPABaseParticle */
void JPADrawCalcScaleAnmTimingReverseX::calc(const JPADrawContext* pDC, JPABaseParticle* ptcl) {
s32 curFrame = ptcl->mCurFrame;
f32 odd = ((s32)curFrame / pDC->pesp->getAnmCycleX()) & 1; // whether we're on an even or odd loop
curFrame = ptcl->mCurFrame; // fakematch; probably an inline function (getAge?)
f32 frame = (f32)((s32)curFrame % pDC->pesp->getAnmCycleX()) / pDC->pesp->getAnmCycleX();
f32 odd = (ptcl->getAge() / pDC->pesp->getAnmCycleX()) & 1; // whether we're on an even or odd loop
f32 frame = (f32)(ptcl->getAge() % pDC->pesp->getAnmCycleX()) / pDC->pesp->getAnmCycleX();
JPADrawContext::pcb->mScaleAnmTiming = odd + (frame - odd * 2.0f * frame);
}

/* 80265588-802656CC .text calc__33JPADrawCalcScaleAnmTimingReverseYFPC14JPADrawContextP15JPABaseParticle */
void JPADrawCalcScaleAnmTimingReverseY::calc(const JPADrawContext* pDC, JPABaseParticle* ptcl) {
s32 curFrame = ptcl->mCurFrame;
f32 odd = ((s32)curFrame / pDC->pesp->getAnmCycleY()) & 1; // whether we're on an even or odd loop
curFrame = ptcl->mCurFrame; // fakematch; probably an inline function (getAge?)
f32 frame = (f32)((s32)curFrame % pDC->pesp->getAnmCycleY()) / pDC->pesp->getAnmCycleY();
f32 odd = (ptcl->getAge() / pDC->pesp->getAnmCycleY()) & 1; // whether we're on an even or odd loop
f32 frame = (f32)(ptcl->getAge() % pDC->pesp->getAnmCycleY()) / pDC->pesp->getAnmCycleY();
JPADrawContext::pcb->mScaleAnmTiming = odd + (frame - odd * 2.0f * frame);
}

Expand Down
22 changes: 10 additions & 12 deletions src/JSystem/JParticle/JPAEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,20 @@ void JPABaseEmitter::calcParticle() {
JSULink<JPABaseParticle> * next = link->getNext();
JPABaseParticle * ptcl = (JPABaseParticle *) link->getObjectPtr();
ptcl->incFrame();
if (!(ptcl->mStatus & 0x80)) {
if (!ptcl->checkStatus(0x80)) {
ptcl->calcVelocity();
if (ptcl->mpCallBack2 != NULL)
ptcl->mpCallBack2->execute(this, ptcl);
if (!(ptcl->mStatus & 0x02)) {
ptcl->calcCB(this);
if (!ptcl->checkStatus(0x02)) {
mDraw.calcParticle(ptcl);
if (getEmitterDataBlockInfoPtr()->getSweepShape() != NULL && ptcl->checkCreateChild())
createChildren(ptcl);
ptcl->calcPosition();
}
} else {
ptcl->mStatus |= 0x02;
ptcl->setStatus(0x02);
}

if (ptcl->mStatus & 0x02)
if (ptcl->checkStatus(0x02))
deleteParticle(ptcl, &mActiveParticles);

link = next;
Expand All @@ -312,20 +311,19 @@ void JPABaseEmitter::calcChild() {
JSULink<JPABaseParticle> * next = link->getNext();
JPABaseParticle * ptcl = (JPABaseParticle *) link->getObjectPtr();
ptcl->incFrame();
if (!(ptcl->mStatus & 0x80)) {
if (!ptcl->checkStatus(0x80)) {
if ((s32)ptcl->mCurFrame != 0)
ptcl->calcVelocity();
if (ptcl->mpCallBack2 != NULL)
ptcl->mpCallBack2->execute(this, ptcl);
if (!(ptcl->mStatus & 0x02)) {
ptcl->calcCB(this);
if (!ptcl->checkStatus(0x02)) {
mDraw.calcChild(ptcl);
ptcl->calcPosition();
}
} else {
ptcl->mStatus |= 0x02;
ptcl->setStatus(0x02);
}

if (ptcl->mStatus & 0x02)
if (ptcl->checkStatus(0x02))
deleteParticle(ptcl, &mChildParticles);

link = next;
Expand Down
5 changes: 2 additions & 3 deletions src/JSystem/JParticle/JPAField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ void JPAConvectionField::calc(JPAFieldData* data, JPABaseParticle* ptcl) {

/* 8025B3CC-8025B50C .text calc__14JPARandomFieldFP12JPAFieldDataP15JPABaseParticle */
void JPARandomField::calc(JPAFieldData* data, JPABaseParticle* ptcl) {
/* Nonmatching */
s32 frame = ptcl->mCurFrame;
s32 frame = ptcl->getAge();
if (frame != 0) {
if (data->mCycle == 0)
return;
Expand All @@ -316,7 +315,7 @@ void JPADragField::init(JPAFieldData* data, JPABaseParticle* ptcl) {

/* 8025B584-8025B5F4 .text calc__12JPADragFieldFP12JPAFieldDataP15JPABaseParticle */
void JPADragField::calc(JPAFieldData* data, JPABaseParticle* ptcl) {
if (ptcl->checkStatus(0x04)) {
if (ptcl->checkStatus(JPAPtlcStts_Child)) {
ptcl->mDrag *= ptcl->mFieldDrag;
} else {
f32 affect = JPABaseField::calcFadeAffect(data, ptcl->mCurNormTime);
Expand Down
18 changes: 9 additions & 9 deletions src/JSystem/JParticle/JPAParticle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ void JPABaseParticle::initParticle() {
JGeometry::TVec3<f32> velDir;
JGeometry::TVec3<f32> velRndm;

mStatus = 0x01;
initStatus(JPAPtclStts_FirstFrame);
mFieldAccel.zero();
mFieldDrag = 1.0f;
mDrag = 1.0f;
MTXMultVec(emtrInfo.mEmitterGlobalSR, emtrInfo.mVolumePos, mLocalPosition);
if ((emtr->mDataFlag & 0x08) != 0)
mStatus |= 0x20;
setStatus(0x20);

mGlobalPosition.set(emtrInfo.mEmitterGlobalCenter);

Expand Down Expand Up @@ -88,7 +88,7 @@ void JPABaseParticle::initParticle() {
mGlobalPosition.z + mLocalPosition.z * emtrInfo.mPublicScale.z
);

mpCallBack2 = emtr->mpParticleCallBack;
setCallBackPtr(emtr->mpParticleCallBack);
emtr->mFieldManager.init(this);
field_0xd0 = 0;
}
Expand All @@ -100,10 +100,10 @@ void JPABaseParticle::initChild(JPABaseParticle* parent) {
JPABaseEmitter * emtr = emtrInfo.mpCurEmitter;
JPASweepShape * sweep = emtr->mpDataLinkInfo->getSweepShape();

mStatus = 0x04 | 0x01;
initStatus(JPAPtclStts_FirstFrame | JPAPtlcStts_Child);

if (!sweep->isEnableField()) {
mStatus |= 0x40;
setStatus(0x40);
mFieldDrag = 1.0f;
mDrag = 1.0f;
} else {
Expand Down Expand Up @@ -137,7 +137,7 @@ void JPABaseParticle::initChild(JPABaseParticle* parent) {
mVelocity = vel;

if (emtr->checkEmDataFlag(0x10))
mStatus |= 0x20;
setStatus(0x20);

mGlobalPosition.set(parent->mGlobalPosition);
mLocalPosition.set(parent->mLocalPosition);
Expand All @@ -151,7 +151,7 @@ void JPABaseParticle::initChild(JPABaseParticle* parent) {
mLocalPosition.add(unit);
}

mpCallBack2 = emtr->mpParticleCallBack;
setCallBackPtr(emtr->mpParticleCallBack);
field_0xd0 = parent->field_0xd0;
}

Expand All @@ -161,11 +161,11 @@ void JPABaseParticle::incFrame() {
if (mCurFrame < 0.0f)
mCurFrame = 0.0f;

mStatus &= ~0x01;
clearStatus(JPAPtclStts_FirstFrame);

if (mCurFrame >= mLifeTime) {
mCurNormTime = 1.0f;
mStatus |= 0x02;
setStatus(0x02); // setDeleteParticleFlag
} else {
mCurNormTime = mCurFrame / mLifeTime;
}
Expand Down
Loading

0 comments on commit bae8aa6

Please sign in to comment.