Fixed a bug in the multi-hex tiling code...

...causing severe memory corruption and failure to invalidate old
terrains when terrains were rebuilt.
This commit is contained in:
Philippe Plantier 2004-05-17 21:12:17 +00:00
parent e3c775bb9e
commit 20940bde4b
2 changed files with 17 additions and 2 deletions

View File

@ -16,6 +16,19 @@
#include "util.hpp"
#include "log.hpp"
void terrain_builder::tile::clear()
{
flags.clear();
images_foreground.clear();
images_background.clear();
}
void terrain_builder::tilemap::reset()
{
for(std::vector<tile>::iterator it = map_.begin(); it != map_.end(); ++it)
it->clear();
}
terrain_builder::terrain_builder(const config& cfg, const gamemap& gmap) :
map_(gmap), tile_map_(gmap.x(), gmap.y())
{
@ -41,7 +54,7 @@ const std::vector<image::locator> *terrain_builder::get_terrain_at(const gamemap
void terrain_builder::rebuild_terrain(const gamemap::location &loc)
{
tile_map_.clear();
tile_map_.reset();
terrain_by_type_.clear();
// For now, rebuild the whole map on each rebuilt_terrain. This is highly slow and

View File

@ -68,6 +68,8 @@ private:
std::set<std::string> flags;
std::vector<image::locator> images_foreground;
std::vector<image::locator> images_background;
void clear();
};
struct tilemap
@ -76,7 +78,7 @@ private:
tile &operator[](const gamemap::location &loc) { return map_[(loc.x+1) + (loc.y+1)*(x_+2)]; }
const tile &operator[] (const gamemap::location &loc) const { return map_[(loc.x+1) + (loc.y+1)*(x_+2)]; }
void clear() { map_.clear(); }
void reset();
std::vector<tile> map_;
int x_;