diff --git a/ege/AudioElement.cpp b/ege/AudioElement.cpp deleted file mode 100644 index a9f1c7e..0000000 --- a/ege/AudioElement.cpp +++ /dev/null @@ -1,9 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -#include -#include - diff --git a/ege/AudioElement.hpp b/ege/AudioElement.hpp deleted file mode 100644 index 7d44baf..0000000 --- a/ege/AudioElement.hpp +++ /dev/null @@ -1,13 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ -#pragma once - -namespace ege { - -} - - - diff --git a/ege/AudioEngine.cpp b/ege/AudioEngine.cpp deleted file mode 100644 index 3b5b4d2..0000000 --- a/ege/AudioEngine.cpp +++ /dev/null @@ -1,9 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -#include -#include - diff --git a/ege/AudioEngine.hpp b/ege/AudioEngine.hpp deleted file mode 100644 index 3683409..0000000 --- a/ege/AudioEngine.hpp +++ /dev/null @@ -1,12 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ -#pragma once - -namespace ege { - -} - - diff --git a/ege/CollisionShapeCreator.cpp b/ege/CollisionShapeCreator.cpp index 861517f..bde9442 100644 --- a/ege/CollisionShapeCreator.cpp +++ b/ege/CollisionShapeCreator.cpp @@ -14,7 +14,7 @@ #include #include -// Documentetion of bullet library : +// Documentetion of bullet library: // http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Shapes /* btCollisionShape* ege::collision::createShape(const ememory::SharedPtr& _mesh) { diff --git a/ege/Engine.cpp b/ege/Engine.cpp new file mode 100644 index 0000000..3d70c4a --- /dev/null +++ b/ege/Engine.cpp @@ -0,0 +1,33 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include +#include + +ege::Engine::Engine(ege::Environement* _env) : + m_env(_env) { + +} + +const std::string& ege::Engine::getType() const { + static std::string tmp("engine"); + return tmp; +} + +void ege::Engine::componentRemove(const ememory::SharedPtr& _ref) { + +} + +void ege::Engine::componentAdd(const ememory::SharedPtr& _ref) { + +} + +void ege::Engine::update(const echrono::Duration& _delta) { + +} + +void ege::Engine::render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) { + +} \ No newline at end of file diff --git a/ege/Engine.hpp b/ege/Engine.hpp new file mode 100644 index 0000000..6933275 --- /dev/null +++ b/ege/Engine.hpp @@ -0,0 +1,53 @@ +/** @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 { + class Environement; + class Camera; + class Engine : public ememory::EnableSharedFromThis { + protected: + ege::Environement* m_env; + public: + Engine(ege::Environement* _env); + virtual ~Engine() = default; + public: + /** + * @brief get the type of the engine + * @return the type in string + */ + virtual const std::string& getType() const; + /** + * @brief An ege::Element component has been removed ==> need remove it in local if needed + * @param[in] _ref Referrence on the component + */ + virtual void componentRemove(const ememory::SharedPtr& _ref); + /** + * @brief An ege::Element component has been added ==> need add it in local if needed + * @param[in] _ref Referrence on the component + */ + virtual void componentAdd(const ememory::SharedPtr& _ref); + /** + * @brief Global game engine main cycle of update internal parameters + * @param[in] _delta time from the last update + */ + virtual void update(const echrono::Duration& _delta); + /** + * @brief Globalgame engine main cycle of draw + * @param[in] _delta time from the last render + * @param[in] _camera Camera property to render the engine properties ... + */ + virtual void render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera); + }; +} + diff --git a/ege/Environement.cpp b/ege/Environement.cpp index a7d8eff..30a7bb6 100644 --- a/ege/Environement.cpp +++ b/ege/Environement.cpp @@ -9,9 +9,100 @@ #include #include +#include +#include +#include +#include + #include #include + +void ege::Environement::addEngine(const ememory::SharedPtr& _ref) { + if (_ref == nullptr) { + EGE_ERROR("try to add an empty Engine"); + return; + } + // check if not exist + for (auto &it: m_engine) { + if (it == nullptr) { + continue; + } + if (it->getType() == _ref->getType()) { + it = _ref; + return; + } + } + // try to add in an empty slot + for (auto &it: m_engine) { + if (it != nullptr) { + continue; + } + it = _ref; + return; + } + // add it at the end ... + m_engine.push_back(_ref); +} + +void ege::Environement::rmEngine(const ememory::SharedPtr& _ref) { + if (_ref == nullptr) { + EGE_ERROR("try to remove an empty engine"); + return; + } + // check if not exist + for (auto &it: m_engine) { + if (it == nullptr) { + continue; + } + if (it == _ref) { + it = nullptr; + return; + } + } + EGE_ERROR("try to remove an unexisting engine"); +} + +void ege::Environement::rmEngine(const std::string& _type) { + // check if not exist + for (auto &it: m_engine) { + if (it == nullptr) { + continue; + } + if (it->getType() == _type) { + it = nullptr; + return; + } + } + EGE_ERROR("try to remove an unexisting engine type : '" << _type << "'"); + return; +} + + +void ege::Environement::engineComponentRemove(const ememory::SharedPtr& _ref) { + for (auto &it: m_engine) { + if (it == nullptr) { + continue; + } + if (it->getType() == _ref->getType()) { + it->componentRemove(_ref); + return; + } + } +} +void ege::Environement::engineComponentAdd(const ememory::SharedPtr& _ref) { + for (auto &it: m_engine) { + if (it == nullptr) { + continue; + } + if (it->getType() == _ref->getType()) { + it->componentAdd(_ref); + return; + } + } +} + + ememory::SharedPtr ege::Environement::getElementNearest(ememory::SharedPtr _sourceRequest, float& _distance) { if (_sourceRequest == nullptr) { return nullptr; @@ -32,7 +123,7 @@ ememory::SharedPtr ege::Environement::getElementNearest(ememory::S } // check distance ... vec3 destPosition = m_listElement[iii]->getPosition(); - float distance = btDistance(sourcePosition, destPosition); + float distance = (sourcePosition - destPosition).length(); //EGE_DEBUG("Distance : " << _distance << " >? " << distance << " id=" << iii); if (_distance>distance) { _distance = distance; @@ -61,7 +152,7 @@ void ege::Environement::getElementNearest(const vec3& _sourcePosition, if (_sourcePosition == destPosition) { continue; } - result.dist = btDistance(_sourcePosition, destPosition); + result.dist = (_sourcePosition - destPosition).length(); //EGE_DEBUG("Distance : " << _distance << " >? " << distance << " id=" << iii); if (_distanceMax>result.dist) { _resultList.push_back(result); @@ -87,7 +178,7 @@ void ege::Environement::getElementNearestFixed(const vec3& _sourcePosition, } // check distance ... vec3 destPosition = result.element->getPositionTheoric(); - result.dist = btDistance(_sourcePosition, destPosition); + result.dist = (_sourcePosition - destPosition).length(); //EGE_DEBUG("Distance : " << _distance << " >? " << distance << " id=" << iii); if (_distanceMax <= result.dist) { continue; @@ -285,7 +376,7 @@ void ege::Environement::rmElement(ememory::SharedPtr _removeElemen } } - +// TODO : DEPRECATED ==> special function of the renderer ... void ege::Environement::getOrderedElementForDisplay(std::vector& _resultList, const vec3& _position, const vec3& _direction) { @@ -316,7 +407,7 @@ void ege::Environement::getOrderedElementForDisplay(std::vector500.0f) { // The element is realy too far ... == > no need to display @@ -348,7 +439,7 @@ void ege::Environement::generateInteraction(ege::ElementInteraction& _event) { _event.applyEvent(*m_listElement[iii]); /* vec3 destPosition = m_listElement[iii]->getPosition(); - float dist = btDistance(sourcePosition, destPosition); + float dist = (sourcePosition - destPosition).length; if (dist == 0 || dist>decreasePower) { continue; } @@ -367,12 +458,16 @@ ege::Environement::Environement() : propertyRatio(this, "ratio", 1.0f, "game speed ratio"), - m_listElement(), - m_particuleEngine(this) { + m_listElement() { // nothing to do ... propertyStatus.add(gameStart, "start", "Scene is started"); propertyStatus.add(gamePause, "pause", "Scene is paused"); propertyStatus.add(gameStop, "stop", "Scene is stopped"); + // we add the 4 classical engines (the order is used to the global rendering cycle ... + addEngine(ememory::makeShared(this)); + addEngine(ememory::makeShared(this)); + addEngine(ememory::makeShared(this)); + addEngine(ememory::makeShared(this)); } void ege::Environement::clear() { @@ -380,6 +475,22 @@ void ege::Environement::clear() { } +void ege::Environement::render(const echrono::Duration& _delta, const std::string& _camera) { + // get the correct camera: + ememory::SharedPtr camera = getCamera(_camera); + if (camera == nullptr) { + EGE_ERROR("Render: Can not get camera named: '" << _camera << "'"); + return; + } + for (auto &it: m_engine) { + if(it == nullptr) { + continue; + } + EGE_INFO(" render: " << it->getType()); + it->render(_delta, camera); + } +} + void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) { float curentDelta = _event.getDeltaCall(); EGE_INFO("periodic call : " << _event); @@ -406,15 +517,24 @@ void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) it.second->periodicCall(curentDelta); } } + EGE_INFO(" step simulation : " << curentDelta); + for (auto &it: m_engine) { + if(it == nullptr) { + continue; + } + EGE_INFO(" update: " << it->getType()); + it->update(echrono::Duration(double(curentDelta))); + } + //EGE_DEBUG("stepSimulation (start)"); ///step the simulation - EGE_INFO(" step simulation : " << curentDelta); - m_physicEngine.update(curentDelta); - //optional but useful: debug drawing - m_physicEngine.debugDrawWorld(); - EGE_INFO(" Update particule engine"); - m_particuleEngine.update(curentDelta); + // TODO : m_physicEngine.update(curentDelta); + // TODO : //optional but useful: debug drawing + // TODO : m_physicEngine.debugDrawWorld(); + // TODO : EGE_INFO(" Update particule engine"); + // TODO : m_particuleEngine.update(curentDelta); // remove all element that requested it ... + /** { int32_t numberEnnemyKilled=0; int32_t victoryPoint=0; @@ -440,6 +560,7 @@ void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) //signalKillEnemy.emit(numberEnnemyKilled); } } + */ } diff --git a/ege/Environement.hpp b/ege/Environement.hpp index c387a4a..f424339 100644 --- a/ege/Environement.hpp +++ b/ege/Environement.hpp @@ -10,9 +10,10 @@ namespace ege { class ElementInteraction; }; #include -#include -#include -#include + +#include + + #include #include #include @@ -23,7 +24,6 @@ namespace ege { #include #include #include -#include namespace ege { class Element; @@ -73,7 +73,7 @@ namespace ege { public: virtual void applyEvent(ege::Element& _element) { }; }; - + // TODO : An element must be created by a local factory... class Environement : public ewol::Object { public: // Signals @@ -81,30 +81,14 @@ namespace ege { // properties: eproperty::List propertyStatus; //!< the display is running (not in pause) eproperty::Value propertyRatio; //!< Speed ratio - private: - ege::physics::Engine m_physicEngine; //!< EGE physic engine interface. + protected: + std::vector> m_engine; //!< EGE sub engine interface (like physique, rendering, audio, ...). public: - ege::physics::Engine& getPhysicEngine() { - return m_physicEngine; - } - private: - ege::render::Engine m_renderEngine; //!< EGE rendering engine interface. - public: - ege::render::Engine& getRenderEngine() { - return m_renderEngine; - } - private: - ege::particule::Engine m_particuleEngine; //!< EGE particule engine interface. - public: - ege::particule::Engine& getParticuleEngine() { - return m_particuleEngine; - } - private: - ege::ia::Engine m_iaEngine; //!< EGE Artificial inteligence engine interface. - public: - ege::ia::Engine& getIAEngine() { - return m_iaEngine; - } + void addEngine(const ememory::SharedPtr& _ref); + void rmEngine(const ememory::SharedPtr& _ref); + void rmEngine(const std::string& _type); + void engineComponentRemove(const ememory::SharedPtr& _ref); + void engineComponentAdd(const ememory::SharedPtr& _ref); private: std::vector> m_listElement; //!< List of all element added in the Game protected: @@ -112,7 +96,8 @@ namespace ege { public: DECLARE_FACTORY(Environement); virtual ~Environement() { }; - protected: + public: + void render(const echrono::Duration& _delta, const std::string& _camera); protected: std::map> m_listCamera; //!< list of all camera in the world public: diff --git a/ege/Game.cpp b/ege/Game.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/ege/Game.hpp b/ege/Game.hpp deleted file mode 100644 index ad6ffc0..0000000 --- a/ege/Game.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class btBroadphaseInterface; -class btCollisionShape; -class btOverlappingPairCache; -class btCollisionDispatcher; -class btConstraintSolver; -struct btCollisionAlgorithmCreateFunc; -class btDefaultCollisionConfiguration; -class btDynamicsWorld; -#include -class btVector3; -#include - -namespace ege { - enum gameStatus { - gameStart, - gamePause, - gameStop - }; - class Game : public ewol::Object { - protected: - Game(); - void init(); - public: - ~Game() - protected: - ege::PhysicEngine m_physicEngine; //!< physic engine interface - ege::AudioEngine m_AudioEngine; //!< physic engine interface - ege::IAEngine m_iAEngine; //!< physic engine interface - } -} diff --git a/ege/Ray.cpp b/ege/Ray.cpp index 289d638..b28b5af 100644 --- a/ege/Ray.cpp +++ b/ege/Ray.cpp @@ -7,6 +7,7 @@ #include #include #include +#include ege::Ray::Ray(const vec3& _origin, const vec3& _direction) : diff --git a/ege/camera/Camera.cpp b/ege/camera/Camera.cpp index 774cfae..c5d40a4 100644 --- a/ege/camera/Camera.cpp +++ b/ege/camera/Camera.cpp @@ -7,6 +7,7 @@ #include #include +#include #include diff --git a/ege/camera/Camera.hpp b/ege/camera/Camera.hpp index c68ee83..bae2a80 100644 --- a/ege/camera/Camera.hpp +++ b/ege/camera/Camera.hpp @@ -10,11 +10,12 @@ #include #include #include -#include +//#include #include namespace ege { + class Ray; class Camera : public ememory::EnableSharedFromThis{ public: /** diff --git a/ege/camera/View.cpp b/ege/camera/View.cpp index df379f3..c8a3161 100644 --- a/ege/camera/View.cpp +++ b/ege/camera/View.cpp @@ -8,6 +8,7 @@ #include #include #include +#include void ege::camera::View::update() { //m_matrix = etk::matLookAt(m_eye, m_target, m_up); diff --git a/ege/elements/Element.cpp b/ege/elements/Element.cpp index 9800a7a..9f2baab 100644 --- a/ege/elements/Element.cpp +++ b/ege/elements/Element.cpp @@ -19,11 +19,6 @@ 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), @@ -77,18 +72,6 @@ void ege::Element::addComponent(const ememory::SharedPtr& _ref) findId = m_component.size(); m_component.push_back(_ref); } - if (_ref->getType() == "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; iii& _ref) { EGE_ERROR("try to remove an unexisting component"); return; } - if (_ref->getType() == "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; iii> 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); diff --git a/ege/elements/ElementPhysic.hpp b/ege/elements/ElementPhysic.hpp index 74c08fd..4a381a2 100644 --- a/ege/elements/ElementPhysic.hpp +++ b/ege/elements/ElementPhysic.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #define INDEX_RIGHT_AXIS (0) diff --git a/ege/ia/Engine.cpp b/ege/ia/Engine.cpp index e69de29..64de8f5 100644 --- a/ege/ia/Engine.cpp +++ b/ege/ia/Engine.cpp @@ -0,0 +1,24 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include + +ege::ia::Engine::Engine(ege::Environement* _env) : + ege::Engine(_env) { + +} + +const std::string& ege::ia::Engine::getType() const { + static std::string tmp("ia"); + return tmp; +} + +void ege::ia::Engine::componentRemove(const ememory::SharedPtr& _ref) { + +} + +void ege::ia::Engine::componentAdd(const ememory::SharedPtr& _ref) { + +} diff --git a/ege/ia/Engine.hpp b/ege/ia/Engine.hpp index 6bf568a..cd3acb7 100644 --- a/ege/ia/Engine.hpp +++ b/ege/ia/Engine.hpp @@ -4,7 +4,7 @@ * @license MPL v2.0 (see license file) */ #pragma once - +#include #include #include #include @@ -14,13 +14,17 @@ namespace ege { namespace ia { - class Engine { + class Engine : public ege::Engine { public: - Engine() {} + Engine(ege::Environement* _env); ~Engine() {} // update cycle void update(float _delta) {} + public: + const std::string& getType() const override; + void componentRemove(const ememory::SharedPtr& _ref) override; + void componentAdd(const ememory::SharedPtr& _ref) override; }; } } diff --git a/ege/particule/Engine.cpp b/ege/particule/Engine.cpp index a63cf80..2d440a8 100644 --- a/ege/particule/Engine.cpp +++ b/ege/particule/Engine.cpp @@ -10,7 +10,7 @@ #include ege::particule::Engine::Engine(ege::Environement* _env) : - m_env(_env) { + ege::Engine(_env) { } @@ -18,6 +18,21 @@ ege::particule::Engine::~Engine() { clear(); } +const std::string& ege::particule::Engine::getType() const { + static std::string tmp("particule"); + return tmp; +} + +void ege::particule::Engine::componentRemove(const ememory::SharedPtr& _ref) { + +} + +void ege::particule::Engine::componentAdd(const ememory::SharedPtr& _ref) { + +} + + + void ege::particule::Engine::add(const ememory::SharedPtr& _particule) { if (_particule == nullptr) { EGE_ERROR("Try to add particule nullptr"); @@ -68,16 +83,17 @@ ememory::SharedPtr ege::particule::Engine::respown(co return nullptr; } -void ege::particule::Engine::update(float _deltaTime) { - if (_deltaTime>(1.0f/60.0f)) { - _deltaTime = (1.0f/60.0f); +void ege::particule::Engine::update(const echrono::Duration& _delta) { + float deltaTime = _delta.toSeconds(); + if (deltaTime>(1.0f/60.0f)) { + deltaTime = (1.0f/60.0f); } - EGE_WARNING("Update the Particule engine ... " << _deltaTime); + EGE_WARNING("Update the Particule engine ... " << deltaTime); for (size_t iii=0; iiiupdate(_deltaTime); + m_particuleList[iii]->update(deltaTime); } // check removing elements for (size_t iii=0; iii& _camera) { for (size_t iii=0; iiidraw(_camera); + m_particuleList[iii]->draw(*_camera); } } diff --git a/ege/particule/Engine.hpp b/ege/particule/Engine.hpp index 83eff7e..b0b2ff6 100644 --- a/ege/particule/Engine.hpp +++ b/ege/particule/Engine.hpp @@ -4,19 +4,16 @@ * @license MPL v2.0 (see license file) */ #pragma once - +#include #include #include -#include #include namespace ege { class Environement; namespace particule { class Component; - class Engine { - private: - ege::Environement* m_env; + class Engine : public ege::Engine { public: Engine(ege::Environement* _env); // note : need the engine to register has an dynamic element ... (the first ...) ~Engine(); @@ -40,16 +37,6 @@ namespace ege { */ 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. @@ -59,6 +46,12 @@ namespace ege { */ ememory::SharedPtr respown(const char* _particuleType); + public: + const std::string& getType() const override; + void componentRemove(const ememory::SharedPtr& _ref) override; + void componentAdd(const ememory::SharedPtr& _ref) override; + void update(const echrono::Duration& _delta) override; + void render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) override; }; } } diff --git a/ege/physics/Engine.cpp b/ege/physics/Engine.cpp index 78c75b2..368a343 100644 --- a/ege/physics/Engine.cpp +++ b/ege/physics/Engine.cpp @@ -4,6 +4,7 @@ * @license MPL v2.0 (see license file) */ +#include #include #include @@ -13,6 +14,19 @@ #include +const std::string& ege::physics::Engine::getType() const { + static std::string tmp("physics"); + return tmp; +} + +void ege::physics::Engine::componentRemove(const ememory::SharedPtr& _ref) { + +} + +void ege::physics::Engine::componentAdd(const ememory::SharedPtr& _ref) { + +} + // unique callback function : /* @@ -38,7 +52,8 @@ static bool handleContactsProcess(btManifoldPoint& _point, btCollisionObject* _b } */ -ege::physics::Engine::Engine(): +ege::physics::Engine::Engine(ege::Environement* _env) : + ege::Engine(_env), m_dynamicsWorld(nullptr), m_accumulator(0.0f) { // Start engine with no gravity @@ -69,9 +84,10 @@ void ege::physics::Engine::setGravity(const vec3& _axePower) { // Constant physics time step const float timeStep = 1.0 / 60.0; -void ege::physics::Engine::update(float _delta) { +void ege::physics::Engine::update(const echrono::Duration& _delta) { + float deltaTime = _delta.toSeconds(); // Add the time difference in the accumulator - m_accumulator += _delta; + m_accumulator += deltaTime; // While there is enough accumulated time to take one or several physics steps while (m_accumulator >= timeStep) { if (m_dynamicsWorld != nullptr) { diff --git a/ege/physics/Engine.hpp b/ege/physics/Engine.hpp index 2f41fe9..7ed98a0 100644 --- a/ege/physics/Engine.hpp +++ b/ege/physics/Engine.hpp @@ -5,6 +5,8 @@ */ #pragma once +#include + namespace ege { namespace physics { class Engine; @@ -25,12 +27,12 @@ namespace ege { namespace ege { namespace physics { - class Engine { + class Engine : public ege::Engine { private: rp3d::DynamicsWorld* m_dynamicsWorld; float m_accumulator; // limit call of the step rendering public: - Engine(); + Engine(ege::Environement* _env); ~Engine(); public: // Define a collision point ==> for debug only ... @@ -63,12 +65,16 @@ namespace ege { * @param[in] _axePower energy of this gravity */ void setGravity(const vec3& _axePower); - // update cycle - void update(float _delta); void debugDrawWorld() { // TODO: later ... } + public: + const std::string& getType() const override; + void componentRemove(const ememory::SharedPtr& _ref) override; + void componentAdd(const ememory::SharedPtr& _ref) override; + void update(const echrono::Duration& _delta) override; + //void render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) override; }; } } diff --git a/ege/physicsShape/PhysicsBox.cpp b/ege/physicsShape/PhysicsBox.cpp index a8ad4b9..8cfa579 100644 --- a/ege/physicsShape/PhysicsBox.cpp +++ b/ege/physicsShape/PhysicsBox.cpp @@ -4,6 +4,7 @@ * @license MPL v2.0 (see license file) */ #include +#include #include diff --git a/ege/render/Component.hpp b/ege/render/Component.hpp index 39a0b36..b3bf31d 100644 --- a/ege/render/Component.hpp +++ b/ege/render/Component.hpp @@ -56,6 +56,9 @@ namespace ege { return m_mesh; }; + const etk::Transform3D& getTransform() { + return m_transform; + } public: const std::string& getType() const override; void addFriendComponent(const ememory::SharedPtr& _component) override; diff --git a/ege/render/Engine.cpp b/ege/render/Engine.cpp index e69de29..4ae7d43 100644 --- a/ege/render/Engine.cpp +++ b/ege/render/Engine.cpp @@ -0,0 +1,158 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include + +ege::render::Engine::Engine(ege::Environement* _env) : + ege::Engine(_env) { + +} + +const std::string& ege::render::Engine::getType() const { + static std::string tmp("render"); + return tmp; +} + +void ege::render::Engine::componentRemove(const ememory::SharedPtr& _ref) { + ememory::SharedPtr ref = ememory::dynamicPointerCast(_ref); + for (auto it=m_component.begin(); + it != m_component.end(); + ++it) { + if (*it == ref) { + it->reset(); + return; + } + } +} + +void ege::render::Engine::componentAdd(const ememory::SharedPtr& _ref) { + ememory::SharedPtr ref = ememory::dynamicPointerCast(_ref); + for (auto it=m_component.begin(); + it != m_component.end(); + ++it) { + if (*it == nullptr) { + *it = ref; + return; + } + } + m_component.push_back(ref); +} + + +void ege::render::Engine::getOrderedElementForDisplay(std::vector& _resultList, + const vec3& _position, + const vec3& _direction) { + // TODO : Set it back ... corrected... + // remove all unneeded elements (old display...) + _resultList.clear(); + // basic element result + ege::render::Engine::ResultNearestElement result; + result.dist = 99999999999.0f; + result.element = nullptr; + // for all element in the game we chek if it is needed to display it ... + for (auto &it: m_component) { + // check nullptr pointer + if (it == nullptr) { + // no pointer null are set in the output list ... + continue; + } + result.element = it; + // check distance ... + vec3 destPosition = result.element->getTransform().getPosition(); + vec3 angleView = (destPosition - _position); + angleView.safeNormalize(); + float dotResult = angleView.dot(_direction); + //EGE_DEBUG("Dot position : " << destPosition << " == > dot=" << dotResult); + /* + if (dotResult <= 0.85f) { + // they are not in the camera angle view ... == > no need to process display + continue; + } + */ + result.dist = (_position - destPosition).length(); + /* + if (result.dist>500.0f) { + // The element is realy too far ... == > no need to display + continue; + } + */ + // try to add the element at the best positions: + size_t jjj; + for (jjj=0; jjj<_resultList.size(); jjj++) { + if (_resultList[jjj].dist>result.dist) { + _resultList.insert(_resultList.begin()+jjj, result); + break; + } + } + // add element at the end : + if (jjj >= _resultList.size()) { + _resultList.push_back(result); + } + } +} + + +void ege::render::Engine::render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) { + for (auto &it : m_component) { + if (it == nullptr) { + continue; + } + + } + + //EGE_DEBUG("Draw (start)"); + mat4 tmpMatrix; + getOrderedElementForDisplay(m_displayElementOrdered, _camera->getEye(), _camera->getViewVector()); + EGE_VERBOSE("DRAW : " << m_displayElementOrdered.size() << "/" << m_component.size() << " elements"); + + // TODO : remove this == > no more needed ==> checked in the generate the list of the element ordered + for (auto &it: m_displayElementOrdered) { + it.element->preCalculationDraw(*_camera); + } + // note : the first pass is done at the reverse way to prevent multiple display od the same point in the screen + // (and we remember that the first pass is to display all the non transparent elements) + for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) { + m_displayElementOrdered[iii].element->draw(0); + } + // for the other pass the user can draw transparent elements ... + for (int32_t pass=1; pass <= NUMBER_OF_SUB_PASS+1; pass++) { + for (auto &it: m_displayElementOrdered) { + it.element->draw(pass); + } + } + #if 0 + if (propertyDebugPhysic.get() == true) { + // Draw debug ... (Object) + for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) { + m_displayElementOrdered[iii].element->drawDebug(m_debugDrawProperty, camera); + } + // Draw debug ... (Camera) + /* + std::map> listCamera = m_env->getCameraList(); + for (auto &itCam : listCamera) { + if (itCam.second != nullptr) { + itCam.second->drawDebug(m_debugDrawProperty, camera); + } + } + */ + } + if (propertyDebugNormal.get() == true) { + // Draw debug ... (Object) + for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) { + m_displayElementOrdered[iii].element->drawNormalDebug(m_debugDrawProperty, camera); + } + } + + if (propertyDebugApplication.get() == true) { + // Draw debug ... (User) + signalDisplayDebug.emit(m_debugDrawProperty); + } + /* TODO: set it back ... + if (camera != nullptr) { + m_env->getParticuleEngine().draw(*camera); + } + */ + #endif +} \ No newline at end of file diff --git a/ege/render/Engine.hpp b/ege/render/Engine.hpp index 2120078..4755bc2 100644 --- a/ege/render/Engine.hpp +++ b/ege/render/Engine.hpp @@ -11,17 +11,31 @@ #include #include #include +#include namespace ege { namespace render { - class Engine { + class Engine : public ege::Engine { public: - Engine() {} + Engine(ege::Environement* _env); ~Engine() {} - - // update cycle - void update(float _delta) {} + protected: + std::vector> m_component; + class ResultNearestElement { + public: + ememory::SharedPtr element; + float dist; + }; + std::vector m_displayElementOrdered; + public: + const std::string& getType() const override; + void componentRemove(const ememory::SharedPtr& _ref) override; + void componentAdd(const ememory::SharedPtr& _ref) override; + void render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) override; + void getOrderedElementForDisplay(std::vector& _resultList, + const vec3& _position, + const vec3& _direction); }; } } diff --git a/ege/resource/Mesh.cpp b/ege/resource/Mesh.cpp index c4c622d..2f2b1fd 100644 --- a/ege/resource/Mesh.cpp +++ b/ege/resource/Mesh.cpp @@ -186,7 +186,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, switch(m_normalMode) { case normalModeFace: for(size_t iii=0; iii= 0.0f) { + if((mattttt * m_listFacesNormal[tmppFaces[iii].m_normal[0]]).dot(cameraNormal) >= 0.0f) { tmpIndexResult.push_back(iii*3); tmpIndexResult.push_back(iii*3+1); tmpIndexResult.push_back(iii*3+2); @@ -195,9 +195,9 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, break; case normalModeVertex: for(size_t iii=0; iii= -0.2f) - || (btDot(mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[1]], cameraNormal) >= -0.2f) - || (btDot(mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[2]], cameraNormal) >= -0.2f) ) { + if( ((mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[0]]).dot(cameraNormal) >= -0.2f) + || ((mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[1]]).dot(cameraNormal) >= -0.2f) + || ((mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[2]]).dot(cameraNormal) >= -0.2f) ) { tmpIndexResult.push_back(iii*3); tmpIndexResult.push_back(iii*3+1); tmpIndexResult.push_back(iii*3+2); @@ -285,7 +285,7 @@ void ege::resource::Mesh::drawNormal(mat4& _positionMatrix, vec3 position = m_listVertex[tmpFaceList.m_faces[iii].m_vertex[indice]]; vec3 normal = m_listVertexNormal[tmpFaceList.m_faces[iii].m_normal[indice]]; vertices.push_back(position); - vertices.push_back(position+normal/4); + vertices.push_back(position+normal*0.25f); } } break; case normalModeFace: @@ -298,7 +298,7 @@ void ege::resource::Mesh::drawNormal(mat4& _positionMatrix, center /= float(nbIndicInFace); vec3 normal = m_listFacesNormal[tmpFaceList.m_faces[iii].m_normal[0]]; vertices.push_back(center); - vertices.push_back(center+normal/4); + vertices.push_back(center+normal*0.25f); } break; case normalModeNone: break; @@ -325,8 +325,7 @@ void ege::resource::Mesh::calculateNormaleFace(const std::string& _materialName) } for(auto &it : m_listFaces[_materialName].m_faces) { // for all case, We use only the 3 vertex for quad element, in theory 3D modeler export element in triangle if it is not a real plane. - vec3 normal = btCross(m_listVertex[it.m_vertex[0]]-m_listVertex[it.m_vertex[1]], - m_listVertex[it.m_vertex[1]]-m_listVertex[it.m_vertex[2]]); + vec3 normal = (m_listVertex[it.m_vertex[0]]-m_listVertex[it.m_vertex[1]]).cross(m_listVertex[it.m_vertex[1]]-m_listVertex[it.m_vertex[2]]); if (normal == vec3(0,0,0)) { EGE_ERROR("Null vertor for a face ... " << m_listVertex[it.m_vertex[0]] << " " << m_listVertex[it.m_vertex[1]] << " " << m_listVertex[it.m_vertex[2]]); m_listFacesNormal.push_back(vec3(1,0,0)); diff --git a/ege/resource/ParticuleMesh.cpp b/ege/resource/ParticuleMesh.cpp index 647cc18..03f00ad 100644 --- a/ege/resource/ParticuleMesh.cpp +++ b/ege/resource/ParticuleMesh.cpp @@ -90,7 +90,7 @@ void ege::resource::ParticuleMesh::draw(mat4& _positionMatrix, //std::vector& tmppIndex = m_listFaces.getValue(kkk).m_index; if (normalModeFace == m_normalMode) { for(size_t iii=0; iii= 0.0f) { + if((mattttt * m_listFacesNormal[tmppFaces[iii].m_normal[0]]).dot(cameraNormal) >= 0.0f) { tmpIndexResult.push_back(iii*3); tmpIndexResult.push_back(iii*3+1); tmpIndexResult.push_back(iii*3+2); @@ -98,9 +98,9 @@ void ege::resource::ParticuleMesh::draw(mat4& _positionMatrix, } } else { for(size_t iii=0; iii= -0.2f) - || (btDot(mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[1]], cameraNormal) >= -0.2f) - || (btDot(mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[2]], cameraNormal) >= -0.2f) ) { + if( ((mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[0]]).dot(cameraNormal) >= -0.2f) + || ((mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[1]]).dot(cameraNormal) >= -0.2f) + || ((mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[2]]).dot(cameraNormal) >= -0.2f) ) { tmpIndexResult.push_back(iii*3); tmpIndexResult.push_back(iii*3+1); tmpIndexResult.push_back(iii*3+2); diff --git a/ege/widget/Scene.cpp b/ege/widget/Scene.cpp index 89399c7..569b7b2 100644 --- a/ege/widget/Scene.cpp +++ b/ege/widget/Scene.cpp @@ -71,7 +71,8 @@ void ege::widget::Scene::onDraw() { g_counterNbTimeDisplay++; g_startTime = echrono::Steady::now(); #endif - + m_env->render(echrono::Duration(1.0/60.0), m_cameraName); + #if 0 // draw constant object: { mat4 tmpMatrix; @@ -82,7 +83,7 @@ void ege::widget::Scene::onDraw() { } } - // get camera : + // get camera: ememory::SharedPtr camera = m_env->getCamera(m_cameraName); if (camera == nullptr) { EGE_ERROR(" can not get camera named: '" << m_cameraName << "'"); @@ -134,9 +135,12 @@ void ege::widget::Scene::onDraw() { // Draw debug ... (User) signalDisplayDebug.emit(m_debugDrawProperty); } + /* TODO: set it back ... if (camera != nullptr) { m_env->getParticuleEngine().draw(*camera); } + */ + #endif #ifdef SCENE_DISPLAY_SPEED echrono::Duration localTime = echrono::Steady::now() - g_startTime; if (localTime>1) { diff --git a/lutin_ege.py b/lutin_ege.py index ef16ce2..67fe9fc 100644 --- a/lutin_ege.py +++ b/lutin_ege.py @@ -27,8 +27,9 @@ def get_version(): def configure(target, my_module): my_module.add_src_file([ 'ege/debug.cpp', - 'ege/AudioElement.cpp', - 'ege/AudioEngine.cpp', + 'ege/Engine.cpp', + 'ege/Component.cpp', + 'ege/Environement.cpp', 'ege/camera/Camera.cpp', 'ege/camera/View.cpp', 'ege/camera/FPS.cpp', @@ -36,7 +37,6 @@ def configure(target, my_module): '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', @@ -49,7 +49,6 @@ def configure(target, my_module): 'ege/render/Engine.cpp', 'ege/widget/Mesh.cpp', 'ege/widget/Scene.cpp', - 'ege/Environement.cpp', 'ege/resource/Mesh.cpp', 'ege/resource/MeshEmf.cpp', 'ege/resource/MeshGird.cpp', @@ -79,8 +78,9 @@ def configure(target, my_module): '-Wall']) my_module.add_header_file([ 'ege/debug.hpp', - 'ege/AudioElement.hpp', - 'ege/AudioEngine.hpp', + 'ege/Engine.hpp', + 'ege/Component.hpp', + 'ege/Environement.hpp', 'ege/camera/Camera.hpp', 'ege/camera/View.hpp', 'ege/camera/FPS.hpp', @@ -88,7 +88,6 @@ def configure(target, my_module): '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', @@ -101,7 +100,6 @@ def configure(target, my_module): 'ege/render/Engine.hpp', 'ege/widget/Mesh.hpp', 'ege/widget/Scene.hpp', - 'ege/Environement.hpp', 'ege/resource/Mesh.hpp', 'ege/resource/ParticuleMesh.hpp', 'ege/resource/tools/icoSphere.hpp', diff --git a/sample/Collision/appl/Windows.cpp b/sample/Collision/appl/Windows.cpp index a5273e9..9baaaa3 100644 --- a/sample/Collision/appl/Windows.cpp +++ b/sample/Collision/appl/Windows.cpp @@ -20,6 +20,7 @@ #include #include #include +#include appl::Windows::Windows() { addObjectType("appl::Windows"); @@ -242,6 +243,7 @@ bool appl::Windows::onEventInput(const ewol::event::Input& _event) { } void appl::Windows::onCallbackPeriodicCheckCollision(const ewol::event::Time& _event) { + /* std::vector list = m_env->getPhysicEngine().getListOfCollision(); if (list.size() != 0) { @@ -250,6 +252,7 @@ void appl::Windows::onCallbackPeriodicCheckCollision(const ewol::event::Time& _e for (size_t iii=0;iiigetUID() << "]:point1=" << list[iii].positionElem1 << " [" << list[iii].elem1->getUID() << "]:point2=" << list[iii].positionElem2 << " normal=" << list[iii].normalElem2); } + */ }