taisei-project / taisei

A free and open-source Touhou Project fangame
https://taisei-project.org/
Other
940 stars 88 forks source link

New resource delivery system for Emscripten port #352

Closed Akaricchi closed 1 year ago

Akaricchi commented 1 year ago

Resource files are no longer packaged and preloaded all in advance. Instead, they are downloaded while the game is running.

The implementation is less than ideal, but it works. Resources are requested on demand and cached into IDBFS. Unfortunately, since the resource system was not designed with web-style asynchrony in mind and we aren't ready for threads either, we have no way to do any useful work while a required file is downloading. To somewhat offset that, we also pre-fetch files that were not requested yet. The pre-fetching is limited to 4 files at a time, which seems to be a reasonable compromise between throughput and cold-cache load latency on slow connections. Also unfortunately, it's dumb as rocks: we have no way of knowing which files we will actually be needing soon, so the pre-fetching is done in whatever order the files were indexed.

Possibly the easiest way to improve this system would be to bundle (and compress) all of the tiny text files together to alleviate the overhead of hundreds of HTTP requests.