Merge branch 'sdl_android' of github.com:pelya/commandergenius into android

This commit is contained in:
pelya
2012-10-29 16:51:46 +02:00
12 changed files with 76 additions and 31 deletions

View File

@@ -771,24 +771,32 @@ public class MainActivity extends Activity
// ----- VCMI hack -----
try {
//System.out.println("libSDL: Extracting VCMI server");
//System.out.println("libSDL: Extracting binaries");
InputStream in = null;
try
{
for( int i = 0; ; i++ )
{
InputStream in2 = getAssets().open("vcmiserver" + String.valueOf(i));
InputStream in2 = getAssets().open("binaries.zip" + String.format("%02d", i));
if( in == null )
in = in2;
else
in = new SequenceInputStream( in, in2 );
}
}
catch( IOException ee ) { }
catch( IOException ee )
{
try
{
if( in == null )
in = getAssets().open("binaries.zip");
}
catch( IOException eee ) {}
}
if( in == null )
throw new RuntimeException("libSDL: Extracting VCMI server failed, the .apk file packaged incorrectly");
throw new RuntimeException("libSDL: Extracting binaries failed, the .apk file packaged incorrectly");
ZipInputStream zip = new ZipInputStream(in);
@@ -808,7 +816,7 @@ public class MainActivity extends Activity
*/
if( entry == null )
{
System.out.println("Extracting libs finished");
System.out.println("Extracting binaries finished");
break;
}
if( entry.isDirectory() )

View File

@@ -59,6 +59,7 @@ import android.text.SpannedString;
import android.content.Intent;
import android.app.PendingIntent;
import android.app.AlarmManager;
import android.util.DisplayMetrics;
// TODO: too much code here, split into multiple files, possibly auto-generated menus?
class Settings
@@ -2472,6 +2473,28 @@ class Settings
nativeSetEnv( "LANG", lang );
nativeSetEnv( "LANGUAGE", lang );
// TODO: get current user name and set envvar USER, the API is not availalbe on Android 1.6 so I don't bother with this
nativeSetEnv( "APPDIR", p.getFilesDir().getAbsolutePath() );
nativeSetEnv( "SECURE_STORAGE_DIR", p.getFilesDir().getAbsolutePath() );
nativeSetEnv( "DATADIR", Globals.DataDir );
nativeSetEnv( "UNSECURE_STORAGE_DIR", Globals.DataDir );
nativeSetEnv( "HOME", Globals.DataDir );
try {
DisplayMetrics dm = new DisplayMetrics();
p.getWindowManager().getDefaultDisplay().getMetrics(dm);
float xx = dm.widthPixels/dm.xdpi;
float yy = dm.heightPixels/dm.ydpi;
float x = Math.max(xx, yy);
float y = Math.min(xx, yy);
float displayInches = (float)Math.sqrt( x*x + y*y );
nativeSetEnv( "DISPLAY_SIZE", String.valueOf(displayInches) );
nativeSetEnv( "DISPLAY_SIZE_MM", String.valueOf((int)(displayInches*25.4f)) );
nativeSetEnv( "DISPLAY_WIDTH", String.valueOf(x) );
nativeSetEnv( "DISPLAY_HEIGHT", String.valueOf(y) );
nativeSetEnv( "DISPLAY_WIDTH_MM", String.valueOf((int)(x*25.4f)) );
nativeSetEnv( "DISPLAY_HEIGHT_MM", String.valueOf((int)(y*25.4f)) );
nativeSetEnv( "DISPLAY_RESOLUTION_WIDTH", String.valueOf(Math.max(dm.widthPixels, dm.heightPixels)) );
nativeSetEnv( "DISPLAY_RESOLUTION_HEIGHT", String.valueOf(Math.min(dm.widthPixels, dm.heightPixels)) );
} catch (Exception eeeee) {}
}
static byte [] loadRaw(Activity p, int res)

View File

@@ -494,7 +494,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
// Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code
nativeInit( Globals.DataDir,
Globals.CommandLine,
( (Globals.SwVideoMode && Globals.MultiThreadedVideo) || Globals.CompatibilityHacksVideo ) ? 1 : 0 );
( (Globals.SwVideoMode && Globals.MultiThreadedVideo) || Globals.CompatibilityHacksVideo ) ? 1 : 0,
android.os.Debug.isDebuggerConnected() ? 1 : 0 );
System.exit(0); // The main() returns here - I don't bother with deinit stuff, just terminate process
}
@@ -669,7 +670,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
private native void nativeInitJavaCallbacks();
private native void nativeInit(String CurrentPath, String CommandLine, int multiThreadedVideo);
private native void nativeInit(String CurrentPath, String CommandLine, int multiThreadedVideo, int isDebuggerConnected);
private native void nativeResize(int w, int h, int keepAspectRatio);
private native void nativeDone();
private native void nativeGlContextLost();

View File

@@ -0,0 +1 @@
AndroidData

View File

@@ -20,7 +20,7 @@ AppUsesMouse=n
AppNeedsTwoButtonMouse=n
ShowMouseCursor=n
ForceRelativeMouseMode=n
AppNeedsArrowKeys=n
AppNeedsArrowKeys=y
AppNeedsTextInput=y
AppUsesJoystick=y
AppUsesAccelerometer=y
@@ -33,10 +33,10 @@ RedefinedKeysScreenKb="0 1 2 3 4 5 6 7 8 9"
StartupMenuButtonTimeout=3000
HiddenMenuOptions='OptionalDownloadConfig DisplaySizeConfig'
FirstStartMenuOptions=''
MultiABI=n
AppVersionCode=0880301
MultiABI=y
AppVersionCode=08803
AppVersionName="0.8.8.03"
ResetSdlConfigForThisVersion=n
ResetSdlConfigForThisVersion=y
DeleteFilesOnUpgrade="libsdl-DownloadFinished-1.flag"
CompiledLibraries="sdl_mixer sdl_image freetype curl vorbis ogg"
CustomBuildScript=y
@@ -46,6 +46,6 @@ AppSubdirsBuild=''
AppCmdline=''
ReadmeText='^Readme text'
MinimumScreenSize=n
AdmobPublisherId=a14fe4dd0ebe974
AdmobPublisherId=n #a14fe4dd0ebe974
AdmobTestDeviceId=66133194946FB6C1CD0ED2EFCCB82539
AdmobBannerSize=BANNER

View File

@@ -4,17 +4,25 @@ LOCAL_PATH=`dirname $0`
LOCAL_PATH=`cd $LOCAL_PATH && pwd`
[ "$1" = "armeabi" ] && (
mkdir -p AndroidData
[ -e libapplication.so ] || ln -s libapplication-armeabi.so libapplication.so
make -j8 -C vm BUILD_MISSIONPACK=0
make -j8 -C vm BUILD_MISSIONPACK=0 || exit 1
cd vm/build/release-linux-`uname -m`/baseq3
rm -f ../../../../AndroidData/binaries.zip
cd baseq3
zip -r vm.zip vm
cmp -s vm.zip ../../../../AndroidData/vm.zip || mv -f vm.zip ../../../../AndroidData/vm.zip
)
env NO_SHARED_LIBS=1 BUILD_EXECUTABLE=1 V=1 ../setEnvironment-armeabi.sh make -C vm -j8 PLATFORM=android ARCH=$1 USE_LOCAL_HEADERS=0 BUILD_MISSIONPACK=0 || exit 1
../setEnvironment-armeabi.sh sh -c "cd vm/build/release-android-$1/baseq3 && \$STRIP --strip-unneeded *.so && zip ../../../../AndroidData/binaries.zip *.so"
../setEnvironment-$1.sh make -j8 -C engine release \
PLATFORM=android ARCH=$1 USE_GLES=1 USE_LOCAL_HEADERS=0 \
USE_OPENAL=0 USE_CURL=1 USE_CURL_DLOPEN=0 USE_CODEC_VORBIS=1 USE_MUMBLE=0 USE_FREETYPE=1 \
USE_RENDERER_DLOPEN=0 USE_INTERNAL_ZLIB=0 USE_INTERNAL_JPEG=1 && \
echo "Copying engine/build/release-android-$1/openarena.$1 -> libapplication-$1.so" && \
cp -f engine/build/release-android-$1/openarena.$1 libapplication-$1.so && \
cp -f engine/build/release-android-$1/openarena.$1 libapplication-$1.so || exit 1
exit 0

View File

@@ -24,14 +24,9 @@ OBJS_GENIUSAI=$(patsubst %.cpp, out/%.o, $(SOURCES_GENIUSAI))
SOURCES_ERM=$(wildcard vcmi/Scripting/ERM/*.cpp)
OBJS_ERM=$(patsubst %.cpp, out/%.o, $(SOURCES_ERM))
all: AndroidData/vcmiserver0
all: AndroidData/binaries.zip
AndroidData/vcmiserver0: vcmiserver.zip
rm -f AndroidData/vcmiserver*
split -b 1048576 -d -a 1 $< AndroidData/vcmiserver
cp -f AndroidData/vcmiserver* ../../../assets
vcmiserver.zip: vcmiserver AI/libGeniusAI.so AI/libStupidAI.so Scripting/libvcmiERM.so
AndroidData/binaries.zip: vcmiserver AI/libGeniusAI.so AI/libStupidAI.so Scripting/libvcmiERM.so
rm -f $@
zip -r $@ $^

View File

@@ -1,5 +1,3 @@
#ifdef ANDROID
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
@@ -46,10 +44,15 @@ jobject SDL_ANDROID_JniVideoObject()
extern void SDL_ANDROID_MultiThreadedVideoLoopInit();
extern void SDL_ANDROID_MultiThreadedVideoLoop();
static int threadedMain(void * unused);
static int threadedMain(void * waitForDebugger);
int threadedMain(void * unused)
int threadedMain(void * waitForDebugger)
{
if( waitForDebugger )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "We are being debugged - waiting for debugger for 7 seconds");
//usleep(7000000);
}
SDL_main( argc, argv );
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Application closed, calling exit(0)");
exit(0);
@@ -57,7 +60,7 @@ int threadedMain(void * unused)
#endif
extern C_LINKAGE void
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring jcurdir, jstring cmdline, jint multiThreadedVideo )
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring jcurdir, jstring cmdline, jint multiThreadedVideo, jint waitForDebugger )
{
int i = 0;
char curdir[PATH_MAX] = "";
@@ -123,14 +126,19 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring
SDL_main( argc, argv );
#else
if( ! multiThreadedVideo )
{
if( waitForDebugger )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "We are being debugged - waiting for debugger for 7 seconds");
//usleep(7000000);
}
SDL_main( argc, argv );
}
else
{
SDL_ANDROID_MultiThreadedVideoLoopInit();
SDL_CreateThread(threadedMain, NULL);
SDL_CreateThread(threadedMain, (void *)waitForDebugger);
SDL_ANDROID_MultiThreadedVideoLoop();
}
#endif
};
#endif