Skip to content

Commit c7fc6ea

Browse files
authored
fix: RewindableAction to handle later ticks (#534)
When modifying a rewindable action from outside of its parent, it may set a tick in one loop, but not in the next one. For example, the player hits a spike, and the spike sets the RewindableAction for tick 15. On the next loop, the player doesn't hit the spike on tick 15, but is also not simulated for tick 15 since it doesn't have input. This results in TicksetSerializer's assert failing, because there's an active tick past the last set one. Instead, RewindableAction now serializes the last set tick, even if it was not set in the current loop. TicksetSerializer will not serialize ticks outside of the specified range. Fixes #532
1 parent da82e7a commit c7fc6ea

File tree

8 files changed

+33
-6
lines changed

8 files changed

+33
-6
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.35.2"
6+
version="1.35.3"
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.35.2"
6+
version="1.35.3"
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.35.2"
6+
version="1.35.3"
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.35.2"
6+
version="1.35.3"
77
script="netfox.gd"

addons/netfox/rewindable-action.gd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,12 @@ func _after_loop() -> void:
203203

204204
# Submit
205205
if is_multiplayer_authority() and _last_set_tick >= 0:
206-
var active_tick_bytes = _TicksetSerializer.serialize(NetworkRollback.history_start, _last_set_tick, _active_ticks)
206+
var serialize_from := NetworkRollback.history_start
207+
var serialize_to := _last_set_tick
208+
if not _active_ticks.is_empty():
209+
serialize_to = maxi(_active_ticks.max(), serialize_to)
210+
211+
var active_tick_bytes = _TicksetSerializer.serialize(serialize_from, serialize_to, _active_ticks)
207212
_submit_state.rpc(active_tick_bytes)
208213

209214
@rpc("authority", "unreliable_ordered", "call_remote")

addons/netfox/serializers/tickset-serializer.gd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ static func serialize(earliest_tick: int, latest_tick: int, active_ticks: _Set)
1212
buffer.put_u8(tickset_duration)
1313

1414
for tick in active_ticks:
15-
assert(tick <= latest_tick, "Trying to serialize ticks beyond latest !")
15+
# Don't serialize before range
16+
if tick < earliest_tick: continue
17+
# Don't serialize past range
18+
if tick > latest_tick: break
1619
buffer.put_u8(tick - earliest_tick)
1720

1821
return buffer.data_array

test/netfox/serializers/tickset-serializer.test.gd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ func test_should_serialize_ticks():
3333
expect_equal(deserialized[1], latest_tick)
3434
expect_equal(deserialized[2], active_ticks)
3535

36+
func test_should_serialize_only_range():
37+
# Given
38+
var earliest_tick = 16
39+
var latest_tick = 20
40+
var active_ticks = _Set.of([15, 16, 20, 24])
41+
42+
# When
43+
var bytes = _TicksetSerializer.serialize(earliest_tick, latest_tick, active_ticks)
44+
var deserialized = _TicksetSerializer.deserialize(bytes)
45+
46+
# Then
47+
expect_equal(deserialized[0], earliest_tick)
48+
expect_equal(deserialized[1], latest_tick)
49+
expect_equal(deserialized[2], _Set.of([16, 20]))
50+
3651
func test_should_fail_on_earliest_after_latest():
3752
# Given
3853
var earliest_tick = 42

test/network-mocks.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ static func in_network_tick(callback: Callable) -> void:
3636
## Runs a single network tick
3737
static func run_network_tick() -> void:
3838
in_network_tick(NOOP)
39+
40+
## Runs a single-tick network tick loop
41+
static func run_network_tick_loop() -> void:
42+
in_network_tick_loop(NOOP)

0 commit comments

Comments
 (0)