Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/tools/ParticleInterface.cc @ 9365

Last change on this file since 9365 was 8858, checked in by landauf, 13 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

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