Very unstable and broken XML loader added.
This commit is contained in:
@@ -1,8 +1,188 @@
|
|||||||
|
#include <string>
|
||||||
#include "DataModelInstance.h"
|
#include "DataModelInstance.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace rapidxml;
|
||||||
|
|
||||||
|
PhysicalInstance* DataModelInstance::makePart()
|
||||||
|
{
|
||||||
|
PhysicalInstance* part = new PhysicalInstance();
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
|
rapidxml::xml_node<>* DataModelInstance::getNode(xml_node<> * node,const char* name)
|
||||||
|
{
|
||||||
|
xml_node<> * tempNode = node->first_node(name);
|
||||||
|
if (!tempNode)
|
||||||
|
{
|
||||||
|
_errMsg = "Expected <";
|
||||||
|
_errMsg += name;
|
||||||
|
_errMsg+="> tag.";
|
||||||
|
_successfulLoad=true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tempNode;
|
||||||
|
}
|
||||||
|
float DataModelInstance::getFloatValue(xml_node<> * node,const char* name)
|
||||||
|
{
|
||||||
|
xml_node<> * tempNode = node->first_node(name);
|
||||||
|
if (!tempNode)
|
||||||
|
{
|
||||||
|
_errMsg = "Expected <";
|
||||||
|
_errMsg += name;
|
||||||
|
_errMsg+="> tag.";
|
||||||
|
_successfulLoad=true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
float newFloat;
|
||||||
|
stringstream converter;
|
||||||
|
converter << tempNode->value();
|
||||||
|
converter >> newFloat;
|
||||||
|
return newFloat;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DataModelInstance::scanXMLObject(xml_node<> * scanNode)
|
||||||
|
{
|
||||||
|
xml_node<> * watchFirstNode = scanNode->first_node();
|
||||||
|
|
||||||
|
for (xml_node<> *node = scanNode->first_node();node; node = node->next_sibling())
|
||||||
|
{
|
||||||
|
if (strncmp(node->name(),"Item",4)==0)
|
||||||
|
{
|
||||||
|
xml_attribute<> *classAttr = node->first_attribute("class");
|
||||||
|
std::string className = classAttr->value();
|
||||||
|
if (className=="Part") {
|
||||||
|
xml_node<> *propNode = node->first_node();
|
||||||
|
xml_node<> *cFrameNode=0;
|
||||||
|
xml_node<> *sizeNode=0;
|
||||||
|
xml_node<> *colorNode=0;
|
||||||
|
|
||||||
|
for (xml_node<> *partPropNode = propNode->first_node();partPropNode; partPropNode = partPropNode->next_sibling())
|
||||||
|
{
|
||||||
|
for (xml_attribute<> *attr = partPropNode->first_attribute();attr; attr = attr->next_attribute())
|
||||||
|
{
|
||||||
|
std::string xmlName = attr->name();
|
||||||
|
std::string xmlValue = attr->value();
|
||||||
|
|
||||||
|
if (xmlValue=="CFrame" | xmlValue=="CoordinateFrame")
|
||||||
|
{
|
||||||
|
cFrameNode = partPropNode;
|
||||||
|
}
|
||||||
|
if (xmlValue=="Color")
|
||||||
|
{
|
||||||
|
colorNode=partPropNode;
|
||||||
|
}
|
||||||
|
if (xmlValue=="size")
|
||||||
|
{
|
||||||
|
sizeNode = partPropNode;
|
||||||
|
}
|
||||||
|
if (xmlValue=="Part")
|
||||||
|
{
|
||||||
|
for (xml_node<> *featureNode = partPropNode->first_node();featureNode; featureNode = featureNode->next_sibling())
|
||||||
|
{
|
||||||
|
for (xml_attribute<> *attr = featureNode->first_attribute();attr; attr = attr->next_attribute())
|
||||||
|
{
|
||||||
|
std::string xmlName = attr->name();
|
||||||
|
std::string xmlValue = attr->value();
|
||||||
|
if (xmlValue=="size")
|
||||||
|
{
|
||||||
|
sizeNode=featureNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cFrameNode) {
|
||||||
|
_errMsg="CFrame is missing in Part";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!sizeNode) {
|
||||||
|
_errMsg="Size is missing in Part";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float R=1;
|
||||||
|
float G=1;
|
||||||
|
float B=1;
|
||||||
|
|
||||||
|
if (colorNode)
|
||||||
|
{
|
||||||
|
R = getFloatValue(colorNode,"R");
|
||||||
|
G = getFloatValue(colorNode,"G");
|
||||||
|
B = getFloatValue(colorNode,"B");
|
||||||
|
}
|
||||||
|
|
||||||
|
float X = getFloatValue(cFrameNode,"X");
|
||||||
|
float Y = getFloatValue(cFrameNode,"Y");
|
||||||
|
float Z = getFloatValue(cFrameNode,"Z");
|
||||||
|
float R00 = getFloatValue(cFrameNode,"R00");
|
||||||
|
float R01 = getFloatValue(cFrameNode,"R01");
|
||||||
|
float R02 = getFloatValue(cFrameNode,"R02");
|
||||||
|
float R10 = getFloatValue(cFrameNode,"R10");
|
||||||
|
float R11 = getFloatValue(cFrameNode,"R11");
|
||||||
|
float R12 = getFloatValue(cFrameNode,"R12");
|
||||||
|
float R20 = getFloatValue(cFrameNode,"R20");
|
||||||
|
float R21 = getFloatValue(cFrameNode,"R21");
|
||||||
|
float R22 = getFloatValue(cFrameNode,"R22");
|
||||||
|
|
||||||
|
float sizeX = getFloatValue(sizeNode,"X");
|
||||||
|
float sizeY = getFloatValue(sizeNode,"Y");
|
||||||
|
float sizeZ = getFloatValue(sizeNode,"Z");
|
||||||
|
|
||||||
|
if (_successfulLoad) {
|
||||||
|
PhysicalInstance* test = makePart();
|
||||||
|
test->setParent(getWorkspace());
|
||||||
|
test->color = Color3(R,G,B);
|
||||||
|
test->setSize(Vector3(sizeX,sizeY,sizeZ));
|
||||||
|
test->setCFrame(Matrix3(R00,R01,R02,R10,R11,R12,R20,R21,R22)*Vector3(X,Y,Z));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
for (xml_attribute<> *attr = node->first_attribute();attr; attr = attr->next_attribute())
|
||||||
|
{
|
||||||
|
std::string xmlName = attr->name();
|
||||||
|
std::string xmlValue = attr->value();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
scanXMLObject(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DataModelInstance::load()
|
||||||
|
{
|
||||||
|
ifstream levelFile("skooter.rbxm");
|
||||||
|
if (levelFile) {
|
||||||
|
levelFile.seekg(0,levelFile.end);
|
||||||
|
int length = levelFile.tellg();
|
||||||
|
levelFile.seekg(0,levelFile.beg);
|
||||||
|
char * buffer = new char[length+1];
|
||||||
|
buffer[length]=0;
|
||||||
|
levelFile.read(buffer,length);
|
||||||
|
xml_document<> doc;
|
||||||
|
doc.parse<0>(buffer);
|
||||||
|
xml_node<> *mainNode = doc.first_node();
|
||||||
|
std::string xmlName = mainNode->name();
|
||||||
|
//node = node->first_node();
|
||||||
|
//xmlName = node->name();
|
||||||
|
scanXMLObject(mainNode);
|
||||||
|
|
||||||
|
delete[] buffer;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
DataModelInstance::DataModelInstance(void)
|
DataModelInstance::DataModelInstance(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "rapidxml/rapidxml.hpp"
|
||||||
#include "instance.h"
|
#include "instance.h"
|
||||||
#include "WorkspaceInstance.h"
|
#include "WorkspaceInstance.h"
|
||||||
|
#include "PhysicalInstance.h"
|
||||||
|
|
||||||
class DataModelInstance :
|
class DataModelInstance :
|
||||||
public Instance
|
public Instance
|
||||||
@@ -10,6 +12,8 @@ public:
|
|||||||
~DataModelInstance(void);
|
~DataModelInstance(void);
|
||||||
void setMessage(std::string);
|
void setMessage(std::string);
|
||||||
void clearMessage();
|
void clearMessage();
|
||||||
|
bool load();
|
||||||
|
bool printIfLoadError(const char* errorMsg);
|
||||||
void drawMessage(RenderDevice*);
|
void drawMessage(RenderDevice*);
|
||||||
WorkspaceInstance* getWorkspace();
|
WorkspaceInstance* getWorkspace();
|
||||||
WorkspaceInstance* workspace;
|
WorkspaceInstance* workspace;
|
||||||
@@ -24,4 +28,11 @@ public:
|
|||||||
void setMousePos(int x,int y);
|
void setMousePos(int x,int y);
|
||||||
void setMousePos(Vector2 pos);
|
void setMousePos(Vector2 pos);
|
||||||
bool mouseButton1Down;
|
bool mouseButton1Down;
|
||||||
|
PhysicalInstance* makePart();
|
||||||
|
private:
|
||||||
|
bool scanXMLObject(rapidxml::xml_node<>* node);
|
||||||
|
rapidxml::xml_node<>* getNode(rapidxml::xml_node<> * node,const char* name );
|
||||||
|
float getFloatValue(rapidxml::xml_node<> * node,const char* name);
|
||||||
|
bool _successfulLoad;
|
||||||
|
std::string _errMsg;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,9 +56,9 @@ void PhysicalInstance::setSize(Vector3 newSize)
|
|||||||
if(sizex > 512)
|
if(sizex > 512)
|
||||||
sizex = 512;
|
sizex = 512;
|
||||||
|
|
||||||
int sizey = (int)newSize.y;
|
float sizey = newSize.y;
|
||||||
if(sizey <= 0)
|
if(sizey <= 0)
|
||||||
sizey = 1;
|
sizey = 0.4;
|
||||||
if(sizey > 512)
|
if(sizey > 512)
|
||||||
sizey = 512;
|
sizey = 512;
|
||||||
|
|
||||||
|
|||||||
5
main.cpp
5
main.cpp
@@ -708,7 +708,10 @@ void Demo::onInit() {
|
|||||||
|
|
||||||
initGUI();
|
initGUI();
|
||||||
|
|
||||||
|
dataModel->load();
|
||||||
|
|
||||||
|
// Say bye bye to this soon...
|
||||||
|
/*
|
||||||
PhysicalInstance* test = makePart();
|
PhysicalInstance* test = makePart();
|
||||||
test->setParent(dataModel->getWorkspace());
|
test->setParent(dataModel->getWorkspace());
|
||||||
test->color = Color3(0.2F,0.3F,1);
|
test->color = Color3(0.2F,0.3F,1);
|
||||||
@@ -784,7 +787,7 @@ void Demo::onInit() {
|
|||||||
test->color = Color3::gray();
|
test->color = Color3::gray();
|
||||||
test->setSize(Vector3(4,1,2));
|
test->setSize(Vector3(4,1,2));
|
||||||
test->setPosition(Vector3(2,7,0));
|
test->setPosition(Vector3(2,7,0));
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
406
rapidxml/manual.html
Normal file
406
rapidxml/manual.html
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user