This topic is 2347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In my game I am essentially finished with the engine (curse you A*!!!) and I have introduced enough functionality that it's worth having save state and load save options.

The only problem I am having is that my game is very large in scope and has a whole lot of information. For example, in my small test area that I pre-render, the grid of play is 300x300 ->90,000 tile objects each with many attributes that can not be "figured out" when loaded (i.e. whenever I make the map, I make sure every tile has a pointer to every adjacent tile, this is something that could be "figured out" out when loaded, but soil fertility and irrigation states cannot be "figured out" and must be known.) As well, I have creatures, items, trees, buildings which all have trait values that are not exactly the same as a member of their same class.

I know how to store this information in a text file, but retrieval seems inefficient and I'm unsure how it will scale when I start trying out actual game sized maps. I've done bioinformatic programs that read out of FASTA files (comparable to .txt) and I know how slow that can be with only a few million data points.

I've come to the mountain. Is there a better alternative to text file data storage? If so, what's available?

##### Share on other sites
Text file are generally more inefficient in speed and memory footprint. The simple reason is that you are storing extra (unneeded) data. It then needs to be parsed when deserialized. The only benefit to text files is that they are human-readable.

So, if you do not need the files to be human readable, what you are looking for is binary storage. Depending on the language/framework/libraries you are using, the specific implementation will vary. If memory footprint of the file is a concern, you can also use compression, but you will generally trade some speed in the process.

##### Share on other sites
I have never done binary storage. How does one go about that?

##### Share on other sites
Which language/framework/libraries are you using? Many languages include libraries to simplify binary input/output (which, at the lower level, is implemented by the operating system).

##### Share on other sites
I am programming in Java-Eclipse and included libraries. Everything else is my code.

##### Share on other sites
I haven't done much with Java, so I am only guessing here, but I'd look through the standard lib docs for things such as "binary serialization", "binary IO", "binary streams" or "binary files". I'd be suprised if Java didn't include some high-level methods for simplifying this. Maybe someone here with more Java experience can comment.

##### Share on other sites
Alright, I'll check it out.

Thank you for the responses, I appreciate it.

##### Share on other sites
Use FileOutputStream and DataOutputStream.

 try { File file = new File("test.bin"); FileOutputStream fos = new FileOutputStream(file); DataOutputStream dos = new DataOutputStream(fos); try { dos.writeInt(100); dos.writeByte(20); dos.writeUTF("Hello World"); } finally { dos.close(); } } catch (IOException e) { System.out.println("Exception thrown."); } 

Output:

 00 00 00 64 14 00 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64  Edited by alnite

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013763
×