Okay, heres a game component to design and code (or steal ).
Functions:
Manages game variables.
Loads from txt files.
Loads from compiled files.
The primary function of this class is to load&parse files, that look something like this:
Growth would be a variable, and the data manager would keep variables handy for other classes to get to.
And # means comment, ofcourse The word between [ ] basically indicates what to do with the following stuff, until the next [ ]
Another example would be classes
When it encounters "unit" it will know what follows is a unit defintion. However it wont have to do anything with the data, rather it'll call a function in the unit factory which will know how to extract the data it wants from the token stream, do stuff with the data (create a new unit, I should hope), then return when it hits the next [ ] or hit's an error.
However the data manager will have to provide functions to extract the tokens from the stream, for example a snippet of the factory method for a new unit might look something like this
Notes:
Use c style streams, as c++ streams are really dodgy at the moment, they seem to work a different way with each version of gnu g++.
Stuff like compiled formats are very low priority.
It could be fun to have a way to register a factory method (and associated class name) with the data manager class, thus avoiding the need to change the code when adding more factory methods.
A singleton class could work well.
The format can basically be designed on the fly, however it could be worthwhile looking at how other games do. My examples look quite a bit like FreeCiv's data format.
Everything I've said or suggested is basically a suggestion, discussion of better methods is welcome.
Any volunteers?
Functions:
Manages game variables.
Loads from txt files.
Loads from compiled files.
The primary function of this class is to load&parse files, that look something like this:
Code:
[Variables] Growth = 40 #Nominal population growth ( /1000 for %age) Growth_Per_SE = 4 #The change to growth caused by each + in SE Growth
And # means comment, ofcourse The word between [ ] basically indicates what to do with the following stuff, until the next [ ]
Another example would be classes
Code:
[unit] name = "Light Tank" hitpoints = 300 range = 4 firepower = 3 speed = 10 [unit] name = "Hover Tank" hitpoints = 150 range = 3 firepower = 3 speed = 20
However the data manager will have to provide functions to extract the tokens from the stream, for example a snippet of the factory method for a new unit might look something like this
Code:
unit = new Unit; dataman->discard("name ="); // dataman complains if doesn't find "name =" unit->name = dataman->readString(); //complains if doesn't find a string dataman->discard("hitpoints ="); unit->hitpoints = dataman->readInt(); //complains if it doesn't find a int
Use c style streams, as c++ streams are really dodgy at the moment, they seem to work a different way with each version of gnu g++.
Stuff like compiled formats are very low priority.
It could be fun to have a way to register a factory method (and associated class name) with the data manager class, thus avoiding the need to change the code when adding more factory methods.
A singleton class could work well.
The format can basically be designed on the fly, however it could be worthwhile looking at how other games do. My examples look quite a bit like FreeCiv's data format.
Everything I've said or suggested is basically a suggestion, discussion of better methods is welcome.
Any volunteers?
Comment