GameDevTecnico / cubos

A still very barebones game engine focused on voxels and data-oriented programming
https://cubosengine.org
MIT License
83 stars 36 forks source link

Allow a single asset to contain multiple data #1274

Open RiscadoA opened 3 months ago

RiscadoA commented 3 months ago

Problem

Our asset flow lacks support for non-trivial asset handling.

The following scenario is a good example of this:

Currently, we can tackle this by providing an Image asset type, which loads a .png or equivalent. Then, on the UI side, we keep a Asset<Image> field on a component, and the UI code must manually manage the render device texture creation. This is cumbersome and error prone, and this is only one of the examples - we also have a similar situation with voxel grids.

Solution

A single asset (UUID) should be able to contain multiple data types. For example, taking the image example once again, we could have two asset types: Image, and Texture. The UI would store an Asset<Texture>, keeping a reference to only the GPU/render device texture asset. When loading texture data for a given asset, the TextureBridge load method is called, which internally loads the Image data of the same asset, and creates a render device texture. As no reference is kept to the Image data, it can be unloaded, keeping only the Texture part.

To sum it up, we should:

RiscadoA commented 2 months ago

After thinking about this a bit further, I came to the conclusion that this might not be such a good idea, as multiple 'source' assets may need to be exported multiple times, with different options. For example, it should be possible to create multiple font atlas assets from a single font asset.