SpriteManager Class Reference

#include <sprite_manager.hpp>

List of all members.

Public Member Functions

 SpriteManager ()
 ~SpriteManager ()
SpritePtr create (const std::string &filename)
 loads a sprite.

Private Types

typedef std::map< std::string,
SpriteData * > 
Sprites

Private Member Functions

SpriteDataload (const std::string &filename)

Private Attributes

Sprites sprites


Detailed Description

Definition at line 28 of file sprite_manager.hpp.


Member Typedef Documentation

typedef std::map<std::string, SpriteData*> SpriteManager::Sprites [private]

Definition at line 31 of file sprite_manager.hpp.


Constructor & Destructor Documentation

SpriteManager::SpriteManager (  ) 

Definition at line 28 of file sprite_manager.cpp.

00028                              :
00029   sprites()
00030 {
00031 }

SpriteManager::~SpriteManager (  ) 

Definition at line 33 of file sprite_manager.cpp.

References sprites.

00034 {
00035   for(Sprites::iterator i = sprites.begin(); i != sprites.end(); ++i) {
00036     delete i->second;
00037   }
00038 }


Member Function Documentation

SpritePtr SpriteManager::create ( const std::string &  filename  ) 

loads a sprite.

Definition at line 41 of file sprite_manager.cpp.

References load(), and sprites.

Referenced by BouncyCoin::BouncyCoin(), Bullet::Bullet(), Door::Door(), FallingCoin::FallingCoin(), Firefly::Firefly(), Flower::Flower(), GhostTree::GhostTree(), Haywire::Haywire(), Lantern::Lantern(), LevelIntro::LevelIntro(), worldmap::LevelTile::LevelTile(), Light::Light(), MovingSprite::MovingSprite(), MrBomb::MrBomb(), Player::Player(), RainSplash::RainSplash(), Root::Root(), ShortFuse::ShortFuse(), SmokeCloud::SmokeCloud(), worldmap::SpecialTile::SpecialTile(), Spotlight::Spotlight(), worldmap::SpriteChange::SpriteChange(), SpriteParticle::SpriteParticle(), Switch::Switch(), worldmap::Teleporter::Teleporter(), Trampoline::Trampoline(), and worldmap::Tux::Tux().

00042 {
00043   Sprites::iterator i = sprites.find(name);
00044   SpriteData* data;
00045   if(i == sprites.end()) {
00046     // try loading the spritefile
00047     data = load(name);
00048     if(data == NULL) {
00049       std::stringstream msg;
00050       msg << "Sprite '" << name << "' not found.";
00051       throw std::runtime_error(msg.str());
00052     }
00053   } else {
00054     data = i->second;
00055   }
00056 
00057   return SpritePtr(new Sprite(*data));
00058 }

SpriteData * SpriteManager::load ( const std::string &  filename  )  [private]

Definition at line 61 of file sprite_manager.cpp.

References FileSystem::basename(), FileSystem::dirname(), lisp::Lisp::get_lisp(), lisp::Parser::parse(), and sprites.

Referenced by create().

00062 {
00063   lisp::Parser parser;
00064   const lisp::Lisp* root;
00065 
00066   try {
00067     if(filename.size() >= 7 && filename.compare(filename.size() - 7, 7, ".sprite") == 0) {
00068         // Sprite file
00069         root = parser.parse(filename);
00070     } else {
00071       // Load image file directly
00072       std::stringstream lisptext;
00073       lisptext << "(supertux-sprite (action "
00074                <<    "(name \"default\") "
00075                <<    "(images \"" << FileSystem::basename(filename) << "\")))";
00076 
00077       root = parser.parse(lisptext, "SpriteManager::load");
00078     }
00079   } catch(const std::exception& e) {
00080     std::ostringstream msg;
00081     msg << "Parse error when trying to load sprite '" << filename
00082         << "': " << e.what() << "\n";
00083     throw std::runtime_error(msg.str());
00084   }
00085 
00086   const lisp::Lisp* sprite = root->get_lisp("supertux-sprite");
00087   if(!sprite) {
00088     std::ostringstream msg;
00089     msg << "'" << filename << "' is not a supertux-sprite file";
00090     throw std::runtime_error(msg.str());
00091   }
00092 
00093   std::auto_ptr<SpriteData> data (
00094     new SpriteData(*sprite, FileSystem::dirname(filename)) );
00095   sprites[filename] = data.release();
00096 
00097   return sprites[filename];
00098 }


Member Data Documentation

Sprites SpriteManager::sprites [private]

Definition at line 32 of file sprite_manager.hpp.

Referenced by create(), load(), and ~SpriteManager().


The documentation for this class was generated from the following files:
Generated on Mon Apr 14 03:38:45 2014 for SuperTux by  doxygen 1.5.1