30 #define DBG_NG LOG_STREAM(debug, log_engine)
31 #define LOG_NG LOG_STREAM(info, log_engine)
32 #define WRN_NG LOG_STREAM(warn, log_engine)
35 #define LOG_EH LOG_STREAM(info, log_event_handler)
36 #define DBG_EH LOG_STREAM(debug, log_event_handler)
41 class event_handler_list_lock
44 event_handler_list_lock()
49 ~event_handler_list_lock()
56 return num_locks_ == 0u;
59 static unsigned int num_locks_;
62 unsigned int event_handler_list_lock::num_locks_ = 0u;
73 !handler[
"first_time_only"].to_bool(
true),
74 handler[
"priority"].to_double(0.),
77 if(new_handler.valid()) {
78 new_handler->read_filters(handler);
83 if(attr ==
"id" || attr ==
"name" || attr ==
"first_time_only" || attr ==
"priority" || attr.compare(0, 6,
"filter") == 0) {
89 if(child.key.compare(0, 6,
"filter") != 0) {
93 new_handler->set_arguments(args);
94 new_handler->register_wml_event(lk);
95 DBG_EH <<
"Registered WML event "
96 << (new_handler->names_raw().empty() ?
"" :
"'" + new_handler->names_raw() +
"'")
97 << (new_handler->id().empty() ?
"" :
"{id=" + new_handler->id() +
"}")
98 << (new_handler->repeatable() ?
" (repeating" :
" (first time only")
99 <<
"; priority " + std::to_string(new_handler->priority())
100 << (is_menu_item ?
"; menu item)" :
")")
101 <<
" with the following actions:\n"
104 LOG_EH <<
"Content of failed event:\n" << handler.
debug();
110 return event_handlers_->add_event_handler(name,
id, repeat, priority, is_menu_item);
141 for(
const std::string&
id :
utils::split(scenario_cfg[
"unit_wml_ids"])) {
165 for(
const config& new_ev : cfgs) {
166 if(
type.empty() && new_ev[
"id"].empty()) {
167 WRN_NG <<
"attempt to add an [event] with empty id=, ignoring ";
178 if(!eh || eh->is_menu_item()) {
193 assert(!eh->disabled());
197 eh->write_config(event_cfg, include_nonserializable);
198 if(!event_cfg.
empty()) {
199 cfg.
add_child(
"event", std::move(event_cfg));
215 const unsigned saved_end = active_handlers.size();
220 event_handler_list_lock lock;
222 for (
unsigned i = 0;
i < saved_end; ++
i) {
226 handler = active_handlers.at(
i);
228 catch (
const std::out_of_range&) {
233 if (!handler || handler->disabled()) {
238 for(
const std::string& name : handler->names(gd)) {
239 if(standardized_event_id == name) {
240 func(*
this, handler);
248 if(event_handler_list_lock::none()) {
256 return !event_handler_list_lock::none();
A config object defines a single node in a WML file, with access to child nodes.
const_attr_itors attribute_range() const
const_all_children_itors all_children_range() const
In-order iteration over all children.
child_itors child_range(config_key_type key)
std::string debug() const
boost::iterator_range< const_child_iterator > const_child_itors
config & add_child(config_key_type key)
static std::string standardize_name(const std::string &name)
Utility to standardize the event names used in by_name_.
std::function< void(game_events::manager &, handler_ptr &)> event_func_t
void execute_on_events(const std::string &event_id, event_func_t func)
const std::unique_ptr< game_events::wml_event_pump > pump_
game_events::wml_event_pump & pump()
void write_events(config &cfg, bool include_nonserializable=false) const
void remove_event_handler(const std::string &id)
Removes an event handler.
void read_scenario(const config &scenario_cfg, game_lua_kernel &lk)
void add_event_handler_from_wml(const config &handler, game_lua_kernel &lk, bool is_menu_item=false)
Create an event handler from an [event] tag.
void add_events(const config::const_child_itors &cfgs, game_lua_kernel &lk, const std::string &type=std::string())
const handler_ptr get_event_handler_by_id(const std::string &id)
Gets an event handler by ID.
bool is_event_running() const
const std::unique_ptr< event_handlers > event_handlers_
game_events::wmi_manager wml_menu_items_
pending_event_handler add_event_handler_from_lua(const std::string &name, const std::string &id, bool repeat=false, double priority=0., bool is_menu_item=false)
Create an empty event handler.
std::set< std::string > unit_wml_ids_
Represents a handler that is about to be added to the events manager but is still waiting for some da...
void init_handlers(game_lua_kernel &lk) const
Initializes the implicit event handlers for inlined [command]s.
void to_config(config &cfg) const
void set_menu_items(const config &cfg)
Sets the current menu items to the "menu_item" children of cfg.
static lg::log_domain log_engine("engine")
static lg::log_domain log_event_handler("event_handler")
Define the handlers for the game's events mechanism.
Standard logging facilities (interface).
std::shared_ptr< event_handler > handler_ptr
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< std::string > split(const config_attribute_value &val)
Define the game's event mechanism.