Save directory in the SaveGame class

Hey

i played arround a little bit with saving my game state.

I used the JME SaveGame class and also tooked a try with the BinaryExporter (which is also used in the SaveGame class)

i also tried to write my own save game class (used Serializer), which i rejected, cause there is no easy way to save the data from a Node

I decided to use the SaveGame class but i don’t know how i can change the default save dir (under the user homes directory) called .jme
I see that the jmesystem.getstoragefolder function is used where i can set INTERNAL and EXTERNAl which is pointing on the same /.jme directory. (also described in this topic JmeSystem.getStorageFolder() updates - #9 by danomano)

So my question:
can i change this default directory by using the SaveGame class or need i write my own class with the BinaryExporter?

1 Like

Is there a nice way to save 3D matrix e.g. int ?

i’ve seen the OutputCapsule.write cant write byte, float, int … 2D arrays but no 3D arrays.
my workaround for this is currently

for(int i =0; i < matrix.length; i++) {
capsule.write(matrix.get(i), “row_”+i, default);
}

I’m not sure if it helps: https://jmonkeyengine.github.io/wiki/jme3/advanced/save_and_load.html

Further more I have no clue what you try to do or want to achieve. I guess you tread Node and Spatials as game objects, which is the wrong way. You should separate game objects and visual stuff and only store your game objects. I personally do it that way and store my game objects (not visual things just data) with Jackson https://www.mkyong.com/java/jackson-2-convert-java-object-to-from-json/ 2 hours to get how to use it (just wrote some test code).

As I said no clue if it helps. The stuff you ask above I can not answer as I don’t use that so far.

2 Likes

Have you tried to look into the SourceCode to see if there is a way to change the path?
You can use the OutputCapsules/BinaryWriter along with a new File() but that’s not desirable.
What is your intention when changing the path?

Simple Reason why OutputCapsule is bad:

Linux: /home/<username>/.mygame
MacOS: /Users/<username>/.mygame or even /Application Support/MyGame
Windows: C:\Users\<username>\AppData\Local\Roaming\MyGame or
C:\Users\<username>\Documents\MyGame\ or 
Whatever MS recommends (C:\Users\<username>\Saved Games\ or such)

Then the Windows App Store and Apples AppStore might also have rules on where to save which you have to follow.
Note: You can’t write to C:\Programs\ anymore without admin rights.

So unless you have good reasons and want to reinvent the wheel, probably try to stick to the same path.
See AppSettings, maybe they contain something like a SaveGame Folder.

Regards your int[][][]: That’s not implemented since the Engine doesn’t use it since its also a hint that you are doing things wrong.
Even if you had Object or Integer as types, you would have 4 or 8 Byte per Entry.
Imagine you’d have a { [0..10], [0..10], [0..10]} space, then you’d have: 10^3 * 8 == 8000 Byte == 8kB just for empty values. Also note that expanding the space by doubling it leads to a 2^3 == 8 times the memory usage.

So 0…20 would be 64kB just for an empty file.

You CAN save some space (e.g. by iterating over x and nulling if for a given x all y == z == null), but that is just too much work for corner cases.

If you want to use those to store something by coordinates, rather use a LinkedList or maybe a HashMap. And then you can always serialize your own classes by extending Savable

Edit: You can however use those three dimensional arrays, if you don’t use them to store coordinates, so when your space is really limited, but I don’t really see a use.
Also note that the inbuilt JME System is better than something like jackson in terms of size and it’s a bit of a protection to save game manipulation (Though you can also use XmlWriter, if you don’t want them to be binary)

1 Like

This link is that what i already tried out

i dont save my visual stuff cause i dont need to save it. I load all this stuff when i initialize my classes.
i only need stuff from my game onjects (like positions, userdata and so on)

my save class is working fine
as i said i use the jmonkey SaveGame class (in the Sample Code of your link), but there i cant say where it should save my file

i ve taken a look into the SourceCode and find no way to set the path i want,
cause this will be handlend internal by the file (if i understand correct, and this will set the path to System.getproperty(“user.home”) which means on windows “C:\user<username>.jme” )

so i guess this should be no problem on other systems cause it is set the path by the systems specific path

i use the 3D matrix only to save a small couble of field (and yes these values are coordinates), but you are right. it is really stupid to save many empty coords.
i guess i try to save them as an on written wrapper ( so i save only what i need)
thank you for that