wavelength 1.0.0
Loading...
Searching...
No Matches
rndgenerator.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <list>
5
6#include "math/transform.h"
7#include "math/vector3.h"
8#include "os/binstream.h"
9#include "os/mem.h"
10#include "os/prnstream.h"
11#include "rnd/rndanimatable.h"
12#include "rnd/rndcam.h"
13#include "rnd/rnddrawable.h"
14#include "rnd/rndmesh.h"
15#include "rnd/rndmultimesh.h"
16#include "rnd/rndparticlesys.h"
17#include "rnd/rndtransanim.h"
19#include "rnd/rndview.h"
20
31public:
38
40 typedef void (RndGenerator::*DrawInstanceFunc)(float fAge, const Transform &xfm);
41
49 explicit RndGenerator(const char *pszName);
50
57 ~RndGenerator() override;
58
65 void *operator new(size_t nSize) {
66 return PoolMemAlloc(static_cast<int>(nSize), "Generator", 0);
67 }
68
74 void operator delete(void *pBlock) {
75 PoolMemFree(pBlock);
76 }
77
89 int SetFrameSelf(float fFrame) override;
90
98 void ListDrawObjects(std::list<RndObject *> &objects) override;
99
110 void ListDrawables(std::list<RndDrawable *> &drawables) override;
111
122 int DrawShowing() override;
123
133 void DumpText(PrnStream &stream) override;
134
142 void Save(BinStream &stream) override;
143
152 void Replace(RndObject *pFrom, RndObject *pTo) override;
153
161 const char *ClassName() const override {
162 return sClassName;
163 }
164
173 void Copy(const RndObject *pSource, int nFlags) override;
174
182 void Load(BinStream &stream) override;
183
193
204
214
226 void SetPath(RndTransAnim *pPath, float fStart, float fEnd);
227
238 void Generate(float fFrame);
239
251 void DrawView(float fAge, const Transform &xfm);
252
263 void DrawMesh(float fAge, const Transform &xfm);
264
275 void SetMultiMeshXfm(float fAge, const Transform &xfm);
276
287 void SetParticlePos(float fAge, const Transform &xfm);
288
297 static RndObject *New(const char *pszName) {
298 return new RndGenerator(pszName);
299 }
300
307 static const char *sClassName;
308
314 static int sRev;
315
317 const float *GetPathVarMax() const {
318 return mPathVarMax;
319 }
320
327 void SetPathVarMax(int nIndex, float fDegrees) {
328 mPathVarMax[nIndex] = fDegrees;
329 }
330
332 float GetRateGenHigh() const {
333 return mRateGenHigh;
334 }
335
337 void SetRateGenHigh(float fRateGenHigh) {
338 mRateGenHigh = fRateGenHigh;
339 }
340
342 float GetRateGenLow() const {
343 return mRateGenLow;
344 }
345
347 void SetRateGenLow(float fRateGenLow) {
348 mRateGenLow = fRateGenLow;
349 }
350
352 float GetScaleGenHigh() const {
353 return mScaleGenHigh;
354 }
355
357 void SetScaleGenHigh(float fScaleGenHigh) {
358 mScaleGenHigh = fScaleGenHigh;
359 }
360
362 float GetScaleGenLow() const {
363 return mScaleGenLow;
364 }
365
367 void SetScaleGenLow(float fScaleGenLow) {
368 mScaleGenLow = fScaleGenLow;
369 }
370
371private:
372 // Build the transform of an instance from the path at its age, its scale, and its birth
373 // transform, and report the age. The binary inlines the routine in ListDrawables() and
374 // DrawShowing().
375 inline float InstanceXfm(const Instance &instance, float fDirection, Transform &xfm);
376
377 std::list<Instance> mInstances;
378 RndTransAnim *mPath;
379 float mPathStartFrame;
380 float mPathEndFrame;
381 RndMesh *mMesh;
382 RndView *mView;
383 RndMultiMesh *mMultiMesh;
384 RndParticleSys *mParticleSys;
385 int mAnimateFromStart;
386 float mNextFrame;
387 int mBirthFrontOnly;
388 int mBirthCheckDist;
389 float mBirthSquareDist;
390 RndCam *mBirthCam;
391 float mRateGenLow;
392 float mRateGenHigh;
393 float mScaleGenLow;
394 float mScaleGenHigh;
395 float mPathVarMax[3];
396 Particle *mCurParticle;
397 std::list<Transform>::iterator mCurXfm;
398};
399
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Text output stream.
Definition prnstream.h:16
RndAnimatable()
Construct an animatable at frame 0 without children or filters.
Definition rndanimatable.h:600
Camera.
Definition rndcam.h:23
RndDrawable()
Construct a showing drawable without a highlight or children.
Definition rnddrawable.h:23
void Copy(const RndObject *pSource, int nFlags) override
Copy another generator and its bases.
const float * GetPathVarMax() const
Definition rndgenerator.h:317
static RndObject * New(const char *pszName)
Create a generator.
Definition rndgenerator.h:297
void(RndGenerator::* DrawInstanceFunc)(float fAge, const Transform &xfm)
A routine that draws or places one instance's subject at a transform.
Definition rndgenerator.h:40
void SetScaleGenHigh(float fScaleGenHigh)
Definition rndgenerator.h:357
void SetPathVarMax(int nIndex, float fDegrees)
Set one entry of the most rotation about each axis, in degrees.
Definition rndgenerator.h:327
void Save(BinStream &stream) override
Write the generator and its bases.
void SetScaleGenLow(float fScaleGenLow)
Definition rndgenerator.h:367
void DrawView(float fAge, const Transform &xfm)
Move the view to a transform, animate it to an age when mAnimateFromStart is set, and draw it.
void ListDrawables(std::list< RndDrawable * > &drawables) override
Add the generator, when a subject of an instance would draw, then the children, to a list.
void Replace(RndObject *pFrom, RndObject *pTo) override
Replace a referenced object with another in the bases and the subjects.
RndGenerator(const char *pszName)
Construct a generator without a path or a subject that generates every 100 frames.
void SetRateGenLow(float fRateGenLow)
Definition rndgenerator.h:347
float GetScaleGenHigh() const
Definition rndgenerator.h:352
float GetRateGenHigh() const
Definition rndgenerator.h:332
static const char * sClassName
The class name a .rnd file writes, Generator.
Definition rndgenerator.h:307
void ListDrawObjects(std::list< RndObject * > &objects) override
Add the generator and the objects of the subjects to a list.
void AcquireRefs()
Take the references on the subjects, the path, and the birth camera, then give each instance a partic...
const char * ClassName() const override
Report the class name.
Definition rndgenerator.h:161
int DrawShowing() override
Draw the subject at each instance.
void SetPath(RndTransAnim *pPath, float fStart, float fEnd)
Set the path and the frames of it the instances play.
void DumpText(PrnStream &stream) override
Write a description of the generator and its bases.
float GetScaleGenLow() const
Definition rndgenerator.h:362
float GetRateGenLow() const
Definition rndgenerator.h:342
void Generate(float fFrame)
Add an instance born at a frame, unless the birth camera rules it out.
void ResetParticles()
Free the particles of the particle system, then allocate one for each instance.
void SetParticlePos(float fAge, const Transform &xfm)
Move the next particle to the position of a transform.
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it.
static int sRev
The format version Save() writes and Load() accepts.
Definition rndgenerator.h:314
int SetFrameSelf(float fFrame) override
Drop the instances whose path has run out, animate the view, and generate the instances due by a fram...
void ReleaseRefs()
Drop the references on the subjects, the path, and the birth camera, and the instances.
~RndGenerator() override
Drop the references and the instances.
void SetMultiMeshXfm(float fAge, const Transform &xfm)
Store a transform in the next transform of the multimesh.
void SetRateGenHigh(float fRateGenHigh)
Definition rndgenerator.h:337
void DrawMesh(float fAge, const Transform &xfm)
Move the mesh to a transform and draw it.
Triangle mesh with a material.
Definition rndmesh.h:31
Mesh drawn once at each of a list of transforms.
Definition rndmultimesh.h:17
RndObject(const char *pszName)
Construct an object and register it under a name.
Emitter that spawns, moves, and fades a population of particles.
Definition rndparticlesys.h:69
Animation of a transformable's local transform by rotation, translation, and scale keys.
Definition rndtransanim.h:20
RndTransformable()
Construct a transformable with identity transforms, no origin offset, and no billboard.
View that shows the children of another view, its children owner, under its own transform and frame.
Definition rndview.h:27
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.
PrnStream & operator<<(PrnStream &stream, const RndGenerator::Instance &instance)
Write an instance's birth frame and transform.
One particle of a RndParticleSys pool.
Definition rndparticlesys.h:27
One generated instance.
Definition rndgenerator.h:33
Transform mXfm
Definition rndgenerator.h:35
float mFrame
Definition rndgenerator.h:34
Vector3 mScale
Definition rndgenerator.h:36
Affine transform stored as three basis rows and a translation row.
Definition transform.h:18
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:14