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

Loading assets per scene instead of all assets #128

Open
JamesTKhan opened this issue Nov 8, 2022 · 2 comments
Open

Loading assets per scene instead of all assets #128

JamesTKhan opened this issue Nov 8, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@JamesTKhan
Copy link
Owner

Is your feature request related to a problem? Please describe.
Currently Mundus loads all assets on both the Editor and Runtime when loading a project. This is fine for small projects, and even makes scene switching fast, but becomes less practical in large projects with lots of assets.

Describe the solution you'd like
Look into refactoring asset loading to only load what is needed for the current scene to see if its viable.

Additional context
This could be a pretty sizable refactor of the loading system and is not a high priority.

@JamesTKhan JamesTKhan added the enhancement New feature or request label Nov 8, 2022
@Mr00Anderson
Copy link

Still down for having this as a feature? One proposed approach:

I've been experimenting with loading assets per scene (screen) by wrapping the AssetManager so that each scene has its own context-aware tracker. In my approach, when a scene loads assets, they’re tagged to that scene and can be unloaded when the scene is disposed. I'm also incorporating reference counting to ensure that if an asset is shared between scenes, it isn’t disposed prematurely, along with a cache flag to prevent early unloading.

Looking ahead, I’ve been contemplating a more granular system using “asset packs” that scenes can load. With asset packs, the entire collection of assets for a scene is managed as a unit. This would allow packs to be swapped in and out easily and even support shared settings across scenes. In such a design, the cache flag might become unnecessary because the pack itself could be marked to prevent auto-unload when it leaves the current context.

What do you think about expanding on this idea?

@Dgzt
Copy link
Collaborator

Dgzt commented Feb 25, 2025

Still down for having this as a feature? One proposed approach:

I've been experimenting with loading assets per scene (screen) by wrapping the AssetManager so that each scene has its own context-aware tracker. In my approach, when a scene loads assets, they’re tagged to that scene and can be unloaded when the scene is disposed. I'm also incorporating reference counting to ensure that if an asset is shared between scenes, it isn’t disposed prematurely, along with a cache flag to prevent early unloading.

I like this idea.

Currently Mundus stores the assets in an assets.txt file, as a list. Here is the reason why.

And this is the current flow:

mundus = new Mundus(Gdx.files.internal("mundus")); // Here Mundus loads all assets (what are in the assets.txt file)
scene = mundus.loadScene("Main Scene.mundus"); // Here Mundus loads / initialzes scene what can be rendered

And as I understand:

  • Somehow need to split "assets.txt" into scene based "assets.txt" (or stored the list as a map?).
  • Should move the assets loading part from Mundus constructor into loadScene method.
  • Need an unloadScene method (or something similar) what decreases the scene used asset's reference count and disposes unused assets

Right?

And as I understand these logic would work with custom loaded assets (like sound like here) because the scenes don't change it's reference count.

And if we want to use the application like now (to load all assets at startup) then need to load all scenes.

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

No branches or pull requests

3 participants