Cerealization
This is a good point for actually using a first form of save state, as the initialization is now computationally intensive. So far, the following things take place:
- Load configuration files to create/initialize systems
- Load/initialize resources: textures, texture atlases, shaders, renderers, framebuffers, widgets, application states, etc etc
- Create world
- Generate (or use cached) a biome map
- Generate (or use cached) autotiling data
- Generate (or use cached) a resource map
- Generate cities, territory map, factions, mines, relationships, etc
- Generate (or use cached) pathfinding routes
In the above, 'or use cached' implies an adhoc piece of code that looks for a cache file with the results of the process and uses that, or runs the calculations and dumps the results in the end. It exists only in certain parts, when the outputs are very contained, e.g. a 2D array of data.
At this point, I need to serialize the entire "Create world" process, but now the generated results are not simple anymore:
- Some new resources
- Completely new state of several systems
- State of existing resources (initialized now, not initialized before)
I've already prepared for that, and I'm using the library cereal for serialization. Currently the process is mostly complete, so the whole "Create world" process takes very little time, as it just serializes data from a 6MB file.
Currently I need to "standardize" serialization of GPU resources (textures, buffer objects), which is a bit trickier but doable. The way it's getting implemented is as follows:
- JSON configuration initializes a config structure, specific to the GPU object, e.g. cTextureConfig has ( dims, target, format, iformat, dtype, miplevels, data, etc)
- The config structure is used to initialize the object
- A member function can update the config structure from the current state of the GPU resource (this is mainly for textures/buffers that have been updated)
- cereal out: update the config structure from current state, then serialize out the config structure
- cereal in: load from disk to the config structure, then call Init()
- json in: load from the json file to the config structure, then call Init()
I can also implement GPU resource cloning using this config update mechanism