Original Post
I'm just getting started on my game and I'm trying to find a consistent way of managing game assets, which I define to be things like textures, meshes, audio files, shaders, lua scripts, etc.
I'm looking to create something along the lines of a ResourceManager class, maybe templated, ie. typedef ResourceManager TextureManager; but I'm not exactly sure of what the interface should be like.
I've searched around for some examples here, but none of them seemed like optimal solutions for me. Id like for it to reference count resources so when a particular mesh is no longer being used by anything, that asset is removed from memory. Although, it would probably be better that the resource not be removed immediately upon reaching 0 references, so maybe the ResourceManager keeps it's own reference so the count never drops bellow 1, and semi-periodically, it will find assets with 1 count and remove them. That way you don't have to re-load a file because it's count reached 0 but was needed again just a few seconds later. If a particular URI is requested which matches one of the assets already loaded, it will return a ref counted pointer to the asset already in memory, so you never have more than one instance of an asset loaded in memory. The system will also have to be thread and Async IO friendly, as I plan to use a task based system and asynchronous loading. The other issue I foresee, maybe, is serialization. I know storing pointers is bad for that, and a smart pointer would be no different.
Help with this would be greatly appreciated.
I'm looking to create something along the lines of a ResourceManager class, maybe templated, ie. typedef ResourceManager
I've searched around for some examples here, but none of them seemed like optimal solutions for me. Id like for it to reference count resources so when a particular mesh is no longer being used by anything, that asset is removed from memory. Although, it would probably be better that the resource not be removed immediately upon reaching 0 references, so maybe the ResourceManager keeps it's own reference so the count never drops bellow 1, and semi-periodically, it will find assets with 1 count and remove them. That way you don't have to re-load a file because it's count reached 0 but was needed again just a few seconds later. If a particular URI is requested which matches one of the assets already loaded, it will return a ref counted pointer to the asset already in memory, so you never have more than one instance of an asset loaded in memory. The system will also have to be thread and Async IO friendly, as I plan to use a task based system and asynchronous loading. The other issue I foresee, maybe, is serialization. I know storing pointers is bad for that, and a smart pointer would be no different.
Help with this would be greatly appreciated.