From 8f599ed04338112f73c5ee35836571a3a0a4d632 Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Sun, 2 Oct 2022 14:23:03 +0300 Subject: [PATCH] NKAI: android fixes --- cmake_modules/VCMI_lib.cmake | 55 +++++++++++++++++++----------------- lib/CGameInterface.cpp | 8 +++++- server/CVCMIServer.cpp | 6 +++- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index a3e8d48da..9ba3074c2 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -1,5 +1,8 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) - set(MAIN_LIB_DIR "${CMAKE_SOURCE_DIR}/lib") + if(NOT DEFINED MAIN_LIB_DIR) + set(MAIN_LIB_DIR "${CMAKE_SOURCE_DIR}/lib") + endif() + set(lib_SRCS ${MAIN_LIB_DIR}/StdInc.cpp @@ -203,33 +206,33 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) endif() set(lib_HEADERS - ${CMAKE_SOURCE_DIR}/include/vstd/CLoggerBase.h - ${CMAKE_SOURCE_DIR}/Global.h + ${MAIN_LIB_DIR}/../include/vstd/CLoggerBase.h + ${MAIN_LIB_DIR}/../Global.h ${MAIN_LIB_DIR}/StdInc.h - ${CMAKE_SOURCE_DIR}/include/vstd/ContainerUtils.h - ${CMAKE_SOURCE_DIR}/include/vstd/RNG.h - ${CMAKE_SOURCE_DIR}/include/vstd/StringUtils.h + ${MAIN_LIB_DIR}/../include/vstd/ContainerUtils.h + ${MAIN_LIB_DIR}/../include/vstd/RNG.h + ${MAIN_LIB_DIR}/../include/vstd/StringUtils.h - ${CMAKE_SOURCE_DIR}/include/vcmi/events/ApplyDamage.h - ${CMAKE_SOURCE_DIR}/include/vcmi/events/Event.h - ${CMAKE_SOURCE_DIR}/include/vcmi/events/EventBus.h - ${CMAKE_SOURCE_DIR}/include/vcmi/events/SubscriptionRegistry.h + ${MAIN_LIB_DIR}/../include/vcmi/events/ApplyDamage.h + ${MAIN_LIB_DIR}/../include/vcmi/events/Event.h + ${MAIN_LIB_DIR}/../include/vcmi/events/EventBus.h + ${MAIN_LIB_DIR}/../include/vcmi/events/SubscriptionRegistry.h - ${CMAKE_SOURCE_DIR}/include/vcmi/scripting/Service.h + ${MAIN_LIB_DIR}/../include/vcmi/scripting/Service.h - ${CMAKE_SOURCE_DIR}/include/vcmi/spells/Caster.h - ${CMAKE_SOURCE_DIR}/include/vcmi/spells/Magic.h - ${CMAKE_SOURCE_DIR}/include/vcmi/spells/Service.h - ${CMAKE_SOURCE_DIR}/include/vcmi/spells/Spell.h + ${MAIN_LIB_DIR}/../include/vcmi/spells/Caster.h + ${MAIN_LIB_DIR}/../include/vcmi/spells/Magic.h + ${MAIN_LIB_DIR}/../include/vcmi/spells/Service.h + ${MAIN_LIB_DIR}/../include/vcmi/spells/Spell.h - ${CMAKE_SOURCE_DIR}/include/vcmi/Artifact.h - ${CMAKE_SOURCE_DIR}/include/vcmi/ArtifactService.h - ${CMAKE_SOURCE_DIR}/include/vcmi/Creature.h - ${CMAKE_SOURCE_DIR}/include/vcmi/CreatureService.h - ${CMAKE_SOURCE_DIR}/include/vcmi/Entity.h - ${CMAKE_SOURCE_DIR}/include/vcmi/Environment.h - ${CMAKE_SOURCE_DIR}/include/vcmi/Services.h + ${MAIN_LIB_DIR}/../include/vcmi/Artifact.h + ${MAIN_LIB_DIR}/../include/vcmi/ArtifactService.h + ${MAIN_LIB_DIR}/../include/vcmi/Creature.h + ${MAIN_LIB_DIR}/../include/vcmi/CreatureService.h + ${MAIN_LIB_DIR}/../include/vcmi/Entity.h + ${MAIN_LIB_DIR}/../include/vcmi/Environment.h + ${MAIN_LIB_DIR}/../include/vcmi/Services.h ${MAIN_LIB_DIR}/abilities/Ability.h @@ -457,8 +460,8 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - PUBLIC ${CMAKE_SOURCE_DIR} - PUBLIC ${CMAKE_SOURCE_DIR}/include + PUBLIC ${MAIN_LIB_DIR}/.. + PUBLIC ${MAIN_LIB_DIR}/../include PUBLIC ${MAIN_LIB_DIR} PRIVATE ${SDL2_INCLUDE_DIR} ) @@ -484,8 +487,8 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/config COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/Mods - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/config ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/config - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Mods ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/Mods + COMMAND ${CMAKE_COMMAND} -E copy_directory ${MAIN_LIB_DIR}/../config ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/config + COMMAND ${CMAKE_COMMAND} -E copy_directory ${MAIN_LIB_DIR}/../Mods ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/Mods ) endif() diff --git a/lib/CGameInterface.cpp b/lib/CGameInterface.cpp index 5abf49072..f47fa1bdf 100644 --- a/lib/CGameInterface.cpp +++ b/lib/CGameInterface.cpp @@ -25,6 +25,7 @@ #ifdef VCMI_ANDROID #include "AI/VCAI/VCAI.h" +#include "AI/Nullkiller/AIGateway.h" #include "AI/BattleAI/BattleAI.h" #endif @@ -96,7 +97,12 @@ std::shared_ptr createAny(const boost::filesystem::path & libpath, const s template<> std::shared_ptr createAny(const boost::filesystem::path & libpath, const std::string & methodName) { - return std::make_shared(); + if(libpath.stem() == "libNullkiller") { + return std::make_shared(); + } + else{ + return std::make_shared(); + } } template<> diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 12f972cd0..78bfb692b 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -171,7 +171,10 @@ void CVCMIServer::run() startAsyncAccept(); -#if !defined(VCMI_ANDROID) && !defined(VCMI_IOS) +#if defined(VCMI_ANDROID) + CAndroidVMHelper vmHelper; + vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "onServerReady"); +#elif !defined(VCMI_IOS) if(shm) { shm->sr->setToReadyAndNotify(port); @@ -1011,6 +1014,7 @@ int main(int argc, char * argv[]) void CVCMIServer::create() { const char * foo[1] = {"android-server"}; + main(1, const_cast(foo)); } #elif defined(SINGLE_PROCESS_APP)