Skip to content

Commit d5ec2fb

Browse files
fix: Record inputs after gathering in after_tick (#614)
One off inputs are recorded on NetworkTİme.after_tick. Before that* commit rollback inputs were recorded from rbs after_tick. After that commit rollback inputs are recorded from network-rollback after_tick. Godot calls signals based on their connected order. Before server update rbs's were connecting their signals with a deferred call. This was resulting in one off input node winning the race. But after the server update, since servers are initialized before anything else, input nodes are always losing the race. This pr fixes the race condition by explicitly calling NetworkRollback methods, instead of relying on signal connection order. --------- Co-authored-by: Tamás Gálffy <ezittgtx@gmail.com>
1 parent d138bf4 commit d5ec2fb

7 files changed

Lines changed: 34 additions & 19 deletions

File tree

addons/netfox.extras/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.extras"
44
description="Game-specific utilities for Netfox"
55
author="Tamas Galffy and contributors"
6-
version="1.46.4"
6+
version="1.46.5"
77
script="netfox-extras.gd"

addons/netfox.internals/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.internals"
44
description="Shared internals for netfox addons"
55
author="Tamas Galffy and contributors"
6-
version="1.46.4"
6+
version="1.46.5"
77
script="plugin.gd"

addons/netfox.noray/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.noray"
44
description="Bulletproof your connectivity with noray integration for netfox"
55
author="Tamas Galffy and contributors"
6-
version="1.46.4"
6+
version="1.46.5"
77
script="netfox-noray.gd"

addons/netfox/network-time.gd

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,16 @@ func _loop() -> void:
562562
_last_process_time = _clock.get_time()
563563
while _next_tick_time < _last_process_time and ticks_in_loop < max_ticks_per_frame:
564564
if ticks_in_loop == 0:
565-
InterpolationServer._clear_teleports()
566-
InterpolationServer._apply_target_state()
567-
before_tick_loop.emit()
565+
_before_tick_loop()
568566

569567
before_tick.emit(ticktime, tick)
570-
571568
on_tick.emit(ticktime, tick)
572-
573569
after_tick.emit(ticktime, tick)
570+
571+
# Record data for rollback
572+
NetworkRollback._after_tick(tick)
573+
574+
# Record data for StateSynchronizer
574575
NetworkHistoryServer._record_sync_state(tick + 1)
575576
NetworkSynchronizationServer._synchronize_sync_state(tick + 1)
576577

@@ -579,12 +580,27 @@ func _loop() -> void:
579580
_next_tick_time += ticktime
580581

581582
if ticks_in_loop > 0:
582-
after_tick_loop.emit()
583-
NetworkHistoryServer._restore_synchronizer_state(tick)
584-
InterpolationServer._record_next_state()
583+
_after_tick_loop()
585584

585+
# Send queued network identities
586586
NetworkIdentityServer.flush_queue()
587587

588+
func _before_tick_loop() -> void:
589+
InterpolationServer._clear_teleports()
590+
InterpolationServer._apply_target_state()
591+
before_tick_loop.emit()
592+
593+
func _after_tick_loop() -> void:
594+
# Run rollback loop
595+
NetworkRollback._rollback()
596+
597+
# Emit signal
598+
after_tick_loop.emit()
599+
600+
# Restore state for StateSynchronizer
601+
NetworkHistoryServer._restore_synchronizer_state(tick)
602+
InterpolationServer._record_next_state()
603+
588604
func _process(delta: float) -> void:
589605
_process_delta = delta
590606

addons/netfox/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox"
44
description="Shared internals for netfox addons"
55
author="Tamas Galffy and contributors"
6-
version="1.46.4"
6+
version="1.46.5"
77
script="netfox.gd"

addons/netfox/rollback/network-rollback.gd

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,6 @@ func _get_rollback_destroy_method(object: Object) -> Callable:
341341

342342
func _ready():
343343
NetfoxLogger.register_tag(_get_rollback_tag)
344-
NetworkTime.after_tick_loop.connect(_rollback)
345-
NetworkTime.after_tick.connect(func(_dt, tick):
346-
NetworkHistoryServer._record_rollback_input(tick + input_delay)
347-
NetworkSynchronizationServer._synchronize_input(tick + input_delay)
348-
)
349344

350345
NetworkSynchronizationServer._on_input.connect(_handle_input)
351346
NetworkSynchronizationServer._on_state.connect(_handle_state)
@@ -446,6 +441,10 @@ func _rollback() -> void:
446441
_mutated_nodes.clear()
447442
_is_rollback = false
448443

444+
func _after_tick(tick: int) -> void:
445+
NetworkHistoryServer._record_rollback_input(tick + input_delay)
446+
NetworkSynchronizationServer._synchronize_input(tick + input_delay)
447+
449448
func _handle_input(snapshot: _Snapshot):
450449
if snapshot.is_empty():
451450
return

test/network-mocks.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ static func in_rollback(callback: Callable) -> void:
2323

2424
## Runs [param callback] in the network tick loop
2525
static func in_network_tick_loop(callback: Callable) -> void:
26-
NetworkTime.before_tick_loop.emit()
26+
NetworkTime._before_tick_loop()
2727
callback.call()
28-
NetworkTime.after_tick_loop.emit()
28+
NetworkTime._after_tick_loop()
2929

3030
## Runs [param callback] as part of a network tick
3131
static func in_network_tick(callback: Callable) -> void:

0 commit comments

Comments
 (0)