Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    132
  • comments
    99
  • views
    89142

Metadata is a good thing

Sign in to follow this  
Driv3MeFar

79 views

I've spent a large part of today removing hard-coded numbers and other ugliness from my code. I also tried using XML for the first time, and so far am duly impressed.

To make the whole affair easier, I am using TinyXML, which I definitely give a big . Now instead of calling LoadHeightMap(magic number 1, magic number 2, etc) from main, I simply give my heightmap c-tor a filename and have it load in all the necessary settings from an XML file. I also do this for setting up my window, and plan to in several other places as I expand on this project. Not having to recompile every time I change the starting size of the window or the distance between samples in my heightmap is a great thing.

I also restructured it a bit. Now my heightmap class resides within a more general Map class, which will hold a texture, unit info, movement squares, and the like. Took a little longer then expected, but worth it I suspect.

I've tried to set up all my XML saving and loading close to how (as I understad it) C# does things. I have an ISerializable inteface declaired thusly:

class ISerializable
{
public:
bool Write(const std::string &filename)
{
return (*this) << filename;
}
bool Read(const std::string &filename)
{
return (*this) >> filename;
}
protected:
//write (serialize) to file
virtual bool operator<<(const std::string &filename) = 0;
//read (deserialize) from file
virtual bool operator>>(const std::string &filename) = 0;
};


Now, every class I want to have load from an XML file merely has to derive from ISerializable and provide its own << and >> operators. I know some people may be mad at me for using the stream operators in an unusual way (ie, not: ostream& operator<<(ostream &, Object &obj) and the like), and I was a bit reluctant to do it at first myself, but I just like the way it looks in the end.

Don't know how much more work I'll do tonight. One of my recently graduated friends just got a job in the industry so we're throwing him a big party. It promises to be a good time. Maybe I'll tell you lucky readers about it tomorrow, if I remember any of it [wink].

Edit: Don't forget to add me to your GGE friends [grin]!
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 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!