Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/worldentities/ParticleSpawner.cc @ 2731

Last change on this file since 2731 was 2710, checked in by rgrieder, 16 years ago

Merged buildsystem3 containing buildsystem2 containing Adi's buildsystem branch back to the trunk.
Please update the media directory if you were not using buildsystem3 before.

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