Xml Object Generation
So (there's that word again) I've been trying to work on a side project for awhile now. I think the whole side project thing formed a core component of my work ethic and if anything (outside of my wife and friends) got me through school, it had to be that. I started work on a new game called "Attack of the Robo Zombies" and my first approach was to go ballz out in making a prototype. I started slacking on creating an kind of design or plan to develop and instead got into the old trap of designing code while writing code. This is not 100% avoidable but you need to know the big picture before moving forward. Another problem was that as a side project, I was just trying to grind out something that didn't have an r&d hook that was keeping me interested in working on it. So in the face of all these problems I've started pretty much from scratch (again).
This time around, I'm building a prototype but I'm going to be using Bullet Physics to run dynamics for the world (making my life easier) and also focusing on developing a "robust" object generation system to make it easier to make the game data driven. This is more or less an experiment with Xml. So I figured, more for myself then anyone, I would dive into it here.
The problem that I encountered with previous projects was never developing a universal method to create objects from files. Usually I would end up writing several loading functions that would get a bit tedious since they only varied by a few things. While there are lots of solutions (and many better then the one I am about to go into), I started thinking about xml and how I wanted my solution to be driven by that as much as possible. For the game I wanted to make, I knew there would be many occasions where I would want to spawn things into the world. So lets say I wrote an xml file for a spawn point:
-spawnthis-
-enititylist-
-entity-
-/enititylist-
-spawnthis-
So from this, I wanted the ability to just say "Generate everything in
-spawnthis-
-enititylist-
-entity-
-/enititylist-
-effect-
-/effectlist-
My normal inclination would be to write a special chunk of spawn code that would look for the EntityList and EffectList and generate special groups for each. But lets say down the road I wrote something else that wasn't a spawn point but had to do the exact same thing. So this got me thinking about making a system that forced me to write the object creation code in a generic/reusable fashion. So now I've created a static object called a Generator. The Generator has a map of Creator objects (where Creator is the base class) where each one is mapped to a name that corresponds to an xml tag (ie
-stats-
-/grunt-
-entity default="grunt"-
There are definite drawbacks to a system like this. For one, it relys a lot on string comparisons and as of now, my use of Tiny Xml is creating a lot of strings on the fly so I'll need to iron that out. My hope is that by developing this feature now, I can use it to move prototype/game development faster. That and keep myself from regressing to doing nothing but playing games in my free time.
No comments:
Post a Comment