leopard
leopard copied to clipboard
Implement Scratch-like sequencer behavior
Depends on #210.
This PR makes a few changes as progress towards #212:
- Instead of stepping each script once per frame, we do what Scratch does and keep going until a redraw is requested or we run out of frametime.
- Therefore, requesting redraws has also been implemented. Most functions which cause something visual to change on-screen request a redraw.
- The state that corresponds to a running script (namely the generator) has been moved out of
Trigger
and into its own class calledThread
. Threads can:- Be "parked"--if it is waiting for a promise to resolve, it will park itself until the promise resolves.
- Yield to another thread--that is, if the other thread is parked, the yielding thread will park itself as well, and ask the other thread to wake it up.
- Be restarted in-place, without worrying about stale promise state.
Generator functions that are running as Leopard threads can await promises without having to be async themselves using the new Thread.await
function.