35 #include <boost/unordered_map.hpp>
40 #define DBG_NG LOG_STREAM(debug, log_engine)
41 #define LOG_NG LOG_STREAM(info, log_engine)
42 #define WRN_NG LOG_STREAM(warn, log_engine)
45 #define DBG_EH LOG_STREAM(debug, log_event_handler)
97 main_list_(man.event_handlers_->
get(event_name)),
98 var_list_(man.event_handlers_->
get()),
99 event_name_(event_name),
100 end_(man.event_handlers_->
size()),
101 current_is_known_(false),
102 main_is_current_(false),
103 main_it_(main_list_.begin()),
104 var_it_(event_name.empty() ? var_list_.
end() : var_list_.begin()),
118 if ( !current_is_known_ )
124 if ( main_is_current_ )
130 current_is_known_ =
false;
144 handler_vec::size_type main_index = ptr_index(main_ptr);
149 while ( var_ptr && var_ptr->index() < main_index &&
150 !var_ptr->matches_name(event_name_, gamedata_) )
151 var_ptr = *++var_it_;
152 handler_vec::size_type var_index = ptr_index(var_ptr);
155 current_is_known_ = main_index < end_ || var_index < end_;
156 main_is_current_ = main_index <= var_index;
158 if ( !current_is_known_ )
161 return main_is_current_ ? main_ptr : var_ptr;
171 for(
const config &new_ev : cfgs) {
172 if(type.empty() && new_ev[
"id"].empty())
174 WRN_NG <<
"attempt to add an [event] with empty id=, ignoring " << std::endl;
184 if ( !eh || eh->is_menu_item() ) {
187 cfg.
add_child(
"event", eh->get_config());
void remove_event_handler(const std::string &id)
Removes an event handler.
child_itors child_range(const std::string &key)
boost::scoped_ptr< game_events::t_pump > pump_
static thandler * handler
void write_events(config &cfg)
GLuint GLuint GLsizei GLenum type
boost::shared_ptr< event_handler > handler_ptr
Shared pointer to handler objects.
std::pair< const_child_iterator, const_child_iterator > const_child_itors
game_events::wmi_container wml_menu_items_
void read_scenario(const config &scenario_cfg)
void to_config(config &cfg) const
std::set< std::string > unit_wml_ids_
config & add_child(const std::string &key)
void set_menu_items(const config &cfg)
Sets the current menu items to the "menu_item" children of cfg.
Templates and utility-routines for strings and numbers.
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
void add_event_handler(const config &handler, bool is_menu_item=false)
Create an event handler.
Define the game's event mechanism.
The game event manager loads the scenario configuration object, and ensures that events are handled a...
This class is similar to an input iterator through event handlers, except each instance knows its own...
game_events::t_pump & pump()
iteration(const std::string &event_name, manager &)
Event-specific constructor.
Define the handlers for the game's events mechanism.
handler_ptr operator*()
Dereference Will return a null pointer when the end of the iteration is reached.
void init_handlers() const
Initializes the implicit event handlers for inlined [command]s.
bool find(E event, F functor)
Tests whether an event handler is available.
Standard logging facilities (interface).
boost::scoped_ptr< t_event_handlers > event_handlers_
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
iteration & operator++()
Increment Incrementing guarantees that the next dereference will differ from the previous derference ...
A config object defines a single node in a WML file, with access to child nodes.
static lg::log_domain log_engine("engine")
void add_events(const config::const_child_itors &cfgs, const std::string &type=std::string())
GLsizei const GLcharARB ** string
static lg::log_domain log_event_handler("event_handler")