After much thinking I’m heavily leaning on the creation of everything at the start of the game instead as the player explored further and further. It doesn’t change anything in the way the game plays out, but it does remove some potentially threading issues as everything is created at the start of the game instead of during.
But, because of that, when the world creation is done, which takes about 20 secs of so, the game saves everything to disk, and that… that takes a lot more time than I’m willing to let it. (I didn’t time it, but it was quite a while when I did it)
Loading the game isn’t that much of an issue. It’s slower than I want it really, but it’s not that problematic. At least not now.
The main problem is saving at creation with a “small world” composed of about 500 sectors each containing about 500 systems.
The way I’m doing it right now is by having a directory for each sector and saving its data there. The base dir having the game state and other data.
As for when I load sector data, the latest example I have is from redoing the cache from zero:
Loading 27 sectors, for a total of about 11 MB, takes more or less 11 seconds.
Result output:
17:37:48.728 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #320] from disk) took 753 millisecs.
17:37:49.031 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #334] from disk) took 303 millisecs.
17:37:49.816 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #92] from disk) took 785 millisecs.
17:37:49.975 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #145] from disk) took 159 millisecs.
17:37:50.452 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #332] from disk) took 477 millisecs.
17:37:51.253 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #333] from disk) took 801 millisecs.
17:37:51.986 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #330] from disk) took 733 millisecs.
17:37:52.211 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #391] from disk) took 225 millisecs.
17:37:52.434 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #148] from disk) took 223 millisecs.
17:37:52.644 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #390] from disk) took 210 millisecs.
17:37:52.798 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #331] from disk) took 154 millisecs.
17:37:52.877 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #389] from disk) took 79 millisecs.
17:37:53.345 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #329] from disk) took 468 millisecs.
17:37:53.522 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #516] from disk) took 177 millisecs.
17:37:53.645 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #236] from disk) took 123 millisecs.
17:37:53.718 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #513] from disk) took 73 millisecs.
17:37:53.963 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #514] from disk) took 245 millisecs.
17:37:54.352 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #515] from disk) took 389 millisecs.
17:37:54.481 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #381] from disk) took 129 millisecs.
17:37:54.708 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #382] from disk) took 227 millisecs.
17:37:55.493 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #317] from disk) took 785 millisecs.
17:37:55.672 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #497] from disk) took 179 millisecs.
17:37:56.128 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #498] from disk) took 456 millisecs.
17:37:56.456 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #319] from disk) took 328 millisecs.
17:37:56.527 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #424] from disk) took 71 millisecs.
17:37:56.767 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #189] from disk) took 240 millisecs.
17:37:56.974 [Game Thread] DEBUG c.m.g.d.g.galaxyoctree.LeafCache - Part 1 of cacheLeafs (loading [leaf #423] from disk) took 207 millisecs.
No real voodoo code in there
The loading loop:
[java] long realStart = System.currentTimeMillis();
long start = realStart;
long part1;
long part2;
for (Integer i : idsToAdd) {
cachedLeafs.add(TreeLeaf.loadLeaf(i));
part1 = System.currentTimeMillis();
LOGGER.debug(“Part 1 of cacheLeafs (loading [leaf #” + i + “] from disk) took " + (part1 - start) + " millisecs.”);
start = part1;
} [/java]
The loadLeaf method (load form disk)
[java]
static TreeLeaf loadLeaf(int leafID) {
boolean success = false;
FileInputStream fis;
ObjectInputStream in;
TreeLeaf outLeaf = null;
String leafFilename = Utils.getSaveGamePath() + leafID + "\\leafData";
// FIXME: Since saved leafs won't be committed until the user has
// manually saved the game, we use ".temp" until then.
// Look for these before loading default file.
if (new File(leafFilename + ".temp").exists()) {
leafFilename += ".temp";
}
try {
fis = new FileInputStream(leafFilename);
in = new ObjectInputStream(fis);
outLeaf = (TreeLeaf) in.readObject();
in.close();
success = true;
} catch (IOException | ClassNotFoundException ex) {
Logger.getLogger(OctreeList.class.getName()).log(Level.SEVERE, null, ex);
success = false;
} finally {
if (success) {
return outLeaf;
} else {
throw new RuntimeException("Could not LOAD LEAF " + leafFilename);
}
}
}
[/java]
What I’m thinking of doing might be to use a single file, something similar to a compressed file (a la zip) into which I could dump the whole thing in memory and save when queried by user or whatever.
I’m sure some of you have suggestions or even potential fixes for better response time for deserialization of saved files.
As usual, thanks for all replies.