Replaced .reset(new Surface()) with a factory method
authorIngo Ruhnke <grumbel@gmx.de>
Sat, 21 Nov 2009 16:28:12 +0000 (16:28 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Sat, 21 Nov 2009 16:28:12 +0000 (16:28 +0000)
Added some more std::auto_ptr<Surface> instead of Surface*

SVN-Revision: 6081

src/object/cloud_particle_system.cpp
src/object/cloud_particle_system.hpp
src/object/comet_particle_system.cpp
src/object/comet_particle_system.hpp
src/object/ghost_particle_system.cpp
src/object/ghost_particle_system.hpp
src/object/rain_particle_system.cpp
src/object/rain_particle_system.hpp
src/supertux/info_box.cpp
src/supertux/info_box.hpp
src/supertux/title_screen.cpp

index dda8c69..096b153 100644 (file)
@@ -26,7 +26,7 @@ CloudParticleSystem::CloudParticleSystem() :
   ParticleSystem(128),
   cloudimage()
 {
-  cloudimage = new Surface("images/objects/particles/cloud.png");
+  cloudimage = Surface::create("images/objects/particles/cloud.png");
 
   virtual_width = 2000.0;
 
@@ -35,7 +35,7 @@ CloudParticleSystem::CloudParticleSystem() :
     CloudParticle* particle = new CloudParticle;
     particle->pos.x = systemRandom.rand(static_cast<int>(virtual_width));
     particle->pos.y = systemRandom.rand(static_cast<int>(virtual_height));
-    particle->texture = cloudimage;
+    particle->texture = cloudimage.get();
     particle->speed = -systemRandom.randf(25.0, 54.0);
 
     particles.push_back(particle);
@@ -50,7 +50,6 @@ CloudParticleSystem::parse(const Reader& reader)
 
 CloudParticleSystem::~CloudParticleSystem()
 {
-  delete cloudimage;
 }
 
 void CloudParticleSystem::update(float elapsed_time)
index 236940f..db7b3d3 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef HEADER_SUPERTUX_OBJECT_CLOUD_PARTICLE_SYTEM_HPP
 #define HEADER_SUPERTUX_OBJECT_CLOUD_PARTICLE_SYTEM_HPP
 
+#include <memory>
+
 #include "object/particlesystem.hpp"
 
 class CloudParticleSystem : public ParticleSystem
@@ -43,7 +45,7 @@ private:
     {}
   };
 
-  Surface* cloudimage;
+  std::auto_ptr<Surface> cloudimage;
 
 private:
   CloudParticleSystem(const CloudParticleSystem&);
index eb2e377..679ebf0 100644 (file)
@@ -23,8 +23,8 @@
 
 CometParticleSystem::CometParticleSystem()
 {
-  cometimages[0] = new Surface("images/creatures/mr_bomb/exploding-left-0.png");
-  cometimages[1] = new Surface("images/creatures/mr_bomb/exploding-left-0.png");
+  cometimages[0] = Surface::create("images/creatures/mr_bomb/exploding-left-0.png");
+  cometimages[1] = Surface::create("images/creatures/mr_bomb/exploding-left-0.png");
 
   virtual_width = SCREEN_WIDTH * 2;
 
@@ -35,7 +35,7 @@ CometParticleSystem::CometParticleSystem()
     particle->pos.x = systemRandom.rand(int(virtual_width));
     particle->pos.y = systemRandom.rand(int(virtual_height));
     int cometsize = systemRandom.rand(2);
-    particle->texture = cometimages[cometsize];
+    particle->texture = cometimages[cometsize].get();
     do {
       particle->speed = (cometsize+1)*30 + systemRandom.randf(3.6);
     } while(particle->speed < 1);
@@ -53,8 +53,6 @@ CometParticleSystem::parse(const Reader& reader)
 
 CometParticleSystem::~CometParticleSystem()
 {
-  for(int i=0;i<2;++i)
-    delete cometimages[i];
 }
 
 void CometParticleSystem::update(float elapsed_time)
index 7eb7e9c..f627a05 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef HEADER_SUPERTUX_OBJECT_COMET_PARTICLE_SYSTEM_HPP
 #define HEADER_SUPERTUX_OBJECT_COMET_PARTICLE_SYSTEM_HPP
 
+#include <memory>
+
 #include "object/particlesystem_interactive.hpp"
 
 class CometParticleSystem : public ParticleSystem_Interactive
@@ -44,7 +46,7 @@ private:
     {}
   };
 
-  Surface* cometimages[2];
+  std::auto_ptr<Surface> cometimages[2];
 
 private:
   CometParticleSystem(const CometParticleSystem&);
index aca6ccd..ceadfec 100644 (file)
@@ -26,8 +26,8 @@
 //       Ghosts don't change their movement pattern - not random
 GhostParticleSystem::GhostParticleSystem()
 {
-  ghosts[0] = new Surface("images/objects/particles/ghost0.png");
-  ghosts[1] = new Surface("images/objects/particles/ghost1.png");
+  ghosts[0] = Surface::create("images/objects/particles/ghost0.png");
+  ghosts[1] = Surface::create("images/objects/particles/ghost1.png");
 
   virtual_width = SCREEN_WIDTH * 2;
 
@@ -38,7 +38,7 @@ GhostParticleSystem::GhostParticleSystem()
     particle->pos.x = systemRandom.randf(virtual_width);
     particle->pos.y = systemRandom.randf(SCREEN_HEIGHT);
     int size = systemRandom.rand(2);
-    particle->texture = ghosts[size];
+    particle->texture = ghosts[size].get();
     particle->speed = systemRandom.randf(std::max(50, (size * 10)), 180 + (size * 10));
     particles.push_back(particle);
   }
@@ -52,8 +52,6 @@ GhostParticleSystem::parse(const Reader& reader)
 
 GhostParticleSystem::~GhostParticleSystem()
 {
-  for(int i=0;i<2;++i)
-    delete ghosts[i];
 }
 
 void GhostParticleSystem::update(float elapsed_time)
index 6a85e04..f8cf89b 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef HEADER_SUPERTUX_OBJECT_GHOST_PARTICLE_SYSTEM_HPP
 #define HEADER_SUPERTUX_OBJECT_GHOST_PARTICLE_SYSTEM_HPP
 
+#include <memory>
+
 #include "object/particlesystem.hpp"
 
 class GhostParticleSystem : public ParticleSystem
@@ -43,7 +45,7 @@ private:
     {}
   };
 
