I am nonetheless on the early levels of my recreation engine, however I’m at some extent the place I want to have the ability to load information, and I am leaning in direction of having asset lessons that may load themselves, for instance:
class Picture
{
public:
Picture();
Picture(const std::string& filepath);
// most likely one other constructor to load picture from reminiscence
~Picture();
void Load((const std::string& filepath);
// once more most likely produce other strategies to load picture from reminiscence
int GetWidth() const;
int GetHeight() const;
const Coloration* GetPixels() const;
// ...
non-public:
// helper/utility stuff
};
And I actually like this as a result of it permits me to do one thing like this:
Picture img("path/to/img");
Texture tex(img);
And I discover this to be fairly easy, however I’ve learn a handful of recreation engine structure books in addition to peeked at just a few open supply tasks, and there are specific points I’m missing, reminiscent of caching and file abstraction. Most code I’ve seen roughly does one thing like this:
auto cache = std::make_shared();
cache->RegisterLoader(...) // non-compulsory technique
Useful resource res("path/to/useful resource"); // create an identifier
cache->GetHandle(&res); // load and/or get the deal with
So I am form of conflicted as a result of I just like the simplicity and understanding of my method, however it’s missing sure points that I am going to probably want in the long term. I am curious if there’s a approach I can design this in order that I can have it my approach however incorporate the performance of the second method?
