Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5741 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

  • Property svn:eol-style set to native
File size: 4.4 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"
[1552]33#include "core/Executor.h"
[2065]34#include "core/XMLPort.h"
[1553]35#include "tools/ParticleInterface.h"
[1552]36
37namespace orxonox
38{
39    CreateFactory(ParticleSpawner);
40
[2065]41    ParticleSpawner::ParticleSpawner(BaseObject* creator) : ParticleEmitter(creator)
[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
73    void ParticleSpawner::processEvent(Event& event)
74    {
75        SUPER(ParticleSpawner, processEvent, event);
76
[3196]77        ORXONOX_SET_EVENT(ParticleSpawner, "spawn", spawn, event);
[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    {
[2065]90        if (!this->particles_)
91            return;
[1552]92
[2067]93        this->setActive(false);
[2065]94
95        if (this->bForceDestroy_ || this->bSuppressStart_)
96            return;
97
98        this->timer_.setTimer(this->startdelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::fireParticleSpawner)));
99    }
100
101    void ParticleSpawner::fireParticleSpawner()
[1608]102    {
[2067]103        this->setActive(true);
[2065]104        if (this->lifetime_ != 0)
105            this->timer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&ParticleSpawner::stopParticleSpawner)));
[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_)
118                this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));
119        }
120        else if (this->bLoop_)
121        {
122            this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::startParticleSpawner)));
123        }
[1552]124    }
125
126    void ParticleSpawner::destroyParticleSpawner()
127    {
128        delete this;
129    }
130}
Note: See TracBrowser for help on using the repository browser.