Skip to content

Commit

Permalink
Merge branch 'sdl_android' of github.com:pelya/commandergenius into s…
Browse files Browse the repository at this point in the history
…dl_android

Conflicts:
	project/jni/application/commandergenius/AndroidAppSettings.cfg
	project/jni/application/commandergenius/AndroidData/keen1.zip
	project/jni/application/commandergenius/AndroidData/keen4.zip
	project/jni/application/commandergenius/AndroidData/keen7.zip
	project/jni/application/vcmi/AndroidAppSettings.cfg
  • Loading branch information
gerstrong committed Jan 16, 2013
2 parents 0956a58 + e647a97 commit 75d5f09
Show file tree
Hide file tree
Showing 3,949 changed files with 466,362 additions and 52,621 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 4 additions & 4 deletions bugs.txt
Expand Up @@ -3,6 +3,8 @@ Known bugs

- With 4:3 screen aspect ratio the on-screen buttons are not shown on the inactive part of screen.

- Put video at the center of the screen with 4:3 aspect ratio option

- Calling SDL_SetVideoMode() with SDL 1.3 several times makes it crash.

- Calling SDL_Init()/SDL_Quit() several times will make SDL 1.2 crash.
Expand All @@ -11,15 +13,13 @@ Known bugs

- 32-bpp color mode does not work with SW video surface, 24-bpp and 32-bpp mode does not work with SDL_HWSURFACE.

- Option SdlVideoResizeKeepAspect has no effect

Requested features
==================

- Support for resuming download of partially-downloaded files.

- Perform a check for free space available on SD card before writing there, and write to the internal storage if SD card is unplugged.

- Force SW video mode from AndroidAppSettings.cfg, ignore SDL_HWSURFACE if app does not explicitly support it.

- Split Settings.java into several files

- Show/hide screen controls with longpress on Text Edit button.
Expand Down
84 changes: 53 additions & 31 deletions build.sh
Expand Up @@ -3,6 +3,13 @@

install_apk=false
run_apk=false
sign_apk=false
build_release=false

if [ "$#" -gt 0 -a "$1" = "-s" ]; then
shift
sign_apk=true
fi

if [ "$#" -gt 0 -a "$1" = "-i" ]; then
shift
Expand All @@ -15,22 +22,29 @@ if [ "$#" -gt 0 -a "$1" = "-r" ]; then
run_apk=true
fi

