]> git.lizzy.rs Git - minetest.git/blob - src/particles.h
308da551f997825c33febb3aa3ee856f1ba449bd
[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                 AtlasPointer texture
46         );
47         ~Particle();
48
49         virtual const core::aabbox3d<f32>& getBoundingBox() const
50         {
51                 return m_box;
52         }
53
54         virtual u32 getMaterialCount() const
55         {
56                 return 1;
57         }
58
59         virtual video::SMaterial& getMaterial(u32 i)
60         {
61                 return m_material;
62         }
63
64         virtual void OnRegisterSceneNode();
65         virtual void render();
66
67         void step(float dtime, ClientEnvironment &env);
68
69         bool get_expired ()
70         { return m_expiration < m_time; }
71
72 private:
73         void updateLight(ClientEnvironment &env);
74         void updateVertices();
75
76         video::S3DVertex m_vertices[4];
77         float m_time;
78         float m_expiration;
79
80         IGameDef *m_gamedef;
81         core::aabbox3d<f32> m_box;
82         core::aabbox3d<f32> m_collisionbox;
83         video::SMaterial m_material;
84         v3f m_pos;
85         v3f m_velocity;
86         v3f m_acceleration;
87         float tex_x0;
88         float tex_x1;
89         float tex_y0;
90         float tex_y1;
91         LocalPlayer *m_player;
92         float m_size;
93         AtlasPointer m_ap;
94         u8 m_light;
95         bool m_collisiondetection;
96 };
97
98 class ParticleSpawner
99 {
100         public:
101         ParticleSpawner(IGameDef* gamedef,
102                 scene::ISceneManager *smgr,
103                 LocalPlayer *player,
104                 u16 amount,
105                 float time,
106                 v3f minp, v3f maxp,
107                 v3f minvel, v3f maxvel,
108                 v3f minacc, v3f maxacc,
109                 float minexptime, float maxexptime,
110                 float minsize, float maxsize,
111                 bool collisiondetection,
112                 AtlasPointer ap,
113                 u32 id);
114
115         ~ParticleSpawner();
116
117         void step(float dtime, ClientEnvironment &env);
118
119         bool get_expired ()
120         { return (m_amount <= 0) && m_spawntime != 0; }
121
122         private:
123         float m_time;
124         IGameDef *m_gamedef;
125         scene::ISceneManager *m_smgr;
126         LocalPlayer *m_player;
127         u16 m_amount;
128         float m_spawntime;
129         v3f m_minpos;
130         v3f m_maxpos;
131         v3f m_minvel;
132         v3f m_maxvel;
133         v3f m_minacc;
134         v3f m_maxacc;
135         float m_minexptime;
136         float m_maxexptime;
137         float m_minsize;
138         float m_maxsize;
139         AtlasPointer m_ap;
140         std::vector<float> m_spawntimes;
141         bool m_collisiondetection;
142 };
143
144 void allparticles_step (float dtime, ClientEnvironment &env);
145 void allparticlespawners_step (float dtime, ClientEnvironment &env);
146
147 void delete_particlespawner (u32 id);
148 void clear_particles ();
149
150 void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
151         LocalPlayer *player, ClientEnvironment &env, v3s16 pos,
152         const TileSpec tiles[]);
153
154 void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
155         LocalPlayer *player, ClientEnvironment &env, v3s16 pos,
156         const TileSpec tiles[]);
157
158 void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
159         LocalPlayer *player, ClientEnvironment &env, v3s16 pos,
160         const TileSpec tiles[]);
161
162 #endif