mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-09 03:14:20 +00:00
remove gamema::bordercache and gamema::terrainfrequencycache
Both are not used anymore because maps now always include a border and gamemap::get_weighted_terrain_frequencies() was removed.
This commit is contained in:
parent
296faefa20
commit
94611c6967
@ -109,8 +109,6 @@ gamemap::gamemap(const tdata_cache& tdata, const std::string& data):
|
||||
tiles_(1, 1),
|
||||
tdata_(tdata),
|
||||
villages_(),
|
||||
borderCache_(),
|
||||
terrainFrequencyCache_(),
|
||||
w_(-1),
|
||||
h_(-1)
|
||||
{
|
||||
@ -312,65 +310,7 @@ t_translation::t_terrain gamemap::get_terrain(const map_location& loc) const
|
||||
return (*this)[loc];
|
||||
}
|
||||
|
||||
if ( loc == map_location::null_location() ) {
|
||||
return t_translation::NONE_TERRAIN;
|
||||
}
|
||||
|
||||
const std::map<map_location, t_translation::t_terrain>::const_iterator itor = borderCache_.find(loc);
|
||||
if(itor != borderCache_.end())
|
||||
return itor->second;
|
||||
|
||||
// If not on the board, decide based on what surrounding terrain is
|
||||
t_translation::t_terrain items[6];
|
||||
int number_of_items = 0;
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc,adj);
|
||||
for(int n = 0; n != 6; ++n) {
|
||||
if(on_board(adj[n])) {
|
||||
items[number_of_items] = tiles_[adj[n].x][adj[n].y];
|
||||
++number_of_items;
|
||||
} else {
|
||||
// If the terrain is off map but already in the border cache,
|
||||
// this will be used to determine the terrain.
|
||||
// This avoids glitches
|
||||
// * on map with an even width in the top right corner
|
||||
// * on map with an odd height in the bottom left corner.
|
||||
// It might also change the result on other map and become random,
|
||||
// but the border tiles will be determined in the future, so then
|
||||
// this will no longer be used in the game
|
||||
// (The editor will use this feature to expand maps in a better way).
|
||||
std::map<map_location, t_translation::t_terrain>::const_iterator itor =
|
||||
borderCache_.find(adj[n]);
|
||||
|
||||
// Only add if it is in the cache and a valid terrain
|
||||
if(itor != borderCache_.end() &&
|
||||
itor->second != t_translation::NONE_TERRAIN) {
|
||||
|
||||
items[number_of_items] = itor->second;
|
||||
++number_of_items;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Count all the terrain types found,
|
||||
// and see which one is the most common, and use it.
|
||||
t_translation::t_terrain used_terrain;
|
||||
int terrain_count = 0;
|
||||
for(int i = 0; i != number_of_items; ++i) {
|
||||
if(items[i] != used_terrain && !tdata_->is_village(items[i]) && !tdata_->is_keep(items[i])) {
|
||||
const int c = std::count(items+i+1,items+number_of_items,items[i]) + 1;
|
||||
if(c > terrain_count) {
|
||||
used_terrain = items[i];
|
||||
terrain_count = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
borderCache_.insert(std::pair<map_location, t_translation::t_terrain>(loc,used_terrain));
|
||||
return used_terrain;
|
||||
|
||||
return loc == map_location::null_location() ? t_translation::NONE_TERRAIN : t_translation::t_terrain();
|
||||
}
|
||||
|
||||
map_location gamemap::special_location(const std::string& id) const
|
||||
@ -467,14 +407,6 @@ void gamemap::set_terrain(const map_location& loc, const t_translation::t_terrai
|
||||
}
|
||||
|
||||
(*this)[loc] = new_terrain;
|
||||
|
||||
// Update the off-map autogenerated tiles
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc,adj);
|
||||
|
||||
for(int n = 0; n < 6; ++n) {
|
||||
remove_from_border_cache(adj[n]);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<map_location> gamemap::parse_location_range(const std::string &x, const std::string &y,
|
||||
|
@ -106,10 +106,13 @@ public:
|
||||
{
|
||||
return tiles_.get(loc.x + border_size(), loc.y + border_size());
|
||||
}
|
||||
private:
|
||||
//private method, use set_terrain instead which also updates villages_.
|
||||
t_translation::t_terrain& operator[](const map_location& loc)
|
||||
{
|
||||
return tiles_.get(loc.x + border_size(), loc.y + border_size());
|
||||
}
|
||||
public:
|
||||
|
||||
/**
|
||||
* Looks up terrain at a particular location.
|
||||
@ -166,15 +169,6 @@ public:
|
||||
*/
|
||||
void set_terrain(const map_location& loc, const t_translation::t_terrain & terrain, const terrain_type_data::tmerge_mode mode=terrain_type_data::BOTH, bool replace_if_failed = false);
|
||||
|
||||
/**
|
||||
* Remove the cached border terrain at loc.
|
||||
*
|
||||
* Needed by the editor to make tiles at the border update correctly when
|
||||
* drawing other tiles.
|
||||
*/
|
||||
void remove_from_border_cache(const map_location &loc)
|
||||
{ borderCache_.erase(loc); }
|
||||
|
||||
/**
|
||||
* Maximum number of players supported.
|
||||
*
|
||||
@ -230,9 +224,6 @@ private:
|
||||
tdata_cache tdata_;
|
||||
std::vector<map_location> villages_;
|
||||
|
||||
mutable std::map<map_location, t_translation::t_terrain> borderCache_;
|
||||
mutable std::map<t_translation::t_terrain, size_t> terrainFrequencyCache_;
|
||||
|
||||
protected:
|
||||
/** Sizes of the map area. */
|
||||
int w_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user