[ -e local.properties ] || {
if [ "$#" -gt 0 -a "$1" = "release" ]; then
shift
build_release=true
fi

[ -e project/local.properties ] || {
android update project -p project || exit 1
rm -f project/src/Globals.java
}
# Set here your own NDK path if needed
# export PATH=$PATH:~/src/endless_space/android-ndk-r7
NDKBUILDPATH=$PATH
export `grep "AppFullName=" AndroidAppSettings.cfg`
if ( grep "package $AppFullName;" project/src/Globals.java > /dev/null && \
if ( grep "package $AppFullName;" project/src/Globals.java > /dev/null 2>&1 && \
[ "`readlink AndroidAppSettings.cfg`" -ot "project/src/Globals.java" ] && \
[ -z "`find project/java/* project/AndroidManifestTemplate.xml -cnewer project/src/Globals.java`" ] && \
[ -z "`find project/jni/application/src/AndroidData/* -cnewer project/src/Globals.java`" ] ) ; then true ; else
[ -z "`find project/java/* project/AndroidManifestTemplate.xml -cnewer project/src/Globals.java`" ] ) ; then true ; else
./changeAppSettings.sh -a
sleep 1
touch project/src/Globals.java
fi
if $build_release ; then
sed -i 's/android:debuggable="true"/android:debuggable="false"/g' project/AndroidManifest.xml
fi

MYARCH=linux-x86
NCPU=4
Expand All @@ -51,31 +65,39 @@ rm -r -f project/bin/* # New Android SDK introduced some lame-ass optimizations
./AndroidPreBuild.sh || { echo "AndroidPreBuild.sh returned with error" ; exit 1 ; }
cd ../../../..
}

cd project && env PATH=$NDKBUILDPATH BUILD_NUM_CPUS=$NCPU nice -n19 ndk-build -j$NCPU V=1 && \
{ grep "CustomBuildScript=y" ../AndroidAppSettings.cfg > /dev/null && \
echo Stripping libapplication.so by hand && \
rm obj/local/armeabi/libapplication.so && \
cp jni/application/src/libapplication.so obj/local/armeabi/ && \
cp jni/application/src/libapplication.so libs/armeabi/ && \
`which ndk-build | sed 's@/ndk-build@@'`/toolchains/arm-linux-androideabi-4.6/prebuilt/$MYARCH/bin/arm-linux-androideabi-strip --strip-unneeded libs/armeabi/libapplication.so \
|| true ; } && \
{ grep "CustomBuildScript=y" ../AndroidAppSettings.cfg > /dev/null && \
grep "MultiABI=y" ../AndroidAppSettings.cfg > /dev/null && \
echo Stripping libapplication-armeabi-v7a.so by hand && \
rm obj/local/armeabi-v7a/libapplication.so && \
cp jni/application/src/libapplication-armeabi-v7a.so obj/local/armeabi-v7a/libapplication.so && \
cp jni/application/src/libapplication-armeabi-v7a.so libs/armeabi-v7a/libapplication.so && \
`which ndk-build | sed 's@/ndk-build@@'`/toolchains/arm-linux-androideabi-4.6/prebuilt/$MYARCH/bin/arm-linux-androideabi-strip --strip-unneeded libs/armeabi-v7a/libapplication.so \
|| true ; } && \
cd .. && ./copyAssets.sh && cd project && \
ant debug && \
$install_apk && [ -n "`adb devices | tail -n +2`" ] && \
{ cd bin && adb install -r MainActivity-debug.apk | grep 'Failure' && \
adb uninstall `grep AppFullName ../../AndroidAppSettings.cfg | sed 's/.*=//'` && adb install -r MainActivity-debug.apk ; true ; } && \
$run_apk && {
ActivityName="`grep AppFullName ../../AndroidAppSettings.cfg | sed 's/.*=//'`/.MainActivity"
RUN_APK="adb shell am start -n $ActivityName"
echo "Running $ActivityName on the USB-connected device:"
echo "$RUN_APK"
eval $RUN_APK
}
{ grep "CustomBuildScript=y" ../AndroidAppSettings.cfg > /dev/null && \
echo Stripping libapplication.so by hand && \
rm obj/local/armeabi/libapplication.so && \
cp jni/application/src/libapplication.so obj/local/armeabi/ && \
cp jni/application/src/libapplication.so libs/armeabi/ && \
`which ndk-build | sed 's@/ndk-build@@'`/toolchains/arm-linux-androideabi-4.6/prebuilt/$MYARCH/bin/arm-linux-androideabi-strip --strip-unneeded libs/armeabi/libapplication.so \
|| true ; } && \
{ grep "CustomBuildScript=y" ../AndroidAppSettings.cfg > /dev/null && \
grep "MultiABI=y" ../AndroidAppSettings.cfg > /dev/null && \
echo Stripping libapplication-armeabi-v7a.so by hand && \
rm obj/local/armeabi-v7a/libapplication.so && \
cp jni/application/src/libapplication-armeabi-v7a.so obj/local/armeabi-v7a/libapplication.so && \
cp jni/application/src/libapplication-armeabi-v7a.so libs/armeabi-v7a/libapplication.so && \
`which ndk-build | sed 's@/ndk-build@@'`/toolchains/arm-linux-androideabi-4.6/prebuilt/$MYARCH/bin/arm-linux-androideabi-strip --strip-unneeded libs/armeabi-v7a/libapplication.so \
|| true ; } && \
cd .. && ./copyAssets.sh && cd project && \
{ if $build_release ; then \
ant release || exit 1 ; \
jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -sigalg MD5withRSA -digestalg SHA1 bin/MainActivity-release-unsigned.apk androiddebugkey || exit 1 ; \
zipalign 4 bin/MainActivity-release-unsigned.apk bin/MainActivity-debug.apk ; \
else \
ant debug ; \
fi ; } && \
{ if $sign_apk; then cd .. && ./sign.sh && cd project ; else true ; fi ; } && \
$install_apk && [ -n "`adb devices | tail -n +2`" ] && \
{ cd bin && adb install -r MainActivity-debug.apk | grep 'Failure' && \
adb uninstall `grep AppFullName ../../AndroidAppSettings.cfg | sed 's/.*=//'` && adb install -r MainActivity-debug.apk ; true ; } && \
$run_apk && { \
ActivityName="`grep AppFullName ../../AndroidAppSettings.cfg | sed 's/.*=//'`/.MainActivity" ; \
RUN_APK="adb shell am start -n $ActivityName" ; \
echo "Running $ActivityName on the USB-connected device:" ; \
echo "$RUN_APK" ; \
eval $RUN_APK ; \
}
5 changes: 3 additions & 2 deletions changeAppSettings.sh
Expand Up @@ -630,7 +630,7 @@ fi
if [ -z "$AUTO" -o -z "$MinimumScreenSize" ]; then
echo
echo "Screen size is used by Google Play to prevent an app to be installed on devices with smaller screens"
echo -n "Minimum screen size that application supports: (s)mall / (n)ormal / (l)arge ($MinimumScreenSize): "
echo -n "Minimum screen size that application supports: (s)mall / (m)edium / (l)arge ($MinimumScreenSize): "
read var
if [ -n "$var" ] ; then
MinimumScreenSize="$var"
Expand Down Expand Up @@ -662,6 +662,7 @@ echo CompatibilityHacksStaticInit=$CompatibilityHacksStaticInit >> AndroidAppSet
echo CompatibilityHacksTextInputEmulatesHwKeyboard=$CompatibilityHacksTextInputEmulatesHwKeyboard >> AndroidAppSettings.cfg
echo CompatibilityHacksPreventAudioChopping=$CompatibilityHacksPreventAudioChopping >> AndroidAppSettings.cfg
echo CompatibilityHacksAppIgnoresAudioBufferSize=$CompatibilityHacksAppIgnoresAudioBufferSize >> AndroidAppSettings.cfg
echo CompatibilityHacksAdditionalPreloadedSharedLibraries=\"$CompatibilityHacksAdditionalPreloadedSharedLibraries\" >> AndroidAppSettings.cfg
echo AppUsesMouse=$AppUsesMouse >> AndroidAppSettings.cfg
echo AppNeedsTwoButtonMouse=$AppNeedsTwoButtonMouse >> AndroidAppSettings.cfg
echo ShowMouseCursor=$ShowMouseCursor >> AndroidAppSettings.cfg
Expand Down Expand Up @@ -879,7 +880,7 @@ fi

LibrariesToLoad="\\\"sdl-$LibSdlVersion\\\""
StaticLibraries=`grep 'APP_AVAILABLE_STATIC_LIBS' project/jni/SettingsTemplate.mk | sed 's/.*=\(.*\)/\1/'`
for lib in $CompiledLibraries; do
for lib in $CompiledLibraries $CompatibilityHacksAdditionalPreloadedSharedLibraries; do
process=true
for lib1 in $StaticLibraries; do
if [ "$lib" = "$lib1" ]; then process=false; fi
Expand Down
2 changes: 1 addition & 1 deletion createSourceArchive.sh
Expand Up @@ -8,7 +8,7 @@ APPVER=`grep AppVersionName AndroidAppSettings.cfg | sed 's/.*=//' | tr -d '"' |
tar -c -z --exclude-vcs --exclude="*.o" --exclude="*.d" --exclude="*.dep" \
-f $APPNAME-$APPVER-src.tar.gz \
`git ls-files --exclude-standard | grep -v '^project/jni/application/.*'` \
`find project/jni/application -maxdepth 1 -type f` \
`find project/jni/application -maxdepth 1 -type f -o -type l` \
project/jni/application/src \
project/jni/application/`readlink project/jni/application/src` \
project/AndroidManifest.xml project/src
22 changes: 18 additions & 4 deletions project/java/GLSurfaceView_SDL.java
Expand Up @@ -674,6 +674,8 @@ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
String cfglog = "";
int idx = 0;
int selectidx = -1;

Log.v("SDL", "Desired GL config: " + "R" + mRedSize + "G" + mGreenSize + "B" + mBlueSize + "A" + mAlphaSize + " depth " + mDepthSize + " stencil " + mStencilSize + " type " + (mIsGles2 ? "GLES2" : "GLES"));
for(EGLConfig config : configs) {
if ( config == null )
continue;
Expand All @@ -699,12 +701,16 @@ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
int distance = Math.abs(r - mRedSize)
+ Math.abs(g - mGreenSize)
+ Math.abs(b - mBlueSize) + Math.abs(a - mAlphaSize);
int dist2 = distance;
if( (d > 0) != (mDepthSize > 0) )
distance += (d > 0) ? 5 : 1; // Small penalty if we don't need zbuffer but it is present
if( (s > 0) == (mStencilSize > 0) )
distance += (s > 0) ? 5 : 1;
distance += (mDepthSize > 0) ? 5 : 1; // Small penalty if we don't need zbuffer but it is present
int dist3 = distance;
if( (s > 0) != (mStencilSize > 0) )
distance += (mStencilSize > 0) ? 5 : 1;
int dist4 = distance;
if( (rendertype & desiredtype) == 0 )
distance += 5;
int dist5 = distance;
if( caveat == EGL10.EGL_SLOW_CONFIG )
distance += 4;
if( caveat == EGL10.EGL_NON_CONFORMANT_CONFIG ) // dunno what that means, probably R and B channels swapped
Expand All @@ -726,7 +732,7 @@ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
caveat == EGL10.EGL_NON_CONFORMANT_CONFIG ? "non-conformant" :
String.valueOf(caveat)));
cfgcur += " nr " + nativeRender;
cfgcur += " pos " + distance;
cfgcur += " pos " + distance + " (" + dist2 + "," + dist3 + "," + dist4 + "," + dist5 + ")";
Log.v("SDL", "GL config " + idx + ": " + cfgcur);
if (distance < closestDistance) {
closestDistance = distance;
Expand Down Expand Up @@ -890,6 +896,14 @@ public GL createSurface(SurfaceHolder holder) {
/*
* Create an EGL surface we can render into.
*/
/*
// This does not have any effect on Galaxy Note
int [] attribList = new int[4];
attribList[0] = mEgl.EGL_RENDER_BUFFER;
attribList[1] = mEgl.EGL_SINGLE_BUFFER;
attribList[2] = mEgl.EGL_NONE;
attribList[3] = mEgl.EGL_NONE;
*/
mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay,
mEglConfig, holder, null);

