about summary refs log tree commit diff
path: root/src/game/client/components/particles.hpp
blob: 6c466d9419066aadcf19334676b8cdd1c6f08aad (plain)
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
#include <base/vmath.hpp>
#include <game/client/component.hpp>

// particles
struct PARTICLE
{
	void set_default()
	{
		vel = vec2(0,0);
		life_span = 0;
		start_size = 32;
		end_size = 32;
		rot = 0;
		rotspeed = 0;
		gravity = 0;
		friction = 0;
		flow_affected = 1.0f;
		color = vec4(1,1,1,1);
	}
	
	vec2 pos;
	vec2 vel;

	int spr;

	float flow_affected;

	float life_span;
	
	float start_size;
	float end_size;

	float rot;
	float rotspeed;

	float gravity;
	float friction;

	vec4 color;
	
	// set by the particle system
	float life;
	int prev_part;
	int next_part;
};

class PARTICLES : public COMPONENT
{
	friend class GAMECLIENT;
public:
	enum
	{
		GROUP_PROJECTILE_TRAIL=0,
		GROUP_EXPLOSIONS,
		GROUP_GENERAL,
		NUM_GROUPS
	};

	PARTICLES();
	
	void add(int group, PARTICLE *part);
	
	virtual void on_reset();
	virtual void on_render();

private:
	
	enum
	{
		MAX_PARTICLES=1024*8,
	};

	PARTICLE particles[MAX_PARTICLES];
	int first_free;
	int first_part[NUM_GROUPS];
	
	void render_group(int group);
	void update(float time_passed);

	template<int TGROUP>
	class RENDER_GROUP : public COMPONENT
	{
	public:
		PARTICLES *parts;
		virtual void on_render() { parts->render_group(TGROUP); }
	};
	
	RENDER_GROUP<GROUP_PROJECTILE_TRAIL> render_trail;
	RENDER_GROUP<GROUP_EXPLOSIONS> render_explosions;
	RENDER_GROUP<GROUP_GENERAL> render_general;
};