From 912f4b83167007e6ca5bed76d899316a802f1590 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 13 Sep 2013 21:47:52 +0200 Subject: [PATCH] [DEV] display of the first particule done --- ege/Environement.h | 1 + ege/Particule.h | 13 ++++++-- ege/ParticuleEngine.cpp | 72 ++++++++++++++++++++++++++++++++++++++--- ege/ParticuleEngine.h | 36 +++++++++++++++++++-- ege/ParticuleSimple.cpp | 21 ++++++++++-- ege/ParticuleSimple.h | 5 +++ ege/Scene.cpp | 4 ++- 7 files changed, 139 insertions(+), 13 deletions(-) diff --git a/ege/Environement.h b/ege/Environement.h index 1bc4ba2..f389060 100644 --- a/ege/Environement.h +++ b/ege/Environement.h @@ -13,6 +13,7 @@ namespace ege { class Environement; class ElementInteraction; }; +#include #include #include diff --git a/ege/Particule.h b/ege/Particule.h index 181037f..b35b2a8 100644 --- a/ege/Particule.h +++ b/ege/Particule.h @@ -15,6 +15,7 @@ namespace ege { #include #include +#include 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; }; }; }; diff --git a/ege/ParticuleEngine.cpp b/ege/ParticuleEngine.cpp index 9209d12..f272542 100644 --- a/ege/ParticuleEngine.cpp +++ b/ege/ParticuleEngine.cpp @@ -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; iiiGetParticuleType()==_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; iiiNeedRemove()) { - 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; iiiDraw(); + m_particuleList[iii]->Draw(_camera); } } void ege::ParticuleEngine::Clear(void) { + // clear element not removed for (esize_t iii=0; iii m_particuleList; + etk::Vector m_particuleList; //!< all particule created and active + etk::Vector 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); + }; }; diff --git a/ege/ParticuleSimple.cpp b/ege/ParticuleSimple.cpp index 26f5cfb..cce628e 100644 --- a/ege/ParticuleSimple.cpp +++ b/ege/ParticuleSimple.cpp @@ -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; +} diff --git a/ege/ParticuleSimple.h b/ege/ParticuleSimple.h index 99a8d8b..15f70be 100644 --- a/ege/ParticuleSimple.h +++ b/ege/ParticuleSimple.h @@ -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); }; }; diff --git a/ege/Scene.cpp b/ege/Scene.cpp index 1ab5e0c..146b755 100644 --- a/ege/Scene.cpp +++ b/ege/Scene.cpp @@ -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) {