Asset Manager
- Pablo Narvaja

- Jan 2, 2020
- 2 min read
In Llamathrust when you want to load an image or create a material you have to do it manually and deal with all those clases.
Wouldn't be easier to ask to one object a mesh, a material or a texture?
Having an object and only one that manage loading the texture from disk if the texture we asked isn't in memory and deal with all this sort of escenarios?
Having a singleton class that manage every asset in the game makes the API a lot clearer and uniform, also makes easier scalability of the project. All this is the asset manager!.
Prerequisites
For the asset manager to work I needed assets and for the moment the only asset I can load right from the disk is a mesh so I started to define the specifiation of files that describe textures and materials to make the creations of this objects more automatic. This files are xml based since I realized this format is clearer to represent them and file size isnt an issue given the amount of elements a texture or a material have right now.
Cubemaps from files are still no supported so the specs on that are provisory.
The API
So what I want this singleton to do is:
Load (load the asset from disc)
Get (Get the asset from memory)
Get and Load if necesary (GetSafe)
But sometimes you ask for a file that is not there so I set a folder for every asset type and store the name with the filepath in a unrodered_map so when I ask for an asset to be loaded it first search for the asset to exists. I did not test the performance of this technique maybe is unnecessary since a function exists(file_path) is in std::filesystem.
Now I added setASSET_TYPEfolder(folder_path) function to the class:
Implementation
The factory static class is the one responsable of creating the asset object, and the AssetManager is the one that manage the owners and the life of the objects so the implementation for every function is the same but changes the corresponding function of the factory for every type.
Comparison
The old manual method vs the new AssetManager method side by side:
As you can see before I needed to load every texture I needed and set them as diffuse in the corresponding material and now it does it automatically reading from the file and I only need to get the material and load it to the GPU.
TODO
ShadersLibrary is a static class that I have right now that manage shaders and a FontManager also a static class, those should be integrated into the asset manager to have a more uniform API. As stated before cube maps needs to be supported as well.
That's all for this post, folks. Bye!

















Comments