1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Android port.

Conflicts:
	lib/vcmi_endian.h
This commit is contained in:
Ilya Zhuravlev
2014-02-20 22:53:18 +04:00
committed by Ilya Zhuravlev
parent ccc5c69fa2
commit db7cd79cf7
11 changed files with 128 additions and 16 deletions

View File

@ -22,7 +22,17 @@
*
*/
#ifdef __ANDROID__
// we can't use shared libraries on Android so here's a hack
extern "C" DLL_EXPORT void VCAI_GetAiName(char* name);
extern "C" DLL_EXPORT void VCAI_GetNewAI(shared_ptr<CGlobalAI> &out);
extern "C" DLL_EXPORT void StupidAI_GetAiName(char* name);
extern "C" DLL_EXPORT void StupidAI_GetNewBattleAI(shared_ptr<CGlobalAI> &out);
extern "C" DLL_EXPORT void BattleAI_GetAiName(char* name);
extern "C" DLL_EXPORT void BattleAI_GetNewBattleAI(shared_ptr<CBattleGameInterface> &out);
#endif
template<typename rett>
shared_ptr<rett> createAny(std::string dllname, std::string methodName)
@ -35,6 +45,21 @@ shared_ptr<rett> createAny(std::string dllname, std::string methodName)
TGetAIFun getAI = nullptr;
TGetNameFun getName = nullptr;
#ifdef __ANDROID__
// this is awful but it seems using shared libraries on some devices is even worse
if (dllname.find("libVCAI.so") != std::string::npos) {
getName = (TGetNameFun)VCAI_GetAiName;
getAI = (TGetAIFun)VCAI_GetNewAI;
} else if (dllname.find("libStupidAI.so") != std::string::npos) {
getName = (TGetNameFun)StupidAI_GetAiName;
getAI = (TGetAIFun)StupidAI_GetNewBattleAI;
} else if (dllname.find("libBattleAI.so") != std::string::npos) {
getName = (TGetNameFun)BattleAI_GetAiName;
getAI = (TGetAIFun)BattleAI_GetNewBattleAI;
} else {
throw std::runtime_error("Don't know what to do with " + dllname + " and method " + methodName);
}
#else
#ifdef _WIN32
HINSTANCE dll = LoadLibraryA(dllname.c_str());
@ -69,6 +94,8 @@ shared_ptr<rett> createAny(std::string dllname, std::string methodName)
throw std::runtime_error("Cannot find method " + methodName);
}
#endif // __ANDROID__
getName(temp);
logGlobal->infoStream() << "Loaded " << temp;