____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"00001 // ____ _ __ 00002 // / __ )____ _____ | | / /___ ___________ 00003 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ 00004 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) 00005 // /_____/\____/____/ |__/|__/\__,_/_/ /____/ 00006 // 00007 // A futuristic real-time strategy game. 00008 // This file is part of Bos Wars. 00009 // 00011 // 00012 // (c) Copyright 2007-2008 by Jimmy Salmon and Francois Beerten 00013 // 00014 // This program is free software; you can redistribute it and/or modify 00015 // it under the terms of the GNU General Public License as published by 00016 // the Free Software Foundation; only version 2 of the License. 00017 // 00018 // This program is distributed in the hope that it will be useful, 00019 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 // GNU General Public License for more details. 00022 // 00023 // You should have received a copy of the GNU General Public License 00024 // along with this program; if not, write to the Free Software 00025 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00026 // 02111-1307, USA. 00027 // 00028 00030 00031 #include "stratagus.h" 00032 #include "particle.h" 00033 #include "video.h" 00034 #include "ui.h" 00035 00036 00037 CParticleManager ParticleManager; 00038 00039 00040 CParticleManager::CParticleManager() : 00041 vp(NULL), lastTicks(0) 00042 { 00043 } 00044 00045 CParticleManager::~CParticleManager() 00046 { 00047 } 00048 00049 void CParticleManager::init() 00050 { 00051 } 00052 00053 void CParticleManager::exit() 00054 { 00055 ParticleManager.clear(); 00056 } 00057 00058 void CParticleManager::clear() 00059 { 00060 std::vector<CParticle *>::iterator i; 00061 for (i = particles.begin(); i != particles.end(); ++i) { 00062 delete *i; 00063 } 00064 particles.clear(); 00065 00066 for (i = new_particles.begin(); i != new_particles.end(); ++i) { 00067 delete *i; 00068 } 00069 new_particles.clear(); 00070 } 00071 00072 void CParticleManager::draw(const CViewport *vp) 00073 { 00074 this->vp = vp; 00075 00076 std::vector<CParticle *>::iterator i; 00077 for (i = particles.begin(); i != particles.end(); ++i) { 00078 (*i)->draw(); 00079 } 00080 00081 this->vp = NULL; 00082 } 00083 00084 void CParticleManager::update() 00085 { 00086 unsigned long ticks = GetTicks() - lastTicks; 00087 std::vector<CParticle *>::iterator i; 00088 00089 particles.insert(particles.end(), new_particles.begin(), new_particles.end()); 00090 new_particles.clear(); 00091 00092 i = particles.begin(); 00093 while (i != particles.end()) { 00094 (*i)->update(ticks); 00095 if ((*i)->isDestroyed()) { 00096 delete *i; 00097 i = particles.erase(i); 00098 } else { 00099 ++i; 00100 } 00101 } 00102 00103 lastTicks += ticks; 00104 } 00105 00106 void CParticleManager::add(CParticle *particle) 00107 { 00108 new_particles.push_back(particle); 00109 } 00110 00111 CPosition CParticleManager::getScreenPos(const CPosition &pos) 00112 { 00113 int x = (int)pos.x; 00114 int y = (int)pos.y; 00115 vp->MapPixel2Viewport(x, y); 00116 return CPosition((float)x, (float)y); 00117 } 00118
1.5.6