浏览代码

Restart button fix (#288)

Dydzio 8 年之前
父节点
当前提交
88952aefff
共有 3 个文件被更改,包括 12 次插入3 次删除
  1. 6 2
      client/CMT.cpp
  2. 3 1
      client/CMT.h
  3. 3 0
      client/Client.cpp

+ 6 - 2
client/CMT.cpp

@@ -42,7 +42,6 @@
 #include "../lib/GameConstants.h"
 #include "gui/CGuiHandler.h"
 #include "../lib/logging/CBasicLogConfigurator.h"
-#include "../lib/CondSh.h"
 #include "../lib/StringConstants.h"
 #include "../lib/CPlayerState.h"
 #include "gui/CAnimation.h"
@@ -90,6 +89,7 @@ std::queue<SDL_Event> events;
 boost::mutex eventsM;
 
 bool gNoGUI = false;
+CondSh<bool> serverAlive(false);
 static po::variables_map vm;
 
 //static bool setResolution = false; //set by event handling thread after resolution is adjusted
@@ -1171,13 +1171,14 @@ static void handleEvent(SDL_Event & ev)
 		case RETURN_TO_MAIN_MENU:
 			{
 				endGame();
-				GH.curInt = CGPreGame::create();;
+				GH.curInt = CGPreGame::create();
 				GH.defActionsDef = 63;
 			}
 			break;
 		case RESTART_GAME:
 			{
 				StartInfo si = *client->getStartInfo(true);
+				si.seedToBeUsed = 0; //server gives new random generator seed if 0
 				endGame();
 				startGame(&si);
 			}
@@ -1248,6 +1249,9 @@ static void mainLoop()
 
 void startGame(StartInfo * options, CConnection *serv/* = nullptr*/)
 {
+	serverAlive.waitWhileTrue();
+	serverAlive.setn(true);
+
 	if(vm.count("onlyAI"))
 	{
 		auto ais = vm.count("ai") ? vm["ai"].as<std::vector<std::string>>() : std::vector<std::string>();

+ 3 - 1
client/CMT.h

@@ -1,6 +1,6 @@
 #pragma once
-
 #include <SDL_render.h>
+#include "../lib/CondSh.h"
 
 extern SDL_Texture * screenTexture;
 
@@ -14,4 +14,6 @@ extern SDL_Surface *screenBuf; // points to screen (if only advmapint is present
 
 extern bool gNoGUI; //if true there is no client window and game is silently played between AIs
 
+extern CondSh<bool> serverAlive; //used to prevent game start from executing if server is already running
+
 void handleQuit(bool ask = true);

+ 3 - 0
client/Client.cpp

@@ -1022,7 +1022,10 @@ void CServerHandler::callServer()
 	const std::string comm = VCMIDirs::get().serverPath().string() + " --port=" + port + " > \"" + logName + '\"';
 	int result = std::system(comm.c_str());
 	if (result == 0)
+	{
 		logNetwork->infoStream() << "Server closed correctly";
+		serverAlive.setn(false);
+	}
 	else
 	{
 		logNetwork->errorStream() << "Error: server failed to close correctly or crashed!";