| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name particlemanager.cpp - The particle manager. */ |
| 11 |
// |
| 12 |
// (c) Copyright 2007-2008 by Jimmy Salmon and Francois Beerten |
| 13 |
// |
| 14 |
// This program is free software; you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation; only version 2 of the License. |
| 17 |
// |
| 18 |
// This program is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program; if not, write to the Free Software |
| 25 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
// 02111-1307, USA. |
| 27 |
// |
| 28 |
|
| 29 |
//@{ |
| 30 |
|
| 31 |
#include "stratagus.h" |
| 32 |
#include "particle.h" |
| 33 |
#include "video.h" |
| 34 |
#include "ui.h" |
| 35 |
|
| 36 |
|
| 37 |
CParticleManager ParticleManager; |
| 38 |
|
| 39 |
|
| 40 |
CParticleManager::CParticleManager() : |
| 41 |
vp(NULL), lastTicks(0) |
| 42 |
{ |
| 43 |
} |
| 44 |
|
| 45 |
CParticleManager::~CParticleManager() |
| 46 |
{ |
| 47 |
} |
| 48 |
|
| 49 |
void CParticleManager::init() |
| 50 |
{ |
| 51 |
} |
| 52 |
|
| 53 |
void CParticleManager::exit() |
| 54 |
{ |
| 55 |
ParticleManager.clear(); |
| 56 |
} |
| 57 |
|
| 58 |
void CParticleManager::clear() |
| 59 |
{ |
| 60 |
std::vector<CParticle *>::iterator i; |
| 61 |
for (i = particles.begin(); i != particles.end(); ++i) { |
| 62 |
delete *i; |
| 63 |
} |
| 64 |
particles.clear(); |
| 65 |
|
| 66 |
for (i = new_particles.begin(); i != new_particles.end(); ++i) { |
| 67 |
delete *i; |
| 68 |
} |
| 69 |
new_particles.clear(); |
| 70 |
} |
| 71 |
|
| 72 |
void CParticleManager::draw(const CViewport *vp) |
| 73 |
{ |
| 74 |
this->vp = vp; |
| 75 |
|
| 76 |
std::vector<CParticle *>::iterator i; |
| 77 |
for (i = particles.begin(); i != particles.end(); ++i) { |
| 78 |
(*i)->draw(); |
| 79 |
} |
| 80 |
|
| 81 |
this->vp = NULL; |
| 82 |
} |
| 83 |
|
| 84 |
void CParticleManager::update() |
| 85 |
{ |
| 86 |
unsigned long ticks = GetTicks() - lastTicks; |
| 87 |
std::vector<CParticle *>::iterator i; |
| 88 |
|
| 89 |
particles.insert(particles.end(), new_particles.begin(), new_particles.end()); |
| 90 |
new_particles.clear(); |
| 91 |
|
| 92 |
i = particles.begin(); |
| 93 |
while (i != particles.end()) { |
| 94 |
(*i)->update(ticks); |
| 95 |
if ((*i)->isDestroyed()) { |
| 96 |
delete *i; |
| 97 |
i = particles.erase(i); |
| 98 |
} else { |
| 99 |
++i; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
lastTicks += ticks; |
| 104 |
} |
| 105 |
|
| 106 |
void CParticleManager::add(CParticle *particle) |
| 107 |
{ |
| 108 |
new_particles.push_back(particle); |
| 109 |
} |
| 110 |
|
| 111 |
CPosition CParticleManager::getScreenPos(const CPosition &pos) |
| 112 |
{ |
| 113 |
int x = (int)pos.x; |
| 114 |
int y = (int)pos.y; |
| 115 |
vp->MapPixel2Viewport(x, y); |
| 116 |
return CPosition((float)x, (float)y); |
| 117 |
} |
| 118 |
|
| 119 |
//@} |