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

Conflicts:
	project/jni/application/commandergenius/commandergenius
This commit is contained in:
Gerhard Stein
2014-10-20 18:25:56 +02:00
10 changed files with 130 additions and 63 deletions

1
.gitignore vendored
View File

@@ -16,3 +16,4 @@ project/res/drawable/app_icon.png
project/proguard-project.txt
project/proguard-local.cfg
project/themes/converter
project/jni/android-support

View File

@@ -912,6 +912,9 @@ fi
./copyAssets.sh || exit 1
rm -rf project/jni/android-support
ln -s "`which ndk-build | sed 's@/ndk-build@@'`/sources/android/support" project/jni/android-support
if uname -s | grep -i "darwin" > /dev/null ; then
find project/src -name "*.killme.tmp" -delete
fi

View File

@@ -362,6 +362,7 @@ abstract class DifferentTouchInput
}
private static class IcsTouchInput extends GingerbreadTouchInput
{
float hatX = 0.0f, hatY = 0.0f;
private static class Holder
{
private static final IcsTouchInput sInstance = new IcsTouchInput();
@@ -391,6 +392,29 @@ abstract class DifferentTouchInput
event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
event.getAxisValue(MotionEvent.AXIS_Z), event.getAxisValue(MotionEvent.AXIS_RZ),
event.getAxisValue(MotionEvent.AXIS_RTRIGGER), event.getAxisValue(MotionEvent.AXIS_LTRIGGER) );
// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, on Nvidia Shield and some other joysticks
if( event.getAxisValue(MotionEvent.AXIS_HAT_X) != hatX )
{
hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
if( hatX == 0.0f )
{
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_LEFT, 0, 0);
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_RIGHT, 0, 0);
}
else
DemoGLSurfaceView.nativeKey(hatX < 0.0f ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT, 1, 0);
}
if( event.getAxisValue(MotionEvent.AXIS_HAT_Y) != hatY )
{
hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
if( hatY == 0.0f )
{
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_UP, 0, 0);
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_DOWN, 0, 0);
}
else
DemoGLSurfaceView.nativeKey(hatY < 0.0f ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DPAD_DOWN, 1, 0);
}
return;
}
// Process mousewheel
@@ -436,41 +460,8 @@ abstract class DifferentTouchInput
{
private static final CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad sInstance = new CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad();
}
float hatX = 0.0f, hatY = 0.0f;
public void processGenericEvent(final MotionEvent event)
{
// Joysticks are supported since Honeycomb, but I don't care about it, because very little devices have it
if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK )
{
// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, they also send keyboard events
DemoGLSurfaceView.nativeGamepadAnalogJoystickInput(
event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
event.getAxisValue(MotionEvent.AXIS_RX), event.getAxisValue(MotionEvent.AXIS_RZ),
0, 0);
if( event.getAxisValue(MotionEvent.AXIS_HAT_X) != hatX )
{
hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
if( hatX == 0.0f )
{
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_LEFT, 0, 0);
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_RIGHT, 0, 0);
}
else
DemoGLSurfaceView.nativeKey(hatX < 0.0f ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT, 1, 0);
}
if( event.getAxisValue(MotionEvent.AXIS_HAT_Y) != hatY )
{
hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
if( hatY == 0.0f )
{
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_UP, 0, 0);
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_DOWN, 0, 0);
}
else
DemoGLSurfaceView.nativeKey(hatY < 0.0f ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DPAD_DOWN, 1, 0);
}
return;
}
super.processGenericEvent(event);
}
public boolean detect()

View File

@@ -3,7 +3,7 @@
APP_MODULES := application sdl-1.2 sdl_main sdl_native_helpers jpeg png ogg flac vorbis freetype tremor ogg
# To filter out static libs from all libs in makefile
APP_AVAILABLE_STATIC_LIBS := jpeg png tremor freetype xerces ogg tremor vorbis flac boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread boost_locale glu icudata icutest icui18n icuio icule iculx icutu icuuc sdl_savepng
APP_AVAILABLE_STATIC_LIBS := jpeg png tremor freetype xerces ogg tremor vorbis flac boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread boost_locale glu icudata icutest icui18n icuio icule iculx icutu icuuc sdl_savepng android_support
APP_ABI := armeabi

View File

@@ -221,7 +221,7 @@ AppMinimumRAM=0
# Optional shared libraries to compile - removing some of them will save space
# MP3 support by libMAD is encumbered by patents and libMAD is GPL-ed
# Available libraries: mad (GPL-ed!) sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx sdl_sound intl xml2 lua jpeg png ogg flac tremor vorbis freetype xerces curl theora fluidsynth lzma lzo2 mikmod openal timidity zzip bzip2 yaml-cpp python boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread glu avcodec avdevice avfilter avformat avresample avutil swscale swresample bzip2
CompiledLibraries="sdl_image"
CompiledLibraries="sdl_image android_support"
# Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n)
CustomBuildScript=n

