32 #define DBG_NG LOG_STREAM(debug, log_engine) 33 #define LOG_NG LOG_STREAM(info, log_engine) 34 #define WRN_NG LOG_STREAM(warn, log_engine) 37 #define DBG_EH LOG_STREAM(debug, log_event_handler) 42 class event_handler_list_lock
45 event_handler_list_lock()
50 ~event_handler_list_lock()
57 return num_locks_ == 0u;
60 static unsigned int num_locks_;
63 unsigned int event_handler_list_lock::num_locks_ = 0u;
69 void manager::add_event_handler(
const config& handler,
bool is_menu_item)
71 event_handlers_->add_event_handler(handler, is_menu_item);
75 void manager::remove_event_handler(
const std::string&
id)
77 event_handlers_->remove_event_handler(
id);
81 const handler_ptr manager::get_event_handler_by_id(
const std::string&
id)
83 return event_handlers_->get_event_handler_by_id(
id);
102 for(
const std::string&
id :
utils::split(scenario_cfg[
"unit_wml_ids"])) {
126 for(
const config& new_ev : cfgs) {
127 if(type.empty() && new_ev[
"id"].empty()) {
128 WRN_NG <<
"attempt to add an [event] with empty id=, ignoring " << std::endl;
139 if(!eh || eh->is_menu_item()) {
152 assert(!eh->disabled());
155 cfg.
add_child(
"event", eh->get_config());;
170 const unsigned saved_end = active_handlers.size();
175 event_handler_list_lock lock;
177 for (
unsigned i = 0;
i < saved_end; ++
i) {
181 handler = active_handlers.at(
i);
183 catch (
const std::out_of_range&) {
188 if (!handler || handler->disabled()) {
193 for (
const std::string& name : handler->names()) {
194 bool matches =
false;
203 matches = standardized_event_id ==
207 matches = standardized_event_id == name;
211 func(*
this, handler);
219 if(event_handler_list_lock::none()) {
227 return !event_handler_list_lock::none();
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
bool is_event_running() const
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
static std::string standardize_name(const std::string &name)
Utility to standardize the event names used in by_name_.
child_itors child_range(config_key_type key)
void init_handlers() const
Initializes the implicit event handlers for inlined [command]s.
void read_scenario(const config &scenario_cfg)
game_events::wmi_manager wml_menu_items_
std::set< std::string > unit_wml_ids_
std::function< void(game_events::manager &, handler_ptr &)> event_func_t
void set_menu_items(const config &cfg)
Sets the current menu items to the "menu_item" children of cfg.
const std::unique_ptr< event_handlers > event_handlers_
void to_config(config &cfg) const
boost::iterator_range< const_child_iterator > const_child_itors
const std::unique_ptr< game_events::wml_event_pump > pump_
void write_events(config &cfg) const
void add_event_handler(const config &handler, bool is_menu_item=false)
Create an event handler.
Define the game's event mechanism.
config & add_child(config_key_type key)
bool might_contain_variables(const std::string &str)
Determines if a string might contain variables to interpolate.
Define the handlers for the game's events mechanism.
std::vector< std::string > split(const config_attribute_value &val)
Standard logging facilities (interface).
game_events::wml_event_pump & pump()
std::shared_ptr< event_handler > handler_ptr
A config object defines a single node in a WML file, with access to child nodes.
static lg::log_domain log_engine("engine")
void execute_on_events(const std::string &event_id, event_func_t func)
void add_events(const config::const_child_itors &cfgs, const std::string &type=std::string())
static lg::log_domain log_event_handler("event_handler")