mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-20 20:23:03 +02:00
fix single process build for Android
This commit is contained in:
parent
71d51beab2
commit
c4e7e91850
@ -36,6 +36,11 @@ class BattleStateInfoForRetreat;
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
// in static AI build this file gets included into libvcmi
|
||||
#ifdef STATIC_AI
|
||||
VCMI_LIB_USING_NAMESPACE
|
||||
#endif
|
||||
|
||||
class CClient;
|
||||
struct lua_State;
|
||||
|
||||
|
5
Global.h
5
Global.h
@ -756,6 +756,9 @@ namespace vstd
|
||||
}
|
||||
using vstd::operator-=;
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
|
||||
#ifdef NO_STD_TOSTRING
|
||||
namespace std
|
||||
{
|
||||
@ -768,5 +771,3 @@ namespace std
|
||||
}
|
||||
}
|
||||
#endif // NO_STD_TOSTRING
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@ -18,6 +18,7 @@ public final class LibsLoader
|
||||
SDL.setContext(ctx);
|
||||
}
|
||||
|
||||
// not used in single-process build
|
||||
public static void loadServerLibs()
|
||||
{
|
||||
SDL.loadLibrary("vcmiserver");
|
||||
|
@ -65,7 +65,7 @@ template<typename T> class CApplyOnLobby;
|
||||
|
||||
const std::string CServerHandler::localhostAddress{"127.0.0.1"};
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
#if defined(VCMI_ANDROID) && !defined(SINGLE_PROCESS_APP)
|
||||
extern std::atomic_bool androidTestServerReadyFlag;
|
||||
#endif
|
||||
|
||||
@ -196,12 +196,7 @@ void CServerHandler::startLocalServerAndConnect()
|
||||
//no connection means that port is not busy and we can start local server
|
||||
}
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
{
|
||||
CAndroidVMHelper envHelper;
|
||||
envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true);
|
||||
}
|
||||
#elif defined(SINGLE_PROCESS_APP)
|
||||
#if defined(SINGLE_PROCESS_APP)
|
||||
boost::condition_variable cond;
|
||||
std::vector<std::string> args{"--uuid=" + uuid, "--port=" + boost::lexical_cast<std::string>(getHostPort())};
|
||||
if(settings["session"]["lobby"].Bool() && settings["session"]["host"].Bool())
|
||||
@ -217,6 +212,11 @@ void CServerHandler::startLocalServerAndConnect()
|
||||
onServerFinished();
|
||||
});
|
||||
threadRunLocalServer->detach();
|
||||
#elif defined(VCMI_ANDROID)
|
||||
{
|
||||
CAndroidVMHelper envHelper;
|
||||
envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true);
|
||||
}
|
||||
#else
|
||||
threadRunLocalServer = std::make_shared<boost::thread>(&CServerHandler::threadRunServer, this); //runs server executable;
|
||||
#endif
|
||||
@ -224,16 +224,7 @@ void CServerHandler::startLocalServerAndConnect()
|
||||
|
||||
th->update();
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
logNetwork->info("waiting for server");
|
||||
while(!androidTestServerReadyFlag.load())
|
||||
{
|
||||
logNetwork->info("still waiting...");
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||
}
|
||||
logNetwork->info("waiting for server finished...");
|
||||
androidTestServerReadyFlag = false;
|
||||
#elif defined(SINGLE_PROCESS_APP)
|
||||
#ifdef SINGLE_PROCESS_APP
|
||||
{
|
||||
#ifdef VCMI_IOS
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
@ -253,6 +244,15 @@ void CServerHandler::startLocalServerAndConnect()
|
||||
});
|
||||
#endif
|
||||
}
|
||||
#elif defined(VCMI_ANDROID)
|
||||
logNetwork->info("waiting for server");
|
||||
while(!androidTestServerReadyFlag.load())
|
||||
{
|
||||
logNetwork->info("still waiting...");
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||
}
|
||||
logNetwork->info("waiting for server finished...");
|
||||
androidTestServerReadyFlag = false;
|
||||
#else
|
||||
if(shm)
|
||||
shm->sr->waitTillReady();
|
||||
|
@ -52,11 +52,11 @@
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
#include "lib/CAndroidVMHelper.h"
|
||||
#endif
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
#ifndef SINGLE_PROCESS_APP
|
||||
std::atomic_bool androidTestServerReadyFlag;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ThreadSafeVector<int> CClient::waitingRequest;
|
||||
|
||||
@ -778,6 +778,7 @@ void CClient::removeGUI()
|
||||
}
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
#ifndef SINGLE_PROCESS_APP
|
||||
extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_notifyServerClosed(JNIEnv * env, jclass cls)
|
||||
{
|
||||
logNetwork->info("Received server closed signal");
|
||||
@ -791,6 +792,7 @@ extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_notifyServerRe
|
||||
logNetwork->info("Received server ready signal");
|
||||
androidTestServerReadyFlag.store(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL Java_eu_vcmi_vcmi_NativeMethods_tryToSaveTheGame(JNIEnv * env, jclass cls)
|
||||
{
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "CAndroidVMHelper.h"
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
static JavaVM * vmCache = nullptr;
|
||||
|
||||
/// cached java classloader so that we can find our classes from other threads
|
||||
@ -109,4 +111,5 @@ void CAndroidVMHelper::initClassloader(void * baseEnv)
|
||||
vcmiFindClassMethod = env->GetMethodID(classLoaderClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
#endif
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
/// helper class that allows access to java vm to communicate with java code from native
|
||||
class DLL_LINKAGE CAndroidVMHelper
|
||||
{
|
||||
@ -47,4 +49,6 @@ public:
|
||||
static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods";
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
@ -13,6 +13,8 @@
|
||||
#ifdef VCMI_ANDROID
|
||||
#include <android/log.h>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
namespace ELogLevel
|
||||
{
|
||||
int toAndroid(ELogLevel logLevel)
|
||||
@ -30,6 +32,8 @@ namespace ELogLevel
|
||||
return ANDROID_LOG_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
#elif defined(VCMI_IOS)
|
||||
#import "iOS_utils.h"
|
||||
extern "C" {
|
||||
|
@ -188,8 +188,10 @@ void CVCMIServer::run()
|
||||
}
|
||||
|
||||
#if defined(VCMI_ANDROID)
|
||||
#ifndef SINGLE_PROCESS_APP
|
||||
CAndroidVMHelper vmHelper;
|
||||
vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "onServerReady");
|
||||
#endif
|
||||
#elif !defined(VCMI_IOS)
|
||||
if(shm)
|
||||
{
|
||||
@ -1024,7 +1026,7 @@ void handleLinuxSignal(int sig)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void handleCommandOptions(int argc, char * argv[], boost::program_options::variables_map & options)
|
||||
static void handleCommandOptions(int argc, const char * argv[], boost::program_options::variables_map & options)
|
||||
{
|
||||
namespace po = boost::program_options;
|
||||
po::options_description opts("Allowed options");
|
||||
@ -1084,13 +1086,14 @@ static void handleCommandOptions(int argc, char * argv[], boost::program_options
|
||||
#ifdef SINGLE_PROCESS_APP
|
||||
#define main server_main
|
||||
#endif
|
||||
#ifdef VCMI_ANDROID
|
||||
|
||||
#if VCMI_ANDROID_DUAL_PROCESS
|
||||
void CVCMIServer::create()
|
||||
{
|
||||
const int argc = 1;
|
||||
char * argv[argc] = { "android-server" };
|
||||
const char * argv[argc] = { "android-server" };
|
||||
#else
|
||||
int main(int argc, char * argv[])
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
#endif
|
||||
|
||||
@ -1121,7 +1124,7 @@ int main(int argc, char * argv[])
|
||||
srand((ui32)time(nullptr));
|
||||
|
||||
#ifdef SINGLE_PROCESS_APP
|
||||
boost::condition_variable * cond = reinterpret_cast<boost::condition_variable *>(argv[0]);
|
||||
boost::condition_variable * cond = reinterpret_cast<boost::condition_variable *>(const_cast<char *>(argv[0]));
|
||||
cond->notify_one();
|
||||
#endif
|
||||
|
||||
@ -1155,20 +1158,19 @@ int main(int argc, char * argv[])
|
||||
//and return non-zero status so client can detect error
|
||||
throw;
|
||||
}
|
||||
#ifdef VCMI_ANDROID
|
||||
#if VCMI_ANDROID_DUAL_PROCESS
|
||||
CAndroidVMHelper envHelper;
|
||||
envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "killServer");
|
||||
#endif
|
||||
logConfig.deconfigure();
|
||||
vstd::clear_pointer(VLC);
|
||||
|
||||
#ifndef VCMI_ANDROID
|
||||
#if !VCMI_ANDROID_DUAL_PROCESS
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
|
||||
#if VCMI_ANDROID_DUAL_PROCESS
|
||||
extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_createServer(JNIEnv * env, jclass cls)
|
||||
{
|
||||
__android_log_write(ANDROID_LOG_INFO, "VCMI", "Got jni call to init server");
|
||||
@ -1181,13 +1183,12 @@ extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_initClassloade
|
||||
{
|
||||
CAndroidVMHelper::initClassloader(baseEnv);
|
||||
}
|
||||
|
||||
#elif defined(SINGLE_PROCESS_APP)
|
||||
void CVCMIServer::create(boost::condition_variable * cond, const std::vector<std::string> & args)
|
||||
{
|
||||
std::vector<const void *> argv = {cond};
|
||||
for(auto & a : args)
|
||||
argv.push_back(a.c_str());
|
||||
main(argv.size(), reinterpret_cast<char **>(const_cast<void **>(&*argv.begin())));
|
||||
main(argv.size(), reinterpret_cast<const char **>(&*argv.begin()));
|
||||
}
|
||||
#endif
|
||||
|
@ -14,6 +14,10 @@
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#if defined(VCMI_ANDROID) && !defined(SINGLE_PROCESS_APP)
|
||||
#define VCMI_ANDROID_DUAL_PROCESS 1
|
||||
#endif
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class CMapInfo;
|
||||
@ -113,7 +117,7 @@ public:
|
||||
|
||||
ui8 getIdOfFirstUnallocatedPlayer() const;
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
#if VCMI_ANDROID_DUAL_PROCESS
|
||||
static void create();
|
||||
#elif defined(SINGLE_PROCESS_APP)
|
||||
static void create(boost::condition_variable * cond, const std::vector<std::string> & args);
|
||||
|
Loading…
Reference in New Issue
Block a user