X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fvideo%2Ftexture.hpp;h=76964a9fd88a3875653d2c213044dc8835242f8e;hb=e449041f97af574103b20cca6d45c06d71677a98;hp=589fd95921936a005343961349428d93c130bea3;hpb=08813a74da6ac1fd045a105e4e8105f1d7f716f0;p=supertux.git diff --git a/src/video/texture.hpp b/src/video/texture.hpp index 589fd9592..76964a9fd 100644 --- a/src/video/texture.hpp +++ b/src/video/texture.hpp @@ -22,19 +22,22 @@ #include #include +#include "supertux/globals.hpp" #include "video/texture_manager.hpp" /// bitset for drawing effects -enum DrawingEffect { +enum { /** Don't apply anything */ - NO_EFFECT, + NO_EFFECT = 0, /** Draw the Surface upside down */ - VERTICAL_FLIP, + VERTICAL_FLIP = (1<<1), /** Draw the Surface from left to down */ - HORIZONTAL_FLIP, + HORIZONTAL_FLIP = (1<<2), NUM_EFFECTS }; +typedef unsigned int DrawingEffect; + /** * This class is a wrapper around a texture handle. It stores the texture width * and height and provides convenience functions for uploading SDL_Surfaces @@ -42,48 +45,27 @@ enum DrawingEffect { */ class Texture { -protected: - int refcount; - std::string filename; +private: + friend class TextureManager; + /* The name under which this texture is cached by the texture manager, + * or the empty string if not. */ + std::string cache_filename; public: - Texture() : refcount(0), filename() {} - virtual ~Texture() {} + Texture() : cache_filename() {} + virtual ~Texture() + { + if (TextureManager::current() && cache_filename != "") + /* The cache entry is now useless: its weak pointer to us has been + * cleared. Remove the entry altogether to save memory. */ + TextureManager::current()->reap_cache_entry(cache_filename); + } virtual unsigned int get_texture_width() const = 0; virtual unsigned int get_texture_height() const = 0; virtual unsigned int get_image_width() const = 0; virtual unsigned int get_image_height() const = 0; - std::string get_filename() const - { - return filename; - } - - void set_filename(std::string filename) - { - this->filename = filename; - } - - void ref() - { - refcount++; - } - - void unref() - { - assert(refcount > 0); - refcount--; - if(refcount == 0) - release(); - } - -private: - void release() - { - texture_manager->release(this); - } - private: Texture(const Texture&); Texture& operator=(const Texture&);