Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/particleEngine: spread works, and many other functions implemented

File size: 3.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_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  ParticleConnection* tmpCon = new ParticleConnection;
85  tmpCon->emitter = emitter;
86  tmpCon->system = system;
87
88  this->connectionList->add(tmpCon);
89}
90
91
92bool ParticleEngine::removeSystem(ParticleSystem* system)
93{
94  this->systemList->remove(system);
95 
96}
97
98bool ParticleEngine::removeEmitter(ParticleEmitter* emitter)
99{
100  this->emitterList->remove(emitter);
101}
102
103
104/**
105   \brief this function ticks all the ParticleSystems, so an animation will flow
106   \param dt passed since last tick
107*/
108void ParticleEngine::tick(float dt)
109{
110  // add new Particles to each System they are connected to.
111  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
112  ParticleConnection* tmpConnection = tmpConIt->nextElement();
113  while(tmpConnection)
114    {
115      tmpConnection->emitter->tick(dt, tmpConnection->system);
116      tmpConnection = tmpConIt->nextElement();
117    }
118  delete tmpConIt;
119 
120
121  // ticks all the ParticleSystems
122  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
123  ParticleSystem* tmpSys = tmpIt->nextElement();
124  while(tmpSys)
125    {
126      tmpSys->tick(dt);
127      tmpSys = tmpIt->nextElement();
128    }
129  delete tmpIt;
130
131}
132
133
134void ParticleEngine::draw(void)
135{
136  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
137  ParticleSystem* tmpSys = tmpIt->nextElement();
138  while(tmpSys)
139    {
140      tmpSys->draw();
141      tmpSys = tmpIt->nextElement();
142    }
143  delete tmpIt;
144
145}
Note: See TracBrowser for help on using the repository browser.