More use of SurfacePtr
authorIngo Ruhnke <grumbel@gmx.de>
Sun, 13 Dec 2009 23:51:40 +0000 (23:51 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Sun, 13 Dec 2009 23:51:40 +0000 (23:51 +0000)
SVN-Revision: 6211

38 files changed:
src/badguy/yeti.cpp
src/gui/button.cpp
src/gui/button.hpp
src/gui/menu.cpp
src/gui/mousecursor.cpp
src/gui/mousecursor.hpp
src/object/background.cpp
src/object/candle.cpp
src/object/candle.hpp
src/object/cloud_particle_system.cpp
src/object/comet_particle_system.cpp
src/object/ghost_particle_system.cpp
src/object/level_time.cpp
src/object/particlesystem.hpp
src/object/particlesystem_interactive.hpp
src/object/player.cpp
src/object/rain_particle_system.cpp
src/object/snow_particle_system.cpp
src/object/snow_particle_system.hpp
src/sprite/sprite.cpp
src/sprite/sprite.hpp
src/sprite/sprite_data.cpp
src/sprite/sprite_data.hpp
src/supertux/console.cpp
src/supertux/game_session.cpp
src/supertux/info_box.cpp
src/supertux/info_box_line.cpp
src/supertux/player_status.cpp
src/supertux/statistics.cpp
src/supertux/statistics.hpp
src/supertux/textscroller.cpp
src/supertux/tile.cpp
src/supertux/tile.hpp
src/supertux/title_screen.cpp
src/video/drawing_context.cpp
src/video/drawing_context.hpp
src/video/gl/gl_lightmap.cpp
src/video/gl/gl_renderer.cpp

index 26cdfb1..ba8b54a 100644 (file)
@@ -95,19 +95,18 @@ Yeti::draw_hit_points(DrawingContext& context)
 {
   int i;
 
-  Surface *hh = hud_head.get();
-  if (!hh)
-    return;
+  if (hud_head)
+  {
+    context.push_transform();
+    context.set_translation(Vector(0, 0));
 
-  context.push_transform();
-  context.set_translation(Vector(0, 0));
+    for (i = 0; i < hit_points; ++i)
+    {
+      context.draw_surface(hud_head, Vector(BORDER_X + (i * hud_head->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1);
+    }
 
-  for (i = 0; i < hit_points; ++i)
-  {
-    context.draw_surface(hh, Vector(BORDER_X + (i * hh->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1);
+    context.pop_transform();
   }
-
-  context.pop_transform();
 }
 
 void
index 7a57620..0105741 100644 (file)
@@ -21,7 +21,7 @@
 
 Font* Button::info_font = 0;
 
-Button::Button(Surface* image_, std::string info_, SDLKey binding_) :
+Button::Button(SurfacePtr image_, std::string info_, SDLKey binding_) :
   pos(),
   size(),
   image(),
index f66d868..7d08232 100644 (file)
@@ -21,8 +21,8 @@
 #include <string>
 
 #include "math/vector.hpp"
+#include "video/surface_ptr.hpp"
 
-class Surface;
 class DrawingContext;
 class Font;
 class ButtonGroup;
@@ -37,7 +37,7 @@ enum {
 class Button
 {
 public:
-  Button(Surface* image_, std::string info_, SDLKey binding_);
+  Button(SurfacePtr image_, std::string info_, SDLKey binding_);
   Button(const Button& rhs);
   ~Button();
 
@@ -55,7 +55,7 @@ private:
   Vector pos;
   Vector size;
 
-  Surface* image;
+  SurfacePtr image;
   SDLKey binding;
 
   int id;
index 2e1c17d..ab6c37b 100644 (file)
@@ -555,10 +555,10 @@ Menu::draw_item(DrawingContext& context, int index)
                         ALIGN_LEFT, LAYER_GUI, text_color);
 
       // Draw right side
-      context.draw_surface(arrow_left.get(),
+      context.draw_surface(arrow_left,
                            Vector(right - list_width - roff - roff, y_pos - 8),
                            LAYER_GUI);
-      context.draw_surface(arrow_right.get(),
+      context.draw_surface(arrow_right,
                            Vector(right - roff, y_pos - 8),
                            LAYER_GUI);
       context.draw_text(Resources::normal_font, pitem.list[pitem.selected],
@@ -571,7 +571,7 @@ Menu::draw_item(DrawingContext& context, int index)
       context.draw_text(Resources::Resources::normal_font, pitem.text,
                         Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)),
                         ALIGN_CENTER, LAYER_GUI, text_color);
-      context.draw_surface(back.get(),
+      context.draw_surface(back,
                            Vector(x_pos + text_width/2  + 16, y_pos - 8),
                            LAYER_GUI);
       break;
@@ -584,11 +584,11 @@ Menu::draw_item(DrawingContext& context, int index)
                         ALIGN_LEFT, LAYER_GUI, text_color);
 
       if(pitem.toggled)
-        context.draw_surface(checkbox_checked.get(),
+        context.draw_surface(checkbox_checked,
                              Vector(x_pos + (menu_width/2-16) - checkbox->get_width(), y_pos - 8),
                              LAYER_GUI + 1);
       else
-        context.draw_surface(checkbox.get(),
+        context.draw_surface(checkbox,
                              Vector(x_pos + (menu_width/2-16) - checkbox->get_width(), y_pos - 8),
                              LAYER_GUI + 1);
       break;
index 7139d2e..5994003 100644 (file)
@@ -30,14 +30,13 @@ MouseCursor::MouseCursor(std::string cursor_file) :
   cur_state(),
   cursor()
 {
-  cursor = new Surface(cursor_file);
+  cursor = Surface::create(cursor_file);
 
   cur_state = MC_NORMAL;
 }
 
 MouseCursor::~MouseCursor()
 {
-  delete cursor;
 }
 
 int MouseCursor::state()
index 897a7ee..7e4d3b3 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <string>
 
-class Surface;
+#include "video/surface_ptr.hpp"
 
 #define MC_STATES_NB 3
 
@@ -69,7 +69,7 @@ private:
   int mid_y;
   int state_before_click;
   int cur_state;
-  Surface* cursor;
+  SurfacePtr cursor;
 
 private:
   static MouseCursor* current_;
index 09d147c..597aa9d 100644 (file)
@@ -159,7 +159,7 @@ Background::draw_image(DrawingContext& context, const Vector& pos)
       {
         Vector p(pos.x - parallax_image_size.width / 2.0f,
                  pos.y + y * image->get_height()  - image->get_height() / 2.0f);
-        context.draw_surface(image.get(), p, layer);
+        context.draw_surface(image, p, layer);
       }
       break;
 
@@ -168,7 +168,7 @@ Background::draw_image(DrawingContext& context, const Vector& pos)
       {
         Vector p(pos.x + parallax_image_size.width / 2.0f - image->get_width(),
                  pos.y + y * image->get_height() - image->get_height() / 2.0f);
-        context.draw_surface(image.get(), p, layer);
+        context.draw_surface(image, p, layer);
       }
       break;
 
@@ -177,7 +177,7 @@ Background::draw_image(DrawingContext& context, const Vector& pos)
       {
         Vector p(pos.x + x * image->get_width() - image->get_width() / 2.0f, 
                  pos.y - parallax_image_size.height / 2.0f);       
-        context.draw_surface(image.get(), p, layer);
+        context.draw_surface(image, p, layer);
       }
       break;
 
@@ -186,7 +186,7 @@ Background::draw_image(DrawingContext& context, const Vector& pos)
       {
         Vector p(pos.x + x * image->get_width()  - image->get_width() / 2.0f, 
                  pos.y - image->get_height() + parallax_image_size.height / 2.0f);       
-        context.draw_surface(image.get(), p, layer);
+        context.draw_surface(image, p, layer);
       }
       break;
 
@@ -199,15 +199,15 @@ Background::draw_image(DrawingContext& context, const Vector& pos)
 
           if (image_top.get() != NULL && (y < 0))
           {
-            context.draw_surface(image_top.get(), p, layer);
+            context.draw_surface(image_top, p, layer);
           }
           else if (image_bottom.get() != NULL && (y > 0))
           {
-            context.draw_surface(image_bottom.get(), p, layer);
+            context.draw_surface(image_bottom, p, layer);
           }
           else
           {
-            context.draw_surface(image.get(), p, layer);
+            context.draw_surface(image, p, layer);
           }
         }
       break;
index e2899cb..d428745 100644 (file)
@@ -25,8 +25,8 @@
 
 Candle::Candle(const Reader& lisp)
   : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true),
-    candle_light_1("images/objects/candle/candle-light-1.png"),
-    candle_light_2("images/objects/candle/candle-light-2.png")
+    candle_light_1(Surface::create("images/objects/candle/candle-light-1.png")),
+    candle_light_2(Surface::create("images/objects/candle/candle-light-2.png"))
 {
   lisp.get("name", name);
   lisp.get("burning", burning);
@@ -47,14 +47,14 @@ Candle::draw(DrawingContext& context)
 
   // draw on lightmap
   if (burning) {
-    Vector pos = get_pos() + (bbox.get_size() - candle_light_1.get_size()) / 2;
+    Vector pos = get_pos() + (bbox.get_size() - candle_light_1->get_size()) / 2;
     context.push_target();
     context.set_target(DrawingContext::LIGHTMAP);
     // draw approx. 1 in 10 frames darker. Makes the candle flicker
     if (systemRandom.rand(10) != 0) {
-      context.draw_surface(&candle_light_1, pos, layer);
+      context.draw_surface(candle_light_1, pos, layer);
     } else {
-      context.draw_surface(&candle_light_2, pos, layer);
+      context.draw_surface(candle_light_2, pos, layer);
     }
     context.pop_target();
   }
index ea82414..4b7146c 100644 (file)
@@ -48,8 +48,8 @@ public:
 
 private:
   bool burning; /**< true if candle is currently lighted */
-  Surface candle_light_1; /**< drawn to lightmap */
-  Surface candle_light_2; /**< drawn to lightmap (alternative image) */
+  SurfacePtr candle_light_1; /**< drawn to lightmap */
+  SurfacePtr candle_light_2; /**< drawn to lightmap (alternative image) */
 
 };
 
index 096b153..ace29ee 100644 (file)
@@ -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.get();
+    particle->texture = cloudimage;
     particle->speed = -systemRandom.randf(25.0, 54.0);
 
     particles.push_back(particle);
index 679ebf0..fb923f9 100644 (file)
@@ -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].get();
+    particle->texture = cometimages[cometsize];
     do {
       particle->speed = (cometsize+1)*30 + systemRandom.randf(3.6);
     } while(particle->speed < 1);
index ceadfec..17ddcf4 100644 (file)
@@ -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].get();
+    particle->texture = ghosts[size];
     particle->speed = systemRandom.randf(std::max(50, (size * 10)), 180 + (size * 10));
     particles.push_back(particle);
   }
index 8cc4d09..44d656b 100644 (file)
@@ -88,11 +88,13 @@ LevelTime::draw(DrawingContext& context)
     ss << int(time_left);
     std::string time_text = ss.str();
 
-    Surface* time_surf = time_surface.get();
-    if (time_surf) {
-      float all_width = time_surf->get_width() + Resources::normal_font->get_text_width(time_text);
-      context.draw_surface(time_surf, Vector((SCREEN_WIDTH - all_width)/2, BORDER_Y + 1), LAYER_FOREGROUND1);
-      context.draw_text(Resources::normal_font, time_text, Vector((SCREEN_WIDTH - all_width)/2 + time_surf->get_width(), BORDER_Y), ALIGN_LEFT, LAYER_FOREGROUND1, LevelTime::text_color);
+    if (time_surface)
+    {
+      float all_width = time_surface->get_width() + Resources::normal_font->get_text_width(time_text);
+      context.draw_surface(time_surface, Vector((SCREEN_WIDTH - all_width)/2, BORDER_Y + 1), LAYER_FOREGROUND1);
+      context.draw_text(Resources::normal_font, time_text, 
+                        Vector((SCREEN_WIDTH - all_width)/2 + time_surface->get_width(), BORDER_Y), 
+                        ALIGN_LEFT, LAYER_FOREGROUND1, LevelTime::text_color);
     }
   }
 
index 32259b1..0e72620 100644 (file)
@@ -22,8 +22,8 @@
 #include "math/vector.hpp"
 #include "supertux/game_object.hpp"
 #include "util/reader.hpp"
+#include "video/surface_ptr.hpp"
 
-class Surface;
 class DisplayManager;
 
 /**
@@ -62,7 +62,7 @@ protected:
     {}
 
     Vector pos;
-    Surface* texture;
+    SurfacePtr texture;
 
   private:
     Particle(const Particle&);
index 1a7796d..e703c27 100644 (file)
@@ -20,8 +20,8 @@
 #include "math/vector.hpp"
 #include "supertux/game_object.hpp"
 #include "supertux/sector.hpp"
+#include "video/surface_ptr.hpp"
 
-class Surface;
 class DisplayManager;
 
 /**
@@ -56,7 +56,7 @@ protected:
     {}
 
     Vector pos;
-    Surface* texture;
+    SurfacePtr texture;
 
   private:
     Particle(const Particle&);
index 6e756f3..11aeef5 100644 (file)
@@ -995,7 +995,7 @@ Player::draw(DrawingContext& context)
     float px = get_pos().x + (get_bbox().p2.x - get_bbox().p1.x - airarrow.get()->get_width()) / 2;
     float py = Sector::current()->camera->get_translation().y;
     py += std::min(((py - (get_bbox().p2.y + 16)) / 4), 16.0f);
-    context.draw_surface(airarrow.get(), Vector(px, py), LAYER_HUD - 1);
+    context.draw_surface(airarrow, Vector(px, py), LAYER_HUD - 1);
   }
 
   std::string sa_prefix = "";
index 5c5e9d9..4a6500f 100644 (file)
@@ -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].get();
+    particle->texture = rainimages[rainsize];
     do {
       particle->speed = (rainsize+1)*45 + systemRandom.randf(3.6);
     } while(particle->speed < 1);
index a6a2add..cc02ffc 100644 (file)
@@ -24,9 +24,9 @@
 
 SnowParticleSystem::SnowParticleSystem()
 {
-  snowimages[0] = new Surface("images/objects/particles/snow2.png");
-  snowimages[1] = new Surface("images/objects/particles/snow1.png");
-  snowimages[2] = new Surface("images/objects/particles/snow0.png");
+  snowimages[0] = Surface::create("images/objects/particles/snow2.png");
+  snowimages[1] = Surface::create("images/objects/particles/snow1.png");
+  snowimages[2] = Surface::create("images/objects/particles/snow0.png");
 
   virtual_width = SCREEN_WIDTH * 2;
 
@@ -59,8 +59,6 @@ SnowParticleSystem::parse(const Reader& reader)
 
 SnowParticleSystem::~SnowParticleSystem()
 {
-  for(int i=0;i<3;++i)
-    delete snowimages[i];
 }
 
 void SnowParticleSystem::update(float elapsed_time)
index 7c5510d..f66e923 100644 (file)
@@ -49,7 +49,7 @@ private:
     {}
   };
 
-  Surface* snowimages[3];
+  SurfacePtr snowimages[3];
 
 private:
   SnowParticleSystem(const SnowParticleSystem&);
index 7739a75..d4ac1c5 100644 (file)
@@ -159,13 +159,29 @@ Sprite::draw_part(DrawingContext& context, const Vector& source,
 int
 Sprite::get_width() const
 {
-  return (int) action->surfaces[get_frame()]->get_width();
+  if((int)frame >= get_frames() || (int)frame < 0)
+  {
+    log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+    return 0;
+  }
+  else
+  {
+    return (int) action->surfaces[get_frame()]->get_width();
+  }
 }
 
 int
 Sprite::get_height() const
 {
+  if((int)frame >= get_frames() || (int)frame < 0)
+  {
+    log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+    return 0;
+  }
+  else
+  {
   return (int) action->surfaces[get_frame()]->get_height();
+  }
 }
 
 float
index b2ec201..6328f41 100644 (file)
@@ -104,7 +104,7 @@ public:
   {
     this->frame = (float) (frame_ % get_frames());
   }
-  Surface* get_frame(unsigned int frame_)
+  SurfacePtr get_frame(unsigned int frame_)
   {
     assert(frame_ < action->surfaces.size());
     return action->surfaces[frame_];
index d9baad4..38e58d5 100644 (file)
@@ -43,9 +43,6 @@ SpriteData::Action::Action() :
 
 SpriteData::Action::~Action()
 {
-  for(std::vector<Surface*>::iterator i = surfaces.begin();
-      i != surfaces.end(); ++i)
-    delete *i;
 }
 
 SpriteData::SpriteData(const Reader& lisp, const std::string& basedir) :
@@ -113,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++) {
-        Surface* surface = new Surface(*(act_tmp->surfaces[i]));
+        SurfacePtr surface(new Surface(*act_tmp->surfaces[i]));
         surface->hflip();
         max_w = std::max(max_w, (float) surface->get_width());
         max_h = std::max(max_h, (float) surface->get_height());
@@ -134,7 +131,7 @@ SpriteData::parse_action(const Reader& lisp, const std::string& basedir)
     float max_w = 0;
     float max_h = 0;
     for(std::vector<std::string>::size_type i = 0; i < images.size(); i++) {
-      Surface* surface = new Surface(basedir + images[i]);
+      SurfacePtr surface = Surface::create(basedir + images[i]);
       max_w = std::max(max_w, (float) surface->get_width());
       max_h = std::max(max_h, (float) surface->get_height());
       action->surfaces.push_back(surface);
index f732cbe..d5e3a86 100644 (file)
@@ -61,7 +61,7 @@ private:
     /** Frames per second */
     float fps;
 
-    std::vector<Surface*> surfaces;
+    std::vector<SurfacePtr> surfaces;
   };
 
   typedef std::map <std::string, Action*> Actions;
index ffff99f..71a7fd5 100644 (file)
@@ -488,10 +488,10 @@ Console::draw(DrawingContext& context)
 
   context.push_transform();
   context.set_alpha(alpha);
-  context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), layer);
-  context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), layer);
+  context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), layer);
+  context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), layer);
   for (int x = (SCREEN_WIDTH/2 - background->get_width()/2 - (static_cast<int>(ceilf((float)SCREEN_WIDTH / (float)background->get_width()) - 1) * background->get_width())); x < SCREEN_WIDTH; x+=background->get_width()) {
-    context.draw_surface(background.get(), Vector(x, height - background->get_height()), layer);
+    context.draw_surface(background, Vector(x, height - background->get_height()), layer);
   }
   backgroundOffset+=10;
   if (backgroundOffset > (int)background->get_width()) backgroundOffset -= (int)background->get_width();
