From: Florian Forster Date: Sun, 21 Feb 2010 08:15:57 +0000 (+0000) Subject: Bug 524: Fading TileMaps may change solidity of the TileMap. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=87c5da21eaa57842230bf19d24ffd12d3c1cc974;p=supertux.git Bug 524: Fading TileMaps may change solidity of the TileMap. When the alpha value of a layer is changed to > .75, the solid flag will be set. When the alpha value of a layer is changed to < .25, the solid flag is cleared. This prevents hiding background / foreground layers at the beginning of the level and display them as a result to some action of the player. Resolves #524. SVN-Revision: 6342 --- diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index 9528a81d6..43a100f27 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -28,7 +28,8 @@ TileMap::TileMap(const TileSet *new_tileset) : tileset(new_tileset), tiles(), - solid(false), + real_solid(false), + effective_solid(false), speed_x(1), speed_y(1), width(0), @@ -49,7 +50,8 @@ TileMap::TileMap(const TileSet *new_tileset) : TileMap::TileMap(const Reader& reader) : tileset(), tiles(), - solid(false), + real_solid(false), + effective_solid(false), speed_x(1), speed_y(1), width(-1), @@ -69,13 +71,13 @@ TileMap::TileMap(const Reader& reader) : assert(tileset != NULL); reader.get("name", name); - reader.get("solid", solid); + reader.get("solid", real_solid); reader.get("speed", speed_x); reader.get("speed-y", speed_y); z_pos = reader_get_layer (reader, /* default = */ 0); - if(solid && ((speed_x != 1) || (speed_y != 1))) { + if(real_solid && ((speed_x != 1) || (speed_y != 1))) { log_warning << "Speed of solid tilemap is not 1. fixing" << std::endl; speed_x = 1; speed_y = 1; @@ -99,6 +101,10 @@ TileMap::TileMap(const Reader& reader) : current_alpha = alpha; } + /* Initialize effective_solid based on real_solid and current_alpha. */ + effective_solid = real_solid; + update_effective_solid (); + reader.get("width", width); reader.get("height", height); if(width < 0 || height < 0) @@ -130,7 +136,8 @@ TileMap::TileMap(const TileSet *new_tileset, std::string name, int z_pos, bool solid, size_t width, size_t height) : tileset(new_tileset), tiles(), - solid(solid), + real_solid(solid), + effective_solid(solid), speed_x(1), speed_y(1), width(0), @@ -171,8 +178,7 @@ TileMap::update(float elapsed_time) if (amt > 0) current_alpha = std::min(current_alpha + amt, alpha); if (amt < 0) current_alpha = std::max(current_alpha + amt, alpha); } - if ((alpha < 0.25) && (current_alpha < 0.25)) set_solid(false); - if ((alpha > 0.75) && (current_alpha > 0.75)) set_solid(true); + update_effective_solid (); } movement = Vector(0,0); @@ -288,7 +294,8 @@ TileMap::set(int newwidth, int newheight, const std::vector&newt, z_pos = LAYER_GUI - 100; else z_pos = new_z_pos; - solid = newsolid; + real_solid = newsolid; + update_effective_solid (); // make sure all tiles are loaded for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i) @@ -343,7 +350,8 @@ TileMap::get_tiles_overlapping(const Rectf &rect) const void TileMap::set_solid(bool solid) { - this->solid = solid; + this->real_solid = solid; + update_effective_solid (); } uint32_t @@ -418,8 +426,7 @@ TileMap::set_alpha(float alpha) this->alpha = alpha; this->current_alpha = alpha; this->remaining_fade_time = 0; - if (current_alpha < 0.25) set_solid(false); - if (current_alpha > 0.75) set_solid(true); + update_effective_solid (); } float @@ -428,5 +435,18 @@ TileMap::get_alpha() return this->current_alpha; } +/* + * Private methods + */ +void +TileMap::update_effective_solid (void) +{ + if (!real_solid) + effective_solid = false; + else if (effective_solid && (current_alpha < .25)) + effective_solid = false; + else if (!effective_solid && (current_alpha >= .75)) + effective_solid = true; +} /* EOF */ diff --git a/src/object/tilemap.hpp b/src/object/tilemap.hpp index ff6bd0b1c..c2b61dd05 100644 --- a/src/object/tilemap.hpp +++ b/src/object/tilemap.hpp @@ -106,7 +106,7 @@ public: { return z_pos; } bool is_solid() const - { return solid; } + { return real_solid && effective_solid; } /** * Changes Tilemap's solidity, i.e. whether to consider it when doing collision detection. @@ -161,7 +161,14 @@ private: typedef std::vector Tiles; Tiles tiles; - bool solid; + /* read solid: In *general*, is this a solid layer? + * effective solid: is the layer *currently* solid? A generally solid layer + * may be not solid when its alpha is low. + * See `is_solid' above. */ + bool real_solid; + bool effective_solid; + void update_effective_solid (void); + float speed_x; float speed_y; int width, height;