Also, anything wrong with static instead of dynamic allocation? |
Well, if we use static allocation for the buffer that reads in the shipcfg files, you would be limited to how much jewelry you could put on ships, because if the section names and key names got longer than the buffer size, stuff would get cut off.
Does it work the same way the AI ships? |
Well, the AI reads in their basic hull and configuration from a shipcfg file, but then they add their weapons, etc. So yes, it will also affect the AI ships.
If I understand correctly, does this mean that you will keep in memory the contents of files corresponding to data wthat won't change. Unless I am mistaken, but once a ship has been designed, the associated shpcfg data won't change until the next use of the ship designer on that design. Maybe a dictionnary like structure maybe be useful for keeping track of buffers that you decide not to regenerate each time you are doing a save. Sometimes, it is more efficient to calculate some data one time for all and memorize them instead of calculating them each time, especially if they aren't subject to lots of modification. |
The shipcfgs will now stay in memory, parsed, until a new game is created or a save game loaded. Then they will be cleared so that there aren't a ton of shipcfgs in memory that aren't being used.
I used to save all the definitions like techs, planet improvements, etc, in a file in the temp folder, and then just copy the data if it hadn't changed, but every time you design a new ship, it changes what needs to be in that block, so it was almost always re-saving that block anyway. I could probably do it for everything except the ship designs and then just save the ship designs every time.