Controller Settings Binary Schema
This section describes the binary schema for serializing controller settings efficiently.
The schema is designed to pack the settings data tightly to minimize storage space.
The data assumes it is not aligned.
Schema Overview
The controller settings data is stored as a sequence of bytes, with each setting represented by a group of bytes.
All multi-byte values are stored in little-endian format. The file is 4 byte aligned.
This file is not as aggressively packed as the other configs.
The number of times a user rebinds is usually small. And we can still make use of SOLID compression.
Header
| Field | Type | Description |
|---|---|---|
version |
u8 | The file version. Currently 0. |
num_controllers |
u8 | The number of controller specific settings. |
num_players |
u8 | The number of player slots. |
reserved |
u8 |
Controller Entry
This involves a sequence of settings for each controller.
| Field | Type | Description |
|---|---|---|
controller_index |
u8 | The unique identifier for the controller. |
reserved |
u8 | Unused |
config_size |
u16 | The size of the embedded regular config in bytes. |
config_data |
u8[config_size] |
Config data serialized using Standard Binary-Format.md |
Player Entry
This involves a sequence of settings for each player.
| Field | Type | Description |
|---|---|---|
file_size |
u19 | The size of the file. |
num_settings |
u13 | The number of settings (for each player). |
file_size is in lower bits, num_settings is in higher bits.
num_settings is constrained to 8191.
Hopefully that's sufficient.
Size: 4 bytes
Binding Header
Each setting entry in the binary data follows this format:
| Field | Type | Description |
|---|---|---|
setting_index |
u16 | The unique index of the setting. |
num_bindings |
u8 | The number of bindings for the setting. |
padding |
u8 | Currently unused. |
binding_data |
[binding-entry][config-schema] | The serialized data for each binding. |
Size: 4
Binding Entry
Each binding entry within a setting follows this format:
| Field | Type | Description |
|---|---|---|
controller_index |
u8 | The index of the gamepad to which the binding applies. |
type |
u8 | The type of the binding (0: button, 1: axis, 2: hat). |
value |
u8 | The value of the binding ([button, axis, or hat constant][available-bin2dings]). |
comparison |
u8 | The comparison operator for axis bindings (0: >=, 1: <=). |
threshold |
f32 | The threshold value for axis bindings. |
deadzone |
f32 | The deadzone value for axis bindings. |
radius |
f32 | The radius value for axis bindings. |
scale |
f32 | The scale value for button bindings to emulate an axis. |
Size: 20 bytes
Serialization Steps
- Write the header.
- For each controller:
- Write the
controller_indexas a 1-byte unsigned integer. - Serialize the regular config data for the controller's settings according to the
Binary-Format.mdschema. - Write the size of the serialized config data as a 2-byte unsigned integer (
config_size). - Write the serialized config data.
- Write the
- For each player:
- Write the
file_sizeandnum_settingsas a 4-byte value, withfile_sizein the lower 19 bits andnum_settingsin the upper 13 bits. - For each setting:
- Write the
setting_indexas a 2-byte unsigned integer. - Write the
num_bindingsas a 1-byte unsigned integer. - For each binding in the setting:
- Write the
controller_indexas a 1-byte unsigned integer. - Write the
typeas a 1-byte unsigned integer. - Write the
valueas a 2-byte unsigned integer. - Write the
thresholdas a 4-byte floating-point value. - Write the
comparisonas a 1-byte unsigned integer. - Write the
deadzoneas a 4-byte floating-point value. - Write the
radiusas a 4-byte floating-point value. - Write the
scaleas a 4-byte floating-point value.
- Write the
- Write the
- Write the
Deserialization Steps
- Read the header.
- For each controller (repeated
num_controllerstimes):- Read the
controller_indexas a 1-byte unsigned integer. - Read the
config_sizeas a 2-byte unsigned integer. - Read
config_sizebytes of serialized regular config data. - Deserialize the regular config data according to the
Binary-Format.mdschema.
- Read the
- For each player (repeated
num_playerstimes):- Read the
file_sizeandnum_settingsas a 4-byte value. - Extract
file_sizefrom the lower 19 bits andnum_settingsfrom the upper 13 bits. - For each setting (repeated
num_settingstimes):- Read the
setting_indexas a 2-byte unsigned integer. - Read the
num_bindingsas a 1-byte unsigned integer. - For each binding (repeated
num_bindingstimes):- Read the
controller_indexas a 1-byte unsigned integer. - Read the
typeas a 1-byte unsigned integer. - Read the
valueas a 2-byte unsigned integer. - Read the
thresholdas a 4-byte floating-point value. - Read the
comparisonas a 1-byte unsigned integer. - Read the
deadzoneas a 4-byte floating-point value. - Read the
radiusas a 4-byte floating-point value. - Read the
scaleas a 4-byte floating-point value. - Reconstruct the binding entry using the read values.
- Read the
- Read the
- Reconstruct the setting entry using the
setting_index,num_bindings, and the list of binding entries.
- Read the