mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Restart button fix (#288)
This commit is contained in:
parent
09d593e59b
commit
88952aefff
@ -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>();
|
||||
|
@ -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);
|
||||
|
@ -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!";
|
||||
|
Loading…
Reference in New Issue
Block a user