The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
game_events::t_pump Class Reference

#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_implimpl_
 

Detailed Description

Definition at line 66 of file pump.hpp.

Constructor & Destructor Documentation

game_events::t_pump::t_pump ( manager man)

Definition at line 607 of file pump.cpp.

game_events::t_pump::~t_pump ( )

Definition at line 611 of file pump.cpp.

Member Function Documentation

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)

Sets whether or not we believe WML might have changed something.

Definition at line 436 of file pump.cpp.

References impl_.

bool game_events::t_pump::context_skip_messages ( )

Returns whether or not we are skipping messages.

Definition at line 442 of file pump.cpp.

References impl_.

void game_events::t_pump::context_skip_messages ( bool  skip)

Sets whether or not we are skipping messages.

Definition at line 448 of file pump.cpp.

References impl_.

void game_events::t_pump::fill_wml_messages_map ( std::map< std::string, int > &  msg_map,
std::stringstream &  source 
)
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().

bool game_events::t_pump::filter_event ( const event_handler handler,
const queued_event ev 
)
private
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() 
)
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() ( )
bool game_events::t_pump::process_event ( handler_ptr handler_p,
const queued_event ev 
)
private

Processes an event through a single event handler.

This includes checking event filters, but not checking that the event name matches.

Parameters
[in,out]handler_pThe handler to offer the event to. This may be reset during processing.
[in]evThe event information.
Returns
true if the game state changed.

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().

void game_events::t_pump::put_wml_message ( lg::logger logger,
const std::string prefix,
const std::string message,
bool  in_chat 
)
private

Definition at line 402 of file pump.cpp.

References impl_, and log_wml.

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().

void game_events::t_pump::show_wml_errors ( )
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().

void game_events::t_pump::show_wml_messages ( std::stringstream &  source,
const std::string caption,
bool  to_cerr 
)
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.

void game_events::t_pump::show_wml_messages ( )
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_.

Member Data Documentation

boost::scoped_ptr<pump_impl> game_events::t_pump::impl_
private

Definition at line 67 of file pump.hpp.

Referenced by process_event(), put_wml_message(), and show_wml_messages().


The documentation for this class was generated from the following files: