Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resource delivery system for Emscripten port #352

Merged
merged 4 commits into from
Jan 27, 2023

Conversation

Akaricchi
Copy link
Member

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.

This is currently unused. It's going to be the backbone for a new
on-the-fly resource fetching system for the Emscripten port.

In this mode, the virtual resource directory structure is embedded into
the executable. Files are referenced by their "content IDs", which are
currently their sha256 hashes. The "resindex" VFS backend allows one to
define a custom file open function, which connects the content IDs to
actual data. A example implementation is provided in resindex_layered,
which simply opens the content ID as a file under a specified VFS path.
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.
@Akaricchi Akaricchi merged commit e2c0282 into master Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant