42 #define DBG_NG LOG_STREAM(debug, log_engine)
43 #define LOG_NG LOG_STREAM(info, log_engine)
44 #define ERR_NG LOG_STREAM(err, log_engine)
47 #define DBG_WML LOG_STREAM(debug, log_wml)
48 #define LOG_WML LOG_STREAM(info, log_wml)
49 #define WRN_WML LOG_STREAM(warn, log_wml)
50 #define ERR_WML LOG_STREAM(err, log_wml)
53 #define DBG_EH LOG_STREAM(debug, log_event_handler)
67 explicit state(
bool s,
bool m =
true)
78 scoped(std::stack<context::state>& contexts,
bool m =
true);
114 pump_manager(pump_impl&);
128 unsigned count()
const
130 return impl_.instance_count;
151 pump_manager::pump_manager(pump_impl& impl)
164 pump_manager::~pump_manager()
175 std::vector<queued_event> temp;
200 DBG_EH <<
"processing event " << ev.
name <<
" with id=" << ev.
id;
214 if(!handler_p->filter_event(ev)) {
224 if(ev.
name ==
"select") {
241 std::getline(source,
msg);
251 if(msg_map.find(
msg) == msg_map.end()) {
276 std::map<std::string, int> messages;
280 for(std::map<std::string, int>::const_iterator itor = messages.begin(); itor != messages.end(); ++itor) {
281 std::stringstream
msg;
283 if(itor->second > 1) {
284 msg <<
" (" << itor->second <<
")";
319 lg::logger& logger,
const std::string& prefix,
const std::string& message,
bool in_chat)
323 impl_->wml_messages_stream << prefix << message << std::endl;
328 : contexts_(contexts)
339 assert(contexts_.size() > 1);
340 bool undo_disabled = contexts_.top().undo_disabled;
341 bool action_canceled = contexts_.top().action_canceled;
344 contexts_.top().undo_disabled |= undo_disabled;
345 contexts_.top().action_canceled |= action_canceled;
350 assert(
impl_->contexts_.size() > 0);
351 return impl_->contexts_.top().undo_disabled;
356 assert(
impl_->contexts_.size() > 0);
357 impl_->contexts_.top().undo_disabled =
b;
362 assert(
impl_->contexts_.size() > 0);
363 return impl_->contexts_.top().action_canceled;
368 assert(
impl_->contexts_.size() > 0);
369 impl_->contexts_.top().action_canceled =
true;
375 assert(
impl_->contexts_.size() > 0);
376 return impl_->contexts_.top().skip_messages;
381 assert(
impl_->contexts_.size() > 0);
382 impl_->contexts_.top().skip_messages =
b;
391 if(logger ==
"err" || logger ==
"error") {
392 put_wml_message(
lg::err(),
_(
"Error: "), message, in_chat);
393 }
else if(logger ==
"warn" || logger ==
"wrn" || logger ==
"warning") {
394 put_wml_message(
lg::warn(),
_(
"Warning: "), message, in_chat);
395 }
else if((logger ==
"debug" || logger ==
"dbg") && !
lg::debug().dont_log(
log_wml)) {
396 put_wml_message(
lg::debug(),
_(
"Debug: "), message, in_chat);
398 put_wml_message(
lg::info(),
_(
"Info: "), message, in_chat);
405 raise(event, loc1, loc2,
data);
410 const std::string&
id,
415 raise(event,
id, loc1, loc2,
data);
420 const std::string&
id,
428 DBG_EH <<
"raising event name=" <<
event <<
", id=" <<
id;
430 impl_->events_queue.emplace_back(event,
id, loc1, loc2,
data);
441 if(
impl_->events_queue.empty()) {
442 DBG_EH <<
"Processing queued events, but none found.";
447 ERR_NG <<
"game_events pump waiting to process new events because "
448 <<
"recursion level would exceed maximum: "
454 std::stringstream ss;
456 ss <<
"name=" << ev.
name <<
", "
457 <<
"id=" << ev.
id <<
"; ";
459 DBG_EH <<
"processing queued events: " << ss.str();
466 pump_manager pump_instance(*
impl_);
469 while(!pump_instance.done()) {
472 if(ev.
name.empty() && ev.
id.empty()) {
476 const std::string& event_name = ev.
name;
477 const std::string& event_id = ev.
id;
488 assert(
impl_->my_manager);
495 if(event_id.empty()) {
498 DBG_EH <<
"processing event " << event_name <<
" with id=" << ptr->id();
501 process_event(ptr, ev);
505 handler_ptr cur_handler =
impl_->my_manager->get_event_handler_by_id(event_id);
508 DBG_EH <<
"processing event " << event_name <<
" with id=" << cur_handler->id();
509 process_event(cur_handler, ev);
521 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)
Euivalent 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