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
42 ClientEnvironment *env,
48 bool collisiondetection,
49 bool collision_removal,
51 video::ITexture *texture,
54 const struct TileAnimationParams &anim,
56 video::SColor color = video::SColor(0xFFFFFFFF)
60 virtual const aabb3f &getBoundingBox() const
65 virtual u32 getMaterialCount() const
70 virtual video::SMaterial& getMaterial(u32 i)
75 virtual void OnRegisterSceneNode();
76 virtual void render();
78 void step(float dtime);
81 { return m_expiration < m_time; }
85 void updateVertices();
87 video::S3DVertex m_vertices[4];
91 ClientEnvironment *m_env;
94 aabb3f m_collisionbox;
95 video::SMaterial m_material;
101 LocalPlayer *m_player;
103 //! Color without lighting
104 video::SColor m_base_color;
105 //! Final rendered color
106 video::SColor m_color;
107 bool m_collisiondetection;
108 bool m_collision_removal;
110 v3s16 m_camera_offset;
111 struct TileAnimationParams m_animation;
112 float m_animation_time = 0.0f;
113 int m_animation_frame = 0;
117 class ParticleSpawner
120 ParticleSpawner(IGameDef* gamedef,
125 v3f minvel, v3f maxvel,
126 v3f minacc, v3f maxacc,
127 float minexptime, float maxexptime,
128 float minsize, float maxsize,
129 bool collisiondetection,
130 bool collision_removal,
133 video::ITexture *texture,
135 const struct TileAnimationParams &anim, u8 glow,
136 ParticleManager* p_manager);
140 void step(float dtime, ClientEnvironment *env);
143 { return (m_amount <= 0) && m_spawntime != 0; }
146 ParticleManager* m_particlemanager;
149 LocalPlayer *m_player;
162 video::ITexture *m_texture;
163 std::vector<float> m_spawntimes;
164 bool m_collisiondetection;
165 bool m_collision_removal;
168 struct TileAnimationParams m_animation;
173 * Class doing particle as well as their spawners handling
175 class ParticleManager
177 friend class ParticleSpawner;
179 ParticleManager(ClientEnvironment* env);
182 void step (float dtime);
184 void handleParticleEvent(ClientEvent *event, Client *client,
185 LocalPlayer *player);
187 void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
188 const MapNode &n, const ContentFeatures &f);
190 void addPunchingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
191 const MapNode &n, const ContentFeatures &f);
193 void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
194 const MapNode &n, const ContentFeatures &f);
197 void addParticle(Particle* toadd);
201 void stepParticles (float dtime);
202 void stepSpawners (float dtime);
206 std::vector<Particle*> m_particles;
207 std::map<u32, ParticleSpawner*> m_particle_spawners;
209 ClientEnvironment* m_env;
210 std::mutex m_particle_list_lock;
211 std::mutex m_spawner_list_lock;