[ad_1]
The best way I’ve realized to implement an asset supervisor is having unordered maps for every asset sort (textures, shaders, meshes, and so forth.), every with a string key and object worth after which having strategies Add()
, Get()
, Load()
for every asset sort. For my ability degree and the dimensions of tasks I will be doing that is in all probability adequate, nevertheless, I got here throughout a weblog that makes use of the idea of handles which I discovered fairly fascinating. It reveals a deal with as a wrapper round a uint32_t
after which goes on a few supervisor class that follows the same construction to what I mentioned.
What I do not perceive about this strategy is how do you affiliate a deal with with a object? With the tactic I have been utilizing because it’s simply strings I can simply create an object and retailer the ID in it
AssetManager::AddTexture("Textures/participant.png", "PlayerTexture");
AssetManager::AddMesh("Meshes/participant.obj", "PlayerMesh");
// This might technically be written anyplace
Scene::AddObject(GameObject("Participant", "PlayerTexture", "PlayerMesh"));
AssetManager::GetMesh(Object.MeshName);
static Mesh GetMesh(std::string ID) {
return meshes[ID];
}
However with handles would not I must make my object proper after loading the asset? Or how else am I purported to get the deal with to the article until I proceed to make use of string IDs however for the handles, however I really feel like that may defeat the aim. Here is an instance of making an attempt to grasp utilizing handles.
TextureHandle playerTextureHandle = AssetManager::AddTexture("Textures/participant.png");
// Must be right here so I can entry the variable
Scene::AddObject(GameObject("Participant", playerTextureHandle));
AssetManager::GetTexture(Object.textureHandle);
struct TextureHandle {
unsigned int deal with;
}
static Texture GetTexture(TextureHandle deal with) {
return textures[handle.handle];
}
Penning this put up one other potential drawback may be the very fact I do not perceive what a deal with absolutely is so I’ve a sense I won’t be utilizing it within the supposed manner.
[ad_2]