Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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