From 6f6fc74f3174670efe954e4815797fcdd6573037 Mon Sep 17 00:00:00 2001 From: grumbel Date: Sat, 21 Nov 2009 16:28:12 +0000 Subject: [PATCH] Replaced .reset(new Surface()) with a factory method Added some more std::auto_ptr instead of Surface* git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6081 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/object/cloud_particle_system.cpp | 5 ++--- src/object/cloud_particle_system.hpp | 4 +++- src/object/comet_particle_system.cpp | 8 +++----- src/object/comet_particle_system.hpp | 4 +++- src/object/ghost_particle_system.cpp | 8 +++----- src/object/ghost_particle_system.hpp | 4 +++- src/object/rain_particle_system.cpp | 8 +++----- src/object/rain_particle_system.hpp | 4 +++- src/supertux/info_box.cpp | 19 ++++++++----------- src/supertux/info_box.hpp | 5 +++-- src/supertux/title_screen.cpp | 2 +- 11 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/object/cloud_particle_system.cpp b/src/object/cloud_particle_system.cpp index dda8c6909..096b15382 100644 --- a/src/object/cloud_particle_system.cpp +++ b/src/object/cloud_particle_system.cpp @@ -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(virtual_width)); particle->pos.y = systemRandom.rand(static_cast(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) diff --git a/src/object/cloud_particle_system.hpp b/src/object/cloud_particle_system.hpp index 236940f4a..db7b3d349 100644 --- a/src/object/cloud_particle_system.hpp +++ b/src/object/cloud_particle_system.hpp @@ -17,6 +17,8 @@ #ifndef HEADER_SUPERTUX_OBJECT_CLOUD_PARTICLE_SYTEM_HPP #define HEADER_SUPERTUX_OBJECT_CLOUD_PARTICLE_SYTEM_HPP +#include + #include "object/particlesystem.hpp" class CloudParticleSystem : public ParticleSystem @@ -43,7 +45,7 @@ private: {} }; - Surface* cloudimage; + std::auto_ptr cloudimage; private: CloudParticleSystem(const CloudParticleSystem&); diff --git a/src/object/comet_particle_system.cpp b/src/object/comet_particle_system.cpp index eb2e37725..679ebf0bd 100644 --- a/src/object/comet_particle_system.cpp +++ b/src/object/comet_particle_system.cpp @@ -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) diff --git a/src/object/comet_particle_system.hpp b/src/object/comet_particle_system.hpp index 7eb7e9c1f..f627a0533 100644 --- a/src/object/comet_particle_system.hpp +++ b/src/object/comet_particle_system.hpp @@ -17,6 +17,8 @@ #ifndef HEADER_SUPERTUX_OBJECT_COMET_PARTICLE_SYSTEM_HPP #define HEADER_SUPERTUX_OBJECT_COMET_PARTICLE_SYSTEM_HPP +#include + #include "object/particlesystem_interactive.hpp" class CometParticleSystem : public ParticleSystem_Interactive @@ -44,7 +46,7 @@ private: {} }; - Surface* cometimages[2]; + std::auto_ptr cometimages[2]; private: CometParticleSystem(const CometParticleSystem&); diff --git a/src/object/ghost_particle_system.cpp b/src/object/ghost_particle_system.cpp index aca6ccd19..ceadfec8e 100644 --- a/src/object/ghost_particle_system.cpp +++ b/src/object/ghost_particle_system.cpp @@ -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) diff --git a/src/object/ghost_particle_system.hpp b/src/object/ghost_particle_system.hpp index 6a85e0455..f8cf89bd6 100644 --- a/src/object/ghost_particle_system.hpp +++ b/src/object/ghost_particle_system.hpp @@ -17,6 +17,8 @@ #ifndef HEADER_SUPERTUX_OBJECT_GHOST_PARTICLE_SYSTEM_HPP #define HEADER_SUPERTUX_OBJECT_GHOST_PARTICLE_SYSTEM_HPP +#include + #include "object/particlesystem.hpp" class GhostParticleSystem : public ParticleSystem @@ -43,7 +45,7 @@ private: {} }; - Surface* ghosts[2]; + std::auto_ptr ghosts[2]; private: GhostParticleSystem(const GhostParticleSystem&); diff --git a/src/object/rain_particle_system.cpp b/src/object/rain_particle_system.cpp index 3f4a1252f..5c5e9d9f1 100644 --- a/src/object/rain_particle_system.cpp +++ b/src/object/rain_particle_system.cpp @@ -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) diff --git a/src/object/rain_particle_system.hpp b/src/object/rain_particle_system.hpp index 25715ea32..e3c257fe3 100644 --- a/src/object/rain_particle_system.hpp +++ b/src/object/rain_particle_system.hpp @@ -17,6 +17,8 @@ #ifndef HEADER_SUPERTUX_OBJECT_RAIN_PARTICLE_SYSTEM_HPP #define HEADER_SUPERTUX_OBJECT_RAIN_PARTICLE_SYSTEM_HPP +#include + #include "object/particlesystem_interactive.hpp" class RainParticleSystem : public ParticleSystem_Interactive @@ -43,7 +45,7 @@ private: {} }; - Surface* rainimages[2]; + std::auto_ptr rainimages[2]; private: RainParticleSystem(const RainParticleSystem&); diff --git a/src/supertux/info_box.cpp b/src/supertux/info_box.cpp index c6d997f4e..c5521c88a 100644 --- a/src/supertux/info_box.cpp +++ b/src/supertux/info_box.cpp @@ -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::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); diff --git a/src/supertux/info_box.hpp b/src/supertux/info_box.hpp index 190617a4a..6286a646e 100644 --- a/src/supertux/info_box.hpp +++ b/src/supertux/info_box.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_SUPERTUX_INFO_BOX_HPP #include +#include #include #include @@ -42,8 +43,8 @@ private: size_t firstline; std::vector lines; std::map images; - Surface* arrow_scrollup; - Surface* arrow_scrolldown; + std::auto_ptr arrow_scrollup; + std::auto_ptr arrow_scrolldown; private: InfoBox(const InfoBox&); diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index d77e38169..0372be321 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -54,7 +54,7 @@ TitleScreen::TitleScreen() : player->set_controller(controller.get()); player->set_speedlimit(230); //MAX_WALK_XM - frame = std::auto_ptr(new Surface("images/engine/menu/frame.png")); + frame = Surface::create("images/engine/menu/frame.png"); } std::string -- 2.11.0