[DEV] display of the first particule done

This commit is contained in:
Edouard DUPIN 2013-09-13 21:47:52 +02:00
parent 013e809172
commit 912f4b8316
7 changed files with 139 additions and 13 deletions

View File

@ -13,6 +13,7 @@ namespace ege {
class Environement;
class ElementInteraction;
};
#include <ege/Camera.h>
#include <etk/UString.h>
#include <BulletDynamics/Dynamics/btActionInterface.h>

View File

@ -15,6 +15,7 @@ namespace ege {
#include <etk/UString.h>
#include <ege/Environement.h>
#include <ege/Camera.h>
namespace ege {
@ -31,9 +32,10 @@ namespace ege {
public:
/**
* @brief Constructor.
* @param[in] _env reference on the envorionement ...
* @param[in] _particuleEngine reference on the particule engine ...
* @param[in] _particuleType Type of the particule (Set NULL if you did not want to use the respowner ...)
*/
Particule(ege::ParticuleEngine& _particuleEngine, const char* _particuleType);
Particule(ege::ParticuleEngine& _particuleEngine, const char* _particuleType = NULL);
/**
* @brief Destructor.
*/
@ -54,13 +56,18 @@ namespace ege {
/**
* @brief Draw the current particule
*/
virtual void Draw(void) { };
virtual void Draw(const ege::Camera& _camera) { };
/**
* @brief Check if the element might be removed
* @return true : The element might be removed
* @return false : The element might be keeped
*/
virtual bool NeedRemove(void) { return false; };
/**
* @brief Get the type of the particule
* @return Type of the current particule
*/
const char* GetParticuleType(void) { return m_particuleType; };
};
};

View File

@ -20,7 +20,7 @@ ege::ParticuleEngine::ParticuleEngine(ege::Environement& _env) :
ege::ParticuleEngine::~ParticuleEngine(void)
{
Clear();
}
void ege::ParticuleEngine::Add(Particule* _particule)
@ -40,8 +40,47 @@ void ege::ParticuleEngine::Add(Particule* _particule)
m_particuleList.PushBack(_particule);
}
void ege::ParticuleEngine::AddRemoved(Particule* _particule)
{
if (_particule==NULL) {
return;
}
for (esize_t iii=0; iii<m_particuleRemoved.Size(); ++iii) {
if (m_particuleRemoved[iii] != NULL) {
continue;
}
m_particuleRemoved[iii] = _particule;
return;
}
// Just add it at the end ...
m_particuleRemoved.PushBack(_particule);
}
ege::Particule* ege::ParticuleEngine::Respown(const char* _particuleType)
{
if (_particuleType == NULL) {
return NULL;
}
for (esize_t iii=0; iii<m_particuleRemoved.Size(); ++iii) {
if (m_particuleRemoved[iii] == NULL) {
continue;
}
if (m_particuleRemoved[iii]->GetParticuleType()==_particuleType) {
Add(m_particuleRemoved[iii]);
ege::Particule* tmpParticule = m_particuleRemoved[iii];
m_particuleRemoved[iii]=NULL;
tmpParticule->Init();
return tmpParticule;
}
}
return NULL;
}
void ege::ParticuleEngine::Update(float _deltaTime)
{
if (_deltaTime>(1.0f/60.0f)) {
_deltaTime = (1.0f/60.0f);
}
for (esize_t iii=0; iii<m_particuleList.Size(); ++iii) {
if (m_particuleList[iii] == NULL) {
continue;
@ -54,24 +93,40 @@ void ege::ParticuleEngine::Update(float _deltaTime)
continue;
}
if (m_particuleList[iii]->NeedRemove()) {
delete m_particuleList[iii];
if (m_particuleList[iii]->GetParticuleType()==NULL) {
// Real remove particule ...
delete (m_particuleList[iii]);
} else {
AddRemoved(m_particuleList[iii]);
}
m_particuleList[iii] = NULL;
}
}
/*
int32_t nbParticule = 0;
for (esize_t iii=0; iii<m_particuleList.Size(); ++iii) {
if (m_particuleList[iii] == NULL) {
continue;
}
nbParticule++;
}
EGE_DEBUG("number of particule : " << nbParticule);
*/
}
void ege::ParticuleEngine::Draw(void)
void ege::ParticuleEngine::Draw(const ege::Camera& _camera)
{
for (esize_t iii=0; iii<m_particuleList.Size(); ++iii) {
if (m_particuleList[iii] == NULL) {
continue;
}
m_particuleList[iii]->Draw();
m_particuleList[iii]->Draw(_camera);
}
}
void ege::ParticuleEngine::Clear(void)
{
// clear element not removed
for (esize_t iii=0; iii<m_particuleList.Size(); ++iii) {
if (m_particuleList[iii] == NULL) {
continue;
@ -80,4 +135,13 @@ void ege::ParticuleEngine::Clear(void)
m_particuleList[iii] = NULL;
}
m_particuleList.Clear();
// clear element that are auto-removed
for (esize_t iii=0; iii<m_particuleRemoved.Size(); ++iii) {
if (m_particuleRemoved[iii] == NULL) {
continue;
}
delete m_particuleRemoved[iii];
m_particuleRemoved[iii] = NULL;
}
m_particuleRemoved.Clear();
}

View File

@ -28,12 +28,44 @@ namespace ege {
ParticuleEngine(ege::Environement& _env); // note : Need the engine to register has an dynamic element ... (the first ...)
~ParticuleEngine(void);
private:
etk::Vector<Particule*> m_particuleList;
etk::Vector<Particule*> m_particuleList; //!< all particule created and active
etk::Vector<Particule*> m_particuleRemoved; //!< removed particule
public:
/**
* @brief Clear the particule engine
*/
void Clear(void);
/**
* @brief Add a particule in the engine (internal acces only)
* @param[in] _particule Pointer on the particule to add
*/
void Add(Particule* _particule);
private:
/**
* @brief Add a particule in the removed section ==> this not delete the particule, but just set it in an other list
* @param[in] _particule Pointer on the particule to add
*/
void AddRemoved(Particule* _particule);
public:
/**
* @brief Update particule properties
* @param[in] _deltaTime delta time to process
*/
void Update(float _deltaTime);
void Draw(void);
/**
* @brief Draw all the active Particule
* @param[in] _camera Reference on the current camera
*/
void Draw(const ege::Camera& _camera);
/**
* @brief Get a particue with his type, we get particule that has been already removed, otherwise, you will create new
* @param[in] _particuleType Particule type, this chek only the pointer not the data.
* @return NULL, the particule has not been removed from the created pool
* @return The pointer on the requested element (an Init has been done).
* @note If you did not want to use respawn set type at NULL.
*/
Particule* Respown(const char* _particuleType);
};
};

View File

@ -22,11 +22,14 @@ ege::ParticuleSimple::ParticuleSimple(ege::ParticuleEngine& _particuleEngine, co
void ege::ParticuleSimple::Init(void)
{
m_life = 0;
m_lifeFull = 3;
m_life = m_lifeFull;
m_level = 0;
m_pos = vec3(0,0,0);
m_angle = vec4(0,0,0,0);
m_speed = vec3(0,0,0);
m_scale = vec3(1,1,1);
m_scaleExpand = vec3(0,0,0);
}
bool ege::ParticuleSimple::NeedRemove(void)
@ -37,13 +40,16 @@ bool ege::ParticuleSimple::NeedRemove(void)
void ege::ParticuleSimple::Update(float _delta)
{
//EGE_DEBUG("Life : " << m_life << "-" << _delta);
m_life -= _delta;
m_pos += m_speed;
m_pos += m_speed*_delta;
m_scale += m_scaleExpand*_delta;
}
void ege::ParticuleSimple::SetLife(float _life)
{
m_life = _life;
m_lifeFull = _life;
m_life = m_lifeFull;
}
void ege::ParticuleSimple::SetLevel(float _level)
@ -66,3 +72,12 @@ void ege::ParticuleSimple::SetMoveSpeed(const vec3& _speed)
m_speed = _speed;
}
void ege::ParticuleSimple::SetScale(const vec3& _scale)
{
m_scale = _scale;
}
void ege::ParticuleSimple::SetScaleExpend(const vec3& _scaleExpand)
{
m_scaleExpand=_scaleExpand;
}

View File

@ -46,11 +46,14 @@ namespace ege {
virtual bool NeedRemove(void);
virtual void Init(void);
protected:
float m_lifeFull;
float m_life;
float m_level;
vec3 m_pos;
vec4 m_angle;
vec3 m_speed;
vec3 m_scale;
vec3 m_scaleExpand;
public:
/**
*
@ -60,6 +63,8 @@ namespace ege {
virtual void SetPosition(const vec3& _pos);
virtual void SetAngleSpeed(const vec4& _angle);
virtual void SetMoveSpeed(const vec3& _speed);
virtual void SetScale(const vec3& _scale);
virtual void SetScaleExpend(const vec3& _scaleExpand);
};
};

View File

@ -228,7 +228,9 @@ void ege::Scene::OnDraw(void)
}
#endif
}
m_env.GetParticuleEngine().Draw();
if (NULL!=m_camera) {
m_env.GetParticuleEngine().Draw(*m_camera);
}
#ifdef SCENE_DISPLAY_SPEED
float localTime = (float)(ewol::GetTime() - g_startTime) / 1000.0f;
if (localTime>1) {