Skip to content

Resource

Alex Miyamoto edited this page Apr 23, 2018 · 2 revisions

The resource library contains all of the code relating to loading assets from disc and tracking them in memory. In most cases when Usagi falls short it is because of the hardware it was targetting, there is no threaded loading - this required us to load everything in advance and hurt load times. Refactoring this library is a high priority.

Resources

All resources inherit from ResourceBase which tracks the name and data hashes and in the future will be the interface for managing dependencies and handling threaded loading.
The resource manager does not return direct pointers, but typedef'd SharedPointers. Theoretically this allows us to see which files are not currently referenced and unload them if tight on memory (it also allows us to track down memory leaks as by the time a set of resources are freed all classes referencing them should have been deleted).

ResourceMgr

The resource manager used to be a singleton, fortunately this is no longer the case, ensuring that load requests can only be made at the appropriate time (such as the OnLoaded callbacks for components).

Currently it is just using two stacks, static (resources that will always be present), and dynamic (things loaded for a given mode). This is not very flexible, internally it is capable of using tags as many tags as required and then clearing resources by this tag so if you want more flexibility you only need to expose this functionality.