31
Feature requests / Unloadable Resources
« on: April 17, 2011, 03:02:17 am »Quote from: "Tank"
Quote from: "Laurent"I wouldn't call them "uninitialized" or "invalid", but "empty".
Then sf::Image::Unload() or sf::Image::Clear() would just be fine. To be honest I can't really think of situations where it's really needed, but for consistency I'd say it's okay.
I don't like the word "consistency", because if a function is not needed you should not implement it in my opinion. The very simple reason is, that it is easy to use it in a wrong way. You would be able to clear an image, but you also would be able, to "use" this empty image again. And so of course an image can be empty, but it isn't supposed to.
I rather would prefer not to offer any default constructor. So that the user had to initialise the image immediately after creating it.
If you cant initialise it immediately(see Laurent's example) I would use pointers(I would use them even with a default constructor, because it is very simple to check, weather a pointer is NULL or not and so you can prevent missuse of an uninitialised image).
So the code would look like:
Code: [Select]
class Game
{
public:
Game()
: tileset()
{
}
~Game()
{
if( tileset )
delete tileset;
}
void LoadMap(const std::string& tileset)
{
if( !tileset )
tileset = new sf::Image( "myImage.jpg" );
}
private:
sf::Image* tileset;
};