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
23 #define DIGGING_PARTICLES_AMOUNT 10
26 #include "irrlichttypes_extrabloated.h"
27 #include "client/tile.h"
28 #include "localplayer.h"
29 #include "environment.h"
30 #include "tileanimation.h"
33 class ParticleManager;
34 class ClientEnvironment;
36 struct ContentFeatures;
38 class Particle : public scene::ISceneNode
43 scene::ISceneManager* mgr,
45 ClientEnvironment *env,
51 bool collisiondetection,
52 bool collision_removal,
54 video::ITexture *texture,
57 const struct TileAnimationParams &anim,
59 video::SColor color = video::SColor(0xFFFFFFFF)
63 virtual const aabb3f &getBoundingBox() const
68 virtual u32 getMaterialCount() const
73 virtual video::SMaterial& getMaterial(u32 i)
78 virtual void OnRegisterSceneNode();
79 virtual void render();
81 void step(float dtime);
84 { return m_expiration < m_time; }
88 void updateVertices();
90 video::S3DVertex m_vertices[4];
94 ClientEnvironment *m_env;
97 aabb3f m_collisionbox;
98 video::SMaterial m_material;
104 LocalPlayer *m_player;
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;
113 v3s16 m_camera_offset;
114 struct TileAnimationParams m_animation;
115 float m_animation_time;
116 int m_animation_frame;
120 class ParticleSpawner
123 ParticleSpawner(IGameDef* gamedef,
124 scene::ISceneManager *smgr,
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,
137 video::ITexture *texture,
139 const struct TileAnimationParams &anim, u8 glow,
140 ParticleManager* p_manager);
144 void step(float dtime, ClientEnvironment *env);
147 { return (m_amount <= 0) && m_spawntime != 0; }
150 ParticleManager* m_particlemanager;
153 scene::ISceneManager *m_smgr;
154 LocalPlayer *m_player;
167 video::ITexture *m_texture;
168 std::vector<float> m_spawntimes;
169 bool m_collisiondetection;
170 bool m_collision_removal;
173 struct TileAnimationParams m_animation;
178 * Class doing particle as well as their spawners handling
180 class ParticleManager
182 friend class ParticleSpawner;
184 ParticleManager(ClientEnvironment* env);
187 void step (float dtime);
189 void handleParticleEvent(ClientEvent *event, Client *client,
190 scene::ISceneManager* smgr, LocalPlayer *player);
192 void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
193 LocalPlayer *player, v3s16 pos, const MapNode &n,
194 const ContentFeatures &f);
196 void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
197 LocalPlayer *player, v3s16 pos, const MapNode &n,
198 const ContentFeatures &f);
200 void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
201 LocalPlayer *player, v3s16 pos, const MapNode &n,
202 const ContentFeatures &f);
205 void addParticle(Particle* toadd);
209 void stepParticles (float dtime);
210 void stepSpawners (float dtime);
214 std::vector<Particle*> m_particles;
215 std::map<u32, ParticleSpawner*> m_particle_spawners;
217 ClientEnvironment* m_env;
218 Mutex m_particle_list_lock;
219 Mutex m_spawner_list_lock;