Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/particleEngine: the first particles are being drawn :)

File size: 2.7 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
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
72
73/**
74   \brief
75
76   \todo header, check for double connections
77*/
78void ParticleEngine::addConnection(ParticleEmitter* emitter, ParticleSystem* system)
79{
80  ParticleConnection* tmpCon = new ParticleConnection;
81  tmpCon->emitter = emitter;
82  tmpCon->system = system;
83
84  this->connectionList->add(tmpCon);
85}
86
87
88/**
89   \brief this function ticks all the ParticleSystems, so an animation will flow
90   \param dt passed since last tick
91*/
92void ParticleEngine::tick(float dt)
93{
94  // add new Particles to each System they are connected to.
95  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
96  ParticleConnection* tmpConnection = tmpConIt->nextElement();
97  while(tmpConnection)
98    {
99      tmpConnection->emitter->tick(dt, tmpConnection->system);
100      tmpConnection = tmpConIt->nextElement();
101    }
102  delete tmpConIt;
103 
104
105  // ticks all the ParticleSystems
106  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
107  ParticleSystem* tmpSys = tmpIt->nextElement();
108  while(tmpSys)
109    {
110      tmpSys->tick(dt);
111      tmpSys = tmpIt->nextElement();
112    }
113  delete tmpIt;
114
115}
116
117
118void ParticleEngine::draw(void)
119{
120  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
121  ParticleSystem* tmpSys = tmpIt->nextElement();
122  while(tmpSys)
123    {
124      tmpSys->draw();
125      tmpSys = tmpIt->nextElement();
126    }
127  delete tmpIt;
128
129}
Note: See TracBrowser for help on using the repository browser.