From: Christoph Sommer Date: Sat, 20 Jan 2007 15:31:01 +0000 (+0000) Subject: Removed additional ConsoleCommandReceiver interface. Console is now 100% squirrel. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c0caa810fcbd6f6a09c0078fdf2d30a4a6cb7bc9;p=supertux.git Removed additional ConsoleCommandReceiver interface. Console is now 100% squirrel. SVN-Revision: 4611 --- diff --git a/src/console.cpp b/src/console.cpp index 422e24757..305913291 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -256,14 +256,6 @@ Console::autocomplete() std::list cmds; - // append all known CCRs to list - for (std::map >::iterator i = commands.begin(); i != commands.end(); i++) { - std::string cmdKnown = i->first; - if (cmdKnown.substr(0, prefix.length()) == prefix) { - cmds.push_back(cmdKnown); - } - } - ready_vm(); // append all keys of the current root table to list @@ -364,48 +356,17 @@ Console::parse(std::string s) // ignore if it's an internal command if (consoleCommand(command,args)) return; - // look up registered ccr - std::map >::iterator i = commands.find(command); - if ((i == commands.end()) || (i->second.size() == 0)) { - try { - execute_script(s); - } catch(std::exception& e) { - addLines(e.what()); - } - return; + try { + execute_script(s); + } catch(std::exception& e) { + addLines(e.what()); } - // send command to the most recently registered ccr - ConsoleCommandReceiver* ccr = i->second.front(); - if (ccr->consoleCommand(command, args) != true) log_warning << "Sent command to registered ccr, but command was unhandled" << std::endl; } bool -Console::consoleCommand(std::string command, std::vector arguments) +Console::consoleCommand(std::string /*command*/, std::vector /*arguments*/) { - if (command == "ccrs") { - if (arguments.size() != 1) { - log_info << "Usage: ccrs " << std::endl; - return true; - } - std::map >::iterator i = commands.find(arguments[0]); - if ((i == commands.end()) || (i->second.size() == 0)) { - log_info << "unknown command: \"" << arguments[0] << "\"" << std::endl; - return true; - } - - std::ostringstream ccr_list; - std::list &ccrs = i->second; - std::list::iterator j; - for (j = ccrs.begin(); j != ccrs.end(); j++) { - if (j != ccrs.begin()) ccr_list << ", "; - ccr_list << "[" << *j << "]"; - } - - log_info << "registered ccrs for \"" << arguments[0] << "\": " << ccr_list.str() << std::endl; - return true; - } - return false; } @@ -501,40 +462,6 @@ Console::draw(DrawingContext& context) context.pop_transform(); } -void -Console::registerCommand(std::string command, ConsoleCommandReceiver* ccr) -{ - commands[command].push_front(ccr); -} - -void -Console::unregisterCommand(std::string command, ConsoleCommandReceiver* ccr) -{ - std::map >::iterator i = commands.find(command); - if ((i == commands.end()) || (i->second.size() == 0)) { - log_warning << "Command \"" << command << "\" not associated with a command receiver. Not dissociated." << std::endl; - return; - } - std::list::iterator j = find(i->second.begin(), i->second.end(), ccr); - if (j == i->second.end()) { - log_warning << "Command \"" << command << "\" not associated with given command receiver. Not dissociated." << std::endl; - return; - } - i->second.erase(j); -} - -void -Console::unregisterCommands(ConsoleCommandReceiver* ccr) -{ - for (std::map >::iterator i = commands.begin(); i != commands.end(); i++) { - std::list &ccrs = i->second; - std::list::iterator j; - while ((j = find(ccrs.begin(), ccrs.end(), ccr)) != ccrs.end()) { - ccrs.erase(j); - } - } -} - Console* Console::instance = NULL; ConsoleStreamBuffer Console::inputBuffer; ConsoleStreamBuffer Console::outputBuffer; diff --git a/src/console.hpp b/src/console.hpp index 15d9791cb..83ea2fe07 100644 --- a/src/console.hpp +++ b/src/console.hpp @@ -61,9 +61,6 @@ public: void toggle(); /**< display the console if hidden, hide otherwise */ bool hasFocus(); /**< true if characters should be sent to the console instead of their normal target */ - void registerCommand(std::string command, ConsoleCommandReceiver* ccr); /**< associate command with the given CCR */ - void unregisterCommand(std::string command, ConsoleCommandReceiver* ccr); /**< dissociate command and CCR */ - void unregisterCommands(ConsoleCommandReceiver* ccr); /**< dissociate all commands of given CCR */ template static bool string_is(std::string s) { std::istringstream iss(s); @@ -89,7 +86,6 @@ private: std::list history; /**< command history. New lines get added to back. */ std::list::iterator history_position; /**< item of command history that is currently displayed */ std::list lines; /**< backbuffer of lines sent to the console. New lines get added to front. */ - std::map > commands; /**< map of console commands and a list of associated ConsoleCommandReceivers */ std::auto_ptr background; /**< console background image */ std::auto_ptr background2; /**< second, moving console background image */ @@ -138,19 +134,4 @@ class ConsoleStreamBuffer : public std::stringbuf } }; -class ConsoleCommandReceiver -{ -public: - virtual ~ConsoleCommandReceiver() - { - Console::instance->unregisterCommands(this); - } - - /** - * callback from Console; return false if command was unknown, - * true otherwise - */ - virtual bool consoleCommand(std::string command, std::vector arguments) = 0; -}; - #endif diff --git a/src/player_status.cpp b/src/player_status.cpp index 44512a1da..8279e17b1 100644 --- a/src/player_status.cpp +++ b/src/player_status.cpp @@ -48,8 +48,6 @@ PlayerStatus::PlayerStatus() reset(); coin_surface.reset(new Surface("images/engine/hud/coins-0.png")); - - Console::instance->registerCommand("coins", this); } PlayerStatus::~PlayerStatus() @@ -171,16 +169,3 @@ PlayerStatus::operator= (const PlayerStatus& other) max_score_multiplier = other.max_score_multiplier; } -bool -PlayerStatus::consoleCommand(std::string command, std::vector arguments) -{ - if (command == "coins") { - if ((arguments.size() < 1) || (!Console::string_is(arguments[0]))) { - log_info << "Usage: coins " << std::endl; - } else { - coins = Console::string_to(arguments[0]); - } - return true; - } - return false; -} diff --git a/src/player_status.hpp b/src/player_status.hpp index bf5cc272d..e23177424 100644 --- a/src/player_status.hpp +++ b/src/player_status.hpp @@ -41,7 +41,7 @@ class DrawingContext; * This class memorizes player status between different game sessions (for * example when switching maps in the worldmap) */ -class PlayerStatus : public Serializable, public ConsoleCommandReceiver +class PlayerStatus : public Serializable { public: PlayerStatus(); @@ -54,8 +54,6 @@ public: void draw(DrawingContext& context); - bool consoleCommand(std::string command, std::vector arguments); /**< callback from Console; return false if command was unknown, true otherwise */ - int coins; BonusType bonus; int max_fire_bullets; /**< maximum number of fire bullets in play */