101fc49ce145cb8cb5a0bd72f8e8315318ec6543
[oweals/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 "tile.h"
28 #include "localplayer.h"
29 #include "environment.h"
30
31 class Particle : public scene::ISceneNode
32 {
33         public:
34         Particle(
35                 IGameDef* gamedef,
36                 scene::ISceneManager* mgr,
37                 LocalPlayer *player,
38                 ClientEnvironment &env,
39                 v3f pos,
40                 v3f velocity,
41                 v3f acceleration,
42                 float expirationtime,
43                 float size,
44                 bool collisiondetection,
45                 bool vertical,
46                 video::ITexture *texture,
47                 v2f texpos,
48                 v2f texsize
49         );
50         ~Particle();
51
52         virtual const core::aabbox3d<f32>& getBoundingBox() const
53         {
54                 return m_box;
55         }
56
57         virtual u32 getMaterialCount() const
58         {
59                 return 1;
60         }
61
62         virtual video::SMaterial& getMaterial(u32 i)
63         {
64                 return m_material;
65         }
66
67         virtual void OnRegisterSceneNode();
68         virtual void render();
69
70         void step(float dtime);
71
72         bool get_expired ()
73         { return m_expiration < m_time; }
74
75 private:
76         void updateLight();
77         void updateVertices();
78
79         video::S3DVertex m_vertices[4];
80         float m_time;
81         float m_expiration;
82
83         ClientEnvironment *m_env;
84         IGameDef *m_gamedef;
85         core::aabbox3d<f32> m_box;
86         core::aabbox3d<f32> m_collisionbox;
87         video::SMaterial m_material;
88         v2f m_texpos;
89         v2f m_texsize;
90         v3f m_pos;
91         v3f m_velocity;
92         v3f m_acceleration;
93         LocalPlayer *m_player;
94         float m_size;
95         u8 m_light;
96         bool m_collisiondetection;
97         bool m_vertical;
98         v3s16 m_camera_offset;
99 };
100
101 class ParticleSpawner
102 {
103         public:
104         ParticleSpawner(IGameDef* gamedef,
105                 scene::ISceneManager *smgr,
106                 LocalPlayer *player,
107                 u16 amount,
108                 float time,
109                 v3f minp, v3f maxp,
110                 v3f minvel, v3f maxvel,
111                 v3f minacc, v3f maxacc,
112                 float minexptime, float maxexptime,
113                 float minsize, float maxsize,
114                 bool collisiondetection,
115                 bool vertical,
116                 video::ITexture *texture,
117                 u32 id);
118
119         ~ParticleSpawner();
120
121         void step(float dtime, ClientEnvironment &env);
122
123         bool get_expired ()
124         { return (m_amount <= 0) && m_spawntime != 0; }
125
126         private:
127         float m_time;
128         IGameDef *m_gamedef;
129         scene::ISceneManager *m_smgr;
130         LocalPlayer *m_player;
131         u16 m_amount;
132         float m_spawntime;
133         v3f m_minpos;
134         v3f m_maxpos;
135         v3f m_minvel;
136         v3f m_maxvel;
137         v3f m_minacc;
138         v3f m_maxacc;
139         float m_minexptime;
140         float m_maxexptime;
141         float m_minsize;
142         float m_maxsize;
143         video::ITexture *m_texture;
144         std::vector<float> m_spawntimes;
145         bool m_collisiondetection;
146         bool m_vertical;
147 };
148
149 void allparticles_step (float dtime);
150 void allparticlespawners_step (float dtime, ClientEnvironment &env);
151
152 void delete_particlespawner (u32 id);
153 void clear_particles ();
154
155 void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
156         LocalPlayer *player, ClientEnvironment &env, v3s16 pos,
157         const TileSpec tiles[]);
158
159 void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
160         LocalPlayer *player, ClientEnvironment &env, v3s16 pos,
161         const TileSpec tiles[]);
162
163 void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
164         LocalPlayer *player, ClientEnvironment &env, v3s16 pos,
165         const TileSpec tiles[]);
166
167 #endif