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

Dynamic asset management for 'game areas' #1

Open
UkoeHB opened this issue Jul 12, 2024 · 0 comments
Open

Dynamic asset management for 'game areas' #1

UkoeHB opened this issue Jul 12, 2024 · 0 comments

Comments

@UkoeHB
Copy link
Owner

UkoeHB commented Jul 12, 2024

Problem

Certain types of games dynamically load and unload assets as you move between areas. Currently, this crate assumes all assets are loaded at startup and persist until shut down.

Solution

We can support dynamic assets for game areas with the following API:

  • Add a resource GameAreas that tracks currently-active areas. You can add/remove/clear areas from this.
  • Add asset manifest loaders that are type-bound to specific 'area tags'. For example, LoadAreaImages<MyHome>. When a manifest is loaded, asset paths are cached in an areas map and only immediately loaded if the corresponding areas are active.
  • When the GameAreas resource changes, send a reactive event GameAreasUpdated. On GameAreasUpdated, enter LoadState::Loading and run systems to update all asset managers (unload assets in non-existent areas, load assets for new layers (this would be smart enough to retain assets used in multiple areas)). The user is responsible for displaying a loading screen and deciding when to switch areas.
  • Add AreaTag<T> loadable that can be used to mark scene nodes in cobweb asset files for cleanup when leaving an area.
    • It's also possible to load cobweb asset file manifests separately per area, e.g. with app.load_for_area::<T>(manifest/path.caf.json). Then when any scene root node referenced by a file loaded recursively from that manifest is spawned, we can insert AreaTag<T> automatically. We could even dynamically load and unload caf files at area transitions (to implement this we'd need to limit caf file imports to only files in the 'global area' and the 'current area'). To implement this we'd need to update how data is cleaned up post-loading, since new data could be loaded now.

Implementing this is not high priority for me, but it would address a major feature gap in this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant