diff --git a/src/game_events.cpp b/src/game_events.cpp index c276245253f..866a4765633 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -324,9 +324,6 @@ void show_wml_messages() } // anonymous namespace -typedef void (*wml_handler_function)( - const queued_event &event_info, const vconfig &cfg); - namespace { typedef std::map static_wml_action_map; @@ -335,6 +332,13 @@ static_wml_action_map static_wml_actions; } // anonymous namespace +/** Registers a standard action handler. */ +void register_action(const std::string & tag, wml_handler_function handler) +{ + static_wml_actions[tag] = handler; +} + + /** * WML_HANDLER_FUNCTION macro handles auto registration for wml handlers * @@ -358,7 +362,7 @@ static_wml_action_map static_wml_actions; * void wml_action_foo(...); * struct wml_func_register_foo { * wml_func_register_foo() { - * static_wml_actions["foo"] = &wml_func_foo; + * register_action("foo", &wml_func_foo); * } wml_func_register_foo; * void wml_func_foo(...) * { @@ -371,7 +375,7 @@ static_wml_action_map static_wml_actions; struct wml_func_register_##pname \ { \ wml_func_register_##pname() \ - { static_wml_actions[#pname] = &wml_func_##pname; } \ + { register_action(#pname, &wml_func_##pname); } \ }; \ static wml_func_register_##pname wml_func_register_##pname##_aux; \ static void wml_func_##pname(const queued_event& pei, const vconfig& pcfg) @@ -3611,7 +3615,7 @@ bool process_event(event_handler& handler, const queued_event& ev) manager::~manager() { assert(running_); running_ = false; - events_queue.clear(); + clear_events(); event_handlers.clear(); reports::reset_generators(); delete resources::lua_kernel; @@ -3620,6 +3624,12 @@ bool process_event(event_handler& handler, const queued_event& ev) used_items.clear(); } + /** Clears all events tha have been raised (and not pumped). */ + void clear_events() + { + events_queue.clear(); + } + void raise(const std::string& event, const entity_location& loc1, const entity_location& loc2, diff --git a/src/game_events.hpp b/src/game_events.hpp index 3e217550ddf..3d95d5a386a 100644 --- a/src/game_events.hpp +++ b/src/game_events.hpp @@ -179,6 +179,9 @@ void change_terrain(const map_location &loc, const t_translation::t_terrain &t, // Declarations that will be more useful after the split: + typedef void (*wml_handler_function)(const queued_event &event_info, + const vconfig &cfg); + /// Create an event handler. void add_event_handler(const config & event); /// Add a pending menu item command change. @@ -195,6 +198,9 @@ void change_terrain(const map_location &loc, const t_translation::t_terrain &t, /// really be pushed into the wml_messages_stream, and does it. void put_wml_message(const std::string& logger, const std::string& message); + /// Registers a standard action handler. + void register_action(const std::string & tag, wml_handler_function handler); + /// Checks if an item has been used. bool item_used(const std::string & id); /// Records if an item has been used. @@ -212,6 +218,8 @@ void change_terrain(const map_location &loc, const t_translation::t_terrain &t, /// Sets whether or not we believe WML might have changed something. void context_mutated(bool mutated); + /// Clears all events tha have been raised (and not pumped). + void clear_events(); } // end namespace game_events #endif