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 | |
---|
45 | namespace 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 ParticleEmitter, 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 | { |
---|
105 | delete this->particles_; |
---|
106 | this->particles_ = 0; |
---|
107 | } |
---|
108 | |
---|
109 | if (Core::showsGraphics() && this->getScene() && this->getScene()->getSceneManager()) |
---|
110 | { |
---|
111 | try |
---|
112 | { |
---|
113 | this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), this->source_, this->LOD_); |
---|
114 | this->attachOgreObject(this->particles_->getParticleSystem()); |
---|
115 | this->particles_->setVisible(this->isVisible()); |
---|
116 | this->particles_->setEnabled(this->isActive()); |
---|
117 | } |
---|
118 | catch (...) |
---|
119 | { |
---|
120 | COUT(1) << "Error: Couln't load particle effect \"" << this->source_ << "\"" << std::endl; |
---|
121 | this->particles_ = 0; |
---|
122 | } |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | void ParticleEmitter::LODchanged() |
---|
127 | { |
---|
128 | if (this->particles_) |
---|
129 | this->particles_->setDetailLevel(this->LOD_); |
---|
130 | } |
---|
131 | } |
---|