Using hsmcpp in gamedev #6
-
I want to use hsmcpp in game render loop. Is it possible repeatedly execute some function for active states (including parent and substates) ? registerSelfTransition(MyState, UpdateEventID, TransitionType::INTERNAL_TRANSITION, []{ draw calls here }) In render loop: But if I understand right the documentation, self trasition will be executed only for the current active substate (not parent). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello @ershovdz. In general, the easiest way to repeatedly trigger some event for active states would be to use a repeating timer: But if I understand right the documentation, self transition will be executed only for the current active substate (not parent). I have a feeling you are trying to do something like scene composition using state machine (so that each state only knows how to render part of the scene). If that's the case, this might not be the best approach. State machine can't guarantee execution time so you probably will end up with inconsistent frame rate or (if one of the callbacks would take too long to execute) even stalled animations. I could recommend you to consider using getActiveStates API inside your rendering loop to decide on the scene composition. This function returns a list of currently active states in accordance with HSM hierarchy. For example, if state Child_1_2 is active call to this API will return [Parent, Child_1, Child_1_2]: This way you could keep rendering and game rules/events separate and not block each other. |
Beta Was this translation helpful? Give feedback.
-
Keeping rendering and app state separate - seems to be good idea. I will try to use getActiveStates. Thanks for the tip ! |
Beta Was this translation helpful? Give feedback.
Hello @ershovdz.
In general, the easiest way to repeatedly trigger some event for active states would be to use a repeating timer:
But if I understand right the documentation, self transition will be executed only for the current active substate (not parent).
Yes, if both child and parent have exactly same event defined then only child's transition will be executed (Priority of transitions). So no, it's impossible to execute some function for both parent and active child on a single event. But there are way to workaround it (for example by using 2 different events for parent and for children and triggering parent event from a child self-transition).
I have a feeling you are trying to do …