]> git.lizzy.rs Git - minetest.git/blobdiff - src/particles.cpp
Set acceleration only once in falling node
[minetest.git] / src / particles.cpp
index 603e38cdd546b627ee3766e395b8e3e2e1801321..ab77e9f54c8cba2924409688fa368a6015f4c000 100644 (file)
@@ -20,9 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "particles.h"
 #include "constants.h"
 #include "debug.h"
-#include "main.h" // For g_profiler and g_settings
 #include "settings.h"
-#include "tile.h"
+#include "client/tile.h"
 #include "gamedef.h"
 #include "collision.h"
 #include <stdlib.h>
@@ -89,7 +88,7 @@ Particle::Particle(
        m_vertical = vertical;
 
        // Irrlicht stuff
-       m_collisionbox = core::aabbox3d<f32>
+       m_collisionbox = aabb3f
                        (-size/2,-size/2,-size/2,size/2,size/2,size/2);
        this->setAutomaticCulling(scene::EAC_OFF);
 
@@ -107,20 +106,13 @@ Particle::~Particle()
 void Particle::OnRegisterSceneNode()
 {
        if (IsVisible)
-       {
-               SceneManager->registerNodeForRendering
-                               (this, scene::ESNRP_TRANSPARENT);
-               SceneManager->registerNodeForRendering
-                               (this, scene::ESNRP_SOLID);
-       }
+               SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT_EFFECT);
 
        ISceneNode::OnRegisterSceneNode();
 }
 
 void Particle::render()
 {
-       // TODO: Render particles in front of water and the selectionbox
-
        video::IVideoDriver* driver = SceneManager->getVideoDriver();
        driver->setMaterial(m_material);
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
@@ -136,17 +128,15 @@ void Particle::step(float dtime)
        m_time += dtime;
        if (m_collisiondetection)
        {
-               core::aabbox3d<f32> box = m_collisionbox;
+               aabb3f box = m_collisionbox;
                v3f p_pos = m_pos*BS;
                v3f p_velocity = m_velocity*BS;
-               v3f p_acceleration = m_acceleration*BS;
                collisionMoveSimple(m_env, m_gamedef,
                        BS*0.5, box,
                        0, dtime,
-                       p_pos, p_velocity, p_acceleration);
+                       &p_pos, &p_velocity, m_acceleration * BS);
                m_pos = p_pos/BS;
                m_velocity = p_velocity/BS;
-               m_acceleration = p_acceleration/BS;
        }
        else
        {
@@ -296,7 +286,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env)
                        }
                        else
                        {
-                               i++;
+                               ++i;
                        }
                }
        }
@@ -316,7 +306,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env)
                                                *(m_maxsize-m_minsize)
                                                +m_minsize;
 
-                               new Particle(
+                               Particle* toadd = new Particle(
                                        m_gamedef,
                                        m_smgr,
                                        m_player,
@@ -331,6 +321,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment* env)
                                        m_texture,
                                        v2f(0.0, 0.0),
                                        v2f(1.0, 1.0));
+                               m_particlemanager->addParticle(toadd);
                        }
                }
        }
@@ -354,7 +345,7 @@ void ParticleManager::step(float dtime)
 
 void ParticleManager::stepSpawners (float dtime)
 {
-       JMutexAutoLock lock(m_spawner_list_lock);
+       MutexAutoLock lock(m_spawner_list_lock);
        for(std::map<u32, ParticleSpawner*>::iterator i = 
                        m_particle_spawners.begin();
                        i != m_particle_spawners.end();)
@@ -367,14 +358,14 @@ void ParticleManager::stepSpawners (float dtime)
                else
                {
                        i->second->step(dtime, m_env);
-                       i++;
+                       ++i;
                }
        }
 }
 
 void ParticleManager::stepParticles (float dtime)
 {
-       JMutexAutoLock lock(m_particle_list_lock);
+       MutexAutoLock lock(m_particle_list_lock);
        for(std::vector<Particle*>::iterator i = m_particles.begin();
                        i != m_particles.end();)
        {
@@ -387,15 +378,15 @@ void ParticleManager::stepParticles (float dtime)
                else
                {
                        (*i)->step(dtime);
-                       i++;
+                       ++i;
                }
        }
 }
 
 void ParticleManager::clearAll ()
 {
-       JMutexAutoLock lock(m_spawner_list_lock);
-       JMutexAutoLock lock2(m_particle_list_lock);
+       MutexAutoLock lock(m_spawner_list_lock);
+       MutexAutoLock lock2(m_particle_list_lock);
        for(std::map<u32, ParticleSpawner*>::iterator i =
                        m_particle_spawners.begin();
                        i != m_particle_spawners.end();)
@@ -418,7 +409,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef,
                scene::ISceneManager* smgr, LocalPlayer *player)
 {
        if (event->type == CE_DELETE_PARTICLESPAWNER) {
-               JMutexAutoLock lock(m_spawner_list_lock);
+               MutexAutoLock lock(m_spawner_list_lock);
                if (m_particle_spawners.find(event->delete_particlespawner.id) !=
                                m_particle_spawners.end())
                {
@@ -432,7 +423,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef,
        if (event->type == CE_ADD_PARTICLESPAWNER) {
 
                {
-                       JMutexAutoLock lock(m_spawner_list_lock);
+                       MutexAutoLock lock(m_spawner_list_lock);
                        if (m_particle_spawners.find(event->add_particlespawner.id) !=
                                                        m_particle_spawners.end())
                        {
@@ -441,7 +432,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef,
                        }
                }
                video::ITexture *texture =
-                       gamedef->tsrc()->getTexture(*(event->add_particlespawner.texture));
+                       gamedef->tsrc()->getTextureForMesh(*(event->add_particlespawner.texture));
 
                ParticleSpawner* toadd = new ParticleSpawner(gamedef, smgr, player,
                                event->add_particlespawner.amount,
@@ -472,7 +463,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef,
                delete event->add_particlespawner.maxacc;
 
                {
-                       JMutexAutoLock lock(m_spawner_list_lock);
+                       MutexAutoLock lock(m_spawner_list_lock);
                        m_particle_spawners.insert(
                                        std::pair<u32, ParticleSpawner*>(
                                                        event->add_particlespawner.id,
@@ -484,7 +475,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef,
 
        if (event->type == CE_SPAWN_PARTICLE) {
                video::ITexture *texture =
-                       gamedef->tsrc()->getTexture(*(event->spawn_particle.texture));
+                       gamedef->tsrc()->getTextureForMesh(*(event->spawn_particle.texture));
 
                Particle* toadd = new Particle(gamedef, smgr, player, m_env,
                                *event->spawn_particle.pos,
@@ -575,6 +566,6 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* s
 
 void ParticleManager::addParticle(Particle* toadd)
 {
-       JMutexAutoLock lock(m_particle_list_lock);
+       MutexAutoLock lock(m_particle_list_lock);
        m_particles.push_back(toadd);
 }