Fix another round of squirrel coverity issues
[supertux.git] / src / video / texture.hpp
index a4beb86..76964a9 100644 (file)
 #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
@@ -43,15 +45,20 @@ enum DrawingEffect {
  */
 class Texture
 {
-protected:
-  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() : filename() {}
-  virtual ~Texture() 
+  Texture() : cache_filename() {}
+  virtual ~Texture()
   {
-    if (texture_manager)
-      texture_manager->release(this);
+    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;
@@ -59,16 +66,6 @@ public:
   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;
-  }
-
 private:
   Texture(const Texture&);
   Texture& operator=(const Texture&);