From 605d5b648172d6c2774f136a38bdc733ee8d2346 Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Fri, 16 Sep 2022 16:43:21 +0300 Subject: [PATCH] add dedicated macro when building as single process fix kambala-decapitator/vcmi#40 --- CMakeLists.txt | 4 ++++ client/CServerHandler.cpp | 19 +++++++++++++------ client/CServerHandler.h | 1 + server/CVCMIServer.cpp | 10 +++++----- server/CVCMIServer.h | 2 +- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8fddb52e..6c84e97fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,10 @@ set(CMAKE_XCODE_ATTRIBUTE_MARKETING_VERSION ${APP_SHORT_VERSION}) set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO) set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=Debug] YES) +if(BUILD_SINGLE_APP) + add_compile_definitions(SINGLE_PROCESS_APP=1) +endif() + if(APPLE_IOS) set(CMAKE_MACOSX_RPATH 1) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.0) diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index fe509ada3..88d28067e 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -186,14 +186,12 @@ void CServerHandler::startLocalServerAndConnect() CAndroidVMHelper envHelper; envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true); } -#elif defined(VCMI_IOS) +#elif defined(SINGLE_PROCESS_APP) boost::condition_variable cond; threadRunLocalServer = std::make_shared([&cond, this] { setThreadName("CVCMIServer"); CVCMIServer::create(&cond, uuid); - // todo ios copypaste - threadRunLocalServer.reset(); - CSH->campaignServerRestartLock.setn(false); + onServerFinished(); }); threadRunLocalServer->detach(); #else @@ -212,11 +210,13 @@ void CServerHandler::startLocalServerAndConnect() } logNetwork->info("waiting for server finished..."); androidTestServerReadyFlag = false; -#elif defined(VCMI_IOS) +#elif defined(SINGLE_PROCESS_APP) { +#ifdef VCMI_IOS dispatch_sync(dispatch_get_main_queue(), ^{ iOS_utils::showLoadingIndicator(); }); +#endif boost::mutex m; boost::unique_lock lock{m}; @@ -224,9 +224,11 @@ void CServerHandler::startLocalServerAndConnect() cond.wait(lock); logNetwork->info("server is ready"); +#ifdef VCMI_IOS dispatch_sync(dispatch_get_main_queue(), ^{ iOS_utils::hideLoadingIndicator(); }); +#endif } #else if(shm) @@ -771,9 +773,14 @@ void CServerHandler::threadRunServer() logNetwork->error("Error: server failed to close correctly or crashed!"); logNetwork->error("Check %s for more info", logName); } + onServerFinished(); +#endif +} + +void CServerHandler::onServerFinished() +{ threadRunLocalServer.reset(); CSH->campaignServerRestartLock.setn(false); -#endif } void CServerHandler::sendLobbyPack(const CPackForLobby & pack) const diff --git a/client/CServerHandler.h b/client/CServerHandler.h index 749e46cb7..3b70d4343 100644 --- a/client/CServerHandler.h +++ b/client/CServerHandler.h @@ -83,6 +83,7 @@ class CServerHandler : public IServerAPI, public LobbyInfo void threadHandleConnection(); void threadRunServer(); + void onServerFinished(); void sendLobbyPack(const CPackForLobby & pack) const override; public: diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 1598c78f1..d4982ebd4 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -856,7 +856,7 @@ void handleLinuxSignal(int sig) static void handleCommandOptions(int argc, char * argv[], boost::program_options::variables_map & options) { namespace po = boost::program_options; -#ifdef VCMI_IOS +#ifdef SINGLE_PROCESS_APP options.emplace("run-by-client", po::variable_value{true, true}); options.emplace("uuid", po::variable_value{std::string{argv[1]}, true}); #else @@ -885,7 +885,7 @@ static void handleCommandOptions(int argc, char * argv[], boost::program_options po::notify(options); -#ifndef VCMI_IOS +#ifndef SINGLE_PROCESS_APP if(options.count("help")) { auto time = std::time(0); @@ -907,7 +907,7 @@ static void handleCommandOptions(int argc, char * argv[], boost::program_options #endif } -#ifdef VCMI_IOS +#ifdef SINGLE_PROCESS_APP #define main server_main #endif int main(int argc, char * argv[]) @@ -936,7 +936,7 @@ int main(int argc, char * argv[]) loadDLLClasses(); srand((ui32)time(nullptr)); -#ifdef VCMI_IOS +#ifdef SINGLE_PROCESS_APP boost::condition_variable * cond = reinterpret_cast(argv[0]); cond->notify_one(); #endif @@ -986,7 +986,7 @@ void CVCMIServer::create() const char * foo[1] = {"android-server"}; main(1, const_cast(foo)); } -#elif defined(VCMI_IOS) +#elif defined(SINGLE_PROCESS_APP) void CVCMIServer::create(boost::condition_variable * cond, const std::string & uuid) { const std::initializer_list argv = { diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h index 55ad15542..3370a0c66 100644 --- a/server/CVCMIServer.h +++ b/server/CVCMIServer.h @@ -108,7 +108,7 @@ public: #ifdef VCMI_ANDROID static void create(); -#elif defined(VCMI_IOS) +#elif defined(SINGLE_PROCESS_APP) static void create(boost::condition_variable * cond, const std::string & uuid); #endif };