]> git.lizzy.rs Git - dragonfireclient.git/blob - src/particles.h
Pass clang-format on various cpp/header files (#5559)
[dragonfireclient.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 struct MapNode;
36 struct ContentFeatures;
37
38 class Particle : public scene::ISceneNode
39 {
40         public:
41         Particle(
42                 IGameDef* gamedef,
43                 scene::ISceneManager* mgr,
44                 LocalPlayer *player,
45                 ClientEnvironment *env,
46                 v3f pos,
47                 v3f velocity,
48                 v3f acceleration,
49                 float expirationtime,
50                 float size,
51                 bool collisiondetection,
52                 bool collision_removal,
53                 bool vertical,
54                 video::ITexture *texture,
55                 v2f texpos,
56                 v2f texsize,
57                 const struct TileAnimationParams &anim,
58                 u8 glow,
59                 video::SColor color = video::SColor(0xFFFFFFFF)
60         );
61         ~Particle();
62
63         virtual const aabb3f &getBoundingBox() const
64         {
65                 return m_box;
66         }
67
68         virtual u32 getMaterialCount() const
69         {
70                 return 1;
71         }
72
73         virtual video::SMaterial& getMaterial(u32 i)
74         {
75                 return m_material;
76         }
77
78         virtual void OnRegisterSceneNode();
79         virtual void render();
80
81         void step(float dtime);
82
83         bool get_expired ()
84         { return m_expiration < m_time; }
85
86 private:
87         void updateLight();
88         void updateVertices();
89
90         video::S3DVertex m_vertices[4];
91         float m_time;
92         float m_expiration;
93
94         ClientEnvironment *m_env;
95         IGameDef *m_gamedef;
96         aabb3f m_box;
97         aabb3f m_collisionbox;
98         video::SMaterial m_material;
99         v2f m_texpos;
100         v2f m_texsize;
101         v3f m_pos;
102         v3f m_velocity;
103         v3f m_acceleration;
104         LocalPlayer *m_player;
105         float m_size;
106         //! Color without lighting
107         video::SColor m_base_color;
108         //! Final rendered color
109         video::SColor m_color;
110         bool m_collisiondetection;
111         bool m_collision_removal;
112         bool m_vertical;
113         v3s16 m_camera_offset;
114         struct TileAnimationParams m_animation;
115         float m_animation_time;
116         int m_animation_frame;
117         u8 m_glow;
118 };
119
120 class ParticleSpawner
121 {
122         public:
123         ParticleSpawner(IGameDef* gamedef,
124                 scene::ISceneManager *smgr,
125                 LocalPlayer *player,
126                 u16 amount,
127                 float time,
128                 v3f minp, v3f maxp,
129                 v3f minvel, v3f maxvel,
130                 v3f minacc, v3f maxacc,
131                 float minexptime, float maxexptime,
132                 float minsize, float maxsize,
133                 bool collisiondetection,
134                 bool collision_removal,
135                 u16 attached_id,
136                 bool vertical,
137                 video::ITexture *texture,
138                 u32 id,
139                 const struct TileAnimationParams &anim, u8 glow,
140                 ParticleManager* p_manager);
141
142         ~ParticleSpawner();
143
144         void step(float dtime, ClientEnvironment *env);
145
146         bool get_expired ()
147         { return (m_amount <= 0) && m_spawntime != 0; }
148
149         private:
150         ParticleManager* m_particlemanager;
151         float m_time;
152         IGameDef *m_gamedef;
153         scene::ISceneManager *m_smgr;
154         LocalPlayer *m_player;
155         u16 m_amount;
156         float m_spawntime;
157         v3f m_minpos;
158         v3f m_maxpos;
159         v3f m_minvel;
160         v3f m_maxvel;
161         v3f m_minacc;
162         v3f m_maxacc;
163         float m_minexptime;
164         float m_maxexptime;
165         float m_minsize;
166         float m_maxsize;
167         video::ITexture *m_texture;
168         std::vector<float> m_spawntimes;
169         bool m_collisiondetection;
170         bool m_collision_removal;
171         bool m_vertical;
172         u16 m_attached_id;
173         struct TileAnimationParams m_animation;
174         u8 m_glow;
175 };
176
177 /**
178  * Class doing particle as well as their spawners handling
179  */
180 class ParticleManager
181 {
182 friend class ParticleSpawner;
183 public:
184         ParticleManager(ClientEnvironment* env);
185         ~ParticleManager();
186
187         void step (float dtime);
188
189         void handleParticleEvent(ClientEvent *event, Client *client,
190                         scene::ISceneManager* smgr, LocalPlayer *player);
191
192         void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
193                 LocalPlayer *player, v3s16 pos, const MapNode &n,
194                 const ContentFeatures &f);
195
196         void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
197                 LocalPlayer *player, v3s16 pos, const MapNode &n,
198                 const ContentFeatures &f);
199
200         void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
201                 LocalPlayer *player, v3s16 pos, const MapNode &n,
202                 const ContentFeatures &f);
203
204 protected:
205         void addParticle(Particle* toadd);
206
207 private:
208
209         void stepParticles (float dtime);
210         void stepSpawners (float dtime);
211
212         void clearAll ();
213
214         std::vector<Particle*> m_particles;
215         std::map<u32, ParticleSpawner*> m_particle_spawners;
216
217         ClientEnvironment* m_env;
218         Mutex m_particle_list_lock;
219         Mutex m_spawner_list_lock;
220 };
221
222 #endif