View File

@@ -13,6 +13,7 @@
#include <string.h>
#include <math.h>
#include <android/log.h>
#include <wchar.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
@@ -554,6 +555,19 @@ int main(int argc, char* argv[])
memset(gamepads, 0, sizeof(gamepads));
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "sizeof(int) %d long %d long long %d size_t %d", sizeof(int), sizeof(long), sizeof(long long), sizeof(size_t));
wchar_t ss[256];
const wchar_t *ss2 = L"String 2 ЕНГ ---";
swprintf(ss, 256, L"String ЙЦУК --- %ls", ss2);
char ss3[512] = "";
char ss4[512] = "";
for(i = 0; i < wcslen(ss); i++)
{
char tmp[16];
sprintf(tmp, "%04X ", (int)ss[i]);
strcat(ss3, tmp);
sprintf(ss4, "%ls", ss);
}
__android_log_print(ANDROID_LOG_VERBOSE, "Ballfield", "swprintf: len %d data %s: %s", wcslen(ss), ss3, ss4);
__android_log_print(ANDROID_LOG_VERBOSE, "Ballfield", "On-screen buttons:");
for(i = 0; i < SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM; i++)

View File

@@ -7,10 +7,10 @@ AppName="JaggedAlliance2"
AppFullName=com.opensourced.ja2
# Application version code (integer)
AppVersionCode=2347
AppVersionCode=01235204
# Application user-visible version name (string)
AppVersionName="0.12.10"
AppVersionName="0.12.352.04"
# Specify path to download application data in zip archive in the form 'Description|URL|MirrorURL^Description2|URL2|MirrorURL2^...'
# If you'll start Description with '!' symbol it will be enabled by default, other downloads should be selected by user from startup config menu
@@ -21,7 +21,7 @@ AppVersionName="0.12.10"
AppDataDownloadUrl="!!JaggedAllianceData|ja2.zip"
# Reset SDL config when updating application to the new version (y) / (n)
ResetSdlConfigForThisVersion=y
ResetSdlConfigForThisVersion=n
# Delete application data files when upgrading (specify file/dir paths separated by spaces)
DeleteFilesOnUpgrade=""
@@ -75,30 +75,30 @@ CompatibilityHacksForceScreenUpdate=n
CompatibilityHacksForceScreenUpdateMouseClick=y
# Application initializes SDL audio/video inside static constructors (which is bad, you won't be able to run ndk-gdb) (y)/(n)
CompatibilityHacksStaticInit=
CompatibilityHacksStaticInit=n
# On-screen Android soft text input emulates hardware keyboard, this will only work with Hackers Keyboard app (y)/(n)
CompatibilityHacksTextInputEmulatesHwKeyboard=
CompatibilityHacksTextInputEmulatesHwKeyboard=n
# Hack for broken devices: prevent audio chopping, by sleeping a bit after pushing each audio chunk (y)/(n)
CompatibilityHacksPreventAudioChopping=
CompatibilityHacksPreventAudioChopping=n
# Hack for broken apps: application ignores audio buffer size returned by SDL (y)/(n)
CompatibilityHacksAppIgnoresAudioBufferSize=
CompatibilityHacksAppIgnoresAudioBufferSize=n
# Hack for VCMI: preload additional shared libraries before aplication start
CompatibilityHacksAdditionalPreloadedSharedLibraries=""
# Hack for Free Heroes 2, which redraws the screen inside SDL_PumpEvents(): slow and compatible SDL event queue -
# do not use it with accelerometer/gyroscope, or your app may freeze at random (y)/(n)
CompatibilityHacksSlowCompatibleEventQueue=
CompatibilityHacksSlowCompatibleEventQueue=n
# Save and restore OpenGL state when drawing on-screen keyboard for apps that use SDL_OPENGL
CompatibilityHacksTouchscreenKeyboardSaveRestoreOpenGLState=
CompatibilityHacksTouchscreenKeyboardSaveRestoreOpenGLState=n
# Application uses SDL_UpdateRects() properly, and does not draw in any region outside those rects.
# This improves drawing speed, but I know only one application that does that, and it's written by me (y)/(n)
CompatibilityHacksProperUsageOfSDL_UpdateRects=
CompatibilityHacksProperUsageOfSDL_UpdateRects=n
# Application uses mouse (y) or (n), this will show mouse emulation dialog to the user
AppUsesMouse=y
@@ -108,19 +108,19 @@ AppNeedsTwoButtonMouse=y
# Right mouse button can do long-press/drag&drop action, necessary for some games (y) or (n)
# If you disable it, swiping with two fingers will send mouse wheel events
RightMouseButtonLongPress=
RightMouseButtonLongPress=y
# Show SDL mouse cursor, for applications that do not draw cursor at all (y) or (n)
ShowMouseCursor=
ShowMouseCursor=n
# Generate more touch events, by default SDL generates one event per one video frame, this is useful for drawing apps (y) or (n)
GenerateSubframeTouchEvents=
GenerateSubframeTouchEvents=n
# Force relative (laptop) mouse movement mode, useful when both on-screen keyboard and mouse are needed (y) or (n)
ForceRelativeMouseMode=n
# Show on-screen dpad/joystick, that will act as arrow keys (y) or (n)
AppNeedsArrowKeys=y
AppNeedsArrowKeys=n
# On-screen dpad/joystick will appear under finger when it touches the screen (y) or (n)
# Joystick always follows finger, so moving mouse requires touching the screen with other finger
@@ -154,16 +154,16 @@ AppUsesMultitouch=n
# Application records audio (it will use any available source, such a s microphone)
# API is defined in file SDL_android.h: int SDL_ANDROID_OpenAudioRecording(SDL_AudioSpec *spec); void SDL_ANDROID_CloseAudioRecording(void);
# This option will add additional permission to Android manifest (y)/(n)
AppRecordsAudio=
AppRecordsAudio=n
# Application needs to access SD card. If your data files are bigger than 5 Mb, enable it. (y) / (n)
AccessSdCard=
AccessSdCard=y
# Application needs Internet access. If you disable it, you'll have to bundle all your data files inside .apk (y) / (n)
AccessInternet=
AccessInternet=n
# Immersive mode - Android will hide on-screen Home/Back keys. Looks bad if you invoke Android keyboard. (y) / (n)
ImmersiveMode=
ImmersiveMode=y
# Application implements Android-specific routines to put to background, and will not draw anything to screen
# between SDL_ACTIVEEVENT lost / gained notifications - you should check for them
@@ -176,10 +176,10 @@ NonBlockingSwapBuffers=n
# SEARCH and CALL by default return same keycode as DPAD_CENTER - one of those keys is available on most devices
# Use word NO_REMAP if you want to preserve native functionality for certain key (volume keys are 3-rd and 4-th)
# Keys: TOUCHSCREEN (works only when AppUsesMouse=n), DPAD_CENTER/SEARCH, VOLUMEUP, VOLUMEDOWN, MENU, BACK, CAMERA
RedefinedKeys="LCTRL RETURN KP_PLUS KP_MINUS LCTRL"
RedefinedKeys="MOUSE_RIGHT"
# Number of virtual keyboard keys (currently 6 is maximum)
AppTouchscreenKeyboardKeysAmount=5
AppTouchscreenKeyboardKeysAmount=1
# Redefine on-screen keyboard keys to SDL keysyms - 6 keyboard keys + 4 multitouch gestures (zoom in/out and rotate left/right)
RedefinedKeysScreenKb="LCTRL RETURN KP_PLUS KP_MINUS LCTRL"
@@ -221,7 +221,7 @@ AppMinimumRAM=0
# Optional shared libraries to compile - removing some of them will save space
# MP3 support by libMAD is encumbered by patents and libMAD is GPL-ed
# Available libraries: mad (GPL-ed!) sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx sdl_sound intl xml2 lua jpeg png ogg flac tremor vorbis freetype xerces curl theora fluidsynth lzma lzo2 mikmod openal timidity zzip bzip2 yaml-cpp python boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread glu avcodec avdevice avfilter avformat avresample avutil swscale swresample bzip2
CompiledLibraries="jpeg png boost_filesystem boost_system"
CompiledLibraries="jpeg png boost_filesystem boost_system android_support"
# Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n)
CustomBuildScript=y

