Hacking around AssetManager

I need non-trivial handling of some resources and I’m wondering if it can be fit into current AssetManager framework:

  1. I need to pass configuration file to AssetLocator, in addition to rootPath. As I’m passing only class of AssetLocator, not instance, I cannot do it directly. One option is encoding it in passed path - something like “c:/games/mygame/data;c:/Users/abies/mygame/loader.config” but it seems very hacky. Is there any other option?

  2. I need AssetLocator helping with resolving the type of the asset. I need to request something like mymonster.texture, with asset locator actually realizing if texture is dds,tga,jpeg or whatever. I though I could cheat my way by passing AssetKey with .texture extension but returning AssetInfo with assetKey with proper extensions from loader, but it seems that AssetLoader is chosen based on the original key. Looks like I will have to create something like TextureAssetLoader, which is passed AssetInfo and will in turn delegate it to specific loaders to do actual heavy lifting. Unfortunately, for that I would need access to handler to retrieve other AssetLoaders, which seems to be not possible

Any smart solutions here, short of forking DesktopAssetManager?

Theres no need to fork it for that, just have another class with another method that in the end uses the assetmanager to load the model and on the way does whatever you want to do with the suffix. Internally the extension defines what loader is used so idk why you struggle with separating that data anyway. But like I say you are trying to put some functionality in assetmanager that just doesn’t belong there.

Maybe I overcomplicated the explanation. I need ‘generic’ AssetKey which doesn’t specify particular AssetLoader to be used for it - and the information has to come from AssetLocator. At the moment, it seems there is no real way to influence which AssetLoader is used from AssetLocator.

Why? Either do it properly and implement the AssetLoader yourself and make it do what you want or just don’t use a system for stuff you want to do that wasn’t built for that… Build around it instead of extending stuff, thats always the better way anyway.

If we stop speaking in the hypothetical then maybe we can provide better advice. Can you tell us more specifically what you are trying to do?

Specific case:

I want to load NWN models from NWN files directly. I already got all parsing stuff done, so I’m able to create AssetLocator without the issues. Problem is with textures. Models reference the textures by name without extension/type (for example c_goblin). In NWN files, I can have c_goblin.dds and c_goblin.tga, or maybe just c_goblin.tga. DDS textures are supposed to take precedence if they are available.

I don’t want to request c_goblin.dds, catch exception and then request c_goblin.tga - AssetLocator is smart enough to know what is the precedence. I would like to request c_goblin.nwntexture and have AssetLocator returning c_goblin.dds if it is available, c_goblin.tga if not. Problem is, that in default AssetManager implementation, code will follow through to progress with AssetLoader for .nwntexture.

Now, all of this almost works, except:

  • I’m not able to give information from AssetLoader to further code that default dds or tga loader should be used
  • alternatively, I could implement my own NwnTextureAssetLoader, but I’m not able to get hold of references to already embedded dds/tga loaders to pass that information further

From what I see atm is that I will probably have to implement NwnTextureAssetLoader, which will instantiate it’s own copies of DDS and TGA loaders and dispatch accordingly. I was probably too much fixated on trying to reuse currently existing instance of these, from AssetManager.

So as I said, make your own method that uses AssetManager.tryLocate() and loadTexture so that it behaves as you want, then use that method in the loader. Absolutely zero reason to hack the AssetManager just to make that one method return what you want…