Expand Down
81 changes: 73 additions & 8 deletions project/java/MainActivity.java
Expand Up @@ -72,6 +72,7 @@ Java source code (C) 2009-2012 Sergii Pylypenko
import java.util.concurrent.Semaphore;
import android.content.pm.ActivityInfo;
import android.view.Display;
import android.text.InputType;

public class MainActivity extends Activity
{
Expand Down Expand Up @@ -293,8 +294,10 @@ private void initSDLInternal()
_tv = null;
_inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
_videoLayout = new FrameLayout(this);
SetLayerType.get().setLayerType(_videoLayout);
setContentView(_videoLayout);
mGLView = new DemoGLSurfaceView(this);
SetLayerType.get().setLayerType(mGLView);
_videoLayout.addView(mGLView);
mGLView.setFocusableInTouchMode(true);
mGLView.setFocusable(true);
Expand Down Expand Up @@ -418,13 +421,35 @@ public boolean onKey(View v, int keyCode, KeyEvent event)
_parent.hideScreenKeyboard();
return true;
}
if ((sendBackspace && event.getAction() == KeyEvent.ACTION_UP) && (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_CLEAR))
if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_CLEAR)
{
synchronized(textInput) {
DemoRenderer.nativeTextInput( 8, 0 ); // Send backspace to native code
if (sendBackspace && event.getAction() == KeyEvent.ACTION_UP)
{
synchronized(textInput) {
DemoRenderer.nativeTextInput( 8, 0 ); // Send backspace to native code
}
}
// EditText deletes two characters at a time, here's a hacky fix
if (event.getAction() == KeyEvent.ACTION_DOWN && (event.getFlags() | KeyEvent.FLAG_SOFT_KEYBOARD) != 0)
{
EditText t = (EditText) v;
int start = t.getSelectionStart(); //get cursor starting position
int end = t.getSelectionEnd(); //get cursor ending position
if ( start < 0 )
return true;
if ( end < 0 || end == start )
{
start --;
if ( start < 0 )
return true;
end = start + 1;
}
t.setText(t.getText().toString().substring(0, start) + t.getText().toString().substring(end));
t.setSelection(start);
return true;
}
return false; // and proceed to delete text in keyboard input field
}
//System.out.println("Key " + keyCode + " flags " + event.getFlags() + " action " + event.getAction());
return false;
}
};
Expand All @@ -433,7 +458,8 @@ public boolean onKey(View v, int keyCode, KeyEvent event)
_screenKeyboard.setOnKeyListener(new simpleKeyListener(this, sendBackspace));
_screenKeyboard.setHint(R.string.text_edit_click_here);
_screenKeyboard.setText(oldText);
_screenKeyboard.setKeyListener(new TextKeyListener(TextKeyListener.Capitalize.NONE, false));
//_screenKeyboard.setKeyListener(new TextKeyListener(TextKeyListener.Capitalize.NONE, false));
_screenKeyboard.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
_screenKeyboard.setFocusableInTouchMode(true);
_screenKeyboard.setFocusable(true);
_screenKeyboard.requestFocus();
Expand Down Expand Up @@ -812,15 +838,18 @@ public void LoadLibraries()
}