View File

@@ -5,4 +5,4 @@
patch -p1 -d src-$1 < ja2.patch || exit 1
} || exit 1
../setEnvironment-$1.sh sh -c "make -j4 -C src-$1 WITH_LPTHREAD=0" && cp -f src-$1/ja2 libapplication-$1.so
../setEnvironment-$1.sh sh -c "make -j4 -C src-$1 WITH_LPTHREAD=0 Q=" && cp -f src-$1/ja2 libapplication-$1.so

View File

@@ -1,5 +1,5 @@
diff --git a/Makefile b/Makefile
index a21c6b5..8a65a69 100644
index a21c6b5..d6a8e9d 100644
--- a/Makefile
+++ b/Makefile
@@ -55,7 +55,7 @@ endif
@@ -21,6 +21,15 @@ index a21c6b5..8a65a69 100644
CFLAGS += -I _build/lib-rapidjson
CFLAGS += -I _build/lib-slog
CFLAGS += -I _build/lib-smacker/libsmacker
@@ -154,7 +155,7 @@ CCFLAGS += -Wmissing-prototypes
CXXFLAGS += $(CFLAGS)
-LDFLAGS += -lm
+LDFLAGS += -lm -landroid_support
ifeq "$(WITH_LPTHREAD)" "1"
LDFLAGS += -lpthread
@@ -522,15 +523,15 @@ SRCS += _build/lib-MicroIni/src/MicroIni/Line.cpp
SRCS += _build/lib-MicroIni/src/MicroIni/Section.cpp
SRCS += _build/lib-MicroIni/src/MicroIni/Value.cpp
@@ -240,8 +249,21 @@ index 263f9b1..57d377c 100644
#define PATH_SEPARATOR '/'
#define PATH_SEPARATOR_STR "/"
#endif
diff --git a/sgp/PlatformSDL.h b/sgp/PlatformSDL.h
index 7d69ce0..246d80c 100644
--- a/sgp/PlatformSDL.h
+++ b/sgp/PlatformSDL.h
@@ -15,7 +15,7 @@
* http://developer.apple.com/library/mac/#technotes/tn2133/_index.html
*
*/
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__ANDROID__)
#define EXPENSIVE_SDL_UPDATE_RECT (1)
#else
#define EXPENSIVE_SDL_UPDATE_RECT (0)
diff --git a/sgp/SGP.cc b/sgp/SGP.cc
index d156d73..66d7cf0 100644
index d156d73..e34ecd8 100644
--- a/sgp/SGP.cc
+++ b/sgp/SGP.cc
@@ -13,6 +13,9 @@
@@ -254,7 +276,17 @@ index d156d73..66d7cf0 100644
#include "Button_System.h"
#include "Debug.h"
@@ -49,9 +52,6 @@
@@ -32,6 +35,9 @@
#include "Video.h"
#include "VSurface.h"
#include <SDL.h>
+#ifdef __ANDROID__
+#include <SDL_screenkeyboard.h>
+#endif
#include "UILayout.h"
#include "GameRes.h"
#include "Logger.h"
@@ -49,9 +55,6 @@
#include "slog/slog.h"
#define TAG "SGP"
@@ -264,7 +296,15 @@ index d156d73..66d7cf0 100644
#if defined _WIN32
# define WIN32_LEAN_AND_MEAN
@@ -318,7 +318,7 @@ static BOOLEAN ParseParameters(int argc, char* const argv[],
@@ -273,6 +276,7 @@ static void MainLoop(int msPerGameCycle)
static int Failure(char const* const msg, bool showInfoIcon=false)
{
+ __android_log_print(ANDROID_LOG_FATAL, "JA2", "%s", msg);
fprintf(stderr, "%s\n", msg);
#if defined _WIN32
MessageBox(0, msg, APPLICATION_NAME, MB_OK | (showInfoIcon ? MB_ICONINFORMATION : MB_ICONERROR) | MB_TASKMODAL);
@@ -318,7 +322,7 @@ static BOOLEAN ParseParameters(int argc, char* const argv[],
int main(int argc, char* argv[])
try
{
@@ -273,7 +313,23 @@ index d156d73..66d7cf0 100644
#if defined BROKEN_SWPRINTF
if (setlocale(LC_CTYPE, "UTF-8") == NULL)
@@ -398,7 +401,7 @@ try
@@ -365,6 +369,15 @@ try
SDL_Init(SDL_INIT_VIDEO);
SDL_EnableUNICODE(SDL_ENABLE);
+#ifdef __ANDROID__
+ SDL_Rect r = { 64 * SDL_ListModes(NULL, 0)[0]->w / 1280,
+ 492 * SDL_ListModes(NULL, 0)[0]->h / 800,
+ (199 - 64) * SDL_ListModes(NULL, 0)[0]->w / 1280,
+ (627 - 492) * SDL_ListModes(NULL, 0)[0]->h / 800};
+ if (!SDL_ANDROID_GetScreenKeyboardRedefinedByUser())
+ SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, &r);
+#endif
+
#ifdef __APPLE__
// Enable 3-button mouse support if the user haven't instructed
// otherwise
@@ -398,7 +411,7 @@ try
if(extraDataDir.empty())
{
// use location of the exe file
@@ -282,7 +338,7 @@ index d156d73..66d7cf0 100644
}
std::string externalizedDataPath = FileMan::joinPaths(extraDataDir, "externalized");
@@ -775,7 +779,7 @@ static void WriteDefaultConfigFile(const char* ConfigFile)
@@ -775,7 +788,7 @@ static void WriteDefaultConfigFile(const char* ConfigFile)
#ifdef _WIN32
fprintf(IniFile, "data_dir = C:\\Program Files\\Jagged Alliance 2");
#else

View File

@@ -30,3 +30,5 @@ TODO, which will get actually done
- USB Keyboard: touchpad mode, configurable mouse speed, show keyboard LEDs, show error when root is not installed.
- S Planner Killer: options to restore calendar settiongs, and to kill lock-screen widget.
- GemRB: update.