-
-
Notifications
You must be signed in to change notification settings - Fork 14
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 starting order for RollbackSynchronizer
#284
base: main
Are you sure you want to change the base?
Changes from 8 commits
753f44b
7a85290
bd49333
3fbe20a
4ff2351
bed38a5
4e57462
e6af3ce
77a3159
e18be09
5f55088
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ class_name RollbackSynchronizer | |
## synchronizing data between players, but with support for rollback. | ||
|
||
@export var root: Node = get_parent() | ||
## This is to give time for Input authority to be set. | ||
@export var await_first_frame: bool = true | ||
@export var state_properties: Array[String] | ||
|
||
@export_subgroup("Inputs") | ||
|
@@ -24,6 +26,7 @@ var _states: Dictionary = {} | |
var _inputs: Dictionary = {} | ||
var _latest_state: int = -1 | ||
var _earliest_input: int | ||
var _started_at_tick: int = -1 | ||
|
||
var _property_cache: PropertyCache | ||
var _freshness_store: RollbackFreshnessStore | ||
|
@@ -43,16 +46,12 @@ func process_settings(): | |
|
||
_states.clear() | ||
_inputs.clear() | ||
_latest_state = NetworkTime.tick - 1 | ||
_earliest_input = NetworkTime.tick | ||
|
||
# Gather state props - all state props are recorded | ||
for property in state_properties: | ||
var pe = _property_cache.get_entry(property) | ||
_record_state_props.push_back(pe) | ||
|
||
process_authority() | ||
|
||
# Gather all rollback-aware nodes to simulate during rollbacks | ||
_nodes = root.find_children("*") | ||
_nodes.push_front(root) | ||
|
@@ -84,13 +83,24 @@ func process_authority(): | |
_record_input_props.push_back(pe) | ||
_auth_input_props.push_back(pe) | ||
|
||
func process_time_flags(): | ||
_latest_state = NetworkTime.tick - 1 | ||
_earliest_input = NetworkTime.tick | ||
if (_started_at_tick == -1): | ||
_started_at_tick = NetworkTime.tick | ||
|
||
func _ready(): | ||
process_settings() | ||
|
||
if (await_first_frame): | ||
await get_tree().process_frame | ||
process_authority() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After |
||
|
||
if not NetworkTime.is_initial_sync_done(): | ||
# Wait for time sync to complete | ||
await NetworkTime.after_sync | ||
_latest_state = NetworkTime.tick - 1 | ||
process_time_flags() | ||
|
||
|
||
NetworkTime.before_tick.connect(_before_tick) | ||
NetworkTime.after_tick.connect(_after_tick) | ||
|
@@ -160,7 +170,9 @@ func _record_tick(tick: int): | |
# Broadcast as new state | ||
_latest_state = max(_latest_state, tick) | ||
_states[tick] = PropertySnapshot.merge(_states.get(tick, {}), broadcast) | ||
_submit_state.rpc(broadcast, tick) | ||
for picked_peer_id in multiplayer.get_peers(): | ||
if (NetworkTime.is_client_synced(picked_peer_id)): #This assumes the server is the authority -_- | ||
_submit_state.rpc_id(picked_peer_id, broadcast, tick) | ||
|
||
# Record state for specified tick ( current + 1 ) | ||
if not _record_state_props.is_empty() and tick > _latest_state: | ||
|
@@ -220,6 +232,8 @@ func _get_history(buffer: Dictionary, tick: int) -> Dictionary: | |
var latest = buffer.keys().max() | ||
|
||
if tick < earliest: | ||
_logger.warning("Tried to load tick %s which is earlier than the earliest we have recorded (%s) | ||
Try increasing the history limit." % [tick, earliest]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug comment, to confirm #260 is fixed. Place this message on |
||
return buffer[earliest] | ||
|
||
if tick > latest: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,10 +47,6 @@ func _ready(): | |
|
||
_snap_to_spawn() | ||
|
||
# TODO: What if the RollbackSynchronizer had a flag for this? | ||
# Wait a frame so Input has time to get its authority set | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And that's what I did :P |
||
await get_tree().process_frame | ||
rollback_synchronizer.process_settings() | ||
GameEvents.on_brawler_spawn.emit(self) | ||
NetworkTime.on_tick.connect(_tick) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable ultimately ended up being unused, but its useful to keep so as to know when an avatar joined/started.