Rework asset system 2 : electric boogaloo #70

Open
opened 2022-08-02 12:07:25 +02:00 by kazhnuz · 3 comments
Owner

The current asset system have several flaws:

  • We have to reimport some assets for every scenes, complicating the process +
  • No "lazy loading" ability + error if we try loading an asset that's not here
  • Each name of asset is defined from each scene, no unique identifier
  • The loading process needing to be done manually make impossible some stuff, like easy global sound effect for menu (as we need to "name" and reapplying it) or default font (same)
  • Don't scale well, if we have for instance 100+ monster for an RPG battlesystem, we have to either load all of them at battle start, either add a manual function to load a custom different monster in code.
  • The asset folder have no organisation.

In order to solve all that, we should:

  • Make the asset system global, disconnected from both core and scene.
  • Add a loader/scrapper system that would search all the folder and generate assets lists that would contain the path and a medatafile if the asset type need one
  • Add subfolder support : the sound "sounds/menu/confirm.wav" would be name "menu.confirm"
  • Add a dynamic cache system with a global and local cache. Reset the local cache each scene
  • Add "asset handlers" that'll handle the actuall assets (like assets.sounds), to make most common case easier. Kill asset subtypes when possible.
  • When an asset is accessed (via an assets.get(type, name), assets.handler.get(name) or stuff like assets.sfx.play(name)), if it's not in the cache, load it in local cache.
  • Add handling a "preload.lua" file to handle preloading files without code, but also do a assets.preload(name, type, isGlobal) and assets.handler.preload(name, isGlobal) functions.
  • Add also some preloadAll in order to keep some elements from the current asset system
The current asset system have several flaws: - We have to reimport some assets for every scenes, complicating the process + - No "lazy loading" ability + error if we try loading an asset that's not here - Each name of asset is defined from each scene, no unique identifier - The loading process needing to be done manually make impossible some stuff, like easy global sound effect for menu (as we need to "name" and reapplying it) or default font (same) - Don't scale well, if we have for instance 100+ monster for an RPG battlesystem, we have to either load all of them at battle start, either add a manual function to load a custom different monster in code. - The asset folder have no organisation. In order to solve all that, we should: - Make the asset system global, disconnected from both core and scene. - Add a loader/scrapper system that would search all the folder and generate assets lists that would contain the path and a medatafile if the asset type need one - Add subfolder support : the sound "sounds/menu/confirm.wav" would be name "menu.confirm" - Add a dynamic cache system with a global and local cache. Reset the local cache each scene - Add "asset handlers" that'll handle the actuall assets (like `assets.sounds`), to make most common case easier. Kill asset subtypes when possible. - When an asset is accessed (via an `assets.get(type, name)`, `assets.handler.get(name)` or stuff like `assets.sfx.play(name)`), if it's not in the cache, load it in local cache. - Add handling a "preload.lua" file to handle preloading files without code, but also do a `assets.preload(name, type, isGlobal)` and `assets.handler.preload(name, isGlobal)` functions. - Add also some preloadAll in order to keep some elements from the current asset system
Author
Owner

Assets folder file tree

  • assets/
    • init.lua :: The asset manager, will contain some shortcuts and subjects for handlers
    • cache.lua :: The dynamic cache, can cache and retrieve assets
    • loader.lua :: the asset loader, called once and give every data to the cache system
    • handlers/
      • sounds.lua :: Handle sfx.
      • music.lua :: Handle current music. Can play current music, set new music, etc
      • textures.lua :: Handle simple textures
      • sprites.lua :: Handle sprites and animation
      • tilesets.lua :: Handle tilesets
      • fonts.lua :: Handle fonts, and have special support for "default" fonts
    • types/
      • fonts/
        • init.lua :: basic classic fonts
        • imagefonts :: image-based fonts
      • sprites/
        • init.lua :: A sprite
        • animator.lua :: A sprite animator
      • texture.lua >> To delete
      • sfx.lua >> To delete
      • tileset.lua :: A tileset, with quads for the tiles
      • background.lua >> To delete
      • autotile.lua >> To delete (and replace by something in gui/)
Assets folder file tree - assets/ - init.lua :: The asset manager, will contain some shortcuts and subjects for handlers - cache.lua :: The dynamic cache, can cache and retrieve assets - loader.lua :: the asset loader, called once and give every data to the cache system - handlers/ - sounds.lua :: Handle sfx. - music.lua :: Handle current music. Can play current music, set new music, etc - textures.lua :: Handle simple textures - sprites.lua :: Handle sprites and animation - tilesets.lua :: Handle tilesets - fonts.lua :: Handle fonts, and have special support for "default" fonts - types/ - fonts/ - init.lua :: basic classic fonts - imagefonts :: image-based fonts - sprites/ - init.lua :: A sprite - animator.lua :: A sprite animator - texture.lua >> To delete - sfx.lua >> To delete - tileset.lua :: A tileset, with quads for the tiles - background.lua >> To delete - autotile.lua >> To delete (and replace by something in gui/)
kazhnuz added the
4. Assets
1. Feature
labels 2022-08-08 11:50:29 +02:00
kazhnuz added this to the epervier 0.7.0 milestone 2022-08-08 11:50:34 +02:00
kazhnuz added the
2. Epic
1. Improvement
1. Clean-up
labels 2022-08-08 11:50:52 +02:00
Author
Owner

Maybe handlers should handle everything
-> When started, they scann their directory and populate their list
-> Their load function add to the cache an asset if it's not already in it (and fail if it doesn't exists at all)
--> It can handle a string (load the asset) or a table (load all assets)
-> Their "get()" function load the asset if it's not in the cache
-> They have a purge function to purge their own cache
-> The "asset" object will just be a collection of handler

Each handler will be derived from a common AssetHandlerParent that'll manage the cache and give all the generic function
-> They'll give a list of extensions, and if it handle metadata (in a separate lua file) or not
-> They'll override a "newAsset" that create the actual asset
-> They'll have a few function to handle directly their assets

Questions:
-> Does font really need a specific object ?
-> How to handle font size ? (the first one could answer the second...)
-> Music maybe will work a bit different as they won't have strong caching ?

Maybe handlers should handle everything -> When started, they scann their directory and populate their list -> Their load function add to the cache an asset if it's not already in it (and fail if it doesn't exists at all) --> It can handle a string (load the asset) or a table (load all assets) -> Their "get()" function load the asset if it's not in the cache -> They have a purge function to purge their own cache -> The "asset" object will just be a collection of handler Each handler will be derived from a common AssetHandlerParent that'll manage the cache and give all the generic function -> They'll give a list of extensions, and if it handle metadata (in a separate lua file) or not -> They'll override a "newAsset" that create the actual asset -> They'll have a few function to handle directly their assets Questions: -> Does font really need a specific object ? -> How to handle font size ? (the first one could answer the second...) -> Music maybe will work a bit different as they won't have strong caching ?
Author
Owner

Add a global function to preload everything (except music ? Or maybe even music ?) and bypass lazy loading.

Add a global function to preload everything (except music ? Or maybe even music ?) and bypass lazy loading.
Sign in to join this conversation.
No description provided.