2010-03-27 04:09:11 +01:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest Shared Library (www.glest.org)
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#include "math_wrapper.h"
|
2010-03-27 04:09:11 +01:00
|
|
|
|
#include "particle.h"
|
|
|
|
|
|
2010-08-24 03:21:34 +02:00
|
|
|
|
#include <stdexcept>
|
2010-03-27 04:09:11 +01:00
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "particle_renderer.h"
|
|
|
|
|
#include "math_util.h"
|
2010-08-24 03:21:34 +02:00
|
|
|
|
#include "platform_common.h"
|
2010-03-27 04:09:11 +01:00
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
2010-08-24 03:21:34 +02:00
|
|
|
|
using namespace std;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
using namespace Shared::Util;
|
2010-08-24 03:21:34 +02:00
|
|
|
|
using namespace Shared::PlatformCommon;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
namespace Shared {
|
|
|
|
|
namespace Graphics {
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class ParticleSystem
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
ParticleSystem::ParticleSystem(int particleCount){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//init particle vector
|
2011-03-14 00:16:07 +01:00
|
|
|
|
blendMode= bmOne;
|
2010-08-24 03:21:34 +02:00
|
|
|
|
//particles= new Particle[particleCount];
|
|
|
|
|
particles.clear();
|
2010-08-26 03:25:27 +02:00
|
|
|
|
//particles.reserve(particleCount);
|
|
|
|
|
particles.resize(particleCount);
|
2010-08-24 03:21:34 +02:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
state= sPlay;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
aliveParticleCount= 0;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
active= true;
|
|
|
|
|
visible= true;
|
|
|
|
|
|
|
|
|
|
//vars
|
|
|
|
|
texture= NULL;
|
|
|
|
|
particleObserver= NULL;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//params
|
2010-10-06 19:04:51 +02:00
|
|
|
|
this->particleCount= particleCount;
|
2010-08-24 03:21:34 +02:00
|
|
|
|
//this->particleCount= particles.size();
|
2010-03-27 04:09:11 +01:00
|
|
|
|
maxParticleEnergy= 250;
|
|
|
|
|
varParticleEnergy= 50;
|
|
|
|
|
pos= Vec3f(0.0f);
|
|
|
|
|
color= Vec4f(1.0f);
|
|
|
|
|
colorNoEnergy= Vec4f(0.0f);
|
2010-09-24 18:36:59 +02:00
|
|
|
|
emissionRate= 15.0f;
|
2010-09-25 16:38:00 +02:00
|
|
|
|
emissionState= 1.0f; // initialized with 1 because we must have at least one particle in the beginning!
|
2010-03-27 04:09:11 +01:00
|
|
|
|
speed= 1.0f;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
teamcolorNoEnergy= false;
|
|
|
|
|
teamcolorEnergy= false;
|
|
|
|
|
alternations= 0;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParticleSystem::~ParticleSystem(){
|
2010-08-24 03:21:34 +02:00
|
|
|
|
//delete [] particles;
|
|
|
|
|
particles.clear();
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============== VIRTUAL ======================
|
|
|
|
|
|
|
|
|
|
//updates all living particles and creates new ones
|
2011-03-14 00:16:07 +01:00
|
|
|
|
void ParticleSystem::update(){
|
|
|
|
|
if(aliveParticleCount > (int) particles.size()){
|
2010-08-24 03:21:34 +02:00
|
|
|
|
throw runtime_error("aliveParticleCount >= particles.size()");
|
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2010-08-24 03:21:34 +02:00
|
|
|
|
if(state != sPause){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
for(int i= 0; i < aliveParticleCount; ++i){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
updateParticle(&particles[i]);
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(deathTest(&particles[i])){
|
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//kill the particle
|
|
|
|
|
killParticle(&particles[i]);
|
|
|
|
|
|
2010-08-24 03:21:34 +02:00
|
|
|
|
//maintain alive particles at front of the array
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(aliveParticleCount > 0){
|
|
|
|
|
particles[i]= particles[aliveParticleCount];
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-26 21:01:44 +02:00
|
|
|
|
if(state != ParticleSystem::sFade){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
emissionState= emissionState + emissionRate;
|
|
|
|
|
int emissionIntValue= (int) emissionState;
|
|
|
|
|
for(int i= 0; i < emissionIntValue; i++){
|
|
|
|
|
Particle *p= createParticle();
|
2010-03-27 04:09:11 +01:00
|
|
|
|
initParticle(p, i);
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
emissionState= emissionState - (float) emissionIntValue;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::render(ParticleRenderer *pr, ModelRenderer *mr){
|
|
|
|
|
if(active){
|
|
|
|
|
pr->renderSystem(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParticleSystem::BlendMode ParticleSystem::strToBlendMode(const string &str){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(str == "normal"){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
return bmOne;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
else if(str == "black"){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
return bmOneMinusAlpha;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
throw "Unknown particle mode: " + str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============== SET ==========================
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setState(State state){
|
|
|
|
|
this->state= state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setTexture(Texture *texture){
|
|
|
|
|
this->texture= texture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setPos(Vec3f pos){
|
|
|
|
|
this->pos= pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setColor(Vec4f color){
|
|
|
|
|
this->color= color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setColorNoEnergy(Vec4f colorNoEnergy){
|
|
|
|
|
this->colorNoEnergy= colorNoEnergy;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 18:36:59 +02:00
|
|
|
|
void ParticleSystem::setEmissionRate(float emissionRate){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
this->emissionRate= emissionRate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setMaxParticleEnergy(int maxParticleEnergy){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->maxParticleEnergy= maxParticleEnergy;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setVarParticleEnergy(int varParticleEnergy){
|
|
|
|
|
this->varParticleEnergy= varParticleEnergy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setParticleSize(float particleSize){
|
|
|
|
|
this->particleSize= particleSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setSpeed(float speed){
|
|
|
|
|
this->speed= speed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setActive(bool active){
|
|
|
|
|
this->active= active;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setObserver(ParticleObserver *particleObserver){
|
|
|
|
|
this->particleObserver= particleObserver;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setVisible(bool visible){
|
|
|
|
|
this->visible= visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============== MISC =========================
|
2011-03-14 00:16:07 +01:00
|
|
|
|
void ParticleSystem::fade(){
|
|
|
|
|
if(particleObserver != NULL){
|
2010-11-09 10:06:52 +01:00
|
|
|
|
assert(state == sPlay);
|
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
state= sFade;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(particleObserver != NULL){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
particleObserver->update(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ParticleSystem::isEmpty() const{
|
|
|
|
|
assert(aliveParticleCount>=0);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
return aliveParticleCount == 0 && state != sPause;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============== PROTECTED =========================
|
|
|
|
|
|
|
|
|
|
// if there is one dead particle it returns it else, return the particle with
|
|
|
|
|
// less energy
|
|
|
|
|
Particle * ParticleSystem::createParticle(){
|
|
|
|
|
|
|
|
|
|
//if any dead particles
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(aliveParticleCount < particleCount){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
++aliveParticleCount;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
return &particles[aliveParticleCount - 1];
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if not
|
2011-03-14 00:16:07 +01:00
|
|
|
|
int minEnergy= particles[0].energy;
|
|
|
|
|
int minEnergyParticle= 0;
|
2010-10-06 19:04:51 +02:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
for(int i= 0; i < particleCount; ++i){
|
2010-10-06 19:04:51 +02:00
|
|
|
|
if(particles[i].energy < minEnergy){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
minEnergy= particles[i].energy;
|
|
|
|
|
minEnergyParticle= i;
|
2010-10-06 19:04:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-24 03:21:34 +02:00
|
|
|
|
return &particles[minEnergyParticle];
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
/*
|
|
|
|
|
//if any dead particles
|
|
|
|
|
if(aliveParticleCount < particleCount) {
|
|
|
|
|
++aliveParticleCount;
|
|
|
|
|
return &particles[aliveParticleCount-1];
|
|
|
|
|
}
|
2010-08-24 03:21:34 +02:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
//if not
|
|
|
|
|
int minEnergy = particles[0].energy;
|
|
|
|
|
int minEnergyParticle = 0;
|
2010-08-24 03:21:34 +02:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
for(int i = 0; i < particleCount; ++i){
|
|
|
|
|
if(particles[i].energy < minEnergy){
|
|
|
|
|
minEnergy = particles[i].energy;
|
|
|
|
|
minEnergyParticle = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
return &particles[minEnergyParticle];
|
|
|
|
|
*/
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::initParticle(Particle *p, int particleIndex){
|
|
|
|
|
p->pos= pos;
|
|
|
|
|
p->lastPos= p->pos;
|
|
|
|
|
p->speed= Vec3f(0.0f);
|
|
|
|
|
p->accel= Vec3f(0.0f);
|
|
|
|
|
p->color= Vec4f(1.0f, 1.0f, 1.0f, 1.0);
|
|
|
|
|
p->size= particleSize;
|
|
|
|
|
p->energy= maxParticleEnergy + random.randRange(-varParticleEnergy, varParticleEnergy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::updateParticle(Particle *p){
|
|
|
|
|
p->lastPos= p->pos;
|
|
|
|
|
p->pos= p->pos + p->speed;
|
|
|
|
|
p->speed= p->speed + p->accel;
|
|
|
|
|
p->energy--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ParticleSystem::deathTest(Particle *p){
|
|
|
|
|
return p->energy <= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::killParticle(Particle *p){
|
|
|
|
|
aliveParticleCount--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleSystem::setFactionColor(Vec3f factionColor){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->factionColor= factionColor;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
Vec3f tmpCol;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
|
|
|
|
if(teamcolorEnergy){
|
|
|
|
|
this->color= Vec4f(factionColor.x, factionColor.y, factionColor.z, this->color.w);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(teamcolorNoEnergy){
|
|
|
|
|
this->colorNoEnergy= Vec4f(factionColor.x, factionColor.y, factionColor.z, this->colorNoEnergy.w);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// FireParticleSystem
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
FireParticleSystem::FireParticleSystem(int particleCount) :
|
|
|
|
|
ParticleSystem(particleCount){
|
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
radius= 0.5f;
|
|
|
|
|
speed= 0.01f;
|
|
|
|
|
windSpeed= Vec3f(0.0f);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
setParticleSize(0.6f);
|
|
|
|
|
setColorNoEnergy(Vec4f(1.0f, 0.5f, 0.0f, 1.0f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FireParticleSystem::initParticle(Particle *p, int particleIndex){
|
|
|
|
|
ParticleSystem::initParticle(p, particleIndex);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
|
|
|
|
float ang= random.randRange(-2.0f * pi, 2.0f * pi);
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#ifdef USE_STREFLOP
|
2010-04-24 05:57:38 +02:00
|
|
|
|
float mod= streflop::fabsf(random.randRange(-radius, radius));
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-04-24 05:57:38 +02:00
|
|
|
|
float x= streflop::sinf(ang)*mod;
|
|
|
|
|
float y= streflop::cosf(ang)*mod;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-04-24 05:57:38 +02:00
|
|
|
|
float radRatio= streflop::sqrtf(streflop::sqrtf(mod/radius));
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#else
|
|
|
|
|
float mod= fabsf(random.randRange(-radius, radius));
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
float x= sinf(ang) * mod;
|
|
|
|
|
float y= cosf(ang) * mod;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
float radRatio= sqrtf(sqrtf(mod / radius));
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#endif
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->color= colorNoEnergy * 0.5f + colorNoEnergy * 0.5f * radRatio;
|
|
|
|
|
p->energy= static_cast<int> (maxParticleEnergy * radRatio)
|
|
|
|
|
+ random.randRange(-varParticleEnergy, varParticleEnergy);
|
|
|
|
|
p->pos= Vec3f(pos.x + x, pos.y + random.randRange(-radius / 2, radius / 2), pos.z + y);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->lastPos= pos;
|
|
|
|
|
p->size= particleSize;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->speed= Vec3f(0, speed + speed * random.randRange(-0.5f, 0.5f), 0) + windSpeed;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FireParticleSystem::updateParticle(Particle *p){
|
|
|
|
|
p->lastPos= p->pos;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->pos= p->pos + p->speed;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->energy--;
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(p->color.x > 0.0f)
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->color.x*= 0.98f;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(p->color.y > 0.0f)
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->color.y*= 0.98f;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(p->color.w > 0.0f)
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->color.w*= 0.98f;
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->speed.x*= 1.001f;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================= SET PARAMS ====================
|
|
|
|
|
|
|
|
|
|
void FireParticleSystem::setRadius(float radius){
|
|
|
|
|
this->radius= radius;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FireParticleSystem::setWind(float windAngle, float windSpeed){
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#ifdef USE_STREFLOP
|
2010-04-24 05:57:38 +02:00
|
|
|
|
this->windSpeed.x= streflop::sinf(degToRad(windAngle))*windSpeed;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
this->windSpeed.y= 0.0f;
|
2010-04-24 05:57:38 +02:00
|
|
|
|
this->windSpeed.z= streflop::cosf(degToRad(windAngle))*windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#else
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->windSpeed.x= sinf(degToRad(windAngle)) * windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
this->windSpeed.y= 0.0f;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#endif
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// UnitParticleSystem
|
|
|
|
|
// ===========================================================================
|
2011-03-14 00:16:07 +01:00
|
|
|
|
bool UnitParticleSystem::isNight= false;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
UnitParticleSystem::UnitParticleSystem(int particleCount) :
|
|
|
|
|
ParticleSystem(particleCount){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
radius= 0.5f;
|
|
|
|
|
speed= 0.01f;
|
|
|
|
|
windSpeed= Vec3f(0.0f);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
setParticleSize(0.6f);
|
|
|
|
|
setColorNoEnergy(Vec4f(1.0f, 0.5f, 0.0f, 1.0f));
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
primitive= pQuad;
|
|
|
|
|
offset= Vec3f(0.0f);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
direction= Vec3f(0.0f, 1.0f, 0.0f);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
gravity= 0.0f;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
|
|
|
|
fixed= false;
|
|
|
|
|
rotation= 0.0f;
|
|
|
|
|
relativeDirection= true;
|
|
|
|
|
relative= false;
|
|
|
|
|
staticParticleCount= 0;
|
|
|
|
|
|
|
|
|
|
isVisibleAtNight= true;
|
|
|
|
|
isVisibleAtDay= true;
|
|
|
|
|
|
|
|
|
|
cRotation= Vec3f(1.0f, 1.0f, 1.0f);
|
|
|
|
|
fixedAddition= Vec3f(0.0f, 0.0f, 0.0f);
|
2010-09-25 16:38:00 +02:00
|
|
|
|
//prepare system for given staticParticleCount
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(staticParticleCount > 0){
|
|
|
|
|
emissionState= (float) staticParticleCount;
|
2010-09-25 16:38:00 +02:00
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
energyUp= false;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
bool UnitParticleSystem::getVisible() const{
|
|
|
|
|
if((isNight==true) && (isVisibleAtNight==true)){
|
|
|
|
|
return visible;
|
|
|
|
|
}
|
|
|
|
|
else if((isNight==false) && (isVisibleAtDay==true)){
|
|
|
|
|
return visible;
|
|
|
|
|
}
|
|
|
|
|
else return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnitParticleSystem::render(ParticleRenderer *pr, ModelRenderer *mr){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//if(active){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
switch(primitive){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
case pQuad:
|
|
|
|
|
pr->renderSystem(this);
|
|
|
|
|
break;
|
|
|
|
|
case pLine:
|
|
|
|
|
pr->renderSystemLine(this);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UnitParticleSystem::Primitive UnitParticleSystem::strToPrimitive(const string &str){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(str == "quad"){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
return pQuad;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
else if(str == "line"){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
return pLine;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
throw "Unknown particle primitive: " + str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
|
|
|
|
|
ParticleSystem::initParticle(p, particleIndex);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
|
|
|
|
float ang= random.randRange(-2.0f * pi, 2.0f * pi);
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#ifdef USE_STREFLOP
|
2010-04-24 05:57:38 +02:00
|
|
|
|
float mod= streflop::fabsf(random.randRange(-radius, radius));
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-04-24 05:57:38 +02:00
|
|
|
|
float x= streflop::sinf(ang)*mod;
|
|
|
|
|
float y= streflop::cosf(ang)*mod;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-04-24 05:57:38 +02:00
|
|
|
|
float radRatio= streflop::sqrtf(streflop::sqrtf(mod/radius));
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#else
|
|
|
|
|
float mod= fabsf(random.randRange(-radius, radius));
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
float x= sinf(ang) * mod;
|
|
|
|
|
float y= cosf(ang) * mod;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
float radRatio= sqrtf(sqrtf(mod / radius));
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#endif
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//p->color= color*0.5f + color*0.5f*radRatio;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->color= color;
|
|
|
|
|
if(radiusBasedStartenergy == true){
|
|
|
|
|
p->energy= static_cast<int> (maxParticleEnergy * radRatio) + random.randRange(-varParticleEnergy,
|
|
|
|
|
varParticleEnergy);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
p->energy= static_cast<int> (maxParticleEnergy) + random.randRange(-varParticleEnergy, varParticleEnergy);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->lastPos= pos;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
oldPosition= pos;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->size= particleSize;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
|
|
|
|
p->speed= Vec3f(direction.x + direction.x * random.randRange(-0.5f, 0.5f), direction.y + direction.y
|
|
|
|
|
* random.randRange(-0.5f, 0.5f), direction.z + direction.z * random.randRange(-0.5f, 0.5f));
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->speed= p->speed * speed;
|
|
|
|
|
p->accel= Vec3f(0.0f, -gravity, 0.0f);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
|
|
|
|
if(relative == false){
|
|
|
|
|
p->pos= Vec3f(pos.x + x + offset.x, pos.y + random.randRange(-radius / 2, radius / 2) + offset.y, pos.z + y
|
|
|
|
|
+ offset.z);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
else{// rotate it according to rotation
|
|
|
|
|
float rad= degToRad(rotation);
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#ifdef USE_STREFLOP
|
2010-04-24 05:57:38 +02:00
|
|
|
|
p->pos= Vec3f(pos.x+x+offset.z*streflop::sinf(rad)+offset.x*streflop::cosf(rad), pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+(offset.z*streflop::cosf(rad)-offset.x*streflop::sinf(rad)));
|
2010-03-27 04:09:11 +01:00
|
|
|
|
if(relativeDirection){
|
2010-04-24 05:57:38 +02:00
|
|
|
|
p->speed=Vec3f(p->speed.z*streflop::sinf(rad)+p->speed.x*streflop::cosf(rad),p->speed.y,(p->speed.z*streflop::cosf(rad)-p->speed.x*streflop::sinf(rad)));
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#else
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->pos= Vec3f(pos.x + x + offset.z * sinf(rad) + offset.x * cosf(rad), pos.y + random.randRange(-radius / 2,
|
|
|
|
|
radius / 2) + offset.y, pos.z + y + (offset.z * cosf(rad) - offset.x * sinf(rad)));
|
2010-05-01 22:14:25 +02:00
|
|
|
|
if(relativeDirection){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->speed= Vec3f(p->speed.z * sinf(rad) + p->speed.x * cosf(rad), p->speed.y, (p->speed.z * cosf(rad)
|
|
|
|
|
- p->speed.x * sinf(rad)));
|
2010-05-01 22:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnitParticleSystem::update(){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(fixed){
|
|
|
|
|
fixedAddition= Vec3f(pos.x - oldPosition.x, pos.y - oldPosition.y, pos.z - oldPosition.z);
|
|
|
|
|
oldPosition= pos;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
ParticleSystem::update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnitParticleSystem::updateParticle(Particle *p){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
float energyRatio;
|
|
|
|
|
if(alternations > 0){
|
|
|
|
|
int interval= (maxParticleEnergy / alternations);
|
|
|
|
|
float moduloValue= static_cast<int> (static_cast<float> (p->energy)) % interval;
|
|
|
|
|
|
|
|
|
|
if(moduloValue < interval / 2){
|
|
|
|
|
energyRatio= (interval - moduloValue) / interval;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
energyRatio= moduloValue / interval;
|
|
|
|
|
}
|
|
|
|
|
energyRatio= clamp(energyRatio, 0.f, 1.f);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
energyRatio= clamp(static_cast<float> (p->energy) / maxParticleEnergy, 0.f, 1.f);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->lastPos+= p->speed;
|
|
|
|
|
p->pos+= p->speed;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(fixed){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->lastPos+= fixedAddition;
|
|
|
|
|
p->pos+= fixedAddition;
|
|
|
|
|
}
|
|
|
|
|
p->speed+= p->accel;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio);
|
|
|
|
|
p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio);
|
|
|
|
|
if(state == ParticleSystem::sFade || staticParticleCount < 1){
|
2010-09-25 16:38:00 +02:00
|
|
|
|
p->energy--;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
else{
|
|
|
|
|
if(maxParticleEnergy > 2){
|
2010-09-25 16:38:00 +02:00
|
|
|
|
if(energyUp){
|
|
|
|
|
p->energy++;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
else{
|
2010-09-25 16:38:00 +02:00
|
|
|
|
p->energy--;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
|
|
|
|
if(p->energy == 1){
|
|
|
|
|
energyUp= true;
|
2010-09-25 16:38:00 +02:00
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(p->energy == maxParticleEnergy){
|
|
|
|
|
energyUp= false;
|
2010-09-25 16:38:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================= SET PARAMS ====================
|
|
|
|
|
|
|
|
|
|
void UnitParticleSystem::setRadius(float radius){
|
|
|
|
|
this->radius= radius;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnitParticleSystem::setWind(float windAngle, float windSpeed){
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#ifdef USE_STREFLOP
|
2010-04-24 05:57:38 +02:00
|
|
|
|
this->windSpeed.x= streflop::sinf(degToRad(windAngle))*windSpeed;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
this->windSpeed.y= 0.0f;
|
2010-04-24 05:57:38 +02:00
|
|
|
|
this->windSpeed.z= streflop::cosf(degToRad(windAngle))*windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#else
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->windSpeed.x= sinf(degToRad(windAngle)) * windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
this->windSpeed.y= 0.0f;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#endif
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// RainParticleSystem
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
RainParticleSystem::RainParticleSystem(int particleCount) :
|
|
|
|
|
ParticleSystem(particleCount){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
setWind(0.0f, 0.0f);
|
|
|
|
|
setRadius(20.0f);
|
|
|
|
|
|
2010-09-24 18:36:59 +02:00
|
|
|
|
setEmissionRate(25.0f);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
setParticleSize(3.0f);
|
|
|
|
|
setColor(Vec4f(0.5f, 0.5f, 0.5f, 0.3f));
|
|
|
|
|
setSpeed(0.2f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RainParticleSystem::render(ParticleRenderer *pr, ModelRenderer *mr){
|
|
|
|
|
pr->renderSystemLineAlpha(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RainParticleSystem::initParticle(Particle *p, int particleIndex){
|
|
|
|
|
ParticleSystem::initParticle(p, particleIndex);
|
|
|
|
|
|
|
|
|
|
float x= random.randRange(-radius, radius);
|
|
|
|
|
float y= random.randRange(-radius, radius);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->color= color;
|
|
|
|
|
p->energy= 10000;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->pos= Vec3f(pos.x + x, pos.y, pos.z + y);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->lastPos= p->pos;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->speed= Vec3f(random.randRange(-speed / 10, speed / 10), -speed, random.randRange(-speed / 10, speed / 10))
|
|
|
|
|
+ windSpeed;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RainParticleSystem::deathTest(Particle *p){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
return p->pos.y < 0;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RainParticleSystem::setRadius(float radius){
|
|
|
|
|
this->radius= radius;
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
|
|
|
|
void RainParticleSystem::setWind(float windAngle, float windSpeed){
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#ifdef USE_STREFLOP
|
2010-04-24 05:57:38 +02:00
|
|
|
|
this->windSpeed.x= streflop::sinf(degToRad(windAngle))*windSpeed;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
this->windSpeed.y= 0.0f;
|
2010-04-24 05:57:38 +02:00
|
|
|
|
this->windSpeed.z= streflop::cosf(degToRad(windAngle))*windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#else
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->windSpeed.x= sinf(degToRad(windAngle)) * windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
this->windSpeed.y= 0.0f;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#endif
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// SnowParticleSystem
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
SnowParticleSystem::SnowParticleSystem(int particleCount) :
|
|
|
|
|
ParticleSystem(particleCount){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
setWind(0.0f, 0.0f);
|
|
|
|
|
setRadius(30.0f);
|
|
|
|
|
|
2010-09-24 18:36:59 +02:00
|
|
|
|
setEmissionRate(2.0f);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
setParticleSize(0.2f);
|
|
|
|
|
setColor(Vec4f(0.8f, 0.8f, 0.8f, 0.8f));
|
|
|
|
|
setSpeed(0.05f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnowParticleSystem::initParticle(Particle *p, int particleIndex){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
ParticleSystem::initParticle(p, particleIndex);
|
|
|
|
|
|
|
|
|
|
float x= random.randRange(-radius, radius);
|
|
|
|
|
float y= random.randRange(-radius, radius);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->color= color;
|
|
|
|
|
p->energy= 10000;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->pos= Vec3f(pos.x + x, pos.y, pos.z + y);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->lastPos= p->pos;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->speed= Vec3f(0.0f, -speed, 0.0f) + windSpeed;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->speed.x+= random.randRange(-0.005f, 0.005f);
|
|
|
|
|
p->speed.y+= random.randRange(-0.005f, 0.005f);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
bool SnowParticleSystem::deathTest(Particle *p){
|
|
|
|
|
return p->pos.y < 0;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnowParticleSystem::setRadius(float radius){
|
|
|
|
|
this->radius= radius;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
|
|
|
|
void SnowParticleSystem::setWind(float windAngle, float windSpeed){
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#ifdef USE_STREFLOP
|
2010-04-24 05:57:38 +02:00
|
|
|
|
this->windSpeed.x= streflop::sinf(degToRad(windAngle))*windSpeed;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
this->windSpeed.y= 0.0f;
|
2010-04-24 05:57:38 +02:00
|
|
|
|
this->windSpeed.z= streflop::cosf(degToRad(windAngle))*windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#else
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->windSpeed.x= sinf(degToRad(windAngle)) * windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
this->windSpeed.y= 0.0f;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
this->windSpeed.z= cosf(degToRad(windAngle)) * windSpeed;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#endif
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// AttackParticleSystem
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
AttackParticleSystem::AttackParticleSystem(int particleCount) :
|
|
|
|
|
ParticleSystem(particleCount){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
model= NULL;
|
|
|
|
|
primitive= pQuad;
|
|
|
|
|
offset= Vec3f(0.0f);
|
|
|
|
|
gravity= 0.0f;
|
2011-06-10 19:33:09 +02:00
|
|
|
|
tween= 0.0f;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
direction= Vec3f(1.0f, 0.0f, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AttackParticleSystem::render(ParticleRenderer *pr, ModelRenderer *mr){
|
|
|
|
|
if(active){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(model != NULL){
|
2011-06-10 19:33:09 +02:00
|
|
|
|
pr->renderModel(this, mr);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
switch(primitive){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
case pQuad:
|
|
|
|
|
pr->renderSystem(this);
|
|
|
|
|
break;
|
|
|
|
|
case pLine:
|
|
|
|
|
pr->renderSystemLine(this);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AttackParticleSystem::Primitive AttackParticleSystem::strToPrimitive(const string &str){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(str == "quad"){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
return pQuad;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
else if(str == "line"){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
return pLine;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
throw "Unknown particle primitive: " + str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// ProjectileParticleSystem
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
ProjectileParticleSystem::ProjectileParticleSystem(int particleCount) :
|
|
|
|
|
AttackParticleSystem(particleCount){
|
2010-09-24 18:36:59 +02:00
|
|
|
|
setEmissionRate(20.0f);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
setColor(Vec4f(1.0f, 0.3f, 0.0f, 0.5f));
|
|
|
|
|
setMaxParticleEnergy(100);
|
|
|
|
|
setVarParticleEnergy(50);
|
|
|
|
|
setParticleSize(0.4f);
|
|
|
|
|
setSpeed(0.14f);
|
|
|
|
|
|
|
|
|
|
trajectory= tLinear;
|
|
|
|
|
trajectorySpeed= 1.0f;
|
|
|
|
|
trajectoryScale= 1.0f;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
trajectoryFrequency= 1.0f;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
|
|
|
|
nextParticleSystem= NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectileParticleSystem::~ProjectileParticleSystem(){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(nextParticleSystem != NULL){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
nextParticleSystem->prevParticleSystem= NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectileParticleSystem::link(SplashParticleSystem *particleSystem){
|
|
|
|
|
nextParticleSystem= particleSystem;
|
|
|
|
|
nextParticleSystem->setState(sPause);
|
|
|
|
|
nextParticleSystem->prevParticleSystem= this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectileParticleSystem::update(){
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(state == sPlay){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
|
|
|
|
lastPos= pos;
|
|
|
|
|
flatPos+= zVector * trajectorySpeed;
|
|
|
|
|
Vec3f targetVector= endPos - startPos;
|
|
|
|
|
Vec3f currentVector= flatPos - startPos;
|
|
|
|
|
|
|
|
|
|
// ratio
|
2011-06-10 19:33:09 +02:00
|
|
|
|
tween = clamp(currentVector.length() / targetVector.length(), 0.0f, 1.0f);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
// trajectory
|
|
|
|
|
switch(trajectory){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
case tLinear: {
|
2010-03-27 04:09:11 +01:00
|
|
|
|
pos= flatPos;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
break;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
case tParabolic: {
|
2011-06-10 19:33:09 +02:00
|
|
|
|
float scaledT= 2.0f * (tween - 0.5f);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
float paraboleY= (1.0f - scaledT * scaledT) * trajectoryScale;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
pos= flatPos;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
pos.y+= paraboleY;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
break;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
case tSpiral: {
|
2010-03-27 04:09:11 +01:00
|
|
|
|
pos= flatPos;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#ifdef USE_STREFLOP
|
2011-06-10 19:33:09 +02:00
|
|
|
|
pos+= xVector * streflop::cos(tween * trajectoryFrequency * targetVector.length()) * trajectoryScale;
|
|
|
|
|
pos+= yVector * streflop::sin(tween * trajectoryFrequency * targetVector.length()) * trajectoryScale;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#else
|
2011-06-10 19:33:09 +02:00
|
|
|
|
pos+= xVector * cos(tween * trajectoryFrequency * targetVector.length()) * trajectoryScale;
|
|
|
|
|
pos+= yVector * sin(tween * trajectoryFrequency * targetVector.length()) * trajectoryScale;
|
2010-05-01 22:14:25 +02:00
|
|
|
|
#endif
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
break;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
direction= pos - lastPos;
|
|
|
|
|
direction.normalize();
|
|
|
|
|
|
|
|
|
|
//arrive destination
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(flatPos.dist(endPos) < 0.5f){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
state= sFade;
|
|
|
|
|
model= NULL;
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(particleObserver != NULL){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
particleObserver->update(this);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(nextParticleSystem != NULL){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
nextParticleSystem->setState(sPlay);
|
|
|
|
|
nextParticleSystem->setPos(endPos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParticleSystem::update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectileParticleSystem::initParticle(Particle *p, int particleIndex){
|
|
|
|
|
|
|
|
|
|
ParticleSystem::initParticle(p, particleIndex);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
|
|
|
|
float t= static_cast<float> (particleIndex) / emissionRate;
|
|
|
|
|
|
|
|
|
|
p->pos= pos + (lastPos - pos) * t;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->lastPos= lastPos;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->speed= Vec3f(random.randRange(-0.1f, 0.1f), random.randRange(-0.1f, 0.1f), random.randRange(-0.1f, 0.1f))
|
|
|
|
|
* speed;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->accel= Vec3f(0.0f, -gravity, 0.0f);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
updateParticle(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectileParticleSystem::updateParticle(Particle *p){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
float energyRatio= clamp(static_cast<float> (p->energy) / maxParticleEnergy, 0.f, 1.f);
|
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->lastPos+= p->speed;
|
|
|
|
|
p->pos+= p->speed;
|
|
|
|
|
p->speed+= p->accel;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio);
|
|
|
|
|
p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->energy--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectileParticleSystem::setPath(Vec3f startPos, Vec3f endPos){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//compute axis
|
|
|
|
|
zVector= endPos - startPos;
|
|
|
|
|
zVector.normalize();
|
|
|
|
|
yVector= Vec3f(0.0f, 1.0f, 0.0f);
|
|
|
|
|
xVector= zVector.cross(yVector);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//apply offset
|
|
|
|
|
startPos+= xVector * offset.x;
|
|
|
|
|
startPos+= yVector * offset.y;
|
|
|
|
|
startPos+= zVector * offset.z;
|
|
|
|
|
|
|
|
|
|
pos= startPos;
|
|
|
|
|
lastPos= startPos;
|
|
|
|
|
flatPos= startPos;
|
|
|
|
|
|
|
|
|
|
//recompute axis
|
|
|
|
|
zVector= endPos - startPos;
|
|
|
|
|
zVector.normalize();
|
|
|
|
|
yVector= Vec3f(0.0f, 1.0f, 0.0f);
|
|
|
|
|
xVector= zVector.cross(yVector);
|
|
|
|
|
|
|
|
|
|
// set members
|
|
|
|
|
this->startPos= startPos;
|
|
|
|
|
this->endPos= endPos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectileParticleSystem::Trajectory ProjectileParticleSystem::strToTrajectory(const string &str){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(str == "linear"){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
return tLinear;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
else if(str == "parabolic"){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
return tParabolic;
|
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
else if(str == "spiral"){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
return tSpiral;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
throw "Unknown particle system trajectory: " + str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// SplashParticleSystem
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
SplashParticleSystem::SplashParticleSystem(int particleCount) :
|
|
|
|
|
AttackParticleSystem(particleCount){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
setColor(Vec4f(1.0f, 0.3f, 0.0f, 0.8f));
|
|
|
|
|
setMaxParticleEnergy(100);
|
|
|
|
|
setVarParticleEnergy(50);
|
|
|
|
|
setParticleSize(1.0f);
|
|
|
|
|
setSpeed(0.003f);
|
|
|
|
|
|
|
|
|
|
prevParticleSystem= NULL;
|
|
|
|
|
|
|
|
|
|
emissionRateFade= 1;
|
|
|
|
|
verticalSpreadA= 1.0f;
|
|
|
|
|
verticalSpreadB= 0.0f;
|
|
|
|
|
horizontalSpreadA= 1.0f;
|
|
|
|
|
horizontalSpreadB= 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SplashParticleSystem::~SplashParticleSystem(){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(prevParticleSystem != NULL){
|
|
|
|
|
prevParticleSystem->nextParticleSystem= NULL;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-10 21:44:34 +02:00
|
|
|
|
void SplashParticleSystem::initParticleSystem() {
|
|
|
|
|
startEmissionRate = emissionRate;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
void SplashParticleSystem::update(){
|
|
|
|
|
ParticleSystem::update();
|
2011-06-10 21:44:34 +02:00
|
|
|
|
if(state != sPause) {
|
2010-03-27 04:09:11 +01:00
|
|
|
|
emissionRate-= emissionRateFade;
|
2011-06-10 21:44:34 +02:00
|
|
|
|
|
|
|
|
|
tween= 1.0f - ((emissionRate + startEmissionRate) / (startEmissionRate * 2.0f));
|
|
|
|
|
tween= clamp(tween, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
if(emissionRate < 0.0f) {//otherwise this system lives forever!
|
2010-09-25 16:38:00 +02:00
|
|
|
|
fade();
|
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SplashParticleSystem::initParticle(Particle *p, int particleIndex){
|
|
|
|
|
p->pos= pos;
|
|
|
|
|
p->lastPos= p->pos;
|
|
|
|
|
p->energy= maxParticleEnergy;
|
|
|
|
|
p->size= particleSize;
|
|
|
|
|
p->color= color;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
|
|
|
|
|
p->speed= Vec3f(horizontalSpreadA * random.randRange(-1.0f, 1.0f) + horizontalSpreadB, verticalSpreadA
|
|
|
|
|
* random.randRange(-1.0f, 1.0f) + verticalSpreadB, horizontalSpreadA * random.randRange(-1.0f, 1.0f)
|
|
|
|
|
+ horizontalSpreadB);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->speed.normalize();
|
|
|
|
|
p->speed= p->speed * speed;
|
|
|
|
|
|
|
|
|
|
p->accel= Vec3f(0.0f, -gravity, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SplashParticleSystem::updateParticle(Particle *p){
|
2011-03-14 00:16:07 +01:00
|
|
|
|
float energyRatio= clamp(static_cast<float> (p->energy) / maxParticleEnergy, 0.f, 1.f);
|
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
p->lastPos= p->pos;
|
|
|
|
|
p->pos= p->pos + p->speed;
|
|
|
|
|
p->speed= p->speed + p->accel;
|
|
|
|
|
p->energy--;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio);
|
|
|
|
|
p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
// ParticleManager
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
|
|
ParticleManager::~ParticleManager(){
|
|
|
|
|
end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParticleManager::render(ParticleRenderer *pr, ModelRenderer *mr) const{
|
2011-03-14 00:16:07 +01:00
|
|
|
|
for(unsigned int i= 0; i < particleSystems.size(); i++){
|
|
|
|
|
ParticleSystem *ps= particleSystems[i];
|
|
|
|
|
if(ps != NULL && ps->getVisible()){
|
2010-09-06 19:52:33 +02:00
|
|
|
|
ps->render(pr, mr);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
bool ParticleManager::hasActiveParticleSystem(ParticleSystem::ParticleSystemType type) const{
|
|
|
|
|
bool result= false;
|
2011-01-29 04:53:05 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
size_t particleSystemCount= particleSystems.size();
|
|
|
|
|
int currentParticleCount= 0;
|
2011-01-29 04:53:05 +01:00
|
|
|
|
|
|
|
|
|
vector<ParticleSystem *> cleanupParticleSystemsList;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
for(unsigned int i= 0; i < particleSystems.size(); i++){
|
|
|
|
|
ParticleSystem *ps= particleSystems[i];
|
|
|
|
|
if(ps != NULL){
|
|
|
|
|
currentParticleCount+= ps->getAliveParticleCount();
|
|
|
|
|
|
|
|
|
|
bool showParticle= true;
|
|
|
|
|
if(dynamic_cast<UnitParticleSystem *> (ps) != NULL || dynamic_cast<FireParticleSystem *> (ps) != NULL){
|
|
|
|
|
showParticle= ps->getVisible() || (ps->getState() == ParticleSystem::sFade);
|
2011-01-29 04:53:05 +01:00
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(showParticle == true){
|
2011-01-29 04:53:05 +01:00
|
|
|
|
//printf("Looking for [%d] current id [%d] i = %d\n",type,ps->getParticleSystemType(),i);
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(type == ParticleSystem::pst_All || type == ps->getParticleSystemType()){
|
2011-01-29 04:53:05 +01:00
|
|
|
|
//printf("FOUND particle system type match for [%d] current id [%d] i = %d\n",type,ps->getParticleSystemType(),i);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
result= true;
|
2011-01-29 04:53:05 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
void ParticleManager::update(int renderFps){
|
2010-08-24 03:21:34 +02:00
|
|
|
|
Chrono chrono;
|
2011-03-28 05:54:23 +02:00
|
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
size_t particleSystemCount= particleSystems.size();
|
|
|
|
|
int currentParticleCount= 0;
|
2010-09-06 19:52:33 +02:00
|
|
|
|
|
|
|
|
|
vector<ParticleSystem *> cleanupParticleSystemsList;
|
2011-03-14 00:16:07 +01:00
|
|
|
|
for(unsigned int i= 0; i < particleSystems.size(); i++){
|
|
|
|
|
ParticleSystem *ps= particleSystems[i];
|
|
|
|
|
if(ps != NULL){
|
|
|
|
|
currentParticleCount+= ps->getAliveParticleCount();
|
|
|
|
|
|
|
|
|
|
bool showParticle= true;
|
|
|
|
|
if(dynamic_cast<UnitParticleSystem *> (ps) != NULL || dynamic_cast<FireParticleSystem *> (ps) != NULL){
|
|
|
|
|
showParticle= ps->getVisible() || (ps->getState() == ParticleSystem::sFade);
|
2010-08-26 21:01:44 +02:00
|
|
|
|
}
|
2011-03-14 00:16:07 +01:00
|
|
|
|
if(showParticle == true){
|
2010-08-26 21:01:44 +02:00
|
|
|
|
ps->update();
|
2011-05-01 23:46:04 +02:00
|
|
|
|
if(ps->isEmpty() && ps->getState() == ParticleSystem::sFade){
|
2010-09-06 19:52:33 +02:00
|
|
|
|
//delete ps;
|
|
|
|
|
//*it= NULL;
|
|
|
|
|
cleanupParticleSystemsList.push_back(ps);
|
2010-08-26 21:01:44 +02:00
|
|
|
|
}
|
2010-08-24 04:49:55 +02:00
|
|
|
|
}
|
2010-08-24 22:19:30 +02:00
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
2010-09-06 19:52:33 +02:00
|
|
|
|
//particleSystems.remove(NULL);
|
|
|
|
|
cleanupParticleSystems(cleanupParticleSystemsList);
|
2010-08-24 03:21:34 +02:00
|
|
|
|
|
2011-03-28 05:54:23 +02:00
|
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0)
|
2011-03-14 00:16:07 +01:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld, particleSystemCount = %d, currentParticleCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),particleSystemCount,currentParticleCount);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
bool ParticleManager::validateParticleSystemStillExists(ParticleSystem * particleSystem) const{
|
|
|
|
|
int index= findParticleSystems(particleSystem, this->particleSystems);
|
2010-09-07 19:30:13 +02:00
|
|
|
|
return (index >= 0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
int ParticleManager::findParticleSystems(ParticleSystem *psFind, const vector<ParticleSystem *> &particleSystems) const{
|
|
|
|
|
int result= -1;
|
|
|
|
|
for(unsigned int i= 0; i < particleSystems.size(); i++){
|
|
|
|
|
ParticleSystem *ps= particleSystems[i];
|
|
|
|
|
if(ps != NULL && psFind != NULL && psFind == ps){
|
|
|
|
|
result= i;
|
2010-09-06 19:52:33 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
void ParticleManager::cleanupParticleSystems(ParticleSystem *ps){
|
2010-09-06 19:52:33 +02:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
int index= findParticleSystems(ps, this->particleSystems);
|
|
|
|
|
if(ps != NULL && index >= 0){
|
2010-09-06 19:52:33 +02:00
|
|
|
|
delete ps;
|
|
|
|
|
this->particleSystems.erase(this->particleSystems.begin() + index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
void ParticleManager::cleanupParticleSystems(vector<ParticleSystem *> &particleSystems){
|
2010-09-06 19:52:33 +02:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
for(unsigned int i= 0; i < particleSystems.size(); i++){
|
|
|
|
|
ParticleSystem *ps= particleSystems[i];
|
2010-09-06 19:52:33 +02:00
|
|
|
|
cleanupParticleSystems(ps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
particleSystems.clear();
|
|
|
|
|
//this->particleSystems.remove(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
void ParticleManager::cleanupUnitParticleSystems(vector<UnitParticleSystem *> &particleSystems){
|
2010-09-06 19:52:33 +02:00
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
for(unsigned int i= 0; i < particleSystems.size(); i++){
|
|
|
|
|
ParticleSystem *ps= particleSystems[i];
|
2010-09-06 19:52:33 +02:00
|
|
|
|
cleanupParticleSystems(ps);
|
|
|
|
|
}
|
|
|
|
|
particleSystems.clear();
|
|
|
|
|
//this->particleSystems.remove(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
void ParticleManager::manage(ParticleSystem *ps){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
particleSystems.push_back(ps);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
void ParticleManager::end(){
|
|
|
|
|
while(particleSystems.empty() == false){
|
2010-09-06 19:52:33 +02:00
|
|
|
|
delete particleSystems.back();
|
|
|
|
|
particleSystems.pop_back();
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
}
|
|
|
|
|
}//end namespace
|