[1552] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "ParticleSpawner.h" |
---|
| 31 | |
---|
| 32 | #include "core/CoreIncludes.h" |
---|
| 33 | #include "core/Executor.h" |
---|
[1553] | 34 | #include "tools/ParticleInterface.h" |
---|
[1608] | 35 | #include "GraphicsEngine.h" |
---|
[1552] | 36 | |
---|
| 37 | namespace orxonox |
---|
| 38 | { |
---|
| 39 | CreateFactory(ParticleSpawner); |
---|
| 40 | |
---|
[1559] | 41 | ParticleSpawner::ParticleSpawner() |
---|
[1552] | 42 | { |
---|
| 43 | RegisterObject(ParticleSpawner); |
---|
[1602] | 44 | this->particle_ = 0; |
---|
[1552] | 45 | } |
---|
| 46 | |
---|
[1608] | 47 | ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) |
---|
[1552] | 48 | { |
---|
| 49 | RegisterObject(ParticleSpawner); |
---|
[1608] | 50 | this->setParticle(templateName, detaillevel, lifetime, startdelay, destroydelay, direction); |
---|
[1602] | 51 | } |
---|
[1552] | 52 | |
---|
[1608] | 53 | void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) |
---|
[1602] | 54 | { |
---|
[1552] | 55 | ExecutorMember<ParticleSpawner>* executor = createExecutor(createFunctor(&ParticleSpawner::createParticleSpawner)); |
---|
[1608] | 56 | this->destroydelay_ = destroydelay; |
---|
[1552] | 57 | executor->setDefaultValues(lifetime); |
---|
[1608] | 58 | this->timer_.setTimer(startdelay, false, this, executor); |
---|
[1563] | 59 | this->particle_ = new ParticleInterface(templateName, detaillevel); |
---|
[1552] | 60 | this->particle_->addToSceneNode(this->getNode()); |
---|
| 61 | this->particle_->setEnabled(false); |
---|
| 62 | if (direction != Vector3::ZERO) |
---|
| 63 | { |
---|
| 64 | this->particle_->getAllEmitters()->setDirection(direction); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | ParticleSpawner::~ParticleSpawner() |
---|
| 69 | { |
---|
[1602] | 70 | if (this->isInitialized() && this->particle_) |
---|
[1552] | 71 | { |
---|
| 72 | this->particle_->detachFromSceneNode(); |
---|
| 73 | delete this->particle_; |
---|
| 74 | } |
---|
| 75 | }; |
---|
| 76 | |
---|
[1608] | 77 | void ParticleSpawner::destroy() |
---|
| 78 | { |
---|
| 79 | this->setPosition(this->getNode()->getParent()->getPosition()); |
---|
| 80 | this->getNode()->getParent()->removeChild(this->getNode()); |
---|
| 81 | GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->addChild(this->getNode()); |
---|
| 82 | if (this->particle_) |
---|
| 83 | this->particle_->setEnabled(false); |
---|
| 84 | if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_) |
---|
| 85 | this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner))); |
---|
| 86 | } |
---|
| 87 | |
---|
[1552] | 88 | void ParticleSpawner::createParticleSpawner(float lifetime) |
---|
| 89 | { |
---|
| 90 | this->particle_->setEnabled(true); |
---|
[1602] | 91 | if (lifetime != 0) |
---|
| 92 | this->timer_.setTimer(lifetime, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner))); |
---|
[1552] | 93 | } |
---|
| 94 | |
---|
| 95 | void ParticleSpawner::destroyParticleSpawner() |
---|
| 96 | { |
---|
| 97 | delete this; |
---|
| 98 | } |
---|
[1602] | 99 | |
---|
| 100 | void ParticleSpawner::setVisible(bool visible) |
---|
| 101 | { |
---|
| 102 | if (this->particle_) |
---|
| 103 | this->particle_->setEnabled(visible); |
---|
| 104 | } |
---|
[1552] | 105 | } |
---|