I have a game I am attempting to program but the initial data entry for it is just huge. The thing is all this data is read-only. So when the program runs, it is the same every time.
The reason I need to ask this question is because I think it would be inefficient to re-run the data through a class system each time the program is run. Initially I was using an XML setup:
XML Setup Example:
<?xml version="1.0"?>
<gameBoard>
<!-- Area 1 -->
<area name="Area 1">
<arrows white="Area 2" black="Area 3" />
<color>white</color>
<location name="Area 1 Atrium" />
<location name="Location 1.1">
<attr1>foo</attr1>
<attr2>bar</attr2>
<attr3>foobar</attr3>
</location>
<location name="Location 1.2">
<attr1>foo</attr1>
<attr2>bar</attr2>
<attr3>foobar</attr3>
</location>
<location name="Location 1.3">
<attr1>foo</attr1>
<attr2>bar</attr2>
<attr3>foobar</attr3>
</location>
</area>
</gameBoard>
I chose this over JSON or YAML because the attributes on each the locations and area tags come in handy, plus I know XML best and I know how widely supported it is.
But, is this the best thing to do? Each time a player would move, I think it will have to iterate through this setup to find the specific location the player wanted to move to (technically it wouldn’t be iterating through the document as Java’s DOM parser loads the whole document into memory first, but either way).
My second thought was to make a class for each area that would have a method for each location and just set variables through the methods (for instance, playerLocation would get set to a location’s name, which could easily be done).
Additionally, this data by no means has to be human readable. I know that when data is byte-code it is generally much faster so that would work as well. Only the program needs to read it and even if a user were to change the XML/WhateverOtherConfig file, the additions would get ignored.
Thanks for the patience. If I need to clarify anything then let me know. This is very much in the alpha stages and I haven’t even gotten all my thoughts out of my head yet so I am just going as I think of it for much of this. Thanks again! Let me know if stuff needs clarifying.
There are two levels of optimisation that need to be considered.
For the first consider low overhead serialisation such as JSON (as @Perception has pointed out) but perhaps you should consider binary serialisation as this will load the quickest.
For the second consider using OS technology such as memory mapped files to help you.
But in all questions of optimisation I must say – first measure measure and measure again to determine where the real performance concerns are.