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