Skip to content
Open
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
12 changes: 9 additions & 3 deletions addons/netfox/state-synchronizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class_name StateSynchronizer
## The root node for resolving node paths in properties.
@export var root: Node

## Controls how often state updates are sent (0 = every tick). Higher values = less frequent updates.
@export_range(0, 100,1,"or_greater") var update_frequency_dial: float = 0
var _tick_counter: int = 0

## Properties to record and broadcast.
@export var properties: Array[String]

Expand Down Expand Up @@ -85,9 +89,11 @@ func _exit_tree():

func _after_tick(_dt, tick):
if is_multiplayer_authority():
# Submit snapshot
var state = PropertySnapshot.extract(_property_entries)
_submit_state.rpc(state, tick)
_tick_counter += 1
if int(update_frequency_dial) == 0 or _tick_counter % int(update_frequency_dial) == 0:
# Submit snapshot
var state = PropertySnapshot.extract(_property_entries)
_submit_state.rpc(state, tick)
else:
# Apply last received state
PropertySnapshot.apply(_last_received_state, _property_cache)
Expand Down