Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/particleEngine/src/lib/graphics/particles/particle_engine.cc @ 3943

Last change on this file since 3943 was 3943, checked in by bensch, 19 years ago

orxonox/branches/particleEngine: now the ParticleSystem/Emitter should get deleted nicely

File size: 5.0 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: ...
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PARTICLE
17
18#include "particle_engine.h"
19
20#include "particle_system.h"
21#include "particle_emitter.h"
22
23#include "list.h"
24
25using namespace std;
26
27/**
28   \brief standard constructor
29*/
30ParticleEngine::ParticleEngine () 
31{
32   this->setClassName ("ParticleEngine");
33
34   this->systemList = new tList<ParticleSystem>;
35   this->emitterList = new tList<ParticleEmitter>;
36   this->connectionList = new tList<ParticleConnection>;
37}
38
39/**
40   \brief the singleton reference to this class
41*/
42ParticleEngine* ParticleEngine::singletonRef = NULL;
43
44/**
45   \returns a Pointer to this Class
46*/
47ParticleEngine* ParticleEngine::getInstance(void)
48{
49  if (!ParticleEngine::singletonRef)
50    ParticleEngine::singletonRef = new ParticleEngine();
51  return ParticleEngine::singletonRef;
52}
53
54/**
55   \brief standard destructor
56
57*/
58ParticleEngine::~ParticleEngine () 
59{
60  delete this->systemList;
61
62  delete this->connectionList;
63
64  ParticleEngine::singletonRef = NULL;
65}
66
67void ParticleEngine::addSystem(ParticleSystem* system)
68{
69  this->systemList->add(system);
70}
71
72void ParticleEngine::addEmitter(ParticleEmitter* emitter)
73{
74  this->emitterList->add(emitter);
75}
76
77/**
78   \brief
79
80   \todo header, check for double connections
81*/
82void ParticleEngine::addConnection(ParticleEmitter* emitter, ParticleSystem* system)
83{
84  // look, if we have already added this connection
85  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
86  ParticleConnection* tmpConnection = tmpConIt->nextElement();
87  while(tmpConnection)
88    {
89      if (tmpConnection->emitter == emitter && tmpConnection->system == system)
90        {
91          PRINTF(2)("Connection between Emitter and System already added\n");
92          delete tmpConIt;
93          return;
94        }
95     
96      tmpConnection = tmpConIt->nextElement();
97    }
98  delete tmpConIt;
99 
100
101
102  ParticleConnection* tmpCon = new ParticleConnection;
103  tmpCon->emitter = emitter;
104  tmpCon->system = system;
105
106  this->connectionList->add(tmpCon);
107}
108
109
110bool ParticleEngine::removeSystem(ParticleSystem* system)
111{
112  // remove any connections, that have this system within
113  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
114  ParticleConnection* tmpConnection = tmpConIt->nextElement();
115  while(tmpConnection)
116    {
117      if (tmpConnection->system == system)
118        this->breakConnection(tmpConnection);
119      tmpConnection = tmpConIt->nextElement();
120    }
121  delete tmpConIt;
122
123  // remove the System from the systemList.
124  this->systemList->remove(system);
125}
126
127bool ParticleEngine::removeEmitter(ParticleEmitter* emitter)
128{
129  // remove any connections, that have this emitter within
130  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
131  ParticleConnection* tmpConnection = tmpConIt->nextElement();
132  while(tmpConnection)
133    {
134      if (tmpConnection->emitter == emitter)
135        this->breakConnection(tmpConnection);
136      tmpConnection = tmpConIt->nextElement();
137    }
138  delete tmpConIt;
139
140  // remove the emitter from the emitterList
141  this->emitterList->remove(emitter);
142}
143
144
145bool ParticleEngine::breakConnection(ParticleEmitter* emitter, ParticleSystem* system)
146{
147  // look, if we have already added this connection
148  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
149  ParticleConnection* tmpConnection = tmpConIt->nextElement();
150  while(tmpConnection)
151    {
152      if (tmpConnection->emitter == emitter && tmpConnection->system == system)
153        this->breakConnection(tmpConnection);
154      tmpConnection = tmpConIt->nextElement();
155    }
156  delete tmpConIt; 
157}
158
159bool ParticleEngine::breakConnection(ParticleConnection* connection)
160{
161  this->connectionList->remove(connection);
162}
163
164
165/**
166   \brief this function ticks all the ParticleSystems, so an animation will flow
167   \param dt passed since last tick
168*/
169void ParticleEngine::tick(float dt)
170{
171  // add new Particles to each System they are connected to.
172  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
173  ParticleConnection* tmpConnection = tmpConIt->nextElement();
174  while(tmpConnection)
175    {
176      tmpConnection->emitter->tick(dt, tmpConnection->system);
177      tmpConnection = tmpConIt->nextElement();
178    }
179  delete tmpConIt;
180 
181
182  // ticks all the ParticleSystems
183  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
184  ParticleSystem* tmpSys = tmpIt->nextElement();
185  while(tmpSys)
186    {
187      tmpSys->tick(dt);
188      tmpSys = tmpIt->nextElement();
189    }
190  delete tmpIt;
191}
192
193
194void ParticleEngine::draw(void)
195{
196  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
197  ParticleSystem* tmpSys = tmpIt->nextElement();
198  while(tmpSys)
199    {
200      tmpSys->draw();
201      tmpSys = tmpIt->nextElement();
202    }
203  delete tmpIt;
204
205}
Note: See TracBrowser for help on using the repository browser.