Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

C++ how can I reduce repetitive code with templates and/or OOP?

$
0
0

I'm working on an asset manager for my game engine and there's a bit of repetition I assume the solution to this is are templates and/or inheritance, however, I don't have much experience working with those so it's not very apparent how I might refactor this.

My current code requires 4 things a container, load function, and two get functions. Using templates/OOP I imagine I could probably have a single unordered_map and two get functions and then the load functions would stay as is since those are unique per asset.

struct ResourceHandle {    unsigned int id;    bool valid;};struct Mesh {    std::vector<float> vertices;    unsigned int vao, vbo;};struct MeshMeta {    ResourceHandle handle;    std::string filepath;    time_t lastModifiedTime;};namespace ResourceManager {    namespace {        std::unordered_map<ResourceHandle, MeshMeta> meshes;        std::unordered_map<ResourceHandle, TextureMeta> textures;        std::unordered_map<ResourceHandle, ShaderMeta> shaders;    }    ResourceHandle LoadMesh() {}    void ReloadResources() {}    MeshMeta GetMesh(ResourceHandle handle) {}    ResourceHandle GetMesh(const std::string& filepath) {}}

Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>