Metadata is a good thing

Published January 26, 2007
Advertisement
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]!
Next Entry 1,000+ views!
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

/facepalm

1710 views

Baby Steps

1272 views

...

720 views

Stuff

1310 views

Productivity++

1199 views

Rock Band FTW

1230 views

Seattle Opera

1275 views

Christ

1200 views

I maek gaem!

1175 views
Advertisement