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.
23 #include "irrlichttypes_extrabloated.h"
24 #include "client/tile.h"
25 #include "localplayer.h"
26 #include "tileanimation.h"
29 class ParticleManager;
30 class ClientEnvironment;
32 struct ContentFeatures;
34 class Particle : public scene::ISceneNode
40 ClientEnvironment *env,
46 bool collisiondetection,
47 bool collision_removal,
49 video::ITexture *texture,
52 const struct TileAnimationParams &anim,
54 video::SColor color = video::SColor(0xFFFFFFFF)
56 ~Particle() = default;
58 virtual const aabb3f &getBoundingBox() const
63 virtual u32 getMaterialCount() const
68 virtual video::SMaterial& getMaterial(u32 i)
73 virtual void OnRegisterSceneNode();
74 virtual void render();
76 void step(float dtime);
79 { return m_expiration < m_time; }
83 void updateVertices();
85 video::S3DVertex m_vertices[4];
89 ClientEnvironment *m_env;
92 aabb3f m_collisionbox;
93 video::SMaterial m_material;
99 LocalPlayer *m_player;
101 //! Color without lighting
102 video::SColor m_base_color;
103 //! Final rendered color
104 video::SColor m_color;
105 bool m_collisiondetection;
106 bool m_collision_removal;
108 v3s16 m_camera_offset;
109 struct TileAnimationParams m_animation;
110 float m_animation_time = 0.0f;
111 int m_animation_frame = 0;
115 class ParticleSpawner
118 ParticleSpawner(IGameDef* gamedef,
123 v3f minvel, v3f maxvel,
124 v3f minacc, v3f maxacc,
125 float minexptime, float maxexptime,
126 float minsize, float maxsize,
127 bool collisiondetection,
128 bool collision_removal,
131 video::ITexture *texture,
133 const struct TileAnimationParams &anim, u8 glow,
134 ParticleManager* p_manager);
136 ~ParticleSpawner() = default;
138 void step(float dtime, ClientEnvironment *env);
141 { return (m_amount <= 0) && m_spawntime != 0; }
144 void spawnParticle(ClientEnvironment *env, float radius,
145 bool is_attached, const v3f &attached_pos,
148 ParticleManager *m_particlemanager;
151 LocalPlayer *m_player;
164 video::ITexture *m_texture;
165 std::vector<float> m_spawntimes;
166 bool m_collisiondetection;
167 bool m_collision_removal;
170 struct TileAnimationParams m_animation;
175 * Class doing particle as well as their spawners handling
177 class ParticleManager
179 friend class ParticleSpawner;
181 ParticleManager(ClientEnvironment* env);
184 void step (float dtime);
186 void handleParticleEvent(ClientEvent *event, Client *client,
187 LocalPlayer *player);
189 void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
190 const MapNode &n, const ContentFeatures &f);
192 void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
193 const MapNode &n, const ContentFeatures &f);
195 u32 getSpawnerId() const
197 for (u32 id = 0;; ++id) { // look for unused particlespawner id
198 if (m_particle_spawners.find(id) == m_particle_spawners.end())
204 void addParticle(Particle* toadd);
208 void stepParticles (float dtime);
209 void stepSpawners (float dtime);
213 std::vector<Particle*> m_particles;
214 std::map<u32, ParticleSpawner*> m_particle_spawners;
216 ClientEnvironment* m_env;
217 std::mutex m_particle_list_lock;
218 std::mutex m_spawner_list_lock;