Author: sapient
Date: Tue May 1 03:04:32 2007
New Revision: 17221
URL: http://svn.gna.org/viewcvs/wesnoth?rev=17221&view=rev
Log:
cache the parsed terrain list when matching a location filter (as requested by
Mordante)
Modified:
trunk/src/map.cpp
trunk/src/map.hpp
Modified: trunk/src/map.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.cpp?rev=17221&r1=17220&r2=17221&view=diff
==============================================================================
--- trunk/src/map.cpp (original)
+++ trunk/src/map.cpp Tue May 1 03:04:32 2007
@@ -562,6 +562,14 @@
return true;
}
+namespace {
+ struct terrain_cache_manager {
+ terrain_cache_manager() : ptr(NULL) {}
+ ~terrain_cache_manager() { delete ptr; }
+ t_translation::t_list *ptr;
+ };
+} //end anonymous namespace
+
bool gamemap::terrain_matches_filter(const gamemap::location& loc, const
vconfig& cfg,
const gamestatus& game_status, const unit_map& units, const
bool flat_tod,
const size_t max_loop) const
@@ -576,8 +584,9 @@
size_t loop_count = 0;
bool matches = false;
std::set<gamemap::location>::const_iterator i;
+ terrain_cache_manager tcm;
for(i = hexes.begin(); i != hexes.end() && loop_count <= max_loop &&
!matches; ++i) {
- matches = terrain_matches_internal(*i, cfg, game_status, units,
flat_tod);
+ matches = terrain_matches_internal(*i, cfg, game_status, units,
flat_tod, false, tcm.ptr);
++loop_count;
}
if(!matches) return false;
@@ -594,7 +603,7 @@
bool gamemap::terrain_matches_internal(const gamemap::location& loc, const
vconfig& cfg,
const gamestatus& game_status, const unit_map& units, const
bool flat_tod,
- const bool ignore_xy) const
+ const bool ignore_xy, t_translation::t_list*& parsed_terrain)
const
{
const int terrain_format = lexical_cast_default(cfg["terrain_format"],
-1);
@@ -602,12 +611,16 @@
lg::wml_error << "key terrain_format in filter_location is no
longer used, this message will disappear in 1.3.5\n";
}
- const t_translation::t_list& terrain =
t_translation::read_list(cfg["terrain"]);
- if(! terrain.empty()) {
-
- const t_translation::t_letter letter =
get_terrain_info(loc).number();
- if(! t_translation::terrain_matches(letter, terrain)) {
+ if(cfg.has_attribute("terrain")) {
+ if(parsed_terrain == NULL) {
+ t_translation::t_list& parsed_list =
t_translation::read_list(cfg["terrain"]);
+ parsed_terrain = new t_translation::t_list(parsed_list);
+ }
+ if(!parsed_terrain->empty()) {
+ const t_translation::t_letter letter =
get_terrain_info(loc).number();
+ if(!t_translation::terrain_matches(letter,
*parsed_terrain)) {
return false;
+ }
}
}
@@ -783,9 +796,10 @@
}
//handle filter
+ terrain_cache_manager tcm;
std::vector<gamemap::location>::iterator loc_itor = xy_locs.begin();
while(loc_itor != xy_locs.end()) {
- if(terrain_matches_internal(*loc_itor, filter, game_status,
units, flat_tod, true)) {
+ if(terrain_matches_internal(*loc_itor, filter, game_status,
units, flat_tod, true, tcm.ptr)) {
++loc_itor;
} else {
loc_itor = xy_locs.erase(loc_itor);
Modified: trunk/src/map.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/map.hpp?rev=17221&r1=17220&r2=17221&view=diff
==============================================================================
--- trunk/src/map.hpp (original)
+++ trunk/src/map.hpp Tue May 1 03:04:32 2007
@@ -219,7 +219,8 @@
private:
bool terrain_matches_internal(const location& loc, const vconfig& cfg,
const gamestatus& game_status, const unit_map& units,
- const bool flat_tod=false, const bool ignore_xy=false)
const;
+ const bool flat_tod, const bool ignore_xy,
+ t_translation::t_list*& parsed_terrain) const;
int num_starting_positions() const
{ return
sizeof(startingPositions_)/sizeof(*startingPositions_); }
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits