Open kreibaum opened 5 months ago
Download model before unlocking the play button. Also load it and perform an action on an example state.
Branch https://github.com/kreibaum/pacosako/tree/ai-preload will now preload the AI in the main menu. I also show preload progress in the game view, but that does not fix the error reload problem yet. But at least it explains better what is going on.
I won't merge this until I have time to do some "old-code"/"new-code" testing, as I am afraid the download changes may "corrupt" something about the model cache.
On demand downloads of onnx-runtime backends are also just part of the "Setting up Runtime" step which sucks on bad network connection. I think I need a service worker to intercept those fetch requests and to report progress.
https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
Performance: https://developer.mozilla.org/en-US/docs/Web/API/InstallEvent/addRoutes -> Nope, this isn't actually supported in Firefox.
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#examples
It appears I need to use "scope" for this.
There is frequent confusion surrounding the meaning and use of scope. A service worker can't have a scope broader than its own location, unless the server specifies a broader maximum scope in a Service-Worker-Allowed header on the service worker script. Therefore you should use the scope option when you need a narrower scope than the default.
TODO: Write a service worker that logs all the web requests it can see to understand if requests to other origins are even visible to it. If not, try the header.
When playing against Hedwig on a 6 Mbit/sec connection (or slower) downloading the model takes more than 10 seconds which resets the download :-(