index cffb72d..b7d52ba 100644 (file)
@@ -591,7 +591,7 @@ GameSession::drawstatus(DrawingContext& context)
 
   // draw level stats while end_sequence is running
   if (end_sequence) {
-    level->stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop.get());
+    level->stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop);
   }
 }
 
index 0ba7f38..a5c6220 100644 (file)
@@ -79,12 +79,12 @@ InfoBox::draw(DrawingContext& context)
   {
     // draw the scrolling arrows
     if (arrow_scrollup.get() && firstline > 0)
-      context.draw_surface(arrow_scrollup.get(),
+      context.draw_surface(arrow_scrollup,
                            Vector( x1 + width  - arrow_scrollup->get_width(),  // top-right corner of box
                                    y1), LAYER_GUI);
 
     if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
-      context.draw_surface(arrow_scrolldown.get(),
+      context.draw_surface(arrow_scrolldown,
                            Vector( x1 + width  - arrow_scrolldown->get_width(),  // bottom-light corner of box
                                    y1 + height - arrow_scrolldown->get_height()),
                            LAYER_GUI);
index 119733f..b770792 100644 (file)
@@ -174,7 +174,7 @@ InfoBoxLine::draw(DrawingContext& context, const Rectf& bbox, int layer)
   Vector position = bbox.p1;
   switch (lineType) {
     case IMAGE:
-      context.draw_surface(image.get(), Vector( (bbox.p1.x + bbox.p2.x - image->get_width()) / 2, position.y), layer);
+      context.draw_surface(image, Vector( (bbox.p1.x + bbox.p2.x - image->get_width()) / 2, position.y), layer);
       break;
     case NORMAL_LEFT:
       context.draw_text(font, text, Vector(position.x, position.y), ALIGN_LEFT, layer, color);
index 4dc5188..0f322ca 100644 (file)
@@ -145,10 +145,12 @@ PlayerStatus::draw(DrawingContext& context)
   context.push_transform();
   context.set_translation(Vector(0, 0));
 
-  Surface* coin_surf = coin_surface.get();
-  if (coin_surf) {
-    context.draw_surface(coin_surf, Vector(SCREEN_WIDTH - BORDER_X - coin_surf->get_width() - Resources::fixed_font->get_text_width(coins_text), 
-                                                      BORDER_Y + 1), LAYER_HUD);
+  if (coin_surface)
+  {
+    context.draw_surface(coin_surface, 
+                         Vector(SCREEN_WIDTH - BORDER_X - coin_surface->get_width() - Resources::fixed_font->get_text_width(coins_text), 
+                                BORDER_Y + 1),
+                         LAYER_HUD);
   }
   context.draw_text(Resources::fixed_font, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), ALIGN_RIGHT, LAYER_HUD, PlayerStatus::text_color);
 
index 270d71b..6b294ff 100644 (file)
@@ -168,7 +168,7 @@ Statistics::draw_worldmap_info(DrawingContext& context)
 }
 
 void
-Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, Surface* backdrop)
+Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, SurfacePtr backdrop)
 {
   // skip draw if level was never played
   // TODO: do we need this?
index 3526602..5de05c8 100644 (file)
 #include <squirrel.h>
 
 #include "video/color.hpp"
+#include "video/surface_ptr.hpp"
 
 namespace lisp { class Writer; }
 namespace lisp { class Lisp; }
-class Surface;
 class DrawingContext;
 
 /** This class is a layer between level and worldmap to keep
@@ -64,7 +64,7 @@ public:
   void unserialize_from_squirrel(HSQUIRRELVM vm);
 
   void draw_worldmap_info(DrawingContext& context); /**< draw worldmap stat HUD */
-  void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, Surface* backdrop); /**< draw panel shown during level's end sequence */
+  void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, SurfacePtr backdrop); /**< draw panel shown during level's end sequence */
 
   void zero(); /**< Set stats to zero */
   void reset(); /**< Set stats (but not totals) to zero */
