Added Surface::clone() method
authorgrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Mon, 14 Dec 2009 05:01:53 +0000 (05:01 +0000)
committergrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Mon, 14 Dec 2009 05:01:53 +0000 (05:01 +0000)
git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6214 837edb03-e0f3-0310-88ca-d4d4e8b29345

src/sprite/sprite_data.cpp
src/video/surface.cpp
src/video/surface.hpp

index 38e58d5..4225de0 100644 (file)
@@ -110,7 +110,7 @@ SpriteData::parse_action(const Reader& lisp, const std::string& basedir)
       float max_w = 0;
       float max_h = 0;
       for(int i = 0; static_cast<unsigned int>(i) < act_tmp->surfaces.size(); i++) {
-        SurfacePtr surface(new Surface(*act_tmp->surfaces[i]));
+        SurfacePtr surface = act_tmp->surfaces[i]->clone();
         surface->hflip();
         max_w = std::max(max_w, (float) surface->get_width());
         max_h = std::max(max_h, (float) surface->get_height());
index 6df0cf1..98bd868 100644 (file)
@@ -67,20 +67,17 @@ Surface::Surface(const Surface& rhs) :
   surface_data = VideoSystem::new_surface_data(*this);
 }
 
-const Surface& 
-Surface::operator=(const Surface& rhs)
+Surface::~Surface()
 {
-  rhs.texture->ref();
+  VideoSystem::free_surface_data(surface_data);
   texture->unref();
-  texture = rhs.texture;
-  rect = rhs.rect;
-  return *this;
 }
 
-Surface::~Surface()
+SurfacePtr
+Surface::clone() const
 {
-  VideoSystem::free_surface_data(surface_data);
-  texture->unref();
+  SurfacePtr surface(new Surface(*this));
+  return surface;
 }
 
 /** flip the surface horizontally */
index ad1d9fe..9523efd 100644 (file)
@@ -42,13 +42,15 @@ private:
   Rect rect;
   bool flipx;
 
-public:
+private:
   Surface(const std::string& file);
   Surface(const std::string& file, const Rect& rect);
-  Surface(const Surface& other);
+  Surface(const Surface&);
+
+public:
   ~Surface();
 
-  const Surface& operator= (const Surface& other);
+  SurfacePtr clone() const;
 
   /** flip the surface horizontally */
   void hflip();
@@ -64,6 +66,9 @@ public:
 
   /** returns a vector containing width and height */
   Vector get_size() const;
+
+private:
+  Surface& operator=(const Surface&);
 };
 
 #endif