[DEV] update new version of ewol API 0.9

This commit is contained in:
Edouard DUPIN 2014-05-30 23:20:09 +02:00
parent ba20ab59f7
commit 73455cc61b
24 changed files with 245 additions and 284 deletions

View File

@ -27,8 +27,8 @@
#undef __class__ #undef __class__
#define __class__ "CollisionShapeCreator" #define __class__ "CollisionShapeCreator"
btCollisionShape* ege::collision::createShape(const ege::resource::Mesh* _mesh) { btCollisionShape* ege::collision::createShape(const ewol::object::Shared<ege::resource::Mesh>& _mesh) {
if (NULL == _mesh) { if (nullptr == _mesh) {
return new btEmptyShape();; return new btEmptyShape();;
} }
const std::vector<ege::PhysicsShape*>& physiqueProperty = _mesh->getPhysicalProperties(); const std::vector<ege::PhysicsShape*>& physiqueProperty = _mesh->getPhysicalProperties();
@ -37,29 +37,29 @@ btCollisionShape* ege::collision::createShape(const ege::resource::Mesh* _mesh)
} }
int32_t count = 0; int32_t count = 0;
for (size_t iii=0; iii<physiqueProperty.size(); iii++) { for (size_t iii=0; iii<physiqueProperty.size(); iii++) {
if (NULL == physiqueProperty[iii]) { if (nullptr == physiqueProperty[iii]) {
continue; continue;
} }
count++; count++;
} }
btCompoundShape* outputShape = NULL; btCompoundShape* outputShape = nullptr;
if (count>1) { if (count>1) {
outputShape = new btCompoundShape(); outputShape = new btCompoundShape();
} }
for (size_t iii=0; iii<physiqueProperty.size(); iii++) { for (size_t iii=0; iii<physiqueProperty.size(); iii++) {
if (NULL == physiqueProperty[iii]) { if (nullptr == physiqueProperty[iii]) {
continue; continue;
} }
switch (physiqueProperty[iii]->getType()) { switch (physiqueProperty[iii]->getType()) {
case ege::PhysicsShape::box : { case ege::PhysicsShape::box : {
const ege::PhysicsBox* tmpElement = physiqueProperty[iii]->toBox(); const ege::PhysicsBox* tmpElement = physiqueProperty[iii]->toBox();
if (NULL == tmpElement) { if (nullptr == tmpElement) {
// ERROR ... // ERROR ...
continue; continue;
} }
btCollisionShape* tmpShape = new btBoxShape(tmpElement->getSize()); btCollisionShape* tmpShape = new btBoxShape(tmpElement->getSize());
if (NULL != tmpShape) { if (nullptr != tmpShape) {
if (outputShape == NULL) { if (outputShape == nullptr) {
return tmpShape; return tmpShape;
} else { } else {
vec4 qqq = tmpElement->getQuaternion(); vec4 qqq = tmpElement->getQuaternion();
@ -71,13 +71,13 @@ btCollisionShape* ege::collision::createShape(const ege::resource::Mesh* _mesh)
} }
case ege::PhysicsShape::cylinder : { case ege::PhysicsShape::cylinder : {
const ege::PhysicsCylinder* tmpElement = physiqueProperty[iii]->toCylinder(); const ege::PhysicsCylinder* tmpElement = physiqueProperty[iii]->toCylinder();
if (NULL == tmpElement) { if (nullptr == tmpElement) {
// ERROR ... // ERROR ...
continue; continue;
} }
btCollisionShape* tmpShape = new btCylinderShape(tmpElement->getSize()); btCollisionShape* tmpShape = new btCylinderShape(tmpElement->getSize());
if (NULL != tmpShape) { if (nullptr != tmpShape) {
if (outputShape == NULL) { if (outputShape == nullptr) {
return tmpShape; return tmpShape;
} else { } else {
vec4 qqq = tmpElement->getQuaternion(); vec4 qqq = tmpElement->getQuaternion();
@ -89,13 +89,13 @@ btCollisionShape* ege::collision::createShape(const ege::resource::Mesh* _mesh)
} }
case ege::PhysicsShape::capsule : { case ege::PhysicsShape::capsule : {
const ege::PhysicsCapsule* tmpElement = physiqueProperty[iii]->toCapsule(); const ege::PhysicsCapsule* tmpElement = physiqueProperty[iii]->toCapsule();
if (NULL == tmpElement) { if (nullptr == tmpElement) {
// ERROR ... // ERROR ...
continue; continue;
} }
btCollisionShape* tmpShape = new btCapsuleShape(tmpElement->getRadius(), tmpElement->getHeight()); btCollisionShape* tmpShape = new btCapsuleShape(tmpElement->getRadius(), tmpElement->getHeight());
if (NULL != tmpShape) { if (nullptr != tmpShape) {
if (outputShape == NULL) { if (outputShape == nullptr) {
return tmpShape; return tmpShape;
} else { } else {
vec4 qqq = tmpElement->getQuaternion(); vec4 qqq = tmpElement->getQuaternion();
@ -107,13 +107,13 @@ btCollisionShape* ege::collision::createShape(const ege::resource::Mesh* _mesh)
} }
case ege::PhysicsShape::cone : { case ege::PhysicsShape::cone : {
const ege::PhysicsCone* tmpElement = physiqueProperty[iii]->toCone(); const ege::PhysicsCone* tmpElement = physiqueProperty[iii]->toCone();
if (NULL == tmpElement) { if (nullptr == tmpElement) {
// ERROR ... // ERROR ...
continue; continue;
} }
btCollisionShape* tmpShape = new btConeShape(tmpElement->getRadius(), tmpElement->getHeight()); btCollisionShape* tmpShape = new btConeShape(tmpElement->getRadius(), tmpElement->getHeight());
if (NULL != tmpShape) { if (nullptr != tmpShape) {
if (outputShape == NULL) { if (outputShape == nullptr) {
return tmpShape; return tmpShape;
} else { } else {
vec4 qqq = tmpElement->getQuaternion(); vec4 qqq = tmpElement->getQuaternion();
@ -125,13 +125,13 @@ btCollisionShape* ege::collision::createShape(const ege::resource::Mesh* _mesh)
} }
case ege::PhysicsShape::sphere : { case ege::PhysicsShape::sphere : {
const ege::PhysicsSphere* tmpElement = physiqueProperty[iii]->toSphere(); const ege::PhysicsSphere* tmpElement = physiqueProperty[iii]->toSphere();
if (NULL == tmpElement) { if (nullptr == tmpElement) {
// ERROR ... // ERROR ...
continue; continue;
} }
btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius()); btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius());
if (NULL != tmpShape) { if (nullptr != tmpShape) {
if (outputShape == NULL) { if (outputShape == nullptr) {
return tmpShape; return tmpShape;
} else { } else {
vec4 qqq = tmpElement->getQuaternion(); vec4 qqq = tmpElement->getQuaternion();
@ -143,13 +143,13 @@ btCollisionShape* ege::collision::createShape(const ege::resource::Mesh* _mesh)
} }
case ege::PhysicsShape::convexHull : { case ege::PhysicsShape::convexHull : {
const ege::PhysicsConvexHull* tmpElement = physiqueProperty[iii]->toConvexHull(); const ege::PhysicsConvexHull* tmpElement = physiqueProperty[iii]->toConvexHull();
if (NULL == tmpElement) { if (nullptr == tmpElement) {
// ERROR ... // ERROR ...
continue; continue;
} }
btConvexHullShape* tmpShape = new btConvexHullShape(&(tmpElement->getPointList()[0].x()), tmpElement->getPointList().size()); btConvexHullShape* tmpShape = new btConvexHullShape(&(tmpElement->getPointList()[0].x()), tmpElement->getPointList().size());
if (NULL != tmpShape) { if (nullptr != tmpShape) {
if (outputShape == NULL) { if (outputShape == nullptr) {
return tmpShape; return tmpShape;
} else { } else {
vec4 qqq = tmpElement->getQuaternion(); vec4 qqq = tmpElement->getQuaternion();
@ -164,7 +164,7 @@ btCollisionShape* ege::collision::createShape(const ege::resource::Mesh* _mesh)
break; break;
} }
} }
if (NULL == outputShape) { if (nullptr == outputShape) {
return new btEmptyShape(); return new btEmptyShape();
} }
return outputShape; return outputShape;

View File

@ -16,7 +16,7 @@
namespace ege { namespace ege {
namespace collision { namespace collision {
btCollisionShape* createShape(const ege::resource::Mesh* _mesh); btCollisionShape* createShape(const ewol::object::Shared<ege::resource::Mesh>& _mesh);
}; };
}; };
#endif #endif

View File

@ -36,17 +36,17 @@ const std::string& ege::ElementGame::getType() const {
ege::ElementGame::ElementGame(ege::Environement& _env) : ege::ElementGame::ElementGame(ege::Environement& _env) :
m_env(_env), m_env(_env),
m_body(NULL), m_body(nullptr),
m_uID(0), m_uID(0),
m_mesh(NULL), m_mesh(nullptr),
m_shape(NULL), m_shape(nullptr),
m_life(100), m_life(100),
m_lifeMax(100), m_lifeMax(100),
m_group(0), m_group(0),
m_fixe(true), m_fixe(true),
m_radius(0), m_radius(0),
m_elementInPhysicsSystem(false), m_elementInPhysicsSystem(false),
m_IA(NULL) { m_IA(nullptr) {
static uint32_t unique=0; static uint32_t unique=0;
m_uID = unique; m_uID = unique;
EGE_DEBUG("Create element : uId=" << m_uID); EGE_DEBUG("Create element : uId=" << m_uID);
@ -60,61 +60,60 @@ ege::ElementGame::~ElementGame() {
// same ... // same ...
dynamicDisable(); dynamicDisable();
removeShape(); removeShape();
ege::resource::Mesh::release(m_mesh); if (nullptr != m_body) {
if (NULL != m_body) {
delete(m_body); delete(m_body);
m_body = NULL; m_body = nullptr;
} }
EGE_DEBUG("Destroy element : uId=" << m_uID); EGE_DEBUG("Destroy element : uId=" << m_uID);
} }
void ege::ElementGame::removeShape() { void ege::ElementGame::removeShape() {
// no shape // no shape
if (NULL == m_shape) { if (nullptr == m_shape) {
return; return;
} }
// need to chek if the shape is the same as the mesh shape ... // need to chek if the shape is the same as the mesh shape ...
if (m_mesh == NULL) { if (m_mesh == nullptr) {
// no mesh == > standalone shape // no mesh == > standalone shape
delete(m_shape); delete(m_shape);
m_shape=NULL; m_shape=nullptr;
return; return;
} }
if (m_shape != m_mesh->getShape()) { if (m_shape != m_mesh->getShape()) {
delete(m_shape); delete(m_shape);
m_shape=NULL; m_shape=nullptr;
return; return;
} }
// otherwise : the shape is auto remove by the resources when no more needed ... // otherwise : the shape is auto remove by the resources when no more needed ...
} }
void ege::ElementGame::FunctionFreeShape(void* _pointer) { void ege::ElementGame::FunctionFreeShape(void* _pointer) {
if (NULL == _pointer) { if (nullptr == _pointer) {
return; return;
} }
delete(static_cast<btCollisionShape*>(_pointer)); delete(static_cast<btCollisionShape*>(_pointer));
} }
bool ege::ElementGame::loadMesh(const std::string& _meshFileName) { bool ege::ElementGame::loadMesh(const std::string& _meshFileName) {
ege::resource::Mesh* tmpMesh = ege::resource::Mesh::keep(_meshFileName); ewol::object::Shared<ege::resource::Mesh> tmpMesh = ege::resource::Mesh::keep(_meshFileName);
if(NULL == tmpMesh) { if(nullptr == tmpMesh) {
EGE_ERROR("can not load the resources : " << _meshFileName); EGE_ERROR("can not load the resources : " << _meshFileName);
return false; return false;
} }
return setMesh(tmpMesh); return setMesh(tmpMesh);
} }
bool ege::ElementGame::setMesh(ege::resource::Mesh* _mesh) { bool ege::ElementGame::setMesh(const ewol::object::Shared<ege::resource::Mesh>& _mesh) {
if (NULL!=m_mesh) { if (nullptr!=m_mesh) {
removeShape(); removeShape();
ege::resource::Mesh::release(m_mesh); m_mesh.reset();
} }
m_mesh = _mesh; m_mesh = _mesh;
// auto load the shape : // auto load the shape :
if (NULL == m_mesh) { if (m_mesh == nullptr) {
return true; return true;
} }
if (NULL != m_mesh->getShape()) { if (m_mesh->getShape() != nullptr) {
m_shape = static_cast<btCollisionShape*>(m_mesh->getShape()); m_shape = static_cast<btCollisionShape*>(m_mesh->getShape());
return true; return true;
} }
@ -150,7 +149,7 @@ void ege::ElementGame::setFireOn(int32_t _groupIdSource, int32_t _type, float _p
} }
void ege::ElementGame::setPosition(const vec3& _pos) { void ege::ElementGame::setPosition(const vec3& _pos) {
if (NULL!=m_body) { if (nullptr!=m_body) {
btTransform transformation = m_body->getCenterOfMassTransform(); btTransform transformation = m_body->getCenterOfMassTransform();
transformation.setOrigin(_pos); transformation.setOrigin(_pos);
m_body->setCenterOfMassTransform(transformation); m_body->setCenterOfMassTransform(transformation);
@ -160,7 +159,7 @@ void ege::ElementGame::setPosition(const vec3& _pos) {
const vec3& ege::ElementGame::getPosition() { const vec3& ege::ElementGame::getPosition() {
// this is to prevent error like segmentation fault ... // this is to prevent error like segmentation fault ...
static vec3 emptyPosition(-1000000,-1000000,-1000000); static vec3 emptyPosition(-1000000,-1000000,-1000000);
if (NULL!=m_body) { if (nullptr!=m_body) {
return m_body->getCenterOfMassPosition(); return m_body->getCenterOfMassPosition();
} }
return emptyPosition; return emptyPosition;
@ -169,20 +168,20 @@ const vec3& ege::ElementGame::getPosition() {
const vec3& ege::ElementGame::getSpeed() { const vec3& ege::ElementGame::getSpeed() {
// this is to prevent error like segmentation fault ... // this is to prevent error like segmentation fault ...
static vec3 emptySpeed(0,0,0); static vec3 emptySpeed(0,0,0);
if (NULL!=m_body) { if (nullptr!=m_body) {
return m_body->getLinearVelocity(); return m_body->getLinearVelocity();
} }
return emptySpeed; return emptySpeed;
}; };
const float ege::ElementGame::getInvMass() { const float ege::ElementGame::getInvMass() {
if (NULL!=m_body) { if (nullptr!=m_body) {
return m_body->getInvMass(); return m_body->getInvMass();
} }
return 0.0000000001f; return 0.0000000001f;
}; };
static void drawSphere(ewol::resource::Colored3DObject* _draw, static void drawSphere(const ewol::object::Shared<ewol::resource::Colored3DObject>& _draw,
btScalar _radius, btScalar _radius,
int _lats, int _lats,
int _longs, int _longs,
@ -230,8 +229,8 @@ const float lifeHeight = 0.3f;
const float lifeWidth = 2.0f; const float lifeWidth = 2.0f;
const float lifeYPos = 1.7f; const float lifeYPos = 1.7f;
void ege::ElementGame::drawLife(ewol::resource::Colored3DObject* _draw, const ege::Camera& _camera) { void ege::ElementGame::drawLife(const ewol::object::Shared<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera) {
if (NULL == _draw) { if (nullptr == _draw) {
return; return;
} }
float ratio = getLifeRatio(); float ratio = getLifeRatio();
@ -268,11 +267,11 @@ void ege::ElementGame::drawLife(ewol::resource::Colored3DObject* _draw, const eg
} }
static void drawShape(const btCollisionShape* _shape, static void drawShape(const btCollisionShape* _shape,
ewol::resource::Colored3DObject* _draw, const ewol::object::Shared<ewol::resource::Colored3DObject>& _draw,
mat4 _transformationMatrix, mat4 _transformationMatrix,
std::vector<vec3> _tmpVertices) { std::vector<vec3> _tmpVertices) {
if( NULL == _draw if( nullptr == _draw
|| NULL == _shape) { || nullptr == _shape) {
return; return;
} }
etk::Color<float> tmpColor(1.0, 0.0, 0.0, 0.3); etk::Color<float> tmpColor(1.0, 0.0, 0.0, 0.3);
@ -338,7 +337,7 @@ static void drawShape(const btCollisionShape* _shape,
if (_shape->isConvex()) { if (_shape->isConvex()) {
EGE_DEBUG(" shape->isConvex()"); EGE_DEBUG(" shape->isConvex()");
const btConvexPolyhedron* poly = _shape->isPolyhedral() ? ((btPolyhedralConvexShape*) _shape)->getConvexPolyhedron() : 0; const btConvexPolyhedron* poly = _shape->isPolyhedral() ? ((btPolyhedralConvexShape*) _shape)->getConvexPolyhedron() : 0;
if (NULL!=poly) { if (nullptr!=poly) {
EGE_DEBUG(" have poly"); EGE_DEBUG(" have poly");
/* /*
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
@ -435,7 +434,7 @@ static void drawShape(const btCollisionShape* _shape,
} }
} }
void ege::ElementGame::drawDebug(ewol::resource::Colored3DObject* _draw, const ege::Camera& _camera) { void ege::ElementGame::drawDebug(const ewol::object::Shared<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera) {
m_debugText.clear(); m_debugText.clear();
m_debugText.setColor(0x00FF00FF); m_debugText.setColor(0x00FF00FF);
m_debugText.setPos(vec3(-20,32,0)); m_debugText.setPos(vec3(-20,32,0));
@ -465,8 +464,8 @@ void ege::ElementGame::draw(int32_t _pass) {
return; return;
} }
if (_pass == 0) { if (_pass == 0) {
if( NULL != m_body if( nullptr != m_body
&& NULL != m_mesh && nullptr != m_mesh
&& m_body->getMotionState() ) { && m_body->getMotionState() ) {
btScalar mmm[16]; btScalar mmm[16];
btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState(); btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState();
@ -483,10 +482,10 @@ void ege::ElementGame::dynamicEnable() {
if (true == m_elementInPhysicsSystem) { if (true == m_elementInPhysicsSystem) {
return; return;
} }
if(NULL!=m_body) { if(nullptr!=m_body) {
m_env.getDynamicWorld()->addRigidBody(m_body); m_env.getDynamicWorld()->addRigidBody(m_body);
} }
if(NULL!=m_IA) { if(nullptr!=m_IA) {
m_env.getDynamicWorld()->addAction(m_IA); m_env.getDynamicWorld()->addAction(m_IA);
} }
m_elementInPhysicsSystem = true; m_elementInPhysicsSystem = true;
@ -496,10 +495,10 @@ void ege::ElementGame::dynamicDisable() {
if (false == m_elementInPhysicsSystem) { if (false == m_elementInPhysicsSystem) {
return; return;
} }
if(NULL!=m_IA) { if(nullptr!=m_IA) {
m_env.getDynamicWorld()->removeAction(m_IA); m_env.getDynamicWorld()->removeAction(m_IA);
} }
if(NULL!=m_body) { if(nullptr!=m_body) {
// Unlink element from the engine // Unlink element from the engine
m_env.getDynamicWorld()->removeRigidBody(m_body); m_env.getDynamicWorld()->removeRigidBody(m_body);
m_env.getDynamicWorld()->removeCollisionObject(m_body); m_env.getDynamicWorld()->removeCollisionObject(m_body);
@ -508,12 +507,12 @@ void ege::ElementGame::dynamicDisable() {
} }
void ege::ElementGame::iaEnable() { void ege::ElementGame::iaEnable() {
if (NULL != m_IA) { if (nullptr != m_IA) {
// IA already started ... // IA already started ...
return; return;
} }
m_IA = new localIA(*this); m_IA = new localIA(*this);
if (NULL == m_IA) { if (nullptr == m_IA) {
EGE_ERROR("Can not start the IA == > allocation error"); EGE_ERROR("Can not start the IA == > allocation error");
return; return;
} }
@ -523,7 +522,7 @@ void ege::ElementGame::iaEnable() {
} }
void ege::ElementGame::iaDisable() { void ege::ElementGame::iaDisable() {
if (NULL == m_IA) { if (nullptr == m_IA) {
// IA already stopped ... // IA already stopped ...
return; return;
} }
@ -532,7 +531,7 @@ void ege::ElementGame::iaDisable() {
} }
// remove IA : // remove IA :
delete(m_IA); delete(m_IA);
m_IA = NULL; m_IA = nullptr;
} }

View File

@ -75,7 +75,7 @@ namespace ege {
return m_uID; return m_uID;
}; };
private: private:
ege::resource::Mesh* m_mesh; //!< Mesh of the Element (can be NULL) ewol::object::Shared<ege::resource::Mesh> m_mesh; //!< Mesh of the Element (can be nullptr)
btCollisionShape* m_shape; //!< shape of the element (set a copy here to have the debug display of it) btCollisionShape* m_shape; //!< shape of the element (set a copy here to have the debug display of it)
public: public:
/** /**
@ -87,11 +87,11 @@ namespace ege {
bool loadMesh(const std::string& _meshFileName); bool loadMesh(const std::string& _meshFileName);
/** /**
* @brief set the the Mesh properties. * @brief set the the Mesh properties.
* @param[in] _mesh The mesh pointer. (NULL to force the mesh remove ...) * @param[in] _mesh The mesh pointer. (nullptr to force the mesh remove ...)
* @note : this remove the shape and the mesh properties. * @note : this remove the shape and the mesh properties.
* @return true if no error occured * @return true if no error occured
*/ */
bool setMesh(ege::resource::Mesh* _mesh); bool setMesh(const ewol::object::Shared<ege::resource::Mesh>& _mesh);
/** /**
* @brief set the shape properties. * @brief set the shape properties.
* @param[in] _shape The shape pointer. * @param[in] _shape The shape pointer.
@ -103,7 +103,7 @@ namespace ege {
* @brief get a pointer on the Mesh file. * @brief get a pointer on the Mesh file.
* @return the mesh pointer. * @return the mesh pointer.
*/ */
inline ege::resource::Mesh* getMesh() { inline const ewol::object::Shared<ege::resource::Mesh>& getMesh() {
return m_mesh; return m_mesh;
}; };
/** /**
@ -186,7 +186,7 @@ namespace ege {
/** /**
* @brief draw the current life of the element * @brief draw the current life of the element
*/ */
virtual void drawLife(ewol::resource::Colored3DObject* _draw, const ege::Camera& _camera); virtual void drawLife(const ewol::object::Shared<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera);
protected: protected:
// For debug only ... // For debug only ...
@ -196,7 +196,7 @@ namespace ege {
* @brief Debug display of the current element * @brief Debug display of the current element
* @param[in,out] draw Basic system to draw the debug shape and informations * @param[in,out] draw Basic system to draw the debug shape and informations
*/ */
virtual void drawDebug(ewol::resource::Colored3DObject* _draw, const ege::Camera& _camera); virtual void drawDebug(const ewol::object::Shared<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera);
/** /**
* @brief get the theoric position. Sometimes, the element has move due to an explosion or something else, then its real position in not the one that woult it be at the end ... * @brief get the theoric position. Sometimes, the element has move due to an explosion or something else, then its real position in not the one that woult it be at the end ...

View File

@ -16,14 +16,14 @@
ege::ElementGame* ege::Environement::getElementNearest(ege::ElementGame* _sourceRequest, float& _distance) { ege::ElementGame* ege::Environement::getElementNearest(ege::ElementGame* _sourceRequest, float& _distance) {
if (NULL == _sourceRequest) { if (nullptr == _sourceRequest) {
return NULL; return nullptr;
} }
vec3 sourcePosition = _sourceRequest->getPosition(); vec3 sourcePosition = _sourceRequest->getPosition();
ege::ElementGame* result = NULL; ege::ElementGame* result = nullptr;
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElementGame.size() ; iii++) {
// chack NULL pointer // chack nullptr pointer
if (NULL == m_listElementGame[iii]) { if (nullptr == m_listElementGame[iii]) {
continue; continue;
} }
if (m_listElementGame[iii]->getGroup() <= 0) { if (m_listElementGame[iii]->getGroup() <= 0) {
@ -52,11 +52,11 @@ void ege::Environement::getElementNearest(const vec3& _sourcePosition,
_resultList.clear(); _resultList.clear();
ege::Environement::ResultNearestElement result; ege::Environement::ResultNearestElement result;
result.dist = 99999999999.0f; result.dist = 99999999999.0f;
result.element = NULL; result.element = nullptr;
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElementGame.size() ; iii++) {
// chack NULL pointer // chack nullptr pointer
result.element = m_listElementGame[iii]; result.element = m_listElementGame[iii];
if (NULL == result.element) { if (nullptr == result.element) {
continue; continue;
} }
// check distance ... // check distance ...
@ -78,11 +78,11 @@ void ege::Environement::getElementNearestFixed(const vec3& _sourcePosition,
_resultList.clear(); _resultList.clear();
ege::Environement::ResultNearestElement result; ege::Environement::ResultNearestElement result;
result.dist = 99999999999.0f; result.dist = 99999999999.0f;
result.element = NULL; result.element = nullptr;
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElementGame.size() ; iii++) {
// chack NULL pointer // chack nullptr pointer
result.element = m_listElementGame[iii]; result.element = m_listElementGame[iii];
if (NULL == result.element) { if (nullptr == result.element) {
continue; continue;
} }
if (false == result.element->isFixed()) { if (false == result.element->isFixed()) {
@ -116,7 +116,7 @@ static etk::Hash<ege::createElement_tf>& getHachTableCreating() {
} }
void ege::Environement::addCreator(const std::string& _type, ege::createElement_tf _creator) { void ege::Environement::addCreator(const std::string& _type, ege::createElement_tf _creator) {
if (NULL == _creator) { if (nullptr == _creator) {
EGE_ERROR("Try to add an empty CREATOR ..."); EGE_ERROR("Try to add an empty CREATOR ...");
return; return;
} }
@ -128,23 +128,23 @@ void ege::Environement::addCreator(const std::string& _type, ege::createElement_
ege::ElementGame* ege::Environement::createElement(const std::string& _type, bool _autoAddElement, enum ege::property _property, void* _value) { ege::ElementGame* ege::Environement::createElement(const std::string& _type, bool _autoAddElement, enum ege::property _property, void* _value) {
if (false == getHachTableCreating().exist(_type)) { if (false == getHachTableCreating().exist(_type)) {
EGE_ERROR("Request creating of an type that is not known '" << _type << "'"); EGE_ERROR("Request creating of an type that is not known '" << _type << "'");
return NULL; return nullptr;
} }
ege::createElement_tf creatorPointer = getHachTableCreating()[_type]; ege::createElement_tf creatorPointer = getHachTableCreating()[_type];
if (NULL == creatorPointer) { if (nullptr == creatorPointer) {
EGE_ERROR("NULL pointer creator == > internal error... '" << _type << "'"); EGE_ERROR("nullptr pointer creator == > internal error... '" << _type << "'");
return NULL; return nullptr;
} }
ege::ElementGame* tmpElement = creatorPointer(*this); ege::ElementGame* tmpElement = creatorPointer(*this);
if (NULL == tmpElement) { if (nullptr == tmpElement) {
EGE_ERROR("allocation error '" << _type << "'"); EGE_ERROR("allocation error '" << _type << "'");
return NULL; return nullptr;
} }
if (false == tmpElement->init(_property, _value)) { if (false == tmpElement->init(_property, _value)) {
EGE_ERROR("Init error ... '" << _type << "'"); EGE_ERROR("Init error ... '" << _type << "'");
// remove created element ... // remove created element ...
delete(tmpElement); delete(tmpElement);
return NULL; return nullptr;
} }
if (_autoAddElement == true) { if (_autoAddElement == true) {
addElementGame(tmpElement); addElementGame(tmpElement);
@ -167,11 +167,11 @@ ege::ElementGame* ege::Environement::createElement(const std::string& _type, exm
void ege::Environement::addElementGame(ege::ElementGame* _newElement) { void ege::Environement::addElementGame(ege::ElementGame* _newElement) {
// prevent memory allocation and un allocation ... // prevent memory allocation and un allocation ...
if (NULL == _newElement) { if (nullptr == _newElement) {
return; return;
} }
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElementGame.size() ; iii++) {
if (NULL == m_listElementGame[iii]) { if (nullptr == m_listElementGame[iii]) {
m_listElementGame[iii] = _newElement; m_listElementGame[iii] = _newElement;
m_listElementGame[iii]->dynamicEnable(); m_listElementGame[iii]->dynamicEnable();
return; return;
@ -182,12 +182,12 @@ void ege::Environement::addElementGame(ege::ElementGame* _newElement) {
} }
void ege::Environement::rmElementGame(ege::ElementGame* _removeElement) { void ege::Environement::rmElementGame(ege::ElementGame* _removeElement) {
if (NULL == _removeElement) { if (nullptr == _removeElement) {
return; return;
} }
// inform the element that an element has been removed == > this permit to keep pointer on elements ... // inform the element that an element has been removed == > this permit to keep pointer on elements ...
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElementGame.size() ; iii++) {
if (NULL != m_listElementGame[iii]) { if (nullptr != m_listElementGame[iii]) {
m_listElementGame[iii]->elementIsRemoved(_removeElement); m_listElementGame[iii]->elementIsRemoved(_removeElement);
} }
} }
@ -198,7 +198,7 @@ void ege::Environement::rmElementGame(ege::ElementGame* _removeElement) {
m_listElementGame[iii]->dynamicDisable(); m_listElementGame[iii]->dynamicDisable();
m_listElementGame[iii]->unInit(); m_listElementGame[iii]->unInit();
delete(m_listElementGame[iii]); delete(m_listElementGame[iii]);
m_listElementGame[iii] = NULL; m_listElementGame[iii] = nullptr;
} }
} }
} }
@ -212,11 +212,11 @@ void ege::Environement::getOrderedElementForDisplay(std::vector<ege::Environemen
// basic element result // basic element result
ege::Environement::ResultNearestElement result; ege::Environement::ResultNearestElement result;
result.dist = 99999999999.0f; result.dist = 99999999999.0f;
result.element = NULL; result.element = nullptr;
// for all element in the game we chek if it is needed to display it ... // for all element in the game we chek if it is needed to display it ...
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElementGame.size() ; iii++) {
// chack NULL pointer // chack nullptr pointer
if (NULL == m_listElementGame[iii]) { if (nullptr == m_listElementGame[iii]) {
// no pointer null are set in the output list ... // no pointer null are set in the output list ...
continue; continue;
} }
@ -254,7 +254,7 @@ void ege::Environement::getOrderedElementForDisplay(std::vector<ege::Environemen
void ege::Environement::generateInteraction(ege::ElementInteraction& _event) { void ege::Environement::generateInteraction(ege::ElementInteraction& _event) {
// inform the element that an element has been removed == > this permit to keep pointer on elements ... // inform the element that an element has been removed == > this permit to keep pointer on elements ...
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElementGame.size() ; iii++) {
if (NULL == m_listElementGame[iii]) { if (nullptr == m_listElementGame[iii]) {
continue; continue;
} }
_event.applyEvent(*m_listElementGame[iii]); _event.applyEvent(*m_listElementGame[iii]);
@ -271,7 +271,7 @@ void ege::Environement::generateInteraction(ege::ElementInteraction& _event) {
} }
ege::Environement::Environement() : ege::Environement::Environement() :
m_dynamicsWorld(NULL), m_dynamicsWorld(nullptr),
m_particuleEngine(*this) { m_particuleEngine(*this) {
// nothing to do ... // nothing to do ...
} }

View File

@ -91,10 +91,10 @@ namespace ege {
* @param[in] _type Type of the element that might be created. * @param[in] _type Type of the element that might be created.
* @param[in] _description String that describe the content of the element properties. * @param[in] _description String that describe the content of the element properties.
* @param[in] _autoAddElement this permit to add the element if it is created == > no more action ... * @param[in] _autoAddElement this permit to add the element if it is created == > no more action ...
* @return NULL if an error occured OR the pointer on the element and it is already added on the system. * @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... * @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=NULL); 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, 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, ejson::Value* _value, bool _autoAddElement=true);
ege::ElementGame* createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement=true); ege::ElementGame* createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement=true);
@ -129,7 +129,7 @@ namespace ege {
* @brief get the nearest Element * @brief get the nearest Element
* @param[in] _sourceRequest Pointer on the element that request this. * @param[in] _sourceRequest Pointer on the element that request this.
* @param[in] _distance Maximum distance search == > return the element distance * @param[in] _distance Maximum distance search == > return the element distance
* @return Pointer on the neares element OR NULL * @return Pointer on the neares element OR nullptr
*/ */
ege::ElementGame* getElementNearest(ege::ElementGame* _sourceRequest, float& _distance); ege::ElementGame* getElementNearest(ege::ElementGame* _sourceRequest, float& _distance);

View File

@ -27,8 +27,8 @@ ege::Light::~Light() {
} }
void ege::Light::link(ewol::resource::Program* _prog, const std::string& _baseName) { void ege::Light::link(const ewol::object::Shared<ewol::resource::Program>& _prog, const std::string& _baseName) {
if (NULL == _prog) { if (nullptr == _prog) {
return; return;
} }
m_GL_direction = _prog->getUniform(_baseName+".direction"); m_GL_direction = _prog->getUniform(_baseName+".direction");
@ -38,7 +38,7 @@ void ege::Light::link(ewol::resource::Program* _prog, const std::string& _baseNa
m_GL_specularColor = _prog->getUniform(_baseName+".specularColor"); m_GL_specularColor = _prog->getUniform(_baseName+".specularColor");
} }
void ege::Light::draw(ewol::resource::Program* _prog) { void ege::Light::draw(const ewol::object::Shared<ewol::resource::Program>& _prog) {
_prog->uniform3(m_GL_direction, m_direction); _prog->uniform3(m_GL_direction, m_direction);
_prog->uniform3(m_GL_halfplane, m_halfplane); _prog->uniform3(m_GL_halfplane, m_halfplane);
_prog->uniform4(m_GL_ambientColor, m_ambientColor); _prog->uniform4(m_GL_ambientColor, m_ambientColor);

View File

@ -33,8 +33,8 @@ namespace ege {
public: public:
Light(); Light();
~Light(); ~Light();
void link(ewol::resource::Program* _prog, const std::string& _baseName); void link(const ewol::object::Shared<ewol::resource::Program>& _prog, const std::string& _baseName);
void draw(ewol::resource::Program* _prog); void draw(const ewol::object::Shared<ewol::resource::Program>& _prog);
void setDirection(const vec3& val) { void setDirection(const vec3& val) {
m_direction = val; m_direction = val;
} }

View File

@ -20,8 +20,8 @@ ege::MaterialGlId::MaterialGlId() :
} }
void ege::MaterialGlId::link(ewol::resource::Program* _prog, const std::string& _baseName) { void ege::MaterialGlId::link(const ewol::object::Shared<ewol::resource::Program>& _prog, const std::string& _baseName) {
if (NULL == _prog) { if (nullptr == _prog) {
return; return;
} }
m_GL_ambientFactor = _prog->getUniform(_baseName+".ambientFactor"); m_GL_ambientFactor = _prog->getUniform(_baseName+".ambientFactor");
@ -36,21 +36,19 @@ ege::Material::Material() :
m_diffuseFactor(0,0,0,1), m_diffuseFactor(0,0,0,1),
m_specularFactor(0,0,0,1), m_specularFactor(0,0,0,1),
m_shininess(1), m_shininess(1),
m_texture0(NULL) { m_texture0(nullptr) {
// nothing to do else ... // nothing to do else ...
} }
ege::Material::~Material() { ege::Material::~Material() {
if(NULL!=m_texture0) {
ewol::resource::TextureFile::release(m_texture0);
}
} }
void ege::Material::draw(ewol::resource::Program* _prog, const MaterialGlId& _glID) { void ege::Material::draw(const ewol::object::Shared<ewol::resource::Program>& _prog, const MaterialGlId& _glID) {
_prog->uniform4(_glID.m_GL_ambientFactor, m_ambientFactor); _prog->uniform4(_glID.m_GL_ambientFactor, m_ambientFactor);
_prog->uniform4(_glID.m_GL_diffuseFactor, m_diffuseFactor); _prog->uniform4(_glID.m_GL_diffuseFactor, m_diffuseFactor);
_prog->uniform4(_glID.m_GL_specularFactor, m_specularFactor); _prog->uniform4(_glID.m_GL_specularFactor, m_specularFactor);
_prog->uniform1f(_glID.m_GL_shininess, m_shininess); _prog->uniform1f(_glID.m_GL_shininess, m_shininess);
if (NULL != m_texture0) { if (nullptr != m_texture0) {
_prog->setTexture0(_glID.m_GL_texture0, m_texture0->getId()); _prog->setTexture0(_glID.m_GL_texture0, m_texture0->getId());
} }
} }
@ -58,18 +56,14 @@ void ege::Material::draw(ewol::resource::Program* _prog, const MaterialGlId& _gl
void ege::Material::setTexture0(const std::string& _filename) { void ege::Material::setTexture0(const std::string& _filename) {
ivec2 tmpSize(256, 256); ivec2 tmpSize(256, 256);
// prevent overloard error : // prevent overloard error :
ewol::resource::TextureFile* tmpCopy = m_texture0; ewol::object::Shared<ewol::resource::TextureFile> tmpCopy = m_texture0;
m_texture0 = ewol::resource::TextureFile::keep(_filename, tmpSize); m_texture0 = ewol::resource::TextureFile::keep(_filename, tmpSize);
if (NULL == m_texture0 ) { if (m_texture0 == nullptr) {
EGE_ERROR("Can not load specific texture : " << _filename); EGE_ERROR("Can not load specific texture : " << _filename);
// retreave previous texture: // retreave previous texture:
m_texture0 = tmpCopy; m_texture0 = tmpCopy;
return; return;
} }
if (NULL != tmpCopy) {
// really release previous texture. In case of same texture loading, then we did not have reload it .. just increase and decrease index...
ewol::resource::TextureFile::release(tmpCopy);
}
} }

View File

@ -28,7 +28,7 @@ namespace ege {
int32_t m_GL_shininess; int32_t m_GL_shininess;
int32_t m_GL_texture0; int32_t m_GL_texture0;
MaterialGlId(); MaterialGlId();
void link(ewol::resource::Program* _prog, const std::string& _baseName); void link(const ewol::object::Shared<ewol::resource::Program>& _prog, const std::string& _baseName);
}; };
class Material { class Material {
private: private:
@ -37,13 +37,13 @@ namespace ege {
vec4 m_diffuseFactor; vec4 m_diffuseFactor;
vec4 m_specularFactor; vec4 m_specularFactor;
float m_shininess; float m_shininess;
ewol::resource::TextureFile* m_texture0; ewol::object::Shared<ewol::resource::TextureFile> m_texture0;
public: public:
std::vector<uint32_t> m_listIndexFaces; std::vector<uint32_t> m_listIndexFaces;
public: public:
Material(); Material();
~Material(); ~Material();
void draw(ewol::resource::Program* _prog, const ege::MaterialGlId& _glID); void draw(const ewol::object::Shared<ewol::resource::Program>& _prog, const ege::MaterialGlId& _glID);
void setAmbientFactor(const vec4& _val) { void setAmbientFactor(const vec4& _val) {
m_ambientFactor = _val; m_ambientFactor = _val;
} }
@ -59,21 +59,21 @@ namespace ege {
void setTexture0(const std::string& _filename); void setTexture0(const std::string& _filename);
void setImageSize(const ivec2& _newSize) { void setImageSize(const ivec2& _newSize) {
if (m_texture0 == NULL){ if (m_texture0 == nullptr){
return; return;
} }
m_texture0->setImageSize(_newSize); m_texture0->setImageSize(_newSize);
}; };
// get the reference on this image to draw nomething on it ... // get the reference on this image to draw nomething on it ...
egami::Image* get() { egami::Image* get() {
if (m_texture0 == NULL){ if (m_texture0 == nullptr){
return NULL; return nullptr;
} }
return &m_texture0->get(); return &m_texture0->get();
}; };
// flush the data to send it at the openGl system // flush the data to send it at the openGl system
void flush() { void flush() {
if (m_texture0 == NULL){ if (m_texture0 == nullptr){
return; return;
} }
m_texture0->flush(); m_texture0->flush();

View File

@ -32,9 +32,9 @@ namespace ege {
/** /**
* @brief Constructor. * @brief Constructor.
* @param[in] _particuleEngine reference on the particule engine ... * @param[in] _particuleEngine reference on the particule engine ...
* @param[in] _particuleType Type of the particule (set NULL if you did not want to use the respowner ...) * @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 = NULL); Particule(ege::ParticuleEngine& _particuleEngine, const char* _particuleType = nullptr);
/** /**
* @brief Destructor. * @brief Destructor.
*/ */

View File

@ -22,12 +22,12 @@ ege::ParticuleEngine::~ParticuleEngine() {
} }
void ege::ParticuleEngine::add(Particule* _particule) { void ege::ParticuleEngine::add(Particule* _particule) {
if (_particule == NULL) { if (_particule == nullptr) {
EGE_ERROR("Try to add particule NULL"); EGE_ERROR("Try to add particule nullptr");
return; return;
} }
for (size_t iii=0; iii<m_particuleList.size(); ++iii) { for (size_t iii=0; iii<m_particuleList.size(); ++iii) {
if (m_particuleList[iii] != NULL) { if (m_particuleList[iii] != nullptr) {
continue; continue;
} }
m_particuleList[iii] = _particule; m_particuleList[iii] = _particule;
@ -38,11 +38,11 @@ void ege::ParticuleEngine::add(Particule* _particule) {
} }
void ege::ParticuleEngine::addRemoved(Particule* _particule) { void ege::ParticuleEngine::addRemoved(Particule* _particule) {
if (_particule == NULL) { if (_particule == nullptr) {
return; return;
} }
for (size_t iii=0; iii<m_particuleRemoved.size(); ++iii) { for (size_t iii=0; iii<m_particuleRemoved.size(); ++iii) {
if (m_particuleRemoved[iii] != NULL) { if (m_particuleRemoved[iii] != nullptr) {
continue; continue;
} }
m_particuleRemoved[iii] = _particule; m_particuleRemoved[iii] = _particule;
@ -53,22 +53,22 @@ void ege::ParticuleEngine::addRemoved(Particule* _particule) {
} }
ege::Particule* ege::ParticuleEngine::respown(const char* _particuleType) { ege::Particule* ege::ParticuleEngine::respown(const char* _particuleType) {
if (_particuleType == NULL) { if (_particuleType == nullptr) {
return NULL; return nullptr;
} }
for (size_t iii=0; iii<m_particuleRemoved.size(); ++iii) { for (size_t iii=0; iii<m_particuleRemoved.size(); ++iii) {
if (m_particuleRemoved[iii] == NULL) { if (m_particuleRemoved[iii] == nullptr) {
continue; continue;
} }
if (m_particuleRemoved[iii]->getParticuleType() == _particuleType) { if (m_particuleRemoved[iii]->getParticuleType() == _particuleType) {
add(m_particuleRemoved[iii]); add(m_particuleRemoved[iii]);
ege::Particule* tmpParticule = m_particuleRemoved[iii]; ege::Particule* tmpParticule = m_particuleRemoved[iii];
m_particuleRemoved[iii]=NULL; m_particuleRemoved[iii]=nullptr;
tmpParticule->init(); tmpParticule->init();
return tmpParticule; return tmpParticule;
} }
} }
return NULL; return nullptr;
} }
void ege::ParticuleEngine::update(float _deltaTime) { void ege::ParticuleEngine::update(float _deltaTime) {
@ -76,31 +76,31 @@ void ege::ParticuleEngine::update(float _deltaTime) {
_deltaTime = (1.0f/60.0f); _deltaTime = (1.0f/60.0f);
} }
for (size_t iii=0; iii<m_particuleList.size(); ++iii) { for (size_t iii=0; iii<m_particuleList.size(); ++iii) {
if (m_particuleList[iii] == NULL) { if (m_particuleList[iii] == nullptr) {
continue; continue;
} }
m_particuleList[iii]->update(_deltaTime); m_particuleList[iii]->update(_deltaTime);
} }
// check removing elements // check removing elements
for (size_t iii=0; iii<m_particuleList.size(); ++iii) { for (size_t iii=0; iii<m_particuleList.size(); ++iii) {
if (m_particuleList[iii] == NULL) { if (m_particuleList[iii] == nullptr) {
continue; continue;
} }
if (m_particuleList[iii]->needRemove()) { if (m_particuleList[iii]->needRemove()) {
m_particuleList[iii]->onEnd(); m_particuleList[iii]->onEnd();
if (m_particuleList[iii]->getParticuleType() == NULL) { if (m_particuleList[iii]->getParticuleType() == nullptr) {
// Real remove particule ... // Real remove particule ...
delete (m_particuleList[iii]); delete (m_particuleList[iii]);
} else { } else {
addRemoved(m_particuleList[iii]); addRemoved(m_particuleList[iii]);
} }
m_particuleList[iii] = NULL; m_particuleList[iii] = nullptr;
} }
} }
/* /*
int32_t nbParticule = 0; int32_t nbParticule = 0;
for (int32_t iii=0; iii<m_particuleList.size(); ++iii) { for (int32_t iii=0; iii<m_particuleList.size(); ++iii) {
if (m_particuleList[iii] == NULL) { if (m_particuleList[iii] == nullptr) {
continue; continue;
} }
nbParticule++; nbParticule++;
@ -111,7 +111,7 @@ void ege::ParticuleEngine::update(float _deltaTime) {
void ege::ParticuleEngine::draw(const ege::Camera& _camera) { void ege::ParticuleEngine::draw(const ege::Camera& _camera) {
for (size_t iii=0; iii<m_particuleList.size(); ++iii) { for (size_t iii=0; iii<m_particuleList.size(); ++iii) {
if (m_particuleList[iii] == NULL) { if (m_particuleList[iii] == nullptr) {
continue; continue;
} }
m_particuleList[iii]->draw(_camera); m_particuleList[iii]->draw(_camera);
@ -121,20 +121,20 @@ void ege::ParticuleEngine::draw(const ege::Camera& _camera) {
void ege::ParticuleEngine::clear() { void ege::ParticuleEngine::clear() {
// clear element not removed // clear element not removed
for (size_t iii=0; iii<m_particuleList.size(); ++iii) { for (size_t iii=0; iii<m_particuleList.size(); ++iii) {
if (m_particuleList[iii] == NULL) { if (m_particuleList[iii] == nullptr) {
continue; continue;
} }
delete m_particuleList[iii]; delete m_particuleList[iii];
m_particuleList[iii] = NULL; m_particuleList[iii] = nullptr;
} }
m_particuleList.clear(); m_particuleList.clear();
// clear element that are auto-removed // clear element that are auto-removed
for (size_t iii=0; iii<m_particuleRemoved.size(); ++iii) { for (size_t iii=0; iii<m_particuleRemoved.size(); ++iii) {
if (m_particuleRemoved[iii] == NULL) { if (m_particuleRemoved[iii] == nullptr) {
continue; continue;
} }
delete m_particuleRemoved[iii]; delete m_particuleRemoved[iii];
m_particuleRemoved[iii] = NULL; m_particuleRemoved[iii] = nullptr;
} }
m_particuleRemoved.clear(); m_particuleRemoved.clear();
} }

View File

@ -59,9 +59,9 @@ namespace ege {
/** /**
* @brief get a particue with his type, we get particule that has been already removed, otherwise, you will create new * @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. * @param[in] _particuleType Particule type, this chek only the pointer not the data.
* @return NULL, the particule has not been removed from the created pool * @return nullptr, the particule has not been removed from the created pool
* @return The pointer on the requested element (an init has been done). * @return The pointer on the requested element (an init has been done).
* @note If you did not want to use respawn set type at NULL. * @note If you did not want to use respawn set type at nullptr.
*/ */
Particule* respown(const char* _particuleType); Particule* respown(const char* _particuleType);

View File

@ -19,7 +19,7 @@ bool ege::PhysicsConvexHull::parse(const char* _line) {
char* base = (char*)(&_line[8]); char* base = (char*)(&_line[8]);
char* tmp= strchr(base, '|'); char* tmp= strchr(base, '|');
vec3 pos(0,0,0); vec3 pos(0,0,0);
while (tmp != NULL) { while (tmp != nullptr) {
*tmp = '\0'; *tmp = '\0';
sscanf(base, "%f %f %f", &pos.m_floats[0], &pos.m_floats[1], &pos.m_floats[2] ); sscanf(base, "%f %f %f", &pos.m_floats[0], &pos.m_floats[1], &pos.m_floats[2] );
m_points.push_back(pos); m_points.push_back(pos);

View File

@ -16,7 +16,7 @@
ege::PhysicsShape* ege::PhysicsShape::create(const std::string& _name) { ege::PhysicsShape* ege::PhysicsShape::create(const std::string& _name) {
ege::PhysicsShape* tmpp = NULL; ege::PhysicsShape* tmpp = nullptr;
std::string name = std::tolower(_name); std::string name = std::tolower(_name);
if (name == "box") { if (name == "box") {
tmpp = new ege::PhysicsBox(); tmpp = new ege::PhysicsBox();
@ -32,9 +32,9 @@ ege::PhysicsShape* ege::PhysicsShape::create(const std::string& _name) {
tmpp = new ege::PhysicsConvexHull(); tmpp = new ege::PhysicsConvexHull();
} else { } else {
EGE_ERROR("Create an unknow element : '" << _name << "' availlable : [BOX,SPHERE,CONE,CYLINDER,CAPSULE,CONVEXHULL]"); EGE_ERROR("Create an unknow element : '" << _name << "' availlable : [BOX,SPHERE,CONE,CYLINDER,CAPSULE,CONVEXHULL]");
return NULL; return nullptr;
} }
if (tmpp == NULL) { if (tmpp == nullptr) {
EGE_ERROR("Allocation error for physical element : '" << _name << "'"); EGE_ERROR("Allocation error for physical element : '" << _name << "'");
} }
return tmpp; return tmpp;

View File

@ -89,45 +89,45 @@ namespace ege {
}; };
virtual const ege::PhysicsBox* toBox() const { virtual const ege::PhysicsBox* toBox() const {
return NULL; return nullptr;
}; };
virtual ege::PhysicsBox* toBox() { virtual ege::PhysicsBox* toBox() {
return NULL; return nullptr;
}; };
virtual const ege::PhysicsCylinder* toCylinder() const { virtual const ege::PhysicsCylinder* toCylinder() const {
return NULL; return nullptr;
}; };
virtual ege::PhysicsCylinder* toCylinder() { virtual ege::PhysicsCylinder* toCylinder() {
return NULL; return nullptr;
}; };
virtual const ege::PhysicsCapsule* toCapsule() const { virtual const ege::PhysicsCapsule* toCapsule() const {
return NULL; return nullptr;
}; };
virtual ege::PhysicsCapsule* toCapsule() { virtual ege::PhysicsCapsule* toCapsule() {
return NULL; return nullptr;
}; };
virtual const ege::PhysicsCone* toCone() const { virtual const ege::PhysicsCone* toCone() const {
return NULL; return nullptr;
}; };
virtual ege::PhysicsCone* toCone() { virtual ege::PhysicsCone* toCone() {
return NULL; return nullptr;
}; };
virtual const ege::PhysicsConvexHull* toConvexHull() const { virtual const ege::PhysicsConvexHull* toConvexHull() const {
return NULL; return nullptr;
}; };
virtual ege::PhysicsConvexHull* toConvexHull() { virtual ege::PhysicsConvexHull* toConvexHull() {
return NULL; return nullptr;
}; };
virtual const ege::PhysicsSphere* toSphere() const { virtual const ege::PhysicsSphere* toSphere() const {
return NULL; return nullptr;
}; };
virtual ege::PhysicsSphere* toSphere() { virtual ege::PhysicsSphere* toSphere() {
return NULL; return nullptr;
}; };
}; };
}; };

View File

@ -18,8 +18,8 @@ ege::resource::Mesh::Mesh(const std::string& _fileName, const std::string& _shad
ewol::Resource(_fileName), ewol::Resource(_fileName),
m_normalMode(normalModeNone), m_normalMode(normalModeNone),
m_checkNormal(false), m_checkNormal(false),
m_pointerShape(NULL), m_pointerShape(nullptr),
m_functionFreeShape(NULL) { m_functionFreeShape(nullptr) {
addObjectType("ewol::resource::Mesh"); addObjectType("ewol::resource::Mesh");
EGE_VERBOSE("Load a new mesh : '" << _fileName << "'"); EGE_VERBOSE("Load a new mesh : '" << _fileName << "'");
// get the shader resource : // get the shader resource :
@ -33,7 +33,7 @@ ege::resource::Mesh::Mesh(const std::string& _fileName, const std::string& _shad
//EGE_DEBUG(m_name << " " << m_light); //EGE_DEBUG(m_name << " " << m_light);
m_GLprogram = ewol::resource::Program::keep(_shaderName); m_GLprogram = ewol::resource::Program::keep(_shaderName);
if (NULL != m_GLprogram ) { if (m_GLprogram != nullptr) {
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d"); m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
m_GLtexture = m_GLprogram->getAttribute("EW_texture2d"); m_GLtexture = m_GLprogram->getAttribute("EW_texture2d");
m_GLNormal = m_GLprogram->getAttribute("EW_normal"); m_GLNormal = m_GLprogram->getAttribute("EW_normal");
@ -67,11 +67,9 @@ ege::resource::Mesh::Mesh(const std::string& _fileName, const std::string& _shad
ege::resource::Mesh::~Mesh() { ege::resource::Mesh::~Mesh() {
// remove dynamics dependencies : // remove dynamics dependencies :
ewol::resource::Program::release(m_GLprogram); if (m_functionFreeShape!=nullptr) {
ewol::resource::VirtualBufferObject::release(m_verticesVBO);
if (m_functionFreeShape!=NULL) {
m_functionFreeShape(m_pointerShape); m_functionFreeShape(m_pointerShape);
m_pointerShape = NULL; m_pointerShape = nullptr;
} }
} }
@ -80,7 +78,7 @@ ege::resource::Mesh::~Mesh() {
void ege::resource::Mesh::draw(mat4& _positionMatrix, void ege::resource::Mesh::draw(mat4& _positionMatrix,
bool _enableDepthTest, bool _enableDepthTest,
bool _enableDepthUpdate) { bool _enableDepthUpdate) {
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EGE_ERROR("No shader ..."); EGE_ERROR("No shader ...");
return; return;
} }
@ -394,7 +392,7 @@ bool ege::resource::Mesh::loadOBJ(const std::string& _fileName) {
char inputDataLine[2048]; char inputDataLine[2048];
int32_t lineID = 0; int32_t lineID = 0;
while (NULL != fileName.fileGets(inputDataLine, 2048) ) while (nullptr != fileName.fileGets(inputDataLine, 2048) )
{ {
lineID++; lineID++;
if (inputDataLine[0] == 'v') { if (inputDataLine[0] == 'v') {
@ -552,7 +550,7 @@ char* loadNextData(char* _elementLine,
/* /*
if (m_zipReadingOffset >= m_zipContent->size()) { if (m_zipReadingOffset >= m_zipContent->size()) {
element[0] = '\0'; element[0] = '\0';
return NULL; return nullptr;
} }
*/ */
char current = _file.fileGet(); char current = _file.fileGet();
@ -585,12 +583,12 @@ char* loadNextData(char* _elementLine,
current = _file.fileGet(); current = _file.fileGet();
} }
if (outSize == 0) { if (outSize == 0) {
return NULL; return nullptr;
} else { } else {
// send last line // send last line
return _elementLine; return _elementLine;
} }
return NULL; return nullptr;
} }
void removeEndLine(char* _val) { void removeEndLine(char* _val) {
@ -659,14 +657,14 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
int32_t meshFaceMaterialID = -1; int32_t meshFaceMaterialID = -1;
// material global param : // material global param :
std::string materialName = ""; std::string materialName = "";
ege::Material* material = NULL; ege::Material* material = nullptr;
// physical shape: // physical shape:
ege::PhysicsShape* physics = NULL; ege::PhysicsShape* physics = nullptr;
while(1) { while(1) {
int32_t level = countIndent(fileName); int32_t level = countIndent(fileName);
if (level == 0) { if (level == 0) {
// new section ... // new section ...
if (NULL == loadNextData(inputDataLine, 2048, fileName)) { if (nullptr == loadNextData(inputDataLine, 2048, fileName)) {
// reach end of file ... // reach end of file ...
break; break;
} }
@ -683,7 +681,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
if (currentMode >= EMFModuleMesh && currentMode <= EMFModuleMesh_END) { if (currentMode >= EMFModuleMesh && currentMode <= EMFModuleMesh_END) {
if (level == 1) { if (level == 1) {
//Find mesh name ... //Find mesh name ...
if (NULL == loadNextData(inputDataLine, 2048, fileName, true)) { if (nullptr == loadNextData(inputDataLine, 2048, fileName, true)) {
// reach end of file ... // reach end of file ...
break; break;
} }
@ -695,7 +693,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
} }
if (level == 2) { if (level == 2) {
// In the mesh level 2 the line size must not exced 2048 // In the mesh level 2 the line size must not exced 2048
if (NULL == loadNextData(inputDataLine, 2048, fileName, true)) { if (nullptr == loadNextData(inputDataLine, 2048, fileName, true)) {
// reach end of file ... // reach end of file ...
break; break;
} }
@ -732,7 +730,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
break; break;
case EMFModuleMeshVertex: { case EMFModuleMeshVertex: {
vec3 vertex(0,0,0); vec3 vertex(0,0,0);
while (NULL != loadNextData(inputDataLine, 2048, fileName, true, true) ) { while (nullptr != loadNextData(inputDataLine, 2048, fileName, true, true) ) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
break; break;
} }
@ -749,7 +747,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
} }
case EMFModuleMeshUVMapping: { case EMFModuleMeshUVMapping: {
vec2 uvMap(0,0); vec2 uvMap(0,0);
while (NULL != loadNextData(inputDataLine, 2048, fileName, true, true) ) { while (nullptr != loadNextData(inputDataLine, 2048, fileName, true, true) ) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
break; break;
} }
@ -768,7 +766,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
m_normalMode = normalModeVertex; m_normalMode = normalModeVertex;
vec3 normal(0,0,0); vec3 normal(0,0,0);
// find the vertex Normal list. // find the vertex Normal list.
while (NULL != loadNextData(inputDataLine, 2048, fileName, true, true) ) { while (nullptr != loadNextData(inputDataLine, 2048, fileName, true, true) ) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
break; break;
} }
@ -787,7 +785,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
m_normalMode = normalModeFace; m_normalMode = normalModeFace;
vec3 normal(0,0,0); vec3 normal(0,0,0);
// find the face Normal list. // find the face Normal list.
while (NULL != loadNextData(inputDataLine, 2048, fileName, true, true) ) { while (nullptr != loadNextData(inputDataLine, 2048, fileName, true, true) ) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
break; break;
} }
@ -806,7 +804,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
case EMFModuleMeshFaceMaterial: case EMFModuleMeshFaceMaterial:
if (level == 3) { if (level == 3) {
//Find mesh name ... //Find mesh name ...
if (NULL == loadNextData(inputDataLine, 2048, fileName, true)) { if (nullptr == loadNextData(inputDataLine, 2048, fileName, true)) {
// reach end of file ... // reach end of file ...
break; break;
} }
@ -818,7 +816,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
meshFaceMaterialID = m_listFaces.getId(inputDataLine); meshFaceMaterialID = m_listFaces.getId(inputDataLine);
EGE_VERBOSE(" " << inputDataLine); EGE_VERBOSE(" " << inputDataLine);
} else if (currentMode == EMFModuleMeshFaceMaterial) { } else if (currentMode == EMFModuleMeshFaceMaterial) {
while (NULL != loadNextData(inputDataLine, 2048, fileName, true, true) ) { while (nullptr != loadNextData(inputDataLine, 2048, fileName, true, true) ) {
if (inputDataLine[0] == '\0') { if (inputDataLine[0] == '\0') {
// end of line // end of line
break; break;
@ -863,14 +861,14 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
break; break;
case EMFModuleMeshPhysics: case EMFModuleMeshPhysics:
case EMFModuleMeshPhysicsNamed: case EMFModuleMeshPhysicsNamed:
if (NULL == loadNextData(inputDataLine, 2048, fileName, true, false, false)) { if (nullptr == loadNextData(inputDataLine, 2048, fileName, true, false, false)) {
// reach end of file ... // reach end of file ...
break; break;
} }
removeEndLine(inputDataLine); removeEndLine(inputDataLine);
if (level == 3) { if (level == 3) {
physics = ege::PhysicsShape::create(inputDataLine); physics = ege::PhysicsShape::create(inputDataLine);
if (physics == NULL) { if (physics == nullptr) {
EGE_ERROR("Allocation error when creating physical shape ..."); EGE_ERROR("Allocation error when creating physical shape ...");
continue; continue;
} }
@ -878,7 +876,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
EGE_VERBOSE(" " << m_physics.size() << " " << inputDataLine); EGE_VERBOSE(" " << m_physics.size() << " " << inputDataLine);
currentMode = EMFModuleMeshPhysicsNamed; currentMode = EMFModuleMeshPhysicsNamed;
} else if (currentMode == EMFModuleMeshPhysicsNamed) { } else if (currentMode == EMFModuleMeshPhysicsNamed) {
if (physics == NULL) { if (physics == nullptr) {
EGE_ERROR("Can not parse :'" << inputDataLine << "' in physical shape ..."); EGE_ERROR("Can not parse :'" << inputDataLine << "' in physical shape ...");
continue; continue;
} }
@ -891,7 +889,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
continue; continue;
} else if (currentMode >= EMFModuleMaterial && currentMode <= EMFModuleMaterial_END) { } else if (currentMode >= EMFModuleMaterial && currentMode <= EMFModuleMaterial_END) {
// all material element is stored on 1 line (size < 2048) // all material element is stored on 1 line (size < 2048)
if (NULL == loadNextData(inputDataLine, 2048, fileName, true)) { if (nullptr == loadNextData(inputDataLine, 2048, fileName, true)) {
// reach end of file ... // reach end of file ...
break; break;
} }
@ -899,10 +897,10 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
if (level == 1) { if (level == 1) {
// add previous material : // add previous material :
if( materialName != "" if( materialName != ""
&& material!=NULL) { && material!=nullptr) {
m_materials.add(materialName, material); m_materials.add(materialName, material);
materialName = ""; materialName = "";
material = NULL; material = nullptr;
} }
material = new ege::Material(); material = new ege::Material();
materialName = inputDataLine; materialName = inputDataLine;
@ -916,7 +914,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
jumpEndLine(fileName); jumpEndLine(fileName);
continue; continue;
} }
if (NULL == material) { if (nullptr == material) {
EGE_ERROR("material allocation error"); EGE_ERROR("material allocation error");
jumpEndLine(fileName); jumpEndLine(fileName);
continue; continue;
@ -980,10 +978,10 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
} }
// add last material ... // add last material ...
if( materialName != "" if( materialName != ""
&& material!=NULL) { && material!=nullptr) {
m_materials.add(materialName, material); m_materials.add(materialName, material);
materialName = ""; materialName = "";
material = NULL; material = nullptr;
} }
EGE_VERBOSE("Stop parsing Mesh file"); EGE_VERBOSE("Stop parsing Mesh file");
@ -993,7 +991,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
} }
void ege::resource::Mesh::addMaterial(const std::string& _name, ege::Material* _data) { void ege::resource::Mesh::addMaterial(const std::string& _name, ege::Material* _data) {
if (NULL == _data) { if (nullptr == _data) {
EGE_ERROR(" can not add material with null pointer"); EGE_ERROR(" can not add material with null pointer");
return; return;
} }
@ -1006,33 +1004,24 @@ void ege::resource::Mesh::addMaterial(const std::string& _name, ege::Material* _
} }
void ege::resource::Mesh::setShape(void* _shape) { void ege::resource::Mesh::setShape(void* _shape) {
if (m_functionFreeShape!=NULL) { if (m_functionFreeShape!=nullptr) {
m_functionFreeShape(m_pointerShape); m_functionFreeShape(m_pointerShape);
m_pointerShape = NULL; m_pointerShape = nullptr;
} }
m_pointerShape=_shape; m_pointerShape=_shape;
} }
ege::resource::Mesh* ege::resource::Mesh::keep(const std::string& _meshName) { ewol::object::Shared<ege::resource::Mesh> ege::resource::Mesh::keep(const std::string& _meshName) {
ege::resource::Mesh* object = static_cast<ege::resource::Mesh*>(getManager().localKeep(_meshName)); ewol::object::Shared<ege::resource::Mesh> object = ewol::dynamic_pointer_cast<ege::resource::Mesh>(getManager().localKeep(_meshName));
if (NULL != object) { if (object != nullptr) {
return object; return object;
} }
EGE_DEBUG("CREATE: Mesh: '" << _meshName << "'"); EGE_DEBUG("CREATE: Mesh: '" << _meshName << "'");
object = new ege::resource::Mesh(_meshName); object = ewol::object::makeShared(new ege::resource::Mesh(_meshName));
if (NULL == object) { if (object == nullptr) {
EGE_ERROR("allocation error of a resource : ??Mesh??" << _meshName); EGE_ERROR("allocation error of a resource : ??Mesh??" << _meshName);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ege::resource::Mesh::release(ege::resource::Mesh*& _object) {
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -91,7 +91,7 @@ namespace ege {
enum normalMode m_normalMode; // select the normal mode of display enum normalMode m_normalMode; // select the normal mode of display
bool m_checkNormal; //!< when enable, this check the normal of the mesh before sending it at the 3d card bool m_checkNormal; //!< when enable, this check the normal of the mesh before sending it at the 3d card
protected: protected:
ewol::resource::Program* m_GLprogram; ewol::object::Shared<ewol::resource::Program> m_GLprogram;
int32_t m_GLPosition; int32_t m_GLPosition;
int32_t m_GLMatrix; int32_t m_GLMatrix;
int32_t m_GLMatrixPosition; int32_t m_GLMatrixPosition;
@ -110,8 +110,8 @@ namespace ege {
etk::Hash<ege::Material*> m_materials; etk::Hash<ege::Material*> m_materials;
std::vector<ege::PhysicsShape*> m_physics; //!< collision shape module ... (independent of bullet lib) std::vector<ege::PhysicsShape*> m_physics; //!< collision shape module ... (independent of bullet lib)
protected: protected:
ewol::resource::VirtualBufferObject* m_verticesVBO; ewol::object::Shared<ewol::resource::VirtualBufferObject> m_verticesVBO;
protected: public:
Mesh(const std::string& _fileName, const std::string& _shaderName="DATA:textured3D2.prog"); Mesh(const std::string& _fileName, const std::string& _shaderName="DATA:textured3D2.prog");
virtual ~Mesh(); virtual ~Mesh();
public: public:
@ -177,14 +177,9 @@ namespace ege {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the ewol mesh file. * @param[in] _filename Name of the ewol mesh file.
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ege::resource::Mesh* keep(const std::string& _meshname); static ewol::object::Shared<ege::resource::Mesh> keep(const std::string& _meshname);
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ege::resource::Mesh*& _object);
}; };
}; };
}; };

View File

@ -13,7 +13,7 @@
ege::resource::ParticuleMesh::ParticuleMesh(const std::string& _fileName, const std::string& _shaderName) : ege::resource::ParticuleMesh::ParticuleMesh(const std::string& _fileName, const std::string& _shaderName) :
ege::resource::Mesh(_fileName, _shaderName) ege::resource::Mesh(_fileName, _shaderName)
{ {
if (m_GLprogram != NULL) { if (m_GLprogram != nullptr) {
m_GLMainColor = m_GLprogram->getUniform("EW_mainColor"); m_GLMainColor = m_GLprogram->getUniform("EW_mainColor");
} }
} }
@ -28,7 +28,7 @@ void ege::resource::ParticuleMesh::draw(mat4& _positionMatrix,
bool _enableDepthTest, bool _enableDepthTest,
bool _enableDepthUpdate) bool _enableDepthUpdate)
{ {
if (m_GLprogram == NULL) { if (m_GLprogram == nullptr) {
EGE_ERROR("No shader ..."); EGE_ERROR("No shader ...");
return; return;
} }
@ -126,27 +126,18 @@ void ege::resource::ParticuleMesh::draw(mat4& _positionMatrix,
glBindBuffer(GL_ARRAY_BUFFER,0); glBindBuffer(GL_ARRAY_BUFFER,0);
} }
ege::resource::ParticuleMesh* ege::resource::ParticuleMesh::keep(const std::string& _meshName, const std::string& _shaderName) ewol::object::Shared<ege::resource::ParticuleMesh> ege::resource::ParticuleMesh::keep(const std::string& _meshName, const std::string& _shaderName)
{ {
ege::resource::ParticuleMesh* object = static_cast<ege::resource::ParticuleMesh*>(getManager().localKeep(_meshName)); ewol::object::Shared<ege::resource::ParticuleMesh> object = ewol::dynamic_pointer_cast<ege::resource::ParticuleMesh>(getManager().localKeep(_meshName));
if (NULL != object) { if (object != nullptr) {
return object; return object;
} }
object = new ege::resource::ParticuleMesh(_meshName, _shaderName); object = ewol::object::makeShared(new ege::resource::ParticuleMesh(_meshName, _shaderName));
if (object == NULL) { if (object == nullptr) {
EGE_ERROR("allocation error of a resource : ??Mesh??" << _meshName); EGE_ERROR("allocation error of a resource : ??Mesh??" << _meshName);
return NULL; return nullptr;
} }
getManager().localAdd(object); getManager().localAdd(object);
return object; return object;
} }
void ege::resource::ParticuleMesh::release(ege::resource::ParticuleMesh*& _object)
{
if (_object == NULL) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
getManager().release(object2);
_object = NULL;
}

View File

@ -16,7 +16,7 @@ namespace ege {
class ParticuleMesh : public ege::resource::Mesh { class ParticuleMesh : public ege::resource::Mesh {
protected: protected:
int32_t m_GLMainColor; int32_t m_GLMainColor;
protected: public:
ParticuleMesh(const std::string& _fileName, const std::string& _shaderName); ParticuleMesh(const std::string& _fileName, const std::string& _shaderName);
virtual ~ParticuleMesh(); virtual ~ParticuleMesh();
public: public:
@ -29,14 +29,9 @@ namespace ege {
* @brief keep the resource pointer. * @brief keep the resource pointer.
* @note Never free this pointer by your own... * @note Never free this pointer by your own...
* @param[in] _filename Name of the ewol mesh file. * @param[in] _filename Name of the ewol mesh file.
* @return pointer on the resource or NULL if an error occured. * @return pointer on the resource or nullptr if an error occured.
*/ */
static ege::resource::ParticuleMesh* keep(const std::string& _meshName, const std::string& _shaderName="DATA:ParticuleMesh.prog"); static ewol::object::Shared<ege::resource::ParticuleMesh> keep(const std::string& _meshName, const std::string& _shaderName="DATA:ParticuleMesh.prog");
/**
* @brief release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void release(ege::resource::ParticuleMesh*& _object);
}; };
}; };
}; };

View File

@ -21,7 +21,6 @@ extern const char * const ewolEventMeshPressed = "ewol-mesh-Pressed";
ege::widget::Mesh::Mesh(const std::string& _filename) : ege::widget::Mesh::Mesh(const std::string& _filename) :
m_meshName(_filename), m_meshName(_filename),
m_object(NULL),
m_position(0,0,0), m_position(0,0,0),
m_angle(0,0,0), m_angle(0,0,0),
m_angleSpeed(0,0,0), m_angleSpeed(0,0,0),
@ -32,14 +31,14 @@ ege::widget::Mesh::Mesh(const std::string& _filename) :
setMouseLimit(1); setMouseLimit(1);
if (_filename!="") { if (_filename!="") {
m_object = ege::resource::Mesh::keep(m_meshName); m_object = ege::resource::Mesh::keep(m_meshName);
if (NULL == m_object) { if (nullptr == m_object) {
EGE_ERROR("Can not load the resource : \"" << m_meshName << "\""); EGE_ERROR("Can not load the resource : \"" << m_meshName << "\"");
} }
} }
} }
ege::widget::Mesh::~Mesh() { ege::widget::Mesh::~Mesh() {
ege::resource::Mesh::release(m_object);
} }
void ege::widget::Mesh::onDraw() { void ege::widget::Mesh::onDraw() {
@ -48,7 +47,7 @@ void ege::widget::Mesh::onDraw() {
* etk::matRotate(vec3(1,0,0),m_angle.x()) * etk::matRotate(vec3(1,0,0),m_angle.x())
* etk::matRotate(vec3(0,1,0),m_angle.y()) * etk::matRotate(vec3(0,1,0),m_angle.y())
* etk::matRotate(vec3(0,0,1),m_angle.z()); * etk::matRotate(vec3(0,0,1),m_angle.z());
if (NULL != m_object) { if (nullptr != m_object) {
m_object->draw(transformationMatrix); m_object->draw(transformationMatrix);
} }
} }
@ -97,10 +96,9 @@ bool ege::widget::Mesh::onEventInput(const ewol::event::Input& _event) {
void ege::widget::Mesh::setFile(const std::string& _filename) { void ege::widget::Mesh::setFile(const std::string& _filename) {
if( _filename!="" if( _filename!=""
&& m_meshName != _filename ) { && m_meshName != _filename ) {
ege::resource::Mesh::release(m_object);
m_meshName = _filename; m_meshName = _filename;
m_object = ege::resource::Mesh::keep(m_meshName); m_object = ege::resource::Mesh::keep(m_meshName);
if (NULL == m_object) { if (nullptr == m_object) {
EGE_ERROR("Can not load the resource : \"" << m_meshName << "\""); EGE_ERROR("Can not load the resource : \"" << m_meshName << "\"");
} }
} }
@ -127,8 +125,7 @@ void ege::widget::Mesh::setAngleSpeed(const vec3& _speed) {
markToRedraw(); markToRedraw();
} }
void ege::widget::Mesh::setDistance(float _distance) void ege::widget::Mesh::setDistance(float _distance) {
{
m_cameraDistance = _distance; m_cameraDistance = _distance;
markToRedraw(); markToRedraw();
} }

View File

@ -25,7 +25,7 @@ namespace ege {
private: private:
// mesh name : // mesh name :
std::string m_meshName; std::string m_meshName;
ege::resource::Mesh* m_object; ewol::object::Shared<ege::resource::Mesh> m_object;
// mesh display properties: // mesh display properties:
vec3 m_position; vec3 m_position;
vec3 m_angle; vec3 m_angle;

View File

@ -39,11 +39,12 @@ const char * const ege::widget::Scene::eventKillEnemy = "event-scene-kill-ennemy
ege::widget::Scene::Scene(bool _setAutoBullet, bool _setAutoCamera) : ege::widget::Scene::Scene(bool _setAutoBullet, bool _setAutoCamera) :
m_gameTime(0), m_gameTime(0),
m_angleView(M_PI/3.0), m_angleView(M_PI/3.0),
m_dynamicsWorld(NULL), m_dynamicsWorld(nullptr),
m_camera(NULL), m_camera(nullptr),
m_isRunning(true), m_isRunning(true),
m_debugMode(false), m_debugMode(false),
m_debugDrawing(NULL) { m_debugDrawing(nullptr) {
addObjectType("ege::widget::Scene");
setKeyboardRepeate(false); setKeyboardRepeate(false);
setCanHaveFocus(true); setCanHaveFocus(true);
periodicCallEnable(); periodicCallEnable();
@ -66,31 +67,31 @@ void ege::widget::Scene::setBulletConfig(btDefaultCollisionConfiguration* _colli
btBroadphaseInterface* _broadphase, btBroadphaseInterface* _broadphase,
btConstraintSolver* _solver, btConstraintSolver* _solver,
btDynamicsWorld* _dynamicsWorld) { btDynamicsWorld* _dynamicsWorld) {
if (NULL != _collisionConfiguration) { if (nullptr != _collisionConfiguration) {
m_collisionConfiguration = _collisionConfiguration; m_collisionConfiguration = _collisionConfiguration;
} else { } else {
m_collisionConfiguration = new btDefaultCollisionConfiguration(); m_collisionConfiguration = new btDefaultCollisionConfiguration();
} }
///use the default collision dispatcher. ///use the default collision dispatcher.
if (NULL != _dispatcher) { if (nullptr != _dispatcher) {
m_dispatcher = _dispatcher; m_dispatcher = _dispatcher;
} else { } else {
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
} }
if (NULL != _broadphase) { if (nullptr != _broadphase) {
m_broadphase = _broadphase; m_broadphase = _broadphase;
} else { } else {
m_broadphase = new btDbvtBroadphase(); m_broadphase = new btDbvtBroadphase();
} }
///the default constraint solver. ///the default constraint solver.
if (NULL != _solver) { if (nullptr != _solver) {
m_solver = _solver; m_solver = _solver;
} else { } else {
m_solver = new btSequentialImpulseConstraintSolver(); m_solver = new btSequentialImpulseConstraintSolver();
} }
if (NULL != _dynamicsWorld) { if (nullptr != _dynamicsWorld) {
m_dynamicsWorld = _dynamicsWorld; m_dynamicsWorld = _dynamicsWorld;
} else { } else {
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
@ -103,7 +104,7 @@ void ege::widget::Scene::setBulletConfig(btDefaultCollisionConfiguration* _colli
} }
void ege::widget::Scene::setCamera(ege::Camera* _camera) { void ege::widget::Scene::setCamera(ege::Camera* _camera) {
if (NULL != _camera) { if (nullptr != _camera) {
m_camera = _camera; m_camera = _camera;
} else { } else {
m_camera = new ege::Camera(vec3(0,0,0), 0, DEG_TO_RAD(45) ,50); m_camera = new ege::Camera(vec3(0,0,0), 0, DEG_TO_RAD(45) ,50);
@ -113,7 +114,7 @@ void ege::widget::Scene::setCamera(ege::Camera* _camera) {
} }
ege::widget::Scene::~Scene() { ege::widget::Scene::~Scene() {
ewol::resource::Colored3DObject::release(m_debugDrawing);
/* /*
ewol::resource::release(m_directDrawObject); ewol::resource::release(m_directDrawObject);
//cleanup in the reverse order of creation/initialization //cleanup in the reverse order of creation/initialization
@ -215,7 +216,7 @@ void ege::widget::Scene::onDraw() {
} }
#endif #endif
} }
if (NULL!=m_camera) { if (nullptr!=m_camera) {
m_env.getParticuleEngine().draw(*m_camera); m_env.getParticuleEngine().draw(*m_camera);
} }
#ifdef SCENE_DISPLAY_SPEED #ifdef SCENE_DISPLAY_SPEED
@ -257,7 +258,7 @@ void ege::widget::Scene::periodicCall(const ewol::event::Time& _event) {
//EWOL_DEBUG("Time: m_lastCallTime=" << m_lastCallTime << " deltaTime=" << deltaTime); //EWOL_DEBUG("Time: m_lastCallTime=" << m_lastCallTime << " deltaTime=" << deltaTime);
// update camera positions: // update camera positions:
if (NULL != m_camera) { if (nullptr != m_camera) {
m_camera->periodicCall(curentDelta); m_camera->periodicCall(curentDelta);
} }
//EGE_DEBUG("stepSimulation (start)"); //EGE_DEBUG("stepSimulation (start)");
@ -274,7 +275,7 @@ void ege::widget::Scene::periodicCall(const ewol::event::Time& _event) {
int32_t victoryPoint=0; int32_t victoryPoint=0;
std::vector<ege::ElementGame*>& elementList = m_env.getElementGame(); std::vector<ege::ElementGame*>& elementList = m_env.getElementGame();
for (int32_t iii=elementList.size()-1; iii >= 0; --iii) { for (int32_t iii=elementList.size()-1; iii >= 0; --iii) {
if(NULL != elementList[iii]) { if(nullptr != elementList[iii]) {
if (true == elementList[iii]->needToRemove()) { if (true == elementList[iii]->needToRemove()) {
if (elementList[iii]->getGroup() > 1) { if (elementList[iii]->getGroup() > 1) {
numberEnnemyKilled++; numberEnnemyKilled++;

View File

@ -51,12 +51,12 @@ namespace ege {
* @brief Destructor of the widget classes * @brief Destructor of the widget classes
*/ */
virtual ~Scene(); virtual ~Scene();
void setBulletConfig(btDefaultCollisionConfiguration* _collisionConfiguration=NULL, void setBulletConfig(btDefaultCollisionConfiguration* _collisionConfiguration=nullptr,
btCollisionDispatcher* _dispatcher=NULL, btCollisionDispatcher* _dispatcher=nullptr,
btBroadphaseInterface* _broadphase=NULL, btBroadphaseInterface* _broadphase=nullptr,
btConstraintSolver* _solver=NULL, btConstraintSolver* _solver=nullptr,
btDynamicsWorld* _dynamicsWorld=NULL); btDynamicsWorld* _dynamicsWorld=nullptr);
void setCamera(ege::Camera* _camera=NULL); void setCamera(ege::Camera* _camera=nullptr);
private: private:
float m_gameTime; //!< time of the game running float m_gameTime; //!< time of the game running
protected: protected:
@ -89,7 +89,7 @@ namespace ege {
void pauseToggle(); void pauseToggle();
protected: protected:
bool m_debugMode; bool m_debugMode;
ewol::resource::Colored3DObject* m_debugDrawing; //!< for the debug draw elements ewol::object::Shared<ewol::resource::Colored3DObject> m_debugDrawing; //!< for the debug draw elements
public: public:
/** /**
* @brief Toggle the debug mode == > usefull for DEBUG only ... * @brief Toggle the debug mode == > usefull for DEBUG only ...