Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ParticleSpawner.cc @ 2732

Last change on this file since 2732 was 2171, checked in by landauf, 16 years ago

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/ceguilua/src/orxonox/objects/ParticleSpawner.cc1802-1808
    /code/branches/core3/src/orxonox/objects/ParticleSpawner.cc1572-1739
    /code/branches/gcc43/src/orxonox/objects/ParticleSpawner.cc1580
    /code/branches/gui/src/orxonox/objects/ParticleSpawner.cc1635-1723
    /code/branches/input/src/orxonox/objects/ParticleSpawner.cc1629-1636
    /code/branches/objecthierarchy/src/orxonox/objects/worldentities/ParticleSpawner.cc2100,​2110-2169
    /code/branches/script_trigger/src/orxonox/objects/ParticleSpawner.cc1295-1953,​1955
File size: 4.5 KB
Line 
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"
33#include "core/EventIncludes.h"
34#include "core/Executor.h"
35#include "core/XMLPort.h"
36#include "tools/ParticleInterface.h"
37
38namespace orxonox
39{
40    CreateFactory(ParticleSpawner);
41
42    ParticleSpawner::ParticleSpawner(BaseObject* creator) : ParticleEmitter(creator)
43    {
44        RegisterObject(ParticleSpawner);
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();
56    }
57
58    ParticleSpawner::~ParticleSpawner()
59    {
60    }
61
62    void ParticleSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode)
63    {
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;
86        this->destroydelay_ = destroydelay;
87    }
88
89    void ParticleSpawner::startParticleSpawner()
90    {
91        if (!this->particles_)
92            return;
93
94        this->setActive(false);
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()
103    {
104        this->setActive(true);
105        if (this->lifetime_ != 0)
106            this->timer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&ParticleSpawner::stopParticleSpawner)));
107    }
108
109    void ParticleSpawner::stopParticleSpawner()
110    {
111        this->setActive(false);
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        }
125    }
126
127    void ParticleSpawner::destroyParticleSpawner()
128    {
129        delete this;
130    }
131}
Note: See TracBrowser for help on using the repository browser.