particles ptr fixes

This commit is contained in:
Henrique Santiago 2011-12-15 18:07:57 -02:00
parent 16bb12011a
commit 4f905da009
6 changed files with 21 additions and 7 deletions

View File

@ -35,8 +35,12 @@ class FrameBuffer;
class Shader;
class ShaderProgram;
class PainterShaderProgram;
class Particle;
class ParticleEmitter;
class ParticleSystem;
typedef std::weak_ptr<Texture> TextureWeakPtr;
typedef std::weak_ptr<ParticleSystem> ParticleSystemWeakPtr;
typedef std::shared_ptr<Texture> TexturePtr;
typedef std::shared_ptr<AnimatedTexture> AnimatedTexturePtr;
@ -47,6 +51,9 @@ typedef std::shared_ptr<FrameBuffer> FrameBufferPtr;
typedef std::shared_ptr<Shader> ShaderPtr;
typedef std::shared_ptr<ShaderProgram> ShaderProgramPtr;
typedef std::shared_ptr<PainterShaderProgram> PainterShaderProgramPtr;
typedef std::shared_ptr<Particle> ParticlePtr;
typedef std::shared_ptr<ParticleEmitter> ParticleEmitterPtr;
typedef std::shared_ptr<ParticleSystem> ParticleSystemPtr;
typedef std::vector<ShaderPtr> ShaderList;
#endif

View File

@ -78,8 +78,10 @@ void Particle::update()
m_rect.moveTo((int)m_pos.x, (int)m_pos.y);
}
ParticleEmitter::ParticleEmitter()
ParticleEmitter::ParticleEmitter(const ParticleSystemPtr& parent)
{
m_parent = parent;
m_position = Point(0, 0);
m_duration = -1;
m_burstRate = 1; m_burstCount = 32;
@ -228,6 +230,7 @@ void ParticleEmitter::update()
// every burst created at same position.
float pRadius = Fw::randomRange(m_pMinPositionRadius, m_pMaxPositionRadius);
float pAngle = Fw::randomRange(m_pMinPositionAngle, m_pMaxPositionAngle);
Point pPosition = m_position + Point(pRadius * cos(pAngle), pRadius * sin(pAngle));
for(int p = 0; p < m_burstCount; ++p) {

View File

@ -23,6 +23,7 @@
#ifndef PARTICLEEMITTER_H
#define PARTICLEEMITTER_H
#include "declarations.h"
#include <framework/global.h>
#include <framework/graphics/texture.h>
#include <framework/otml/otml.h>
@ -49,12 +50,11 @@ private:
double m_lastUpdateTime;
bool m_finished;
};
typedef std::shared_ptr<Particle> ParticlePtr;
class ParticleEmitter {
public:
ParticleEmitter();
ParticleEmitter(const ParticleSystemPtr& parent);
bool load(const OTMLNodePtr& node);
@ -64,6 +64,8 @@ public:
bool hasFinished() { return m_finished; }
private:
ParticleSystemWeakPtr m_parent;
// self related
Point m_position;
int m_duration;
@ -95,6 +97,5 @@ private:
Color m_pColor;
TexturePtr m_pTexture;
};
typedef std::shared_ptr<ParticleEmitter> ParticleEmitterPtr;
#endif

View File

@ -23,6 +23,7 @@
#ifndef PARTICLEMANAGER_H
#define PARTICLEMANAGER_H
#include "declarations.h"
#include "particlesystem.h"
class ParticleManager {

View File

@ -21,12 +21,14 @@
*/
#include "particlesystem.h"
#include <framework/core/declarations.h>
#include <framework/ui/declarations.h>
bool ParticleSystem::load(const OTMLNodePtr& node)
{
for(const OTMLNodePtr& childNode : node->children()) {
if(childNode->tag() == "Emitter") {
ParticleEmitterPtr emitter = ParticleEmitterPtr(new ParticleEmitter);
ParticleEmitterPtr emitter = ParticleEmitterPtr(new ParticleEmitter(shared_from_this()));
emitter->load(childNode);
m_emitters.push_back(emitter);
}

View File

@ -23,6 +23,7 @@
#ifndef PARTICLESYSTEM_H
#define PARTICLESYSTEM_H
#include "declarations.h"
#include "particleemitter.h"
class Affector {
@ -37,7 +38,7 @@ public:
}
};
class ParticleSystem {
class ParticleSystem : public std::enable_shared_from_this<ParticleSystem> {
public:
bool load(const OTMLNodePtr& node);
@ -48,6 +49,5 @@ private:
std::list<ParticleEmitterPtr> m_emitters;
std::list<Affector> m_affectors;
};
typedef std::shared_ptr<ParticleSystem> ParticleSystemPtr;
#endif