Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9947 was 9946, checked in by landauf, 11 years ago

removed debug output

  • Property svn:eol-style set to native
File size: 14.0 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{
[9667]43    RegisterClass(BigExplosion);
[3087]44
[9939]45    BigExplosion::BigExplosion(Context* context) : MobileEntity(context)
[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
[9939]80    BigExplosion::BigExplosion(Context* context, Vector3 initVelocity) : MobileEntity(context)
81    {
82        RegisterObject(BigExplosion);
83        this->setVelocity(initVelocity);
84
85        if ( GameMode::showsGraphics() && ( !this->getScene() || !this->getScene()->getSceneManager() ) )
86            ThrowException(AbortLoading, "Can't create BigExplosion, no scene or no scene manager given.");
87
88        this->bStop_ = false;
89        this->LOD_ = LODParticle::Normal;
90
91        if ( GameMode::showsGraphics() )
92        {
93            try
94            {
95                this->init();
96            }
97            catch (const std::exception& ex)
98            {
99                orxout(internal_error) << "Couldn't load particle effect in BigExplosion: " << ex.what() << endl;
100                this->initZero();
101            }
102        }
103        else
104        {
105            this->initZero();
106        }
107
108        if (GameMode::isMaster())
109        {
110            this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&BigExplosion::stop, this)));
111        }
112
113        this->registerVariables();
114    }
115
[3087]116    void BigExplosion::init()
117    {
[9667]118        this->debrisEntity1_ = new MovableEntity(this->getContext());
119        this->debrisEntity2_ = new MovableEntity(this->getContext());
120        this->debrisEntity3_ = new MovableEntity(this->getContext());
121        this->debrisEntity4_ = new MovableEntity(this->getContext());
[7176]122
[7163]123        this->debrisEntity1_->setSyncMode(0);
124        this->debrisEntity2_->setSyncMode(0);
125        this->debrisEntity3_->setSyncMode(0);
126        this->debrisEntity4_->setSyncMode(0);
[3087]127
[9667]128        this->debris1_ = new Model(this->getContext());
129        this->debris2_ = new Model(this->getContext());
130        this->debris3_ = new Model(this->getContext());
131        this->debris4_ = new Model(this->getContext());
[7176]132
[7163]133        this->debris1_->setSyncMode(0);
134        this->debris2_->setSyncMode(0);
135        this->debris3_->setSyncMode(0);
136        this->debris4_->setSyncMode(0);
[3087]137
[9939]138        this->explosion_ = new MobileEntity(this->getContext());
[7163]139        this->explosion_->setSyncMode(0);
[3087]140
141        this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
142        this->debrisSmoke2_ =  new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
143        this->debrisSmoke3_ =  new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
144        this->debrisSmoke4_ =  new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
145
146        this->debrisFire1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
147        this->debrisFire2_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
148        this->debrisFire3_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
149        this->debrisFire4_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
150
151        this->debris1_->attachOgreObject(this->debrisSmoke1_->getParticleSystem());
152        this->debris1_->attachOgreObject(this->debrisFire1_->getParticleSystem());
153        this->debris2_->attachOgreObject(this->debrisSmoke2_->getParticleSystem());
154        this->debris2_->attachOgreObject(this->debrisFire2_->getParticleSystem());
155        this->debris3_->attachOgreObject(this->debrisSmoke3_->getParticleSystem());
156        this->debris3_->attachOgreObject(this->debrisFire3_->getParticleSystem());
157        this->debris4_->attachOgreObject(this->debrisSmoke4_->getParticleSystem());
158        this->debris4_->attachOgreObject(this->debrisFire4_->getParticleSystem());
159
160        this->debris1_->setMeshSource("CockpitDebris.mesh");
161        this->debris2_->setMeshSource("WingDebris1.mesh");
162        this->debris3_->setMeshSource("BodyDebris1.mesh");
163        this->debris4_->setMeshSource("WingDebris2.mesh");
164
165        this->debrisEntity1_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
166        this->debrisEntity1_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
167        this->debrisEntity1_->setScale(4);
168
169        this->debrisEntity2_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
170        this->debrisEntity2_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
171        this->debrisEntity2_->setScale(4);
172
173        this->debrisEntity3_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
174        this->debrisEntity3_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
175        this->debrisEntity3_->setScale(4);
176
177        this->debrisEntity4_->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(50,100));
178        this->debrisEntity4_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
179        this->debrisEntity4_->setScale(4);
180
181        this->debrisEntity1_->attach(debris1_);
182        this->debrisEntity2_->attach(debris2_);
183        this->debrisEntity3_->attach(debris3_);
184        this->debrisEntity4_->attach(debris4_);
185
[9939]186        // ///////////////////////
187        // TODO: particleSpawner is a static entity. It should probably be dynamic, for better explosions.
188        //
[9667]189        ParticleSpawner* effect = new ParticleSpawner(this->getContext());
[9939]190        // effect->setVelocity(this->getVelocity());
[3087]191        effect->setDestroyAfterLife(true);
192        effect->setSource("Orxonox/explosion2b");
193        effect->setLifetime(4.0f);
[7163]194        effect->setSyncMode(0);
[3087]195
[9667]196        ParticleSpawner* effect2 = new ParticleSpawner(this->getContext());
[9939]197        // effect2->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10, 200));
[3087]198        effect2->setDestroyAfterLife(true);
199        effect2->setSource("Orxonox/smoke6");
200        effect2->setLifetime(4.0f);
[7163]201        effect2->setSyncMode(0);
[3087]202
203        this->explosion_->attach(effect);
204        this->explosion_->attach(effect2);
205
206        this->attach(explosion_);
207        this->attach(debrisEntity1_);
208        this->attach(debrisEntity2_);
209        this->attach(debrisEntity3_);
210        this->attach(debrisEntity4_);
211
212
213        for(int i=0;i<10;i++)
214        {
[9667]215            Model* part1 = new Model(this->getContext());
216            Model* part2 = new Model(this->getContext());
[3087]217
[9667]218            MovableEntity* partEntity1 = new MovableEntity(this->getContext());
219            MovableEntity* partEntity2 = new MovableEntity(this->getContext());
[7176]220
[7163]221            part1->setSyncMode(0);
222            part2->setSyncMode(0);
223            partEntity1->setSyncMode(0);
224            partEntity2->setSyncMode(0);
[3087]225
226            partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100));
227            partEntity1->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
228            partEntity1->setScale(rnd(1, 3));
229
230            partEntity2->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10, 100));
231            partEntity2->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians());
232            partEntity2->setScale(rnd(1, 3));
233
234            part1->setMeshSource("SmallPart1.mesh");
235            part2->setMeshSource("SmallPart2.mesh");
236
237            partEntity1->attach(part1);
238            partEntity2->attach(part2);
239
240            this->attach(partEntity1);
241            this->attach(partEntity2);
242        }
243    }
244
245    void BigExplosion::initZero()
246    {
247        this->debrisFire1_ = 0;
248        this->debrisFire2_ = 0;
249        this->debrisFire3_ = 0;
250        this->debrisFire4_ = 0;
251
252        this->debrisSmoke1_ = 0;
253        this->debrisSmoke2_ = 0;
254        this->debrisSmoke3_ = 0;
255        this->debrisSmoke4_ = 0;
256
257        this->explosionSmoke_=0;
258        this->explosionFire_=0;
259    }
260
261    BigExplosion::~BigExplosion()
262    {
263        if (this->isInitialized())
264        {
265            if (this->debrisFire1_)
266            {
267                this->debris1_->detachOgreObject(this->debrisFire1_->getParticleSystem());
[9667]268                delete this->debrisFire1_;
[3087]269            }
270            if (this->debrisSmoke1_)
271            {
272                this->debris1_->detachOgreObject(this->debrisSmoke1_->getParticleSystem());
[9667]273                delete this->debrisSmoke1_;
[3087]274            }
275
276            if (this->debrisFire2_)
277            {
278                this->debris2_->detachOgreObject(this->debrisFire2_->getParticleSystem());
[9667]279                delete this->debrisFire2_;
[3087]280            }
281            if (this->debrisSmoke2_)
282            {
283                this->debris2_->detachOgreObject(this->debrisSmoke2_->getParticleSystem());
[9667]284                delete this->debrisSmoke2_;
[3087]285            }
286
287            if (this->debrisFire3_)
288            {
289                this->debris3_->detachOgreObject(this->debrisFire3_->getParticleSystem());
[9667]290                delete this->debrisFire3_;
[3087]291            }
292            if (this->debrisSmoke3_)
293            {
294                this->debris3_->detachOgreObject(this->debrisSmoke3_->getParticleSystem());
[9667]295                delete this->debrisSmoke3_;
[3087]296            }
297
298            if (this->debrisFire4_)
299            {
300                this->debris4_->detachOgreObject(this->debrisFire4_->getParticleSystem());
[9667]301                delete this->debrisFire4_;
[3087]302            }
303            if (this->debrisSmoke4_)
304            {
305                this->debris4_->detachOgreObject(this->debrisSmoke4_->getParticleSystem());
[9667]306                delete this->debrisSmoke4_;
[3087]307            }
308        }
309    }
310
311    void BigExplosion::registerVariables()
312    {
[3280]313        registerVariable((int&)(this->LOD_), VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::LODchanged));
314        registerVariable(this->bStop_,       VariableDirection::ToClient, new NetworkCallback<BigExplosion>(this, &BigExplosion::checkStop));
[3087]315    }
316
317    void BigExplosion::LODchanged()
318    {
319        if (this->debrisFire1_)
320            this->debrisFire1_->setDetailLevel(this->LOD_);
321        if (this->debrisSmoke1_)
322            this->debrisSmoke1_->setDetailLevel(this->LOD_);
323
324        if (this->debrisFire2_)
325            this->debrisFire2_->setDetailLevel(this->LOD_);
326        if (this->debrisSmoke2_)
327            this->debrisSmoke2_->setDetailLevel(this->LOD_);
328
329        if (this->debrisFire3_)
330            this->debrisFire3_->setDetailLevel(this->LOD_);
331        if (this->debrisSmoke3_)
332            this->debrisSmoke3_->setDetailLevel(this->LOD_);
333
334        if (this->debrisFire4_)
335            this->debrisFire4_->setDetailLevel(this->LOD_);
336        if (this->debrisSmoke4_)
337            this->debrisSmoke4_->setDetailLevel(this->LOD_);
338    }
339
340    void BigExplosion::checkStop()
341    {
342        if (this->bStop_)
343            this->stop();
344    }
345
346    void BigExplosion::stop()
347    {
348        if (this->debrisFire1_)
349            this->debrisFire1_->setEnabled(false);
350        if (this->debrisSmoke1_)
351            this->debrisSmoke1_->setEnabled(false);
352
353        if (this->debrisFire2_)
354            this->debrisFire2_->setEnabled(false);
355        if (this->debrisSmoke2_)
356            this->debrisSmoke2_->setEnabled(false);
357
358        if (this->debrisFire3_)
359            this->debrisFire3_->setEnabled(false);
360        if (this->debrisSmoke3_)
361            this->debrisSmoke3_->setEnabled(false);
362
363        if (this->debrisFire4_)
364            this->debrisFire4_->setEnabled(false);
365        if (this->debrisSmoke4_)
366            this->debrisSmoke4_->setEnabled(false);
367
368        if (GameMode::isMaster())
369        {
370            this->bStop_ = true;
[5929]371            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&BigExplosion::destroy, this)));
[3087]372        }
373    }
374
375/* TODO
376
377    void BigExplosion::setDebrisMeshes()
378    {
379
380    }
381    void BigExplosion::getDebrisMeshes()
382    {
383
384    }
385*/
386}
Note: See TracBrowser for help on using the repository browser.