-  Surface* ghosts[2];
+  std::auto_ptr<Surface> ghosts[2];
 
 private:
   GhostParticleSystem(const GhostParticleSystem&);
index 3f4a125..5c5e9d9 100644 (file)
@@ -23,8 +23,8 @@
 
 RainParticleSystem::RainParticleSystem()
 {
-  rainimages[0] = new Surface("images/objects/particles/rain0.png");
-  rainimages[1] = new Surface("images/objects/particles/rain1.png");
+  rainimages[0] = Surface::create("images/objects/particles/rain0.png");
+  rainimages[1] = Surface::create("images/objects/particles/rain1.png");
 
   virtual_width = SCREEN_WIDTH * 2;
 
@@ -35,7 +35,7 @@ RainParticleSystem::RainParticleSystem()
     particle->pos.x = systemRandom.rand(int(virtual_width));
     particle->pos.y = systemRandom.rand(int(virtual_height));
     int rainsize = systemRandom.rand(2);
-    particle->texture = rainimages[rainsize];
+    particle->texture = rainimages[rainsize].get();
     do {
       particle->speed = (rainsize+1)*45 + systemRandom.randf(3.6);
     } while(particle->speed < 1);
@@ -53,8 +53,6 @@ RainParticleSystem::parse(const Reader& reader)
 
 RainParticleSystem::~RainParticleSystem()
 {
-  for(int i=0;i<2;++i)
-    delete rainimages[i];
 }
 
 void RainParticleSystem::update(float elapsed_time)
index 25715ea..e3c257f 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef HEADER_SUPERTUX_OBJECT_RAIN_PARTICLE_SYSTEM_HPP
 #define HEADER_SUPERTUX_OBJECT_RAIN_PARTICLE_SYSTEM_HPP
 
+#include <memory>
+
 #include "object/particlesystem_interactive.hpp"
 
 class RainParticleSystem : public ParticleSystem_Interactive
@@ -43,7 +45,7 @@ private:
     {}
   };
 
-  Surface* rainimages[2];
+  std::auto_ptr<Surface> rainimages[2];
 
 private:
   RainParticleSystem(const RainParticleSystem&);
index c6d997f..c5521c8 100644 (file)
@@ -35,14 +35,14 @@ InfoBox::InfoBox(const std::string& text) :
   try
   {
     // get the arrow sprites
-    arrow_scrollup   = new Surface("images/engine/menu/scroll-up.png");
-    arrow_scrolldown = new Surface("images/engine/menu/scroll-down.png");
+    arrow_scrollup   = Surface::create("images/engine/menu/scroll-up.png");
+    arrow_scrolldown = Surface::create("images/engine/menu/scroll-down.png");
   }
   catch (std::exception& e)
   {
     log_warning << "Could not load scrolling images: " << e.what() << std::endl;
-    arrow_scrollup = 0;
-    arrow_scrolldown = 0;
+    arrow_scrollup.reset();
+    arrow_scrolldown.reset();
   }
 }
 
@@ -51,9 +51,6 @@ InfoBox::~InfoBox()
   for(std::vector<InfoBoxLine*>::iterator i = lines.begin();
       i != lines.end(); i++)
     delete *i;
-
-  delete arrow_scrollup;
-  delete arrow_scrolldown;
 }
 
 void
@@ -81,13 +78,13 @@ InfoBox::draw(DrawingContext& context)
 
   {
     // draw the scrolling arrows
-    if (arrow_scrollup && firstline > 0)
-      context.draw_surface(arrow_scrollup,
+    if (arrow_scrollup.get() && firstline > 0)
+      context.draw_surface(arrow_scrollup.get(),
                            Vector( x1 + width  - arrow_scrollup->get_width(),  // top-right corner of box
                                    y1), LAYER_GUI);
 
-    if (arrow_scrolldown && linesLeft && firstline < lines.size()-1)
-      context.draw_surface(arrow_scrolldown,
+    if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
+      context.draw_surface(arrow_scrolldown.get(),
                            Vector( x1 + width  - arrow_scrolldown->get_width(),  // bottom-light corner of box
                                    y1 + height - arrow_scrolldown->get_height()),
                            LAYER_GUI);
index 190617a..6286a64 100644 (file)
@@ -18,6 +18,7 @@
 #define HEADER_SUPERTUX_SUPERTUX_INFO_BOX_HPP
 
 #include <map>
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -42,8 +43,8 @@ private:
   size_t firstline;
   std::vector<InfoBoxLine*> lines;
   std::map<std::string, Surface*> images;
-  Surface* arrow_scrollup;
-  Surface* arrow_scrolldown;
+  std::auto_ptr<Surface> arrow_scrollup;
+  std::auto_ptr<Surface> arrow_scrolldown;
 
 private:
   InfoBox(const InfoBox&);
index d77e381..0372be3 100644 (file)
@@ -54,7 +54,7 @@ TitleScreen::TitleScreen() :
   player->set_controller(controller.get());
   player->set_speedlimit(230); //MAX_WALK_XM
 
-  frame = std::auto_ptr<Surface>(new Surface("images/engine/menu/frame.png"));
+  frame = Surface::create("images/engine/menu/frame.png");
 }
 
 std::string