aroberge / reeborg

Enhanced Karel-the-robot clone
http://reeborg.ca/reeborg.html
Other
47 stars 36 forks source link

Add visual clue that program is being "compiled" #424

Closed aroberge closed 6 years ago

aroberge commented 6 years ago

Long running programs (which occur more often when using Python than Javascript) may give the impression that nothing is happening. Previously, I had tried to implement a UI feature where some window would be shown prior to evaluating the user's code but, due to the single threaded nature of Javascript and the way I had implemented the function, the window was never shown. However, there is a way around this and it might be worth revisiting this issue.

When clicking on the "run" button, instead of doing something like

// not the real code
function run() {
    eval(code);
    playback_frames();
}

it might be useful to do the following instead:

function _run() {
    eval(code);
    hide_visual();
    playback_frames();
}
function run() {
    show_visual();
    setTimeout(_run, 1); // delay thread so that UI update can take place
}

Edit

An alternative might be to have eval(code) be done, somehow, in a webworker, and have it use postMessage every time a new frame is recorded, so that the frame display is updated.

aroberge commented 6 years ago

done on March 13