-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Direct users to commands.set_state instead of NextState #15127
Comments
commands.set_state
@Shatur @MiniaczQ, pulling the discussion into an issue here. I'm personally on the fence about it. I like exposing users to the "states are resources" model, but I think that the way that this implies the deferred nature of state transitions is really nice. IMO swapping state transitions to use observers and swapping purely to a command or event-based model while removing |
I like being transparent with users too, I think merging struct State {
current: S
/// Never exposed for mutability, only commands
next: Option<S>,
/// Previous (different!) S value, does not update on re-enters
previous: Option<S>,
/// How many times did this state re-enter into itself
repeats: usize,
} I'll discuss this further when I start working on it |
FYI, the reason we didn't do this initially is because it mucks with change detection. Being able to ask is the state has changed is moderately useful, and if |
Fair, but state transitions are the main way of reacting to state changes |
Back onto topic, what's the intended scope of this issue? |
commands.set_state
NextState
in favor of commands.set_state
Personally, I don't think we should update examples and docs unless we decide to fully remove |
Yeah, if we want to break states API again it should be a larger chunk, refactored until completion and in the form of a swap-in crate. |
I'm personally opposed to this because it's incompatible with the "direct mutation" feature, e.g. Direct mutation and Also, trait unification while still using |
I'm still of the opinion that partial mutation is not something we want. |
And yes, trait unification can be done at any point in time, but it's a breaking change. |
If each part of the color mode is its own state, how would you e.g. schedule a system to run on a transition from yellow to black? It would not make sense to have each field as its own state, because they cannot be interpreted separately in this example. If two systems both try to increment the level on the same frame, surely you would actually want a +2? If not, direct mutation enables I can come up with more examples where direct mutation is desirable, if the examples I've provided are not convincing. |
Also reminder that states are state machines, which are a function of current state (Dependencies, we don't have self available yet) and input signal (NextState). |
@benfrankel You can add your own |
Use 2 RGB/enum fields instead of hardcoded color flags.
No and yes. |
I'm not sure what you mean by this, but it's definitely not an architectural issue.
FWIW same-state transitions can be implemented on top of |
If we keep |
It's an issue caused by improperly structuring data.
Same state transitions cannot be implemented without major overhead, it'd need to re-simulate all the state transitions.
|
Could you elaborate? We currently have |
We still need to buffer
Yeah |
There are three ways of sending an event (not counting observer events):
I'll agree to disagree.
Nothing improper about
Well they can be, since I've done it in
Yes of course. The point is that just because it's built on top of something that's already provided by |
If you need to modify the existing solution to make it work then clearly something isn't done right.
It's the difference between being able to do it as purely additive feature (NextState and derivatives) and a feature that only works well if integrated into the core (identity transitions). If you had a If you have Those are on the opposite type of spectrum. |
Exchanging walls of text isn't very productive, we can switch over to discord if you want. |
Okay, I discussed with @MiniaczQ on Discord for a bit. Here is my conclusion from the discussion:
@MiniaczQ was not 100% sold on direct mutation as a feature, but said that the implementation details don't look too bad. However, that discussion is now off-topic for this issue as it's a separate feature and still compatible. My only remaining concern is in the discrepancy between |
NextState
in favor of commands.set_state
|
Second thoughts, I'd like this to be the standard way of updating states.
Using commands:
NextState
, especially when many are usedNextState
I don't think this change has to happen now, but it looks like a better API overall to me
Originally posted by @MiniaczQ in #15083 (comment)
The text was updated successfully, but these errors were encountered: