From: Ingo Ruhnke Date: Mon, 14 Dec 2009 05:59:31 +0000 (+0000) Subject: Added SpritePtr X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=fa3bd983c1922084854d90bd2b46ecfb8cab581c;p=supertux.git Added SpritePtr SVN-Revision: 6215 --- diff --git a/src/badguy/ghosttree.hpp b/src/badguy/ghosttree.hpp index a139554e1..d71cad891 100644 --- a/src/badguy/ghosttree.hpp +++ b/src/badguy/ghosttree.hpp @@ -53,7 +53,7 @@ private: float willo_speed; int willo_color; - std::auto_ptr glow_sprite; + SpritePtr glow_sprite; Timer colorchange_timer; Timer suck_timer; Timer root_timer; diff --git a/src/badguy/root.hpp b/src/badguy/root.hpp index 2c05bbb3d..35df91ab6 100644 --- a/src/badguy/root.hpp +++ b/src/badguy/root.hpp @@ -41,7 +41,7 @@ protected: private: MyState mystate; - std::auto_ptr base_sprite; + SpritePtr base_sprite; float offset_y; Timer hatch_timer; }; diff --git a/src/object/block.cpp b/src/object/block.cpp index 7209bd36f..c18fef3d8 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -30,7 +30,7 @@ static const float BOUNCY_BRICK_SPEED = 90; static const float EPSILON = .0001f; static const float BUMP_ROTATION_ANGLE = 10; -Block::Block(std::auto_ptr newsprite) : +Block::Block(SpritePtr newsprite) : sprite(newsprite), bouncing(false), breaking(false), diff --git a/src/object/block.hpp b/src/object/block.hpp index fecbd0f14..767a414f2 100644 --- a/src/object/block.hpp +++ b/src/object/block.hpp @@ -19,16 +19,16 @@ #include +#include "sprite/sprite_ptr.hpp" #include "supertux/moving_object.hpp" #include "util/reader_fwd.hpp" -class Sprite; class Player; class Block : public MovingObject { public: - Block(std::auto_ptr sprite); + Block(SpritePtr sprite); ~Block(); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); @@ -43,7 +43,7 @@ protected: void start_break(GameObject* hitter); void break_me(); - std::auto_ptr sprite; + SpritePtr sprite; bool bouncing; bool breaking; float bounce_dir; diff --git a/src/object/bonus_block.cpp b/src/object/bonus_block.cpp index f09cef28f..d612c7093 100644 --- a/src/object/bonus_block.cpp +++ b/src/object/bonus_block.cpp @@ -214,15 +214,15 @@ Block::break_me() { Sector* sector = Sector::current(); sector->add_object( - new BrokenBrick(std::auto_ptr(new Sprite(*sprite)), get_pos(), Vector(-100, -400))); + new BrokenBrick(sprite->clone(), get_pos(), Vector(-100, -400))); sector->add_object( - new BrokenBrick(std::auto_ptr(new Sprite(*sprite)), get_pos() + Vector(0, 16), + new BrokenBrick(sprite->clone(), get_pos() + Vector(0, 16), Vector(-150, -300))); sector->add_object( - new BrokenBrick(std::auto_ptr(new Sprite(*sprite)), get_pos() + Vector(16, 0), + new BrokenBrick(sprite->clone(), get_pos() + Vector(16, 0), Vector(100, -400))); sector->add_object( - new BrokenBrick(std::auto_ptr(new Sprite(*sprite)), get_pos() + Vector(16, 16), + new BrokenBrick(sprite->clone(), get_pos() + Vector(16, 16), Vector(150, -300))); remove_me(); } diff --git a/src/object/bouncy_coin.hpp b/src/object/bouncy_coin.hpp index 1fd98eb2a..8709ac45f 100644 --- a/src/object/bouncy_coin.hpp +++ b/src/object/bouncy_coin.hpp @@ -20,6 +20,7 @@ #include #include "math/vector.hpp" +#include "sprite/sprite_ptr.hpp" #include "supertux/game_object.hpp" #include "supertux/timer.hpp" #include "video/color.hpp" @@ -35,7 +36,7 @@ public: virtual void draw(DrawingContext& context); private: - std::auto_ptr sprite; + SpritePtr sprite; Vector position; Timer timer; float emerge_distance; diff --git a/src/object/broken_brick.cpp b/src/object/broken_brick.cpp index bdf3db229..c907f14ea 100644 --- a/src/object/broken_brick.cpp +++ b/src/object/broken_brick.cpp @@ -19,7 +19,7 @@ #include "math/random_generator.hpp" #include "sprite/sprite.hpp" -BrokenBrick::BrokenBrick(std::auto_ptr sprite, +BrokenBrick::BrokenBrick(SpritePtr sprite, const Vector& pos, const Vector& nmovement) : timer(), sprite(sprite), diff --git a/src/object/broken_brick.hpp b/src/object/broken_brick.hpp index 5543662ab..6a0bceb3c 100644 --- a/src/object/broken_brick.hpp +++ b/src/object/broken_brick.hpp @@ -20,16 +20,15 @@ #include #include "math/vector.hpp" +#include "sprite/sprite_ptr.hpp" #include "supertux/game_object.hpp" #include "supertux/timer.hpp" #include "video/color.hpp" -class Sprite; - class BrokenBrick : public GameObject { public: - BrokenBrick(std::auto_ptr sprite, const Vector& pos, const Vector& movement); + BrokenBrick(SpritePtr sprite, const Vector& pos, const Vector& movement); ~BrokenBrick(); virtual void update(float elapsed_time); @@ -37,7 +36,7 @@ public: private: Timer timer; - std::auto_ptr sprite; + SpritePtr sprite; Vector position; Vector movement; diff --git a/src/object/bullet.hpp b/src/object/bullet.hpp index ca90159fe..90977eac4 100644 --- a/src/object/bullet.hpp +++ b/src/object/bullet.hpp @@ -48,7 +48,7 @@ public: private: Physic physic; int life_count; - std::auto_ptr sprite; + SpritePtr sprite; BonusType type; }; diff --git a/src/object/falling_coin.hpp b/src/object/falling_coin.hpp index 3b614c8b6..629aa366d 100644 --- a/src/object/falling_coin.hpp +++ b/src/object/falling_coin.hpp @@ -33,7 +33,7 @@ public: private: Physic physic; Vector pos; - std::auto_ptr sprite; + SpritePtr sprite; }; #endif diff --git a/src/object/floating_image.hpp b/src/object/floating_image.hpp index 40b7d4c7b..85a7697fc 100644 --- a/src/object/floating_image.hpp +++ b/src/object/floating_image.hpp @@ -18,8 +18,8 @@ #define HEADER_SUPERTUX_OBJECT_FLOATING_IMAGE_HPP #include "object/anchor_point.hpp" +#include "sprite/sprite_ptr.hpp" #include "supertux/game_object.hpp" -#include class Sprite; @@ -68,7 +68,7 @@ public: void draw(DrawingContext& context); private: - std::auto_ptr sprite; + SpritePtr sprite; int layer; bool visible; AnchorPoint anchor; diff --git a/src/object/flower.hpp b/src/object/flower.hpp index 1437d2e60..1f3648a30 100644 --- a/src/object/flower.hpp +++ b/src/object/flower.hpp @@ -33,7 +33,7 @@ public: private: BonusType type; - std::auto_ptr sprite; + SpritePtr sprite; private: Flower(const Flower&); diff --git a/src/object/lantern.hpp b/src/object/lantern.hpp index 0c47dc350..1177374c9 100644 --- a/src/object/lantern.hpp +++ b/src/object/lantern.hpp @@ -49,7 +49,7 @@ public: private: Color lightcolor; - std::auto_ptr lightsprite; + SpritePtr lightsprite; void updateColor(); private: diff --git a/src/object/light.hpp b/src/object/light.hpp index 5b0b88c68..2afbfbd37 100644 --- a/src/object/light.hpp +++ b/src/object/light.hpp @@ -20,11 +20,10 @@ #include #include "math/vector.hpp" +#include "sprite/sprite_ptr.hpp" #include "supertux/game_object.hpp" #include "video/color.hpp" -class Sprite; - class Light : public GameObject { public: @@ -37,7 +36,7 @@ public: protected: Vector position; Color color; - std::auto_ptr sprite; + SpritePtr sprite; }; #endif diff --git a/src/object/moving_sprite.cpp b/src/object/moving_sprite.cpp index a79759949..4f06e07fb 100644 --- a/src/object/moving_sprite.cpp +++ b/src/object/moving_sprite.cpp @@ -80,7 +80,7 @@ MovingSprite::MovingSprite(const MovingSprite& other) : sprite(), layer(other.layer) { - sprite.reset(new Sprite(*other.sprite)); + sprite = other.sprite->clone(); } /* MovingSprite& diff --git a/src/object/moving_sprite.hpp b/src/object/moving_sprite.hpp index 95b5c0508..a75e2cad0 100644 --- a/src/object/moving_sprite.hpp +++ b/src/object/moving_sprite.hpp @@ -21,8 +21,7 @@ #include "supertux/moving_object.hpp" #include "util/reader_fwd.hpp" #include "video/drawing_request.hpp" - -class Sprite; +#include "sprite/sprite_ptr.hpp" /** * Abstract base class for MovingObjects that are represented by a Sprite @@ -54,7 +53,7 @@ public: protected: std::string sprite_name; - std::auto_ptr sprite; + SpritePtr sprite; int layer; /**< Sprite's z-position. Refer to video/drawing_context.hpp for sensible values. */ /** set new action for sprite and resize bounding box. use with diff --git a/src/object/player.hpp b/src/object/player.hpp index ebcf86368..f30e4542a 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_OBJECT_PLAYER_HPP #include "scripting/player.hpp" +#include "sprite/sprite_ptr.hpp" #include "supertux/direction.hpp" #include "supertux/moving_object.hpp" #include "supertux/physic.hpp" @@ -30,7 +31,6 @@ class Portable; class Climbable; class Controller; class CodeController; -class Sprite; class Surface; class Timer; @@ -298,7 +298,7 @@ public: Portable* grabbed_object; - std::auto_ptr sprite; /**< The main sprite representing Tux */ + SpritePtr sprite; /**< The main sprite representing Tux */ SurfacePtr airarrow; /**< arrow indicating Tux' position when he's above the camera */ diff --git a/src/object/rainsplash.hpp b/src/object/rainsplash.hpp index ad4f85ad2..279618aa5 100644 --- a/src/object/rainsplash.hpp +++ b/src/object/rainsplash.hpp @@ -34,7 +34,7 @@ protected: virtual void draw(DrawingContext& context); private: - std::auto_ptr sprite; + SpritePtr sprite; Vector position; int frame; }; diff --git a/src/object/smoke_cloud.hpp b/src/object/smoke_cloud.hpp index dca316e53..4b436720d 100644 --- a/src/object/smoke_cloud.hpp +++ b/src/object/smoke_cloud.hpp @@ -17,9 +17,8 @@ #ifndef HEADER_SUPERTUX_OBJECT_SMOKE_CLOUD_HPP #define HEADER_SUPERTUX_OBJECT_SMOKE_CLOUD_HPP -#include - #include "math/vector.hpp" +#include "sprite/sprite_ptr.hpp" #include "supertux/game_object.hpp" #include "supertux/timer.hpp" #include "video/color.hpp" @@ -36,7 +35,7 @@ public: virtual void draw(DrawingContext& context); private: - std::auto_ptr sprite; + SpritePtr sprite; Timer timer; Vector position; diff --git a/src/object/spotlight.hpp b/src/object/spotlight.hpp index 006a49d48..5edf7d95a 100644 --- a/src/object/spotlight.hpp +++ b/src/object/spotlight.hpp @@ -21,11 +21,10 @@ #include "util/reader_fwd.hpp" #include "math/vector.hpp" +#include "sprite/sprite_ptr.hpp" #include "supertux/game_object.hpp" #include "video/color.hpp" -class Sprite; - class Spotlight : public GameObject { public: @@ -38,11 +37,11 @@ public: private: Vector position; float angle; - std::auto_ptr center; - std::auto_ptr base; - std::auto_ptr lights; - std::auto_ptr light; - std::auto_ptr lightcone; + SpritePtr center; + SpritePtr base; + SpritePtr lights; + SpritePtr light; + SpritePtr lightcone; Color color; }; diff --git a/src/object/sprite_particle.hpp b/src/object/sprite_particle.hpp index 85e7f9f57..6a32e052e 100644 --- a/src/object/sprite_particle.hpp +++ b/src/object/sprite_particle.hpp @@ -35,7 +35,7 @@ protected: virtual void draw(DrawingContext& context); private: - std::auto_ptr sprite; + SpritePtr sprite; Vector position; Vector velocity; Vector acceleration; diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index d4ac1c5a2..2e63074cc 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -51,6 +51,12 @@ Sprite::~Sprite() { } +SpritePtr +Sprite::clone() const +{ + return SpritePtr(new Sprite(*this)); +} + void Sprite::set_action(const std::string& name, int loops) { diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index 6328f41ea..a82f05e78 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_SPRITE_SPRITE_HPP #include "sprite/sprite_data.hpp" +#include "sprite/sprite_ptr.hpp" #include "video/drawing_context.hpp" class Surface; @@ -28,9 +29,10 @@ class Sprite { public: Sprite(SpriteData& data); - Sprite(const Sprite& other); ~Sprite(); + SpritePtr clone() const; + /** Draw sprite, automatically calculates next frame */ void draw(DrawingContext& context, const Vector& pos, int layer); @@ -125,6 +127,7 @@ private: SpriteData::Action* action; private: + Sprite(const Sprite& other); Sprite& operator=(const Sprite&); }; diff --git a/src/sprite/sprite_manager.cpp b/src/sprite/sprite_manager.cpp index 8422fda77..fd100b1b9 100644 --- a/src/sprite/sprite_manager.cpp +++ b/src/sprite/sprite_manager.cpp @@ -33,7 +33,7 @@ SpriteManager::~SpriteManager() } } -std::auto_ptr +SpritePtr SpriteManager::create(const std::string& name) { Sprites::iterator i = sprites.find(name); @@ -50,7 +50,7 @@ SpriteManager::create(const std::string& name) data = i->second; } - return std::auto_ptr(new Sprite(*data)); + return SpritePtr(new Sprite(*data)); } SpriteData* diff --git a/src/sprite/sprite_manager.hpp b/src/sprite/sprite_manager.hpp index 520da88ff..d769f1d92 100644 --- a/src/sprite/sprite_manager.hpp +++ b/src/sprite/sprite_manager.hpp @@ -21,8 +21,9 @@ #include #include +#include "sprite/sprite_ptr.hpp" + class SpriteData; -class Sprite; class SpriteManager { @@ -35,7 +36,7 @@ public: ~SpriteManager(); /** loads a sprite. */ - std::auto_ptr create(const std::string& filename); + SpritePtr create(const std::string& filename); private: SpriteData* load(const std::string& filename); diff --git a/src/sprite/sprite_ptr.hpp b/src/sprite/sprite_ptr.hpp new file mode 100644 index 000000000..1f6a12a7d --- /dev/null +++ b/src/sprite/sprite_ptr.hpp @@ -0,0 +1,28 @@ +// SuperTux +// Copyright (C) 2009 Ingo Ruhnke +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_SPRITE_SPRITE_PTR_HPP +#define HEADER_SUPERTUX_SPRITE_SPRITE_PTR_HPP + +#include + +class Sprite; + +typedef boost::shared_ptr SpritePtr; + +#endif + +/* EOF */ diff --git a/src/supertux/levelintro.hpp b/src/supertux/levelintro.hpp index e39decf51..336c33eca 100644 --- a/src/supertux/levelintro.hpp +++ b/src/supertux/levelintro.hpp @@ -47,7 +47,7 @@ public: private: const Level* level; /**< The level of which this is the intro screen */ const Statistics* best_level_statistics; /**< Best level statistics of the level of which is the intro screen */ - std::auto_ptr player_sprite; /**< Sprite representing the player */ + SpritePtr player_sprite; /**< Sprite representing the player */ float player_sprite_py; /**< Position (y axis) for the player sprite */ float player_sprite_vy; /**< Velocity (y axis) for the player sprite */ Timer player_sprite_jump_timer; /**< When timer fires, the player sprite will "jump" */ diff --git a/src/trigger/door.hpp b/src/trigger/door.hpp index 0e93611c7..41e1a14f2 100644 --- a/src/trigger/door.hpp +++ b/src/trigger/door.hpp @@ -46,7 +46,7 @@ private: DoorState state; /**< current state of the door */ std::string target_sector; /**< target sector to teleport to */ std::string target_spawnpoint; /**< target spawnpoint to teleport to */ - std::auto_ptr sprite; /**< "door" sprite to render */ + SpritePtr sprite; /**< "door" sprite to render */ Timer stay_open_timer; /**< time until door will close again */ }; diff --git a/src/trigger/switch.hpp b/src/trigger/switch.hpp index 3bfd59a51..8141a8ffd 100644 --- a/src/trigger/switch.hpp +++ b/src/trigger/switch.hpp @@ -44,7 +44,7 @@ private: private: std::string sprite_name; - std::auto_ptr sprite; + SpritePtr sprite; std::string script; SwitchState state; }; diff --git a/src/trigger/trigger_base.hpp b/src/trigger/trigger_base.hpp index bbb1c164d..5d07527ea 100644 --- a/src/trigger/trigger_base.hpp +++ b/src/trigger/trigger_base.hpp @@ -20,11 +20,11 @@ #include #include +#include "sprite/sprite_ptr.hpp" #include "supertux/moving_object.hpp" #include "supertux/object_remove_listener.hpp" class Player; -class Sprite; /** This class is the base class for all objects you can interact with in some * way. There are several interaction types defined like touch and activate @@ -57,7 +57,7 @@ public: virtual void object_removed(GameObject* object); private: - std::auto_ptr sprite; + SpritePtr sprite; bool lasthit; bool hit; diff --git a/src/worldmap/level.hpp b/src/worldmap/level.hpp index 9120badca..54b62e63a 100644 --- a/src/worldmap/level.hpp +++ b/src/worldmap/level.hpp @@ -45,7 +45,7 @@ public: bool solved; bool auto_play; /**< true if Tux should automatically enter this level if it's unfinished */ - std::auto_ptr sprite; + SpritePtr sprite; /** Statistics for level tiles */ Statistics statistics; diff --git a/src/worldmap/special_tile.hpp b/src/worldmap/special_tile.hpp index 6fd13de59..3a6fa6312 100644 --- a/src/worldmap/special_tile.hpp +++ b/src/worldmap/special_tile.hpp @@ -21,11 +21,10 @@ #include #include -#include "util/reader_fwd.hpp" #include "math/vector.hpp" +#include "sprite/sprite_ptr.hpp" #include "supertux/game_object.hpp" - -class Sprite; +#include "util/reader_fwd.hpp" namespace worldmap { @@ -42,7 +41,7 @@ public: Vector pos; /** Sprite to render instead of guessing what image to draw */ - std::auto_ptr sprite; + SpritePtr sprite; /** Message to show in the Map */ std::string map_message; diff --git a/src/worldmap/sprite_change.hpp b/src/worldmap/sprite_change.hpp index 0f7843e31..9493880e6 100644 --- a/src/worldmap/sprite_change.hpp +++ b/src/worldmap/sprite_change.hpp @@ -56,7 +56,7 @@ public: bool change_on_touch; /** sprite to change tux image to */ - std::auto_ptr sprite; + SpritePtr sprite; /** stay action can be used for objects like boats or cars, if it is != "" then this sprite will be displayed when tux left the tile diff --git a/src/worldmap/teleporter.hpp b/src/worldmap/teleporter.hpp index 210e5467c..f0fa1769f 100644 --- a/src/worldmap/teleporter.hpp +++ b/src/worldmap/teleporter.hpp @@ -41,7 +41,7 @@ public: Vector pos; /** Sprite to render, or 0 for no sprite */ - std::auto_ptr sprite; + SpritePtr sprite; /** Worldmap filename (relative to data root) to teleport to. Leave empty to use current word */ std::string worldmap; diff --git a/src/worldmap/tux.cpp b/src/worldmap/tux.cpp index dfbe6efbf..7ecfb12d1 100644 --- a/src/worldmap/tux.cpp +++ b/src/worldmap/tux.cpp @@ -185,7 +185,7 @@ Tux::tryContinueWalking(float elapsed_time) SpriteChange* sprite_change = worldmap->at_sprite_change(tile_pos); if(sprite_change != NULL) { - sprite.reset(new Sprite( *(sprite_change->sprite.get()) )); + sprite = sprite_change->sprite->clone(); sprite_change->clear_stay_action(); } @@ -272,7 +272,7 @@ Tux::tryContinueWalking(float elapsed_time) SpriteChange* next_sprite = worldmap->at_sprite_change(next_tile); if(next_sprite != NULL && next_sprite->change_on_touch) { - sprite.reset(new Sprite( *(next_sprite->sprite.get()) )); + sprite = next_sprite->sprite->clone(); next_sprite->clear_stay_action(); } SpriteChange* last_sprite = worldmap->at_sprite_change(tile_pos); @@ -313,7 +313,7 @@ Tux::setup() // check if we already touch a SpriteChange object SpriteChange* sprite_change = worldmap->at_sprite_change(tile_pos); if(sprite_change != NULL) { - sprite.reset(new Sprite( *(sprite_change->sprite.get()) )); + sprite = sprite_change->sprite->clone(); sprite_change->clear_stay_action(); } } diff --git a/src/worldmap/tux.hpp b/src/worldmap/tux.hpp index a4a485203..1eb54c6ed 100644 --- a/src/worldmap/tux.hpp +++ b/src/worldmap/tux.hpp @@ -32,7 +32,7 @@ public: Direction back_direction; private: WorldMap* worldmap; - std::auto_ptr sprite; + SpritePtr sprite; Controller* controller; Direction input_direction;