Saving and Loading Game State¶
Level File Format¶
Static scene objects are defined by render
component of an entity.
Only difference for static object is the static flag, defined in the entity.
Static scene object can have any other components defined as well, such as script or sound.
Level is described by simple json or msgpack:
{
"settings": {
"render": {
"resources": {
"levelID": [
"Zip:models/packs/levelResourcePack.zip"
]
},
"colourBackground": "0xc0c0c",
"colourAmbient": "0x7F7F7F",
"colourDiffuse": "0xc0c0c"
},
"script": {
"hooks": {
"camera": "setOrbitalCam()",
"damageEmitter": "emitter.create('damage')"
}
}
},
"entities": [{
"id": "castle",
"render": {
"root": {
"position": "0,0,0",
"rotation": "1,0,-1,0",
"scale": "1,1,1",
"children": [{
"type": "model",
"mesh": "castle.mesh",
"name": "castle",
"castShadows": true
}]
}
}
}
]
}
"settings"
section is used to reconfigure all engine systems
for the particular level. It works in the similar way as the global config.
In this example, "render"
and script
systems are configured, and have the following settings:
"resources"
contains list of resources, that are required for the level. Each resource list is identified by unique id to make shared resources reusable between different levels."script"
has some level startup script hooks defined.
"entities"
section describes entity list to be used as static scene elements.
Loading Levels¶
All levels are stored in the same folder. Level can be loaded by calling Gsage::GameDataManager::loadArea()
.
This will initialize all static entities and reconfigure systems.
By default, level folder path is resources/levels
.
Game data manager is configured in the gameConfig.json file, see Gsage::GameDataManager Config for more information.
Levels information should be considered as constant. Game data loader is designed with thoughts that levels information will be stored in the single archive, which won’t be changed.
To provide ability to modify levels information and save dynamic entities states, save files are used.
Note
Currently save file copies the whole level information. There is plan to save only difference between initial data and save
To load save file Gsage::GameDataManager::loadSave()
function can be used.
Save file format differs from level file format a bit:
save file saves level information in the field
area
.
Several new Fields:
characters
saves all characters information.placement
saves positions of all characters on all locations.settings
saves global configs for systems (can be used for render system settings customizations).
Note
Save file format might change in the future. settings
is likely to be removed.
Saving Levels¶
Each engine component and system supports serialization. All settings, that can be read from configs also can be dumped to config files.
This allows Gsage::GameDataManager
to iterate all systems and entities and dump their state to file.
Save file can be created by calling Gsage::GameDataManager::dumpSave()
.
Note
There is no method to modify level file itself yet. It will be created for editor purposes later.
Lua Bindings¶
game:loadSave("save1234")
game:dumpSave("save1234")