Unity WebGL player doesn't support multi-threaded mode.
The current implementation of SeedLangExamples projects runs SeedLang VM in a separate thread that queues main thread actions with an ActionQueue.
For running SeedLangExamples in web pages with Unity WebGL player, we need to run SeedLang VM in a Unity co-routine that stays in the main thread.
The simplest example:
public IEnumerator SeedLangCoroutine(...) {
setup seedlang engine...
while (!stopping) {
engine.RunStep(...);
yield return null;
}
}
It's also required to sync up between the animation coroutine and the SeedLang coroutine. For example, in the current SortingBot project, the SeedLang engine runs the code, queues a "Swapping" animation to the main thread, and waits for the end of the animation queue, then continues the execution of the code (otherwise, the animation sequence will be out-of-sync of the program execution). When migrating the current multi-thread mode to the coroutine mode, the same sync-up behavior must be supported somehow.
For syncing up between the animation coroutine and the SeedLang VM coroutine, the ideal solution is to support C#-to-SeedPython and SeedPython-to-C# bidirectional coroutines. But this solution is a bit complex since it requires SeedPython to support the same underlying mechanism of C#'s coroutine. We can use simple callback closures or C#'s async/premise to do this first.
Unity WebGL player doesn't support multi-threaded mode.
The current implementation of SeedLangExamples projects runs SeedLang VM in a separate thread that queues main thread actions with an ActionQueue.
For running SeedLangExamples in web pages with Unity WebGL player, we need to run SeedLang VM in a Unity co-routine that stays in the main thread.
The simplest example:
It's also required to sync up between the animation coroutine and the SeedLang coroutine. For example, in the current SortingBot project, the SeedLang engine runs the code, queues a "Swapping" animation to the main thread, and waits for the end of the animation queue, then continues the execution of the code (otherwise, the animation sequence will be out-of-sync of the program execution). When migrating the current multi-thread mode to the coroutine mode, the same sync-up behavior must be supported somehow.
For syncing up between the animation coroutine and the SeedLang VM coroutine, the ideal solution is to support C#-to-SeedPython and SeedPython-to-C# bidirectional coroutines. But this solution is a bit complex since it requires SeedPython to support the same underlying mechanism of C#'s coroutine. We can use simple callback closures or C#'s async/premise to do this first.