Yes, that's correct. Assuming by "index" you mean the value of the index attribute of the SystemBody type, which corresponds with the bodyIndex property of the SystemPath type.TheBob wrote:First, the structure bases on the assumption that the indices of static bodies in a system is always the same. Is that assumption correct?
My advice would be: Worry about maintainability and forward compatibility, not savefile size. There will be lots of core changes that will affect the save file format, in particular we plan to switch to a JSON based format for flexibility (*), and that's not exactly a space-efficient format. If savefile size becomes a problem, the first thing we'll do (because it's basically trivial and doesn't require changes elsewhere in the code) is to pump the data through a general purpose compression library. After that, my guess is that speed of writing (generating) or loading (parsing) the save files is likely to be a more pressing problem than savefile size, and that will require more thought and wider changes.TheBob wrote:Since the project I'm working on is a potential savefile bloater, it is important to me to save the stuff as efficiently as possible. I have the most efficient structure here, but I'm not sure if it's really going to work, and I have even less idea of what LUA will do with it exactly.
No more than 256 bodies per system is probably valid right now, but I have no particular reason to believe it will be valid in the future. The internal SystemPath structure, which provides a unique identifier for any static body in the game, uses a 32-bit integer for the body index. That's probably overkill, but right now putting tight limits on things would just cause headaches for no useful gain. For example, what happens if we want to generate a large number of dwarf planets or major asteroids, or place large numbers of artificial satellites (comms. satellites, navigation markers, sensor pods, zero-g manufacturing plants, goods depots, etc etc) in orbit around heavily populated planets?TheBob wrote:Also, it seems unrealistic that any system has more than 256 static bodies, so a BYTE should be enough to store the body index.
Having said all that, I don't believe it's my place to dictate how modders work, so I shall try to answer your other questions. As you correctly surmised, Lua doesn't pack things into the smallest possible data type. In fact, Lua only deals with a single numeric type (64-bit double precision floating point), and when we serialise Lua data into the save file, it's written as a decimal number, so it doesn't even remotely meet your criteria.
Your best bet if you want to pack data tightly is to do your own serialisation. Lua strings are just blobs (ie, byte arrays), and you can put whatever byte values you want into them. For efficiency you should be careful about how you build this data up: It's usually best to build a table of substrings and then use table.concat to join them into one. If you do it by having a single string variable that you keep appending small chunks to, then performance will suffer (there's an explanation of this in Programming in Lua). To make a string from an arbitrary series of byte values, use string.char. To extract the byte values from a string, use string.byte.
But: If you intend on submitting this work to be merged into the main game distribution (and I hope you will, because I would like us to have more missions and more content in general), then I would ask you to please make life easy for us and keep custom packing/serialisation code isolated, so that it's easy to remove if necessary.
(*) It's very embarrassing that updates to the game often make existing save files useless. We would like to stop that, but we need to be able to keep changing the content of the saves as features are added and changed. The point of switching to a JSON based format is to help make this possible.