ecs-sandbox icon indicating copy to clipboard operation
ecs-sandbox copied to clipboard

Refactor AssetManager

Open numpad opened this issue 3 years ago • 0 comments

The current AssetManager implementation is very basic; it has subpar code quality, bad error handling/feedback and is not extremely performant.

Ideas:

  • Should be mod friendly: Open an assetmanager for a specific dir structure (like base/{images,sounds,...} and modXY/{images,...})
  • Every scene should use its own AssetManager, this way clean up is easy. Once a scene is closed the AssetManager destroys all assets used.
  • But: Engine specific stuff (like UI etc.) shouldn't need to be reloaded every time. Solution: An AssetManager can reference a parent AssetManager, if ChildAssedManager doesn't find a resource, the parent is checked.

Examine a better way to handle Assets, topics that need a rework:

  • [ ] Replace all raw with smart pointers.
  • [ ] Reimplement all assets/filetypes as generic classes.
  • [ ] Think about error handling, are nullptrs OK? Maybe default Assets are easier to handle (like Source engine). Black/Pink texture, 1s no-sound audio, Cube as default model, ...
  • [ ] Performance improvements. Dedicated functionality for preloading, store files that are already confirmed to not exist as empty instead of trying to load them everytime.
  • [ ] Memory handling. When to clean up resources?

Performance: Currently very flexible system, f.ex. AM::getAudio() tries to return a already loaded audio, if that is not yet loaded, call ::loadAudio() and return this instead. Does this make sense performance wise or is there a better system which is still flexible enough? Switch from path to ID keys for Asset key/value pairs.

Memory handling: Should resources be freed after not being used for a specific amount of time and no more references to it? Or on a per-scene/level basis?

numpad avatar Nov 07 '20 01:11 numpad