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

feat: eliminate need to pass context to states #26

Merged
merged 11 commits into from
Dec 23, 2023

Conversation

definitelyokay
Copy link
Member

@definitelyokay definitelyokay commented Dec 23, 2023

  • Eliminates the need for states to have explicit constructors that receive an IContext object. Instead, the context is provided when a state is attached to a logic block as the logic block's active state. Eliminating contexts in state constructors simplifies serialization and reduces typing.
  • Adds OnAttach and OnDetach, which can and should be used for setting up a state instance. These differ from OnEnter and OnExit, respectively, as all callbacks registered via OnAttach and OnDetach will be called on the state instance whenever the state changes, whereas OnEnter and OnExit are only invoked when entering and exiting relevant states with respect to the type hierarchy. OnAttach and OnDetach are great for subscribing to events or other long-running operations that need to be cleaned up on a per-instance basis. Before, previous state instances would be implicitly retained in memory if relevant to the active state's type hierarchy. Now, LogicBlocks is more theoretically sound as only one state is active and retained at any given time.
  • Eliminates the context parameter in GetInitialState.
  • Adds a shorthand method for looking up blackboard contents inside a state via the Get<TDataType>() method available to states.

@definitelyokay definitelyokay marked this pull request as ready for review December 23, 2023 19:17
@definitelyokay definitelyokay merged commit 63deab1 into main Dec 23, 2023
4 checks passed
@definitelyokay definitelyokay deleted the feat/context-free branch December 23, 2023 19:18
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.

None yet

1 participant