Make SharedAsset a base class, eliminate AssetContainer #960
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a PR into #959.
There's a corresponding cesium-unreal branch that goes with this:
https://github.com/CesiumGS/cesium-unreal/tree/shared-assets-image-cesium-only
@azrogers this is the refactoring we talked about (mentioned here). Once again it isn't completely done but is working well enough that you can build on it, if it seems like a reasonable direction to you. I renamed
SingleAssetDepot
toSharedAssetDepot
, andAssetDepot
toSharedAssetSystem
. Feel free to merge into your branch when you're ready, or wait a bit on that if you prefer.Some things I'm still concerned about (but don't know the best way to solve yet)...
Asset Factory
Currently, a Factory class is passed to
getOrFetch
. This is conceptually kind of broken. I mean, if I call that function twice with the same URI but a different factory, do I get the same resource both times?Maybe it's a little bit academic, but if so, why not construct the SharedAssetDepot with the Factory instead, and save the trouble of passing it through each time? Well, we immediately run into the problem that we can't construct a factory for images without knowing the KTX options, which can technically be different on different tilesets (though it's not likely).
Intrusive reference counting feels error-prone
It's disastrous to create an
ImageCesium
instance on the stack or as a member of another class and then refer to it with an IntrusivePointer. If we do, after the last IntrusivePointer goes away, the instanced will bedelete
d, which will go very poorly.This isn't really a new problem, but I think it became obvious to me while working on this.
ImageCesium
used to be a class that was usually instantiated on the stack or as a member of some larger object. But now it is reference counted and therefore must be heap allocated (i.e., allocated withnew
). There's a fair bit of possibility for error in the conversion.I'm not sure yet how much to worry about this, or what we can do about it. One possibility is to prevent allocation anywhere other than the heap by making the constructor private and providing a factory function.
Random aside while I'm thinking about it:
ImageCesium
is a strange name. PerhapsImageAsset
would be more appropriate now.