3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #ifndef PARTICLES_HEADER
21 #define PARTICLES_HEADER
24 #include "irrlichttypes_extrabloated.h"
25 #include "client/tile.h"
26 #include "localplayer.h"
27 #include "environment.h"
28 #include "tileanimation.h"
31 class ParticleManager;
32 class ClientEnvironment;
34 struct ContentFeatures;
36 class Particle : public scene::ISceneNode
41 scene::ISceneManager* mgr,
43 ClientEnvironment *env,
49 bool collisiondetection,
50 bool collision_removal,
52 video::ITexture *texture,
55 const struct TileAnimationParams &anim,
57 video::SColor color = video::SColor(0xFFFFFFFF)
61 virtual const aabb3f &getBoundingBox() const
66 virtual u32 getMaterialCount() const
71 virtual video::SMaterial& getMaterial(u32 i)
76 virtual void OnRegisterSceneNode();
77 virtual void render();
79 void step(float dtime);
82 { return m_expiration < m_time; }
86 void updateVertices();
88 video::S3DVertex m_vertices[4];
92 ClientEnvironment *m_env;
95 aabb3f m_collisionbox;
96 video::SMaterial m_material;
102 LocalPlayer *m_player;
104 //! Color without lighting
105 video::SColor m_base_color;
106 //! Final rendered color
107 video::SColor m_color;
108 bool m_collisiondetection;
109 bool m_collision_removal;
111 v3s16 m_camera_offset;
112 struct TileAnimationParams m_animation;
113 float m_animation_time;
114 int m_animation_frame;
118 class ParticleSpawner
121 ParticleSpawner(IGameDef* gamedef,
122 scene::ISceneManager *smgr,
127 v3f minvel, v3f maxvel,
128 v3f minacc, v3f maxacc,
129 float minexptime, float maxexptime,
130 float minsize, float maxsize,
131 bool collisiondetection,
132 bool collision_removal,
135 video::ITexture *texture,
137 const struct TileAnimationParams &anim, u8 glow,
138 ParticleManager* p_manager);
142 void step(float dtime, ClientEnvironment *env);
145 { return (m_amount <= 0) && m_spawntime != 0; }
148 ParticleManager* m_particlemanager;
151 scene::ISceneManager *m_smgr;
152 LocalPlayer *m_player;
165 video::ITexture *m_texture;
166 std::vector<float> m_spawntimes;
167 bool m_collisiondetection;
168 bool m_collision_removal;
171 struct TileAnimationParams m_animation;
176 * Class doing particle as well as their spawners handling
178 class ParticleManager
180 friend class ParticleSpawner;
182 ParticleManager(ClientEnvironment* env);
185 void step (float dtime);
187 void handleParticleEvent(ClientEvent *event, Client *client,
188 scene::ISceneManager* smgr, LocalPlayer *player);
190 void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
191 LocalPlayer *player, v3s16 pos, const MapNode &n,
192 const ContentFeatures &f);
194 void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
195 LocalPlayer *player, v3s16 pos, const MapNode &n,
196 const ContentFeatures &f);
198 void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
199 LocalPlayer *player, v3s16 pos, const MapNode &n,
200 const ContentFeatures &f);
203 void addParticle(Particle* toadd);
207 void stepParticles (float dtime);
208 void stepSpawners (float dtime);
212 std::vector<Particle*> m_particles;
213 std::map<u32, ParticleSpawner*> m_particle_spawners;
215 ClientEnvironment* m_env;
216 Mutex m_particle_list_lock;
217 Mutex m_spawner_list_lock;