1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

add dedicated macro when building as single process

fix kambala-decapitator/vcmi#40
This commit is contained in:
Andrey Filipenkov 2022-09-16 16:43:21 +03:00
parent f56acf8a80
commit 605d5b6481
5 changed files with 24 additions and 12 deletions

View File

@ -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)

View File

@ -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<boost::thread>([&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<boost::mutex> 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

View File

@ -83,6 +83,7 @@ class CServerHandler : public IServerAPI, public LobbyInfo
void threadHandleConnection();
void threadRunServer();
void onServerFinished();
void sendLobbyPack(const CPackForLobby & pack) const override;
public:

View File

@ -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<boost::condition_variable *>(argv[0]);
cond->notify_one();
#endif
@ -986,7 +986,7 @@ void CVCMIServer::create()
const char * foo[1] = {"android-server"};
main(1, const_cast<char **>(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<const void *> argv = {

View File

@ -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
};