• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

#1DontReferenceMyPointer  Members

182
Like
0Likes
Like

Posted 16 July 2012 - 11:18 AM

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?

#2laztrezort  Members

1058
Like
1Likes
Like

Posted 16 July 2012 - 11:31 AM

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.

#3DontReferenceMyPointer  Members

182
Like
0Likes
Like

Posted 16 July 2012 - 01:14 PM

I have never done binary storage. How does one go about that?

#4laztrezort  Members

1058
Like
0Likes
Like

Posted 16 July 2012 - 01:58 PM

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

#5DontReferenceMyPointer  Members

182
Like
0Likes
Like

Posted 16 July 2012 - 02:00 PM

I am programming in Java-Eclipse and included libraries. Everything else is my code.

#6laztrezort  Members

1058
Like
1Likes
Like

Posted 16 July 2012 - 02:36 PM

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.

#7DontReferenceMyPointer  Members

182
Like
0Likes
Like

Posted 16 July 2012 - 03:25 PM

Alright, I'll check it out.

Thank you for the responses, I appreciate it.

#8alnite  Members

3274
Like
1Likes
Like

Posted 16 July 2012 - 04:18 PM

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, 16 July 2012 - 04:20 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.