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

Building, serving/loading and hot reloading #12

Open
Tracked by #764
FredrikNoren opened this issue Jan 25, 2023 · 3 comments
Open
Tracked by #764

Building, serving/loading and hot reloading #12

FredrikNoren opened this issue Jan 25, 2023 · 3 comments
Labels
topic:assets Asset loading, streaming, etc

Comments

@FredrikNoren
Copy link
Contributor

FredrikNoren commented Jan 25, 2023

In general, all assets (scripts, models, sounds etc.) have three "phases" in Ambient;

  • Building: We take a source asset (.fbx, .wav, a rust crate, etc.) and turn it into a format consumable by Ambient
  • Serving/loading: That asset is loaded into memory by Ambient
  • Hot reloading: The source asset has changed, so we re-run the two first steps and update the game with the new asset

Building
The core idea here is that conceptually we always run a full build. However, the build consist of "build nodes", for instance we might have a PipeImage node which takes a source image, transforms it (resize for instance) and then outputs the result in the target directory. The build node can check if the output file(s) is newer than the input file(s), and if that's the case it can skip that build node.

Builds can be triggered in a number of ways, such as running ambient build or by the hot-reload watcher detecting that any of the source input files have changed

Serving/Loading
Once the assets have been built, they can be served. The important thing here though is that we have to assume that they are served over the network. We also have to assume that they might be served from a static http content server. More over, the assets are normally also cached on the client side (see BytesFromUrl).

Hot reloading
Hot reloading consists of two parts; on the server side we need to detect when anything changes in the source files, and then we should run a full build. And then once the build has finished, we need to figure out which output assets have changed, and then notify all clients (including the running server) which assets have been invalidated. They then need to re-load those assets, potentially with some cache breaking (like for instance adding ?cache_break=random_id to the url).

@erlend-sh
Copy link

erlend-sh commented Mar 6, 2023

@chaosprint
Copy link
Contributor

There are several levels of hot reloading:

I think one pain point in development currently (without an editor) is that when adjusting certain parameters, constant values, or initial values, we have to keep recompiling (or is there a solution already?). If these initial values could be stored in a file (like ambint.toml ) and refreshed immediately once changed, it would be much more comfortable experience.

@philpax
Copy link
Contributor

philpax commented Nov 8, 2023

There's currently a hack in place for hot-reloading WASM modules that will ignore the asset cache and always fetch the latest version when [client_]module_from_url changes. We should remove that hack once we get hot-reloading in proper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:assets Asset loading, streaming, etc
Projects
None yet
Development

No branches or pull requests

4 participants