| 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 "ParticleSpawner.h" |
|---|
| 30 | |
|---|
| 31 | #include "core/CoreIncludes.h" |
|---|
| 32 | #include "core/EventIncludes.h" |
|---|
| 33 | #include "core/Executor.h" |
|---|
| 34 | #include "core/XMLPort.h" |
|---|
| 35 | #include "tools/ParticleInterface.h" |
|---|
| 36 | |
|---|
| 37 | namespace orxonox |
|---|
| 38 | { |
|---|
| 39 | CreateFactory(ParticleSpawner); |
|---|
| 40 | |
|---|
| 41 | ParticleSpawner::ParticleSpawner(BaseObject* creator) : ParticleEmitter(creator) |
|---|
| 42 | { |
|---|
| 43 | RegisterObject(ParticleSpawner); |
|---|
| 44 | |
|---|
| 45 | this->bAutostart_ = true; |
|---|
| 46 | this->bSuppressStart_ = false; |
|---|
| 47 | this->bAutoDestroy_ = true; |
|---|
| 48 | this->bForceDestroy_ = false; |
|---|
| 49 | this->bLoop_ = false; |
|---|
| 50 | this->startdelay_ = 0; |
|---|
| 51 | this->lifetime_ = 0; |
|---|
| 52 | this->destroydelay_ = 0; |
|---|
| 53 | |
|---|
| 54 | this->startParticleSpawner(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | ParticleSpawner::~ParticleSpawner() |
|---|
| 58 | { |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | void ParticleSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
|---|
| 62 | { |
|---|
| 63 | SUPER(ParticleSpawner, XMLPort, xmlelement, mode); |
|---|
| 64 | |
|---|
| 65 | XMLPortParam(ParticleSpawner, "autostart", setAutoStart, getAutoStart, xmlelement, mode).defaultValues(true); |
|---|
| 66 | XMLPortParam(ParticleSpawner, "autodestroy", setDestroyAfterLife, getDestroyAfterLife, xmlelement, mode).defaultValues(false); |
|---|
| 67 | XMLPortParam(ParticleSpawner, "loop", setLoop, getLoop, xmlelement, mode).defaultValues(false); |
|---|
| 68 | XMLPortParam(ParticleSpawner, "lifetime", setLifetime, getLifetime, xmlelement, mode).defaultValues(0.0f); |
|---|
| 69 | XMLPortParam(ParticleSpawner, "startdelay", setStartdelay, getStartdelay, xmlelement, mode).defaultValues(0.0f); |
|---|
| 70 | XMLPortParam(ParticleSpawner, "destroydelay", setDestroydelay, getDestroydelay, xmlelement, mode).defaultValues(0.0f); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | void ParticleSpawner::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
|---|
| 74 | { |
|---|
| 75 | SUPER(ParticleSpawner, XMLEventPort, xmlelement, mode); |
|---|
| 76 | |
|---|
| 77 | XMLPortEventState(ParticleSpawner, BaseObject, "spawn", spawn, xmlelement, mode); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | void ParticleSpawner::configure(float lifetime, float startdelay, float destroydelay, bool autodestroy) |
|---|
| 81 | { |
|---|
| 82 | this->bAutoDestroy_ = autodestroy; |
|---|
| 83 | this->startdelay_ = startdelay; |
|---|
| 84 | this->lifetime_ = lifetime; |
|---|
| 85 | this->destroydelay_ = destroydelay; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void ParticleSpawner::startParticleSpawner() |
|---|
| 89 | { |
|---|
| 90 | this->setActive(false); |
|---|
| 91 | |
|---|
| 92 | if (this->bForceDestroy_ || this->bSuppressStart_) |
|---|
| 93 | { |
|---|
| 94 | this->timer_.stopTimer(); |
|---|
| 95 | return; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | this->timer_.setTimer(this->startdelay_, false, createExecutor(createFunctor(&ParticleSpawner::fireParticleSpawner, this))); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | void ParticleSpawner::fireParticleSpawner() |
|---|
| 102 | { |
|---|
| 103 | this->setActive(true); |
|---|
| 104 | if (this->lifetime_ != 0) |
|---|
| 105 | this->timer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&ParticleSpawner::stopParticleSpawner, this))); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | void ParticleSpawner::stopParticleSpawner() |
|---|
| 109 | { |
|---|
| 110 | this->setActive(false); |
|---|
| 111 | |
|---|
| 112 | if (this->bAutoDestroy_ || this->bForceDestroy_) |
|---|
| 113 | { |
|---|
| 114 | this->setPosition(this->getWorldPosition()); |
|---|
| 115 | this->detachFromParent(); |
|---|
| 116 | |
|---|
| 117 | if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_) |
|---|
| 118 | this->timer_.setTimer(this->destroydelay_, false, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner, this))); |
|---|
| 119 | } |
|---|
| 120 | else if (this->bLoop_) |
|---|
| 121 | { |
|---|
| 122 | this->timer_.setTimer(this->destroydelay_, false, createExecutor(createFunctor(&ParticleSpawner::startParticleSpawner, this))); |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | void ParticleSpawner::destroyParticleSpawner() |
|---|
| 127 | { |
|---|
| 128 | this->destroy(); |
|---|
| 129 | } |
|---|
| 130 | } |
|---|