I'm trying to create an Asset Manager that loads different types based on some reflection data, so that I can call something like GetAsset(uint16_t assetType, Uuid uuid). I do not want to use strings due to performance worries. The system I have works well within a single binary, but not across libraries. What is a good way to register types dynamically across libraries?
The current way I handle this is by using the following strategy. I have a static member variable in each struct:
struct TextureAsset : public Asset {
TextureAsset(Uuid uuid, std::string_view name, Texture* texture) : Asset(uuid, name), texture(texture) {}
Texture* texture = nullptr;
static uint16_t assetType;
};
I then set the static variable from an AssetManager:
private uint16_t assetTypeNames;
template <typename AssetT, typename AssetImporterT>
void RegisterAssetType() {
AssetT::assetType = (AssetType)assetTypeNames.size();
}
Both TextureAsset and AssetManager are in the same library, EngineCore.dll. I also have a file EntryPoint.cpp in a library called Renderables3d.dll, and when I try to reference the member variable:
uint16_t assetType = TextureAsset::assetType;
I get this error in the file in EntryPoint.cpp:
unresolved external symbol "public: static unsigned short TextureAsset::assetType" (?assetType@TextureAsset@@2GA)