Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/brnaches/particleEngine: multiple emitions into one ParticleSystem

File size: 3.5 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_WORLD_ENTITY
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  this->systemList->remove(system);
113}
114
115bool ParticleEngine::removeEmitter(ParticleEmitter* emitter)
116{
117  this->emitterList->remove(emitter);
118}
119
120
121/**
122   \brief this function ticks all the ParticleSystems, so an animation will flow
123   \param dt passed since last tick
124*/
125void ParticleEngine::tick(float dt)
126{
127  // add new Particles to each System they are connected to.
128  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
129  ParticleConnection* tmpConnection = tmpConIt->nextElement();
130  while(tmpConnection)
131    {
132      tmpConnection->emitter->tick(dt, tmpConnection->system);
133      tmpConnection = tmpConIt->nextElement();
134    }
135  delete tmpConIt;
136 
137
138  // ticks all the ParticleSystems
139  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
140  ParticleSystem* tmpSys = tmpIt->nextElement();
141  while(tmpSys)
142    {
143      tmpSys->tick(dt);
144      tmpSys = tmpIt->nextElement();
145    }
146  delete tmpIt;
147
148}
149
150
151void ParticleEngine::draw(void)
152{
153  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
154  ParticleSystem* tmpSys = tmpIt->nextElement();
155  while(tmpSys)
156    {
157      tmpSys->draw();
158      tmpSys = tmpIt->nextElement();
159    }
160  delete tmpIt;
161
162}
Note: See TracBrowser for help on using the repository browser.