Try My Godot Maze Solver
My previous post gave a brief overview of my experience trying to make a basic GUI with the Godot game engine. I had mentioned that Godot provided an HTML5 export option. So how about that?
Well, it works! Kinda. The C# support isn’t 100% there yet, so certain features such as async
/await
and Parallel
won’t export to HTML as of writing. Good news is my maze solver works perfectly without either of those, so I hit the big red “export” button (it’s not actually red) and let it generate (oh! it’s also “export project”, not “export”) my glorious online maze solver…
Maze Solver: WEB EDITION
The “export project” function produced a directory with several files in it, one of which was conspicuously MazeSolver.html
. I decided to open this in a browser and…it didn’t work. Looking at the console revealed why: For security reasons, browsers don’t like when a script tries to load other scripts via file://
. For this to work, it would have to be served by a proper web server. Enter: Python’s SimpleHTTPServer.
We simply issue this command in the output directory (assuming we have Python installed): python3 -m http.server 8000
, and off we go! Everything is now being hosted on a local web server at port 8000.
The first thing I noticed is that everything was horrifically slow and my laptop sounded like it was ready for takeoff. What the heck? Why is this thing using all my CPU? So I did what any self-respecting code monkey would do and ran the profiler. It found the culprit quickly enough:
function _usleep(useconds) {
var msec = useconds / 1e3;
if ((ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && self["performance"] && self["performance"]["now"]) {
var start = self["performance"]["now"]();
while (self["performance"]["now"]() - start < msec) {}
} else {
var start = Date.now();
while (Date.now() - start < msec) {}
}
return 0
}
It’s clear that this function is meant to busy-wait for a precise amount of time. However, doing so eats a ridiculous amount of CPU time. I reckoned maybe we could use JS’s SetTimeout()
and sacrifice a bit of timing precision for acceptable performance since this isn’t actually a game after all. Sure enough, the webapp worked smoothly enough after that (it’s still a bit of a performance hog). I would be lying if I said I knew what that _usleep
method was for, or why it was being used for long-enough periods to render the entire app nigh-unusable. Maybe something in my project config?
Anyways, without further ado, Click Here to be A-Mazed!