resonance 1.0.1
Loading...
Searching...
No Matches
generator.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <stddef.h>
5
6#include "math/transform.h"
7#include "os/hxstr.h"
8#include "rnd/animatable.h"
9#include "rnd/drawable.h"
10#include "rnd/transformable.h"
11
12namespace Rnd {
13class Cam;
14class Dbg;
15} // namespace Rnd
16namespace Rnd {
17class Mesh;
18}
19namespace Rnd {
20class MultiMesh;
21}
22namespace Rnd {
23class Object;
24}
25namespace Rnd {
26class ParticleSys;
27}
28namespace Rnd {
29class Stream;
30}
31namespace Rnd {
32class TransAnim;
33}
34namespace Rnd {
35class View;
36}
37namespace Rnd {
38struct Particle;
39}
40
41namespace Rnd {
42
44constexpr int kPathVarAxisCount = 3;
45
96class Generator : public Animatable, public Transformable, public Drawable {
97public:
106 struct Instance {
109 // +0x04 Alignment padding before mXfmMod. The instance dump does not read it.
110 unsigned char mReserved04[0x0c];
113 // +0x50 The uniform scale SetFrameSelf() draws for this instance, written into all three
114 // components. The instance dump reads none of it, so the title is inferred.
116 };
117
128 explicit Generator(const HxStr &name);
129
134 virtual ~Generator();
135
146 virtual void DumpText(Dbg &sink);
147
158 virtual void Save(Stream &stream);
159
168 virtual void Replace(Object *pFrom, Object *pTo);
169
177 virtual const HxStr &ClassName() const;
178
189 virtual void Copy(const Object *pSource, unsigned nFlags);
190
201 virtual void Load(Stream &stream);
202
217
228 std::list<Instance> &Instances();
229
241 static void Init();
242
251 static void *operator new(size_t nSize);
252
260 static void operator delete(void *pBlock);
261
272
284 void SetMesh(Mesh *pMesh);
285
295 void SetView(View *pView);
296
306 void SetMultiMesh(MultiMesh *pMultiMesh);
307
318 void SetParticleSys(ParticleSys *pParticleSys);
319
329 void SetBirthCamera(Cam *pCam);
330
344 void SetPath(TransAnim *pPath, float flStartFrame, float flEndFrame);
345
354 return mPath;
355 }
356
364 float GetPathStartFrame() const {
365 return mPathStartFrame;
366 }
367
375 float GetPathEndFrame() const {
376 return mPathEndFrame;
377 }
378
386 Mesh *GetMesh() const {
387 return mMesh;
388 }
389
397 View *GetView() const {
398 return mView;
399 }
400
409 return mMultiMesh;
410 }
411
420 return mParticleSys;
421 }
422
430 void SetAnimateFromStart(int nAnimateFromStart) {
431 mAnimateFromStart = nAnimateFromStart;
432 }
433
442 return mAnimateFromStart;
443 }
444
452 void SetBirthFrontOnly(int nBirthFrontOnly) {
453 mBirthFrontOnly = nBirthFrontOnly;
454 }
455
463 int GetBirthFrontOnly() const {
464 return mBirthFrontOnly;
465 }
466
474 void SetBirthSquareDistCull(int nCull) {
475 mBirthSquareDistCull = nCull;
476 }
477
486 return mBirthSquareDistCull;
487 }
488
496 void SetBirthSquareDist(float flSquareDist) {
497 mBirthSquareDist = flSquareDist;
498 }
499
507 float GetBirthSquareDist() const {
508 return mBirthSquareDist;
509 }
510
518 Cam *GetBirthCam() const {
519 return mBirthCam;
520 }
521
529 void SetNextSpawnFrame(float flFrame) {
530 mNextSpawnFrame = flFrame;
531 }
532
541 void SetRateGen(float flLow, float flHigh) {
542 mRateGenHigh = flHigh;
543 mRateGenLow = flLow;
544 }
545
554 void GetRateGen(float &flLow, float &flHigh) const {
555 flLow = mRateGenLow;
556 flHigh = mRateGenHigh;
557 }
558
567 void SetScaleGen(float flLow, float flHigh) {
568 mScaleGenHigh = flHigh;
569 mScaleGenLow = flLow;
570 }
571
580 void GetScaleGen(float &flLow, float &flHigh) const {
581 flLow = mScaleGenLow;
582 flHigh = mScaleGenHigh;
583 }
584
594 void SetPathVarMax(float flX, float flY, float flZ) {
595 mPathVarMax[0] = flX;
596 mPathVarMax[1] = flY;
597 mPathVarMax[2] = flZ;
598 }
599
609 void GetGenPathVarMax(float &flX, float &flY, float &flZ) const {
610 flX = mPathVarMax[0];
611 flY = mPathVarMax[1];
612 flZ = mPathVarMax[2];
613 }
614
615protected:
627 virtual int DrawShowing();
628
639 virtual void SetFrameSelf(float flFrame);
640
641private:
650 void ReleaseRefs();
651
660 void AcquireRefs();
661
662 // The four draw paths DrawShowing() selects from the table at 0x0081c448. Each receives the
663 // composed transform of one instance and the age of that instance in frames.
664
672 void DrawInstanceView(const Transform &xfm, float flAge);
673
680 void DrawInstanceMesh(const Transform &xfm, float flAge);
681
689 void DrawInstanceMultiMesh(const Transform &xfm, float flAge);
690
698 void DrawInstanceParticle(const Transform &xfm, float flAge);
699
700 // No class derives from Rnd::Generator and nothing outside it accesses a member directly.
701 // Every member is therefore private. The order below is the recovered offset order.
702
703 std::list<Instance> mInstances; // +0xe4
704 // Path the spawned instances follow. Load() narrows the resolved object to Rnd::TransAnim.
705 TransAnim *mPath; // +0xe8
706 float mPathStartFrame; // +0xec
707 float mPathEndFrame; // +0xf0
708 Mesh *mMesh; // +0xf4
709 View *mView; // +0xf8
710 MultiMesh *mMultiMesh; // +0xfc
711 ParticleSys *mParticleSys; // +0x100
712 int mAnimateFromStart; // +0x104
713
714public:
724
725private:
726 int mBirthFrontOnly; // +0x10c
727 // +0x110 Whether SetFrameSelf() applies the mBirthSquareDist cull. The constructor zeroes it,
728 // and neither the dump nor the serialiser touches it, so the title is inferred.
729 int mBirthSquareDistCull;
730 float mBirthSquareDist; // +0x114
731 Cam *mBirthCam; // +0x118
732 float mRateGenLow; // +0x11c
733 float mRateGenHigh; // +0x120
734 float mScaleGenLow; // +0x124
735 float mScaleGenHigh; // +0x128
736 float mPathVarMax[kPathVarAxisCount]; // +0x12c
737 // Particle of mParticleSys the walk currently stands on. Regenerate() stores the particle it
738 // allocated and SetFrameSelf() advances it through Rnd::Particle::mNext. The dump omits it, so
739 // the title is inferred from those two routines.
740 Particle *mParticleCursor; // +0x138
741 // Entry of the transform list of mMultiMesh the multi-mesh draw path writes next. DrawShowing()
742 // rewinds it to the head of the list, and only the multi-mesh draw path reads it. The title is
743 // inferred.
744 std::list<Transform>::iterator mMultiMeshCursor; // +0x13c
745};
746
760
768
769} // namespace Rnd
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Animatable()
Construct an animatable with no children, no filters, and a zero frame.
Camera.
Definition cam.h:53
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
Drawable()
Construct a visible drawable with no children.
Emitter that spawns copies of one drawable along an animated path.
Definition generator.h:96
void SetBirthCamera(Cam *pCam)
Set the camera the birth culling measures against.
void SetRateGen(float flLow, float flHigh)
Set the bounds of the random spawn interval.
Definition generator.h:541
virtual void Load(Stream &stream)
Read the emitter from stream.
virtual void DumpText(Dbg &sink)
Write the emitter to the engine text sink.
virtual void Copy(const Object *pSource, unsigned nFlags)
Copy another emitter over this one.
float mNextSpawnFrame
Frame the next instance is spawned on.
Definition generator.h:723
float GetBirthSquareDist() const
Report mBirthSquareDist.
Definition generator.h:507
void SetScaleGen(float flLow, float flHigh)
Set the bounds of the random instance scale.
Definition generator.h:567
float GetPathEndFrame() const
Report the path frame an instance ends at.
Definition generator.h:375
void SetPathVarMax(float flX, float flY, float flZ)
Set the largest random rotation about each axis, in degrees.
Definition generator.h:594
ParticleSys * GetParticleSys() const
Report the particle system subject.
Definition generator.h:419
void Regenerate()
Give every live instance a fresh particle from mParticleSys.
Cam * GetBirthCam() const
Report the birth camera.
Definition generator.h:518
virtual void Replace(Object *pFrom, Object *pTo)
Replace one object reference with another.
void SetMultiMesh(MultiMesh *pMultiMesh)
Make a multi-mesh the drawn subject, clearing mMesh, mView, and mParticleSys.
virtual void SetFrameSelf(float flFrame)
Expire and spawn instances for a frame.
float GetPathStartFrame() const
Report the path frame an instance starts at.
Definition generator.h:364
MultiMesh * GetMultiMesh() const
Report the multi-mesh subject.
Definition generator.h:408
void SetAnimateFromStart(int nAnimateFromStart)
Set mAnimateFromStart.
Definition generator.h:430
std::list< Instance > & Instances()
Report the live instance list.
View * GetView() const
Report the view subject.
Definition generator.h:397
int GetBirthSquareDistCull() const
Report mBirthSquareDistCull.
Definition generator.h:485
virtual void Save(Stream &stream)
Write revision 7 of the emitter to stream.
void SetBirthSquareDist(float flSquareDist)
Set mBirthSquareDist.
Definition generator.h:496
int GetAnimateFromStart() const
Report mAnimateFromStart.
Definition generator.h:441
TransAnim * GetPath() const
Report the path.
Definition generator.h:353
void GetRateGen(float &flLow, float &flHigh) const
Report the bounds of the random spawn interval.
Definition generator.h:554
Mesh * GetMesh() const
Report the mesh subject.
Definition generator.h:386
void GetScaleGen(float &flLow, float &flHigh) const
Report the bounds of the random instance scale.
Definition generator.h:580
void SetMesh(Mesh *pMesh)
Make a mesh the drawn subject.
void GetGenPathVarMax(float &flX, float &flY, float &flZ) const
Report the largest random rotation about each axis, in degrees.
Definition generator.h:609
void SetPath(TransAnim *pPath, float flStartFrame, float flEndFrame)
Replace the path and set the frame span the instances travel.
Generator(const HxStr &name)
Construct an emitter with no instances and no subject.
void SetParticleSys(ParticleSys *pParticleSys)
Make a particle system the drawn subject, clearing mMesh, mView, and mMultiMesh.
virtual int DrawShowing()
Draw every live instance.
void SetBirthFrontOnly(int nBirthFrontOnly)
Set mBirthFrontOnly.
Definition generator.h:452
void SetView(View *pView)
Make a view the drawn subject, clearing mMesh, mMultiMesh, and mParticleSys.
void SetBirthSquareDistCull(int nCull)
Set mBirthSquareDistCull.
Definition generator.h:474
virtual ~Generator()
static void Init()
Register the class with Rnd::TheManager under the key "Generator".
virtual const HxStr & ClassName() const
Return the registered class name, "Generator".
int GetBirthFrontOnly() const
Report mBirthFrontOnly.
Definition generator.h:463
void SetNextSpawnFrame(float flFrame)
Set mNextSpawnFrame.
Definition generator.h:529
int NumInstances()
Count the live instances.
Indexed triangle mesh with one material.
Definition mesh.h:46
Draws one mesh many times, once per recorded instance transform.
Definition multimesh.h:39
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
Byte stream that every renderer object serialises itself through.
Definition stream.h:31
Animation that drives one transformable from three keyframe channels.
Definition transanim.h:49
Transformable()
Construct a dirty transformable with identity transforms and no children.
Root of a loadable scene.
Definition view.h:47
The rendering engine.
Definition animhelper.h:3
constexpr int kPathVarAxisCount
Number of axes the random path variation covers.
Definition generator.h:44
Generator * NewGenerator(const HxStr &name)
Allocate and construct an emitter.
HxStr g_generatorClassName
Registered class name of Rnd::Generator, the string "Generator".
One live instance.
Definition generator.h:106
Vector3 mScale
Definition generator.h:115
Transform mXfmMod
Rotation and translation the instance is drawn with.
Definition generator.h:112
float mFrameOrg
Frame this instance was spawned on.
Definition generator.h:108
unsigned char mReserved04[0x0c]
Definition generator.h:110
One live particle of a Rnd::ParticleSys.
Definition particle.h:33
Affine transform stored as three basis rows and a translation row.
Definition transform.h:14
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:12