[1505] | 1 | /* |
---|
[2087] | 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 | */ |
---|
[1505] | 28 | |
---|
| 29 | /** |
---|
[2171] | 30 | * @file |
---|
[1505] | 31 | * @brief class to control praticle effects |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "ParticleInterface.h" |
---|
| 35 | |
---|
[3196] | 36 | #include <cassert> |
---|
| 37 | #include <string> |
---|
[1552] | 38 | #include <OgreParticleSystem.h> |
---|
| 39 | #include <OgreParticleEmitter.h> |
---|
| 40 | #include <OgreSceneManager.h> |
---|
[1505] | 41 | |
---|
[3196] | 42 | #include "util/Convert.h" |
---|
| 43 | #include "util/Math.h" |
---|
| 44 | #include "core/CoreIncludes.h" |
---|
[3336] | 45 | #include "core/ConfigValueIncludes.h" |
---|
[3196] | 46 | #include "core/GameMode.h" |
---|
[2896] | 47 | #include "GraphicsManager.h" |
---|
[1505] | 48 | |
---|
[1552] | 49 | namespace orxonox |
---|
| 50 | { |
---|
[2087] | 51 | unsigned int ParticleInterface::counter_s = 0; |
---|
| 52 | ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; |
---|
[1505] | 53 | |
---|
[3280] | 54 | ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::Value detaillevel) |
---|
[2087] | 55 | { |
---|
[2662] | 56 | RegisterObject(ParticleInterface); |
---|
[1563] | 57 | |
---|
[2087] | 58 | assert(scenemanager); |
---|
[1563] | 59 | |
---|
[2087] | 60 | this->scenemanager_ = scenemanager; |
---|
[2171] | 61 | this->particleSystem_ = 0; |
---|
[2087] | 62 | |
---|
| 63 | this->bEnabled_ = true; |
---|
| 64 | this->bVisible_ = true; |
---|
| 65 | this->bAllowedByLOD_ = true; |
---|
[2662] | 66 | this->speedFactor_ = 1.0f; |
---|
[2087] | 67 | |
---|
[2896] | 68 | if (GameMode::showsGraphics()) |
---|
[2171] | 69 | { |
---|
| 70 | try |
---|
| 71 | { |
---|
[3280] | 72 | this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + multi_cast<std::string>(ParticleInterface::counter_s++), templateName); |
---|
[2662] | 73 | this->setSpeedFactor(1.0f); |
---|
[2171] | 74 | } |
---|
| 75 | catch (...) |
---|
| 76 | { |
---|
| 77 | COUT(1) << "Error: Couln't load particle system \"" << templateName << "\"" << std::endl; |
---|
| 78 | this->particleSystem_ = 0; |
---|
| 79 | } |
---|
| 80 | } |
---|
[2087] | 81 | |
---|
[3301] | 82 | this->setDetailLevel(static_cast<unsigned int>(detaillevel)); |
---|
[2087] | 83 | } |
---|
| 84 | |
---|
| 85 | ParticleInterface::~ParticleInterface() |
---|
[1563] | 86 | { |
---|
[2171] | 87 | if (this->particleSystem_) |
---|
| 88 | { |
---|
| 89 | this->particleSystem_->removeAllEmitters(); |
---|
| 90 | this->scenemanager_->destroyParticleSystem(this->particleSystem_); |
---|
| 91 | } |
---|
[1563] | 92 | } |
---|
[2087] | 93 | |
---|
[3336] | 94 | void ParticleInterface::setConfigValues() |
---|
| 95 | { |
---|
| 96 | SetConfigValue(globalDetailLevel_, 2) |
---|
| 97 | .description("O: off, 1: low, 2: normal, 3: high").callback(this, &ParticleInterface::detailLevelChanged); |
---|
| 98 | } |
---|
| 99 | |
---|
[2087] | 100 | Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() |
---|
| 101 | { |
---|
[2171] | 102 | if (this->particleSystem_ && this->particleSystem_->getNumEmitters() > 0) |
---|
[2087] | 103 | { |
---|
| 104 | Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); |
---|
| 105 | this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); |
---|
| 106 | return newemitter; |
---|
| 107 | } |
---|
| 108 | else |
---|
| 109 | return 0; |
---|
| 110 | } |
---|
| 111 | Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const |
---|
| 112 | { |
---|
[2171] | 113 | if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters())) |
---|
[2087] | 114 | return this->particleSystem_->getEmitter(emitterNr); |
---|
| 115 | else |
---|
| 116 | return 0; |
---|
| 117 | } |
---|
| 118 | void ParticleInterface::removeEmitter(unsigned int emitterNr) |
---|
| 119 | { |
---|
[2171] | 120 | if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters())) |
---|
[2087] | 121 | this->particleSystem_->removeEmitter(emitterNr); |
---|
| 122 | } |
---|
| 123 | void ParticleInterface::removeAllEmitters() |
---|
| 124 | { |
---|
[2171] | 125 | if (this->particleSystem_) |
---|
| 126 | this->particleSystem_->removeAllEmitters(); |
---|
[2087] | 127 | } |
---|
| 128 | unsigned int ParticleInterface::getNumEmitters() const |
---|
| 129 | { |
---|
[2171] | 130 | if (this->particleSystem_) |
---|
| 131 | return this->particleSystem_->getNumEmitters(); |
---|
| 132 | else |
---|
| 133 | return 0; |
---|
[2087] | 134 | } |
---|
[1505] | 135 | |
---|
[2087] | 136 | Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) |
---|
[1552] | 137 | { |
---|
[2171] | 138 | if (this->particleSystem_) |
---|
| 139 | return this->particleSystem_->addAffector(name); |
---|
| 140 | else |
---|
| 141 | return 0; |
---|
[1552] | 142 | } |
---|
[3196] | 143 | Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) |
---|
[2087] | 144 | { |
---|
[2171] | 145 | if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors())) |
---|
[2087] | 146 | return this->particleSystem_->getAffector(affectorNr); |
---|
| 147 | else |
---|
| 148 | return 0; |
---|
| 149 | } |
---|
| 150 | void ParticleInterface::removeAffector(unsigned int affectorNr) |
---|
| 151 | { |
---|
[2171] | 152 | if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors())) |
---|
[2087] | 153 | this->particleSystem_->removeAffector(affectorNr); |
---|
| 154 | } |
---|
| 155 | void ParticleInterface::removeAllAffectors() |
---|
| 156 | { |
---|
[2171] | 157 | if (this->particleSystem_) |
---|
| 158 | this->particleSystem_->removeAllAffectors(); |
---|
[2087] | 159 | } |
---|
| 160 | unsigned int ParticleInterface::getNumAffectors() const |
---|
| 161 | { |
---|
[2171] | 162 | if (this->particleSystem_) |
---|
| 163 | return this->particleSystem_->getNumAffectors(); |
---|
| 164 | else |
---|
| 165 | return 0; |
---|
[2087] | 166 | } |
---|
[1505] | 167 | |
---|
[2087] | 168 | void ParticleInterface::setEnabled(bool enable) |
---|
[1552] | 169 | { |
---|
[2087] | 170 | this->bEnabled_ = enable; |
---|
| 171 | |
---|
[2171] | 172 | if (this->particleSystem_) |
---|
| 173 | for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) |
---|
| 174 | this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_); |
---|
[1505] | 175 | } |
---|
| 176 | |
---|
[2087] | 177 | void ParticleInterface::setVisible(bool visible) |
---|
| 178 | { |
---|
| 179 | this->bVisible_ = visible; |
---|
[1505] | 180 | |
---|
[2171] | 181 | if (this->particleSystem_) |
---|
| 182 | this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); |
---|
[2087] | 183 | } |
---|
[1563] | 184 | |
---|
[2087] | 185 | void ParticleInterface::setDetailLevel(unsigned int level) |
---|
| 186 | { |
---|
| 187 | this->detaillevel_ = level; |
---|
[2896] | 188 | if (GameMode::showsGraphics()) |
---|
[3336] | 189 | this->detailLevelChanged(); |
---|
[2087] | 190 | } |
---|
[1563] | 191 | |
---|
[3336] | 192 | void ParticleInterface::detailLevelChanged() |
---|
[2087] | 193 | { |
---|
[3336] | 194 | if (this->globalDetailLevel_ >= this->detaillevel_) |
---|
[2087] | 195 | this->bAllowedByLOD_ = true; |
---|
| 196 | else |
---|
| 197 | this->bAllowedByLOD_ = false; |
---|
[1563] | 198 | |
---|
[2087] | 199 | this->updateVisibility(); |
---|
| 200 | } |
---|
[1505] | 201 | |
---|
[2087] | 202 | void ParticleInterface::updateVisibility() |
---|
| 203 | { |
---|
| 204 | this->setEnabled(this->isEnabled()); |
---|
| 205 | this->setVisible(this->isVisible()); |
---|
| 206 | } |
---|
[1505] | 207 | |
---|
[2087] | 208 | void ParticleInterface::setSpeedFactor(float factor) |
---|
| 209 | { |
---|
[2662] | 210 | this->speedFactor_ = factor; |
---|
| 211 | |
---|
[2171] | 212 | if (this->particleSystem_) |
---|
[2662] | 213 | this->particleSystem_->setSpeedFactor(factor * this->getTimeFactor()); |
---|
[2087] | 214 | } |
---|
[2662] | 215 | void ParticleInterface::changedTimeFactor(float factor_new, float factor_old) |
---|
[2087] | 216 | { |
---|
[2662] | 217 | this->setSpeedFactor(this->speedFactor_); |
---|
[2087] | 218 | } |
---|
| 219 | |
---|
| 220 | bool ParticleInterface::getKeepParticlesInLocalSpace() const |
---|
| 221 | { |
---|
[2171] | 222 | if (this->particleSystem_) |
---|
| 223 | return this->particleSystem_->getKeepParticlesInLocalSpace(); |
---|
| 224 | else |
---|
| 225 | return false; |
---|
[2087] | 226 | } |
---|
| 227 | void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) |
---|
| 228 | { |
---|
[2171] | 229 | if (this->particleSystem_) |
---|
| 230 | this->particleSystem_->setKeepParticlesInLocalSpace(keep); |
---|
[2087] | 231 | } |
---|
[1505] | 232 | } |
---|