Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/worldentities/BigExplosion.cc @ 9023

Last change on this file since 9023 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: 12.5 KB
RevLine 
[3087]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 *      Benjamin de Capitani
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "BigExplosion.h"
30
[3196]31#include "util/Exception.h"
[3087]32#include "core/CoreIncludes.h"
[3196]33#include "core/GameMode.h"
[7284]34#include "core/command/Executor.h"
[3196]35#include "tools/ParticleInterface.h"
[5735]36#include "Scene.h"
[5737]37#include "graphics/ParticleSpawner.h"
38#include "graphics/Model.h"
[7176]39#include "MovableEntity.h"
[3087]40
41namespace orxonox
42{
43    CreateFactory(BigExplosion);
44
[7176]45    BigExplosion::BigExplosion(BaseObject* creator) : StaticEntity(creator)
[3087]46    {
47        RegisterObject(BigExplosion);
48
49        if ( GameMode::showsGraphics() && ( !this->getScene() || !this->getScene()->getSceneManager() ) )
50            ThrowException(AbortLoading, "Can't create BigExplosion, no scene or no scene manager given.");
[7176]51
[3087]52        this->bStop_ = false;
[3280]53        this->LOD_ = LODParticle::Normal;
[3087]54
55        if ( GameMode::showsGraphics() )
56        {
57            try
58            {
59                this->init();
60            }
[7174]61            catch (const std::exception& ex)
[3087]62            {
[8858]63                orxout(internal_error) << "Couldn't load particle effect in BigExplosion: " << ex.what() << endl;
[3087]64                this->initZero();
65            }
66        }
67        else
68        {
69            this->initZero();
70        }
71
72        if (GameMode::isMaster())
73        {
[5929]74            this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&BigExplosion::stop, this)));
[3087]75        }
[7176]76
[3087]77        this->registerVariables();
78    }
79
80    void BigExplosion::init()
81    {
[5747]82        this->debrisEntity1_ = new MovableEntity(this);
83        this->debrisEntity2_ = new MovableEntity(this);
84        this->debrisEntity3_ = new MovableEntity(this);
85        this->debrisEntity4_ = new MovableEntity(this);
[7176]86
[7163]87        this->debrisEntity1_->setSyncMode(0);
88        this->debrisEntity2_->setSyncMode(0);
89        this->debrisEntity3_->setSyncMode(0);
90        this->debrisEntity4_->setSyncMode(0);
[3087]91
[5747]92        this->debris1_ = new Model(this);
93        this->debris2_ = new Model(this);
94        this->debris3_ = new Model(this);
95        this->debris4_ = new Model(this);
[7176]96
[7163]97        this->debris1_->setSyncMode(0);
98        this->debris2_->setSyncMode(0);
99        this->debris3_->setSyncMode(0);
100        this->debris4_->setSyncMode(0);
[3087]101
[5747]102        this->explosion_ = new StaticEntity(this);
[7163]103        this->explosion_->setSyncMode(0);
[3087]104
105        this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
106        this->debrisSmoke2_ =  new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
107        this->debrisSmoke3_ =  new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
108        this->debrisSmoke4_ =  new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
109
110        this->debrisFire1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
111        this->debrisFire2_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
112        this->debrisFire3_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
113        this->debrisFire4_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
114
115        this->debris1_->attachOgreObject(this->debrisSmoke1_->getParticleSystem());
116        this->debris1_->attachOgreObject(this->debrisFire1_->getParticleSystem());
117        this->debris2_->attachOgreObject(this->debrisSmoke2_->getParticleSystem());
118        this->debris2_->attachOgreObject(this->debrisFire2_->getParticleSystem());
119        this->debris3_->attachOgreObject(this->debrisSmoke3_->getParticleSystem());
120        this->debris3_->attachOgreObject(this->debrisFire3_->getParticleSystem());
121        this->debris4_->attachOgreObject(this->debrisSmoke4_->getParticleSystem());
122        this->debris4_->attachOgreObject(this->debrisFire4_->getParticleSystem());
123
124        this->debris1_->setMeshSource("CockpitDebris.mesh");
125        this->debris2_->setMeshSource("WingDebris1.mesh");
126        this->debris3_->setMeshSource("BodyDebris1.mesh");
127        this->debris4_->setMeshSource("WingDebris2.mesh");
128
129        this->debrisEntity1_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
130        this->debrisEntity1_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
131        this->debrisEntity1_->setScale(4);
132
133        this->debrisEntity2_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
134        this->debrisEntity2_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
135        this->debrisEntity2_->setScale(4);
136
137        this->debrisEntity3_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
138        this->debrisEntity3_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
139        this->debrisEntity3_->setScale(4);
140
141        this->debrisEntity4_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
142        this->debrisEntity4_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
143        this->debrisEntity4_->setScale(4);
144
145        this->debrisEntity1_->attach(debris1_);
146        this->debrisEntity2_->attach(debris2_);
147        this->debrisEntity3_->attach(debris3_);
148        this->debrisEntity4_->attach(debris4_);
149
150        ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
151        effect->setDestroyAfterLife(true);
152        effect->setSource("Orxonox/explosion2b");
153        effect->setLifetime(4.0f);
[7163]154        effect->setSyncMode(0);
[3087]155
156        ParticleSpawner* effect2 = new ParticleSpawner(this->getCreator());
157        effect2->setDestroyAfterLife(true);
158        effect2->setSource("Orxonox/smoke6");
159        effect2->setLifetime(4.0f);
[7163]160        effect2->setSyncMode(0);
[3087]161
162        this->explosion_->attach(effect);
163        this->explosion_->attach(effect2);
164
165        this->attach(explosion_);
166        this->attach(debrisEntity1_);
167        this->attach(debrisEntity2_);
168        this->attach(debrisEntity3_);
169        this->attach(debrisEntity4_);
170
171
172        for(int i=0;i<10;i++)
173        {
[5747]174            Model* part1 = new Model(this);
175            Model* part2 = new Model(this);
[3087]176
[5747]177            MovableEntity* partEntity1 = new MovableEntity(this);
178            MovableEntity* partEntity2 = new MovableEntity(this);
[7176]179
[7163]180            part1->setSyncMode(0);
181            part2->setSyncMode(0);
182            partEntity1->setSyncMode(0);
183            partEntity2->setSyncMode(0);
[3087]184
185            partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100));
186            partEntity1->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
187            partEntity1->setScale(rnd(1, 3));
188
189            partEntity2->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10, 100));
190            partEntity2->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
191            partEntity2->setScale(rnd(1, 3));
192
193            part1->setMeshSource("SmallPart1.mesh");
194            part2->setMeshSource("SmallPart2.mesh");
195
196            partEntity1->attach(part1);
197            partEntity2->attach(part2);
198
199            this->attach(partEntity1);
200            this->attach(partEntity2);
201        }
202    }
203
204    void BigExplosion::initZero()
205    {
206        this->debrisFire1_ = 0;
207        this->debrisFire2_ = 0;
208        this->debrisFire3_ = 0;
209        this->debrisFire4_ = 0;
210
211        this->debrisSmoke1_ = 0;
212        this->debrisSmoke2_ = 0;
213        this->debrisSmoke3_ = 0;
214        this->debrisSmoke4_ = 0;
215
216        this->explosionSmoke_=0;
217        this->explosionFire_=0;
218    }
219
220    BigExplosion::~BigExplosion()
221    {
222        if (this->isInitialized())
223        {
224            if (this->debrisFire1_)
225            {
226                this->debris1_->detachOgreObject(this->debrisFire1_->getParticleSystem());
[5929]227                this->debrisFire1_->destroy();
[3087]228            }
229            if (this->debrisSmoke1_)
230            {
231                this->debris1_->detachOgreObject(this->debrisSmoke1_->getParticleSystem());
[5929]232                this->debrisSmoke1_->destroy();
[3087]233            }
234
235            if (this->debrisFire2_)
236            {
237                this->debris2_->detachOgreObject(this->debrisFire2_->getParticleSystem());
[5929]238                this->debrisFire2_->destroy();
[3087]239            }
240            if (this->debrisSmoke2_)
241            {
242                this->debris2_->detachOgreObject(this->debrisSmoke2_->getParticleSystem());
[5929]243                this->debrisSmoke2_->destroy();
[3087]244            }
245
246            if (this->debrisFire3_)
247            {
248                this->debris3_->detachOgreObject(this->debrisFire3_->getParticleSystem());
[5929]249                this->debrisFire3_->destroy();
[3087]250            }
251            if (this->debrisSmoke3_)
252            {
253                this->debris3_->detachOgreObject(this->debrisSmoke3_->getParticleSystem());
[5929]254                this->debrisSmoke3_->destroy();
[3087]255            }
256
257            if (this->debrisFire4_)
258            {
259                this->debris4_->detachOgreObject(this->debrisFire4_->getParticleSystem());
[5929]260                this->debrisFire4_->destroy();
[3087]261            }
262            if (this->debrisSmoke4_)
263            {
264                this->debris4_->detachOgreObject(this->debrisSmoke4_->getParticleSystem());
[5929]265                this->debrisSmoke4_->destroy();
[3087]266            }
267        }
268    }
269
270    void BigExplosion::registerVariables()
271    {
[3280]272        registerVariable((int&)(this->LOD_), VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::LODchanged));
273        registerVariable(this->bStop_,       VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::checkStop));
[3087]274    }
275
276    void BigExplosion::LODchanged()
277    {
278        if (this->debrisFire1_)
279            this->debrisFire1_->setDetailLevel(this->LOD_);
280        if (this->debrisSmoke1_)
281            this->debrisSmoke1_->setDetailLevel(this->LOD_);
282
283        if (this->debrisFire2_)
284            this->debrisFire2_->setDetailLevel(this->LOD_);
285        if (this->debrisSmoke2_)
286            this->debrisSmoke2_->setDetailLevel(this->LOD_);
287
288        if (this->debrisFire3_)
289            this->debrisFire3_->setDetailLevel(this->LOD_);
290        if (this->debrisSmoke3_)
291            this->debrisSmoke3_->setDetailLevel(this->LOD_);
292
293        if (this->debrisFire4_)
294            this->debrisFire4_->setDetailLevel(this->LOD_);
295        if (this->debrisSmoke4_)
296            this->debrisSmoke4_->setDetailLevel(this->LOD_);
297    }
298
299    void BigExplosion::checkStop()
300    {
301        if (this->bStop_)
302            this->stop();
303    }
304
305    void BigExplosion::stop()
306    {
307        if (this->debrisFire1_)
308            this->debrisFire1_->setEnabled(false);
309        if (this->debrisSmoke1_)
310            this->debrisSmoke1_->setEnabled(false);
311
312        if (this->debrisFire2_)
313            this->debrisFire2_->setEnabled(false);
314        if (this->debrisSmoke2_)
315            this->debrisSmoke2_->setEnabled(false);
316
317        if (this->debrisFire3_)
318            this->debrisFire3_->setEnabled(false);
319        if (this->debrisSmoke3_)
320            this->debrisSmoke3_->setEnabled(false);
321
322        if (this->debrisFire4_)
323            this->debrisFire4_->setEnabled(false);
324        if (this->debrisSmoke4_)
325            this->debrisSmoke4_->setEnabled(false);
326
327        if (GameMode::isMaster())
328        {
329            this->bStop_ = true;
[5929]330            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&BigExplosion::destroy, this)));
[3087]331        }
332    }
333
334/* TODO
335
336    void BigExplosion::setDebrisMeshes()
337    {
338
339    }
340    void BigExplosion::getDebrisMeshes()
341    {
342
343    }
344*/
345}
Note: See TracBrowser for help on using the repository browser.