File: RenderableParticle.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (97 lines) | stat: -rw-r--r-- 2,793 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once

#include "RenderableParticleStage.h"

#include "iparticles.h"
#include "irender.h"

#include "math/AABB.h"
#include "render.h"
#include <map>
#include <sigc++/connection.h>

namespace particles
{

/// Implementation of IRenderableParticle
class RenderableParticle : public IRenderableParticle,
                           public sigc::trackable
{
	// The particle definition containing the stage info
	IParticleDef::Ptr _particleDef;

    // Signal connection from the particle def
    sigc::connection _defConnection;

	typedef std::vector<RenderableParticleStagePtr> RenderableParticleStageList;

	// Particle stages using the same shader get grouped
	struct ParticleStageGroup
	{
		ShaderPtr shader;
		RenderableParticleStageList stages;
	};

	// Each captured shader can have one or more particle stages assigned to it
	typedef std::map<std::string, ParticleStageGroup> ShaderMap;
	ShaderMap _shaderMap;

	// The random number generator, this is used to generate "constant"
	// starting values for each bunch of particles. This enables us
	// to go back in time when rendering the particle stage.
	Rand48 _random;

	// The particle direction, usually set by the emitter entity or the preview
	Vector3 _direction;

	// Holds the bounds of all stages at the current time. Will be updated
	// by calls to getBounds(), otherwise might hold outdated bounds information.
	AABB _bounds;

	// The colour used when "use entity colour" is activated.
	Vector3 _entityColour;

	// The associated rendersystem, needed to get time an shaders
	RenderSystemWeakPtr _renderSystem;

public:
	RenderableParticle(const IParticleDef::Ptr& particleDef);

	~RenderableParticle();

    void clearRenderables();

	// Time is in msecs
	void update(const Matrix4& viewRotation, const Matrix4& localToWorld, IRenderEntity* entity) override;

    void onPreRender(const VolumeTest& volume) override;
    void renderHighlights(IRenderableCollector& collector, const VolumeTest& volume) override;

	void setRenderSystem(const RenderSystemPtr& renderSystem) override;

	std::size_t getHighlightFlags() override
	{
		return Highlight::NoHighlight; // never highlighted
	}

	const IParticleDef::Ptr& getParticleDef() const override;
	void setParticleDef(const IParticleDef::Ptr& def) override;

	void setMainDirection(const Vector3& direction) override;
	void setEntityColour(const Vector3& colour) override;

	// Updates bounds from stages and returns the value
	const AABB& getBounds() override;

private:
	void calculateBounds();

	// Sort stages into groups sharing a material, without capturing the shader yet
	void setupStages();

	// Capture all shaders, if necessary
	void ensureShaders(RenderSystem& renderSystem);
};
typedef std::shared_ptr<RenderableParticle> RenderableParticlePtr;

} // namespace