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