Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Alternative Civs > Stella Polaris > Coding: Data Manager Class
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!

bottom of page
  
Author
Thread    < Last Thread     Next Thread > Post New Thread     Post A Reply
Blake is offline Blake
King
Brainfallocatione
Oct 2000
time: 17:24
  Old Post 16-12-2002 12:11
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
Coding: Data Manager Class Support Apolyton, buy Alpha Centauri

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:

code:
[Variables] Growth = 40 #Nominal population growth ( /1000 for %age) Growth_Per_SE = 4 #The change to growth caused by each + in SE Growth

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
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


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
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


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?

Kurilka is offline Kurilka
Chieftain
Arkhangelsk, by the White Sea
Dec 2002
time: 08:24
  Old Post 16-12-2002 12:51 Visit Kurilka's homepage!
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Support Apolyton, buy Call to Power 2

what do you mean with c style streams?
fopen etc.?
Why don't we use STLPort to make sure that c++ streams work well?
And why don't we use XML for such things?

Blake is offline Blake
King
Brainfallocatione
Oct 2000
time: 17:24
  Old Post 16-12-2002 14:02
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Support Apolyton or Terrorists Win

Oops, didn't know STLPort did streams too, that'd definitely be an option then.

Well, XML would be a possibility (I hear Clash uses XML), but really, I cant see the advantages for using XML for a game, I think a specialized format and loader would serve our purposes better.

Kurilka is offline Kurilka
Chieftain
Arkhangelsk, by the White Sea
Dec 2002
time: 08:24
  Old Post 16-12-2002 16:34 Visit Kurilka's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy Alpha Centauri

Clash?
The biggest advantage I see is that it is eXtensible ML, consider situation when we need not sections/parameters, but something a little bit more complicated (nested parameters or something like that).

Kurilka is offline Kurilka
Chieftain
Arkhangelsk, by the White Sea
Dec 2002
time: 08:24
  Old Post 16-12-2002 16:45 Visit Kurilka's homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Support Apolyton or Terrorists Win

some example:

code:
<faction name="human"> <unit name="Light Tank> <hitpoints value="250"/> <range value="4"/> ... </unit> </faction> <faction name="aliens"> ... </faction>

Apolyton formatting sucks

DeathByTheSword is offline DeathByTheSword
King
soon to be a major religion
Nov 2001
time: 05:24
  Old Post 16-12-2002 17:48
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Increase the size of your Attachments

maybe another parameter for units could be: visiblity

if this are all the parameters I will get boring after a while....some extra parameter wouldnt hurt....

Kurilka is offline Kurilka
Chieftain
Arkhangelsk, by the White Sea
Dec 2002
time: 08:24
  Old Post 16-12-2002 18:14 Visit Kurilka's homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Support Apolyton, buy GURPS/ Alpha Centauri

yeah, but that is not the question, the main topic to discuss is the format of the data file, i was trying to make something and came to colclusion that we need some NESTING (like XML do).

To make code like this (pseudocode, sorry ):

code:
for each f in dataman->sections("factions") do add faction f->name for each u in f->sections("units") add_unit u->name, u->range, u->hitpoints...

Blake is offline Blake
King
Brainfallocatione
Oct 2000
time: 17:24
  Old Post 17-12-2002 07:56
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Support Apolyton buy from Amazon

Actually using the method I outlined it's not nessecary... every time it runs into a unit definition it simply calls the factory method.
Well, you are right that we need *some* nesting, the question is, do we need an arbitary level of nesting, or will just one (1) level of nesting do the trick?

The main advantage of XML I see at this point is it makes it much easier to extend or partially define stuff (ie add fields, or have optional fields)....

Expat would be a good choice of an XML parser, I believe, it's fast (and used in Mozilla)

Kurilka is offline Kurilka
Chieftain
Arkhangelsk, by the White Sea
Dec 2002
time: 08:24
  Old Post 17-12-2002 12:22 Visit Kurilka's homepage!
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Support Apolyton buy from Amazon

Well that doesn't seem good choice (IMHO):

- C and not C++ (but C++ wrappers exist);
- stream-oriented - SAX and not DOM which is more suitable for our needs - applications must register handlers...
- a bit too large.

I propose tinyXML (http://www.grinninglizard.com/tinyxml/index.html), disatvanages (but i don't see them important for our game) :
- no DTD support;
- no XSL support;
- only ASCII.

The library seems to be quite stable and well designed.

Blake is offline Blake
King
Brainfallocatione
Oct 2000
time: 17:24
  Old Post 17-12-2002 13:18
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Support Apolyton or Terrorists Win

Okay, TinyXML looks rather good.

Kurilka is offline Kurilka
Chieftain
Arkhangelsk, by the White Sea
Dec 2002
time: 08:24
  Old Post 17-12-2002 13:49 Visit Kurilka's homepage!
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Support Apolyton, buy Alpha Centauri

And apart from data loading classes/routines there are some more questions:
1. What will we store in our data files?
2. Will there be 1 file for all stuff (seems to be quite unusable ) or many-many files?

Blake is offline Blake
King
Brainfallocatione
Oct 2000
time: 17:24
  Old Post 17-12-2002 15:02
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Suffering from ads?

many-many files.
Ideally, it would be possible to choose a selection of files to load, for example a core set of rules, but then being able to load extra files, like for extra units or something. (making it particullary easy to add simple mods)

It may make sense to then compile all the rules into a single binary file (I have a few ideas on how to do that, it wont really be the data managers responsibility), because as I understand it a single large XML file would be hell slow to load, *especially* using DOM.

Basically, we want to store everything we possibly can in the data files, except save games, map data etc which should be in a binary format. Or IOW, everything that we want the players to be able to edit, for example editing the save games would not be a sensible thing for a player to do.

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:24.
Apolyton Time is 00:24.
    top of page
Rate This Thread:
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0429 seconds (89.49% PHP - 10.51% MySQL) with 30 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net