RollbackSynchronizer
Inherits: Node
Similar to MultiplayerSynchronizer, this class is responsible for synchronizing data between players, but with support for rollback.
Tutorials
Properties
| Type | Name | Default |
|---|---|---|
| Node | root | get_parent() |
| bool | enable_prediction | false |
| String[] | state_properties | |
| int | full_state_interval | 24 |
| int | diff_ack_interval | 0 |
| String[] | input_properties | |
| bool | enable_input_broadcast | true |
| PeerVisibilityFilter | visibility_filter | new() |
Methods
| Return Type | Name |
|---|---|
| void | process_settings() |
| void | process_authority() |
| void | add_state(Variant node, String property) |
| void | add_input(Variant node, String property) |
| void | set_schema(Dictionary schema) |
| void | merge_schema(Dictionary schema) |
| void | clear_schema() |
| bool | has_input() |
| int | get_input_age() |
| bool | is_predicting() |
| void | ignore_prediction(Node node) |
| int | get_last_known_input() |
| int | get_last_known_state() |
| void | spawn(int p_tick) |
| void | despawn(int p_tick) |
| bool | is_alive(int p_tick) |
Property Descriptions
Node root = get_parent()
The root node for resolving node paths in properties. Defaults to the parent node.
bool enable_prediction = false
Toggle prediction.
Enabling this will run _rollback_tick on nodes under root even if there's no current input available for the tick.
String[] state_properties
Properties that define the game state.
State properties are recorded for each tick and restored during rollback. State is restored before every rollback tick, and recorded after simulating the tick.
int full_state_interval = 24
Ticks to wait between sending full states.
If set to 0, full states will never be sent. If set to 1, only full states will be sent. If set higher, full states will be sent regularly, but not for every tick.
Only considered if _NetworkRollback.enable_diff_states is true.
int diff_ack_interval = 0
No description provided.
String[] input_properties
Properties that define the input for the game simulation.
Input properties drive the simulation, which in turn results in updated state properties. Input is recorded after every network tick.
bool enable_input_broadcast = true
This will broadcast input to all peers, turning this off will limit to sending it to the server only. Turning this off is recommended to save bandwidth and reduce cheating risks.
PeerVisibilityFilter visibility_filter = new()
Decides which peers will receive updates
Method Descriptions
void process_settings ( )
Process settings.
Call this after any change to configuration. Updates based on authority too ( calls process_authority ).
Process settings based on authority.
Call this whenever the authority of any of the nodes managed by RollbackSynchronizer changes. Make sure to do this at the same time on all peers.
void add_state ( Variant node, String property )
Add a state property.
Settings will be automatically updated. The node may be a string or NodePath pointing to a node, or an actual Node instance. If the given property is already tracked, this method does nothing.
void add_input ( Variant node, String property )
Add an input property.
Settings will be automatically updated. The node may be a string or NodePath pointing to a node, or an actual Node instance. If the given property is already tracked, this method does nothing.
void set_schema ( Dictionary schema )
Set the schema for transmitting properties over the network.
The schema must be a dictionary, with the keys being property path strings, and the values are the associated NetworkSchemaSerializer objects. Properties are interpreted relative to the root node. The schema can contain both state and input properties. Properties not specified in the schema will use a generic fallback serializer. By using the right serializer for the right property, bandwidth usage can be lowered.
See NetworkSchemas for many common serializers.
Example:
rollback_synchronizer.set_schema({
":transform": NetworkSchemas.transform3f32(),
":velocity": NetworkSchemas.vec3f32(),
"Input:movement": NetworkSchemas.vec3f32()
})
void merge_schema ( Dictionary schema )
Add serializers from schema.
See set_schema() for specifying schema. As opposed to set_schema(), this method updates the schema, instead of overriding it. If a property had a serializer specified previously, this will replace it.
void clear_schema ( )
Clear any serializers specified earlier.
See set_schema().
bool has_input ( )
Check if input is available for the current tick.
This input is not always current, it may be from multiple ticks ago.
Returns true if input is available.
int get_input_age ( )
Get the age of currently available input in ticks.
The available input may be from the current tick, or from multiple ticks ago. This number of tick is the input's age.
bool is_predicting ( )
Check if the current tick is predicted.
A tick becomes predicted if there's no up-to-date input available. It will be simulated and recorded, but will not be broadcast, nor considered authoritative.
void ignore_prediction ( Node node )
Ignore a node's prediction for the current rollback tick.
Call this when the input is too old to base predictions on. This call is ignored if enable_prediction is false.
int get_last_known_input ( )
Get the tick of the last known input.
This is the latest tick where input information is available. If there's locally owned input for this instance ( e.g. running as client ), this value will be the current tick. Otherwise, this will be the latest tick received from the input owner.
If enable_input_broadcast is false, there may be no input available for peers who own neither state nor input.
Returns -1 if there's no known input.
int get_last_known_state ( )
Get the tick of the last known state.
This is the latest tick where information is available for state. For state owners ( usually the host ), this is the current tick. Note that even this data may change as new input arrives. For peers that don't own state, this will be the tick of the latest state received from the state owner.
void spawn ( int p_tick )
Mark the spawn tick for all nodes managed by this synchronizer.
When rewinding to a tick earlier than the spawn tick, every managed node will be deactivated.
void despawn ( int p_tick )
Mark the despawn tick for all nodes managed by this synchronizer.
When rewinding to a tick later than the despawn tick, every managed node will be deactivated.
bool is_alive ( int p_tick )
Return true if nodes managed by this synchronizer are alive.
Note that this method assumes that all node liveness is managed by the synchronizer. If some node livenesses are handled separately, this method may return the wrong liveness. In that case, use _RollbackLivenessServer.is_alive() and check for individual nodes.