From 95e13b812617deadef390cd5bd1e52abbdf39135 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 31 Oct 2014 22:22:57 +0100 Subject: [PATCH] [DEV] transfert on Environement and some shared_ptr added --- ege/CollisionShapeCreator.cpp | 2 +- ege/ElementGame.cpp | 26 ++- ege/ElementGame.h | 13 +- ege/Environement.cpp | 148 ++++++++++++---- ege/Environement.h | 92 ++++++++-- ege/Game.h | 35 ---- ege/physics/Engine.cpp | 66 ++++++++ ege/physics/Engine.h | 58 +++++++ ege/physicsShape/PhysicsShape.cpp | 16 +- ege/physicsShape/PhysicsShape.h | 3 +- ege/resource/Mesh.cpp | 20 +-- ege/resource/Mesh.h | 12 +- ege/resource/tools/icoSphere.cpp | 2 +- ege/resource/tools/icoSphere.h | 2 +- ege/resource/tools/isoSphere.cpp | 2 +- ege/resource/tools/isoSphere.h | 2 +- ege/resource/tools/viewBox.cpp | 2 +- ege/resource/tools/viewBox.h | 2 +- ege/widget/Scene.cpp | 187 +++++---------------- ege/widget/Scene.h | 74 ++------ sample/Accelerometer/README.md | 0 sample/CameraPosition/README.md | 0 sample/Collision/README.md | 0 sample/DoubleView/README.md | 0 sample/GameFPS/README.md | 0 sample/GamePad/README.md | 0 sample/GameRacer/README.md | 0 sample/GameSpaceSimulation/README.md | 0 sample/Light/README.md | 0 sample/Material/README.md | 0 sample/MeshCreator/README.md | 0 sample/MeshCreator/appl/Windows.cpp | 38 +++++ sample/MeshCreator/appl/Windows.h | 29 ++++ sample/MeshCreator/appl/debug.cpp | 15 ++ sample/MeshCreator/appl/debug.h | 52 ++++++ sample/MeshCreator/appl/main.cpp | 57 +++++++ sample/MeshCreator/appl/main.h | 14 ++ sample/MeshCreator/lutin_egeMeshCreator.py | 40 +++++ sample/Particle/README.md | 0 sample/Script/README.md | 0 sample/StereoVision/README.md | 0 41 files changed, 668 insertions(+), 341 deletions(-) create mode 100644 ege/physics/Engine.cpp create mode 100644 ege/physics/Engine.h create mode 100644 sample/Accelerometer/README.md create mode 100644 sample/CameraPosition/README.md create mode 100644 sample/Collision/README.md create mode 100644 sample/DoubleView/README.md create mode 100644 sample/GameFPS/README.md create mode 100644 sample/GamePad/README.md create mode 100644 sample/GameRacer/README.md create mode 100644 sample/GameSpaceSimulation/README.md create mode 100644 sample/Light/README.md create mode 100644 sample/Material/README.md create mode 100644 sample/MeshCreator/README.md create mode 100644 sample/MeshCreator/appl/Windows.cpp create mode 100644 sample/MeshCreator/appl/Windows.h create mode 100644 sample/MeshCreator/appl/debug.cpp create mode 100644 sample/MeshCreator/appl/debug.h create mode 100644 sample/MeshCreator/appl/main.cpp create mode 100644 sample/MeshCreator/appl/main.h create mode 100644 sample/MeshCreator/lutin_egeMeshCreator.py create mode 100644 sample/Particle/README.md create mode 100644 sample/Script/README.md create mode 100644 sample/StereoVision/README.md diff --git a/ege/CollisionShapeCreator.cpp b/ege/CollisionShapeCreator.cpp index 27fa460..55ecf79 100644 --- a/ege/CollisionShapeCreator.cpp +++ b/ege/CollisionShapeCreator.cpp @@ -31,7 +31,7 @@ btCollisionShape* ege::collision::createShape(const std::shared_ptr& physiqueProperty = _mesh->getPhysicalProperties(); + const std::vector>& physiqueProperty = _mesh->getPhysicalProperties(); if (physiqueProperty.size() == 0) { return new btEmptyShape();; } diff --git a/ege/ElementGame.cpp b/ege/ElementGame.cpp index 291a153..812cfcb 100644 --- a/ege/ElementGame.cpp +++ b/ege/ElementGame.cpp @@ -1,4 +1,4 @@ - /** +/** * @author Edouard DUPIN * * @copyright 2011, Edouard DUPIN, all right reserved @@ -34,11 +34,11 @@ const std::string& ege::ElementGame::getType() const { } -ege::ElementGame::ElementGame(ege::Environement& _env) : +ege::ElementGame::ElementGame(const std::shared_ptr& _env) : m_env(_env), m_body(nullptr), m_uID(0), - m_mesh(nullptr), + m_mesh(), m_shape(nullptr), m_life(100), m_lifeMax(100), @@ -60,10 +60,8 @@ ege::ElementGame::~ElementGame() { // same ... dynamicDisable(); removeShape(); - if (nullptr != m_body) { - delete(m_body); - m_body = nullptr; - } + delete m_body; + m_body = nullptr; EGE_DEBUG("Destroy element : uId=" << m_uID); } @@ -483,10 +481,10 @@ void ege::ElementGame::dynamicEnable() { return; } if(nullptr!=m_body) { - m_env.getDynamicWorld()->addRigidBody(m_body); + m_env->getDynamicWorld()->addRigidBody(m_body); } if(nullptr!=m_IA) { - m_env.getDynamicWorld()->addAction(m_IA); + m_env->getDynamicWorld()->addAction(m_IA); } m_elementInPhysicsSystem = true; } @@ -496,12 +494,12 @@ void ege::ElementGame::dynamicDisable() { return; } if(nullptr!=m_IA) { - m_env.getDynamicWorld()->removeAction(m_IA); + m_env->getDynamicWorld()->removeAction(m_IA); } if(nullptr!=m_body) { // Unlink element from the engine - m_env.getDynamicWorld()->removeRigidBody(m_body); - m_env.getDynamicWorld()->removeCollisionObject(m_body); + m_env->getDynamicWorld()->removeRigidBody(m_body); + m_env->getDynamicWorld()->removeCollisionObject(m_body); } m_elementInPhysicsSystem = false; } @@ -517,7 +515,7 @@ void ege::ElementGame::iaEnable() { return; } if (true == m_elementInPhysicsSystem) { - m_env.getDynamicWorld()->addAction(m_IA); + m_env->getDynamicWorld()->addAction(m_IA); } } @@ -527,7 +525,7 @@ void ege::ElementGame::iaDisable() { return; } if (true == m_elementInPhysicsSystem) { - m_env.getDynamicWorld()->removeAction(m_IA); + m_env->getDynamicWorld()->removeAction(m_IA); } // remove IA : delete(m_IA); diff --git a/ege/ElementGame.h b/ege/ElementGame.h index ef8fd59..6572c76 100644 --- a/ege/ElementGame.h +++ b/ege/ElementGame.h @@ -33,7 +33,7 @@ namespace ege { private: static void FunctionFreeShape(void* _pointer); protected: - ege::Environement& m_env; + std::shared_ptr m_env; protected: btRigidBody* m_body; //!< all the element have a body == > otherwise it will be not manage with this system... public: @@ -42,7 +42,7 @@ namespace ege { * The objest will be stored in a pool of element and keep a second time if needed == > redure memory allocation, * when needed, the system will call the init and un-init function... */ - ElementGame(ege::Environement& _env); + ElementGame(const std::shared_ptr& _env); /** * @brief Destructor */ @@ -150,7 +150,7 @@ namespace ege { */ virtual void setFireOn(int32_t _groupIdSource, int32_t _type, float _power, const vec3& _center=vec3(0,0,0)); /** - * @brief Call chan the element life change + * @brief Call chan the element life change */ virtual void onLifeChange() { }; protected: @@ -234,7 +234,7 @@ namespace ege { * @brief Event arrive when an element has been remove from the system == > this permit to keep pointer of ennemy, and not search them every cycle ... * @param[in] _removedElement Pointer on the element removed. */ - virtual void elementIsRemoved(ege::ElementGame* _removedElement) { }; + virtual void elementIsRemoved(std::shared_ptr _removedElement) { }; protected: bool m_fixe; //!< is a fixed element == > used for placement of every elements public: @@ -275,7 +275,10 @@ namespace ege { /** * @brief Constructor */ - localIA(ElementGame& element) : m_element(element) { }; + localIA(ElementGame& _element) : + m_element(_element) { + + }; /** * @brief Destructor */ diff --git a/ege/Environement.cpp b/ege/Environement.cpp index 3e55170..b07f992 100644 --- a/ege/Environement.cpp +++ b/ege/Environement.cpp @@ -9,21 +9,36 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #undef __class__ #define __class__ "Environement" -ege::ElementGame* ege::Environement::getElementNearest(ege::ElementGame* _sourceRequest, float& _distance) { - if (nullptr == _sourceRequest) { +std::shared_ptr ege::Environement::getElementNearest(std::shared_ptr _sourceRequest, float& _distance) { + if (_sourceRequest == nullptr) { return nullptr; } vec3 sourcePosition = _sourceRequest->getPosition(); - ege::ElementGame* result = nullptr; + std::shared_ptr result = nullptr; for (size_t iii=0; iiigetGroup() <= 0) { @@ -82,10 +97,10 @@ void ege::Environement::getElementNearestFixed(const vec3& _sourcePosition, for (size_t iii=0; iiiisFixed()) { + if (result.element->isFixed() == false) { continue; } // check distance ... @@ -116,7 +131,7 @@ static etk::Hash& getHachTableCreating() { } void ege::Environement::addCreator(const std::string& _type, ege::createElement_tf _creator) { - if (nullptr == _creator) { + if (_creator == nullptr) { EGE_ERROR("Try to add an empty CREATOR ..."); return; } @@ -125,25 +140,23 @@ void ege::Environement::addCreator(const std::string& _type, ege::createElement_ EGE_DEBUG("Add creator: " << _type << " (done)"); } -ege::ElementGame* ege::Environement::createElement(const std::string& _type, bool _autoAddElement, enum ege::property _property, void* _value) { +std::shared_ptr ege::Environement::createElement(const std::string& _type, bool _autoAddElement, enum ege::property _property, void* _value) { if (false == getHachTableCreating().exist(_type)) { EGE_ERROR("Request creating of an type that is not known '" << _type << "'"); return nullptr; } ege::createElement_tf creatorPointer = getHachTableCreating()[_type]; - if (nullptr == creatorPointer) { + if (creatorPointer == nullptr) { EGE_ERROR("nullptr pointer creator == > internal error... '" << _type << "'"); return nullptr; } - ege::ElementGame* tmpElement = creatorPointer(*this); - if (nullptr == tmpElement) { + std::shared_ptr tmpElement = creatorPointer(std::dynamic_pointer_cast(shared_from_this())); + if (tmpElement == nullptr) { EGE_ERROR("allocation error '" << _type << "'"); return nullptr; } if (false == tmpElement->init(_property, _value)) { EGE_ERROR("Init error ... '" << _type << "'"); - // remove created element ... - delete(tmpElement); return nullptr; } if (_autoAddElement == true) { @@ -152,26 +165,26 @@ ege::ElementGame* ege::Environement::createElement(const std::string& _type, boo return tmpElement; } -ege::ElementGame* ege::Environement::createElement(const std::string& _type, std::string& _description, bool _autoAddElement) { +std::shared_ptr ege::Environement::createElement(const std::string& _type, std::string& _description, bool _autoAddElement) { return createElement(_type, _autoAddElement, ege::typeString, static_cast(&_description)); } -ege::ElementGame* ege::Environement::createElement(const std::string& _type, ejson::Value* _value, bool _autoAddElement) { +std::shared_ptr ege::Environement::createElement(const std::string& _type, ejson::Value* _value, bool _autoAddElement) { return createElement(_type, _autoAddElement, ege::typeJson, static_cast(_value)); } -ege::ElementGame* ege::Environement::createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement) { +std::shared_ptr ege::Environement::createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement) { return createElement(_type, _autoAddElement, ege::typeXml, static_cast(_node)); } -void ege::Environement::addElementGame(ege::ElementGame* _newElement) { +void ege::Environement::addElementGame(std::shared_ptr _newElement) { // prevent memory allocation and un allocation ... - if (nullptr == _newElement) { + if (_newElement == nullptr) { return; } for (size_t iii=0; iiidynamicEnable(); return; @@ -181,13 +194,13 @@ void ege::Environement::addElementGame(ege::ElementGame* _newElement) { _newElement->dynamicEnable(); } -void ege::Environement::rmElementGame(ege::ElementGame* _removeElement) { - if (nullptr == _removeElement) { +void ege::Environement::rmElementGame(std::shared_ptr _removeElement) { + if (_removeElement == nullptr) { return; } // inform the element that an element has been removed == > this permit to keep pointer on elements ... for (size_t iii=0; iiielementIsRemoved(_removeElement); } } @@ -197,8 +210,7 @@ void ege::Environement::rmElementGame(ege::ElementGame* _removeElement) { m_listElementGame[iii]->onDestroy(); m_listElementGame[iii]->dynamicDisable(); m_listElementGame[iii]->unInit(); - delete(m_listElementGame[iii]); - m_listElementGame[iii] = nullptr; + m_listElementGame[iii].reset(); } } } @@ -271,17 +283,91 @@ void ege::Environement::generateInteraction(ege::ElementInteraction& _event) { } ege::Environement::Environement() : - m_dynamicsWorld(nullptr), + signalPlayTimeChange(*this, "time-change"), + m_dynamicsWorld(), + m_listElementGame(), + m_status(*this, "status", gameStart, "Satus of the activity of the Environement"), + m_ratio(*this, "ratio", 1.0f, "game speed ratio"), m_particuleEngine(*this) { // nothing to do ... + m_status.add(gameStart, "start", "Scene is started"); + m_status.add(gameStop, "stop", "Scene is stopped"); +} + +void ege::Environement::init() { + ewol::Object::init(); + getObjectManager().periodicCall.bind(shared_from_this(), &ege::Environement::periodicCall); + } void ege::Environement::clear() { - for (auto &it : m_listElementGame) { - if (it != nullptr) { - delete it; - it = nullptr; - } - } m_listElementGame.clear(); } + + +void ege::Environement::periodicCall(const ewol::event::Time& _event) { + float curentDelta = _event.getDeltaCall(); + // small hack to change speed ... + curentDelta *= m_ratio; + // check if the processing is availlable + if (m_status.get() == gameStop) { + return; + } + // update game time: + int32_t lastGameTime = m_gameTime*0.000001f; + m_gameTime += curentDelta; + if (lastGameTime != (int32_t)(m_gameTime*0.000001f)) { + signalPlayTimeChange.emit(m_gameTime*0.000001f); + } + + //EWOL_DEBUG("Time: m_lastCallTime=" << m_lastCallTime << " deltaTime=" << deltaTime); + + // update camera positions: + for (auto &it : m_listCamera) { + if (it.second != nullptr) { + it.second->periodicCall(curentDelta); + } + } + //EGE_DEBUG("stepSimulation (start)"); + ///step the simulation + if (m_dynamicsWorld != nullptr) { + m_dynamicsWorld->stepSimulation(curentDelta); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + } + m_particuleEngine.update(curentDelta); + // remove all element that requested it ... + { + int32_t numberEnnemyKilled=0; + int32_t victoryPoint=0; + auto it(m_listElementGame.begin()); + while (it != m_listElementGame.end()) { + if(*it != nullptr) { + if ((*it)->needToRemove() == true) { + if ((*it)->getGroup() > 1) { + numberEnnemyKilled++; + victoryPoint++; + } + EGE_DEBUG("[" << (*it)->getUID() << "] element Removing ... " << (*it)->getType()); + rmElementGame((*it)); + } + } + } + if (0 != numberEnnemyKilled) { + //signalKillEnemy.emit(numberEnnemyKilled); + } + } +} + + +void ege::Environement::addCamera(const std::string& _name, const std::shared_ptr& _camera) { + m_listCamera.insert(std::make_pair(_name, _camera)); +} + +std::shared_ptr ege::Environement::getCamera(const std::string& _name) { + auto cameraIt = m_listCamera.find(_name); + if (cameraIt != m_listCamera.end()) { + return cameraIt->second; + } + return nullptr; +} diff --git a/ege/Environement.h b/ege/Environement.h index 125a79b..a949ad0 100644 --- a/ege/Environement.h +++ b/ege/Environement.h @@ -24,6 +24,9 @@ class btDynamicsWorld; #include #include #include +#include +#include +#include namespace ege { enum property { @@ -36,7 +39,13 @@ namespace ege { }; class ElementGame; class Environement; - typedef ege::ElementGame* (*createElement_tf)(ege::Environement& _env); + typedef std::shared_ptr (*createElement_tf)(const std::shared_ptr& _env); + + enum gameStatus { + gameStart, + gamePause, + gameStop + }; class ElementInteraction { protected: @@ -76,13 +85,58 @@ namespace ege { virtual void applyEvent(ege::ElementGame& _element) { }; }; - class Environement { - private: - btDynamicsWorld* m_dynamicsWorld; //!< curent system world description - std::vector m_listElementGame; //!< List of all element added in the Game + class Environement : public ewol::Object { public: + // extern event + ewol::Signal signalPlayTimeChange; + private: + std::shared_ptr m_dynamicsWorld; //!< curent system world description + std::vector> m_listElementGame; //!< List of all element added in the Game + protected: Environement(); + void init(); + public: + DECLARE_FACTORY(Environement); virtual ~Environement() { }; + protected: + ewol::parameter::List m_status; //!< the display is running (not in pause) + public: + /** + * @brief Get the game status. + * @return the current status. + */ + enum gameStatus getGameStatus() { + return m_status.get(); + } + /** + * @brief Set the game status. + * @param[in] _value New game status. + */ + void setGameStatus(enum gameStatus _value) { + m_status.set(_value); + } + protected: + ewol::parameter::List m_ratio; //!< Speed ratio + public: + /** + * @brief Get the game speed ratio. + * @return the current ratio. + */ + float getSpeedRatio() { + return m_ratio.get(); + } + /** + * @brief Set the game ratio. + * @param[in] _value New game ratio. + */ + void setSpeedRatio(float _value) { + m_ratio.set(_value); + } + protected: + std::map> m_listCamera; //!< list of all camera in the world + public: + void addCamera(const std::string& _name, const std::shared_ptr& _camera); + std::shared_ptr getCamera(const std::string& _name); public: /** * @brief Remove all from the current environement @@ -102,35 +156,35 @@ namespace ege { * @return nullptr if an error occured OR the pointer on the element and it is already added on the system. * @note Pointer is return in case of setting properties on it... */ - ege::ElementGame* createElement(const std::string& _type, bool _autoAddElement=true, enum ege::property _property=ege::typeNone, void* _value=nullptr); - ege::ElementGame* createElement(const std::string& _type, std::string& _description, bool _autoAddElement=true); - ege::ElementGame* createElement(const std::string& _type, ejson::Value* _value, bool _autoAddElement=true); - ege::ElementGame* createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement=true); + std::shared_ptr createElement(const std::string& _type, bool _autoAddElement=true, enum ege::property _property=ege::typeNone, void* _value=nullptr); + std::shared_ptr createElement(const std::string& _type, std::string& _description, bool _autoAddElement=true); + std::shared_ptr createElement(const std::string& _type, ejson::Value* _value, bool _autoAddElement=true); + std::shared_ptr createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement=true); public: class ResultNearestElement { public: - ege::ElementGame* element; + std::shared_ptr element; float dist; }; /** * @brief set the curent world * @param[in] _newWorld Pointer on the current world */ - void setDynamicWorld(btDynamicsWorld* _newWorld) { + void setDynamicWorld(const std::shared_ptr& _newWorld) { m_dynamicsWorld=_newWorld; }; /** * @brief get the curent world * @return pointer on the current world */ - btDynamicsWorld* getDynamicWorld() { + std::shared_ptr getDynamicWorld() { return m_dynamicsWorld; }; /** * @breif get a reference on the curent list of element games * @return all element list */ - std::vector& getElementGame() { + std::vector>& getElementGame() { return m_listElementGame; }; /** @@ -139,7 +193,7 @@ namespace ege { * @param[in] _distance Maximum distance search == > return the element distance * @return Pointer on the neares element OR nullptr */ - ege::ElementGame* getElementNearest(ege::ElementGame* _sourceRequest, float& _distance); + std::shared_ptr getElementNearest(std::shared_ptr _sourceRequest, float& _distance); void getElementNearest(const vec3& _sourcePosition, float _distanceMax, @@ -151,12 +205,12 @@ namespace ege { * @brief add an element on the list availlable. * @param[in] _newElement Element to add. */ - void addElementGame(ege::ElementGame* _newElement); + void addElementGame(std::shared_ptr _newElement); /** * @brief remove an element on the list availlable. * @param[in] _removeElement Element to remove. */ - void rmElementGame(ege::ElementGame* _removeElement); + void rmElementGame(std::shared_ptr _removeElement); /** * @brief get the element order from the nearest to the farest, and remove all element that are not in the camera angle and axes. * @param[in,out] _resultList List of the element ordered. @@ -179,6 +233,12 @@ namespace ege { ege::ParticuleEngine& getParticuleEngine() { return m_particuleEngine; }; + protected: + int64_t m_gameTime; //!< time of the game running + public: + + private: + void periodicCall(const ewol::event::Time& _event); }; }; diff --git a/ege/Game.h b/ege/Game.h index eae7382..db13c54 100644 --- a/ege/Game.h +++ b/ege/Game.h @@ -45,45 +45,10 @@ namespace ege { void init(); public: ~Game() - protected: - ewol::parameter::List m_status; //!< the display is running (not in pause) - public: - /** - * @brief Get the game status. - * @return the current status. - */ - enum gameStatus getGameStatus() { - return m_status.get() - } - /** - * @brief Set the game status. - * @param[in] _value New game status. - */ - enum gameStatus setGameStatus(enum gameStatus _value) { - return m_status.set(_value) - } - protected: - ewol::parameter::List m_ratio; //!< Speed ratio - public: - /** - * @brief Get the game speed ratio. - * @return the current ratio. - */ - float getSpeedRatio() { - return m_ratio.get() - } - /** - * @brief Set the game ratio. - * @param[in] _value New game ratio. - */ - enum gameStatus setSpeedRatio(float _value) { - return m_ratio.set(_value) - } protected: ege::PhysicEngine m_physicEngine; //!< physic engine interface ege::AudioEngine m_AudioEngine; //!< physic engine interface ege::IAEngine m_iAEngine; //!< physic engine interface - std::map> m_listCamera; //!< list of all camera in the world } } diff --git a/ege/physics/Engine.cpp b/ege/physics/Engine.cpp new file mode 100644 index 0000000..b88cf3c --- /dev/null +++ b/ege/physics/Engine.cpp @@ -0,0 +1,66 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#include + + + +ege::physics::Engine::Engine() { + setBulletConfig(); +} + +ege::physics::Engine::~Engine() { + /* + m_dynamicsWorld.release(); + m_solver.release(); + m_broadphase.release(); + m_dispatcher.release(); + m_collisionConfiguration.release(); + */ +} + +void ege::physics::Engine::setBulletConfig(std::make_shared(btDefaultCollisionConfiguration> _collisionConfiguration, + std::make_shared(btCollisionDispatcher> _dispatcher, + std::make_shared(btBroadphaseInterface> _broadphase, + std::make_shared(btConstraintSolver> _solver, + std::make_shared(btDynamicsWorld> _dynamicsWorld) { + if (_collisionConfiguration != nullptr) { + m_collisionConfiguration = _collisionConfiguration; + } else { + m_collisionConfiguration = std::make_shared(btDefaultCollisionConfiguration()); + } + ///use the default collision dispatcher. + if (_dispatcher != nullptr) { + m_dispatcher = _dispatcher; + } else { + m_dispatcher = std::make_shared(btCollisionDispatcher(m_collisionConfiguration)); + } + if (_broadphase != nullptr) { + m_broadphase = _broadphase; + } else { + m_broadphase = std::make_shared(btDbvtBroadphase()); + } + + ///the default constraint solver. + if (_solver != nullptr) { + m_solver = _solver; + } else { + m_solver = std::make_shared(btSequentialImpulseConstraintSolver()); + } + + if (_dynamicsWorld != nullptr) { + m_dynamicsWorld = _dynamicsWorld; + } else { + m_dynamicsWorld = std::make_shared(btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration)); + // By default we set no gravity + m_dynamicsWorld->setGravity(btVector3(0,0,0)); + } + + m_env.setDynamicWorld(m_dynamicsWorld); + +} \ No newline at end of file diff --git a/ege/physics/Engine.h b/ege/physics/Engine.h new file mode 100644 index 0000000..8776ccb --- /dev/null +++ b/ege/physics/Engine.h @@ -0,0 +1,58 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EGE_PHYSICS_ENGINE_H__ +#define __EGE_PHYSICS_ENGINE_H__ + +#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; + + +namespace ege { + namespace physics { + class Engine { + private: + ///this is the most important class + std::shared_ptr m_dispatcher; + std::shared_ptr m_broadphase; + std::shared_ptr m_solver; + std::shared_ptr m_dynamicsWorld; + public: + Engine(); + ~Engine(); + void setBulletConfig(std::shared_ptr _collisionConfiguration=nullptr, + std::shared_ptr _dispatcher=nullptr, + std::shared_ptr _broadphase=nullptr, + std::shared_ptr _solver=nullptr, + std::shared_ptr _dynamicsWorld=nullptr); + }; + }; +}; + +#endif diff --git a/ege/physicsShape/PhysicsShape.cpp b/ege/physicsShape/PhysicsShape.cpp index ca7b842..067ef2c 100644 --- a/ege/physicsShape/PhysicsShape.cpp +++ b/ege/physicsShape/PhysicsShape.cpp @@ -15,21 +15,21 @@ #include -ege::PhysicsShape* ege::PhysicsShape::create(const std::string& _name) { - ege::PhysicsShape* tmpp = nullptr; +std::shared_ptr ege::PhysicsShape::create(const std::string& _name) { + std::shared_ptr tmpp = nullptr; std::string name = etk::tolower(_name); if (name == "box") { - tmpp = new ege::PhysicsBox(); + tmpp = std::make_shared(); } else if (name == "sphere") { - tmpp = new ege::PhysicsSphere(); + tmpp = std::make_shared(); } else if (name == "cone") { - tmpp = new ege::PhysicsCone(); + tmpp = std::make_shared(); } else if (name == "cylinder") { - tmpp = new ege::PhysicsCylinder(); + tmpp = std::make_shared(); } else if (name == "capsule") { - tmpp = new ege::PhysicsCapsule(); + tmpp = std::make_shared(); } else if (name == "convexhull") { - tmpp = new ege::PhysicsConvexHull(); + tmpp = std::make_shared(); } else { EGE_ERROR("Create an unknow element : '" << _name << "' availlable : [BOX,SPHERE,CONE,CYLINDER,CAPSULE,CONVEXHULL]"); return nullptr; diff --git a/ege/physicsShape/PhysicsShape.h b/ege/physicsShape/PhysicsShape.h index 25571e4..5edad94 100644 --- a/ege/physicsShape/PhysicsShape.h +++ b/ege/physicsShape/PhysicsShape.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace ege { @@ -26,7 +27,7 @@ namespace ege { class PhysicsShape { public: - static ege::PhysicsShape* create(const std::string& _name); + static std::shared_ptr create(const std::string& _name); public: enum type { unknow, diff --git a/ege/resource/Mesh.cpp b/ege/resource/Mesh.cpp index 4a55d24..77486a6 100644 --- a/ege/resource/Mesh.cpp +++ b/ege/resource/Mesh.cpp @@ -19,9 +19,7 @@ ege::resource::Mesh::Mesh() : m_normalMode(normalModeNone), - m_checkNormal(false), - m_pointerShape(nullptr), - m_functionFreeShape(nullptr) { + m_checkNormal(false) { addObjectType("ege::resource::Mesh"); } @@ -82,13 +80,7 @@ ege::resource::Mesh::~Mesh() { } void ege::resource::Mesh::clean() { - for (auto &elem : m_physics) { - delete(elem); - } m_physics.clear(); - for (int32_t iii=0; iii material; // physical shape: - ege::PhysicsShape* physics = nullptr; + std::shared_ptr physics; while(1) { int32_t level = countIndent(fileName); if (level == 0) { @@ -848,7 +840,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { materialName = ""; material = nullptr; } - material = new ege::Material(); + material = std::make_shared(); materialName = inputDataLine; currentMode = EMFModuleMaterialNamed; EGE_VERBOSE(" "<< materialName); @@ -927,7 +919,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { && material!=nullptr) { m_materials.add(materialName, material); materialName = ""; - material = nullptr; + material.reset(); } EGE_VERBOSE("Stop parsing Mesh file"); @@ -936,7 +928,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { return true; } -void ege::resource::Mesh::addMaterial(const std::string& _name, ege::Material* _data) { +void ege::resource::Mesh::addMaterial(const std::string& _name, std::shared_ptr _data) { if (nullptr == _data) { EGE_ERROR(" can not add material with null pointer"); return; diff --git a/ege/resource/Mesh.h b/ege/resource/Mesh.h index f9419c8..6ca65fc 100644 --- a/ege/resource/Mesh.h +++ b/ege/resource/Mesh.h @@ -57,16 +57,16 @@ namespace ege { int32_t m_GLtexture; int32_t m_bufferOfset; int32_t m_numberOfElments; - MaterialGlId m_GLMaterial; - ege::Light m_light; + MaterialGlId m_GLMaterial; + ege::Light m_light; protected: std::vector m_listVertex; //!< List of all vertex in the element std::vector m_listUV; //!< List of all UV point in the mesh (for the specify texture) std::vector m_listFacesNormal; //!< List of all Face normal, when calculated std::vector m_listVertexNormal; //!< List of all Face normal, when calculated etk::Hash m_listFaces; //!< List of all Face for the mesh - etk::Hash m_materials; - std::vector m_physics; //!< collision shape module ... (independent of bullet lib) + etk::Hash> m_materials; + std::vector> m_physics; //!< collision shape module ... (independent of bullet lib) void clean(); protected: std::shared_ptr m_verticesVBO; @@ -95,7 +95,7 @@ namespace ege { bool loadOBJ(const std::string& _fileName); bool loadEMF(const std::string& _fileName); public: - void addMaterial(const std::string& _name, ege::Material* _data); + void addMaterial(const std::string& _name, std::shared_ptr _data); public: /** * @brief set the check of normal position befor sending it to the openGl card @@ -111,7 +111,7 @@ namespace ege { bool getCheckNormal() { return m_checkNormal; }; - const std::vector& getPhysicalProperties() const { + const std::vector>& getPhysicalProperties() const { return m_physics; }; private: diff --git a/ege/resource/tools/icoSphere.cpp b/ege/resource/tools/icoSphere.cpp index 20a50a7..e9d348f 100644 --- a/ege/resource/tools/icoSphere.cpp +++ b/ege/resource/tools/icoSphere.cpp @@ -32,7 +32,7 @@ static int32_t addUV(std::vector& _listUV, int32_t _uvId, float _add) { return _listUV.size()-1; } -void ege::icoSphere::create(etk::Hash& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, +void ege::icoSphere::create(etk::Hash>& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, const std::string& _materialName, float _size, int32_t _recursionLevel) { /* 5 diff --git a/ege/resource/tools/icoSphere.h b/ege/resource/tools/icoSphere.h index e37950f..9e16c57 100644 --- a/ege/resource/tools/icoSphere.h +++ b/ege/resource/tools/icoSphere.h @@ -16,7 +16,7 @@ namespace ege { namespace icoSphere { - void create(etk::Hash& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, + void create(etk::Hash>& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, const std::string& _materialName, float _size, int32_t _recursionLevel); }; }; diff --git a/ege/resource/tools/isoSphere.cpp b/ege/resource/tools/isoSphere.cpp index 4496f69..4b7f19f 100644 --- a/ege/resource/tools/isoSphere.cpp +++ b/ege/resource/tools/isoSphere.cpp @@ -9,7 +9,7 @@ #include #include -void ege::isoSphere::create(etk::Hash& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, +void ege::isoSphere::create(etk::Hash>& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, const std::string& _materialName, int32_t _recursionLevel) { _recursionLevel = std::max(_recursionLevel, 3); float size = 1.0f; diff --git a/ege/resource/tools/isoSphere.h b/ege/resource/tools/isoSphere.h index 8ed6a3a..65335c6 100644 --- a/ege/resource/tools/isoSphere.h +++ b/ege/resource/tools/isoSphere.h @@ -16,7 +16,7 @@ namespace ege { namespace isoSphere { - void create(etk::Hash& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, + void create(etk::Hash>& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, const std::string& _materialName, int32_t _recursionLevel); }; }; diff --git a/ege/resource/tools/viewBox.cpp b/ege/resource/tools/viewBox.cpp index 25587ff..74956c3 100644 --- a/ege/resource/tools/viewBox.cpp +++ b/ege/resource/tools/viewBox.cpp @@ -11,7 +11,7 @@ -void ege::viewBox::create(etk::Hash& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, +void ege::viewBox::create(etk::Hash>& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, const std::string& _materialName, float _size) { // This is the direct generation basis on the .obj system /* diff --git a/ege/resource/tools/viewBox.h b/ege/resource/tools/viewBox.h index 903d681..7ba21cd 100644 --- a/ege/resource/tools/viewBox.h +++ b/ege/resource/tools/viewBox.h @@ -16,7 +16,7 @@ namespace ege { namespace viewBox { - void create(etk::Hash& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, + void create(etk::Hash>& _materials, etk::Hash& _listFaces, std::vector& _listVertex, std::vector& _listUV, const std::string& _materialName, float _size); }; }; diff --git a/ege/widget/Scene.cpp b/ege/widget/Scene.cpp index f680e8b..176ee1f 100644 --- a/ege/widget/Scene.cpp +++ b/ege/widget/Scene.cpp @@ -30,29 +30,28 @@ #undef __class__ #define __class__ "Scene" -ege::widget::Scene::Scene() : - signalPlayTimeChange(*this, "time-change"), - signalKillEnemy(*this, "kill-ennemy"), - m_gameTime(0), - m_angleView(M_PI/3.0), - m_dynamicsWorld(nullptr), - m_camera(nullptr), - m_isRunning(*this, "status", gameStart, "Satus of the activity of the Scene"), - m_debugMode(false), - m_debugDrawing(nullptr) { +ege::widget::Scene::Scene() //: + //signalKillEnemy(*this, "kill-ennemy"), + //m_gameTime(0), + //m_angleView(M_PI/3.0), + //m_dynamicsWorld(nullptr), + //m_camera(nullptr), + //m_debugMode(false), + //m_debugDrawing(nullptr) +{ addObjectType("ege::widget::Scene"); } -void ege::widget::Scene::init(bool _setAutoBullet, bool _setAutoCamera) { +void ege::widget::Scene::init(std::shared_ptr _env) { + m_env = _env; ewol::Widget::init(); setKeyboardRepeate(false); setCanHaveFocus(true); periodicCallEnable(); - m_isRunning.add(gameStart, "start", "Scene is started"); - m_isRunning.add(gameStop, "stop", "Scene is stopped"); - m_debugDrawing = ewol::resource::Colored3DObject::create(); + //m_debugDrawing = ewol::resource::Colored3DObject::create(); + /* m_ratioTime = 1.0f; if (_setAutoBullet == true) { setBulletConfig(); @@ -60,49 +59,10 @@ void ege::widget::Scene::init(bool _setAutoBullet, bool _setAutoCamera) { if (_setAutoCamera == true) { setCamera(); } + */ } -void ege::widget::Scene::setBulletConfig(btDefaultCollisionConfiguration* _collisionConfiguration, - btCollisionDispatcher* _dispatcher, - btBroadphaseInterface* _broadphase, - btConstraintSolver* _solver, - btDynamicsWorld* _dynamicsWorld) { - if (nullptr != _collisionConfiguration) { - m_collisionConfiguration = _collisionConfiguration; - } else { - m_collisionConfiguration = new btDefaultCollisionConfiguration(); - } - ///use the default collision dispatcher. - if (nullptr != _dispatcher) { - m_dispatcher = _dispatcher; - } else { - m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); - } - if (nullptr != _broadphase) { - m_broadphase = _broadphase; - } else { - m_broadphase = new btDbvtBroadphase(); - } - - ///the default constraint solver. - if (nullptr != _solver) { - m_solver = _solver; - } else { - m_solver = new btSequentialImpulseConstraintSolver(); - } - - if (nullptr != _dynamicsWorld) { - m_dynamicsWorld = _dynamicsWorld; - } else { - m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); - // By default we set no gravity - m_dynamicsWorld->setGravity(btVector3(0,0,0)); - } - - m_env.setDynamicWorld(m_dynamicsWorld); - -} - +/* void ege::widget::Scene::setCamera(ege::Camera* _camera) { if (nullptr != _camera) { m_camera = _camera; @@ -112,10 +72,9 @@ void ege::widget::Scene::setCamera(ege::Camera* _camera) { m_camera->setEye(vec3(0,0,0)); } } - +*/ ege::widget::Scene::~Scene() { - -/* + /* ewol::resource::release(m_directDrawObject); //cleanup in the reverse order of creation/initialization //remove the rigidbodies from the dynamics world and delete them @@ -128,12 +87,6 @@ ege::widget::Scene::~Scene() { m_dynamicsWorld->removeCollisionObject( obj ); delete obj; } - - delete m_dynamicsWorld; - delete m_solver; - delete m_broadphase; - delete m_dispatcher; - delete m_collisionConfiguration; */ } @@ -143,26 +96,6 @@ void ege::widget::Scene::onRegenerateDisplay() { } } -void ege::widget::Scene::pause() { - EGE_DEBUG("Set pause"); - m_isRunning.set(gameStop); -} - -void ege::widget::Scene::resume() { - EGE_DEBUG("Set resume"); - m_isRunning.set(gameStart); -} - -void ege::widget::Scene::pauseToggle() { - if(m_isRunning.get() == gameStart) { - EGE_DEBUG("Set Toggle: pause"); - m_isRunning.set(gameStop); - } else { - EGE_DEBUG("Set Toggle: resume"); - m_isRunning.set(gameStart); - } -} - //#define SCENE_DISPLAY_SPEED ////////////////////////////////////////////////////////////////////////////////////////////// @@ -179,15 +112,19 @@ void ege::widget::Scene::onDraw() { g_counterNbTimeDisplay++; g_startTime = ewol::getTime(); #endif + // get camera : + std::shared_ptr camera = m_env->getCamera(m_cameraName); //EGE_DEBUG("Draw (start)"); mat4 tmpMatrix; - if (m_dynamicsWorld) { - m_env.getOrderedElementForDisplay(m_displayElementOrdered, m_camera->getOrigin(), m_camera->getViewVector()); + std::shared_ptr world = m_env->getDynamicWorld(); + if (world != nullptr) { + + m_env->getOrderedElementForDisplay(m_displayElementOrdered, camera->getOrigin(), camera->getViewVector()); //EGE_DEBUG("DRAW : " << m_displayElementOrdered.size() << " elements"); // TODO : remove this == > no more needed ==> checked in the generate the list of the element ordered for (size_t iii=0; iiipreCalculationDraw(*m_camera); + m_displayElementOrdered[iii].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) @@ -205,9 +142,12 @@ void ege::widget::Scene::onDraw() { m_displayElementOrdered[iii].element->draw(pass); } } + /* for (size_t iii=0; iiidrawLife(m_debugDrawing, *m_camera); } + */ + /* #ifdef DEBUG if (true == m_debugMode) { for (size_t iii=0; iiigetParticuleEngine().draw(*camera); } #ifdef SCENE_DISPLAY_SPEED float localTime = (float)(ewol::getTime() - g_startTime) / 1000.0f; @@ -238,59 +179,6 @@ btRigidBody& btActionInterface::getFixedBody() { } void ege::widget::Scene::periodicCall(const ewol::event::Time& _event) { - float curentDelta=_event.getDeltaCall(); - // small hack to change speed ... - if (m_ratioTime != 1) { - curentDelta *= m_ratioTime; - } - // check if the processing is availlable - if (m_isRunning.get() == gameStop) { - markToRedraw(); - return; - } - // update game time: - int32_t lastGameTime = m_gameTime; - m_gameTime += curentDelta; - if (lastGameTime != (int32_t)m_gameTime) { - signalPlayTimeChange.emit(m_gameTime); - } - - //EWOL_DEBUG("Time: m_lastCallTime=" << m_lastCallTime << " deltaTime=" << deltaTime); - - // update camera positions: - if (nullptr != m_camera) { - m_camera->periodicCall(curentDelta); - } - //EGE_DEBUG("stepSimulation (start)"); - ///step the simulation - if (m_dynamicsWorld) { - m_dynamicsWorld->stepSimulation(curentDelta); - //optional but useful: debug drawing - m_dynamicsWorld->debugDrawWorld(); - } - m_env.getParticuleEngine().update(curentDelta); - // remove all element that requested it ... - { - int32_t numberEnnemyKilled=0; - int32_t victoryPoint=0; - std::vector& elementList = m_env.getElementGame(); - for (int32_t iii=elementList.size()-1; iii >= 0; --iii) { - if(nullptr != elementList[iii]) { - if (true == elementList[iii]->needToRemove()) { - if (elementList[iii]->getGroup() > 1) { - numberEnnemyKilled++; - victoryPoint++; - } - EGE_DEBUG("[" << elementList[iii]->getUID() << "] element Removing ... " << elementList[iii]->getType()); - m_env.rmElementGame(elementList[iii]); - } - } - } - - if (0 != numberEnnemyKilled) { - signalKillEnemy.emit(numberEnnemyKilled); - } - } markToRedraw(); } @@ -317,17 +205,17 @@ int64_t tmp___startTime1 = ewol::getTime(); #endif float ratio = m_size.x() / m_size.y(); //EWOL_INFO("ratio : " << ratio); - mat4 tmpProjection = etk::matPerspective(m_angleView, ratio, GAME_Z_NEAR, GAME_Z_FAR); + // TODO : mat4 tmpProjection = etk::matPerspective(m_angleView, ratio, GAME_Z_NEAR, GAME_Z_FAR); #ifdef SCENE_BRUT_PERFO_TEST float tmp___localTime1 = (float)(ewol::getTime() - tmp___startTime1) / 1000.0f; EWOL_DEBUG(" SCENE111 : " << tmp___localTime1 << "ms "); int64_t tmp___startTime2 = ewol::getTime(); #endif - ewol::openGL::setCameraMatrix(m_camera->getMatrix()); + // TODO : ewol::openGL::setCameraMatrix(m_camera->getMatrix()); //mat4 tmpMat = tmpProjection * m_camera->getMatrix(); // set internal matrix system : //ewol::openGL::setMatrix(tmpMat); - ewol::openGL::setMatrix(tmpProjection); + // TODO : ewol::openGL::setMatrix(tmpProjection); #ifdef SCENE_BRUT_PERFO_TEST float tmp___localTime2 = (float)(ewol::getTime() - tmp___startTime2) / 1000.0f; EWOL_DEBUG(" SCENE222 : " << tmp___localTime2 << "ms "); @@ -348,7 +236,7 @@ float tmp___localTime4 = (float)(ewol::getTime() - tmp___startTime4) / 1000.0f; EWOL_DEBUG(" SCENE444 : " << tmp___localTime4 << "ms "); #endif } - +/* vec2 ege::widget::Scene::calculateDeltaAngle(const vec2& _posScreen) { double ratio = m_size.x() / m_size.y(); vec2 pos = vec2(m_size.x()/-2.0, m_size.y()/-2.0) + _posScreen; @@ -365,16 +253,19 @@ vec2 ege::widget::Scene::calculateDeltaAngle(const vec2& _posScreen) { return vec2(angleX, angleY); } - +*/ +/* vec3 ege::widget::Scene::convertScreenPositionInMapPosition(const vec2& _posScreen) { return m_camera->projectOnZGround(calculateDeltaAngle(_posScreen)); } - +*/ void ege::widget::Scene::onParameterChangeValue(const ewol::parameter::Ref& _paramPointer) { ewol::Widget::onParameterChangeValue(_paramPointer); + /* if (_paramPointer == m_isRunning) { // nothing to do ... } + */ } diff --git a/ege/widget/Scene.h b/ege/widget/Scene.h index 82b07ea..68105ce 100644 --- a/ege/widget/Scene.h +++ b/ege/widget/Scene.h @@ -36,95 +36,57 @@ class btVector3; namespace ege { namespace widget { class Scene : public ewol::Widget { - public: - // extern event - ewol::Signal signalPlayTimeChange; - ewol::Signal signalKillEnemy; protected: - ege::Environement m_env; + std::shared_ptr m_env; protected: /** * @brief Constructor of the widget classes * @return (no execption generated (not managed in embended platform)) */ Scene(); - void init(bool _setAutoBullet=true, bool _setAutoCamera=true); + void init(std::shared_ptr _env); public: + DECLARE_FACTORY(Scene); /** * @brief Destructor of the widget classes */ virtual ~Scene(); - void setBulletConfig(btDefaultCollisionConfiguration* _collisionConfiguration=nullptr, - btCollisionDispatcher* _dispatcher=nullptr, - btBroadphaseInterface* _broadphase=nullptr, - btConstraintSolver* _solver=nullptr, - btDynamicsWorld* _dynamicsWorld=nullptr); - void setCamera(ege::Camera* _camera=nullptr); - private: - float m_gameTime; //!< time of the game running protected: - float m_angleView; - ///this is the most important class - btDefaultCollisionConfiguration* m_collisionConfiguration; - btCollisionDispatcher* m_dispatcher; - btBroadphaseInterface* m_broadphase; - btConstraintSolver* m_solver; - btDynamicsWorld* m_dynamicsWorld; - // camera section - ege::Camera* m_camera; //!< display point of view. - // Other elements + std::string m_cameraName; public: - enum gameStatus { - gameStart, - gameStop - }; + void setCamera(const std::string& _cameraName) { + m_cameraName = _cameraName; + } protected: - ewol::parameter::List m_isRunning; //!< the display is running (not in pause) - float m_ratioTime; //!< Ratio time for the speed of the game ... // Note : This is only for temporary elements : on the display std::vector m_displayElementOrdered; - public: - /** - * @brief set the scene in pause for a while - */ - void pause(); - /** - * @brief resume the scene activity - */ - void resume(); - /** - * @brief Toggle between pause and running - */ - void pauseToggle(); protected: - bool m_debugMode; - std::shared_ptr m_debugDrawing; //!< for the debug draw elements + //bool m_debugMode; + //std::shared_ptr m_debugDrawing; //!< for the debug draw elements public: /** * @brief Toggle the debug mode == > usefull for DEBUG only ... */ + /* void debugToggle() { m_debugMode = m_debugMode?false:true; }; + */ protected: // Derived function - virtual void ScenePeriodicCall(int64_t _localTime, int32_t _deltaTime) { }; + //virtual void ScenePeriodicCall(int64_t _localTime, int32_t _deltaTime) { }; public: - vec2 calculateDeltaAngle(const vec2& _posScreen); - vec3 convertScreenPositionInMapPosition(const vec2& _posScreen); + //vec2 calculateDeltaAngle(const vec2& _posScreen); + //vec3 convertScreenPositionInMapPosition(const vec2& _posScreen); /** * @brief get the current camera reference for the scene rendering */ + /* ege::Camera& getCamera() { return *m_camera; }; - /** - * @brief set the curent Time Ratio (default 1) - */ - void setRatioTime(float _newRatio) { - m_ratioTime = _newRatio; - }; - + */ + /* void renderscene(int pass); void drawOpenGL(btScalar* m, const btCollisionShape* _shape, @@ -139,7 +101,7 @@ namespace ege { etk::Color& _tmpColor); void getElementAroundNewElement(vec3 _sourcePosition, std::vector& _resultList); - + */ protected: // Derived function virtual void onDraw(); virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer); diff --git a/sample/Accelerometer/README.md b/sample/Accelerometer/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/CameraPosition/README.md b/sample/CameraPosition/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/Collision/README.md b/sample/Collision/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/DoubleView/README.md b/sample/DoubleView/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/GameFPS/README.md b/sample/GameFPS/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/GamePad/README.md b/sample/GamePad/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/GameRacer/README.md b/sample/GameRacer/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/GameSpaceSimulation/README.md b/sample/GameSpaceSimulation/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/Light/README.md b/sample/Light/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/Material/README.md b/sample/Material/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/MeshCreator/README.md b/sample/MeshCreator/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/MeshCreator/appl/Windows.cpp b/sample/MeshCreator/appl/Windows.cpp new file mode 100644 index 0000000..ee14b9d --- /dev/null +++ b/sample/MeshCreator/appl/Windows.cpp @@ -0,0 +1,38 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include +#include +#include +#include + +#undef __class__ +#define __class__ "Windows" + +appl::Windows::Windows() { + addObjectType("appl::Windows"); +} +void appl::Windows::init() { + ewol::widget::Windows::init(); + setTitle("example ege : MeshCreator"); + + m_env = ege::Environement::create(); + // Create basic Camera + m_env->addCamera("basic", std::make_shared()); + + std::shared_ptr tmpWidget = ege::widget::Scene::create(m_env); + if (tmpWidget == nullptr) { + APPL_ERROR("Can not allocate widget ==> display might be in error"); + } else { + tmpWidget->setExpand(bvec2(true,true)); + tmpWidget->setFill(bvec2(true,true)); + tmpWidget->setCamera("basic"); + setSubWidget(tmpWidget); + } +} diff --git a/sample/MeshCreator/appl/Windows.h b/sample/MeshCreator/appl/Windows.h new file mode 100644 index 0000000..68622c4 --- /dev/null +++ b/sample/MeshCreator/appl/Windows.h @@ -0,0 +1,29 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __APPL_WINDOWS_H__ +#define __APPL_WINDOWS_H__ + +#include +#include + +namespace appl { + class Windows : public ewol::widget::Windows { + private: + std::shared_ptr m_env; + protected: + Windows(); + void init(); + public: + DECLARE_FACTORY(Windows); + virtual ~Windows() { }; + }; +}; + + +#endif \ No newline at end of file diff --git a/sample/MeshCreator/appl/debug.cpp b/sample/MeshCreator/appl/debug.cpp new file mode 100644 index 0000000..07299b6 --- /dev/null +++ b/sample/MeshCreator/appl/debug.cpp @@ -0,0 +1,15 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + + +#include + +int32_t appl::getLogId() { + static int32_t g_val = etk::log::registerInstance("GP-spaceShip"); + return g_val; +} diff --git a/sample/MeshCreator/appl/debug.h b/sample/MeshCreator/appl/debug.h new file mode 100644 index 0000000..8036fb5 --- /dev/null +++ b/sample/MeshCreator/appl/debug.h @@ -0,0 +1,52 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + + +#ifndef __APPL_DEBUG_H__ +#define __APPL_DEBUG_H__ + +#include + +namespace appl { + int32_t getLogId(); +}; +// TODO : Review this problem of multiple intanciation of "std::stringbuf sb" +#define APPL_BASE(info,data) \ + do { \ + if (info <= etk::log::getLevel(appl::getLogId())) { \ + std::stringbuf sb; \ + std::ostream tmpStream(&sb); \ + tmpStream << data; \ + etk::log::logStream(appl::getLogId(), info, __LINE__, __class__, __func__, tmpStream); \ + } \ + } while(0) + +#define APPL_CRITICAL(data) APPL_BASE(1, data) +#define APPL_ERROR(data) APPL_BASE(2, data) +#define APPL_WARNING(data) APPL_BASE(3, data) +#ifdef DEBUG + #define APPL_INFO(data) APPL_BASE(4, data) + #define APPL_DEBUG(data) APPL_BASE(5, data) + #define APPL_VERBOSE(data) APPL_BASE(6, data) + #define APPL_TODO(data) APPL_BASE(4, "TODO : " << data) +#else + #define APPL_INFO(data) do { } while(false) + #define APPL_DEBUG(data) do { } while(false) + #define APPL_VERBOSE(data) do { } while(false) + #define APPL_TODO(data) do { } while(false) +#endif + +#define APPL_ASSERT(cond,data) \ + do { \ + if (!(cond)) { \ + APPL_CRITICAL(data); \ + assert(!#cond); \ + } \ + } while (0) + +#endif diff --git a/sample/MeshCreator/appl/main.cpp b/sample/MeshCreator/appl/main.cpp new file mode 100644 index 0000000..ba5e841 --- /dev/null +++ b/sample/MeshCreator/appl/main.cpp @@ -0,0 +1,57 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + + +#include +#include +#include + +#include +#include +#include +#include +#include + + +class MainApplication : public ewol::context::Application { + public: + bool init(ewol::Context& _context, size_t _initId) { + APPL_INFO("==> Init APPL (START) [" << ewol::getBoardType() << "] (" << ewol::getCompilationMode() << ")"); + + // TODO : Remove this : Move if in the windows properties + _context.setSize(vec2(800, 600)); + + // select internal data for font ... + _context.getFontDefault().setUseExternal(true); + _context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19); + + std::shared_ptr basicWindows = appl::Windows::create(); + // create the specific windows + _context.setWindows(basicWindows); + APPL_INFO("==> Init APPL (END)"); + return true; + } + + void unInit(ewol::Context& _context) { + APPL_INFO("==> Un-Init APPL (START)"); + // nothing to do ... + APPL_INFO("==> Un-Init APPL (END)"); + } +}; + +/** + * @brief Main of the program (This can be set in every case, but it is not used in Andoid...). + * @param std IO + * @return std IO + */ +int main(int _argc, const char *_argv[]) { + // second possibility + return ewol::run(new MainApplication(), _argc, _argv); +} + + diff --git a/sample/MeshCreator/appl/main.h b/sample/MeshCreator/appl/main.h new file mode 100644 index 0000000..caa7110 --- /dev/null +++ b/sample/MeshCreator/appl/main.h @@ -0,0 +1,14 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __APPL_MAIN_H__ +#define __APPL_MAIN_H__ + + +#endif + diff --git a/sample/MeshCreator/lutin_egeMeshCreator.py b/sample/MeshCreator/lutin_egeMeshCreator.py new file mode 100644 index 0000000..6b910c7 --- /dev/null +++ b/sample/MeshCreator/lutin_egeMeshCreator.py @@ -0,0 +1,40 @@ +#!/usr/bin/python +import lutinModule as module +import lutinTools as tools +import lutinDebug as debug +import datetime + + +def get_desc(): + return "ege sample : MeshCreator" + +def create(target): + # module name is 'edn' and type binary. + myModule = module.Module(__file__, 'egeMeshCreator', 'PACKAGE') + + myModule.add_src_file([ + 'appl/debug.cpp', + 'appl/main.cpp', + 'appl/Windows.cpp' + ]) + + myModule.add_module_depend('ege') + + myModule.add_path(tools.get_current_path(__file__)) + + #myModule.copy_folder("data/*") + + # set the package properties : + myModule.pkg_set("VERSION", "0.0.0") + myModule.pkg_set("VERSION_CODE", "0") + myModule.pkg_set("COMPAGNY_TYPE", "org") + myModule.pkg_set("COMPAGNY_NAME", "ege") + myModule.pkg_set("MAINTAINER", ["noOne "]) + myModule.pkg_set("SECTION", ["Game"]) + myModule.pkg_set("PRIORITY", "optional") + myModule.pkg_set("DESCRIPTION", "ege sample : MeshCreator") + myModule.pkg_set("NAME", "egeMeshCreator") + + # add the currrent module at the + return myModule + diff --git a/sample/Particle/README.md b/sample/Particle/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/Script/README.md b/sample/Script/README.md new file mode 100644 index 0000000..e69de29 diff --git a/sample/StereoVision/README.md b/sample/StereoVision/README.md new file mode 100644 index 0000000..e69de29