Skip to content

Commit 7be2a3c

Browse files
authored
fix: Always clear RewindableAction queue after loop (#527)
Fixes #517
1 parent ab6089b commit 7be2a3c

File tree

7 files changed

+48
-11
lines changed

7 files changed

+48
-11
lines changed

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.34.0"
6+
version="1.34.1"
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.34.0"
6+
version="1.34.1"
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.34.0"
6+
version="1.34.1"
77
script="netfox-noray.gd"

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.34.0"
6+
version="1.34.1"
77
script="netfox.gd"

addons/netfox/rewindable-action.gd

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,11 @@ func dont_mutate(target: Object) -> void:
138138

139139
func _connect_signals() -> void:
140140
NetworkRollback.before_loop.connect(_before_rollback_loop)
141-
NetworkRollback.on_process_tick.connect(_process_tick)
142-
NetworkTime.after_tick_loop.connect(_after_tick_loop)
141+
NetworkRollback.after_loop.connect(_after_loop)
143142

144143
func _disconnect_signals() -> void:
145144
NetworkRollback.before_loop.disconnect(_before_rollback_loop)
146-
NetworkTime.after_tick_loop.disconnect(_after_tick_loop)
145+
NetworkRollback.after_loop.disconnect(_after_loop)
147146

148147
func _enter_tree() -> void:
149148
_connect_signals()
@@ -170,11 +169,11 @@ func _before_rollback_loop() -> void:
170169
for mutated in _mutated_objects:
171170
NetworkRollback.mutate(mutated, earliest_change)
172171

173-
func _process_tick(tick: int) -> void:
174-
if _queued_changes.has(tick):
175-
set_active(_queued_changes[tick])
172+
# Apply queue
173+
for tick in _queued_changes:
174+
set_active(_queued_changes[tick], tick)
176175

177-
func _after_tick_loop() -> void:
176+
func _after_loop() -> void:
178177
# Trim history
179178
for tick in _active_ticks:
180179
if tick < NetworkRollback.history_start:
@@ -221,6 +220,9 @@ func _submit_state(bytes: PackedByteArray) -> void:
221220
# Don't compare past last event, as to not cancel events the host simply doesn't know about
222221
var latest_tick = maxi(last_known_tick, NetworkRollback.history_start)
223222

223+
if earliest_tick > NetworkTime.tick or latest_tick > NetworkTime.tick:
224+
_logger.warning("Received tickset for range @%d>%d, which has ticks in the future!", [earliest_tick, latest_tick])
225+
224226
for tick in range(earliest_tick, latest_tick + 1):
225227
var is_tick_active = active_ticks.has(tick)
226228
if is_tick_active != is_active(tick):
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
extends VestTest
2+
3+
func get_suite_name():
4+
return "RewindableAction"
5+
6+
var rewindable_action: RewindableAction
7+
8+
func before_case(__) -> void:
9+
rewindable_action = RewindableAction.new()
10+
# TODO(vest): Some good way to add nodes to the tree
11+
await NetworkTime.get_tree().process_frame
12+
NetworkTime.get_tree().root.add_child(rewindable_action)
13+
14+
func after_case(__) -> void:
15+
rewindable_action.free()
16+
17+
func test_should_empty_queue_after_loop():
18+
# Run as client
19+
rewindable_action.set_multiplayer_authority(2)
20+
21+
# Prepare changes
22+
var tickset := _Set.of([0])
23+
var data := _TicksetSerializer.serialize(0, 4, tickset)
24+
NetworkMocks.set_tick(4, 4)
25+
26+
# Run first loop
27+
rewindable_action._submit_state(data) # Server sends data
28+
NetworkMocks.run_network_tick_loop()
29+
expect(rewindable_action.has_confirmed(), "RewindableAction was not confirmed!")
30+
31+
# Run second loop
32+
rewindable_action._submit_state(data) # Server sends data again
33+
NetworkMocks.run_network_tick_loop()
34+
expect_not(rewindable_action.has_confirmed(), "RewindableAction was redundantly confirmed!")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://bjj3hqe3obauq

0 commit comments

Comments
 (0)