Skip to content

refactor: Store state and inputs in HistoryBuffers as PropertySnapshots#399

Merged
elementbound merged 30 commits intofoxssake:mainfrom
DustieDog:RollbackRefactor
Feb 20, 2025
Merged

refactor: Store state and inputs in HistoryBuffers as PropertySnapshots#399
elementbound merged 30 commits intofoxssake:mainfrom
DustieDog:RollbackRefactor

Conversation

@DustieDog
Copy link
Copy Markdown
Collaborator

Successor to #397, as it was easier to rewrite than bugfix. This PR has functional diff states, and a cleaner codebase implementing most requested changes from the previous PR.

Reinstated only core _HistoryBuffer functionality.
Refactored _get_history() into _HistoryBuffer.
Cleaned up comments, added typing where needed.
Added _PropertyStoreSnapshot, removing the need for PropertySnapshot from RollbackSynchronizer.
Fixed missing conversion.
Reformatted PropertyStoreSnapshot.
Added typing comments to RollbackSynchronizer dictionaries.
Added trim feature to HistoryBuffer and refactored out of RollbackSynchronizer.
Refactored _sanitize_by_authority into PropertyStoreSnapshot.
Fixed merge both merging to self and returning PropertyStoreSnapshot.
Updated comments.
Fixed if statement formatting.
# Typed as Dictionary[int, _PropertyStoreSnapshot]
var _buffer: Dictionary = {}

func get_snapshot(tick: int, default = {}) -> _PropertyStoreSnapshot:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is default still needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow missed that line 10 doesn't use default. I kept this to keep consistency with how Dictionary.get() works, with the intention of line 10 returning defualt, but we should be able to remove it if preferred.

if _buffer.has(tick):
return _buffer[tick]
else:
return _PropertyStoreSnapshot.new()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking whether returning just null would make sense, to avoid an extra alloc, but I'll have to read the rest of the PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in line with how RollbackSynchronizer handled things previously, as exampled the following line:
_states[tick] = PropertySnapshot.merge(_states.get(tick, {}), full_state)

I'm not sure if anything else would break with it returning null.

var closest_tick = get_closest_tick(tick)

if closest_tick == -1:
return _PropertyStoreSnapshot.new()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment here, might be worth returning a null here.

var sender = multiplayer.get_remote_sender_id()
var sanitized = _sanitize_by_authority(state, sender)
var sanitize_success := deserialized.sanitize(sender, _property_cache)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note as with inputs above

DustieDog and others added 9 commits February 12, 2025 19:28
Removed get_snapshot_as_dictionary, as it's succeeded by PropertyStoreSnapshot.as_dictionary().
Updated _HistoryBuffer as per @elementbound's PR comments.
Updated _PropertyStoreSnapshot as per @elementbound's PR comments.
Updated RollbackSynchronizer as per @elementbound's PR comments.
Fixed assigning empty state to HistoryBuffer if no valid diffs were transmitted.
@DustieDog DustieDog marked this pull request as ready for review February 15, 2025 21:20
@elementbound elementbound changed the title Rollback Refactor: HistoryBuffer Rewrite refactor: Store state and inputs in HistoryBuffers as PropertySnapshots Feb 19, 2025
@elementbound elementbound changed the base branch from epic/refactor-rollback-synchronizer to main February 19, 2025 21:39
@elementbound elementbound merged commit d13829f into foxssake:main Feb 20, 2025
@DustieDog DustieDog deleted the RollbackRefactor branch March 27, 2025 21:46
@DustieDog DustieDog restored the RollbackRefactor branch March 27, 2025 21:46
@DustieDog DustieDog deleted the RollbackRefactor branch March 27, 2025 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants