Jump to content
  • Advertisement
Sign in to follow this  
cypherx

Scene configuration file?

This topic is 4977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing a 3D simulator and I'm not sure how to store my scenes... The data files must contain which objects are in the scene (what mesh/material/texture, etc..), lights, camera position. I already have c++ functions to do all this (and at the moment my main function exists only to set up the scene). Would this be easier if I exported my C++ functions to lua and ran a setup script, used tinyXML to parse an xml scene description or used a plain text file and parsed it myself? Thanks, Alex

Share this post


Link to post
Share on other sites
Advertisement
It depends on the complexity of your configuration. If you can get away with using scanf (or cin) to read a simple text file, then do that. If your data is more complicated than that, then XML might be the way to go. Lua is probably not worth the effort.

Share this post


Link to post
Share on other sites
xml.h

#ifndef XML_H
#define XML_H

#include "tinyxml/tinystr.h"
#include "tinyxml/tinyxml.h"

namespace Xml
{
/**Xml Element

\code Xml::Element child = root("Child");
Xml::Element child = root();

for( ; child ; child = child.Sibling("Child"))
//...

string name = child["name"];
int age = child.Int("age");
bool dead = child.Bool("isdead");\endcode*/

class Element
{
public:
Element(TiXmlElement *i);
~Element();

Element operator()(); ///< return child element
Element operator()(const char *el); ///< return child el element

operator bool(); ///< is this valid element?

Element Sibling(); ///< return sibling element
Element Sibling(const char *el); ///< return el sibling element

const char *operator[](const char *attr);///< get attribute value
int Int(const char *attr); ///< get int
bool Bool(const char *attr); ///< get bool
private:
TiXmlElement *e;
};

/**Xml Document

\code Xml::Document doc = "mydoc.xml";

Xml::Element root = doc();
Xml::Element root = doc("Root");\endcode*/

class Document
{
public:
Document(const char *src); ///< load src
~Document();

Element operator()(); ///< first child
Element operator()(const char *el); ///< first el child
private:
TiXmlDocument doc;
};
}

#endif


xml.cpp

#include "xml.h"
using namespace Xml;

#include <string>
using std::string;

Element::Element(TiXmlElement *i)
: e(i)
{
}
Element::~Element()
{
}

Element Element::operator()()
{
return Element(e->FirstChildElement());
}
Element Element::operator()(const char *el)
{
return Element(e->FirstChildElement(el));
}

Element::operator bool()
{
return (e) ? 1 : 0;
}

Element Element::Sibling()
{
return e->NextSiblingElement();
}
Element Element::Sibling(const char *el)
{
return e->NextSiblingElement(el);
}

const char *Element::operator[](const char *attr)
{
return e->Attribute(attr);
}
int Element::Int(const char *attr)
{
int x;
e->QueryIntAttribute(attr,&x);
return x;
}
bool Element::Bool(const char *attr)
{
string g = operator[](attr);

if(g == "yes" || g == "1")
return 1;

return 0;
}


Document::Document(const char *src)
: doc(src)
{
doc.LoadFile();
}
Document::~Document()
{
}

Element Document::operator()()
{
return Element(doc.FirstChildElement());
}
Element Document::operator()(const char *el)
{
return Element(doc.FirstChildElement(el));
}


hopefully, it will reduce the verbosity and trouble of TinyXml

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!