From 274ad28f95c936d4fbc1e3843c14668b71be2024 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 5 Sep 2013 21:08:53 +0200 Subject: [PATCH] [DEV] change the init of the element game --- ege/ElementGame.h | 21 ++---------- ege/Environement.cpp | 81 ++++---------------------------------------- ege/Environement.h | 12 +++++-- 3 files changed, 19 insertions(+), 95 deletions(-) diff --git a/ege/ElementGame.h b/ege/ElementGame.h index da5d324..8daeb0c 100644 --- a/ege/ElementGame.h +++ b/ege/ElementGame.h @@ -55,26 +55,11 @@ namespace ege virtual const etk::UString& GetType(void) const; /** * @brief Init the element with the defined properties - * @param[in] _description String properties that the element know how to parse it... - * @note : When the useer reques no parameter ==> if will call this one. - * @note : In a game developpement the user choice a transmission mode (string, json or xml) and use only one ... + * @param[in] _property Type of the next element + * @param[in] _value pointer on the value type * @return true, the element is corectly initialized. */ - virtual bool Init(const etk::UString& _description) { return false; }; - /** - * @brief Init the element with the defined properties - * @param[in] _value json properties that the element know how to parse it... - * @note : in a game developpement the user choice a transmission mode (string, json or xml) and use only one ... - * @return true, the element is corectly initialized. - */ - virtual bool Init(ejson::Value* _value) { return false; }; - /** - * @brief Init the element with the defined properties - * @param[in] _node xml properties that the element know how to parse it... - * @note : in a game developpement the user choice a transmission mode (string, json or xml) and use only one ... - * @return true, the element is corectly initialized. - */ - virtual bool Init(exml::Node* _value) { return false; }; + virtual bool Init(property_te _property, void* _value) { return false; }; virtual bool UnInit(void) { return true; }; private: uint32_t m_uID; //!< This is a reference on a basic element ID diff --git a/ege/Environement.cpp b/ege/Environement.cpp index c6f012d..97143d3 100644 --- a/ege/Environement.cpp +++ b/ege/Environement.cpp @@ -132,7 +132,7 @@ void ege::Environement::AddCreator(const etk::UString& _type, ege::createElement GetHachTableCreating().Add(_type, _creator); } -ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, bool _autoAddElement) +ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, bool _autoAddElement, ege::property_te _property, void* _value) { if (false==GetHachTableCreating().Exist(_type)) { EGE_ERROR("Request creating of an type that is not known '" << _type << "'"); @@ -148,7 +148,7 @@ ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, bo EGE_ERROR("allocation error '" << _type << "'"); return NULL; } - if (false==tmpElement->Init("")) { + if (false==tmpElement->Init(_property, _value)) { EGE_ERROR("Init error ... '" << _type << "'"); // remove created element ... delete(tmpElement); @@ -160,88 +160,19 @@ ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, bo return tmpElement; } -ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, const etk::UString& _description, bool _autoAddElement) +ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, etk::UString& _description, bool _autoAddElement) { - if (false==GetHachTableCreating().Exist(_type)) { - EGE_ERROR("Request creating of an type that is not known '" << _type << "'"); - return NULL; - } - ege::createElement_tf creatorPointer = GetHachTableCreating()[_type]; - if (NULL == creatorPointer) { - EGE_ERROR("NULL pointer creator ==> internal error... '" << _type << "'"); - return NULL; - } - ege::ElementGame* tmpElement = creatorPointer(*this); - if (NULL == tmpElement) { - EGE_ERROR("allocation error '" << _type << "'"); - return NULL; - } - if (false==tmpElement->Init(_description)) { - EGE_ERROR("Init error ... '" << _type << "'"); - // remove created element ... - delete(tmpElement); - return NULL; - } - if (_autoAddElement==true) { - AddElementGame(tmpElement); - } - return tmpElement; + return CreateElement(_type, _autoAddElement, ege::typeString, static_cast(&_description)); } ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, ejson::Value* _value, bool _autoAddElement) { - if (false==GetHachTableCreating().Exist(_type)) { - EGE_ERROR("Request creating of an type that is not known '" << _type << "'"); - return NULL; - } - ege::createElement_tf creatorPointer = GetHachTableCreating()[_type]; - if (NULL == creatorPointer) { - EGE_ERROR("NULL pointer creator ==> internal error... '" << _type << "'"); - return NULL; - } - ege::ElementGame* tmpElement = creatorPointer(*this); - if (NULL == tmpElement) { - EGE_ERROR("allocation error '" << _type << "'"); - return NULL; - } - if (false==tmpElement->Init(_value)) { - EGE_ERROR("Init error ... '" << _type << "'"); - // remove created element ... - delete(tmpElement); - return NULL; - } - if (_autoAddElement==true) { - AddElementGame(tmpElement); - } - return tmpElement; + return CreateElement(_type, _autoAddElement, ege::typeJson, static_cast(_value)); } ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, exml::Node* _node, bool _autoAddElement) { - if (false==GetHachTableCreating().Exist(_type)) { - EGE_ERROR("Request creating of an type that is not known '" << _type << "'"); - return NULL; - } - ege::createElement_tf creatorPointer = GetHachTableCreating()[_type]; - if (NULL == creatorPointer) { - EGE_ERROR("NULL pointer creator ==> internal error... '" << _type << "'"); - return NULL; - } - ege::ElementGame* tmpElement = creatorPointer(*this); - if (NULL == tmpElement) { - EGE_ERROR("allocation error '" << _type << "'"); - return NULL; - } - if (false==tmpElement->Init(_node)) { - EGE_ERROR("Init error ... '" << _type << "'"); - // remove created element ... - delete(tmpElement); - return NULL; - } - if (_autoAddElement==true) { - AddElementGame(tmpElement); - } - return tmpElement; + return CreateElement(_type, _autoAddElement, ege::typeXml, static_cast(_node)); } diff --git a/ege/Environement.h b/ege/Environement.h index a1e77cc..7b36ae6 100644 --- a/ege/Environement.h +++ b/ege/Environement.h @@ -19,6 +19,14 @@ class btDynamicsWorld; #include namespace ege { + typedef enum { + typeNone, //!< no element property + typeString, //!< type element static_cast(xxxxxxx) + typeJson, //!< type element static_cast(xxxxxxx) + typeXml, //!< type element static_cast(xxxxxxx) + typeUser1, //!< user type 1 + typeUser2 //!< User type 2 + } property_te; class ElementGame; class Environement; typedef ege::ElementGame* (*createElement_tf)(ege::Environement& _env); @@ -75,8 +83,8 @@ namespace ege { * @return NULL if an error occured OR the pointer on the element and it is already added on the system. * @note Pointer is return in case of setting properties on it... */ - ege::ElementGame* CreateElement(const etk::UString& _type, bool _autoAddElement=true); - ege::ElementGame* CreateElement(const etk::UString& _type, const etk::UString& _description, bool _autoAddElement=true); + ege::ElementGame* CreateElement(const etk::UString& _type, bool _autoAddElement=true, ege::property_te _property=ege::typeNone, void* _value=NULL); + ege::ElementGame* CreateElement(const etk::UString& _type, etk::UString& _description, bool _autoAddElement=true); ege::ElementGame* CreateElement(const etk::UString& _type, ejson::Value* _value, bool _autoAddElement=true); ege::ElementGame* CreateElement(const etk::UString& _type, exml::Node* _node, bool _autoAddElement=true); public: