Skip to content

Commit

Permalink
adjust rndpart strbase to match big funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
rjkiv committed Jan 24, 2025
1 parent 5aed353 commit 8e0a472
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 3 deletions.
101 changes: 100 additions & 1 deletion src/system/rndobj/Part.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#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"
#include "utl/Symbols.h"

PartOverride gNoPartOverride;
ParticleCommonPool* gParticlePool;
INIT_REVS(RndParticleSys)

namespace {
int ParticlePoolSize(){
Expand Down Expand Up @@ -44,18 +55,106 @@ 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(){

}

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) {
Expand Down
28 changes: 26 additions & 2 deletions src/system/rndobj/Part.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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*);
Expand Down Expand Up @@ -205,52 +212,69 @@ 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)
static void Init(){ REGISTER_OBJ_FACTORY(RndParticleSys) }
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;
int unke8;
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<RndMesh> mMesh; // 0x190
/** "material for particle system" */
ObjPtr<RndMat> mMat; // 0x19c
bool mPreserveParticles; // 0x1a8
Transform mRelativeXfm; // 0x1ac
Transform mLastWorldXfm; // 0x1ec
float mRelativeMotion; // 0x20c
ObjOwnerPtr<RndTransformable> mRelativeParent; // 0x210
/** "Specify a collide plane to reflect particles. Used to bounce particles off surfaces." */
ObjPtr<RndTransformable> 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
float mRPMDrag; // 0x240
Vector2 mStartOffset; // 0x244
Vector2 mEndOffset; // 0x24c
float mStretchScale; // 0x254
/** "Ratio of screen height to width" */
float mScreenAspect; // 0x258
int mSubSamples; // 0x25c
Transform mSubSampleXfm; // 0x260
Expand Down

0 comments on commit 8e0a472

Please sign in to comment.