pioneers / pimulator-js

Portable robotics simulator for the Pioneers in Engineering robotics kit (JavaScript edition)
3 stars 1 forks source link

[SIMULATOR] Run every `Robot.run()` function in its own thread #100

Closed charleshong3 closed 2 years ago

charleshong3 commented 3 years ago

Functions run during setup using Robot.run() should each run in their own thread, and main should also run in a thread. This would match how Runtime works. However, this will be difficult to implement with our current WebWorker/Pyodide setup and will likely be a longer project.

We would likely need to spawn a worker for each Robot.run() call, then have each worker contain a wrapper Robot class whose functions trigger a postMessage() that changes the state of the root worker (which contains the master definition of the robot's current state). One challenge is figuring out how to pass the code to each worker, especially with regards to how the global student code variables (Robot, Gamepad, Keyboard) are stored.