index e3a3d45..33002c3 100644 (file)
@@ -116,7 +116,7 @@ TextScroller::draw(DrawingContext& context)
 {
   context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
                            Color(0.6f, 0.7f, 0.8f, 0.5f), 0);
-  context.draw_surface(background.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 , SCREEN_HEIGHT/2 - background->get_height()/2), 0);
+  context.draw_surface(background, Vector(SCREEN_WIDTH/2 - background->get_width()/2 , SCREEN_HEIGHT/2 - background->get_height()/2), 0);
 
   float y = SCREEN_HEIGHT - scroll;
   for(size_t i = 0; i < lines.size(); i++) {
index 9369355..660dbf3 100644 (file)
@@ -44,10 +44,6 @@ Tile::Tile(const TileSet& new_tileset, const std::vector<ImageSpec>& imagespecs_
 
 Tile::~Tile()
 {
-  for(std::vector<Surface*>::iterator i = images.begin(); i != images.end();
-      ++i) {
-    delete *i;
-  }
 }
 
 void
@@ -60,18 +56,18 @@ Tile::load_images()
     {
       const ImageSpec& spec = *i;
 
-      Surface* surface;
+      SurfacePtr surface;
       if(spec.rect.get_width() <= 0) 
       {
-        surface = new Surface(spec.file);
+        surface = Surface::create(spec.file);
       }
       else 
       {
-        surface = new Surface(spec.file,
-                              Rect((int) spec.rect.p1.x,
-                                   (int) spec.rect.p1.y,
-                                   Size((int) spec.rect.get_width(),
-                                        (int) spec.rect.get_height())));
+        surface = Surface::create(spec.file,
+                                  Rect((int) spec.rect.p1.x,
+                                       (int) spec.rect.p1.y,
+                                       Size((int) spec.rect.get_width(),
+                                            (int) spec.rect.get_height())));
       }
       images.push_back(surface);
     }
index 690aef3..7ba7167 100644 (file)
@@ -94,7 +94,7 @@ public:
 private:
   const TileSet&         tileset;
   std::vector<ImageSpec> imagespecs;
-  std::vector<Surface*>  images;
+  std::vector<SurfacePtr>  images;
 
   /// tile attributes
   uint32_t attributes;
index f9791bc..8d30139 100644 (file)
@@ -139,7 +139,7 @@ TitleScreen::draw(DrawingContext& context)
   sector->draw(context);
 
   // FIXME: Add something to scale the frame to the resolution of the screen
-  context.draw_surface(frame.get(), Vector(0,0),LAYER_FOREGROUND1);
+  context.draw_surface(frame, Vector(0,0),LAYER_FOREGROUND1);
 
   context.draw_text(Resources::small_font, "SuperTux " PACKAGE_VERSION "\n",
                     Vector(5, SCREEN_HEIGHT - 50), ALIGN_LEFT, LAYER_FOREGROUND1);
index e831fe0..5a31e4d 100644 (file)
@@ -78,7 +78,7 @@ DrawingContext::init_renderer()
 }
 
 void
-DrawingContext::draw_surface(const Surface* surface, const Vector& position,
+DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
                              float angle, const Color& color, const Blend& blend,
                              int layer)
 {
@@ -102,20 +102,20 @@ DrawingContext::draw_surface(const Surface* surface, const Vector& position,
   request->color = color;
   request->blend = blend;
 
-  request->request_data = const_cast<Surface*> (surface);
+  request->request_data = surface.get();
 
   requests->push_back(request);
 }
 
 void
-DrawingContext::draw_surface(const Surface* surface, const Vector& position,
+DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
                              int layer)
 {
   draw_surface(surface, position, 0.0f, Color(1.0f, 1.0f, 1.0f), Blend(), layer);
 }
 
 void
-DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
+DrawingContext::draw_surface_part(SurfacePtr surface, const Vector& source,
                                   const Vector& size, const Vector& dest, int layer)
 {
   assert(surface != 0);
@@ -132,7 +132,7 @@ DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
   SurfacePartRequest* surfacepartrequest = new(obst) SurfacePartRequest();
   surfacepartrequest->size = size;
   surfacepartrequest->source = source;
-  surfacepartrequest->surface = surface;
+  surfacepartrequest->surface = surface.get();
 
   // clip on screen borders
   if(request->pos.x < 0) {
index 6845288..6a8f447 100644 (file)
@@ -48,14 +48,14 @@ public:
   void init_renderer();
 
   /// Adds a drawing request for a surface into the request list.
-  void draw_surface(const Surface* surface, const Vector& position,
+  void draw_surface(SurfacePtr surface, const Vector& position,
                     int layer);
   /// Adds a drawing request for a surface into the request list.
-  void draw_surface(const Surface* surface, const Vector& position,
+  void draw_surface(SurfacePtr surface, const Vector& position,
                     float angle, const Color& color, const Blend& blend,
                     int layer);
   /// Adds a drawing request for part of a surface.
-  void draw_surface_part(const Surface* surface, const Vector& source,
+  void draw_surface_part(SurfacePtr surface, const Vector& source,
                          const Vector& size, const Vector& dest, int layer);
   /// Draws a text.
   void draw_text(const Font* font, const std::string& text,
index 4db7d0d..08cfa99 100644 (file)
@@ -254,7 +254,7 @@ GLLightmap::draw_surface_part(const DrawingRequest& request)
 {
   const SurfacePartRequest* surfacepartrequest
     = (SurfacePartRequest*) request.request_data;
-  const Surface *surface = surfacepartrequest->surface;
+  const Surfacesurface = surfacepartrequest->surface;
   GLTexture *gltexture = dynamic_cast<GLTexture *>(surface->get_texture());
   GLSurfaceData *surface_data = reinterpret_cast<GLSurfaceData *>(surface->get_surface_data());
 
index d9ab2e6..9c88cd3 100644 (file)
@@ -215,7 +215,7 @@ GLRenderer::draw_surface_part(const DrawingRequest& request)
 {
   const SurfacePartRequest* surfacepartrequest
     = (SurfacePartRequest*) request.request_data;
-  const Surface *surface = surfacepartrequest->surface;
+  const Surfacesurface = surfacepartrequest->surface;
   GLTexture *gltexture = dynamic_cast<GLTexture *>(surface->get_texture());
   GLSurfaceData *surface_data = reinterpret_cast<GLSurfaceData *>(surface->get_surface_data());