Behaviours can now be serialized in from the scene graph xml
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
#include "KRBehavior.h"
|
#include "KRBehavior.h"
|
||||||
#include "KRNode.h"
|
#include "KRNode.h"
|
||||||
|
|
||||||
|
KRBehaviorFactoryFunctionMap m_factoryFunctions;
|
||||||
|
|
||||||
KRBehavior::KRBehavior()
|
KRBehavior::KRBehavior()
|
||||||
{
|
{
|
||||||
__node = NULL;
|
__node = NULL;
|
||||||
@@ -42,5 +44,23 @@ KRBehavior *KRBehavior::LoadXML(KRNode *node, tinyxml2::XMLElement *e)
|
|||||||
attributes[attribute->Name()] = attribute->Value();
|
attributes[attribute->Name()] = attribute->Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
const char *szElementName = e->Attribute("type");
|
||||||
|
if(szElementName == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
KRBehaviorFactoryFunctionMap::const_iterator itr = m_factoryFunctions.find(szElementName);
|
||||||
|
if(itr == m_factoryFunctions.end()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return (*itr->second)(attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRBehavior::RegisterFactoryCTOR(std::string behaviorName, KRBehaviorFactoryFunction fnFactory)
|
||||||
|
{
|
||||||
|
m_factoryFunctions[behaviorName] = fnFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRBehavior::UnregisterFactoryCTOR(std::string behaviorName)
|
||||||
|
{
|
||||||
|
m_factoryFunctions.erase(behaviorName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#define KRBEHAVIOR_H
|
#define KRBEHAVIOR_H
|
||||||
|
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@@ -17,11 +18,18 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class KRBehavior;
|
||||||
class KRNode;
|
class KRNode;
|
||||||
|
|
||||||
|
typedef KRBehavior *(*KRBehaviorFactoryFunction)(std::map<std::string, std::string> attributes);
|
||||||
|
typedef std::map<std::string, KRBehaviorFactoryFunction> KRBehaviorFactoryFunctionMap;
|
||||||
|
|
||||||
class KRBehavior
|
class KRBehavior
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static void RegisterFactoryCTOR(std::string behaviorName, KRBehaviorFactoryFunction fnFactory);
|
||||||
|
static void UnregisterFactoryCTOR(std::string behaviorName);
|
||||||
|
|
||||||
KRBehavior();
|
KRBehavior();
|
||||||
virtual ~KRBehavior();
|
virtual ~KRBehavior();
|
||||||
KRNode *getNode() const;
|
KRNode *getNode() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user