Coroutine to Play Matinee

Still a :sk: noob here, so here’s another painfully obvious coroutine I’ve been using to play matinees and wait until they’re completed.

This is MatineeActor@_play()

//---------------------------------------------------------------------------------------
// Play a matinee and block until completed
//---------------------------------------------------------------------------------------

() 
[
  play
    
  loop
  [
    if not @is_playing? [exit]
    _wait
  ]
]
1 Like

Simple, yet effective. :madsci:

If performance were a concern, which it probably isn’t in this case, if you knew that the matinee were going to take at least a minute, you could have an initial _wait(50) and then do looping per frame _wait calls after that. Though no need to do unneeded optimization.

Ideally coroutines are resumed with a callback from the engine though a poll can be really easy to write.

Take a look at the InvokedBase class for some powerful methods. They are probably overkill with this example though I thought it would be a good time to point them out. You can get access to the current InvokedMethod by using this_code and then you can call the InvokedBase methods on it.

At the script level (you can do similar things with coroutines written in C++) you would do something like this:

// Set something in motion that will take time
start_stuff

// Store this current invoked coroutine for later
@invoked_coroutine: this_code
// Suspend the coroutine
this_code.pending_increment

// Some other concurrently running code calls @invoked_coroutine.pending_decrement
// and this coroutine resumes.

// Resumed
continue_stuff

This is some pretty sweet stuff, it’s like… a sempahore but without the burning? I need to sandbox some of these advanced features to really harness this beast :slight_smile:

1 Like