39 #define DBG_NG LOG_STREAM(debug, log_engine)
40 #define LOG_NG LOG_STREAM(info, log_engine)
41 #define ERR_NG LOG_STREAM(err, log_engine)
44 #define DBG_WML LOG_STREAM(debug, log_wml)
45 #define LOG_WML LOG_STREAM(info, log_wml)
46 #define WRN_WML LOG_STREAM(warn, log_wml)
47 #define ERR_WML LOG_STREAM(err, log_wml)
50 #define DBG_EH LOG_STREAM(debug, log_event_handler)
64 explicit state(
bool s,
bool m =
true)
75 scoped(std::stack<context::state>& contexts,
bool m =
true);
111 pump_manager(pump_impl&);
125 unsigned count()
const
127 return impl_.instance_count;
148 pump_manager::pump_manager(pump_impl& impl)
161 pump_manager::~pump_manager()
172 std::vector<queued_event> temp;
197 DBG_EH <<
"processing event " << ev.
name <<
" with id=" << ev.
id;
211 if(!handler_p->filter_event(ev)) {
221 if(ev.
name ==
"select") {
238 std::getline(source,
msg);
248 if(msg_map.find(
msg) == msg_map.end()) {
273 std::map<std::string, int> messages;
277 for(std::map<std::string, int>::const_iterator itor = messages.begin(); itor != messages.end(); ++itor) {
278 std::stringstream
msg;
280 if(itor->second > 1) {
281 msg <<
" (" << itor->second <<
")";
316 lg::logger& logger,
const std::string& prefix,
const std::string& message,
bool in_chat)
320 impl_->wml_messages_stream << prefix << message << std::endl;
325 : contexts_(contexts)
336 assert(contexts_.size() > 1);
337 bool undo_disabled = contexts_.top().undo_disabled;
338 bool action_canceled = contexts_.top().action_canceled;
341 contexts_.top().undo_disabled |= undo_disabled;
342 contexts_.top().action_canceled |= action_canceled;
347 assert(
impl_->contexts_.size() > 0);
348 return impl_->contexts_.top().undo_disabled;
353 assert(
impl_->contexts_.size() > 0);
354 impl_->contexts_.top().undo_disabled =
b;
359 assert(
impl_->contexts_.size() > 0);
360 return impl_->contexts_.top().action_canceled;
365 assert(
impl_->contexts_.size() > 0);
366 impl_->contexts_.top().action_canceled =
true;
372 assert(
impl_->contexts_.size() > 0);
373 return impl_->contexts_.top().skip_messages;
378 assert(
impl_->contexts_.size() > 0);
379 impl_->contexts_.top().skip_messages =
b;
388 if(logger ==
"err" || logger ==
"error") {
389 put_wml_message(
lg::err(),
_(
"Error: "), message, in_chat);
390 }
else if(logger ==
"warn" || logger ==
"wrn" || logger ==
"warning") {
391 put_wml_message(
lg::warn(),
_(
"Warning: "), message, in_chat);
392 }
else if((logger ==
"debug" || logger ==
"dbg") && !
lg::debug().dont_log(
log_wml)) {
393 put_wml_message(
lg::debug(),
_(
"Debug: "), message, in_chat);
395 put_wml_message(
lg::info(),
_(
"Info: "), message, in_chat);
402 raise(event, loc1, loc2,
data);
407 const std::string&
id,
412 raise(event,
id, loc1, loc2,
data);
417 const std::string&
id,
425 DBG_EH <<
"raising event name=" <<
event <<
", id=" <<
id;
427 impl_->events_queue.emplace_back(event,
id, loc1, loc2,
data);
438 if(
impl_->events_queue.empty()) {
439 DBG_EH <<
"Processing queued events, but none found.";
444 ERR_NG <<
"game_events pump waiting to process new events because "
445 <<
"recursion level would exceed maximum: "
451 std::stringstream ss;
453 ss <<
"name=" << ev.
name <<
", "
454 <<
"id=" << ev.
id <<
"; ";
456 DBG_EH <<
"processing queued events: " << ss.str();
463 pump_manager pump_instance(*
impl_);
466 while(!pump_instance.done()) {
469 if(ev.
name.empty() && ev.
id.empty()) {
473 const std::string& event_name = ev.
name;
474 const std::string& event_id = ev.
id;
485 assert(
impl_->my_manager);
492 if(event_id.empty()) {
495 DBG_EH <<
"processing event " << event_name <<
" with id=" << ptr->id();
498 process_event(ptr, ev);
502 handler_ptr cur_handler =
impl_->my_manager->get_event_handler_by_id(event_id);
505 DBG_EH <<
"processing event " << event_name <<
" with id=" << cur_handler->id();
506 process_event(cur_handler, ev);
518 return std::tuple(undo_disabled(), action_canceled());
A config object defines a single node in a WML file, with access to child nodes.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
virtual const unit_map & units() const override
map_location last_selected
the last location where a select event fired.
config::attribute_value & get_variable(const std::string &varname)
throws invalid_variablename_exception if varname is no valid variable name.
static game_display * get_singleton()
bool maybe_rebuild()
Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
display_chat_manager & get_chat_manager()
std::stack< context::state > & contexts_
scoped(std::stack< context::state > &contexts, bool m=true)
The game event manager loads the scenario configuration object, and ensures that events are handled a...
void set_action_canceled()
Sets whether or not wml wants to abort the currently executed user action.
void show_wml_errors()
Shows a summary of the errors encountered in WML so far, to avoid a lot of the same messages to be sh...
bool undo_disabled()
Context: The general environment within which events are processed.
bool context_skip_messages()
Returns whether or not we are skipping messages.
void flush_messages()
Flushes WML messages and errors.
const std::unique_ptr< pump_impl > impl_
void show_wml_messages()
Shows a summary of the messages generated so far by WML.
bool action_canceled()
Returns whether or not wml wants to abort the currently executed user action.
pump_result_t fire(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
Function to fire an event.
void raise(const std::string &event, const std::string &id, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
pump_result_t operator()()
void set_undo_disabled(bool mutated)
[allow_undo] implementation
void process_event(handler_ptr &handler_p, const queued_event &ev)
Processes an event through a single event handler.
wml_event_pump(manager &)
void fill_wml_messages_map(std::map< std::string, int > &msg_map, std::stringstream &source)
Helper function for show_wml_messages(), which gathers the messages from a stringstream.
void put_wml_message(const std::string &logger, const std::string &message, bool in_chat)
Helper function which determines whether a wml_message text can really be pushed into the wml_message...
bool run_event(const game_events::queued_event &)
Executes the game_events.on_event function.
Container associating units to locations.
static void clear_status_caches()
Clear this unit status cache for all units.
static std::string _(const char *str)
std::string id
Text to match against addon_info.tags()
Define the handlers for the game's events mechanism.
Standard logging facilities (interface).
#define FORCE_LOG_TO(logger, domain)
const std::size_t max_loop
The maximum number of hexes on a map and items in an array and also used as maximum in wml loops.
std::tuple< bool, bool > pump_result_t
std::shared_ptr< event_handler > handler_ptr
std::stringstream & log_to_chat()
Use this to show WML errors in the ingame chat.
game_lua_kernel * lua_kernel
std::shared_ptr< wb::manager > whiteboard
bool headless()
The game is running headless.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::vector< queued_event > queue_
Tracks the events to process.
static lg::log_domain log_engine("engine")
static lg::log_domain log_event_handler("event_handler")
static lg::log_domain log_wml("wml")
std::size_t pumped_count_
Tracks how many events have been processed.
Define the game's event mechanism.
State when processing a particular flight of events or commands.
state(bool s, bool m=true)
const map_location & filter_loc() const
std::stack< context::state > contexts_
std::stringstream wml_messages_stream
std::vector< queued_event > events_queue
Ensures that the real unit map is active for the duration of the struct's life.
static map_location::direction s