11extends Node
2+ class_name _NetworkRollback
23
34## Whether rollback is enabled.
45var enabled : bool = ProjectSettings .get_setting ("netfox/rollback/enabled" , true )
@@ -7,7 +8,9 @@ var enabled: bool = ProjectSettings.get_setting("netfox/rollback/enabled", true)
78##
89## The larger the history limit, the further we can roll back into the past,
910## thus the more latency we can manage.
10- ##
11+ ## [br][br]
12+ ## Rollback won't go further than this limit, regardless of inputs received.
13+ ## [br][br]
1114## [i]read-only[/i], you can change this in the project settings
1215var history_limit : int :
1316 get :
@@ -21,7 +24,7 @@ var history_limit: int:
2124## state of the game, but let's say the state two frames ago ( offset = 2 ).
2225## This can help with hiding latency, by giving more time for an up-to-date
2326## state to arrive before we try to display it.
24- ##
27+ ## [br][br]
2528## [i]read-only[/i], you can change this in the project settings
2629var display_offset : int :
2730 get :
@@ -33,7 +36,7 @@ var display_offset: int:
3336##
3437## With UDP - packets may be lost, arrive late or out of order.
3538## To mitigate this, we send the current and previous n ticks of input data.
36- ##
39+ ## [br][br]
3740## [i]read-only[/i], you can change this in the project settings
3841var input_redundancy : int :
3942 get :
@@ -78,6 +81,8 @@ var _resim_from: int
7881var _is_rollback : bool = false
7982var _simulated_nodes : Dictionary = {}
8083
84+ static var _logger : _NetfoxLogger = _NetfoxLogger .for_netfox ("NetworkRollback" )
85+
8186## Submit the resimulation start tick for the current loop.
8287##
8388## This is used to determine the resimulation range during each loop.
@@ -97,7 +102,7 @@ func notify_simulated(node: Node):
97102##
98103## This is used mostly internally by [RollbackSynchronizer]. The idea is to
99104## submit each affected node while preparing the tick, and then use
100- ## [code] is_simulated[/code ] to run only the nodes that need to be resimulated.
105+ ## [member is_simulated] to run only the nodes that need to be resimulated.
101106func is_simulated (node : Node ):
102107 return _simulated_nodes .has (node )
103108
@@ -117,10 +122,10 @@ func is_rollback_aware(what: Object) -> bool:
117122## simulation for the given rollback tick.
118123##
119124## This is used by [RollbackSynchronizer] to resimulate ticks during rollback.
120- ## While the _rollback_tick method could be called directly as well, this method
121- ## exists to future-proof the code a bit, so the method name is not repeated all
122- ## over the place.
123- ##
125+ ## While the [code] _rollback_tick[/code] method could be called directly as
126+ ## well, this method exists to future-proof the code a bit, so the method name
127+ ## is not repeated all over the place.
128+ ## [br][br]
124129## [i]Note:[/i] Make sure to check if the target is rollback-aware, because if
125130## it's not, this method will run into an error.
126131func process_rollback (target : Object , delta : float , p_tick : int , is_fresh : bool ):
@@ -144,7 +149,15 @@ func _rollback():
144149
145150 # to = Current tick
146151 var to = NetworkTime .tick
147-
152+
153+ # Limit number of rollback ticks
154+ if to - from > history_limit :
155+ _logger .warning (
156+ "Trying to run rollback for ticks %d to %d , past the history limit of %d " %
157+ [from , to , history_limit ]
158+ )
159+ from = NetworkTime .tick - history_limit
160+
148161 # for tick in from .. to:
149162 for tick in range (from , to ):
150163 _tick = tick
0 commit comments