Manipulation of asset directories


Hi all.

I’m implementing orientation awareness into an existing desktop application (because clients, ugh). When it comes to loading assets, I thought i’d try to be clever and just add an asset directory based on the current orientation, so that assets are automatically loaded from assets/{orientation}/asset.ext, for example. This is fine and dandy, except that there’s no way I can see to remove asset directories once they’ve been added. getAssetDirectories() returns a const ref, and there’s no removeAssetDirectory counterpart.

Before i go hacking this functionality into my fork of cinder, is there any particular reason why asset directories shouldn’t be meddled with at runtime? I’d rather spend my time coming up with a different solution than diving around the cinder source all afternoon if at all possible.




I’m not sure about the reasons of a missing removeAssetDirectory, but I don’t think you’d need one. Why not just concatenate the path in your app?

auto path = getAssetPath("") / mOrientation / "asset.ext";
auto src = loadFile( path );


Well because with my method, i don’t have to duplicate assets that are common to both orientations, the asset system will naturally fall back to a common asset in /assets/.

I’ve just added a non-const getAssetDirectories() in Platform.h which suits my purposes for now, i just wanted to make sure there wasn’t any threading issues to be aware of. I think highly enough of the cinder codebase that when something that could be perceived as an oversight such as this crops up, i tend to assume it’s by design.

Thanks mate.


I’d say the simple reason is that it hasn’t come up. I think it would be fine to add it, with the caveat that it isn’t thread-safe - you should do all asset directory manipulation before any background threads start trying to load assets, or pause your loaders.

I think adding a removeAssetDirectory() method would be cleaner than making getAssetDirectories() non-const.


"The first time you attempt to load an asset or get its path, your Cinder application automatically attempts to find its assets directory. It begins by searching in the same folder in which your .app bundle or .exe lives. Next it searches its parent, on up 5 levels… loadAsset() and getAssetPath() will search the primary assets folder first, followed by any supplemental asset directories the user may have provided. "


For the record, I don’t like this kind of behavior, especially when it can’t be turned off, and especially if it searches 5 directories up before searching the manual override directory.