resonance 1.0.1
Loading...
Searching...
No Matches
particlesys.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <vector>
5
6#include "math/color.h"
7#include "math/plane.h"
8#include "math/vector2.h"
9#include "math/vector3.h"
10#include "os/hxstr.h"
11#include "rnd/animatable.h"
12#include "rnd/drawable.h"
13#include "rnd/manager.h"
14#include "rnd/particle.h"
15#include "rnd/transformable.h"
16
17namespace Rnd {
18class Dbg;
19class Mat;
20class Object;
21class Stream;
22} // namespace Rnd
23
24namespace Rnd {
25
60class ParticleSys : public Animatable, public Transformable, public Drawable {
61public:
70 enum Type {
74 };
75
77 static constexpr unsigned kCopyShareParticles = 0x400;
78
89 ParticleSys(const HxStr &name);
90
95 virtual ~ParticleSys();
96
105 static void *operator new(size_t nSize);
106
114 static void operator delete(void *pBlock);
115
123 virtual void DumpText(Dbg &sink);
124
132 virtual void Save(Stream &stream);
133
145 virtual void Replace(Object *pFrom, Object *pTo);
146
154 virtual const HxStr &ClassName() const;
155
171 virtual void Copy(const Object *pSource, unsigned nFlags);
172
183 virtual void Load(Stream &stream);
184
195 virtual void StartAnim();
196
197 // The three members below are public because code outside this hierarchy calls all three
198 // directly. Rnd::Generator::Regenerate() at `0x0045a998` calls every one of them, and the
199 // stage classes between `0x00412000` and `0x00457000` supply nineteen further callers of
200 // FreeAllParticles() and seven of AllocParticle(). A friend declaration per calling class fits
201 // the image equally well, and nothing in the image distinguishes the two readings.
202
215
228
243
258
269 void SetMat(Mat *pMat);
270
283
295 return mLiveParticles;
296 }
297
307 void SetForce(const Vector3 &force) {
308 mForce = force;
309 }
310
321 return mForce;
322 }
323
324protected:
336 virtual void SetFrameSelf(float flFrame);
337
350 void SetNumParticles(int nCount);
351
352private:
360 void UpdateParticles(float flDeltaFrames);
361
368 void SpawnParticles(float flDeltaFrames);
369
379 void RemoveObjectRefs();
380
392 void AddObjectRefs();
393
394 // Data members follow the recovered offset order.
395
396protected:
397 // The first three are protected rather than private because Rnd::PsParticleSys::DrawShowing()
398 // reads all three directly, the owner and its pool for the overflow guard and the live list
399 // both to test for emptiness and to walk.
400
401 // System whose particles this one draws, itself for a system that owns them. +0xe4
403
404public:
410 std::vector<Particle> mParticles;
411
412protected:
413 // Head of the live list, threaded through Particle::mNext. Rnd::PsParticleSys::DrawShowing()
414 // treats a null head as nothing to draw.
416
417private:
418 // Head of the free list, threaded through Particle::mNext and ending at the finish pointer of
419 // mParticles. Only the owning system's list is used.
420 Particle *mFreeParticles;
421 // Frame SetFrameSelf() last ran for. It starts at the sentinel -0.9997e7, whose bit pattern
422 // is 0xcb18967f, and a frame equal to it makes SetFrameSelf() return without emitting.
423 float mLastFrame;
424 // Particles owed by the emission rate, of which SpawnParticles() emits the whole part and
425 // retains the fraction for the next call. The title is inferred.
426 float mEmitAccumulator;
427 // Systems that share this one's particles. RemoveObjectRefs() removes this system from the
428 // list of whichever system owns its particles.
429 std::list<ParticleSys *> mSharers;
430 // The range pairs below print as "(x: y:)" and store the low end in x and the high end in y.
431 Vector2 mBubblePeriod;
432 Vector2 mBubbleSize;
433 Vector2 mLife;
434 Vector3 mPosLow;
435 Vector3 mPosHigh;
436 Vector2 mSpeed;
437 Vector2 mPitch;
438 Vector2 mYaw;
439
440public:
449 float mSizeLow;
452
453private:
454 unsigned char mReserved168[0x08]; // +0x168 Alignment padding before mStartColorLow.
455
456public:
466
467private:
468 int mCollide; // Non-zero to collide with mCollidePlane.
469 unsigned char mReserved1b4[0xc]; // +0x1b4 Never read or written by a recovered routine.
470 Plane mCollidePlane;
471 Vector3 mForce;
472
473public:
481
482private:
483 int mBubble; // Non-zero to apply mBubblePeriod and mBubbleSize.
484
485public:
493};
494
506
519
529extern ParticleSys *(*g_pfnNewParticleSys)(const HxStr &name);
530
543
551
568
569} // namespace Rnd
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Animatable()
Construct an animatable with no children, no filters, and a zero frame.
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
Drawable()
Construct a visible drawable with no children.
Surface description a Rnd::Mesh draws with.
Definition mat.h:36
Base of every object the renderer can load, resolve by name, and serialise.
Definition object.h:43
Emitter that spawns, integrates, and draws a population of particles.
Definition particlesys.h:60
float mEmitRateLow
Definition particlesys.h:444
Color mStartColorLow
Definition particlesys.h:459
Particle * AllocParticle()
Take one particle from the pool of the owner and push it onto the live list.
void SetMat(Mat *pMat)
Point the system at a material, moving its reference registration from the old one.
float mSizeHigh
Definition particlesys.h:451
std::vector< Particle > mParticles
Definition particlesys.h:410
virtual void Load(Stream &stream)
Load the system.
void SetForce(const Vector3 &force)
Replace the force every particle accelerates by.
Definition particlesys.h:307
virtual void Copy(const Object *pSource, unsigned nFlags)
Copy another system over this one.
Color mEndColorLow
Definition particlesys.h:463
virtual ~ParticleSys()
ParticleSys(const HxStr &name)
Construct an empty system that owns its own particles.
virtual void Save(Stream &stream)
Serialise the system.
Particle * GetLiveParticles() const
Report the head of the live list.
Definition particlesys.h:294
int mLineLength
Definition particlesys.h:492
Particle * mLiveParticles
Definition particlesys.h:415
Type mMode
Definition particlesys.h:480
Type
Primitive a system draws each particle as.
Definition particlesys.h:70
@ kModeSprite
Definition particlesys.h:73
@ kModePoint
Definition particlesys.h:71
@ kModeLine
Definition particlesys.h:72
Color mStartColorHigh
Definition particlesys.h:461
Vector3 & GetForce()
Report the force every particle accelerates by.
Definition particlesys.h:320
void SetNumParticles(int nCount)
Resize the particle owner's pool, the count the dump labels "numParticles:".
void RandomizeColorAndSize(Particle *pParticle)
Draw a random spawn colour and size for one particle.
void SetParticlesOwner(ParticleSys *pOwner)
Draw the particles of another system, or of this one.
virtual void Replace(Object *pFrom, Object *pTo)
Replace one object reference with another.
float mEmitRateHigh
Definition particlesys.h:446
Mat * mMat
Definition particlesys.h:477
virtual void StartAnim()
Restart the emission and release every live particle.
void FreeAllParticles()
Release every live particle back to the pool of its owner.
virtual const HxStr & ClassName() const
Return the registered class name, "ParticleSys".
int mReadZ
Definition particlesys.h:488
Color mEndColorHigh
Definition particlesys.h:465
virtual void DumpText(Dbg &sink)
Write the system to the engine text sink.
float mSizeLow
Definition particlesys.h:449
virtual void SetFrameSelf(float flFrame)
Advance the emission to a frame.
static constexpr unsigned kCopyShareParticles
Copy() flag that shares the source's particles rather than copying its pool.
Definition particlesys.h:77
Particle * FreeParticle(Particle *pParticle)
Unlink one live particle and push it onto the free list of the owner.
ParticleSys * mParticlesOwner
Definition particlesys.h:402
Byte stream that every renderer object serialises itself through.
Definition stream.h:31
Transformable()
Construct a dirty transformable with identity transforms and no children.
The rendering engine.
Definition animhelper.h:3
ParticleSys * NewParticleSysThroughHook(const HxStr &name)
Build a system through the creator hook, the same shape as Rnd::NewButtonThroughHook().
void RegisterParticleSysClass()
Point g_pfnNewParticleSys at NewParticleSys() and register the "ParticleSys" class.
Definition particlesys.h:564
ParticleSys *(* g_pfnNewParticleSys)(const HxStr &name)
Creator the registered "ParticleSys" class builds through.
Manager TheManager
The renderer's object registry.
ParticleSys * NewParticleSys(const HxStr &name)
Allocate and construct a particle system.
HxStr g_particleSysClassName
Registered class name of Rnd::ParticleSys, the string "ParticleSys".
Object * CreateRegisteredParticleSys(const HxStr &name)
Build a system for the registered "ParticleSys" class.
Linear colour with four float components.
Definition color.h:10
Plane equation, padded to a PlayStation 2 quadword.
Definition plane.h:14
One live particle of a Rnd::ParticleSys.
Definition particle.h:33
Two-component vector, used for texture coordinates.
Definition vector2.h:10
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:12