Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/graphics/ParticleSpawner.cc @ 12261

Last change on this file since 12261 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 4.5 KB
RevLine 
[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 "ParticleSpawner.h"
30
31#include "core/CoreIncludes.h"
[2065]32#include "core/EventIncludes.h"
33#include "core/XMLPort.h"
[7284]34#include "core/command/Executor.h"
[1553]35#include "tools/ParticleInterface.h"
[1552]36
37namespace orxonox
38{
[9667]39    RegisterClass(ParticleSpawner);
[1552]40
[9667]41    ParticleSpawner::ParticleSpawner(Context* context) : ParticleEmitter(context)
[1552]42    {
43        RegisterObject(ParticleSpawner);
[2065]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();
[1552]55    }
56
[2065]57    ParticleSpawner::~ParticleSpawner()
[1552]58    {
[1602]59    }
[1552]60
[2065]61    void ParticleSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[1602]62    {
[2065]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
[5929]73    void ParticleSpawner::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
[2065]74    {
[5929]75        SUPER(ParticleSpawner, XMLEventPort, xmlelement, mode);
[2065]76
[5929]77        XMLPortEventState(ParticleSpawner, BaseObject, "spawn", spawn, xmlelement, mode);
[2065]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;
[1608]85        this->destroydelay_ = destroydelay;
[1552]86    }
87
[2065]88    void ParticleSpawner::startParticleSpawner()
[1552]89    {
[2067]90        this->setActive(false);
[2065]91
92        if (this->bForceDestroy_ || this->bSuppressStart_)
[5929]93        {
94            this->timer_.stopTimer();
[2065]95            return;
[5929]96        }
[2065]97
[5929]98        this->timer_.setTimer(this->startdelay_, false, createExecutor(createFunctor(&ParticleSpawner::fireParticleSpawner, this)));
[2065]99    }
100
101    void ParticleSpawner::fireParticleSpawner()
[1608]102    {
[2067]103        this->setActive(true);
[2065]104        if (this->lifetime_ != 0)
[5929]105            this->timer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&ParticleSpawner::stopParticleSpawner, this)));
[1608]106    }
107
[2065]108    void ParticleSpawner::stopParticleSpawner()
[1552]109    {
[2067]110        this->setActive(false);
[2065]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_)
[5929]118                this->timer_.setTimer(this->destroydelay_, false, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner, this)));
[2065]119        }
120        else if (this->bLoop_)
121        {
[5929]122            this->timer_.setTimer(this->destroydelay_, false, createExecutor(createFunctor(&ParticleSpawner::startParticleSpawner, this)));
[2065]123        }
[1552]124    }
125
126    void ParticleSpawner::destroyParticleSpawner()
127    {
[5929]128        this->destroy();
[1552]129    }
130}
Note: See TracBrowser for help on using the repository browser.