wavelength 1.0.0
Loading...
Searching...
No Matches
rndparticlesys.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <list>
5#include <memory>
6
7#include "math/color.h"
8#include "math/plane.h"
9#include "math/vector2.h"
10#include "math/vector3.h"
11#include "os/binstream.h"
12#include "os/mem.h"
13#include "os/prnstream.h"
14#include "rnd/rndanimatable.h"
15#include "rnd/rnddrawable.h"
16#include "rnd/rndmat.h"
18
27struct Particle {
34 void *operator new[](size_t nSize) {
35 return PoolMemAlloc(static_cast<int>(nSize), "Particle", 0);
36 }
37
43 void operator delete[](void *pBlock) {
44 PoolMemFree(pBlock);
45 }
46
54 float mSize;
59};
60
70public:
72 enum Mode {
76 };
77
79 static constexpr int kCopyShareParticles = 0x400;
80
90 explicit RndParticleSys(const char *pszName);
91
98 ~RndParticleSys() override;
99
106 void *operator new(size_t nSize) {
107 return PoolMemAlloc(static_cast<int>(nSize), "ParticleSys", 0);
108 }
109
115 void operator delete(void *pBlock) {
116 PoolMemFree(pBlock);
117 }
118
130 int SetFrameSelf(float fFrame) override;
131
140 void ListDrawObjects(std::list<RndObject *> &objects) override;
141
150 void ListDrawables(std::list<RndDrawable *> &drawables) override;
151
161 void DumpText(PrnStream &stream) override;
162
172 void Save(BinStream &stream) override;
173
184 void Replace(RndObject *pFrom, RndObject *pTo) override;
185
193 const char *ClassName() const override {
194 return sClassName;
195 }
196
208 void Copy(const RndObject *pSource, int nFlags) override;
209
217 void Load(BinStream &stream) override;
218
226 void SetNumParticles(int nCount);
227
236
244 void SetMat(RndMat *pMat);
245
253 int NumLiveParticles() const;
254
263
275
283
294 void SetEmitFrame(float fFrame);
295
305
316 void SpawnParticles(float fDelta);
317
326
337 void UpdateParticles(float fDelta);
338
347 static RndObject *New(const char *pszName) {
348 return new RndParticleSys(pszName);
349 }
350
357 static const char *sClassName;
358
364 static int sRev;
365
371 static int sLoadRev;
372
375 return mParticles.get();
376 }
377
378 std::unique_ptr<Particle[]> mParticles;
379
381 int GetBubble() const {
382 return mBubble;
383 }
384
386 void SetBubble(int nBubble) {
387 mBubble = nBubble;
388 }
389
391 const Vector2 &GetBubblePeriod() const {
392 return mBubblePeriod;
393 }
394
396 void SetBubblePeriod(const Vector2 &range) {
397 mBubblePeriod = range;
398 }
399
401 const Vector2 &GetBubbleSize() const {
402 return mBubbleSize;
403 }
404
407 return mBubbleSize;
408 }
409
411 void SetBubbleSize(const Vector2 &range) {
412 mBubbleSize = range;
413 }
414
416 int GetCollide() const {
417 return mCollide;
418 }
419
421 void SetCollide(int nCollide) {
422 mCollide = nCollide;
423 }
424
426 const Plane &GetCollidePlane() const {
427 return mCollidePlane;
428 }
429
431 void SetCollidePlane(const Plane &plane) {
432 mCollidePlane = plane;
433 }
434
436 const Vector2 &GetEmitRate() const {
437 return mEmitRate;
438 }
439
442 return mEmitRate;
443 }
444
446 const Color &GetEndColorHigh() const {
447 return mEndColorHigh;
448 }
449
452 return mEndColorHigh;
453 }
454
456 void SetEndColorHigh(const Color &color) {
457 mEndColorHigh = color;
458 }
459
461 const Color &GetEndColorLow() const {
462 return mEndColorLow;
463 }
464
467 return mEndColorLow;
468 }
469
471 void SetEndColorLow(const Color &color) {
472 mEndColorLow = color;
473 }
474
476 const Vector3 &GetForce() const {
477 return mForce;
478 }
479
482 return mForce;
483 }
484
486 void SetForce(const Vector3 &force) {
487 mForce = force;
488 }
489
491 const Vector2 &GetLife() const {
492 return mLife;
493 }
494
497 return mLife;
498 }
499
501 void SetLife(const Vector2 &range) {
502 mLife = range;
503 }
504
507 return mLiveParticles;
508 }
509
511 Mode GetMode() const {
512 return mMode;
513 }
514
516 void SetMode(Mode pMode) {
517 mMode = pMode;
518 }
519
521 int GetNumParticles() const {
522 return mNumParticles;
523 }
524
527 return mParticlesOwner;
528 }
529
531 const Vector2 &GetPitch() const {
532 return mPitch;
533 }
534
536 void SetPitch(const Vector2 &range) {
537 mPitch = range;
538 }
539
541 const Vector3 &GetPosHigh() const {
542 return mPosHigh;
543 }
544
547 return mPosHigh;
548 }
549
551 void SetPosHigh(const Vector3 &pos) {
552 mPosHigh = pos;
553 }
554
556 const Vector3 &GetPosLow() const {
557 return mPosLow;
558 }
559
562 return mPosLow;
563 }
564
566 void SetPosLow(const Vector3 &pos) {
567 mPosLow = pos;
568 }
569
571 int GetReadZ() const {
572 return mReadZ;
573 }
574
576 void SetReadZ(int nReadZ) {
577 mReadZ = nReadZ;
578 }
579
581 const Vector2 &GetSize() const {
582 return mSize;
583 }
584
587 return mSize;
588 }
589
591 const Vector2 &GetSpeed() const {
592 return mSpeed;
593 }
594
597 return mSpeed;
598 }
599
601 void SetSpeed(const Vector2 &range) {
602 mSpeed = range;
603 }
604
606 const Color &GetStartColorHigh() const {
607 return mStartColorHigh;
608 }
609
612 return mStartColorHigh;
613 }
614
616 void SetStartColorHigh(const Color &color) {
617 mStartColorHigh = color;
618 }
619
621 const Color &GetStartColorLow() const {
622 return mStartColorLow;
623 }
624
627 return mStartColorLow;
628 }
629
631 void SetStartColorLow(const Color &color) {
632 mStartColorLow = color;
633 }
634
636 const Vector2 &GetYaw() const {
637 return mYaw;
638 }
639
641 void SetYaw(const Vector2 &range) {
642 mYaw = range;
643 }
644
645protected:
656
667
671 int mReadZ;
672
673private:
674 RndParticleSys *mParticlesOwner;
675 int mNumParticles;
676 Particle *mFreeParticles;
677 float mLastFrame;
678 float mLastEmitFrame;
679 float mEmitAccumulator;
680 std::list<RndParticleSys *> mSharers;
681 Vector2 mBubblePeriod;
682 Vector2 mBubbleSize;
683 Vector2 mLife;
684 Vector3 mPosLow;
685 Vector3 mPosHigh;
686 Vector2 mSpeed;
687 Vector2 mPitch;
688 Vector2 mYaw;
689 Vector2 mEmitRate;
690 Vector2 mSize;
691 Color mStartColorLow;
692 Color mStartColorHigh;
693 Color mEndColorLow;
694 Color mEndColorHigh;
695 int mCollide;
696 Plane mCollidePlane;
697 Vector3 mForce;
698 int mBubble;
699 float mLineLength;
700};
701
711PrnStream &operator<<(PrnStream &stream, const Particle &particle);
712
725
735BinStream &operator>>(BinStream &stream, std::list<Plane> &planes);
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
RndDrawable()
Construct a showing drawable without a highlight or children.
Definition rnddrawable.h:23
Surface description: blending, lighting colours, culling, and a list of texture stages.
Definition rndmat.h:20
RndObject(const char *pszName)
Construct an object and register it under a name.
Vector3 & GetForce()
Definition rndparticlesys.h:481
void SetMat(RndMat *pMat)
Set the material the particles are drawn with.
void SetBubbleSize(const Vector2 &range)
Definition rndparticlesys.h:411
Vector2 & GetSize()
Definition rndparticlesys.h:586
Particle * mLiveParticles
Definition rndparticlesys.h:668
int GetBubble() const
Definition rndparticlesys.h:381
void SetStartColorHigh(const Color &color)
Definition rndparticlesys.h:616
void DumpText(PrnStream &stream) override
Write a description of the system and its bases.
const Color & GetEndColorHigh() const
Definition rndparticlesys.h:446
void ResetEmitFrame()
Return the emission clock to SetFrameSelf().
const Vector2 & GetBubblePeriod() const
Definition rndparticlesys.h:391
static int sLoadRev
The version Load() read last.
Definition rndparticlesys.h:371
Vector3 & GetPosLow()
Definition rndparticlesys.h:561
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it.
const Vector3 & GetPosLow() const
Definition rndparticlesys.h:556
const Vector3 & GetPosHigh() const
Definition rndparticlesys.h:541
Vector2 & GetBubbleSize()
Definition rndparticlesys.h:406
Mode GetMode() const
Definition rndparticlesys.h:511
std::unique_ptr< Particle[]> mParticles
Definition rndparticlesys.h:378
void SetPitch(const Vector2 &range)
Definition rndparticlesys.h:536
const Plane & GetCollidePlane() const
Definition rndparticlesys.h:426
const Vector3 & GetForce() const
Definition rndparticlesys.h:476
int GetCollide() const
Definition rndparticlesys.h:416
void SetStartColorLow(const Color &color)
Definition rndparticlesys.h:631
const Vector2 & GetSize() const
Definition rndparticlesys.h:581
~RndParticleSys() override
Free the particles and the pool.
void ListDrawObjects(std::list< RndObject * > &objects) override
Add the system, the material, and the textures of the material's stages, last first,...
const Color & GetEndColorLow() const
Definition rndparticlesys.h:461
Mode mMode
Definition rndparticlesys.h:670
void SetBubblePeriod(const Vector2 &range)
Definition rndparticlesys.h:396
void SetBubble(int nBubble)
Definition rndparticlesys.h:386
Vector2 & GetSpeed()
Definition rndparticlesys.h:596
void SetParticlesOwner(RndParticleSys *pOwner)
Set the system whose pool this one draws from.
void SetEndColorHigh(const Color &color)
Definition rndparticlesys.h:456
int mReadZ
Definition rndparticlesys.h:671
void SetReadZ(int nReadZ)
Definition rndparticlesys.h:576
Color & GetStartColorLow()
Definition rndparticlesys.h:626
int SetFrameSelf(float fFrame) override
Move the particles on to a frame, then emit for the elapsed frames unless SetEmitFrame() clocks the e...
const char * ClassName() const override
Report the class name.
Definition rndparticlesys.h:193
void SetSpeed(const Vector2 &range)
Definition rndparticlesys.h:601
RndMat * mMat
Definition rndparticlesys.h:669
const Color & GetStartColorLow() const
Definition rndparticlesys.h:621
void SetPosHigh(const Vector3 &pos)
Definition rndparticlesys.h:551
int NumLiveParticles() const
Report the number of live particles.
Color & GetEndColorLow()
Definition rndparticlesys.h:466
static constexpr int kCopyShareParticles
The bit of the Copy() flags that shares the source's pool rather than allocating one.
Definition rndparticlesys.h:79
void AddObjectRefs()
Take the references on the material and the owner, and prepare the pool.
void RandomizeColorAndSize(Particle *pParticle)
Give a particle a colour and a size from the start ranges.
const Color & GetStartColorHigh() const
Definition rndparticlesys.h:606
const Vector2 & GetLife() const
Definition rndparticlesys.h:491
int GetReadZ() const
Definition rndparticlesys.h:571
Color & GetEndColorHigh()
Definition rndparticlesys.h:451
void SetCollidePlane(const Plane &plane)
Definition rndparticlesys.h:431
Mode
The primitive each particle is drawn as.
Definition rndparticlesys.h:72
@ kModeSprite
Definition rndparticlesys.h:75
@ kModeLine
Definition rndparticlesys.h:74
@ kModePoint
Definition rndparticlesys.h:73
const Vector2 & GetYaw() const
Definition rndparticlesys.h:636
static const char * sClassName
The class name a .rnd file writes, ParticleSys.
Definition rndparticlesys.h:357
Color & GetStartColorHigh()
Definition rndparticlesys.h:611
const Vector2 & GetBubbleSize() const
Definition rndparticlesys.h:401
void Copy(const RndObject *pSource, int nFlags) override
Copy another system and its bases.
Particle * GetLiveParticles() const
Definition rndparticlesys.h:506
RndParticleSys(const char *pszName)
Construct a system with a pool of 10 particles.
RndParticleSys * GetParticlesOwner() const
Definition rndparticlesys.h:526
const Vector2 & GetPitch() const
Definition rndparticlesys.h:531
void Replace(RndObject *pFrom, RndObject *pTo) override
Replace a referenced object with another in the bases, the material, and the pool owner.
static int sRev
The format version Save() writes and Load() accepts.
Definition rndparticlesys.h:364
Particle * GetParticles() const
Definition rndparticlesys.h:374
void SetCollide(int nCollide)
Definition rndparticlesys.h:421
void RemoveObjectRefs()
Drop the references on the material and the owner, free the live particles, and withdraw from the sha...
Particle * AllocParticle()
Move a particle from the free list of the owner to the head of the live list.
void SetLife(const Vector2 &range)
Definition rndparticlesys.h:501
void FreeAllParticles()
Free every live particle.
int GetNumParticles() const
Definition rndparticlesys.h:521
static RndObject * New(const char *pszName)
Create a system.
Definition rndparticlesys.h:347
void Save(BinStream &stream) override
Write the system and its bases.
void SetNumParticles(int nCount)
Set the pool size, then reallocate the pool of the owner.
void SetPosLow(const Vector3 &pos)
Definition rndparticlesys.h:566
Vector2 & GetEmitRate()
Definition rndparticlesys.h:441
Vector3 & GetPosHigh()
Definition rndparticlesys.h:546
const Vector2 & GetSpeed() const
Definition rndparticlesys.h:591
void SpawnParticles(float fDelta)
Emit the particles the emission rate owes for a number of frames.
void SetEmitFrame(float fFrame)
Emit for the frames since the previous call, and clock the emission from then on in place of SetFrame...
Vector2 & GetLife()
Definition rndparticlesys.h:496
void UpdateParticles(float fDelta)
Free the particles outside their lives, and move and fade the others over a number of frames.
void SetYaw(const Vector2 &range)
Definition rndparticlesys.h:641
const Vector2 & GetEmitRate() const
Definition rndparticlesys.h:436
void SetEndColorLow(const Color &color)
Definition rndparticlesys.h:471
Particle * FreeParticle(Particle *pParticle)
Move a live particle to the free list of the owner.
void SetForce(const Vector3 &force)
Definition rndparticlesys.h:486
void ListDrawables(std::list< RndDrawable * > &drawables) override
Add the system, when a live particle is inside the view volume of the current camera,...
void SetMode(Mode pMode)
Definition rndparticlesys.h:516
RndTransformable()
Construct a transformable with identity transforms, no origin offset, and no billboard.
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.
BinStream & operator>>(BinStream &stream, std::list< Plane > &planes)
Read a list of planes, each as a point on it followed by its normal.
PrnStream & operator<<(PrnStream &stream, const Particle &particle)
Write a particle's position, velocity, colours, size, and life.
Linear colour with four float components.
Definition color.h:12
One particle of a RndParticleSys pool.
Definition rndparticlesys.h:27
float mDeathFrame
Definition rndparticlesys.h:55
Vector3 mVel
Definition rndparticlesys.h:50
float mSize
Definition rndparticlesys.h:54
float mBubblePhase
Definition rndparticlesys.h:53
float mBirthFrame
Definition rndparticlesys.h:56
Particle * mPrev
Definition rndparticlesys.h:57
Vector3 mPos
Definition rndparticlesys.h:49
Particle * mNext
Definition rndparticlesys.h:58
Color mColVel
Definition rndparticlesys.h:48
float mBubbleFrequency
Definition rndparticlesys.h:52
Vector3 mBubbleSize
Definition rndparticlesys.h:51
Color mCol
Definition rndparticlesys.h:47
Plane equation, padded to a PlayStation 2 quadword.
Definition plane.h:15
Two-component vector, used for texture coordinates.
Definition vector2.h:12
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:14