Author: silene
Date: Mon Apr 13 13:49:03 2009
New Revision: 34851
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34851&view=rev
Log:
Removed the command_handlers class. It was left unimplemented.
Modified:
trunk/src/game_events.cpp
trunk/src/game_events.hpp
Modified: trunk/src/game_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=34851&r1=34850&r2=34851&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Mon Apr 13 13:49:03 2009
@@ -232,50 +232,70 @@
}
}
+typedef void (*wml_handler_function)(game_events::event_handler &eh,
+ const game_events::queued_event &event_info, const vconfig &cfg);
+
+typedef std::map<std::string, wml_handler_function> static_wml_action_map;
+static static_wml_action_map static_wml_actions;
+
+/**
+ * Calls registered WML action handler.
+ * @return false if none was found.
+ */
+static bool call_wml_action_handler(const std::string &cmd,
+ game_events::event_handler &eh,
+ const game_events::queued_event &event_info,
+ const vconfig& cfg)
+{
+ static_wml_action_map::iterator itor = static_wml_actions.find(cmd);
+ if (itor == static_wml_actions.end()) return false;
+
+ (*itor->second)(eh, event_info, cfg);
+ return true;
+}
+
+/**
+ * WML_HANDLER_FUNCTION macro handles auto registeration for wml handlers
+ *
+ * @param pname wml tag name
+ * @param peh the variable name of game_events::event_handler object inside
function
+ * @param pei the variable name of game_events::queued_event object inside
function
+ * @param pcfg the variable name of config object inside function
+ *
+ * You are warned! This is evil macro magic!
+ *
+ * For [foo] tag macro is used like:
+ *
+ * // comment out unused parameters to prevent compiler warnings
+ * WML_HANDLER_FUNCTION(foo, handler, event_info, cfg)
+ * {
+ * // code for foo
+ * }
+ *
+ * ready code looks like for [foo]
+ * void wml_action_foo(...);
+ * struct wml_func_register_foo {
+ * wml_func_register_foo() {
+ * static_wml_actions["foo"] = &wml_func_foo;
+ * } wml_func_register_foo;
+ * void wml_func_foo(...)
+ * {
+ * // code for foo
+ * }
+ */
+#define WML_HANDLER_FUNCTION(pname, peh, pei, pcfg) \
+ void wml_func_##pname(game_events::event_handler &peh, \
+ const game_events::queued_event &pei, const vconfig &pcfg); \
+ struct wml_func_register_##pname \
+ { \
+ wml_func_register_##pname() \
+ { static_wml_actions[#pname] = &wml_func_##pname; } \
+ }; \
+ static wml_func_register_##pname wml_func_register_##pname##_aux; \
+ void wml_func_##pname(game_events::event_handler &peh, \
+ const game_events::queued_event& pei, const vconfig& pcfg)
+
namespace game_events {
-
-
- command_handlers command_handlers::manager_;
-
- command_handlers& command_handlers::get()
- {
- return manager_;
- }
-
- command_handlers::command_handlers() :
- function_call_map_()
- {
- }
-
- command_handlers::~command_handlers()
- {
- clear_all();
- }
-
- void command_handlers::add_handler(const std::string& key,
wml_handler_function func)
- {
- function_call_map_.insert(std::make_pair(key, func));
- }
-
- void command_handlers::clear_all()
- {
- function_call_map_.clear();
- }
-
- bool command_handlers::call_handler(
- const std::string& cmd,
- game_events::event_handler& eh,
- const game_events::queued_event& event_info,
- const vconfig& cfg)
- {
- call_map::iterator itor = function_call_map_.find(cmd);
- if (itor != function_call_map_.end())
- {
- (*itor->second)(eh, event_info, cfg);
- return true;
- }
- return false;
- }
static bool unit_matches_filter(const unit& u, const vconfig
filter,const map_location& loc);
static bool matches_special_filter(const config &cfg, const vconfig
filter);
@@ -3470,7 +3490,7 @@
<< std::hex << std::setiosflags(std::ios::uppercase)
<< reinterpret_cast<uintptr_t>(&cfg.get_config()) <<
std::dec << "\n";
- if (!command_handlers::get().call_handler(cmd, *this,
event_info, cfg))
+ if (!call_wml_action_handler(cmd, *this, event_info, cfg))
{
ERR_NG << "Couldn't find function for wml tag: "<< cmd
<<"\n";
}
Modified: trunk/src/game_events.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.hpp?rev=34851&r1=34850&r2=34851&view=diff
==============================================================================
--- trunk/src/game_events.hpp (original)
+++ trunk/src/game_events.hpp Mon Apr 13 13:49:03 2009
@@ -164,119 +164,6 @@
vconfig cfg_;
};
- typedef void (*wml_handler_function)(event_handler& eh,
- const queued_event& event_info,
- const vconfig& cfg);
-
-
- /**
- * WML_HANDLER_FUNCTION macro handles auto registeration for wml
handlers
- *
- * @param pname wml tag name
- * @param peh the variable name of game_events::event_handler object
inside function
- * @param pei the variable name of game_events::queued_event object
inside function
- * @param pcfg the variable name of config object inside function
- *
- * You are warned! This is evil macro magic!
- *
- * For [foo] tag macro is used like:
- *
- * // comment out unused parameters to prevent compiler warnings
- * WML_HANDLER_FUNCTION(foo, handler, event_info, cfg)
- * {
- * // code for foo
- * }
- *
- * ready code looks like for [foo]
- * void wml_func_foo(...);
- * struct wml_func_register_foo {
- * wml_func_resgister_foo() {
- * command_handlers::get().add_handler("foo",&wml_func_foo); }
- * } wml_func_register_foo;
- * void wml_func_foo(...)
- * {
- * // code for foo
- * }
- **/
-#define WML_HANDLER_FUNCTION(pname, peh, pei, pcfg) \
- void wml_func_ ## pname \
- (game_events::event_handler& peh, \
- const game_events::queued_event& pei,\
- const vconfig& pcfg);\
- struct wml_func_register_ ## pname \
- { \
- wml_func_register_ ## pname () \
- { \
- const std::string name(# pname); \
- game_events::command_handlers::get().add_handler( \
- name , &wml_func_ ## pname ); \
- }\
- } wml_func_register_ ## pname ; \
- void wml_func_ ## pname \
- (game_events::event_handler& peh, \
- const game_events::queued_event& pei,\
- const vconfig& pcfg)
-
- /**
- * Stores wml tag handler functions
- * call_handler method searches function for tag and calls it
- * This could be easily extended for runtime wml handler registeration
- * and unregisteration.
- *
- * command_handlers uses singleton implementation
- **/
- class command_handlers {
- command_handlers();
- command_handlers(const command_handlers&);
- ~command_handlers();
-
- typedef std::map<std::string, wml_handler_function> call_map;
- call_map function_call_map_;
-
- // typedef std::vector<std::string> runtime_handlers;
- // runtime_handlers runtime_;
- // bool in_scenario_;
-
- static command_handlers manager_;
-
- // It might be good optimization to use hash instead
- // of string as key for map
- // static size_t make_hash_key(const std::string&);
- public:
- /**
- * gets and creates the singleton storage manager
- **/
- static command_handlers& get();
-
- /**
- * adds new handler function
- **/
- void add_handler(const std::string&, wml_handler_function);
- /**
- * removes all handler functions
- **/
- void clear_all();
-
- /**
- * called in start of scenario so command_handlers knows to mark
- * new handlers after this for removal.
- * Not implemented yet!
- **/
- void start_scenario();
- /**
- * called in end of scenario so command_handler knows to clean
- * up handlers registered in scenario.
- * Not implemented yet!
- **/
- void end_scenario();
-
- /**
- * calls handler if it is registered
- * @return true if command handler was found
- **/
- bool call_handler(const std::string&, event_handler&, const
queued_event&, const vconfig&);
- };
-
game_state* get_state_of_game();
void write_events(config& cfg);
void add_events(const config::const_child_itors &cfgs,const
std::string& id);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits