1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Client: add donotstartserver option. Alternative way to start a game

Option is useful for server profiling also let me test MP over network and much more.
Also there is issues with boost::interprocess on some systems under Windows and this is the way to bypass them.
This commit is contained in:
Arseniy Shestakov
2016-09-16 20:01:44 +03:00
parent ea65fb15c2
commit 1cbe9e1b8b
4 changed files with 19 additions and 0 deletions

View File

@ -240,6 +240,7 @@ int main(int argc, char** argv)
("autoSkip", "automatically skip turns in GUI") ("autoSkip", "automatically skip turns in GUI")
("disable-video", "disable video player") ("disable-video", "disable video player")
("nointro,i", "skips intro movies") ("nointro,i", "skips intro movies")
("donotstartserver,d","do not attempt to start server and just connect to it instead server")
("loadserver","specifies we are the multiplayer server for loaded games") ("loadserver","specifies we are the multiplayer server for loaded games")
("loadnumplayers",po::value<int>(),"specifies the number of players connecting to a multiplayer game") ("loadnumplayers",po::value<int>(),"specifies the number of players connecting to a multiplayer game")
("loadhumanplayerindices",po::value<std::vector<int>>(),"Indexes of human players (0=Red, etc.)") ("loadhumanplayerindices",po::value<std::vector<int>>(),"Indexes of human players (0=Red, etc.)")
@ -277,6 +278,10 @@ int main(int argc, char** argv)
gNoGUI = true; gNoGUI = true;
vm.insert(std::pair<std::string, po::variable_value>("onlyAI", po::variable_value())); vm.insert(std::pair<std::string, po::variable_value>("onlyAI", po::variable_value()));
} }
if(vm.count("donotstartserver"))
{
CServerHandler::DO_NOT_START_SERVER = true;
}
// Have effect on X11 system only (Linux). // Have effect on X11 system only (Linux).
// For whatever reason in fullscreen mode SDL takes "raw" mouse input from DGA X11 extension // For whatever reason in fullscreen mode SDL takes "raw" mouse input from DGA X11 extension

View File

@ -719,6 +719,10 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti
else if(current) else if(current)
{ {
SelectMap sm(*current); SelectMap sm(*current);
// FIXME: Super dirty hack to avoid crash on multiplayer game start.
// There is some issues with TriggeredEvent serialization that cause it.
// We'll look into them once refactored serializer fixed and merged
sm.mapInfo->mapHeader->triggeredEvents.clear();
*serv << &sm; *serv << &sm;
UpdateStartOptions uso(sInfo); UpdateStartOptions uso(sInfo);

View File

@ -928,10 +928,15 @@ std::string CClient::aiNameForPlayer(const PlayerSettings &ps, bool battleAI)
return goodAI; return goodAI;
} }
bool CServerHandler::DO_NOT_START_SERVER = false;
void CServerHandler::startServer() void CServerHandler::startServer()
{ {
if(DO_NOT_START_SERVER)
return;
th.update(); th.update();
serverThread = new boost::thread(&CServerHandler::callServer, this); //runs server executable; serverThread = new boost::thread(&CServerHandler::callServer, this); //runs server executable;
if(verbose) if(verbose)
logNetwork->infoStream() << "Setting up thread calling server: " << th.getDiff(); logNetwork->infoStream() << "Setting up thread calling server: " << th.getDiff();
@ -939,6 +944,9 @@ void CServerHandler::startServer()
void CServerHandler::waitForServer() void CServerHandler::waitForServer()
{ {
if(DO_NOT_START_SERVER)
return;
if(!serverThread) if(!serverThread)
startServer(); startServer();

View File

@ -42,6 +42,8 @@ class CServerHandler
private: private:
void callServer(); //calls server via system(), should be called as thread void callServer(); //calls server via system(), should be called as thread
public: public:
static bool DO_NOT_START_SERVER;
CStopWatch th; CStopWatch th;
boost::thread *serverThread; //thread that called system to run server boost::thread *serverThread; //thread that called system to run server
SharedMem *shared; //interprocess memory (for waiting for server) SharedMem *shared; //interprocess memory (for waiting for server)