Index: client/CPreGame.cpp =================================================================== --- client/CPreGame.cpp (revision 3494) +++ client/CPreGame.cpp (working copy) @@ -1141,7 +1141,7 @@ // Create the map info object CMapInfo mapInfo; - mapInfo.mapHeader = make_unique(); + mapInfo.mapHeader = std::make_shared(CMapHeader()); mapInfo.scenarioOpts = new StartInfo; lf >> *(mapInfo.mapHeader.get()) >> mapInfo.scenarioOpts; mapInfo.fileURI = file.getName(); @@ -1836,7 +1836,7 @@ // Generate header info mapInfo = make_unique(); mapInfo->isRandomMap = true; - mapInfo->mapHeader = make_unique(); + mapInfo->mapHeader = std::make_shared(CMapHeader()); mapInfo->mapHeader->version = EMapFormat::SOD; mapInfo->mapHeader->name = CGI->generaltexth->allTexts[740]; mapInfo->mapHeader->description = CGI->generaltexth->allTexts[741]; Index: client/CMT.cpp =================================================================== --- client/CMT.cpp (revision 3494) +++ client/CMT.cpp (working copy) @@ -194,7 +194,7 @@ #ifdef _WIN32 int wmain(int argc, wchar_t* argv[]) -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(ANDROID) int SDL_main(int argc, char *argv[]) #else int main(int argc, char** argv) @@ -217,6 +217,13 @@ } fclose(check); #endif + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__); + + // Fix crashing locale shit in Boost + setenv( "LANG", "C", 1 ); + setenv( "LANGUAGE", "C", 1 ); + setenv( "LC_ALL", "C", 1 ); + std::cout << "Starting... " << std::endl; po::options_description opts("Allowed options"); opts.add_options() @@ -289,6 +296,7 @@ // Initialize logging based on settings logConfig.configure(); + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__); // Some basic data validation to produce better error messages in cases of incorrect install auto testFile = [](std::string filename, std::string message) -> bool @@ -300,22 +308,31 @@ return false; }; + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__); if (!testFile("DATA/HELP.TXT", "Heroes III data") || !testFile("MODS/VCMI/MOD.JSON", "VCMI mod") || - !testFile("DATA/StackQueueBgBig.PCX", "VCMI data")) + !testFile("DATA/StackQueueBgBig.PCX", "VCMI data")) + { + __android_log_print(ANDROID_LOG_ERROR, "VCMI", "Cannot find data files!"); exit(1); // These are unrecoverable errors + } + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__); // these two are optional + some installs have them on CD and not in data directory testFile("VIDEO/GOOD1A.SMK", "campaign movies"); testFile("SOUNDS/G1A.WAV", "campaign music"); //technically not a music but voiced intro sounds + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__); + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__); conf.init(); logGlobal->infoStream() <<"Loading settings: "<infoStream() << NAME; + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__); srand ( time(nullptr) ); + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__); const JsonNode& video = settings["video"]; const JsonNode& res = video["screenRes"]; @@ -330,6 +347,7 @@ exit(EXIT_FAILURE); } + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__); if(!gNoGUI) { if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO)) @@ -360,7 +378,8 @@ //we can properly play intro only in the main thread, so we have to move loading to the separate thread - boost::thread loading(init); + //boost::thread loading(init); + init(); // boost::thread crashes when destroyed if(!gNoGUI ) { @@ -370,8 +389,8 @@ } CSDL_Ext::update(screen); - loading.join(); - logGlobal->infoStream()<<"Initialization of VCMI (together): "<infoStream()<<"Initialization of VCMI (together): "< #include - +#ifdef ANDROID +/* +#define move disable_move // It crashes with NDK r9 and GCC 4.8 +#include +#undef move +namespace std +{ + template + _Tp move(_Tp __t) + { + return __t; // Unoptimized version that does not crash + } + + template + OutputIt move(InputIt first, InputIt last, OutputIt d_first) + { + while (first != last) + { + *d_first++ = *first++; + } + return d_first; + } +} +*/ +/* +#include +#define unique_ptr shared_ptr +*/ +#endif #include #include #include Index: lib/filesystem/Filesystem.cpp =================================================================== --- lib/filesystem/Filesystem.cpp (revision 3494) +++ lib/filesystem/Filesystem.cpp (working copy) @@ -24,14 +24,14 @@ ResourceID::ResourceID(std::string name) { - CFileInfo info(std::move(name)); + CFileInfo info(/*std::move*/(name)); setName(info.getStem()); setType(info.getType()); } ResourceID::ResourceID(std::string name, EResType::Type type) { - setName(std::move(name)); + setName(/*std::move*/(name)); setType(type); } @@ -47,7 +47,7 @@ void ResourceID::setName(std::string name) { - this->name = std::move(name); + this->name = /*std::move*/(name); size_t dotPos = this->name.find_last_of("/."); Index: lib/filesystem/CFileInfo.cpp =================================================================== --- lib/filesystem/CFileInfo.cpp (revision 3494) +++ lib/filesystem/CFileInfo.cpp (working copy) @@ -7,7 +7,7 @@ } CFileInfo::CFileInfo(std::string name) - : name(std::move(name)) + : name(/*std::move*/(name)) { } Index: lib/mapping/CMapInfo.cpp =================================================================== --- lib/mapping/CMapInfo.cpp (revision 3494) +++ lib/mapping/CMapInfo.cpp (working copy) @@ -35,7 +35,7 @@ } -#define STEAL(x) x = std::move(tmp.x) +#define STEAL(x) x = /*std::move*/(tmp.x) CMapInfo::CMapInfo(CMapInfo && tmp) { @@ -54,13 +54,13 @@ void CMapInfo::mapInit(const std::string & fname) { fileURI = fname; - mapHeader = CMapService::loadMapHeader(fname); + mapHeader = std::make_shared(*CMapService::loadMapHeader(fname)); countPlayers(); } void CMapInfo::campaignInit() { - campaignHeader = std::unique_ptr(new CCampaignHeader(CCampaignHandler::getHeader(fileURI))); + campaignHeader = std::make_shared(CCampaignHandler::getHeader(fileURI)); } CMapInfo & CMapInfo::operator=(CMapInfo &&tmp) Index: lib/mapping/CMapInfo.h =================================================================== --- lib/mapping/CMapInfo.h (revision 3494) +++ lib/mapping/CMapInfo.h (working copy) @@ -20,8 +20,8 @@ class DLL_LINKAGE CMapInfo { public: - unique_ptr mapHeader; //may be nullptr if campaign - unique_ptr campaignHeader; //may be nullptr if scenario + shared_ptr mapHeader; //may be nullptr if campaign + shared_ptr campaignHeader; //may be nullptr if scenario StartInfo * scenarioOpts; //options with which scenario has been started (used only with saved games) std::string fileURI; std::string date; Index: lib/logging/CLogger.cpp =================================================================== --- lib/logging/CLogger.cpp (revision 3494) +++ lib/logging/CLogger.cpp (working copy) @@ -387,6 +387,9 @@ if(threshold > record.level) return; std::string message = formatter.format(record); +#ifdef ANDROID + __android_log_print(ANDROID_LOG_INFO, "VCMI", "%s", message.c_str()); +#endif bool printToStdErr = record.level >= ELogLevel::WARN; if(console) { Index: lib/logging/CLogger.h =================================================================== --- lib/logging/CLogger.h (revision 3494) +++ lib/logging/CLogger.h (working copy) @@ -289,3 +289,11 @@ CLogFormatter formatter; mutable boost::mutex mx; }; + +#ifdef ANDROID +static bool AndroidStaticInitLog() +{ + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Static init: %s", __SOURCE_FILE__); +} +static bool AndroidStaticInitLogFlag = AndroidStaticInitLog(); +#endif Index: lib/JsonNode.cpp =================================================================== --- lib/JsonNode.cpp (revision 3494) +++ lib/JsonNode.cpp (working copy) @@ -1574,7 +1574,7 @@ //reserve place and *move* remaining data from source to dest source.Vector().reserve(source.Vector().size() + dest.Vector().size()); - std::move(source.Vector().begin() + total, source.Vector().end(), + std::copy(source.Vector().begin() + total, source.Vector().end(), std::back_inserter(dest.Vector())); } break; Index: lib/vcmi_endian.h =================================================================== --- lib/vcmi_endian.h (revision 3494) +++ lib/vcmi_endian.h (working copy) @@ -19,7 +19,7 @@ * memory. On big endian machines, the value will be byteswapped. */ -#if defined(linux) && (defined(sparc) || defined(__arm__)) +#if defined(ANDROID) || defined(linux) && (defined(sparc) || defined(__arm__)) /* SPARC does not support unaligned memory access. Let gcc know when * to emit the right code. */ struct unaligned_Uint16 { ui16 val __attribute__(( packed )); }; Index: lib/VCMIDirs.cpp =================================================================== --- lib/VCMIDirs.cpp (revision 3494) +++ lib/VCMIDirs.cpp (working copy) @@ -15,11 +15,16 @@ VCMIDirs::VCMIDirs() { + char buf[1024] = ""; + getcwd(buf, sizeof(buf)); + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d: mkdir '%s' '%s' '%s' '%s' curdir '%s'", __FUNCTION__, __FILE__, __LINE__, + userDataPath().c_str(), userCachePath().c_str(), userConfigPath().c_str(), userSavePath().c_str(), buf); // initialize local directory and create folders to which VCMI needs write access boost::filesystem::create_directory(userDataPath()); boost::filesystem::create_directory(userCachePath()); boost::filesystem::create_directory(userConfigPath()); boost::filesystem::create_directory(userSavePath()); + __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__); } VCMIDirs & VCMIDirs::get() @@ -115,8 +120,10 @@ std::string VCMIDirs::userDataPath() const { +#ifndef ANDROID if (getenv("HOME") != nullptr ) return std::string(getenv("HOME")) + "/.vcmi"; +#endif return "."; }