]> git.lizzy.rs Git - minetest.git/blob - src/particles.h
Add particle animation, glow
[minetest.git] / src / particles.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef PARTICLES_HEADER
21 #define PARTICLES_HEADER
22
23 #define DIGGING_PARTICLES_AMOUNT 10
24
25 #include <iostream>
26 #include "irrlichttypes_extrabloated.h"
27 #include "client/tile.h"
28 #include "localplayer.h"
29 #include "environment.h"
30 #include "tileanimation.h"
31
32 struct ClientEvent;
33 class ParticleManager;
34 class ClientEnvironment;
35
36 class Particle : public scene::ISceneNode
37 {
38         public:
39         Particle(
40                 IGameDef* gamedef,
41                 scene::ISceneManager* mgr,
42                 LocalPlayer *player,
43                 ClientEnvironment *env,
44                 v3f pos,
45                 v3f velocity,
46                 v3f acceleration,
47                 float expirationtime,
48                 float size,
49                 bool collisiondetection,
50                 bool collision_removal,
51                 bool vertical,
52                 video::ITexture *texture,
53                 v2f texpos,
54                 v2f texsize,
55                 const struct TileAnimationParams &anim,
56                 u8 glow
57         );
58         ~Particle();
59
60         virtual const aabb3f &getBoundingBox() const
61         {
62                 return m_box;
63         }
64
65         virtual u32 getMaterialCount() const
66         {
67                 return 1;
68         }
69
70         virtual video::SMaterial& getMaterial(u32 i)
71         {
72                 return m_material;
73         }
74
75         virtual void OnRegisterSceneNode();
76         virtual void render();
77
78         void step(float dtime);
79
80         bool get_expired ()
81         { return m_expiration < m_time; }
82
83 private:
84         void updateLight();
85         void updateVertices();
86
87         video::S3DVertex m_vertices[4];
88         float m_time;
89         float m_expiration;
90
91         ClientEnvironment *m_env;
92         IGameDef *m_gamedef;
93         aabb3f m_box;
94         aabb3f m_collisionbox;
95         video::SMaterial m_material;
96         v2f m_texpos;
97         v2f m_texsize;
98         v3f m_pos;
99         v3f m_velocity;
100         v3f m_acceleration;
101         LocalPlayer *m_player;
102         float m_size;
103         u8 m_light;
104         bool m_collisiondetection;
105         bool m_collision_removal;
106         bool m_vertical;
107         v3s16 m_camera_offset;
108         struct TileAnimationParams m_animation;
109         float m_animation_time;
110         int m_animation_frame;
111         u8 m_glow;
112 };
113
114 class ParticleSpawner
115 {
116         public:
117         ParticleSpawner(IGameDef* gamedef,
118                 scene::ISceneManager *smgr,
119                 LocalPlayer *player,
120                 u16 amount,
121                 float time,
122                 v3f minp, v3f maxp,
123                 v3f minvel, v3f maxvel,
124                 v3f minacc, v3f maxacc,
125                 float minexptime, float maxexptime,
126                 float minsize, float maxsize,
127                 bool collisiondetection,
128                 bool collision_removal,
129                 u16 attached_id,
130                 bool vertical,
131                 video::ITexture *texture,
132                 u32 id,
133                 const struct TileAnimationParams &anim, u8 glow,
134                 ParticleManager* p_manager);
135
136         ~ParticleSpawner();
137
138         void step(float dtime, ClientEnvironment *env);
139
140         bool get_expired ()
141         { return (m_amount <= 0) && m_spawntime != 0; }
142
143         private:
144         ParticleManager* m_particlemanager;
145         float m_time;
146         IGameDef *m_gamedef;
147         scene::ISceneManager *m_smgr;
148         LocalPlayer *m_player;
149         u16 m_amount;
150         float m_spawntime;
151         v3f m_minpos;
152         v3f m_maxpos;
153         v3f m_minvel;
154         v3f m_maxvel;
155         v3f m_minacc;
156         v3f m_maxacc;
157         float m_minexptime;
158         float m_maxexptime;
159         float m_minsize;
160         float m_maxsize;
161         video::ITexture *m_texture;
162         std::vector<float> m_spawntimes;
163         bool m_collisiondetection;
164         bool m_collision_removal;
165         bool m_vertical;
166         u16 m_attached_id;
167         struct TileAnimationParams m_animation;
168         u8 m_glow;
169 };
170
171 /**
172  * Class doing particle as well as their spawners handling
173  */
174 class ParticleManager
175 {
176 friend class ParticleSpawner;
177 public:
178         ParticleManager(ClientEnvironment* env);
179         ~ParticleManager();
180
181         void step (float dtime);
182
183         void handleParticleEvent(ClientEvent *event, Client *client,
184                         scene::ISceneManager* smgr, LocalPlayer *player);
185
186         void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
187                 LocalPlayer *player, v3s16 pos, const TileSpec tiles[]);
188
189         void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
190                 LocalPlayer *player, v3s16 pos, const TileSpec tiles[]);
191
192         void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
193                 LocalPlayer *player, v3s16 pos, const TileSpec tiles[]);
194
195 protected:
196         void addParticle(Particle* toadd);
197
198 private:
199
200         void stepParticles (float dtime);
201         void stepSpawners (float dtime);
202
203         void clearAll ();
204
205         std::vector<Particle*> m_particles;
206         std::map<u32, ParticleSpawner*> m_particle_spawners;
207
208         ClientEnvironment* m_env;
209         Mutex m_particle_list_lock;
210         Mutex m_spawner_list_lock;
211 };
212
213 #endif