From ee07b379861b6fee4bb49a4a6e06c0f7b1e7fe2b Mon Sep 17 00:00:00 2001 From: grumbel Date: Sun, 13 Dec 2009 23:51:40 +0000 Subject: [PATCH] More use of SurfacePtr git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6211 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/badguy/yeti.cpp | 19 +++++++++---------- src/gui/button.cpp | 2 +- src/gui/button.hpp | 6 +++--- src/gui/menu.cpp | 10 +++++----- src/gui/mousecursor.cpp | 3 +-- src/gui/mousecursor.hpp | 4 ++-- src/object/background.cpp | 14 +++++++------- src/object/candle.cpp | 10 +++++----- src/object/candle.hpp | 4 ++-- src/object/cloud_particle_system.cpp | 2 +- src/object/comet_particle_system.cpp | 2 +- src/object/ghost_particle_system.cpp | 2 +- src/object/level_time.cpp | 12 +++++++----- src/object/particlesystem.hpp | 4 ++-- src/object/particlesystem_interactive.hpp | 4 ++-- src/object/player.cpp | 2 +- src/object/rain_particle_system.cpp | 2 +- src/object/snow_particle_system.cpp | 8 +++----- src/object/snow_particle_system.hpp | 2 +- src/sprite/sprite.cpp | 18 +++++++++++++++++- src/sprite/sprite.hpp | 2 +- src/sprite/sprite_data.cpp | 7 ++----- src/sprite/sprite_data.hpp | 2 +- src/supertux/console.cpp | 6 +++--- src/supertux/game_session.cpp | 2 +- src/supertux/info_box.cpp | 4 ++-- src/supertux/info_box_line.cpp | 2 +- src/supertux/player_status.cpp | 10 ++++++---- src/supertux/statistics.cpp | 2 +- src/supertux/statistics.hpp | 4 ++-- src/supertux/textscroller.cpp | 2 +- src/supertux/tile.cpp | 18 +++++++----------- src/supertux/tile.hpp | 2 +- src/supertux/title_screen.cpp | 2 +- src/video/drawing_context.cpp | 10 +++++----- src/video/drawing_context.hpp | 6 +++--- src/video/gl/gl_lightmap.cpp | 2 +- src/video/gl/gl_renderer.cpp | 2 +- 38 files changed, 112 insertions(+), 103 deletions(-) diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 26cdfb174..ba8b54a4f 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -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 diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 7a5762097..0105741ff 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -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(), diff --git a/src/gui/button.hpp b/src/gui/button.hpp index f66d86873..7d08232ff 100644 --- a/src/gui/button.hpp +++ b/src/gui/button.hpp @@ -21,8 +21,8 @@ #include #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; diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 2e1c17d5d..ab6c37be0 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -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; diff --git a/src/gui/mousecursor.cpp b/src/gui/mousecursor.cpp index 7139d2efb..599400332 100644 --- a/src/gui/mousecursor.cpp +++ b/src/gui/mousecursor.cpp @@ -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() diff --git a/src/gui/mousecursor.hpp b/src/gui/mousecursor.hpp index 897a7eeaa..7e4d3b33c 100644 --- a/src/gui/mousecursor.hpp +++ b/src/gui/mousecursor.hpp @@ -19,7 +19,7 @@ #include -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_; diff --git a/src/object/background.cpp b/src/object/background.cpp index 09d147c7d..597aa9d8d 100644 --- a/src/object/background.cpp +++ b/src/object/background.cpp @@ -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; diff --git a/src/object/candle.cpp b/src/object/candle.cpp index e2899cb73..d428745e4 100644 --- a/src/object/candle.cpp +++ b/src/object/candle.cpp @@ -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(); } diff --git a/src/object/candle.hpp b/src/object/candle.hpp index ea82414a4..4b7146cc5 100644 --- a/src/object/candle.hpp +++ b/src/object/candle.hpp @@ -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) */ }; diff --git a/src/object/cloud_particle_system.cpp b/src/object/cloud_particle_system.cpp index 096b15382..ace29eeca 100644 --- a/src/object/cloud_particle_system.cpp +++ b/src/object/cloud_particle_system.cpp @@ -35,7 +35,7 @@ CloudParticleSystem::CloudParticleSystem() : CloudParticle* particle = new CloudParticle; particle->pos.x = systemRandom.rand(static_cast(virtual_width)); particle->pos.y = systemRandom.rand(static_cast(virtual_height)); - particle->texture = cloudimage.get(); + particle->texture = cloudimage; particle->speed = -systemRandom.randf(25.0, 54.0); particles.push_back(particle); diff --git a/src/object/comet_particle_system.cpp b/src/object/comet_particle_system.cpp index 679ebf0bd..fb923f98f 100644 --- a/src/object/comet_particle_system.cpp +++ b/src/object/comet_particle_system.cpp @@ -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); diff --git a/src/object/ghost_particle_system.cpp b/src/object/ghost_particle_system.cpp index ceadfec8e..17ddcf418 100644 --- a/src/object/ghost_particle_system.cpp +++ b/src/object/ghost_particle_system.cpp @@ -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); } diff --git a/src/object/level_time.cpp b/src/object/level_time.cpp index 8cc4d092b..44d656b81 100644 --- a/src/object/level_time.cpp +++ b/src/object/level_time.cpp @@ -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); } } diff --git a/src/object/particlesystem.hpp b/src/object/particlesystem.hpp index 32259b16c..0e72620f3 100644 --- a/src/object/particlesystem.hpp +++ b/src/object/particlesystem.hpp @@ -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&); diff --git a/src/object/particlesystem_interactive.hpp b/src/object/particlesystem_interactive.hpp index 1a7796db7..e703c27ac 100644 --- a/src/object/particlesystem_interactive.hpp +++ b/src/object/particlesystem_interactive.hpp @@ -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&); diff --git a/src/object/player.cpp b/src/object/player.cpp index 6e756f373..11aeef549 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -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 = ""; diff --git a/src/object/rain_particle_system.cpp b/src/object/rain_particle_system.cpp index 5c5e9d9f1..4a6500f03 100644 --- a/src/object/rain_particle_system.cpp +++ b/src/object/rain_particle_system.cpp @@ -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); diff --git a/src/object/snow_particle_system.cpp b/src/object/snow_particle_system.cpp index a6a2added..cc02ffc1b 100644 --- a/src/object/snow_particle_system.cpp +++ b/src/object/snow_particle_system.cpp @@ -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) diff --git a/src/object/snow_particle_system.hpp b/src/object/snow_particle_system.hpp index 7c5510d43..f66e923fb 100644 --- a/src/object/snow_particle_system.hpp +++ b/src/object/snow_particle_system.hpp @@ -49,7 +49,7 @@ private: {} }; - Surface* snowimages[3]; + SurfacePtr snowimages[3]; private: SnowParticleSystem(const SnowParticleSystem&); diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index 7739a7566..d4ac1c5a2 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -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 diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index b2ec201e6..6328f41ea 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -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_]; diff --git a/src/sprite/sprite_data.cpp b/src/sprite/sprite_data.cpp index d9baad459..38e58d5fc 100644 --- a/src/sprite/sprite_data.cpp +++ b/src/sprite/sprite_data.cpp @@ -43,9 +43,6 @@ SpriteData::Action::Action() : SpriteData::Action::~Action() { - for(std::vector::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(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::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); diff --git a/src/sprite/sprite_data.hpp b/src/sprite/sprite_data.hpp index f732cbeda..d5e3a86ee 100644 --- a/src/sprite/sprite_data.hpp +++ b/src/sprite/sprite_data.hpp @@ -61,7 +61,7 @@ private: /** Frames per second */ float fps; - std::vector surfaces; + std::vector surfaces; }; typedef std::map Actions; diff --git a/src/supertux/console.cpp b/src/supertux/console.cpp index ffff99fad..71a7fd592 100644 --- a/src/supertux/console.cpp +++ b/src/supertux/console.cpp @@ -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(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(); diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index cffb72d3f..b7d52ba5d 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -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); } } diff --git a/src/supertux/info_box.cpp b/src/supertux/info_box.cpp index 0ba7f380d..a5c62204d 100644 --- a/src/supertux/info_box.cpp +++ b/src/supertux/info_box.cpp @@ -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); diff --git a/src/supertux/info_box_line.cpp b/src/supertux/info_box_line.cpp index 119733f0a..b77079277 100644 --- a/src/supertux/info_box_line.cpp +++ b/src/supertux/info_box_line.cpp @@ -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); diff --git a/src/supertux/player_status.cpp b/src/supertux/player_status.cpp index 4dc518809..0f322cad9 100644 --- a/src/supertux/player_status.cpp +++ b/src/supertux/player_status.cpp @@ -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); diff --git a/src/supertux/statistics.cpp b/src/supertux/statistics.cpp index 270d71bc1..6b294ffbf 100644 --- a/src/supertux/statistics.cpp +++ b/src/supertux/statistics.cpp @@ -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? diff --git a/src/supertux/statistics.hpp b/src/supertux/statistics.hpp index 35266024d..5de05c836 100644 --- a/src/supertux/statistics.hpp +++ b/src/supertux/statistics.hpp @@ -22,10 +22,10 @@ #include #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 */ diff --git a/src/supertux/textscroller.cpp b/src/supertux/textscroller.cpp index e3a3d45b3..33002c3e9 100644 --- a/src/supertux/textscroller.cpp +++ b/src/supertux/textscroller.cpp @@ -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++) { diff --git a/src/supertux/tile.cpp b/src/supertux/tile.cpp index 936935519..660dbf311 100644 --- a/src/supertux/tile.cpp +++ b/src/supertux/tile.cpp @@ -44,10 +44,6 @@ Tile::Tile(const TileSet& new_tileset, const std::vector& imagespecs_ Tile::~Tile() { - for(std::vector::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); } diff --git a/src/supertux/tile.hpp b/src/supertux/tile.hpp index 690aef323..7ba7167d7 100644 --- a/src/supertux/tile.hpp +++ b/src/supertux/tile.hpp @@ -94,7 +94,7 @@ public: private: const TileSet& tileset; std::vector imagespecs; - std::vector images; + std::vector images; /// tile attributes uint32_t attributes; diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index f9791bc19..8d3013993 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -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); diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index e831fe063..5a31e4d5d 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -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); + 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) { diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index 684528846..6a8f447c6 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -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, diff --git a/src/video/gl/gl_lightmap.cpp b/src/video/gl/gl_lightmap.cpp index 4db7d0d19..08cfa99a8 100644 --- a/src/video/gl/gl_lightmap.cpp +++ b/src/video/gl/gl_lightmap.cpp @@ -254,7 +254,7 @@ GLLightmap::draw_surface_part(const DrawingRequest& request) { const SurfacePartRequest* surfacepartrequest = (SurfacePartRequest*) request.request_data; - const Surface *surface = surfacepartrequest->surface; + const Surface* surface = surfacepartrequest->surface; GLTexture *gltexture = dynamic_cast(surface->get_texture()); GLSurfaceData *surface_data = reinterpret_cast(surface->get_surface_data()); diff --git a/src/video/gl/gl_renderer.cpp b/src/video/gl/gl_renderer.cpp index d9ab2e6df..9c88cd34b 100644 --- a/src/video/gl/gl_renderer.cpp +++ b/src/video/gl/gl_renderer.cpp @@ -215,7 +215,7 @@ GLRenderer::draw_surface_part(const DrawingRequest& request) { const SurfacePartRequest* surfacepartrequest = (SurfacePartRequest*) request.request_data; - const Surface *surface = surfacepartrequest->surface; + const Surface* surface = surfacepartrequest->surface; GLTexture *gltexture = dynamic_cast(surface->get_texture()); GLSurfaceData *surface_data = reinterpret_cast(surface->get_surface_data()); -- 2.11.0