#include <pump.hpp>
Public Member Functions | |
t_pump (manager &) | |
~t_pump () | |
bool | context_mutated () |
Context: The general environment within which events are processed. More... | |
void | context_mutated (bool mutated) |
Sets whether or not we believe WML might have changed something. More... | |
bool | context_skip_messages () |
Returns whether or not we are skipping messages. More... | |
void | context_skip_messages (bool skip) |
Sets whether or not we are skipping messages. More... | |
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_messages_stream, and does it. More... | |
bool | 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. More... | |
void | raise (const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config()) |
bool | operator() () |
void | flush_messages () |
Flushes WML messages and errors. More... | |
size_t | wml_tracking () |
This function can be used to detect when no WML/Lua has been executed. More... | |
Private Member Functions | |
bool | filter_event (const event_handler &handler, const queued_event &ev) |
Returns true iff the given event passes all its filters. More... | |
bool | process_event (handler_ptr &handler_p, const queued_event &ev) |
Processes an event through a single event handler. More... | |
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. More... | |
void | show_wml_messages (std::stringstream &source, const std::string &caption, bool to_cerr) |
Shows a summary of messages/errors generated so far by WML. More... | |
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 shown. More... | |
void | show_wml_messages () |
Shows a summary of the messages generated so far by WML. More... | |
void | put_wml_message (lg::logger &logger, const std::string &prefix, const std::string &message, bool in_chat) |
Private Attributes | |
boost::scoped_ptr< pump_impl > | impl_ |
bool game_events::t_pump::context_mutated | ( | ) |
Context: The general environment within which events are processed.
Returns whether or not we believe WML might have changed something.
Definition at line 430 of file pump.cpp.
References impl_.
Referenced by game_lua_kernel::intf_allow_undo(), and process_event().
void game_events::t_pump::context_mutated | ( | bool | mutated | ) |
bool game_events::t_pump::context_skip_messages | ( | ) |
void game_events::t_pump::context_skip_messages | ( | bool | skip | ) |
|
private |
Helper function for show_wml_messages(), which gathers the messages from a stringstream.
Definition at line 315 of file pump.cpp.
References game_logic::msg().
Referenced by show_wml_messages().
|
private |
Returns true iff the given event passes all its filters.
Definition at line 187 of file pump.cpp.
References config::child(), game_events::conditional_passed(), resources::controller, play_controller::current_side(), game_events::queued_event::data, unit_map::end(), filters, unit_map::find(), game_events::event_handler::get_config(), game_events::queued_event::loc1, game_events::queued_event::loc2, side_filter::match(), game_events::matches_special_filter(), game_events::entity_location::matches_unit(), game_events::entity_location::matches_unit_filter(), and resources::units.
Referenced by process_event().
bool game_events::t_pump::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.
Events may have up to two arguments, both of which must be locations.
Definition at line 471 of file pump.cpp.
Referenced by advance_unit(), advance_unit_at(), play_controller::check_time_over(), play_controller::check_victory(), play_controller::do_init_side(), play_controller::finish_side_turn(), play_controller::finish_turn(), game_events::wml_menu_item::fire_event(), play_controller::fire_preload(), play_controller::fire_prestart(), play_controller::fire_start(), team::get_village(), game_lua_kernel::intf_fire_event(), game_lua_kernel::intf_kill(), game_lua_kernel::intf_put_unit(), events::menu_handler::kill_unit(), actions::place_recruit(), playsingle_controller::play_scenario(), ai::manager::play_turn(), unit_creator::post_create(), events::mouse_handler::select_hex(), and SYNCED_COMMAND_HANDLER_FUNCTION().
void game_events::t_pump::flush_messages | ( | ) |
Flushes WML messages and errors.
Definition at line 577 of file pump.cpp.
References resources::screen.
Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().
bool game_events::t_pump::operator() | ( | ) |
Definition at line 493 of file pump.cpp.
References unit::clear_status_caches(), DBG_EH, lg::debug(), lg::logger::dont_log(), ERR_NG, game_events::entity_location::filter_x(), game_events::entity_location::filter_y(), resources::gamedata, game_data::get_variable(), impl_, game_events::queued_event::loc1, game_events::queued_event::loc2, resources::lua_kernel, game_config::max_loop, game_events::queued_event::name, resources::screen, and resources::whiteboard.
|
private |
Processes an event through a single event handler.
This includes checking event filters, but not checking that the event name matches.
[in,out] | handler_p | The handler to offer the event to. This may be reset during processing. |
[in] | ev | The event information. |
Definition at line 279 of file pump.cpp.
References config::child(), context_mutated(), game_events::queued_event::data, filter_event(), resources::gamedata, impl_, game_data::last_selected, game_events::queued_event::loc1, game_events::queued_event::loc2, resources::lua_kernel, game_display::maybe_rebuild(), game_events::queued_event::name, resources::screen, resources::units, map_location::x, and map_location::y.
void game_events::t_pump::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_messages_stream, and does it.
Definition at line 458 of file pump.cpp.
References _(), lg::debug(), lg::err(), lg::info(), log_wml, and lg::warn().
Referenced by storyscreen::controller::resolve_wml(), and storyscreen::part::resolve_wml().
|
private |
void game_events::t_pump::raise | ( | const std::string & | event, |
const entity_location & | loc1 = entity_location::null_entity , |
||
const entity_location & | loc2 = entity_location::null_entity , |
||
const config & | data = config() |
||
) |
Definition at line 480 of file pump.cpp.
References DBG_EH, impl_, and resources::screen.
Referenced by actions::actor_sighted(), and actions::shroud_clearer::fire_events().
|
private |
Shows a summary of the errors encountered in WML so far, to avoid a lot of the same messages to be shown.
Identical messages are shown once, with (between parentheses) the number of times that message was encountered. The order in which the messages are shown does not need to be the order in which these messages are encountered. Messages are always written to std::cerr.
Definition at line 381 of file pump.cpp.
References show_wml_messages(), and lg::wml_error().
|
private |
Shows a summary of messages/errors generated so far by WML.
Identical messages are shown once, with (between parentheses) the number of times that message was encountered. The order in which the messages are shown does not need to be the order in which these messages are encountered. Messages are also written to std::cerr if to_cerr is true.
Definition at line 347 of file pump.cpp.
References display_chat_manager::add_chat_message(), fill_wml_messages_map(), game_display::get_chat_manager(), itor, events::chat_handler::MESSAGE_PUBLIC, game_logic::msg(), and resources::screen.
|
private |
Shows a summary of the messages generated so far by WML.
Identical messages are shown once, with (between parentheses) the number of times that message was encountered. The order in which the messages are shown does not need to be the order in which these messages are encountered.
Definition at line 395 of file pump.cpp.
References impl_.
Referenced by show_wml_errors().
size_t game_events::t_pump::wml_tracking | ( | ) |
This function can be used to detect when no WML/Lua has been executed.
If two calls to this function return the same value, then one can assume that the usual game mechanics have been followed, and code does not have to account for all the things WML/Lua can do. If the return values are different, then something unusual might have happened between those calls.
This is not intended as a precise metric. Rather, it is motivated by how large the number of fired WML events is, compared to the (typical) number of WML event handlers. It is intended for code that can benefit from caching some aspect of the game state and that cannot rely on [allow_undo] not being used when that state changes.
Definition at line 602 of file pump.cpp.
References impl_.
|
private |
Definition at line 67 of file pump.hpp.
Referenced by process_event(), put_wml_message(), and show_wml_messages().