Selaa lähdekoodia

Change ClientCommandManager to become non-static

Dydzio 2 vuotta sitten
vanhempi
sitoutus
06376ca4ef

+ 8 - 1
client/CMT.cpp

@@ -239,7 +239,14 @@ int main(int argc, char * argv[])
 	std::cout.flags(std::ios::unitbuf);
 #ifndef VCMI_IOS
 	console = new CConsoleHandler();
-	*console->cb = ClientCommandManager::processCommand;
+
+	auto callbackFunction = [](std::string buffer, bool calledFromIngameConsole)
+	{
+		ClientCommandManager commandController;
+		commandController.processCommand(buffer, calledFromIngameConsole);
+	};
+
+	*console->cb = callbackFunction;
 	console->start();
 #endif
 

+ 0 - 2
client/ClientCommandManager.cpp

@@ -33,8 +33,6 @@
 #include "../lib/ScriptHandler.h"
 #endif
 
-bool ClientCommandManager::currentCallFromIngameConsole;
-
 void ClientCommandManager::handleGoSolo()
 {
 	Settings session = settings.write["session"];

+ 8 - 8
client/ClientCommandManager.h

@@ -17,15 +17,15 @@ class CIntObject;
 
 class ClientCommandManager //take mantis #2292 issue about account if thinking about handling cheats from command-line
 {
-	static bool currentCallFromIngameConsole;
+	bool currentCallFromIngameConsole;
 
-	static void giveTurn(const PlayerColor &color);
-	static void printInfoAboutInterfaceObject(const CIntObject *obj, int level);
-	static void printCommandMessage(const std::string &commandMessage, ELogLevel::ELogLevel messageType = ELogLevel::NOT_SET);
-	static void handleGoSolo();
-	static void handleControlAi(const std::string &colorName);
+	void giveTurn(const PlayerColor &color);
+	void printInfoAboutInterfaceObject(const CIntObject *obj, int level);
+	void printCommandMessage(const std::string &commandMessage, ELogLevel::ELogLevel messageType = ELogLevel::NOT_SET);
+	void handleGoSolo();
+	void handleControlAi(const std::string &colorName);
 
 public:
-	ClientCommandManager() = delete;
-	static void processCommand(const std::string &message, bool calledFromIngameConsole);
+	ClientCommandManager() = default;
+	void processCommand(const std::string &message, bool calledFromIngameConsole);
 };

+ 7 - 1
client/widgets/AdventureMapClasses.cpp

@@ -1154,7 +1154,13 @@ void CInGameConsole::endEnteringText(bool processEnteredText)
 		if(txt.at(0) == '/')
 		{
 			//some commands like gosolo don't work when executed from GUI thread
-			boost::thread clientCommandThread(ClientCommandManager::processCommand, txt.substr(1), true);
+			auto threadFunction = [=]()
+			{
+				ClientCommandManager commandController;
+				commandController.processCommand(txt.substr(1), true);
+			};
+
+			boost::thread clientCommandThread(threadFunction);
 			clientCommandThread.detach();
 		}
 		else