Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Disconnect signals on exiting tree #341

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/netfox.extras/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="netfox.extras"
description="Game-specific utilities for Netfox"
author="Tamas Galffy"
version="1.14.1"
version="1.14.2"
script="netfox-extras.gd"
2 changes: 1 addition & 1 deletion addons/netfox.internals/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="netfox.internals"
description="Shared internals for netfox addons"
author="Tamas Galffy"
version="1.14.1"
version="1.14.2"
script="plugin.gd"
2 changes: 1 addition & 1 deletion addons/netfox.noray/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="netfox.noray"
description="Bulletproof your connectivity with noray integration for netfox"
author="Tamas Galffy"
version="1.14.1"
version="1.14.2"
script="netfox-noray.gd"
2 changes: 1 addition & 1 deletion addons/netfox/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="netfox"
description="Shared internals for netfox addons"
author="Tamas Galffy"
version="1.14.1"
version="1.14.2"
script="netfox.gd"
27 changes: 21 additions & 6 deletions addons/netfox/rollback/rollback-synchronizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,7 @@ func process_authority():
_auth_input_property_entries.push_back(property_entry)
_record_input_property_entries.push_back(property_entry)

func _ready():
if not NetworkTime.is_initial_sync_done():
# Wait for time sync to complete
await NetworkTime.after_sync
process_settings.call_deferred()

func _connect_signals():
NetworkTime.before_tick.connect(_before_tick)
NetworkTime.after_tick.connect(_after_tick)
NetworkRollback.before_loop.connect(_before_loop)
Expand All @@ -145,6 +140,26 @@ func _ready():
NetworkRollback.on_record_tick.connect(_record_tick)
NetworkRollback.after_loop.connect(_after_loop)

func _disconnect_signals():
NetworkTime.before_tick.disconnect(_before_tick)
NetworkTime.after_tick.disconnect(_after_tick)
NetworkRollback.before_loop.disconnect(_before_loop)
NetworkRollback.on_prepare_tick.disconnect(_prepare_tick)
NetworkRollback.on_process_tick.disconnect(_process_tick)
NetworkRollback.on_record_tick.disconnect(_record_tick)
NetworkRollback.after_loop.disconnect(_after_loop)

func _enter_tree():
if not NetworkTime.is_initial_sync_done():
# Wait for time sync to complete
await NetworkTime.after_sync
_connect_signals.call_deferred()
process_settings.call_deferred()

func _exit_tree():
_is_initialized = false
_disconnect_signals()

func _before_loop():
if _auth_input_property_entries.is_empty():
# We don't have any inputs we own, simulate from earliest we've received
Expand Down
13 changes: 11 additions & 2 deletions addons/netfox/state-synchronizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@ func process_settings():
var property_entry = _property_cache.get_entry(property)
_property_entries.push_back(property_entry)

func _ready():
process_settings()
func _connect_signals():
NetworkTime.after_tick.connect(_after_tick)

func _disconnect_signals():
NetworkTime.after_tick.disconnect(_after_tick)

func _enter_tree():
_connect_signals.call_deferred()
process_settings.call_deferred()

func _exit_tree():
_disconnect_signals()

func _after_tick(_dt, tick):
if is_multiplayer_authority():
# Submit snapshot
Expand Down
14 changes: 12 additions & 2 deletions addons/netfox/tick-interpolator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,26 @@ func teleport():
_state_from = PropertySnapshot.extract(_property_entries)
_state_to = _state_from

func _ready():
process_settings()
func _connect_signals():
NetworkTime.before_tick_loop.connect(_before_tick_loop)
NetworkTime.after_tick_loop.connect(_after_tick_loop)

func _disconnect_signals():
NetworkTime.before_tick_loop.disconnect(_before_tick_loop)
NetworkTime.after_tick_loop.disconnect(_after_tick_loop)

func _enter_tree():
process_settings()
_connect_signals.call_deferred()

# Wait a frame for any initial setup before recording first state
if record_first_state:
await get_tree().process_frame
teleport()

func _exit_tree():
_disconnect_signals()

func _process(_delta):
_interpolate(_state_from, _state_to, NetworkTime.tick_factor)

Expand Down