简体   繁体   中英

How to load a specific object from a SER-file

I'm saving my game world using serialization. The world is basically a big ArrayList containing each area map object . The number of area maps is fixed , but they vary greatly in size (between 5-30 mB each). So I don't want to have the entire world loaded in memory during runtime, only the specific area maps that the player's characters are located in.

Is it possible to load specific area maps without loading the entire world (or in other words: loading a specific object without deserializing the whole SER-file)? Likewise I need to save specific area maps (when all characters have left the area). Note that the size (in data) of the area map could have changed significantly, since the player could potentially move hundreds of objects from one area to another.

The point of this question is that I want to avoid storing each map in it's own SER-file. That would be A LOT of files, which will become even more with each save the player has. So my goal is to pack it up nicely in a single save-file.

What you could do is create a numbering system for each of your area maps. Afterwards, store an array containing these area maps in a serializable. Unload the serializable to obtain an array, and store it in some form of variable. You could then use your numbering system to select the map which you would want to use.

So to answer your question, I do not think it is possible, because the way a serializable is deserialized is it goes through all the serialized fields one by one. You cannot select something from the middle of a SER-file to deserialize.

Happy Programming:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM