Hi i need some help with OutputCapsule .
It looks pretty nice and useful ,but i wonder if i can make some sort of list or alse of capsuls.
Lets say i have several castles villages and soldiers,and i need to save them all and then read them all…
The problem is here https://wiki.jmonkeyengine.org/jme3/advanced/save_and_load.html
it teach me how to make a capsul for simple class made of classes existing in java ,like int string and soo on .
But lets say i need to take a list of Soldier’s that are made of ints and other made by me classes . And more than this
i actually need to have a list ,soo in game i will make a FOR and create all soldiers from all capsules …
Soo what i need is may be some massive usage of capsule or some thing similar …
Any one had any expirience or ideas ?
I cant paste mutch classes simply couse i have not even created all of them but soldier
Has all most common ints - lvl ,cash ,stamina soo on , while castles have houses ,walls other stuff ,houses has soldiers and soo on .
Is it possible to make entire self made classes saveble object ? soo lets say save list of soldiers and not only data soldier have ?
JME’s serialization system (JmeImporter/JmeExporter/InputCapsule/OutputCapsule/Savable) should work for what you’re doing. The key is to put all your savable state into classes that implement the Savable (read/write) interface. InputCapsule and OutputCapsule provide methods for reading and writing arrays, arraylists, maps, and so on.
ehm could you please if possible give me a code sample of how it could look.
Like lets say you have 3 objects of class Shop and 10 objects of class Car in each shop, soo how could i save it properly ,and most important get to read them properly ?
Class Shop {
int cash;
ArrayList <Car> list;
}
Class Car{
int carType;
}
should be right now
I 've got it how to save one object ,but dont know how to save lots of objects ,like a full list of objects with their lists of objects.
And more complicated is how to load a list of objects and create list of objects from incapsulated list
If the JmeImporter hasn’t already seen the shopWhereItFrom object, it will create a new one. If it has seen it before, then I believe it uses the pre-existing one.
class Shop implements Serializable {
int cash;
ArrayList<Car> list;
public Car() {
}
}
class Car implements Serializable {
int carType;
public Car() {
}
}
And in this case, GSON versions of Shop and Car:
class Shop {
int cash;
ArrayList<Car> list;
public Car() {
}
}
class Car {
int carType;
public Car() {
}
}
…because there are no shared references, GSON will work without anything special.
Java’s built in serialization is super powerful, though. Can handle complex object graphs, overriding read/write if necessary, etc… I think the only feature JME has over it is the ability to alternately output XML… but it gives up a lot and is way uglier to do that. Plus, I think there are already tools to examine Java serialization files. (If not then I should write one because it would be simple.)
Well car refers to shop and shop to car ,and lots of car refers to one shop ,while one shop refers to lots of cars, so we have all types of refferences
The only issue with java serialization is that generally people use it without any “class version management”, so old saves often quickly become unreadable. In many contexts this doesn’t matter. But in some, it does.
I am using JME serialization for mesh data. Seems fine to me. Any reason why i shouldn’t use it?
You have identical problems with JME’s format. There is no magic to serialization… except at least in Java serializations case if you set the serialization version of the class then a bunch of stuff happens automatically for you.
It’s ugly and limiting. You have to write all kinds of serialization code just to make it work as good as Java serialization does without any of that code.