// ----- VCMI hack -----
String [] binaryZipNames = { "binaries-" + android.os.Build.CPU_ABI + ".zip", "binaries.zip" };
for(String binaryZip: binaryZipNames)
{
try {
//System.out.println("libSDL: Extracting binaries");
System.out.println("libSDL: Trying to extract binaries from assets " + binaryZip);

InputStream in = null;
try
{
for( int i = 0; ; i++ )
{
InputStream in2 = getAssets().open("binaries.zip" + String.format("%02d", i));
InputStream in2 = getAssets().open(binaryZip + String.format("%02d", i));
if( in == null )
in = in2;
else
Expand All @@ -832,7 +861,7 @@ public void LoadLibraries()
try
{
if( in == null )
in = getAssets().open("binaries.zip");
in = getAssets().open(binaryZip);
}
catch( IOException eee ) {}
}
Expand Down Expand Up @@ -911,6 +940,7 @@ public void LoadLibraries()
{
//System.out.println("libSDL: Error: " + eee.toString());
}
}
// ----- VCMI hack -----

};
Expand Down Expand Up @@ -1029,3 +1059,38 @@ public void dim(final View view)
}
}
}

abstract class SetLayerType
{
public static SetLayerType get()
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
return SetLayerTypeHoneycomb.Holder.sInstance;
else
return SetLayerTypeDummy.Holder.sInstance;
}
public abstract void setLayerType(final View view);

private static class SetLayerTypeHoneycomb extends SetLayerType
{
private static class Holder
{
private static final SetLayerTypeHoneycomb sInstance = new SetLayerTypeHoneycomb();
}
public void setLayerType(final View view)
{
view.setLayerType(android.view.View.LAYER_TYPE_NONE, null);
//view.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null);
}
}
private static class SetLayerTypeDummy extends SetLayerType
{
private static class Holder
{
private static final SetLayerTypeDummy sInstance = new SetLayerTypeDummy();
}
public void setLayerType(final View view)
{
}
}
}

0 comments on commit 75d5f09

Please sign in to comment.