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,
48 bool object_collision,
50 video::ITexture *texture,
53 const struct TileAnimationParams &anim,
55 video::SColor color = video::SColor(0xFFFFFFFF)
57 ~Particle() = default;
59 virtual const aabb3f &getBoundingBox() const
64 virtual u32 getMaterialCount() const
69 virtual video::SMaterial& getMaterial(u32 i)
74 virtual void OnRegisterSceneNode();
75 virtual void render();
77 void step(float dtime);
80 { return m_expiration < m_time; }
84 void updateVertices();
86 video::S3DVertex m_vertices[4];
90 ClientEnvironment *m_env;
93 aabb3f m_collisionbox;
94 video::SMaterial m_material;
100 LocalPlayer *m_player;
102 //! Color without lighting
103 video::SColor m_base_color;
104 //! Final rendered color
105 video::SColor m_color;
106 bool m_collisiondetection;
107 bool m_collision_removal;
108 bool m_object_collision;
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,
131 bool object_collision,
134 video::ITexture *texture,
135 const struct TileAnimationParams &anim, u8 glow,
136 ParticleManager* p_manager);
138 ~ParticleSpawner() = default;
140 void step(float dtime, ClientEnvironment *env);
143 { return (m_amount <= 0) && m_spawntime != 0; }
146 void spawnParticle(ClientEnvironment *env, float radius,
147 const core::matrix4 *attached_absolute_pos_rot_matrix);
149 ParticleManager *m_particlemanager;
152 LocalPlayer *m_player;
165 video::ITexture *m_texture;
166 std::vector<float> m_spawntimes;
167 bool m_collisiondetection;
168 bool m_collision_removal;
169 bool m_object_collision;
172 struct TileAnimationParams m_animation;
177 * Class doing particle as well as their spawners handling
179 class ParticleManager
181 friend class ParticleSpawner;
183 ParticleManager(ClientEnvironment* env);
186 void step (float dtime);
188 void handleParticleEvent(ClientEvent *event, Client *client,
189 LocalPlayer *player);
191 void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
192 const MapNode &n, const ContentFeatures &f);
194 void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
195 const MapNode &n, const ContentFeatures &f);
198 * This function is only used by client particle spawners
200 * We don't need to check the particle spawner list because client ID will n
204 u64 generateSpawnerId()
206 return m_next_particle_spawner_id++;
210 void addParticle(Particle* toadd);
214 void stepParticles(float dtime);
215 void stepSpawners(float dtime);
219 std::vector<Particle*> m_particles;
220 std::unordered_map<u64, ParticleSpawner*> m_particle_spawners;
221 // Start the particle spawner ids generated from here after u32_max. lower values are
222 // for server sent spawners.
223 u64 m_next_particle_spawner_id = U32_MAX + 1;
225 ClientEnvironment* m_env;
226 std::mutex m_particle_list_lock;
227 std::mutex m_spawner_list_lock;