Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/orxonox/objects/worldentities/ParticleEmitter.cc @ 2481

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

Bugfix for dedicated mode. Should work now except for an exception with an OrxonoxOverlay. Was that there before too?

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