2011-08-03 20:05:33 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2007, 2010 - Bit-Blot
|
|
|
|
|
|
|
|
This file is part of Aquaria.
|
|
|
|
|
|
|
|
Aquaria is free software; you can redistribute it 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.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#ifndef __particles__
|
|
|
|
#define __particles__
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Quad.h"
|
|
|
|
|
|
|
|
class Emitter;
|
|
|
|
class ParticleEffect;
|
|
|
|
|
|
|
|
struct SpawnParticleData
|
|
|
|
{
|
|
|
|
SpawnParticleData();
|
|
|
|
|
|
|
|
float randomScale1, randomScale2;
|
|
|
|
float randomAlphaMod1, randomAlphaMod2;
|
|
|
|
enum { NO_SPAWN = 999 };
|
|
|
|
|
|
|
|
enum SpawnArea { SPAWN_CIRCLE=0, SPAWN_LINE };
|
|
|
|
|
|
|
|
int pauseLevel;
|
|
|
|
int flipH, flipV;
|
|
|
|
SpawnArea spawnArea;
|
|
|
|
|
|
|
|
float updateMultiplier;
|
|
|
|
|
|
|
|
InterpolatedVector velocityMagnitude;
|
|
|
|
int randomParticleAngleRange;
|
|
|
|
int randomVelocityRange;
|
|
|
|
|
|
|
|
float randomVelocityMagnitude;
|
|
|
|
int randomRotationRange;
|
|
|
|
InterpolatedVector initialVelocity, number, gravity;
|
|
|
|
float randomSpawnRadius;
|
|
|
|
Vector randomSpawnMod;
|
|
|
|
int randomSpawnRadiusRange;
|
|
|
|
bool didOne;
|
|
|
|
int justOne;
|
|
|
|
|
|
|
|
int copyParentRotation, copyParentFlip;
|
|
|
|
bool useSpawnRate;
|
|
|
|
bool calculateVelocityToCenter;
|
|
|
|
bool fadeAlphaWithLife, addAsChild;
|
|
|
|
int width, height;
|
|
|
|
InterpolatedVector scale, rotation, color, alpha, spawnOffset;
|
|
|
|
float life;
|
|
|
|
InterpolatedVector spawnRate;
|
|
|
|
std::string texture;
|
|
|
|
RenderObject::BlendTypes blendType;
|
|
|
|
float counter;
|
|
|
|
float spawnTimeOffset;
|
|
|
|
bool spawnLocal;
|
2014-03-10 16:28:41 +00:00
|
|
|
bool inheritColor;
|
|
|
|
bool inheritAlpha;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
float lastDTDifference;
|
|
|
|
int influenced;
|
|
|
|
std::string deathPrt;
|
|
|
|
|
|
|
|
int suckIndex, suckStr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Particle
|
|
|
|
{
|
|
|
|
Particle()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
active = false;
|
|
|
|
life = 1;
|
|
|
|
emitter = 0;
|
|
|
|
color.stop();
|
|
|
|
scale.stop();
|
|
|
|
rot.stop();
|
|
|
|
alpha.stop();
|
|
|
|
pos = Vector(0,0);
|
|
|
|
vel = Vector(0,0);
|
|
|
|
gvy = Vector(0,0);
|
|
|
|
lpos = Vector(0,0);
|
|
|
|
color = Vector(1,1,1);
|
|
|
|
alpha = 1;
|
|
|
|
scale = Vector(1,1);
|
|
|
|
rot = Vector(0,0,0);
|
|
|
|
emitter = 0;
|
|
|
|
index = -1;
|
|
|
|
}
|
|
|
|
float life;
|
|
|
|
bool active;
|
|
|
|
Vector pos, vel, gvy, lpos;
|
|
|
|
InterpolatedVector color, alpha, scale, rot;
|
|
|
|
Emitter *emitter;
|
|
|
|
int index;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Particle> Particles;
|
|
|
|
|
|
|
|
class Emitter : public Quad
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Emitter(ParticleEffect *pe);
|
|
|
|
void destroy();
|
|
|
|
void addParticle(Particle *p);
|
|
|
|
void removeParticle(Particle *p);
|
|
|
|
|
|
|
|
SpawnParticleData data;
|
|
|
|
|
|
|
|
void render();
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
bool isEmpty() const {return particles.empty();}
|
|
|
|
|
|
|
|
|
|
|
|
Vector getSpawnPosition();
|
|
|
|
|
|
|
|
bool hasRot;
|
|
|
|
protected:
|
|
|
|
Vector currentSpawn, lastSpawn;
|
|
|
|
void onRender();
|
|
|
|
void spawnParticle(float perc=1);
|
|
|
|
void onUpdate(float dt);
|
|
|
|
|
|
|
|
ParticleEffect *pe;
|
|
|
|
|
|
|
|
typedef std::list<Particle*> Particles;
|
|
|
|
Particles particles;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParticleEffect : public RenderObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ParticleEffect();
|
|
|
|
void load(const std::string &name);
|
|
|
|
void bankLoad(const std::string &name, const std::string &path);
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
bool isRunning() const {return running;}
|
|
|
|
void killParticleEffect();
|
|
|
|
Emitter *addNewEmitter();
|
|
|
|
void clearEmitters();
|
|
|
|
void transfer(ParticleEffect *pe);
|
|
|
|
|
|
|
|
void setDie(bool v);
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
protected:
|
|
|
|
bool die;
|
|
|
|
bool waitForParticles;
|
|
|
|
|
|
|
|
void onUpdate(float dt);
|
|
|
|
void onRender();
|
|
|
|
|
|
|
|
float effectLife, effectLifeCounter;
|
|
|
|
bool running;
|
|
|
|
typedef std::list<Emitter*> Emitters;
|
|
|
|
Emitters emitters;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ParticleInfluence
|
|
|
|
{
|
2015-11-11 22:28:10 +00:00
|
|
|
ParticleInfluence(Vector pos, float spd, float size, bool pull)
|
2017-01-12 21:51:46 +00:00
|
|
|
: pos(pos), size(size), spd(spd), pull(pull)
|
2011-08-03 20:05:33 +00:00
|
|
|
{}
|
2015-11-11 22:28:10 +00:00
|
|
|
ParticleInfluence() : size(0), spd(0), pull(false) {}
|
2011-08-03 20:05:33 +00:00
|
|
|
Vector pos;
|
2015-11-11 22:28:10 +00:00
|
|
|
float size;
|
|
|
|
float spd;
|
2011-08-03 20:05:33 +00:00
|
|
|
bool pull;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParticleManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ParticleManager(int size);
|
2017-01-14 17:10:20 +00:00
|
|
|
void setSize(size_t size);
|
2011-08-03 20:05:33 +00:00
|
|
|
void loadParticleBank(const std::string &bank1, const std::string &bank2);
|
|
|
|
void clearParticleBank();
|
|
|
|
|
|
|
|
Particle *getFreeParticle(Emitter *emitter);
|
|
|
|
int getSize();
|
|
|
|
|
|
|
|
void update(float dt);
|
|
|
|
|
|
|
|
void loadParticleEffectFromBank(const std::string &name, ParticleEffect *load);
|
|
|
|
void updateParticle(Particle *p, float dt);
|
|
|
|
|
|
|
|
void clearInfluences();
|
|
|
|
void addInfluence(ParticleInfluence inf);
|
|
|
|
int (*collideFunction)(Vector pos);
|
|
|
|
void (*specialFunction)(Particle *me);
|
|
|
|
|
|
|
|
void endParticle(Particle *p);
|
|
|
|
|
2017-01-14 17:23:53 +00:00
|
|
|
void setFree(size_t free);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2017-01-20 03:51:38 +00:00
|
|
|
size_t getFree() { return free; }
|
|
|
|
size_t getNumActive() { return numActive; }
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2017-01-20 03:51:38 +00:00
|
|
|
void setNumSuckPositions(size_t num);
|
2017-01-14 17:10:20 +00:00
|
|
|
void setSuckPosition(size_t idx, const Vector &pos);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2017-01-14 17:10:20 +00:00
|
|
|
Vector *getSuckPosition(size_t idx);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
static std::string particleBankPath;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
std::vector<Vector> suckPositions;
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t numActive;
|
2011-08-03 20:05:33 +00:00
|
|
|
Particle* stomp();
|
|
|
|
|
2017-01-19 17:50:33 +00:00
|
|
|
void nextFree(size_t f=1);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t oldFree;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2015-11-11 22:28:10 +00:00
|
|
|
typedef std::vector<ParticleInfluence> Influences;
|
2011-08-03 20:05:33 +00:00
|
|
|
Influences influences;
|
|
|
|
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t size, used, free, halfSize;
|
2011-08-03 20:05:33 +00:00
|
|
|
Particles particles;
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
extern ParticleManager *particleManager;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|