[3655] | 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 | |
---|
[3924] | 18 | #include "particle_engine.h" |
---|
[3655] | 19 | |
---|
[3931] | 20 | #include "particle_system.h" |
---|
| 21 | #include "particle_emitter.h" |
---|
| 22 | |
---|
[3930] | 23 | #include "list.h" |
---|
| 24 | |
---|
[3655] | 25 | using namespace std; |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | \brief standard constructor |
---|
| 29 | */ |
---|
[3923] | 30 | ParticleEngine::ParticleEngine () |
---|
[3655] | 31 | { |
---|
[3923] | 32 | this->setClassName ("ParticleEngine"); |
---|
[3655] | 33 | |
---|
[3931] | 34 | this->systemList = new tList<ParticleSystem>; |
---|
[3935] | 35 | this->emitterList = new tList<ParticleEmitter>; |
---|
[3932] | 36 | this->connectionList = new tList<ParticleConnection>; |
---|
[3655] | 37 | } |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | \brief the singleton reference to this class |
---|
| 41 | */ |
---|
[3923] | 42 | ParticleEngine* ParticleEngine::singletonRef = NULL; |
---|
[3655] | 43 | |
---|
| 44 | /** |
---|
| 45 | \returns a Pointer to this Class |
---|
| 46 | */ |
---|
[3923] | 47 | ParticleEngine* ParticleEngine::getInstance(void) |
---|
[3655] | 48 | { |
---|
[3923] | 49 | if (!ParticleEngine::singletonRef) |
---|
| 50 | ParticleEngine::singletonRef = new ParticleEngine(); |
---|
| 51 | return ParticleEngine::singletonRef; |
---|
[3655] | 52 | } |
---|
| 53 | |
---|
| 54 | /** |
---|
[3923] | 55 | \brief standard destructor |
---|
[3655] | 56 | |
---|
| 57 | */ |
---|
[3923] | 58 | ParticleEngine::~ParticleEngine () |
---|
[3655] | 59 | { |
---|
[3931] | 60 | delete this->systemList; |
---|
[3930] | 61 | |
---|
[3932] | 62 | delete this->connectionList; |
---|
[3930] | 63 | |
---|
[3923] | 64 | ParticleEngine::singletonRef = NULL; |
---|
[3655] | 65 | } |
---|
[3931] | 66 | |
---|
[3932] | 67 | void ParticleEngine::addSystem(ParticleSystem* system) |
---|
| 68 | { |
---|
| 69 | this->systemList->add(system); |
---|
| 70 | } |
---|
| 71 | |
---|
[3935] | 72 | void ParticleEngine::addEmitter(ParticleEmitter* emitter) |
---|
| 73 | { |
---|
| 74 | this->emitterList->add(emitter); |
---|
| 75 | } |
---|
[3932] | 76 | |
---|
[3931] | 77 | /** |
---|
[3932] | 78 | \brief |
---|
| 79 | |
---|
| 80 | \todo header, check for double connections |
---|
| 81 | */ |
---|
| 82 | void ParticleEngine::addConnection(ParticleEmitter* emitter, ParticleSystem* system) |
---|
| 83 | { |
---|
[3937] | 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 | |
---|
[3932] | 102 | ParticleConnection* tmpCon = new ParticleConnection; |
---|
| 103 | tmpCon->emitter = emitter; |
---|
| 104 | tmpCon->system = system; |
---|
| 105 | |
---|
| 106 | this->connectionList->add(tmpCon); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
[3935] | 110 | bool ParticleEngine::removeSystem(ParticleSystem* system) |
---|
| 111 | { |
---|
| 112 | this->systemList->remove(system); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | bool ParticleEngine::removeEmitter(ParticleEmitter* emitter) |
---|
| 116 | { |
---|
| 117 | this->emitterList->remove(emitter); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | |
---|
[3932] | 121 | /** |
---|
[3931] | 122 | \brief this function ticks all the ParticleSystems, so an animation will flow |
---|
| 123 | \param dt passed since last tick |
---|
| 124 | */ |
---|
| 125 | void ParticleEngine::tick(float dt) |
---|
| 126 | { |
---|
[3932] | 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 |
---|
[3931] | 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 | } |
---|
[3932] | 149 | |
---|
| 150 | |
---|
| 151 | void 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 | } |
---|