From 8e0a47278b48cb7cd41d097902cad5c0f434c7d5 Mon Sep 17 00:00:00 2001 From: rjkiv <76180273+rjkiv@users.noreply.github.com> Date: Fri, 24 Jan 2025 13:59:48 -0700 Subject: [PATCH] adjust rndpart strbase to match big funcs --- src/system/rndobj/Part.cpp | 101 ++++++++++++++++++++++++++++++++++++- src/system/rndobj/Part.h | 28 +++++++++- 2 files changed, 126 insertions(+), 3 deletions(-) diff --git a/src/system/rndobj/Part.cpp b/src/system/rndobj/Part.cpp index 8399cec71..06fcae85f 100644 --- a/src/system/rndobj/Part.cpp +++ b/src/system/rndobj/Part.cpp @@ -1,6 +1,16 @@ #include "rndobj/Part.h" +#include "obj/Data.h" +#include "obj/ObjMacros.h" +#include "obj/Object.h" +#include "os/Debug.h" +#include "os/System.h" +#include "os/Timer.h" +#include "rndobj/Anim.h" +#include "rndobj/Draw.h" #include "rndobj/Mesh.h" #include "rndobj/Mat.h" +#include "rndobj/Poll.h" +#include "rndobj/Trans.h" #include "rndobj/Utl.h" #include "utl/MemMgr.h" #include "obj/DataFunc.h" @@ -8,6 +18,7 @@ PartOverride gNoPartOverride; ParticleCommonPool* gParticlePool; +INIT_REVS(RndParticleSys) namespace { int ParticlePoolSize(){ @@ -44,10 +55,98 @@ void ParticleCommonPool::InitPool(){ mPoolParticles = new RndFancyParticle[0xb0]; } +void RndParticleSys::SetPool(int max, RndParticleSys::Type ty){ + mMaxParticles = max; + DataArray* cfg = SystemConfig("rnd", "particlesys", "local_limit"); +} + +BEGIN_COPYS(RndParticleSys) + CREATE_COPY_AS(RndParticleSys, f) + MILO_ASSERT(f, 0xD6); + COPY_SUPERCLASS(Hmx::Object) + COPY_SUPERCLASS(RndPollable) + COPY_SUPERCLASS(RndAnimatable) + COPY_SUPERCLASS(RndTransformable) + COPY_SUPERCLASS(RndDrawable) + COPY_MEMBER_FROM(f, mPreserveParticles) + if(mPreserveParticles){ + SetPool(mMaxParticles, mType); + } + COPY_MEMBER_FROM(f, unkdc) + unke4 = GetFrame(); + if(ty != kCopyFromMax){ + COPY_MEMBER_FROM(f, mLife) + COPY_MEMBER_FROM(f, mScreenAspect) + COPY_MEMBER_FROM(f, mBoxExtent1) + COPY_MEMBER_FROM(f, mBoxExtent2) + COPY_MEMBER_FROM(f, mSpeed) + COPY_MEMBER_FROM(f, mPitch) + COPY_MEMBER_FROM(f, mYaw) + COPY_MEMBER_FROM(f, mEmitRate) + COPY_MEMBER_FROM(f, mMaxBurst) + COPY_MEMBER_FROM(f, mTimeBetween) + COPY_MEMBER_FROM(f, mPeakRate) + COPY_MEMBER_FROM(f, mDuration) + COPY_MEMBER_FROM(f, mStartSize) + COPY_MEMBER_FROM(f, mDeltaSize) + COPY_MEMBER_FROM(f, mStartColorLow) + COPY_MEMBER_FROM(f, mStartColorHigh) + COPY_MEMBER_FROM(f, mEndColorLow) + COPY_MEMBER_FROM(f, mEndColorHigh) + COPY_MEMBER_FROM(f, mBounce) + COPY_MEMBER_FROM(f, mForceDir) + COPY_MEMBER_FROM(f, mMat) + COPY_MEMBER_FROM(f, mBubblePeriod) + COPY_MEMBER_FROM(f, mBubbleSize) + // bitfield shenanigans here + } +END_COPYS + SAVE_OBJ(RndParticleSys, 0x13D) +BEGIN_LOADS(RndParticleSys) + LOAD_REVS(bs) + ASSERT_REVS(0x25, 0) + MILO_LOG("%s_bounce.trans"); + MILO_LOG("Unable to allocate all particles for %s\n"); +END_LOADS + +RndParticle* RndParticleSys::FreeParticle(RndParticle* p){ + if(!p) return nullptr; + else { + if(p == unkd8){ + unkd8 = p->next; + } + else { + p->prev->next = p->next; + } + if(p->next){ + p->next->prev = p->prev; + } + if(!p->prev){ + MILO_FAIL("Already deallocated particle"); + } + p->prev = nullptr; + RndParticle* ret = nullptr; + if(mPreserveParticles){ + ret = p->next; + p->next = unkd4; + unkd4 = p; + } + else { + ret = gParticlePool->FreeParticle(p); + } + unkdc--; + return ret; + } +} + BinStream& operator>>(BinStream&, RndParticle&); +void RndParticleSys::MoveParticles(float, float){ + START_AUTO_TIMER("psysmove"); +} + RndParticleSys::~RndParticleSys(){ } @@ -55,7 +154,7 @@ RndParticleSys::~RndParticleSys(){ RndParticleSys::RndParticleSys() : mType(t0), mMaxParticles(0), unkd0(0), unkd4(0), unkd8(0), unkdc(0), unke0(0.0f), unke4(0.0f), unke8(0), unkec(0.0f), mBubblePeriod(10.0f, 10.0f), mBubbleSize(1.0f, 1.0f), mLife(100.0f, 100.0f), mBoxExtent1(0.0f, 0.0f, 0.0f), mBoxExtent2(0.0f, 0.0f, 0.0f), mSpeed(1.0f, 1.0f), mPitch(0.0f, 0.0f), mYaw(0.0f, 0.0f), mEmitRate(1.0f, 1.0f), mStartSize(1.0f, 1.0f), mDeltaSize(0.0f, 0.0f), - mMesh(this, 0), mMat(this, 0), mPreserveParticles(0), mRelativeParent(this, 0), mBounce(this, 0), mForceDir(0.0f, 0.0f, 0.0f), mDrag(0.0f), + mMesh(this), mMat(this), mPreserveParticles(0), mRelativeParent(this), mBounce(this), mForceDir(0.0f, 0.0f, 0.0f), mDrag(0.0f), mRPM(0.0f, 0.0f), mRPMDrag(0.0f), mStartOffset(0.0f, 0.0f), mEndOffset(0.0f, 0.0f), mStretchScale(1.0f), mScreenAspect(1.0f), mSubSamples(0), mGrowRatio(0.0f), mShrinkRatio(1.0f), mMidColorRatio(0.5f), mMaxBurst(0), unk2c8(0.0f), mTimeBetween(15.0f, 35.0f), mPeakRate(4.0f, 8.0f), mDuration(20.0f, 30.0f), unk2e4(0), unk2e8(0.0f) { diff --git a/src/system/rndobj/Part.h b/src/system/rndobj/Part.h index d9057bb7c..5475cfe7f 100644 --- a/src/system/rndobj/Part.h +++ b/src/system/rndobj/Part.h @@ -1,6 +1,7 @@ #pragma once #include "math/Color.h" #include "math/Vec.h" +#include "obj/ObjMacros.h" #include "rndobj/Trans.h" #include "rndobj/Draw.h" #include "rndobj/Poll.h" @@ -49,6 +50,7 @@ class ParticleCommonPool { public: ParticleCommonPool() : mPoolParticles(0), mPoolFreeParticles(0), mNumActiveParticles(0), mHighWaterMark(0) {} void InitPool(); + RndParticle* FreeParticle(RndParticle*); RndFancyParticle* mPoolParticles; // 0x0 RndFancyParticle* mPoolFreeParticles; // 0x4 @@ -88,6 +90,9 @@ struct PartOverride { Box box; // 0x58 }; +/** "A ParticleSys object generates, animates, and draws large + * numbers of similar sprites. Currently particles are rendered only + * as points on the PC." */ class RndParticleSys : public RndAnimatable, public RndPollable, public RndTransformable, public RndDrawable { public: enum Type { @@ -133,6 +138,8 @@ class RndParticleSys : public RndAnimatable, public RndPollable, public RndTrans void ExplicitParticles(int, bool, PartOverride&); void FreeAllParticles(); int MaxParticles() const; + RndParticle* FreeParticle(RndParticle*); + void MoveParticles(float, float); DataNode OnSetStartColor(const DataArray*); DataNode OnSetStartColorInt(const DataArray*); @@ -205,6 +212,7 @@ class RndParticleSys : public RndAnimatable, public RndPollable, public RndTrans Type GetType() const { return mType; } RndMat* GetMat() const { return mMat; } + DECLARE_REVS; NEW_OVERLOAD; DELETE_OVERLOAD; NEW_OBJ(RndParticleSys) @@ -212,10 +220,11 @@ class RndParticleSys : public RndAnimatable, public RndPollable, public RndTrans static RndParticle* AllocParticle(); Type mType; // fancy? + /** "maximum number of particles". Ranges from 0 to 3072. */ int mMaxParticles; // 0xcc int unkd0; - int unkd4; - int unkd8; + RndParticle* unkd4; + RndParticle* unkd8; int unkdc; float unke0; float unke4; @@ -223,27 +232,41 @@ class RndParticleSys : public RndAnimatable, public RndPollable, public RndTrans float unkec; Vector2 mBubblePeriod; // 0xf0 Vector2 mBubbleSize; // 0xf8 + /** "Frame range of particle life." */ Vector2 mLife; // 0x100 + /** "Min point and max point, in object coordinates, of box region that particles are emitted from." */ Vector3 mBoxExtent1; // 0x108 + /** "Min point and max point, in object coordinates, of box region that particles are emitted from." */ Vector3 mBoxExtent2; // 0x114 + /** "Speed range, in world units per frame, of particles." */ Vector2 mSpeed; // 0x120 Vector2 mPitch; // 0x128 Vector2 mYaw; // 0x130 + /** "Frame range to generate particles." */ Vector2 mEmitRate; // 0x138 + /** "Size range, in world units, of particles." */ Vector2 mStartSize; // 0x140 + /** "Change in size of particles, in world units." */ Vector2 mDeltaSize; // 0x148 + /** "Random color ranges for start and end color of particles." */ Hmx::Color mStartColorLow; // 0x150 + /** "Random color ranges for start and end color of particles." */ Hmx::Color mStartColorHigh; // 0x160 + /** "Random color ranges for start and end color of particles." */ Hmx::Color mEndColorLow; // 0x170 + /** "Random color ranges for start and end color of particles." */ Hmx::Color mEndColorHigh; // 0x180 ObjPtr mMesh; // 0x190 + /** "material for particle system" */ ObjPtr mMat; // 0x19c bool mPreserveParticles; // 0x1a8 Transform mRelativeXfm; // 0x1ac Transform mLastWorldXfm; // 0x1ec float mRelativeMotion; // 0x20c ObjOwnerPtr mRelativeParent; // 0x210 + /** "Specify a collide plane to reflect particles. Used to bounce particles off surfaces." */ ObjPtr mBounce; // 0x21c + /** "Force direction in world coordinates, in units per frame added to each particle's velocity. Can be used for gravity." */ Vector3 mForceDir; // 0x228 float mDrag; // 0x234 Vector2 mRPM; // 0x238 @@ -251,6 +274,7 @@ class RndParticleSys : public RndAnimatable, public RndPollable, public RndTrans Vector2 mStartOffset; // 0x244 Vector2 mEndOffset; // 0x24c float mStretchScale; // 0x254 + /** "Ratio of screen height to width" */ float mScreenAspect; // 0x258 int mSubSamples; // 0x25c Transform mSubSampleXfm; // 0x260