Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/objects/worldentities/ParticleEmitter.cc @ 2799

Last change on this file since 2799 was 2799, checked in by rgrieder, 15 years ago

Moved all core related initialisations from Main.cc and GSRoot.cc to Core.cc so that everything sticks together more obviously.

Renamed —directory command line argument: Name really doesn't say what it is.
using —writingPathSuffix now. Not much better, but at least you wonder

  • Property svn:eol-style set to native
File size: 4.1 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/**
30* @file
31* @brief class to control praticle effects
32*/
33
34#include "OrxonoxStableHeaders.h"
35#include "ParticleEmitter.h"
36
37#include <OgreParticleSystem.h>
38
39#include "tools/ParticleInterface.h"
40#include "util/Exception.h"
41#include "core/Core.h"
42#include "core/CoreIncludes.h"
43#include "core/XMLPort.h"
44#include "objects/Scene.h"
45
46namespace orxonox
47{
48    CreateFactory(ParticleEmitter);
49
50    ParticleEmitter::ParticleEmitter(BaseObject* creator) : StaticEntity(creator)
51    {
52        RegisterObject(ParticleEmitter);
53
54        if (Core::showsGraphics() && (!this->getScene() || !this->getScene()->getSceneManager()))
55            ThrowException(AbortLoading, "Can't create ParticleEmitter, no scene or no scene manager given.");
56
57        this->particles_ = 0;
58        this->LOD_ = LODParticle::normal;
59
60        this->registerVariables();
61    }
62
63    ParticleEmitter::~ParticleEmitter()
64    {
65        if (this->isInitialized() && this->particles_)
66        {
67            this->detachOgreObject(this->particles_->getParticleSystem());
68            delete this->particles_;
69        }
70    }
71
72    void ParticleEmitter::XMLPort(Element& xmlelement, XMLPort::Mode mode)
73    {
74        SUPER(ParticleEmitter, XMLPort, xmlelement, mode);
75
76        XMLPortParam(ParticleEmitter, "lod",    setLODxml, getLODxml, xmlelement, mode).defaultValues(LODParticle::normal);
77        XMLPortParam(ParticleEmitter, "source", setSource, getSource, xmlelement, mode);
78    }
79
80    void ParticleEmitter::registerVariables()
81    {
82        registerVariable(this->source_, variableDirection::toclient, new NetworkCallback<ParticleEmitter>(this, &ParticleEmitter::sourceChanged));
83        registerVariable((int&)(this->LOD_),    variableDirection::toclient, new NetworkCallback<ParticleEmitter>(this, &ParticleEmitter::LODchanged));
84    }
85
86    void ParticleEmitter::changedVisibility()
87    {
88        SUPER(ParticleEmitter, changedVisibility);
89
90        if (this->particles_)
91            this->particles_->setVisible(this->isVisible());
92    }
93
94    void ParticleEmitter::changedActivity()
95    {
96        SUPER(ParticleEmitter, changedActivity);
97
98        if (this->particles_)
99            this->particles_->setEnabled(this->isActive());
100    }
101
102    void ParticleEmitter::sourceChanged()
103    {
104        if (this->particles_)
105        {
106            delete this->particles_;
107            this->particles_ = 0;
108        }
109
110        if (Core::showsGraphics() && this->getScene() && this->getScene()->getSceneManager())
111        {
112            try
113            {
114                this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), this->source_, this->LOD_);
115                this->attachOgreObject(this->particles_->getParticleSystem());
116                this->particles_->setVisible(this->isVisible());
117                this->particles_->setEnabled(this->isActive());
118            }
119            catch (...)
120            {
121                COUT(1) << "Error: Couln't load particle effect \"" << this->source_ << "\"" << std::endl;
122                this->particles_ = 0;
123            }
124        }
125    }
126
127    void ParticleEmitter::LODchanged()
128    {
129        if (this->particles_)
130            this->particles_->setDetailLevel(this->LOD_);
131    }
132}
Note: See TracBrowser for help on using the repository browser.