mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-28 00:58:29 +00:00
terrain_filter caches its unit filter construction
This commit is contained in:
parent
9bfe3b561d
commit
27436d9b0f
@ -100,6 +100,13 @@ terrain_filter& terrain_filter::operator=(const terrain_filter& other)
|
||||
return *this ;
|
||||
}
|
||||
|
||||
terrain_filter::terrain_filter_cache::terrain_filter_cache() :
|
||||
parsed_terrain(NULL),
|
||||
adjacent_matches(NULL),
|
||||
adjacent_match_cache(),
|
||||
ufilter_()
|
||||
{}
|
||||
|
||||
namespace {
|
||||
struct cfg_isor {
|
||||
bool operator() (std::pair<const std::string,const vconfig> val) {
|
||||
@ -156,9 +163,12 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
|
||||
|
||||
//Allow filtering on unit
|
||||
if(cfg_.has_child("filter")) {
|
||||
const unit_filter ufilt(vconfig(cfg_.child("filter")), fc_, flat_);
|
||||
const unit_map::const_iterator u = fc_->get_disp_context().units().find(loc);
|
||||
if (u == fc_->get_disp_context().units().end() || !ufilt( *u, loc))
|
||||
if (!u.valid())
|
||||
return false;
|
||||
if (!cache_.ufilter_)
|
||||
cache_.ufilter_.reset(new unit_filter(vconfig(cfg_.child("filter")), fc_, flat_));
|
||||
if (!cache_.ufilter_->matches(*u, loc))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,12 @@
|
||||
class config;
|
||||
class filter_context;
|
||||
class unit;
|
||||
class unit_filter;
|
||||
class unit_map;
|
||||
class team;
|
||||
|
||||
#include <boost/scoped_ptr.hpp> //to memoize unit_filter
|
||||
|
||||
//terrain_filter: a class that implements the Standard Location Filter
|
||||
class terrain_filter : public xy_pred {
|
||||
public:
|
||||
@ -70,12 +73,7 @@ private:
|
||||
const filter_context * fc_;
|
||||
|
||||
struct terrain_filter_cache {
|
||||
terrain_filter_cache() :
|
||||
parsed_terrain(NULL),
|
||||
adjacent_matches(NULL),
|
||||
adjacent_match_cache()
|
||||
{
|
||||
}
|
||||
terrain_filter_cache();
|
||||
|
||||
~terrain_filter_cache();
|
||||
|
||||
@ -87,6 +85,8 @@ private:
|
||||
|
||||
//adjacent_match_cache: optimize handling of [filter_adjacent_location] for match()
|
||||
std::vector< std::pair<terrain_filter, std::map<map_location,bool> > > adjacent_match_cache;
|
||||
|
||||
boost::scoped_ptr<unit_filter> ufilter_;
|
||||
};
|
||||
|
||||
mutable terrain_filter_cache cache_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user