So I stopped using that singleton resource manager from SFML essentials and made a simple resource holder class:
std::map<std::string, sf::Texture> Textures;
sf::Texture& Resources::get_texture(std::string const& filename)
{
// See if the texture is already loaded
auto pairFound = Textures.find(filename);
// If yes, return the texture
if (pairFound != Textures.end()) { return pairFound->second; }
// Else, load the texture and return it
else
{
// Create an element in the texture map
auto& texture = Textures[filename];
texture.loadFromFile(filename);
return texture;
}
}
It has the same design as the one from SFML essentials, but it's meant to work with raii.
In this example I pass a resource holder to a class through the constructor:
class A
{
Resources Resource;
B objB{ Resource };
A::A() { Resource.get_texture("x.png"); }
}
class B : public sf::Drawable, public sf::Transformable
{
B::B(Resources& Resource) { tex = Resource.get_texture("x.png"); }
sf::Texture tex; // <- MY QUESTION IS ABOUT THIS
sf::VertexArray va;
}
My question is: Should class B have an sf::Texture or an sf::Texture* ?
I took a look at sf::Texture Class Reference to see what the = overload does, but I couldn't understand if it performs some sort of copy or what.
I remember reading somewhere here not to pass SFML resources around using pointers. Something to do with const references? This is a bit over my head c++ wise.