[DEV] change the init of the element game
This commit is contained in:
parent
7f28ae22f2
commit
274ad28f95
@ -55,26 +55,11 @@ namespace ege
|
|||||||
virtual const etk::UString& GetType(void) const;
|
virtual const etk::UString& GetType(void) const;
|
||||||
/**
|
/**
|
||||||
* @brief Init the element with the defined properties
|
* @brief Init the element with the defined properties
|
||||||
* @param[in] _description String properties that the element know how to parse it...
|
* @param[in] _property Type of the next element
|
||||||
* @note : When the useer reques no parameter ==> if will call this one.
|
* @param[in] _value pointer on the value type
|
||||||
* @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.
|
* @return true, the element is corectly initialized.
|
||||||
*/
|
*/
|
||||||
virtual bool Init(const etk::UString& _description) { return false; };
|
virtual bool Init(property_te _property, void* _value) { 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 UnInit(void) { return true; };
|
virtual bool UnInit(void) { return true; };
|
||||||
private:
|
private:
|
||||||
uint32_t m_uID; //!< This is a reference on a basic element ID
|
uint32_t m_uID; //!< This is a reference on a basic element ID
|
||||||
|
@ -132,7 +132,7 @@ void ege::Environement::AddCreator(const etk::UString& _type, ege::createElement
|
|||||||
GetHachTableCreating().Add(_type, _creator);
|
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)) {
|
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 << "'");
|
||||||
@ -148,7 +148,7 @@ ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, bo
|
|||||||
EGE_ERROR("allocation error '" << _type << "'");
|
EGE_ERROR("allocation error '" << _type << "'");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (false==tmpElement->Init("")) {
|
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);
|
||||||
@ -160,88 +160,19 @@ ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, bo
|
|||||||
return tmpElement;
|
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)) {
|
return CreateElement(_type, _autoAddElement, ege::typeString, static_cast<void*>(&_description));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, ejson::Value* _value, bool _autoAddElement)
|
ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, ejson::Value* _value, bool _autoAddElement)
|
||||||
{
|
{
|
||||||
if (false==GetHachTableCreating().Exist(_type)) {
|
return CreateElement(_type, _autoAddElement, ege::typeJson, static_cast<void*>(_value));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, exml::Node* _node, bool _autoAddElement)
|
ege::ElementGame* ege::Environement::CreateElement(const etk::UString& _type, exml::Node* _node, bool _autoAddElement)
|
||||||
{
|
{
|
||||||
if (false==GetHachTableCreating().Exist(_type)) {
|
return CreateElement(_type, _autoAddElement, ege::typeXml, static_cast<void*>(_node));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,6 +19,14 @@ class btDynamicsWorld;
|
|||||||
#include <exml/exml.h>
|
#include <exml/exml.h>
|
||||||
|
|
||||||
namespace ege {
|
namespace ege {
|
||||||
|
typedef enum {
|
||||||
|
typeNone, //!< no element property
|
||||||
|
typeString, //!< type element static_cast<etk::UString*>(xxxxxxx)
|
||||||
|
typeJson, //!< type element static_cast<ejson::Value*>(xxxxxxx)
|
||||||
|
typeXml, //!< type element static_cast<exml::Node*>(xxxxxxx)
|
||||||
|
typeUser1, //!< user type 1
|
||||||
|
typeUser2 //!< User type 2
|
||||||
|
} property_te;
|
||||||
class ElementGame;
|
class ElementGame;
|
||||||
class Environement;
|
class Environement;
|
||||||
typedef ege::ElementGame* (*createElement_tf)(ege::Environement& _env);
|
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.
|
* @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...
|
* @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, bool _autoAddElement=true, ege::property_te _property=ege::typeNone, void* _value=NULL);
|
||||||
ege::ElementGame* CreateElement(const etk::UString& _type, const etk::UString& _description, bool _autoAddElement=true);
|
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, ejson::Value* _value, bool _autoAddElement=true);
|
||||||
ege::ElementGame* CreateElement(const etk::UString& _type, exml::Node* _node, bool _autoAddElement=true);
|
ege::ElementGame* CreateElement(const etk::UString& _type, exml::Node* _node, bool _autoAddElement=true);
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user