KRBehavior serialization to / from XML in progress
This commit is contained in:
@@ -19,6 +19,11 @@ KRBehavior::~KRBehavior()
|
||||
|
||||
}
|
||||
|
||||
void KRBehavior::init()
|
||||
{
|
||||
// Note: Subclasses are not expected to call this method
|
||||
}
|
||||
|
||||
KRNode *KRBehavior::getNode() const
|
||||
{
|
||||
return __node;
|
||||
@@ -28,3 +33,14 @@ void KRBehavior::__setNode(KRNode *node)
|
||||
{
|
||||
__node = node;
|
||||
}
|
||||
|
||||
|
||||
KRBehavior *KRBehavior::LoadXML(KRNode *node, tinyxml2::XMLElement *e)
|
||||
{
|
||||
std::map<std::string, std::string> attributes;
|
||||
for(const tinyxml2::XMLAttribute *attribute = e->FirstAttribute(); attribute != NULL; attribute = attribute->Next()) {
|
||||
attributes[attribute->Name()] = attribute->Value();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef KRBEHAVIOR_H
|
||||
#define KRBEHAVIOR_H
|
||||
|
||||
|
||||
#include "tinyxml2.h"
|
||||
|
||||
/*
|
||||
|
||||
@@ -26,9 +26,12 @@ public:
|
||||
virtual ~KRBehavior();
|
||||
KRNode *getNode() const;
|
||||
|
||||
virtual void init();
|
||||
virtual void update(float deltaTime) = 0;
|
||||
virtual void visibleUpdate(float deltatime) = 0;
|
||||
void __setNode(KRNode *node);
|
||||
|
||||
static KRBehavior *LoadXML(KRNode *node, tinyxml2::XMLElement *e);
|
||||
private:
|
||||
KRNode *__node;
|
||||
};
|
||||
|
||||
@@ -180,13 +180,21 @@ void KRNode::loadXML(tinyxml2::XMLElement *e) {
|
||||
m_inverseModelMatrixValid = false;
|
||||
|
||||
for(tinyxml2::XMLElement *child_element=e->FirstChildElement(); child_element != NULL; child_element = child_element->NextSiblingElement()) {
|
||||
KRNode *child_node = KRNode::LoadXML(getScene(), child_element);
|
||||
if(child_node) {
|
||||
addChild(child_node);
|
||||
const char *szElementName = child_element->Name();
|
||||
if(strcmp(szElementName, "behavior") == 0) {
|
||||
KRBehavior *behavior = KRBehavior::LoadXML(this, child_element);
|
||||
if(behavior) {
|
||||
addBehavior(behavior);
|
||||
behavior->init();
|
||||
}
|
||||
} else {
|
||||
KRNode *child_node = KRNode::LoadXML(getScene(), child_element);
|
||||
|
||||
if(child_node) {
|
||||
addChild(child_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void KRNode::setLocalTranslation(const KRVector3 &v, bool set_original) {
|
||||
|
||||
Reference in New Issue
Block a user