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