Skip to content

Rollback aware state machine#315

Merged
elementbound merged 21 commits intofoxssake:mainfrom
krazyjakee:rollback-aware-state-machines
Oct 31, 2024
Merged

Rollback aware state machine#315
elementbound merged 21 commits intofoxssake:mainfrom
krazyjakee:rollback-aware-state-machines

Conversation

@krazyjakee
Copy link
Copy Markdown
Contributor

@krazyjakee krazyjakee commented Oct 26, 2024

Introduces the NetworkedStateMachine and NetworkedState in netfox.extras as per the spec at #302

  • Create NetworkedStateMachine logic
  • Create NetworkedState logic
  • Clone the multiplayer-netfox example and use the state machine instead
  • Ensure working rollback and rollforward
  • Add built-in history management
  • Add editor warnings to guide user with RollbackSynchronizer config - @elementbound
  • Update class docs - @elementbound
  • Update docs site - @elementbound
  • Add custom icons - @elementbound

@krazyjakee krazyjakee force-pushed the rollback-aware-state-machines branch from 02d02ec to 986cd78 Compare October 26, 2024 23:57
Copy link
Copy Markdown
Contributor

@elementbound elementbound left a comment

Choose a reason for hiding this comment

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

Kudos for the contrib, it's a solid PR! 🎉

@elementbound
Copy link
Copy Markdown
Contributor

Also, feel free to focus on the feature implementation, I'm happy to take care of the docstrings and doc site update.

@krazyjakee
Copy link
Copy Markdown
Contributor Author

krazyjakee commented Oct 28, 2024

2 issues currently:

  1. When the host jumps, the state is immediately rolled back to Idle can_enter as it's testing whether it's still on the ground. For the client, this isn't an issue. Removing the can_enter logic resolves the issue.
[INF][@787][#1][netfox.extras::NetworkedStateMachine] [Fresh: true] [Rollback: true] Transitioned from state Idle into Jump
[INF][@788][#1][netfox.extras::NetworkedStateMachine] [Fresh: true] [Rollback: true] Transitioned from state Jump into Idle
[INF][@788][#1][netfox.extras::NetworkedStateMachine] [Fresh: true] [Rollback: true] Transitioned from state Idle into Jump
[INF][@789][#1][netfox.extras::NetworkedStateMachine] [Fresh: true] [Rollback: true] Transitioned from state Jump into Idle
[INF][@787][#553236475][netfox.extras::NetworkedStateMachine] [Fresh: true] [Rollback: true] Transitioned from state Idle into Jump
[INF][@789][#553236475][netfox.extras::NetworkedStateMachine] [Fresh: true] [Rollback: true] Transitioned from state Jump into Idle
  1. When the client jumps, it works fine until the client lands. Then it ping pongs between the Jump and Idle states.

image

explorer_20ey2SN81v.mp4

@krazyjakee
Copy link
Copy Markdown
Contributor Author

krazyjakee commented Oct 28, 2024

explorer_ZRbUXxgqWW.mp4

This now seems to be resolved. The issue was can_enter is much more important than I thought. It must guard the state perfectly. We need some mental model to clearly explain how to use this.

Something like...

In a networked state machine, can_enter acts as a crucial "guard rail," ensuring that every transition into a state is intentional and meets all necessary conditions. Networked environments introduce unpredictability, like desyncs and rollbacks, so we can't fully trust that every state entry is happening under ideal circumstances. This makes can_enter essential for confirming all preconditions are met before a state change occurs, preventing unwanted behaviors, glitches, or "ping-ponging" between states.

By setting can_enter to verify key requirements—such as input presence, environmental conditions (like being on the ground), or timing constraints - you create a stable foundation for each state. This validation enforces continuity and predictability, regardless of how or when a state transition is triggered.

@elementbound
Copy link
Copy Markdown
Contributor

Feature itself seems stable, I've updated the PR description with some tasks for myself.

@elementbound elementbound added the feature New feature or request label Oct 31, 2024
@krazyjakee
Copy link
Copy Markdown
Contributor Author

great!

@elementbound elementbound merged commit 9c95109 into foxssake:main Oct 31, 2024
@krazyjakee krazyjakee deleted the rollback-aware-state-machines branch November 26, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants