From: grumbel Date: Sun, 6 Dec 2009 00:01:30 +0000 (+0000) Subject: Got rid of some friend'ship, reducing some access of private member variables X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=a12bb1a7cc0c12fc9db3c43aeaccc28093699746;p=supertux.git Got rid of some friend'ship, reducing some access of private member variables git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6171 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- diff --git a/src/supertux/tile.cpp b/src/supertux/tile.cpp index 01cdff0ce..8ce0755a6 100644 --- a/src/supertux/tile.cpp +++ b/src/supertux/tile.cpp @@ -156,24 +156,27 @@ Tile::parse_images(const Reader& images_lisp) void Tile::load_images() { - const std::string& tiles_path = tileset->tiles_path; - - assert(images.size() == 0); - for(std::vector::iterator i = imagespecs.begin(); i != - imagespecs.end(); ++i) { - const ImageSpec& spec = *i; - Surface* surface; - std::string file = tiles_path + spec.file; - if(spec.rect.get_width() <= 0) { - surface = new Surface(file); - } else { - surface = new Surface(file, - (int) spec.rect.p1.x, - (int) spec.rect.p1.y, - (int) spec.rect.get_width(), - (int) spec.rect.get_height()); + if(images.size() == 0 && imagespecs.size() != 0) + { + const std::string& tiles_path = tileset->tiles_path; + + assert(images.size() == 0); + for(std::vector::iterator i = imagespecs.begin(); i != + imagespecs.end(); ++i) { + const ImageSpec& spec = *i; + Surface* surface; + std::string file = tiles_path + spec.file; + if(spec.rect.get_width() <= 0) { + surface = new Surface(file); + } else { + surface = new Surface(file, + (int) spec.rect.p1.x, + (int) spec.rect.p1.y, + (int) spec.rect.get_width(), + (int) spec.rect.get_height()); + } + images.push_back(surface); } - images.push_back(surface); } } @@ -188,7 +191,8 @@ Tile::draw(DrawingContext& context, const Vector& pos, int z_pos) const } } -void Tile::correct_attributes() +void +Tile::correct_attributes() { //Fix little oddities in attributes (not many, currently...) if(!(attributes & SOLID) && (attributes & SLOPE || attributes & UNISOLID)) { @@ -198,4 +202,14 @@ void Tile::correct_attributes() } } +void +Tile::print_debug(int id) const +{ + log_debug << " Tile: id " << id << ", data " << getData() << ", attributes " << getAttributes() << ":" << std::endl; + for(std::vector::const_iterator im = imagespecs.begin(); im != imagespecs.end(); ++im) + { + log_debug << " Imagespec: file " << im->file << "; rect " << im->rect << std::endl; + } +} + /* EOF */ diff --git a/src/supertux/tile.hpp b/src/supertux/tile.hpp index 3e13d9b42..64636316b 100644 --- a/src/supertux/tile.hpp +++ b/src/supertux/tile.hpp @@ -108,8 +108,14 @@ private: float anim_fps; public: + Tile(const TileSet* tileset); + Tile(const TileSet* tileset, std::vector images, Rect rect, + uint32_t attributes, uint32_t data, float animfps); ~Tile(); + /** load Surfaces, if not already loaded */ + void load_images(); + /** Draw a tile on the screen */ void draw(DrawingContext& context, const Vector& pos, int z_pos) const; @@ -123,28 +129,34 @@ public: int getWidth() const { if(!images.size()) + { return 0; - return (int) images[0]->get_width(); + } + else + { + return (int) images[0]->get_width(); + } } /// returns the height of the tiles in pixels int getHeight() const { if(!images.size()) + { return 0; - return (int) images[0]->get_height(); + } + else + { + return (int) images[0]->get_height(); + } } -protected: - friend class TileSet; - Tile(const TileSet *tileset); - Tile(const TileSet *tileset, std::vector images, Rect rect, - uint32_t attributes = 0, uint32_t data = 0, float animfps = 1.0); - - void load_images(); - /// parses the tile and returns it's id number uint32_t parse(const Reader& reader); + + void print_debug(int id) const; + +private: void parse_images(const Reader& cur); //Correct small oddities in attributes that naive people diff --git a/src/supertux/tile_set.cpp b/src/supertux/tile_set.cpp index 48306eb54..c816d36f5 100644 --- a/src/supertux/tile_set.cpp +++ b/src/supertux/tile_set.cpp @@ -172,13 +172,9 @@ TileSet::TileSet(const std::string& filename) : log_debug << "Tileset in " << filename << std::endl; for(int i = 0; i < int(tiles.size()); ++i) { - if(tiles[i] == 0) - continue; - Tile* t = tiles[i]; - log_debug << " Tile: id " << i << ", data " << t->data << ", attributes " << t->attributes << ":" << std::endl; - for(std::vector::iterator im = t->imagespecs.begin(); im != - t->imagespecs.end(); ++im) { - log_debug << " Imagespec: file " << im->file << "; rect " << im->rect << std::endl; + if(tiles[i] != 0) + { + tiles[i]->print_debug(i); } } } diff --git a/src/supertux/tile_set.hpp b/src/supertux/tile_set.hpp index 467ec6859..8c4410e20 100644 --- a/src/supertux/tile_set.hpp +++ b/src/supertux/tile_set.hpp @@ -51,8 +51,7 @@ public: return tiles[0]; } - if(tile->images.size() == 0 && tile->imagespecs.size() != 0) - tile->load_images(); + tile->load_images(); return tile; }