diff --git a/changeAppSettings.sh b/changeAppSettings.sh index 0a2d93ad8..8b2a8f950 100755 --- a/changeAppSettings.sh +++ b/changeAppSettings.sh @@ -1144,7 +1144,7 @@ fi LibrariesToLoad="\\\"sdl-$LibSdlVersion\\\"" StaticLibraries=`grep 'APP_AVAILABLE_STATIC_LIBS' project/jni/SettingsTemplate.mk | sed 's/.*=\(.*\)/\1/'` -for lib in $CompiledLibraries $CompatibilityHacksAdditionalPreloadedSharedLibraries; do +for lib in $CompiledLibraries; do process=true for lib1 in $StaticLibraries; do if [ "$lib" = "$lib1" ]; then process=false; fi @@ -1154,6 +1154,12 @@ for lib in $CompiledLibraries $CompatibilityHacksAdditionalPreloadedSharedLibrar fi done +MainLibrariesToLoad="" +for lib in $CompatibilityHacksAdditionalPreloadedSharedLibraries; do + MainLibrariesToLoad="$MainLibrariesToLoad \\\"$lib\\\"," +done +MainLibrariesToLoad="$MainLibrariesToLoad \\\"application\\\", \\\"sdl_main\\\"" + if [ "$CustomBuildScript" = "n" ] ; then CustomBuildScript= fi @@ -1275,6 +1281,7 @@ $SEDI "s/public static String AdmobPublisherId = .*/public static String AdmobPu $SEDI "s/public static String AdmobTestDeviceId = .*/public static String AdmobTestDeviceId = \"$AdmobTestDeviceId\";/" project/src/Globals.java $SEDI "s/public static String AdmobBannerSize = .*/public static String AdmobBannerSize = \"$AdmobBannerSize\";/" project/src/Globals.java $SEDI "s/public static String AppLibraries.*/public static String AppLibraries[] = { $LibrariesToLoad };/" project/src/Globals.java +$SEDI "s/public static String AppMainLibraries.*/public static String AppMainLibraries[] = { $MainLibrariesToLoad };/" project/src/Globals.java echo Patching project/jni/Settings.mk diff --git a/project/java/Globals.java b/project/java/Globals.java index ec38ae368..76de3d88f 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -31,6 +31,7 @@ class Globals // These config options are modified by ChangeAppsettings.sh script - see the detailed descriptions there public static String ApplicationName = "CommanderGenius"; public static String AppLibraries[] = { "sdl-1.2", }; + public static String AppMainLibraries[] = { "application", "sdl_main" }; public static final boolean Using_SDL_1_3 = false; public static String[] DataDownloadUrl = { "Data files are 2 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-data.zip/download", "High-quality GFX and music - 40 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-hqp.zip/download" }; public static int VideoDepthBpp = 16; diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index f94942c9d..1cf215313 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -768,114 +768,6 @@ public class MainActivity extends Activity Log.i("SDL", "libSDL: Cannot load GLESv2 lib"); } - // ----- VCMI hack ----- - String [] binaryZipNames = { "binaries-" + android.os.Build.CPU_ABI + ".zip", "binaries.zip" }; - for(String binaryZip: binaryZipNames) - { - try { - Log.i("SDL", "libSDL: Trying to extract binaries from assets " + binaryZip); - - InputStream in = null; - try - { - for( int i = 0; ; i++ ) - { - InputStream in2 = getAssets().open(binaryZip + String.format("%02d", i)); - if( in == null ) - in = in2; - else - in = new SequenceInputStream( in, in2 ); - } - } - catch( IOException ee ) - { - try - { - if( in == null ) - in = getAssets().open(binaryZip); - } - catch( IOException eee ) {} - } - - if( in == null ) - throw new RuntimeException("libSDL: Extracting binaries failed, the .apk file packaged incorrectly"); - - ZipInputStream zip = new ZipInputStream(in); - - File libDir = getFilesDir(); - try { - libDir.mkdirs(); - } catch( SecurityException ee ) { }; - - byte[] buf = new byte[16384]; - while(true) - { - ZipEntry entry = null; - entry = zip.getNextEntry(); - /* - if( entry != null ) - Log.i("SDL", "Extracting lib " + entry.getName()); - */ - if( entry == null ) - { - Log.i("SDL", "Extracting binaries finished"); - break; - } - if( entry.isDirectory() ) - { - File outDir = new File( libDir.getAbsolutePath() + "/" + entry.getName() ); - if( !(outDir.exists() && outDir.isDirectory()) ) - outDir.mkdirs(); - continue; - } - - OutputStream out = null; - String path = libDir.getAbsolutePath() + "/" + entry.getName(); - try { - File outDir = new File( path.substring(0, path.lastIndexOf("/") )); - if( !(outDir.exists() && outDir.isDirectory()) ) - outDir.mkdirs(); - } catch( SecurityException eeeeeee ) { }; - - try { - CheckedInputStream check = new CheckedInputStream( new FileInputStream(path), new CRC32() ); - while( check.read(buf, 0, buf.length) > 0 ) {}; - check.close(); - if( check.getChecksum().getValue() != entry.getCrc() ) - { - File ff = new File(path); - ff.delete(); - throw new Exception(); - } - Log.i("SDL", "File '" + path + "' exists and passed CRC check - not overwriting it"); - continue; - } catch( Exception eeeeee ) { } - - Log.i("SDL", "Saving to file '" + path + "'"); - - out = new FileOutputStream( path ); - int len = zip.read(buf); - while (len >= 0) - { - if(len > 0) - out.write(buf, 0, len); - len = zip.read(buf); - } - - out.flush(); - out.close(); - //Settings.nativeChmod(path, 0755); - String chmod[] = { "/system/bin/chmod", "0755", path }; - Runtime.getRuntime().exec(chmod).waitFor(); - } - } - catch ( Exception eee ) - { - //Log.i("SDL", "libSDL: Error: " + eee.toString()); - } - } - // ----- VCMI hack ----- - // Load all libraries try { @@ -995,36 +887,142 @@ public class MainActivity extends Activity } } + // ----- VCMI hack ----- + String [] binaryZipNames = { "binaries-" + android.os.Build.CPU_ABI + ".zip", "binaries.zip" }; + for(String binaryZip: binaryZipNames) + { + try { + Log.i("SDL", "libSDL: Trying to extract binaries from assets " + binaryZip); + + InputStream in = null; + try + { + for( int i = 0; ; i++ ) + { + InputStream in2 = getAssets().open(binaryZip + String.format("%02d", i)); + if( in == null ) + in = in2; + else + in = new SequenceInputStream( in, in2 ); + } + } + catch( IOException ee ) + { + try + { + if( in == null ) + in = getAssets().open(binaryZip); + } + catch( IOException eee ) {} + } + if( in == null ) + throw new RuntimeException("libSDL: Extracting binaries failed, the .apk file packaged incorrectly"); + + ZipInputStream zip = new ZipInputStream(in); + + File libDir = getFilesDir(); + try { + libDir.mkdirs(); + } catch( SecurityException ee ) { }; + + byte[] buf = new byte[16384]; + while(true) + { + ZipEntry entry = null; + entry = zip.getNextEntry(); + /* + if( entry != null ) + Log.i("SDL", "Extracting lib " + entry.getName()); + */ + if( entry == null ) + { + Log.i("SDL", "Extracting binaries finished"); + break; + } + if( entry.isDirectory() ) + { + File outDir = new File( libDir.getAbsolutePath() + "/" + entry.getName() ); + if( !(outDir.exists() && outDir.isDirectory()) ) + outDir.mkdirs(); + continue; + } + + OutputStream out = null; + String path = libDir.getAbsolutePath() + "/" + entry.getName(); + try { + File outDir = new File( path.substring(0, path.lastIndexOf("/") )); + if( !(outDir.exists() && outDir.isDirectory()) ) + outDir.mkdirs(); + } catch( SecurityException eeeeeee ) { }; + + try { + CheckedInputStream check = new CheckedInputStream( new FileInputStream(path), new CRC32() ); + while( check.read(buf, 0, buf.length) > 0 ) {}; + check.close(); + if( check.getChecksum().getValue() != entry.getCrc() ) + { + File ff = new File(path); + ff.delete(); + throw new Exception(); + } + Log.i("SDL", "File '" + path + "' exists and passed CRC check - not overwriting it"); + continue; + } catch( Exception eeeeee ) { } + + Log.i("SDL", "Saving to file '" + path + "'"); + + out = new FileOutputStream( path ); + int len = zip.read(buf); + while (len >= 0) + { + if(len > 0) + out.write(buf, 0, len); + len = zip.read(buf); + } + + out.flush(); + out.close(); + Settings.nativeChmod(path, 0755); + //String chmod[] = { "/system/bin/chmod", "0755", path }; + //Runtime.getRuntime().exec(chmod).waitFor(); + } + } + catch ( Exception eee ) + { + //Log.i("SDL", "libSDL: Error: " + eee.toString()); + } + } + // ----- VCMI hack ----- }; public static void LoadApplicationLibrary(final Context context) { - String libs[] = { "application", "sdl_main" }; - try + Settings.nativeChdir(Globals.DataDir); + for(String l : Globals.AppMainLibraries) { - for(String l : libs) - { - System.loadLibrary(l); - } - } - catch ( UnsatisfiedLinkError e ) - { - Log.i("SDL", "libSDL: error loading lib: " + e.toString()); try { - for(String l : libs) + String libname = System.mapLibraryName(l); + File libpath = new File(context.getFilesDir().getAbsolutePath() + "/../lib/" + libname); + Log.i("SDL", "libSDL: loading lib " + libpath.getAbsolutePath()); + System.load(libpath.getPath()); + } + catch( UnsatisfiedLinkError e ) + { + Log.i("SDL", "libSDL: error loading lib " + l + ": " + e.toString()); + try { String libname = System.mapLibraryName(l); - File libpath = new File(context.getFilesDir(), libname); - Log.i("SDL", "libSDL: loading lib " + libpath.getPath()); + File libpath = new File(context.getFilesDir().getAbsolutePath() + "/" + libname); + Log.i("SDL", "libSDL: loading lib " + libpath.getAbsolutePath()); System.load(libpath.getPath()); - libpath.delete(); } - } - catch ( UnsatisfiedLinkError ee ) - { - Log.i("SDL", "libSDL: error loading lib: " + ee.toString()); + catch( UnsatisfiedLinkError ee ) + { + Log.i("SDL", "libSDL: error loading lib " + l + ": " + ee.toString()); + System.loadLibrary(l); + } } } } diff --git a/project/java/Settings.java b/project/java/Settings.java index 2486381e5..b379c8a1c 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -767,5 +767,6 @@ class Settings private static native void nativeSetTouchscreenCalibration(int x1, int y1, int x2, int y2); public static native void nativeSetEnv(final String name, final String value); public static native int nativeChmod(final String name, int mode); + public static native void nativeChdir(final String dir); } diff --git a/project/jni/application/vcmi/AndroidAppSettings.cfg b/project/jni/application/vcmi/AndroidAppSettings.cfg index 37956f0d6..e49ed473c 100644 --- a/project/jni/application/vcmi/AndroidAppSettings.cfg +++ b/project/jni/application/vcmi/AndroidAppSettings.cfg @@ -159,10 +159,10 @@ MultiABI=armeabi-v7a AppMinimumRAM=128 # Application version code (integer) -AppVersionCode=09300 +AppVersionCode=09301 # Application user-visible version name (string) -AppVersionName="0.93.00" +AppVersionName="0.93.01" # Reset SDL config when updating application to the new version (y) / (n) ResetSdlConfigForThisVersion=n diff --git a/project/jni/application/vcmi/Makefile b/project/jni/application/vcmi/Makefile index 2b4de8680..0a1f76491 100644 --- a/project/jni/application/vcmi/Makefile +++ b/project/jni/application/vcmi/Makefile @@ -31,7 +31,7 @@ OBJS_LIB_MAPPING:=$(patsubst %.cpp, out/%.o, $(SOURCES_LIB_MAPPING)) SOURCES_LIB_RMG:=$(wildcard vcmi/lib/rmg/*.cpp) OBJS_LIB_RMG:=$(patsubst %.cpp, out/%.o, $(SOURCES_LIB_RMG)) -OBJS_LIB_ALL:=$(OBJS_LIB_FILESYSTEM) $(OBJS_LIB_LOGGING) $(OBJS_LIB_MAPPING) $(OBJS_LIB_RMG) $(OBJS_LIB) $(OBJS_MINIZIP) +OBJS_LIB_ALL:= $(OBJS_MINIZIP) $(OBJS_LIB_FILESYSTEM) $(OBJS_LIB_LOGGING) $(OBJS_LIB_MAPPING) $(OBJS_LIB_RMG) $(OBJS_LIB) SOURCES_SERVER:=$(wildcard vcmi/server/*.cpp) OBJS_SERVER:=$(patsubst %.cpp, out/%.o, $(SOURCES_SERVER)) @@ -65,11 +65,11 @@ $(OBJS_SERVER) $(OBJS_LIB) $(OBJS_LIB_FILESYSTEM) $(OBJS_LIB_LOGGING) $(OBJS_LIB $(OBJS_BATTLEAI) $(OBJS_STUPIDAI) $(OBJS_FUZZYLITE) $(OBJS_VCAI) $(OBJS_CLIENT) $(OBJS_ERM): out/%.o: %.cpp env GCCVER=$(GCC_VERSION) ../setEnvironment-armeabi-v7a.sh sh -c \ "$(GCC_PREFIX)-g++ \ - -c \$$CXXFLAGS -O2 -Ivcmi -std=c++11 -Ivcmi/lib \ + -c \$$CXXFLAGS -O1 -Ivcmi -std=c++11 -Ivcmi/lib \ -DM_DATA_DIR=\\\".\\\" \ -DM_BIN_DIR=\\\"/data/data/eu.vcmi/files\\\" \ -DM_LIB_DIR=\\\"/data/data/eu.vcmi/files\\\" \ - -Wstrict-aliasing -Wcast-align -Wpointer-arith -Waddress \ + -Wstrict-aliasing -Wcast-align -Wpointer-arith -Waddress -D__SOURCE_FILE__=\\\"$<\\\" \ $< -o $@" # -Werror=strict-aliasing -Werror=cast-align -Werror=pointer-arith -Werror=address diff --git a/project/jni/application/vcmi/readme.txt b/project/jni/application/vcmi/readme.txt index 268a146b0..373bfcc84 100644 --- a/project/jni/application/vcmi/readme.txt +++ b/project/jni/application/vcmi/readme.txt @@ -1,6 +1,6 @@ Quick compilation guide: Download my GIT repo from https://github.com/pelya/commandergenius, -then install Android SDK and NDK from http://developer.android.com, +then install Android SDK and NDK r9 from http://developer.android.com, ANT, patch and Subversion tools, then launch commands android update project -p project rm project/jni/application/src diff --git a/project/jni/application/vcmi/vcmi-android.diff b/project/jni/application/vcmi/vcmi-android.diff index 384c52d00..0d444b113 100644 --- a/project/jni/application/vcmi/vcmi-android.diff +++ b/project/jni/application/vcmi/vcmi-android.diff @@ -1,19 +1,28 @@ -Index: client/battle/CBattleInterface.cpp +Index: client/CPreGame.cpp =================================================================== ---- client/battle/CBattleInterface.cpp (revision 3490) -+++ client/battle/CBattleInterface.cpp (working copy) -@@ -34,7 +34,7 @@ - #include "../gui/CGuiHandler.h" - #include "../CMT.h" +--- client/CPreGame.cpp (revision 3494) ++++ client/CPreGame.cpp (working copy) +@@ -1141,7 +1141,7 @@ --#if defined(_MSC_VER) && _MSC_VER >= 1800 -+#if (defined(_MSC_VER) && _MSC_VER >= 1800) || defined(ANDROID) - #define _USE_MATH_DEFINES - #include - #else + // 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 3490) +--- client/CMT.cpp (revision 3494) +++ client/CMT.cpp (working copy) @@ -194,7 +194,7 @@ @@ -24,23 +33,263 @@ Index: client/CMT.cpp int SDL_main(int argc, char *argv[]) #else int main(int argc, char** argv) -Index: CMakeLists.txt -=================================================================== ---- CMakeLists.txt (revision 3490) -+++ CMakeLists.txt (working copy) -@@ -117,6 +117,9 @@ - add_definitions(-DM_BIN_DIR="${CMAKE_INSTALL_PREFIX}/${BIN_DIR}") - add_definitions(-DM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/${LIB_DIR}") - -+#add_definitions(-DDLL_EXPORT=) -+add_definitions(-DIOAPI_NO_64) +@@ -217,6 +217,13 @@ + } + fclose(check); + #endif ++ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__); + - SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/vcmi") - SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) ++ // 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 3490) +--- 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. @@ -51,37 +300,35 @@ Index: lib/vcmi_endian.h /* 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/logging/CLogger.cpp +Index: lib/VCMIDirs.cpp =================================================================== ---- lib/logging/CLogger.cpp (revision 3490) -+++ lib/logging/CLogger.cpp (working copy) -@@ -1,6 +1,10 @@ - #include "StdInc.h" - #include "CLogger.h" -+#ifdef ANDROID -+#include -+#endif +--- lib/VCMIDirs.cpp (revision 3494) ++++ lib/VCMIDirs.cpp (working copy) +@@ -15,11 +15,16 @@ -+ - const std::string CLoggerDomain::DOMAIN_GLOBAL = "global"; - - CLoggerDomain::CLoggerDomain(const std::string & name) : name(name) -@@ -379,6 +383,8 @@ - - CLogConsoleTarget::CLogConsoleTarget(CConsoleHandler * console) : console(console), threshold(ELogLevel::INFO), coloredOutputEnabled(true) + VCMIDirs::VCMIDirs() { -+ __android_log_print(ANDROID_LOG_INFO, "VCMI", "CLogConsoleTarget::CLogConsoleTarget()"); -+ - formatter.setPattern("%m"); ++ 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__); } -@@ -387,6 +393,9 @@ - if(threshold > record.level) return; + VCMIDirs & VCMIDirs::get() +@@ -115,8 +120,10 @@ - std::string message = formatter.format(record); -+#ifdef ANDROID -+ __android_log_print(ANDROID_LOG_INFO, "VCMI", "%s", message.c_str()); + std::string VCMIDirs::userDataPath() const + { ++#ifndef ANDROID + if (getenv("HOME") != nullptr ) + return std::string(getenv("HOME")) + "/.vcmi"; +#endif - bool printToStdErr = record.level >= ELogLevel::WARN; - if(console) - { + return "."; + } + diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c index 16b7400f6..4a79702f8 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c @@ -452,3 +452,32 @@ int SDLCALL SDL_ANDROID_RequestNewAdvertisement(void) return 1; } +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetEnv) ( JNIEnv* env, jobject thiz, jstring j_name, jstring j_value ) +{ + jboolean iscopy; + const char *name = (*env)->GetStringUTFChars(env, j_name, &iscopy); + const char *value = (*env)->GetStringUTFChars(env, j_value, &iscopy); + setenv(name, value, 1); + (*env)->ReleaseStringUTFChars(env, j_name, name); + (*env)->ReleaseStringUTFChars(env, j_value, value); +} + +JNIEXPORT jint JNICALL +JAVA_EXPORT_NAME(Settings_nativeChmod) ( JNIEnv* env, jobject thiz, jstring j_name, jint mode ) +{ + jboolean iscopy; + const char *name = (*env)->GetStringUTFChars(env, j_name, &iscopy); + int ret = chmod(name, mode); + (*env)->ReleaseStringUTFChars(env, j_name, name); + return (ret == 0); +} + +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeChdir) ( JNIEnv* env, jobject thiz, jstring j_dir ) +{ + jboolean iscopy; + const char *dirname = (*env)->GetStringUTFChars(env, j_dir, &iscopy); + chdir(dirname); + (*env)->ReleaseStringUTFChars(env, j_dir, dirname); +} diff --git a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c index 3060af4cb..52237f2e7 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c @@ -1110,28 +1110,6 @@ int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBuf, int textBufSi return 1; }; -// That's probably not the right file to put this func -JNIEXPORT jint JNICALL -JAVA_EXPORT_NAME(Settings_nativeChmod) ( JNIEnv* env, jobject thiz, jstring j_name, jint mode ) -{ - jboolean iscopy; - const char *name = (*env)->GetStringUTFChars(env, j_name, &iscopy); - int ret = chmod(name, mode); - (*env)->ReleaseStringUTFChars(env, j_name, name); - return (ret == 0); -} - -JNIEXPORT void JNICALL -JAVA_EXPORT_NAME(Settings_nativeSetEnv) ( JNIEnv* env, jobject thiz, jstring j_name, jstring j_value ) -{ - jboolean iscopy; - const char *name = (*env)->GetStringUTFChars(env, j_name, &iscopy); - const char *value = (*env)->GetStringUTFChars(env, j_value, &iscopy); - setenv(name, value, 1); - (*env)->ReleaseStringUTFChars(env, j_name, name); - (*env)->ReleaseStringUTFChars(env, j_value, value); -} - int SDLCALL SDL_HasScreenKeyboardSupport(void *unused) { return 1;