derkork / godot-statecharts

A state charts extension for Godot 4
MIT License
797 stars 43 forks source link

Add reentrace lock to _run_transition #83

Closed MidZik closed 7 months ago

MidZik commented 7 months ago

Fixes part of #82. This PR should ensure that all state_entered and state_exited signals emit in the correct order.

The example from #82 now has this order:

[576]: Transition: On Grab from x/Idle to x/Try Grabbing
[576]: exiT: Idle 
[576]: Enter: Try Grabbing
[576]: Transition: To Grabbing from x/Try Grabbing to x/Grabbing Something
[576]: exiT: Try Grabbing
[576]: Enter: Grabbing Something

I noticed that most of the logic to handle a queue of events has already been written, but the bool that enables it wasn't being used. Did some quick testing to verify it fixed the out of order problem and that the examples weren't broken, and everything seems fine from what I could tell.

This PR does not fix the transitions being evaluated multiple times, so the "ignored transition for inactive state" warning may still appear.

derkork commented 7 months ago

Thanks a lot for supplying this, it helped a lot in identifying and fixing the issue. Since i did some internal reorganization, this will no longer fit the code, so I'm going to close this. Thanks again!