_NetworkRollback
Inherits: Node
Orchestrates the rollback loop.
Tutorials
Properties
| Type | Name | Default |
|---|---|---|
| bool | enabled | get_setting(...) |
| bool | enable_diff_states | get_setting(...) |
| int | history_limit | |
| int | history_start | |
| int | display_offset | |
| int | display_tick | |
| int | input_delay | |
| int | input_redundancy | |
| int | tick |
Methods
| Return Type | Name |
|---|---|
| void | notify_resimulation_start(int p_tick) |
| void | notify_simulated(Node node) |
| bool | is_simulated(Node node) |
| bool | is_rollback() |
| bool | is_rollback_aware(Object what) |
| bool | is_rollback_liveness_aware(Object what) |
| bool | is_rollback_spawn_aware(Object what) |
| bool | is_rollback_despawn_aware(Object what) |
| bool | is_rollback_destroy_aware(Object what) |
| void | process_rollback(Object target, float delta, int p_tick, bool is_fresh) |
| void | mutate(Object target, int p_tick) |
| bool | is_mutated(Object target, int p_tick) |
| bool | is_just_mutated(Object target, int p_tick) |
| void | register_rollback_input_submission(Node _node, int _tick) |
| int | get_latest_input_tick(Node node) |
| bool | has_input_for_tick(Node node, int tick) |
| void | free_input_submission_data_for(Node _node) |
Signals
before_loop ( )
Event emitted before running the network rollback loop.
on_prepare_tick ( int tick )
Event emitted in preparation of each rollback tick.
Handlers should apply the state and input corresponding to the given tick.
after_prepare_tick ( int tick )
Event emitted after preparing each rollback tick.
Handlers may process the prepared tick, e.g. modulating the input by its age to implement input prediction.
on_process_tick ( int tick )
Event emitted to process the given rollback tick.
Handlers should check if they need to resimulate the given tick, and if so, generate the next state based on the current data ( applied in the prepare tick phase ).
after_process_tick ( int tick )
Event emitted after the given rollback tick was processed.
on_record_tick ( int tick )
Event emitted to record the given rollback tick.
By this time, the tick is advanced from the simulation, handlers should save their resulting states for the given tick.
after_loop ( )
Event emitted after running the network rollback loop.
Property Descriptions
bool enabled = get_setting(...)
Whether rollback is enabled.
bool enable_diff_states = get_setting(...)
Whether diff states are enabled.
Diff states send only the state properties that have changed.
int history_limit
How many ticks to store as history.
The larger the history limit, the further we can roll back into the past, thus the more latency we can manage. The drawback is, with higher history limit comes more history data stored, thus higher memory usage.
Rollback won't go further than this limit, regardless of inputs received.
read-only, you can change this in the project settings
int history_start
The earliest tick that history is retained for.
Determined by history_limit.
read-only
int display_offset
Offset into the past for display, in ticks.
After the rollback, we have the option to not display the absolute latest state of the game, but let's say the state two frames ago ( offset = 2 ). This can help with hiding latency, by giving more time for an up-to-date state to arrive before we try to display it.
read-only, you can change this in the project settings
int display_tick
The currently displayed tick.
This is the current tick as returned by _NetworkTime.tick, minus the display_offset. By configuring the display_offset, a past tick may be displayed to the player, so that updates from the server have slightly more time to arrive, masking latency.
read-only
int input_delay
Offset into the future to submit inputs, in ticks. By submitting inputs into the future, they don't happen instantly, but with some delay. This can help hiding latency - even if input takes some time to arrive, it will still be up to date, as it was timestamped into the future. This only works if the input delay is greater than the network latency.
In cases where the latency is greater than the input delay, this can still reduce the amount of resimulated frames, resulting in less compute.
Note: the is_fresh parameter may not work as expected with input latency higher than network latency.
read-only, you can change this in the project settings
int input_redundancy
How many previous input frames to send along with the current one.
As inputs are sent over an unreliable channel, packets may get lost or appear out of order. To mitigate packet loss, we send the current and previous n ticks of input data. This way, even if the input for a given tick gets lost in transmission, the next (n-1) packets will contain the data for it.
read-only, you can change this in the project settings
int tick
The current rollback tick.
Note that this is different from _NetworkTime.tick, and only makes sense in the context of a rollback loop.
Method Descriptions
void notify_resimulation_start ( int p_tick )
Submit the resimulation start tick for the current loop. This is used to determine the resimulation range during each loop.
void notify_simulated ( Node node )
Submit node for simulation. This is used mostly internally by RollbackSynchronizer. The idea is to submit each affected node while preparing the tick, and then run only the nodes that need to be resimulated.
bool is_simulated ( Node node )
Check if node was submitted for simulation. This is used mostly internally by RollbackSynchronizer. The idea is to submit each affected node while preparing the tick, and then use is_simulated to run only the nodes that need to be resimulated.
bool is_rollback ( )
Return true if a network rollback is currently active.
bool is_rollback_aware ( Object what )
Return true if a given object is rollback-aware, i.e. has the _rollback_tick method implemented.
Used by RollbackSynchronizer and PredictiveSynchronizer to see if they should simulate the given object during rollback.
bool is_rollback_liveness_aware ( Object what )
Return true if a given object is rollback liveness aware, i.e. has any of the liveness callbacks implemented.
bool is_rollback_spawn_aware ( Object what )
Return true if what implements the _rollback_spawn callback.
bool is_rollback_despawn_aware ( Object what )
Return true if what implements the _rollback_despawn callback.
bool is_rollback_destroy_aware ( Object what )
Return true if what implements the _rollback_destroy callback.
void process_rollback ( Object target, float delta, int p_tick, bool is_fresh )
Calls the _rollback_tick method on the target, running its simulation for the given rollback tick.
This is used by RollbackSynchronizer to resimulate ticks during rollback. While the _rollback_tick method could be called directly as well, this method exists to future-proof the code a bit, so the method name is not repeated all over the place.
Note: Make sure to check if the target is rollback-aware, because if it's not, this method will run into an error.
void mutate ( Object target, int p_tick )
Marks the target object as mutated.
Mutated objects will be re-recorded for the specified tick, and resimulated from the given tick onwards.
For special cases, you can specify the tick when the mutation happened. Since it defaults to the current rollback tick, this parameter rarely needs to be specified.
Note that registering a mutation into the past will yield a warning.
bool is_mutated ( Object target, int p_tick )
Check whether the target object was mutated in or after the given tick via mutate().
bool is_just_mutated ( Object target, int p_tick )
Check whether the target object was mutated specifically in the given tick via mutate().
void register_rollback_input_submission ( Node _node, int _tick )
Register that a node has submitted its input for a specific tick
int get_latest_input_tick ( Node node )
Get the latest input tick submitted for a specific node
Returns -1 if no input was submitted for the node, ever.
bool has_input_for_tick ( Node node, int tick )
Check if a node has submitted input for a specific tick (or later)
void free_input_submission_data_for ( Node _node )
Free all input submission data for a node
Use this once the node is freed.