0
\$\begingroup\$

I'm in the process of redoing my asset/resource manager currently I have load functions scattered throughout my code for example LoadMeshFromFile(), LoadTextureFromFile(), LoadShaderFromFile(), etc, which then get added to the resource manager AddResource(Resource resource) with my new code I'm hoping to just have a single load function like LoadResource<Mesh>("path/to/mesh") or LoadResource("path/to/mesh", ResourceType::Mesh) also instead of working with strings it uses handles.

The problem I'm facing is not knowing how to actually load the individual resources if it's a mesh how do I load a mesh, if it's a texture how do I load that, etc.

    ResourceHandle LoadAsset(const std::string& filepath) {
        // Check if the filepath is valid
        
        // Check if the resource already exists

        // Create handle
        auto resource = std::make_shared<Resource>();
        ResourceHandle handle(nextId++);
        resources[handle.GetID()] = resource;
        filePathToHandle[filepath] = handle.GetID();

        return handle;
    }
\$\endgroup\$
3
  • \$\begingroup\$ Well that completely depends, what do you plan on doing with it after its loaded? Does it just sit in memory? Does it get rendered? \$\endgroup\$ Commented Mar 14, 2024 at 10:31
  • \$\begingroup\$ Well, my plan was to have the game object store the handle which the renderer grabs during rendering to render the asset. I'm just confused because before I'd have unique load functions, but with this more generic/abstract(?) approach do I still need that unique logic? I assume so, but then yeah how do I determine which gets used? \$\endgroup\$ Commented Mar 14, 2024 at 13:44
  • \$\begingroup\$ You probably could use some kind of LoadAsset<T> generic method, and then check what T is within the function to control what happens, but personally I would just keep LoadMesh and LoadTexture, etc seperate functions. \$\endgroup\$ Commented Mar 14, 2024 at 14:04

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.