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 <OgreSceneManager.h> |
---|
33 | #include "core/CoreIncludes.h" |
---|
34 | #include "core/Executor.h" |
---|
35 | #include "tools/ParticleInterface.h" |
---|
36 | #include "GraphicsEngine.h" |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | CreateFactory(ParticleSpawner); |
---|
41 | |
---|
42 | ParticleSpawner::ParticleSpawner() |
---|
43 | { |
---|
44 | RegisterObject(ParticleSpawner); |
---|
45 | this->particle_ = 0; |
---|
46 | } |
---|
47 | |
---|
48 | ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) |
---|
49 | { |
---|
50 | RegisterObject(ParticleSpawner); |
---|
51 | this->setParticle(templateName, detaillevel, lifetime, startdelay, destroydelay, direction); |
---|
52 | } |
---|
53 | |
---|
54 | void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) |
---|
55 | { |
---|
56 | ExecutorMember<ParticleSpawner>* executor = createExecutor(createFunctor(&ParticleSpawner::createParticleSpawner)); |
---|
57 | this->destroydelay_ = destroydelay; |
---|
58 | executor->setDefaultValues(lifetime); |
---|
59 | this->timer_.setTimer(startdelay, false, this, executor); |
---|
60 | this->particle_ = new ParticleInterface(templateName, detaillevel); |
---|
61 | this->particle_->addToSceneNode(this->getNode()); |
---|
62 | this->particle_->setEnabled(false); |
---|
63 | if (direction != Vector3::ZERO) |
---|
64 | { |
---|
65 | this->particle_->getAllEmitters()->setDirection(direction); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | ParticleSpawner::~ParticleSpawner() |
---|
70 | { |
---|
71 | if (this->isInitialized() && this->particle_) |
---|
72 | { |
---|
73 | this->particle_->detachFromSceneNode(); |
---|
74 | delete this->particle_; |
---|
75 | } |
---|
76 | }; |
---|
77 | |
---|
78 | void ParticleSpawner::destroy() |
---|
79 | { |
---|
80 | this->setPosition(this->getNode()->getParent()->getPosition()); |
---|
81 | this->getNode()->getParent()->removeChild(this->getNode()); |
---|
82 | this->detachFromParent(); |
---|
83 | if (this->particle_) |
---|
84 | this->particle_->setEnabled(false); |
---|
85 | if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_) |
---|
86 | this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner))); |
---|
87 | } |
---|
88 | |
---|
89 | void ParticleSpawner::createParticleSpawner(float lifetime) |
---|
90 | { |
---|
91 | this->particle_->setEnabled(true); |
---|
92 | if (lifetime != 0) |
---|
93 | this->timer_.setTimer(lifetime, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner))); |
---|
94 | } |
---|
95 | |
---|
96 | void ParticleSpawner::destroyParticleSpawner() |
---|
97 | { |
---|
98 | delete this; |
---|
99 | } |
---|
100 | |
---|
101 | void ParticleSpawner::setVisible(bool visible) |
---|
102 | { |
---|
103 | if (this->particle_) |
---|
104 | this->particle_->setEnabled(visible); |
---|
105 | } |
---|
106 | } |
---|