+
+void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
+ scene::ISceneManager* smgr, LocalPlayer *player)
+{
+ switch (event->type) {
+ case CE_DELETE_PARTICLESPAWNER: {
+ MutexAutoLock lock(m_spawner_list_lock);
+ if (m_particle_spawners.find(event->delete_particlespawner.id) !=
+ m_particle_spawners.end()) {
+ delete m_particle_spawners.find(event->delete_particlespawner.id)->second;
+ m_particle_spawners.erase(event->delete_particlespawner.id);
+ }
+ // no allocated memory in delete event
+ break;
+ }
+ case CE_ADD_PARTICLESPAWNER: {
+ {
+ MutexAutoLock lock(m_spawner_list_lock);
+ if (m_particle_spawners.find(event->add_particlespawner.id) !=
+ m_particle_spawners.end()) {
+ delete m_particle_spawners.find(event->add_particlespawner.id)->second;
+ m_particle_spawners.erase(event->add_particlespawner.id);
+ }
+ }
+
+ video::ITexture *texture =
+ client->tsrc()->getTextureForMesh(*(event->add_particlespawner.texture));
+
+ ParticleSpawner* toadd = new ParticleSpawner(client, smgr, player,
+ event->add_particlespawner.amount,
+ event->add_particlespawner.spawntime,
+ *event->add_particlespawner.minpos,
+ *event->add_particlespawner.maxpos,
+ *event->add_particlespawner.minvel,
+ *event->add_particlespawner.maxvel,
+ *event->add_particlespawner.minacc,
+ *event->add_particlespawner.maxacc,
+ event->add_particlespawner.minexptime,
+ event->add_particlespawner.maxexptime,
+ event->add_particlespawner.minsize,
+ event->add_particlespawner.maxsize,
+ event->add_particlespawner.collisiondetection,
+ event->add_particlespawner.collision_removal,
+ event->add_particlespawner.attached_id,
+ event->add_particlespawner.vertical,
+ texture,
+ event->add_particlespawner.id,
+ event->add_particlespawner.animation,
+ event->add_particlespawner.glow,
+ this);
+
+ /* delete allocated content of event */
+ delete event->add_particlespawner.minpos;
+ delete event->add_particlespawner.maxpos;
+ delete event->add_particlespawner.minvel;
+ delete event->add_particlespawner.maxvel;
+ delete event->add_particlespawner.minacc;
+ delete event->add_particlespawner.texture;
+ delete event->add_particlespawner.maxacc;
+
+ {
+ MutexAutoLock lock(m_spawner_list_lock);
+ m_particle_spawners.insert(
+ std::pair<u32, ParticleSpawner*>(
+ event->add_particlespawner.id,
+ toadd));
+ }
+ break;
+ }
+ case CE_SPAWN_PARTICLE: {
+ video::ITexture *texture =
+ client->tsrc()->getTextureForMesh(*(event->spawn_particle.texture));
+
+ Particle* toadd = new Particle(client, smgr, player, m_env,
+ *event->spawn_particle.pos,
+ *event->spawn_particle.vel,
+ *event->spawn_particle.acc,
+ event->spawn_particle.expirationtime,
+ event->spawn_particle.size,
+ event->spawn_particle.collisiondetection,
+ event->spawn_particle.collision_removal,
+ event->spawn_particle.vertical,
+ texture,
+ v2f(0.0, 0.0),
+ v2f(1.0, 1.0),
+ event->spawn_particle.animation,
+ event->spawn_particle.glow);
+
+ addParticle(toadd);
+
+ delete event->spawn_particle.pos;
+ delete event->spawn_particle.vel;
+ delete event->spawn_particle.acc;
+ delete event->spawn_particle.texture;
+
+ break;
+ }
+ default: break;
+ }
+}
+
+void ParticleManager::addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
+ LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+{
+ for (u16 j = 0; j < 32; j++) // set the amount of particles here
+ {
+ addNodeParticle(gamedef, smgr, player, pos, tiles);
+ }
+}
+
+void ParticleManager::addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
+ LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+{
+ addNodeParticle(gamedef, smgr, player, pos, tiles);
+}
+
+void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
+ LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+{
+ // Texture
+ u8 texid = myrand_range(0, 5);
+ video::ITexture *texture;
+ struct TileAnimationParams anim;
+ anim.type = TAT_NONE;
+
+ // Only use first frame of animated texture
+ if (tiles[texid].material_flags & MATERIAL_FLAG_ANIMATION)
+ texture = tiles[texid].frames[0].texture;
+ else
+ texture = tiles[texid].texture;
+
+ float size = rand() % 64 / 512.;
+ float visual_size = BS * size;
+ v2f texsize(size * 2, size * 2);
+ v2f texpos;
+ texpos.X = ((rand() % 64) / 64. - texsize.X);
+ texpos.Y = ((rand() % 64) / 64. - texsize.Y);
+
+ // Physics
+ v3f velocity((rand() % 100 / 50. - 1) / 1.5,
+ rand() % 100 / 35.,
+ (rand() % 100 / 50. - 1) / 1.5);
+
+ v3f acceleration(0,-9,0);
+ v3f particlepos = v3f(
+ (f32) pos.X + rand() %100 /200. - 0.25,
+ (f32) pos.Y + rand() %100 /200. - 0.25,
+ (f32) pos.Z + rand() %100 /200. - 0.25
+ );
+
+ Particle* toadd = new Particle(
+ gamedef,
+ smgr,
+ player,
+ m_env,
+ particlepos,
+ velocity,
+ acceleration,
+ rand() % 100 / 100., // expiration time
+ visual_size,
+ true,
+ false,
+ false,
+ texture,
+ texpos,
+ texsize,
+ anim,
+ 0);
+
+ addParticle(toadd);
+}
+
+void ParticleManager::addParticle(Particle* toadd)
+{
+ MutexAutoLock lock(m_particle_list_lock);
+ m_particles.push_back(toadd);
+}