diff --git a/ege/Component.cpp b/ege/Component.cpp new file mode 100644 index 0000000..14f7fe6 --- /dev/null +++ b/ege/Component.cpp @@ -0,0 +1,12 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include + +const std::string& ege::Component::getType() const { + static std::string tmp("component"); + return tmp; +} + diff --git a/ege/Component.hpp b/ege/Component.hpp new file mode 100644 index 0000000..2870ade --- /dev/null +++ b/ege/Component.hpp @@ -0,0 +1,35 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include +#include +#include + + +namespace ege { + class Component : public ememory::EnableSharedFromThis { + protected: + + public: + virtual const std::string& getType() const; + + /** + * @brief Evironement notify that a new component is added on the same Element + * @param[in] _component New component added + */ + virtual void addFriendComponent(const ememory::SharedPtr& _component) { + // nothing to do. + } + /** + * @brief Evironement notify that a component is removed on the same Element + * @param[in] _component Old component removed + */ + virtual void removeFriendComponent(const ememory::SharedPtr& _component) { + // nothing to do. + } + }; +} \ No newline at end of file diff --git a/ege/Environement.cpp b/ege/Environement.cpp index 241f200..a7d8eff 100644 --- a/ege/Environement.cpp +++ b/ege/Environement.cpp @@ -382,7 +382,7 @@ void ege::Environement::clear() { void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) { float curentDelta = _event.getDeltaCall(); - EGE_VERBOSE("periodic call : " << _event); + EGE_INFO("periodic call : " << _event); // small hack to change speed ... curentDelta *= *propertyRatio; // check if the processing is availlable @@ -393,7 +393,7 @@ void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) int32_t lastGameTime = m_gameTime*0.000001f; m_gameTime += curentDelta; if (lastGameTime != (int32_t)(m_gameTime*0.000001f)) { - EGE_VERBOSE(" Emit Signal"); + EGE_INFO(" Emit Signal"); signalPlayTimeChange.emit(m_gameTime*0.000001f); } @@ -402,17 +402,17 @@ void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) // update camera positions: for (auto &it : m_listCamera) { if (it.second != nullptr) { - EGE_VERBOSE(" update camera : '" << it.first << "'"); + EGE_INFO(" update camera : '" << it.first << "'"); it.second->periodicCall(curentDelta); } } //EGE_DEBUG("stepSimulation (start)"); ///step the simulation - EGE_VERBOSE(" step simulation : " << curentDelta); + EGE_INFO(" step simulation : " << curentDelta); m_physicEngine.update(curentDelta); //optional but useful: debug drawing m_physicEngine.debugDrawWorld(); - EGE_VERBOSE(" Update particule engine"); + EGE_INFO(" Update particule engine"); m_particuleEngine.update(curentDelta); // remove all element that requested it ... { @@ -426,7 +426,7 @@ void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) numberEnnemyKilled++; victoryPoint++; } - EGE_VERBOSE("[" << (*it)->getUID() << "] element Removing ... " << (*it)->getType()); + EGE_INFO("[" << (*it)->getUID() << "] element Removing ... " << (*it)->getType()); rmElement((*it)); it = m_listElement.begin(); } else { diff --git a/ege/Environement.hpp b/ege/Environement.hpp index d7ab446..c387a4a 100644 --- a/ege/Environement.hpp +++ b/ege/Environement.hpp @@ -10,7 +10,9 @@ namespace ege { class ElementInteraction; }; #include -#include +#include +#include +#include #include #include #include diff --git a/ege/elements/Element.cpp b/ege/elements/Element.cpp index 75ae853..9800a7a 100644 --- a/ege/elements/Element.cpp +++ b/ege/elements/Element.cpp @@ -19,6 +19,11 @@ const std::string& ege::Element::getType() const { ege::Element::Element(const ememory::SharedPtr& _env) : m_env(_env), + m_idRender(-1), + m_idIA(-1), + m_idParticule(-1), + m_idPhysics(-1), + m_idPosition(-1), m_uID(0), m_mesh(), m_life(100), @@ -37,6 +42,150 @@ ege::Element::~Element() { EGE_DEBUG("Destroy element: uId=" << m_uID); } +void ege::Element::addComponent(const ememory::SharedPtr& _ref) { + if (_ref == nullptr) { + EGE_ERROR("try to add an empty component"); + return; + } + ememory::SharedPtr componentRemoved; + int32_t findId = -1; + // check if not exist + for (int32_t iii=0; iiigetType() == _ref->getType()) { + componentRemoved = m_component[iii]; + m_component[iii] = _ref; + findId = iii; + break; + } + } + // try to add in an empty slot + if (findId == -1) { + for (int32_t iii=0; iiigetType() == "IA") { + m_idIA = findId; + m_env->getIAEngine().remove(_ref); + } else if (_ref->getType() == "render") { + m_idRender = findId; + } else if (_ref->getType() == "particule") { + m_idParticule = findId; + } else if (_ref->getType() == "physics") { + m_idPhysics = findId; + } else if (_ref->getType() == "position") { + m_idPosition = findId; + } + for (int32_t iii=0; iiiengineComponentRemove(componentRemoved); + m_component[iii]->removeFriendComponent(componentRemoved); + } + m_env->engineComponentAdd(_ref); + m_component[iii]->addFriendComponent(_ref); + } + +} +void ege::Element::rmComponent(const ememory::SharedPtr& _ref) { + if (_ref == nullptr) { + EGE_ERROR("try to remove an empty component"); + return; + } + int32_t findId = -1; + // check if not exist + for (int32_t iii=0; iiigetType() == "IA") { + m_idIA = -1; + } else if (_ref->getType() == "render") { + m_idRender = -1; + } else if (_ref->getType() == "particule") { + m_idParticule = -1; + } else if (_ref->getType() == "physics") { + m_idPhysics = -1; + } else if (_ref->getType() == "position") { + m_idPosition = -1; + //m_env->getPositionEngine().remove(componentRemoved); + } + for (int32_t iii=0; iiiengineComponentRemove(_ref); + m_component[iii]->removeFriendComponent(_ref); + } +} + +void ege::Element::rmComponent(const std::string& _type) { + int32_t findId = -1; + ememory::SharedPtr componentRemoved; + // check if not exist + for (int32_t iii=0; iiigetType() == _type) { + componentRemoved = m_component[iii]; + m_component[iii] = nullptr; + findId = iii; + break; + } + } + if (findId == -1) { + EGE_ERROR("try to remove an unexisting component type : '" << _type << "'"); + return; + } + if (_type == "IA") { + m_idIA = -1; + } else if (_type == "render") { + m_idRender = -1; + } else if (_type == "particule") { + m_idParticule = -1; + } else if (_type == "physics") { + m_idPhysics = -1; + } else if (_type == "position") { + m_idPosition = -1; + } + for (int32_t iii=0; iiiengineComponentRemove(componentRemoved); + m_component[iii]->removeFriendComponent(componentRemoved); + } +} + + + + bool ege::Element::init() { EGE_WARNING("init() not implemented: uId=" << m_uID); diff --git a/ege/elements/Element.hpp b/ege/elements/Element.hpp index fa1709c..5748bf6 100644 --- a/ege/elements/Element.hpp +++ b/ege/elements/Element.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #define INDEX_RIGHT_AXIS (0) #define INDEX_FORWARD_AXIS (1) @@ -39,6 +40,22 @@ namespace ege { * @brief Destructor */ virtual ~Element(); + protected: + std::vector> m_component; + int32_t m_idRender; //!< fast reference on the Render component (can static cast and not dynamic cast) + int32_t m_idIA; //!< fast reference on the IA component. + int32_t m_idParticule; //!< fast reference on the Particule component. + int32_t m_idPhysics; //!< fast reference on the Physics component. + int32_t m_idPosition; //!< fast reference on the position component ==> incompatible with 'physics' component. + // int32_t m_idCamera; //!< fast reference on the camera component. + // int32_t m_idSound; //!< fast reference on the Sound component. + // int32_t m_idLife; //!< fast reference on the Life component. + // ... and evry thing the user want to add ... to create a good game ... + public: + void addComponent(const ememory::SharedPtr& _ref); + void rmComponent(const ememory::SharedPtr& _ref); + void rmComponent(const std::string& _type); + /** * @brief get the element Type description string. * @return A reference on the descriptive string. @@ -66,6 +83,11 @@ namespace ege { inline uint32_t getUID() const { return m_uID; }; + /* + * ********************************* + * Remove in progress .... [BEGIN] + * ********************************* + */ protected: ememory::SharedPtr m_mesh; //!< Mesh of the Element (can be nullptr) public: @@ -90,6 +112,11 @@ namespace ege { inline ememory::SharedPtr getMesh() { return m_mesh; }; + /* + * ********************************* + * Remove in progress .... [END] + * ********************************* + */ protected: float m_life; //!< Current life of the object float m_lifeMax; //!< Maximum possible life of the element @@ -153,7 +180,7 @@ namespace ege { * @brief draw the curent element (can have multiple display) * @param[in] pass Id of the current pass : [0..?] */ - virtual void draw(int32_t _pass=0) = 0; + virtual void draw(int32_t _pass=0) { }; /** * @brief draw the current life of the element @@ -233,17 +260,6 @@ namespace ege { */ virtual void dynamicDisable() {}; - // TODO: next step: - /* - public: - void addComponent(const std::string& _name, const ememory::SharedPtr& _ref); - example: addComponent("physic", componentPhysic); - addComponent("ia", componentIA); - addComponent("render", componentRendering); - addComponent("group", componentFormationMovingSquare); // << here we add a group to control the moving interface of the IA ... - if we want to remove the IA, just remove the component, - if the display (render) change (unit upgrade) just the render is change, if it is invisible, just remove the render ... - */ }; } diff --git a/ege/ia/Component.cpp b/ege/ia/Component.cpp new file mode 100644 index 0000000..2ad2273 --- /dev/null +++ b/ege/ia/Component.cpp @@ -0,0 +1,12 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include + +const std::string& ege::ia::Component::getType() const { + static std::string tmp("ia"); + return tmp; +} + diff --git a/ege/ia/Component.hpp b/ege/ia/Component.hpp new file mode 100644 index 0000000..b7ca2ca --- /dev/null +++ b/ege/ia/Component.hpp @@ -0,0 +1,21 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include + +#include + +namespace ege { + namespace ia { + class Component : public ege::Component { + protected: + + public: + virtual const std::string& getType() const; + }; + } +} \ No newline at end of file diff --git a/ege/ia/Engine.cpp b/ege/ia/Engine.cpp new file mode 100644 index 0000000..e69de29 diff --git a/ege/ia/Engine.hpp b/ege/ia/Engine.hpp new file mode 100644 index 0000000..6bf568a --- /dev/null +++ b/ege/ia/Engine.hpp @@ -0,0 +1,27 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2017, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include +#include +#include +#include +#include + + +namespace ege { + namespace ia { + class Engine { + public: + Engine() {} + ~Engine() {} + + // update cycle + void update(float _delta) {} + }; + } +} + diff --git a/ege/particule/Component.cpp b/ege/particule/Component.cpp new file mode 100644 index 0000000..e99b1e1 --- /dev/null +++ b/ege/particule/Component.cpp @@ -0,0 +1,20 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include +#include +#include + +const std::string& ege::particule::Component::getType() const { + static std::string tmp("particule"); + return tmp; +} + +ege::particule::Component::Component(ege::particule::Engine* _particuleEngine, const char* _particuleType) : + m_particuleEngine(_particuleEngine), + m_particuleType(_particuleType) { + m_particuleEngine->add(ememory::staticPointerCast(sharedFromThis())); +} + diff --git a/ege/particule/Component.hpp b/ege/particule/Component.hpp new file mode 100644 index 0000000..d1761cd --- /dev/null +++ b/ege/particule/Component.hpp @@ -0,0 +1,72 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include + +#include + +#include + +namespace ege { + namespace particule { + class Engine; + class Component : public ege::Component { + public: + virtual const std::string& getType() const; + protected: + ege::particule::Engine* m_particuleEngine; + const char* m_particuleType; + public: + /** + * @brief Constructor. + * @param[in] _particuleEngine reference on the particule engine ... + * @param[in] _particuleType Type of the particule (set nullptr if you did not want to use the respowner ...) + */ + Component(ege::particule::Engine* _particuleEngine, const char* _particuleType = nullptr); + /** + * @brief Destructor. + */ + virtual ~Component() = default; + /** + * @brief init the particule + */ + virtual void init() { }; + /** + * @brief Un-init the particule + */ + virtual void UnInit() { }; + /** + * @brief update the paticule properties + * @param[in] _delta Delta time from the previous call + */ + virtual void update(float _delta) { }; + /** + * @brief draw the current particule + */ + 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() { + return false; + }; + /** + * @brief get the type of the particule + * @return Type of the current particule + */ + const char* getParticuleType() { + return m_particuleType; + }; + /** + * @brief When the particule arrive to his end of life, this function is called. + */ + virtual void onEnd() {}; + }; + } +} \ No newline at end of file diff --git a/ege/particule/Engine.cpp b/ege/particule/Engine.cpp index b8879e3..a63cf80 100644 --- a/ege/particule/Engine.cpp +++ b/ege/particule/Engine.cpp @@ -5,20 +5,20 @@ */ #include -#include +#include #include -#include +#include -ege::ParticuleEngine::ParticuleEngine(ege::Environement* _env) : +ege::particule::Engine::Engine(ege::Environement* _env) : m_env(_env) { } -ege::ParticuleEngine::~ParticuleEngine() { +ege::particule::Engine::~Engine() { clear(); } -void ege::ParticuleEngine::add(Particule* _particule) { +void ege::particule::Engine::add(const ememory::SharedPtr& _particule) { if (_particule == nullptr) { EGE_ERROR("Try to add particule nullptr"); return; @@ -34,7 +34,7 @@ void ege::ParticuleEngine::add(Particule* _particule) { m_particuleList.push_back(_particule); } -void ege::ParticuleEngine::addRemoved(Particule* _particule) { +void ege::particule::Engine::addRemoved(const ememory::SharedPtr& _particule) { if (_particule == nullptr) { return; } @@ -49,7 +49,7 @@ void ege::ParticuleEngine::addRemoved(Particule* _particule) { m_particuleRemoved.push_back(_particule); } -ege::Particule* ege::ParticuleEngine::respown(const char* _particuleType) { +ememory::SharedPtr ege::particule::Engine::respown(const char* _particuleType) { if (_particuleType == nullptr) { return nullptr; } @@ -59,8 +59,8 @@ ege::Particule* ege::ParticuleEngine::respown(const char* _particuleType) { } if (m_particuleRemoved[iii]->getParticuleType() == _particuleType) { add(m_particuleRemoved[iii]); - ege::Particule* tmpParticule = m_particuleRemoved[iii]; - m_particuleRemoved[iii]=nullptr; + ememory::SharedPtr tmpParticule = m_particuleRemoved[iii]; + m_particuleRemoved[iii].reset(); tmpParticule->init(); return tmpParticule; } @@ -68,10 +68,11 @@ ege::Particule* ege::ParticuleEngine::respown(const char* _particuleType) { return nullptr; } -void ege::ParticuleEngine::update(float _deltaTime) { +void ege::particule::Engine::update(float _deltaTime) { if (_deltaTime>(1.0f/60.0f)) { _deltaTime = (1.0f/60.0f); } + EGE_WARNING("Update the Particule engine ... " << _deltaTime); for (size_t iii=0; iiionEnd(); if (m_particuleList[iii]->getParticuleType() == nullptr) { // Real remove particule ... - delete (m_particuleList[iii]); + m_particuleList[iii].reset(); } else { addRemoved(m_particuleList[iii]); } @@ -106,7 +107,7 @@ void ege::ParticuleEngine::update(float _deltaTime) { */ } -void ege::ParticuleEngine::draw(const ege::Camera& _camera) { +void ege::particule::Engine::draw(const ege::Camera& _camera) { for (size_t iii=0; iii #include #include +#include namespace ege { - class ParticuleEngine { - private: - ege::Environement* m_env; - public: - ParticuleEngine(ege::Environement* _env); // note : need the engine to register has an dynamic element ... (the first ...) - ~ParticuleEngine(); - private: - std::vector m_particuleList; //!< all particule created and active - std::vector m_particuleRemoved; //!< removed particule - public: - /** - * @brief clear the particule engine - */ - void clear(); - /** - * @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); - /** - * @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 nullptr, 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 nullptr. - */ - Particule* respown(const char* _particuleType); - - }; + class Environement; + namespace particule { + class Component; + class Engine { + private: + ege::Environement* m_env; + public: + Engine(ege::Environement* _env); // note : need the engine to register has an dynamic element ... (the first ...) + ~Engine(); + private: + std::vector> m_particuleList; //!< all particule created and active + std::vector> m_particuleRemoved; //!< removed particule + public: + /** + * @brief clear the particule engine + */ + void clear(); + /** + * @brief add a particule in the engine (internal acces only) + * @param[in] _particule Pointer on the particule to add + */ + void add(const ememory::SharedPtr& _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(const ememory::SharedPtr& _particule); + public: + /** + * @brief update particule properties + * @param[in] _deltaTime delta time to process + */ + void update(float _deltaTime); + /** + * @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 nullptr, 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 nullptr. + */ + ememory::SharedPtr respown(const char* _particuleType); + + }; + } } diff --git a/ege/particule/Particule.cpp b/ege/particule/Particule.cpp index 212f715..e69de29 100644 --- a/ege/particule/Particule.cpp +++ b/ege/particule/Particule.cpp @@ -1,16 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -#include -#include -#include - -ege::Particule::Particule(ege::ParticuleEngine* _particuleEngine, const char* _particuleType) : - m_particuleEngine(_particuleEngine), - m_particuleType(_particuleType) { - m_particuleEngine->add(this); -} - diff --git a/ege/particule/Particule.hpp b/ege/particule/Particule.hpp index fdec5ad..e69de29 100644 --- a/ege/particule/Particule.hpp +++ b/ege/particule/Particule.hpp @@ -1,78 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ -#pragma once - -namespace ege { - class ParticuleEngine; -}; - -#include -#include -#include - - -namespace ege { - /** - * @brief The particule class is an element with no control, when it will be created, - * it does not have any control, for example smoke or reactor generation ... - * or explosion particule ... - */ - class Particule { - protected: - ege::ParticuleEngine* m_particuleEngine; - const char* m_particuleType; - public: - /** - * @brief Constructor. - * @param[in] _particuleEngine reference on the particule engine ... - * @param[in] _particuleType Type of the particule (set nullptr if you did not want to use the respowner ...) - */ - Particule(ege::ParticuleEngine* _particuleEngine, const char* _particuleType = nullptr); - /** - * @brief Destructor. - */ - virtual ~Particule() { }; - /** - * @brief init the particule - */ - virtual void init() { }; - /** - * @brief Un-init the particule - */ - virtual void UnInit() { }; - /** - * @brief update the paticule properties - * @param[in] _delta Delta time from the previous call - */ - virtual void update(float _delta) { }; - /** - * @brief draw the current particule - */ - 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() { - return false; - }; - /** - * @brief get the type of the particule - * @return Type of the current particule - */ - const char* getParticuleType() { - return m_particuleType; - }; - /** - * @brief When the particule arrive to his end of life, this function is called. - */ - virtual void onEnd() {}; - }; -} - - - diff --git a/ege/particule/Simple.cpp b/ege/particule/Simple.cpp index 1e8d3b0..8f69ef1 100644 --- a/ege/particule/Simple.cpp +++ b/ege/particule/Simple.cpp @@ -5,14 +5,14 @@ */ #include -#include +#include -ege::ParticuleSimple::ParticuleSimple(ege::ParticuleEngine* _particuleEngine, const char* _particuleType) : - Particule(_particuleEngine, _particuleType) { +ege::particule::Simple::Simple(ege::particule::Engine* _particuleEngine, const char* _particuleType) : + ege::particule::Component(_particuleEngine, _particuleType) { init(); } -void ege::ParticuleSimple::init() { +void ege::particule::Simple::init() { m_lifeFull = 3; m_life = m_lifeFull; m_level = 0; @@ -23,43 +23,43 @@ void ege::ParticuleSimple::init() { m_scaleExpand = vec3(0,0,0); } -bool ege::ParticuleSimple::needRemove() { +bool ege::particule::Simple::needRemove() { return m_life<0.0f; } -void ege::ParticuleSimple::update(float _delta) { +void ege::particule::Simple::update(float _delta) { //EGE_DEBUG("Life : " << m_life << "-" << _delta); m_life -= _delta; m_pos += m_speed*_delta; m_scale += m_scaleExpand*_delta; } -void ege::ParticuleSimple::setLife(float _life) { +void ege::particule::Simple::setLife(float _life) { m_lifeFull = _life; m_life = m_lifeFull; } -void ege::ParticuleSimple::setLevel(float _level) { +void ege::particule::Simple::setLevel(float _level) { m_level = _level; } -void ege::ParticuleSimple::setPosition(const vec3& _pos) { +void ege::particule::Simple::setPosition(const vec3& _pos) { m_pos = _pos; } -void ege::ParticuleSimple::setAngle(float _angle) { +void ege::particule::Simple::setAngle(float _angle) { m_angle = _angle; } -void ege::ParticuleSimple::setMoveSpeed(const vec3& _speed) { +void ege::particule::Simple::setMoveSpeed(const vec3& _speed) { m_speed = _speed; } -void ege::ParticuleSimple::setScale(const vec3& _scale) { +void ege::particule::Simple::setScale(const vec3& _scale) { m_scale = _scale; } -void ege::ParticuleSimple::setScaleExpend(const vec3& _scaleExpand) { +void ege::particule::Simple::setScaleExpend(const vec3& _scaleExpand) { m_scaleExpand=_scaleExpand; } diff --git a/ege/particule/Simple.hpp b/ege/particule/Simple.hpp index bdfeb24..0016c02 100644 --- a/ege/particule/Simple.hpp +++ b/ege/particule/Simple.hpp @@ -14,53 +14,55 @@ namespace ege { #include #include #include -#include +#include namespace ege { - /** - * @brief The particule class is an element with no control, when it will be created, - * it does not have any control, for example smoke or reactor generation ... - * or explosion particule ... - */ - class ParticuleSimple : public Particule { - public: - /** - * @brief Constructor. - * @param[in] _name Name of the particule. - * @param[in] _standalone The particule are created and have there own life (no dynamic control) - */ - ParticuleSimple(ege::ParticuleEngine* _particuleEngine, const char* _particuleType); - /** - * @brief Destructor. - */ - virtual ~ParticuleSimple() { }; - public: // herited elements: - virtual void update(float _delta); - //virtual void draw() { }; - virtual bool needRemove(); - virtual void init(); - protected: - float m_lifeFull; - float m_life; - float m_level; - vec3 m_pos; - float m_angle; - vec3 m_speed; - vec3 m_scale; - vec3 m_scaleExpand; - public: - /** - * - */ - virtual void setLife(float _life); - virtual void setLevel(float _level); - virtual void setPosition(const vec3& _pos); - virtual void setAngle(float _angle); - virtual void setMoveSpeed(const vec3& _speed); - virtual void setScale(const vec3& _scale); - virtual void setScaleExpend(const vec3& _scaleExpand); - }; + namespace particule { + /** + * @brief The particule class is an element with no control, when it will be created, + * it does not have any control, for example smoke or reactor generation ... + * or explosion particule ... + */ + class Simple : public ege::particule::Component { + public: + /** + * @brief Constructor. + * @param[in] _name Name of the particule. + * @param[in] _standalone The particule are created and have there own life (no dynamic control) + */ + Simple(ege::particule::Engine* _particuleEngine, const char* _particuleType); + /** + * @brief Destructor. + */ + virtual ~Simple() { }; + public: // herited elements: + virtual void update(float _delta); + //virtual void draw() { }; + virtual bool needRemove(); + virtual void init(); + protected: + float m_lifeFull; + float m_life; + float m_level; + vec3 m_pos; + float m_angle; + vec3 m_speed; + vec3 m_scale; + vec3 m_scaleExpand; + public: + /** + * + */ + virtual void setLife(float _life); + virtual void setLevel(float _level); + virtual void setPosition(const vec3& _pos); + virtual void setAngle(float _angle); + virtual void setMoveSpeed(const vec3& _speed); + virtual void setScale(const vec3& _scale); + virtual void setScaleExpend(const vec3& _scaleExpand); + }; + } } diff --git a/ege/physics/Component.cpp b/ege/physics/Component.cpp new file mode 100644 index 0000000..902c34a --- /dev/null +++ b/ege/physics/Component.cpp @@ -0,0 +1,30 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include + +const std::string& ege::physics::Component::getType() const { + static std::string tmp("physics"); + return tmp; +} + + +void ege::physics::Component::setTransform(const etk::Transform3D& _transform) { + /* + if (_transform == m_transform) { + return; + } + m_transform = _transform; + signalPosition.emit(m_transform); + */ +} + +const etk::Transform3D& ege::physics::Component::getTransform() const { + /* + return m_transform; + */ + return etk::Transform3D::identity(); +} + diff --git a/ege/physics/Component.hpp b/ege/physics/Component.hpp new file mode 100644 index 0000000..8683ceb --- /dev/null +++ b/ege/physics/Component.hpp @@ -0,0 +1,35 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include + +#include +#include +#include + +namespace ege { + namespace physics { + class Component : public ege::Component { + public: + esignal::Signal signalPosition; + protected: + + public: + virtual const std::string& getType() const; + /** + * @brief set a new transformation + * @param[in] _transform transformation of the position + */ + void setTransform(const etk::Transform3D& _transform); + /** + * @brief set a new transformation + * @return Transformation of the position + */ + const etk::Transform3D& getTransform() const; + }; + } +} \ No newline at end of file diff --git a/ege/physics/Engine.cpp b/ege/physics/Engine.cpp index 0581dfe..78c75b2 100644 --- a/ege/physics/Engine.cpp +++ b/ege/physics/Engine.cpp @@ -46,6 +46,10 @@ ege::physics::Engine::Engine(): rp3d::Vector3 gravity(0.0f, 0.0f, 0.0f); // Create the dynamics world m_dynamicsWorld = new rp3d::DynamicsWorld(gravity); + if (m_dynamicsWorld != nullptr) { + // Set the number of iterations of the constraint solver + m_dynamicsWorld->setNbIterationsVelocitySolver(15); + } } ege::physics::Engine::~Engine() { @@ -70,8 +74,11 @@ void ege::physics::Engine::update(float _delta) { m_accumulator += _delta; // While there is enough accumulated time to take one or several physics steps while (m_accumulator >= timeStep) { - // Update the Dynamics world with a constant time step - m_dynamicsWorld->update(timeStep); + if (m_dynamicsWorld != nullptr) { + // Update the Dynamics world with a constant time step + EGE_WARNING("Update the Physic engine ... " << timeStep); + m_dynamicsWorld->update(timeStep); + } // Decrease the accumulated time m_accumulator -= timeStep; } diff --git a/ege/position/Component.cpp b/ege/position/Component.cpp new file mode 100644 index 0000000..f7d2e12 --- /dev/null +++ b/ege/position/Component.cpp @@ -0,0 +1,42 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include + +const std::string& ege::position::Component::getType() const { + static std::string tmp("position"); + return tmp; +} + + +ege::position::Component::Component(const etk::Transform3D& _transform): + m_transform(_transform) { + +} + +ege::position::Component::Component(): + m_transform(etk::Transform3D::identity()) { + +} + +void ege::position::Component::setTransform(const etk::Transform3D& _transform) { + if (_transform == m_transform) { + return; + } + m_transform = _transform; + signalPosition.emit(m_transform); +} + +const etk::Transform3D& ege::position::Component::getTransform() const { + return m_transform; +} + + +void ege::position::Component::addFriendComponent(const ememory::SharedPtr& _component) { + if (_component->getType() == "physics") { + EGE_ERROR("Can not add a 'physic' component and a 'position' component ... ==> incompatible"); + } +} + diff --git a/ege/position/Component.hpp b/ege/position/Component.hpp new file mode 100644 index 0000000..123828f --- /dev/null +++ b/ege/position/Component.hpp @@ -0,0 +1,46 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include + +#include +#include +#include + +namespace ege { + namespace position { + class Component : public ege::Component { + public: + esignal::Signal signalPosition; + protected: + etk::Transform3D m_transform; + public: + /** + * @brief Create a basic position component (no orientation and position (0,0,0)) + */ + Component(); + /** + * @brief Create a basic position component + * @param[in] _transform transformation of the position + */ + Component(const etk::Transform3D& _transform); + /** + * @brief set a new transformation + * @param[in] _transform transformation of the position + */ + void setTransform(const etk::Transform3D& _transform); + /** + * @brief set a new transformation + * @return Transformation of the position + */ + const etk::Transform3D& getTransform() const; + public: + const std::string& getType() const override; + void addFriendComponent(const ememory::SharedPtr& _component) override; + }; + } +} \ No newline at end of file diff --git a/ege/render/Component.cpp b/ege/render/Component.cpp new file mode 100644 index 0000000..de3c730 --- /dev/null +++ b/ege/render/Component.cpp @@ -0,0 +1,69 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include +#include +#include + +const std::string& ege::render::Component::getType() const { + static std::string tmp("render"); + return tmp; +} + +ege::render::Component::Component() { + +} + +ege::render::Component::Component(const std::string& _fileName) { + loadMesh(_fileName); +} + +ege::render::Component::Component(ememory::SharedPtr _mesh) : + m_mesh(_mesh) { + +} + +void ege::render::Component::addFriendComponent(const ememory::SharedPtr& _component) { + if (_component->getType() == "physics") { + // get the real usable pointer + ememory::SharedPtr component = ememory::staticPointerCast(_component); + // get the current transform + m_transform = component->getTransform(); + // connnect a signal on it to keep all change + component->signalPosition.connect(sharedFromThis(), &ege::render::Component::onSignalPositionChange); + } else if (_component->getType() == "position") { + // get the real usable pointer + ememory::SharedPtr component = ememory::staticPointerCast(_component); + // get the current transform + m_transform = component->getTransform(); + // connnect a signal on it to keep all change + component->signalPosition.connect(sharedFromThis(), &ege::render::Component::onSignalPositionChange); + } +} + +void ege::render::Component::onSignalPositionChange(const etk::Transform3D& _transform) { + m_transform = _transform; +} + +bool ege::render::Component::loadMesh(const std::string& _meshFileName) { + ememory::SharedPtr tmpMesh = ege::resource::Mesh::create(_meshFileName); + if(tmpMesh == nullptr) { + EGE_ERROR("can not load the resources : " << _meshFileName); + return false; + } + return setMesh(tmpMesh); +} + +bool ege::render::Component::setMesh(ememory::SharedPtr _mesh) { + if (m_mesh != nullptr) { + m_mesh.reset(); + } + m_mesh = _mesh; + // auto load the shape : + if (m_mesh == nullptr) { + return true; + } + return true; +} \ No newline at end of file diff --git a/ege/render/Component.hpp b/ege/render/Component.hpp new file mode 100644 index 0000000..39a0b36 --- /dev/null +++ b/ege/render/Component.hpp @@ -0,0 +1,66 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include + +#include +#include +#include + +namespace ege { + namespace render { + class Component : public ege::Component { + protected: + etk::Transform3D m_transform; // keep it from the physic or the position component... + public: + /** + * @brief basic constructor + */ + Component(); + /** + * @brief contruct with a mesh filename + * @param[in] _fileName filename of the Mesh. + */ + Component(const std::string& _fileName); + /** + * @brief contruct with a prebuild mesh + * @param[in] _mesh The mesh pointer. + */ + Component(ememory::SharedPtr _mesh); + protected: + ememory::SharedPtr m_mesh; //!< Mesh of the Element (can be nullptr) + public: + /** + * @brief Select a mesh with a specific name. + * @param[in] _fileName filename of the Mesh. + * @note Automaticly load the shape if it is specify in the mesh file + * @return true if no error occured + */ + virtual bool loadMesh(const std::string& _fileName); + /** + * @brief set the the Mesh properties. + * @param[in] _mesh The mesh pointer. (nullptr to force the mesh remove ...) + * @note : this remove the shape and the mesh properties. + * @return true if no error occured + */ + virtual bool setMesh(ememory::SharedPtr _mesh); + /** + * @brief get a pointer on the Mesh file. + * @return the mesh pointer. + */ + inline ememory::SharedPtr getMesh() { + return m_mesh; + }; + + public: + const std::string& getType() const override; + void addFriendComponent(const ememory::SharedPtr& _component) override; + private: + void onSignalPositionChange(const etk::Transform3D& _transform); + }; + } +} \ No newline at end of file diff --git a/ege/render/Engine.cpp b/ege/render/Engine.cpp new file mode 100644 index 0000000..e69de29 diff --git a/ege/render/Engine.hpp b/ege/render/Engine.hpp new file mode 100644 index 0000000..2120078 --- /dev/null +++ b/ege/render/Engine.hpp @@ -0,0 +1,28 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2017, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include +#include +#include +#include +#include +#include + + +namespace ege { + namespace render { + class Engine { + public: + Engine() {} + ~Engine() {} + + // update cycle + void update(float _delta) {} + }; + } +} + diff --git a/lutin_ege.py b/lutin_ege.py index b1b467a..ef16ce2 100644 --- a/lutin_ege.py +++ b/lutin_ege.py @@ -33,13 +33,20 @@ def configure(target, my_module): 'ege/camera/View.cpp', 'ege/camera/FPS.cpp', 'ege/CollisionShapeCreator.cpp', + 'ege/position/Component.cpp', + 'ege/physics/Component.cpp', 'ege/physics/Engine.cpp', + 'ege/Component.cpp', 'ege/elements/Element.cpp', 'ege/elements/ElementBase.cpp', 'ege/elements/ElementPhysic.cpp', - 'ege/Particule.cpp', - 'ege/ParticuleEngine.cpp', - 'ege/ParticuleSimple.cpp', + 'ege/particule/Component.cpp', + 'ege/particule/Engine.cpp', + 'ege/particule/Simple.cpp', + 'ege/ia/Component.cpp', + 'ege/ia/Engine.cpp', + 'ege/render/Component.cpp', + 'ege/render/Engine.cpp', 'ege/widget/Mesh.cpp', 'ege/widget/Scene.cpp', 'ege/Environement.cpp', @@ -78,13 +85,20 @@ def configure(target, my_module): 'ege/camera/View.hpp', 'ege/camera/FPS.hpp', 'ege/CollisionShapeCreator.hpp', + 'ege/position/Component.hpp', 'ege/physics/Engine.hpp', + 'ege/physics/Component.hpp', + 'ege/Component.hpp', 'ege/elements/Element.hpp', 'ege/elements/ElementBase.hpp', 'ege/elements/ElementPhysic.hpp', - 'ege/Particule.hpp', - 'ege/ParticuleEngine.hpp', - 'ege/ParticuleSimple.hpp', + 'ege/particule/Component.hpp', + 'ege/particule/Engine.hpp', + 'ege/particule/Simple.hpp', + 'ege/ia/Component.hpp', + 'ege/ia/Engine.hpp', + 'ege/render/Component.hpp', + 'ege/render/Engine.hpp', 'ege/widget/Mesh.hpp', 'ege/widget/Scene.hpp', 'ege/Environement.hpp', @@ -106,6 +120,9 @@ def configure(target, my_module): 'ege/physicsShape/PhysicsSphere.hpp', 'ege/Ray.hpp', ]) + # TODO: Remove this ... + my_module.add_flag('c++', "-Wno-unused-variable") + my_module.add_flag('c++', "-Wno-overloaded-virtual") my_module.add_path(".") return True diff --git a/sample/Collision/appl/Windows.cpp b/sample/Collision/appl/Windows.cpp index b075bfd..a5273e9 100644 --- a/sample/Collision/appl/Windows.cpp +++ b/sample/Collision/appl/Windows.cpp @@ -19,6 +19,7 @@ #include #include #include +#include appl::Windows::Windows() { addObjectType("appl::Windows"); @@ -101,6 +102,21 @@ void appl::Windows::init() { } myMesh = ege::resource::Mesh::createCube(3); if (myMesh != nullptr) { + ememory::SharedPtr element = ememory::makeShared(m_env); + // add all component: + // 1st Position component: + etk::Transform3D transform(vec3(0,0,2), etk::Quaternion::identity()); + ememory::SharedPtr componentPosition = ememory::makeShared(transform); + element->addComponent(componentPosition); + + // 2nd something to diplay: + ememory::SharedPtr componentRender = ememory::makeShared(myMesh); + element->addComponent(componentRender); + + // add it .. + m_env->addElement(element); + + /* //ememory::SharedPtr element = ememory::makeShared(m_env); ememory::SharedPtr element = ememory::makeShared(m_env); // add physic interface: @@ -114,6 +130,7 @@ void appl::Windows::init() { element->setMass(1000); m_env->addElement(element); + */ } myMesh = ege::resource::Mesh::createCube(3); if (myMesh != nullptr) {