From 9211c7355dfeb9b4ee4696da0387ec8f62832faf Mon Sep 17 00:00:00 2001 From: pelya Date: Sat, 10 Aug 2013 17:35:27 +0300 Subject: [PATCH] Added support for gamepad kays remapping to AndroidAppSettings.cfg --- changeAppSettings.sh | 29 +- .../openarena/AndroidAppSettings.cfg | 4 + .../vcmi-r2387/AndroidAppSettings.cfg | 174 +- project/jni/application/vcmi-r2387/Makefile | 25 +- project/jni/application/vcmi-r2387/vcmi | 1 - .../application/vcmi-r2387/vcmi-android.diff | 1597 +++++++++-------- project/jni/boost/src | 2 +- .../jni/sdl-1.2/include/SDL_screenkeyboard.h | 2 +- .../src/video/android/SDL_androidinput.h | 33 + .../jni/sdl-1.2/src/video/android/keymap.c | 20 +- 10 files changed, 1059 insertions(+), 828 deletions(-) delete mode 120000 project/jni/application/vcmi-r2387/vcmi diff --git a/changeAppSettings.sh b/changeAppSettings.sh index 8b2a8f950..5e0838734 100755 --- a/changeAppSettings.sh +++ b/changeAppSettings.sh @@ -475,6 +475,23 @@ if [ -n "$var" ] ; then fi fi +if [ -z "$RedefinedKeysGamepad" -o -z "$AUTO" ]; then +if [ -z "$RedefinedKeysGamepad" ]; then + RedefinedKeysGamepad="$RedefinedKeysScreenKb" + CHANGED=1 +fi +echo +echo "Redefine gamepad keys to SDL keysyms, button order is:" +echo "A B X Y L1 R1 L2 R2 LThumb RThumb" +echo "$RedefinedKeysGamepad - current SDL keycodes" +echo -n ": " +read var +if [ -n "$var" ] ; then + RedefinedKeysGamepad="$var" + CHANGED=1 +fi +fi + if [ -z "$StartupMenuButtonTimeout" -o -z "$AUTO" ]; then echo echo -n "How long to show startup menu button, in msec, 0 to disable startup menu ($StartupMenuButtonTimeout): " @@ -864,6 +881,10 @@ echo >> AndroidAppSettings.cfg echo "# Names for on-screen keyboard keys, such as Fire, Jump, Run etc, separated by spaces, they are used in SDL config menu" >> AndroidAppSettings.cfg echo RedefinedKeysScreenKbNames=\"$RedefinedKeysScreenKbNames\" >> AndroidAppSettings.cfg echo >> AndroidAppSettings.cfg +echo "# Redefine gamepad keys to SDL keysyms, button order is:" >> AndroidAppSettings.cfg +echo "# A B X Y L1 R1 L2 R2 LThumb RThumb" >> AndroidAppSettings.cfg +echo RedefinedKeysGamepad=\"$RedefinedKeysGamepad\" >> AndroidAppSettings.cfg +echo >> AndroidAppSettings.cfg echo "# How long to show startup menu button, in msec, 0 to disable startup menu" >> AndroidAppSettings.cfg echo StartupMenuButtonTimeout=$StartupMenuButtonTimeout >> AndroidAppSettings.cfg echo >> AndroidAppSettings.cfg @@ -1134,6 +1155,12 @@ for KEY in $RedefinedKeysScreenKb; do KEY2=`expr $KEY2 '+' 1` done +KEY2=0 +for KEY in $RedefinedKeysGamepad; do + RedefinedKeycodesGamepad="$RedefinedKeycodesGamepad -DSDL_ANDROID_GAMEPAD_KEYCODE_$KEY2=$KEY" + KEY2=`expr $KEY2 '+' 1` +done + if [ "$MultiABI" = "y" ] ; then MultiABI="armeabi armeabi-v7a" elif [ "$MultiABI" = "n" ] ; then @@ -1296,7 +1323,7 @@ cat project/jni/SettingsTemplate.mk | \ sed "s^APPLICATION_ADDITIONAL_CFLAGS :=.*^APPLICATION_ADDITIONAL_CFLAGS := $AppCflags^" | \ sed "s^APPLICATION_ADDITIONAL_LDFLAGS :=.*^APPLICATION_ADDITIONAL_LDFLAGS := $AppLdflags^" | \ sed "s^APPLICATION_OVERLAPS_SYSTEM_HEADERS :=.*^APPLICATION_OVERLAPS_SYSTEM_HEADERS := $AppOverlapsSystemHeaders^" | \ - sed "s^SDL_ADDITIONAL_CFLAGS :=.*^SDL_ADDITIONAL_CFLAGS := $RedefinedKeycodes $RedefinedKeycodesScreenKb $CompatibilityHacksPreventAudioChopping $CompatibilityHacksAppIgnoresAudioBufferSize $CompatibilityHacksSlowCompatibleEventQueue $CompatibilityHacksTouchscreenKeyboardSaveRestoreOpenGLState^" | \ + sed "s^SDL_ADDITIONAL_CFLAGS :=.*^SDL_ADDITIONAL_CFLAGS := $RedefinedKeycodes $RedefinedKeycodesScreenKb $RedefinedKeycodesGamepad $CompatibilityHacksPreventAudioChopping $CompatibilityHacksAppIgnoresAudioBufferSize $CompatibilityHacksSlowCompatibleEventQueue $CompatibilityHacksTouchscreenKeyboardSaveRestoreOpenGLState^" | \ sed "s^APPLICATION_SUBDIRS_BUILD :=.*^APPLICATION_SUBDIRS_BUILD := $AppSubdirsBuild^" | \ sed "s^APPLICATION_BUILD_EXCLUDE :=.*^APPLICATION_BUILD_EXCLUDE := $AppBuildExclude^" | \ sed "s^APPLICATION_CUSTOM_BUILD_SCRIPT :=.*^APPLICATION_CUSTOM_BUILD_SCRIPT := $CustomBuildScript^" | \ diff --git a/project/jni/application/openarena/AndroidAppSettings.cfg b/project/jni/application/openarena/AndroidAppSettings.cfg index 46eecee83..1919a9f6b 100644 --- a/project/jni/application/openarena/AndroidAppSettings.cfg +++ b/project/jni/application/openarena/AndroidAppSettings.cfg @@ -138,6 +138,10 @@ RedefinedKeysScreenKb="SLASH BACKSPACE TAB END LCTRL SPACE UNKNOWN UNKNOWN UNKNO # Names for on-screen keyboard keys, such as Fire, Jump, Run etc, separated by spaces, they are used in SDL config menu RedefinedKeysScreenKbNames="Change_weapon Sniper_view Show_scores Center_view Fire Jump" +# Redefine gamepad keys to SDL keysyms, button order is: +# A B X Y L1 R1 L2 R2 LThumb RThumb +RedefinedKeysGamepad="SLASH BACKSPACE TAB END SPACE LCTRL SPACE LCTRL SPACE RETURN" + # How long to show startup menu button, in msec, 0 to disable startup menu StartupMenuButtonTimeout=3000 diff --git a/project/jni/application/vcmi-r2387/AndroidAppSettings.cfg b/project/jni/application/vcmi-r2387/AndroidAppSettings.cfg index 6d3cc6b9f..9cf7afcec 100644 --- a/project/jni/application/vcmi-r2387/AndroidAppSettings.cfg +++ b/project/jni/application/vcmi-r2387/AndroidAppSettings.cfg @@ -1,55 +1,215 @@ # The application settings for Android libSDL port -AppSettingVersion=17 + +AppSettingVersion=19 + +# libSDL version to use (1.2 or 1.3, specify 1.3 for SDL2) LibSdlVersion=1.2 + +# Specify application name (e.x. My Application) AppName="VCMI" + +# Specify reversed site name of application (e.x. com.mysite.myapp) AppFullName=eu.vcmi + +# Specify screen orientation: (v)ertical/(p)ortrait or (h)orizontal/(l)andscape ScreenOrientation=h -InhibitSuspend=n + +# Do not allow device to sleep when the application is in foreground, set this for video players or apps which use accelerometer +InhibitSuspend=y + +# 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 +# If the URL in in the form ':dir/file.dat:http://URL/' it will be downloaded as binary BLOB to the application dir and not unzipped +# If the URL does not contain 'http://' it is treated as file from 'project/jni/application/src/AndroidData' dir - +# these files are put inside .apk package by build system +# Also please avoid 'https://' URLs, many Android devices do not have trust certificates and will fail to connect to SF.net over HTTPS AppDataDownloadUrl="!Data files|data1.zip^!Data files|data2.zip^!Data files|data3.zip^" + +# Video color depth - 16 BPP is the fastest and supported for all modes, 24 bpp is supported only +# with SwVideoMode=y, SDL_OPENGL mode supports everything. (16)/(24)/(32) VideoDepthBpp=16 + +# Enable OpenGL depth buffer (needed only for 3-d applications, small speed decrease) (y) or (n) NeedDepthBuffer=n + +# Enable OpenGL stencil buffer (needed only for 3-d applications, small speed decrease) (y) or (n) NeedStencilBuffer=n + +# Try to use GLES 2.x context - will revert to GLES 1.X if unsupported by device +# you need this option only if you're developing 3-d app (y) or (n) NeedGles2=n + +# Application uses software video buffer - you're calling SDL_SetVideoMode() without SDL_HWSURFACE and without SDL_OPENGL, +# this will allow small speed optimization. Enable this even when you're using SDL_HWSURFACE. (y) or (n) SwVideoMode=y + +# Application video output will be resized to fit into native device screen (y)/(n) SdlVideoResize=y + +# Application resizing will keep 4:3 aspect ratio, with black bars at sides (y)/(n) SdlVideoResizeKeepAspect=n + +# Application does not call SDL_Flip() or SDL_UpdateRects() appropriately, or draws from non-main thread - +# enabling the compatibility mode will force screen update every 100 milliseconds, which is laggy and inefficient (y) or (n) CompatibilityHacks=y + +# Application initializes SDL audio/video inside static constructors (which is bad, you won't be able to run ndk-gdb) (y)/(n) CompatibilityHacksStaticInit=n + +# On-screen Android soft text input emulates hardware keyboard, this will only work with Hackers Keyboard app (y)/(n) CompatibilityHacksTextInputEmulatesHwKeyboard=n + +# Hack for broken devices: prevent audio chopping, by sleeping a bit after pushing each audio chunk (y)/(n) CompatibilityHacksPreventAudioChopping=n + +# Hack for broken apps: application ignores audio buffer size returned by SDL (y)/(n) CompatibilityHacksAppIgnoresAudioBufferSize=n + +# Hack for VCMI: preload additional shared libraries before aplication start CompatibilityHacksAdditionalPreloadedSharedLibraries="vcmi" + +# 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=n + +# Save and restore OpenGL state when drawing on-screen keyboard for apps that use SDL_OPENGL +CompatibilityHacksTouchscreenKeyboardSaveRestoreOpenGLState= + +# Application uses mouse (y) or (n), this will show mouse emulation dialog to the user AppUsesMouse=y + +# Application needs two-button mouse, will also enable advanced point-and-click features (y) or (n) AppNeedsTwoButtonMouse=y + +# Show SDL mouse cursor, for applications that do not draw cursor at all (y) or (n) ShowMouseCursor=n + +# Force relative (laptop) mouse movement mode, useful when both on-screen keyboard and mouse are needed (y) or (n) ForceRelativeMouseMode=n + +# Application needs arrow keys (y) or (n), will show on-screen dpad/joystick (y) or (n) AppNeedsArrowKeys=n + +# Application needs text input (y) or (n), enables button for text input on screen AppNeedsTextInput=y + +# Application uses joystick (y) or (n), the on-screen DPAD will be used as joystick 0 axes 0-1 AppUsesJoystick=n + +# Application uses second on-screen joystick, as SDL joystick 0 axes 2-3 (y)/(n) +AppUsesSecondJoystick=n + +# Application uses accelerometer (y) or (n), the accelerometer will be used as joystick 1 axes 0-1 and 5-7 AppUsesAccelerometer=n + +# Application uses gyroscope (y) or (n), the gyroscope will be used as joystick 1 axes 2-4 +AppUsesGyroscope=n + +# Application uses multitouch (y) or (n), multitouch events are passed as SDL_JOYBALLMOTION events for the joystick 0 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=n + +# 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 +# rigth after SDL_Flip(), if (n) then SDL_Flip() will block till app in background (y) or (n) +# This option is reported to be buggy, sometimes failing to restore video state NonBlockingSwapBuffers=n + +# Redefine common hardware keys to SDL keysyms +# BACK hardware key is available on all devices, MENU is available on pre-ICS devices, other keys may be absent +# 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="LALT RETURN NO_REMAP NO_REMAP E" + +# Number of virtual keyboard keys (currently 6 is maximum) AppTouchscreenKeyboardKeysAmount=0 + +# Number of virtual keyboard keys that support autofire (currently 2 is maximum) AppTouchscreenKeyboardKeysAmountAutoFire=0 + +# Redefine on-screen keyboard keys to SDL keysyms - 6 keyboard keys + 4 multitouch gestures (zoom in/out and rotate left/right) RedefinedKeysScreenKb="LALT RETURN KP_PLUS KP_MINUS SPACE DELETE KP_PLUS KP_MINUS 1 2" + +# Names for on-screen keyboard keys, such as Fire, Jump, Run etc, separated by spaces, they are used in SDL config menu +RedefinedKeysScreenKbNames="LALT RETURN KP_PLUS KP_MINUS SPACE DELETE KP_PLUS KP_MINUS 1 2" + +# How long to show startup menu button, in msec, 0 to disable startup menu StartupMenuButtonTimeout=3000 -HiddenMenuOptions='OptionalDownloadConfig' + +# Menu items to hide from startup menu, available menu items: +# SettingsMenu.OkButton SettingsMenu.DummyMenu SettingsMenu.MainMenu SettingsMenuMisc.DownloadConfig SettingsMenuMisc.OptionalDownloadConfig SettingsMenuMisc.AudioConfig SettingsMenuMisc.VideoSettingsConfig SettingsMenuMisc.ShowReadme SettingsMenuMisc.GyroscopeCalibration SettingsMenuMisc.ResetToDefaultsConfig SettingsMenuMouse.MouseConfigMainMenu SettingsMenuMouse.DisplaySizeConfig SettingsMenuMouse.LeftClickConfig SettingsMenuMouse.RightClickConfig SettingsMenuMouse.AdditionalMouseConfig SettingsMenuMouse.JoystickMouseConfig SettingsMenuMouse.TouchPressureMeasurementTool SettingsMenuMouse.CalibrateTouchscreenMenu SettingsMenuKeyboard.KeyboardConfigMainMenu SettingsMenuKeyboard.ScreenKeyboardSizeConfig SettingsMenuKeyboard.ScreenKeyboardDrawSizeConfig SettingsMenuKeyboard.ScreenKeyboardThemeConfig SettingsMenuKeyboard.ScreenKeyboardTransparencyConfig SettingsMenuKeyboard.RemapHwKeysConfig SettingsMenuKeyboard.RemapScreenKbConfig SettingsMenuKeyboard.ScreenGesturesConfig SettingsMenuKeyboard.CustomizeScreenKbLayout +HiddenMenuOptions='SettingsMenuMisc.OptionalDownloadConfig' + +# Menu items to show at startup - this is Java code snippet, leave empty for default +# new SettingsMenuMisc.ShowReadme(), (AppUsesMouse \&\& \! ForceRelativeMouseMode \? new SettingsMenuMouse.DisplaySizeConfig(true) : new SettingsMenu.DummyMenu()), new SettingsMenuMisc.OptionalDownloadConfig(true), new SettingsMenuMisc.GyroscopeCalibration() +# Available menu items: +# SettingsMenu.OkButton SettingsMenu.DummyMenu SettingsMenu.MainMenu SettingsMenuMisc.DownloadConfig SettingsMenuMisc.OptionalDownloadConfig SettingsMenuMisc.AudioConfig SettingsMenuMisc.VideoSettingsConfig SettingsMenuMisc.ShowReadme SettingsMenuMisc.GyroscopeCalibration SettingsMenuMisc.ResetToDefaultsConfig SettingsMenuMouse.MouseConfigMainMenu SettingsMenuMouse.DisplaySizeConfig SettingsMenuMouse.LeftClickConfig SettingsMenuMouse.RightClickConfig SettingsMenuMouse.AdditionalMouseConfig SettingsMenuMouse.JoystickMouseConfig SettingsMenuMouse.TouchPressureMeasurementTool SettingsMenuMouse.CalibrateTouchscreenMenu SettingsMenuKeyboard.KeyboardConfigMainMenu SettingsMenuKeyboard.ScreenKeyboardSizeConfig SettingsMenuKeyboard.ScreenKeyboardDrawSizeConfig SettingsMenuKeyboard.ScreenKeyboardThemeConfig SettingsMenuKeyboard.ScreenKeyboardTransparencyConfig SettingsMenuKeyboard.RemapHwKeysConfig SettingsMenuKeyboard.RemapScreenKbConfig SettingsMenuKeyboard.ScreenGesturesConfig SettingsMenuKeyboard.CustomizeScreenKbLayout FirstStartMenuOptions='' -MultiABI=y -AppMinimumRAM=64 -AppVersionCode=08605 -AppVersionName="0.86.05" + +# Enable multi-ABI binary, with hardware FPU support - it will also work on old devices, +# but .apk size is 2x bigger (y) / (n) / (x86) / (all) +MultiABI=armeabi-v7a + +# Minimum amount of RAM application requires, in Mb, SDL will print warning to user if it's lower +AppMinimumRAM=128 + +# Application version code (integer) +AppVersionCode=08606 + +# Application user-visible version name (string) +AppVersionName="0.86.06" + +# Reset SDL config when updating application to the new version (y) / (n) ResetSdlConfigForThisVersion=y + +# Delete application data files when upgrading (specify file/dir paths separated by spaces) DeleteFilesOnUpgrade="libsdl-DownloadFinished-0.flag libsdl-DownloadFinished-1.flag libsdl-DownloadFinished-2.flag libsdl-DownloadFinished-3.flag libsdl-DownloadFinished-4.flag libsdl-DownloadFinished-5.flag" + +# 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="mad sdl_mixer sdl_image sdl_ttf avutil avcore avcodec avformat swscale boost_program_options boost_filesystem boost_iostreams boost_system boost_thread android" + +# Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n) CustomBuildScript=y + +# Aditional CFLAGS for application AppCflags='' + +# Additional LDFLAGS for application AppLdflags='' + +# If application has headers with the same name as system headers, this option tries to fix compiler flags to make it compilable +AppOverlapsSystemHeaders= + +# Build only following subdirs (empty will build all dirs, ignored with custom script) AppSubdirsBuild='' + +# Exclude these files from build +AppBuildExclude='' + +# Application command line parameters, including app name as 0-th param AppCmdline='' + +# Here you may type readme text, which will be shown during startup. Format is: +# Text in English, use \\\\n to separate lines^de:Text in Deutsch^ru:Text in Russian, and so on (that's four backslashes, nice isn't it?) ReadmeText='^You may press "Home" now - the data will be downloaded in background' + +# Screen size is used by Google Play to prevent an app to be installed on devices with smaller screens +# Minimum screen size that application supports: (s)mall / (m)edium / (l)arge MinimumScreenSize=s + +# Your AdMob Publisher ID, (n) if you don't want advertisements AdmobPublisherId=n + +# Your AdMob test device ID, to receive a test ad AdmobTestDeviceId= + +# Your AdMob banner size (BANNER/IAB_BANNER/IAB_LEADERBOARD/IAB_MRECT/IAB_WIDE_SKYSCRAPER/SMART_BANNER) AdmobBannerSize= + diff --git a/project/jni/application/vcmi-r2387/Makefile b/project/jni/application/vcmi-r2387/Makefile index 9a8cd2c02..8bb83a906 100644 --- a/project/jni/application/vcmi-r2387/Makefile +++ b/project/jni/application/vcmi-r2387/Makefile @@ -1,13 +1,9 @@ -ifeq ($(ARCH),) -ARCH:=armeabi -endif - $(shell mkdir -p $(ARCH)/AI debug/$(ARCH)/AI $(ARCH)/Scripting debug/$(ARCH)/Scripting \ $(ARCH)/out/vcmi/lib $(ARCH)/out/vcmi/server $(ARCH)/out/vcmi/AI/StupidAI \ $(ARCH)/out/vcmi/AI/GeniusAI $(ARCH)/out/vcmi/client $(ARCH)/out/vcmi/Scripting/ERM) -LOCAL_PATH:=$(shell dirname $0) -LOCAL_PATH:=`cd $LOCAL_PATH && pwd` +GCC_VERSION:=4.8 +ARCH:=armeabi-v7a SOURCES_LIB:=$(wildcard vcmi/lib/*.cpp vcmi/CConsoleHandler.cpp vcmi/CThreadHelper.cpp) OBJS_LIB:=$(patsubst %.cpp, $(ARCH)/out/%.o, $(SOURCES_LIB)) @@ -29,12 +25,12 @@ OBJS_CLIENT:=$(patsubst %.cpp, $(ARCH)/out/%.o, $(SOURCES_CLIENT)) all: AndroidData/binaries-$(ARCH).zip libapplication-$(ARCH).so -AndroidData/binaries-$(ARCH).zip: $(ARCH)/vcmiserver $(ARCH)/AI/libGeniusAI.so $(ARCH)/AI/libStupidAI.so $(ARCH)/Scripting/libvcmiERM.so # $(ARCH)/libvcmi.so +AndroidData/binaries-$(ARCH).zip: $(ARCH)/vcmiserver $(ARCH)/AI/libGeniusAI.so $(ARCH)/AI/libStupidAI.so $(ARCH)/Scripting/libvcmiERM.so $(ARCH)/libvcmi.so rm -f $@ cd $(ARCH) && zip -r ../$@ $(foreach F, $^, $(patsubst $(ARCH)/%,%,$(F))) $(OBJS_SERVER) $(OBJS_LIB) $(OBJS_GENIUSAI) $(OBJS_STUPIDAI) $(OBJS_CLIENT) $(OBJS_ERM): $(ARCH)/out/%.o: %.cpp - ../setEnvironment-$(ARCH).sh sh -c \ + env GCCVER=$(GCC_VERSION) ../setEnvironment-$(ARCH).sh sh -c \ "\$$CXX \ -c \$$CXXFLAGS -Ivcmi -Ivcmi/lib \ -DDATA_DIR=\\\"/sdcard/Android/data/eu.vcmi/files\\\" \ @@ -47,10 +43,13 @@ $(OBJS_SERVER) $(OBJS_LIB) $(OBJS_GENIUSAI) $(OBJS_STUPIDAI) $(OBJS_CLIENT) $(OB #ALLOW_UNRESOLVED_SYMBOLS=1 LINK_LIB= \ - env NO_SHARED_LIBS=1 SHARED_LIBRARY_NAME=`basename $@` ../setEnvironment-$(ARCH).sh sh -c \ - "echo SHARED_LIBRARY_NAME \$$SHARED_LIBRARY_NAME && \$$CXX \ + env GCCVER=$(GCC_VERSION) NO_SHARED_LIBS=1 SHARED_LIBRARY_NAME=`basename $@` \ + ../setEnvironment-$(ARCH).sh sh -c \ + "\$$CXX \ -Wl,--whole-archive $^ -Wl,--no-whole-archive -o $@ \ \$$LDFLAGS -L$(ARCH) \ + -Wl,--undefined=__gnu_thumb1_case_uqi -Wl,--undefined=__gnu_thumb1_case_uhi \ + -Wl,--undefined=__clzsi2 -lgcc \ -lboost_filesystem -lboost_iostreams -lboost_system -lboost_thread && \ cp $@ debug/$@ && \ \$$STRIP --strip-unneeded $@" @@ -62,7 +61,7 @@ $(ARCH)/libvcmi.so: $(OBJS_LIB) $(LINK_LIB) -lvcmi: $(ARCH)/libvcmi.so - cp -f $^ ../../../libs/$^ +# cp -f $^ ../../../libs/$^ .PHONY: -lvcmi @@ -76,7 +75,7 @@ $(ARCH)/Scripting/libvcmiERM.so: $(OBJS_ERM) -lvcmi $(LINK_LIB) $(ARCH)/vcmiserver: $(OBJS_SERVER) -lvcmi - env BUILD_EXECUTABLE=1 NO_SHARED_LIBS=1 ../setEnvironment-$(ARCH).sh sh -c \ + env GCCVER=$(GCC_VERSION) BUILD_EXECUTABLE=1 NO_SHARED_LIBS=1 ../setEnvironment-$(ARCH).sh sh -c \ "\$$CXX \ -Wl,--whole-archive $^ -Wl,--no-whole-archive -o $@ \ \$$LDFLAGS -L$(ARCH) -Wl,-rpath,/data/data/eu.vcmi/lib \ @@ -85,7 +84,7 @@ $(ARCH)/vcmiserver: $(OBJS_SERVER) -lvcmi \$$STRIP --strip-unneeded $@" libapplication-$(ARCH).so: $(OBJS_CLIENT) -lvcmi - env ../setEnvironment-$(ARCH).sh sh -c \ + env GCCVER=$(GCC_VERSION) ../setEnvironment-$(ARCH).sh sh -c \ "\$$CXX \ -Wl,--whole-archive $^ -Wl,--no-whole-archive -o $@ \ \$$LDFLAGS -L$(ARCH) \ diff --git a/project/jni/application/vcmi-r2387/vcmi b/project/jni/application/vcmi-r2387/vcmi deleted file mode 120000 index bb55c5f92..000000000 --- a/project/jni/application/vcmi-r2387/vcmi +++ /dev/null @@ -1 +0,0 @@ -../../../../../vcmi \ No newline at end of file diff --git a/project/jni/application/vcmi-r2387/vcmi-android.diff b/project/jni/application/vcmi-r2387/vcmi-android.diff index c0a866d9b..31da08814 100644 --- a/project/jni/application/vcmi-r2387/vcmi-android.diff +++ b/project/jni/application/vcmi-r2387/vcmi-android.diff @@ -1,3 +1,143 @@ +Index: server/CGameHandler.cpp +=================================================================== +--- server/CGameHandler.cpp (revision 2387) ++++ server/CGameHandler.cpp (working copy) +@@ -638,6 +638,7 @@ + (packType != typeList.getTypeID() || !isAllowedArrangePack((ArrangeStacks*)pack)) && // for dialogs like garrison + states[getCurrentPlayer()].queries.size()) + { ++ tlog0<<__FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << std::endl; + complain("Answer the query before attempting any further actions!"); + PackageApplied applied; + applied.result = false; +@@ -650,6 +651,7 @@ + else if(apply) + { + bool result = apply->applyOnGH(this,&c,pack); ++ tlog0<<__FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << std::endl; + tlog5 << "Message successfully applied (result=" << result << ")!\n"; + + //send confirmation that we've applied the package +@@ -1833,7 +1835,7 @@ + iw.player = h1->tempOwner; + iw.components.push_back(Component(Component::SEC_SKILL, 18, ScholarLevel, 0)); + +- iw.text.addTxt(MetaString::GENERAL_TXT, 139);//"%s, who has studied magic extensively, ++ iw.text.addTxt(MetaString::GENERAL_TXT, 139);//%s, who has studied magic extensively, + iw.text.addReplacement(h1->name); + + if (cs2.spells.size())//if found new spell - apply +Index: server/CVCMIServer.cpp +=================================================================== +--- server/CVCMIServer.cpp (revision 2387) ++++ server/CVCMIServer.cpp (working copy) +@@ -29,7 +29,7 @@ + using namespace boost; + using namespace boost::asio; + using namespace boost::asio::ip; +-namespace intpr = boost::interprocess; ++//namespace intpr = boost::interprocess; + bool end2 = false; + int port = 3030; + VCMIDirs GVCMIDirs; +@@ -379,6 +379,7 @@ + + void CVCMIServer::start() + { ++ /* + ServerReady *sr = NULL; + intpr::mapped_region *mr; + try +@@ -395,13 +396,17 @@ + mr = new intpr::mapped_region(smo,intpr::read_write); + sr = new(mr->get_address())ServerReady(); + } ++ */ ++ notifyServerReady(); + + boost::system::error_code error; + tlog0<<"Listening for connections at port " << acceptor->local_endpoint().port() << std::endl; + tcp::socket * s = new tcp::socket(acceptor->get_io_service()); + boost::thread acc(boost::bind(vaccept,acceptor,s,&error)); ++ /* + sr->setToTrueAndNotify(); + delete mr; ++ */ + + acc.join(); + if (error) +Index: server/stdafx.h +=================================================================== +--- server/stdafx.h (revision 2387) ++++ server/stdafx.h (working copy) +@@ -15,8 +15,8 @@ + #include "../global.h" + + #include +-#include +-#include ++//#include ++//#include + #include + #include + #include +Index: global.h +=================================================================== +--- global.h (revision 2387) ++++ global.h (working copy) +@@ -4,6 +4,7 @@ + #include + #include + #include //std::find ++#include //memcpy + #include //std::find + #include + #include +@@ -15,7 +16,7 @@ + #include + #endif + //filesystem version 3 causes problems (and it's default as of boost 1.46) +-#define BOOST_FILESYSTEM_VERSION 2 ++//#define BOOST_FILESYSTEM_VERSION 2 + typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) + typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) + typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +@@ -725,29 +726,21 @@ + } + + +-#if defined(linux) && defined(sparc) +-/* SPARC does not support unaligned memory access. Let gcc know when +- * to emit the right code. */ +-struct unaligned_Uint16 { ui16 val __attribute__(( packed )); }; +-struct unaligned_Uint32 { ui32 val __attribute__(( packed )); }; + + static inline ui16 read_unaligned_u16(const void *p) + { +- const struct unaligned_Uint16 *v = (const struct unaligned_Uint16 *)p; +- return v->val; ++ ui16 out; ++ memcpy(&out, p, sizeof(out)); ++ return out; + } + + static inline ui32 read_unaligned_u32(const void *p) + { +- const struct unaligned_Uint32 *v = (const struct unaligned_Uint32 *)p; +- return v->val; ++ ui32 out; ++ memcpy(&out, p, sizeof(out)); ++ return out; + } + +-#else +-#define read_unaligned_u16(p) (* reinterpret_cast(p)) +-#define read_unaligned_u32(p) (* reinterpret_cast(p)) +-#endif +- + //for explicit overrides + #ifdef _MSC_VER + #define OVERRIDE override Index: Scripting/ERM/ERMParser.cpp =================================================================== --- Scripting/ERM/ERMParser.cpp (revision 2387) @@ -176,6 +316,21 @@ Index: lib/CLodHandler.cpp } return NULL; } +Index: lib/Connection.h +=================================================================== +--- lib/Connection.h (revision 2387) ++++ lib/Connection.h (working copy) +@@ -82,7 +82,9 @@ + { + bool operator()(const std::type_info *a, const std::type_info *b) const + { +- return a->before(*b); ++ // Comparing pointers is bad bad practice, because type_info pointers to the same types ++ // are different inside shared library and the executable that links to that library ++ return strcmp(a->name(), b->name()) > 0; + } + }; + Index: lib/CGameInterface.cpp =================================================================== --- lib/CGameInterface.cpp (revision 2387) @@ -212,626 +367,57 @@ Index: lib/CGameInterface.cpp if(!ret) tlog1 << "Cannot get AI!\n"; -Index: lib/Connection.h +Index: client/Graphics.cpp =================================================================== ---- lib/Connection.h (revision 2387) -+++ lib/Connection.h (working copy) -@@ -82,7 +82,9 @@ - { - bool operator()(const std::type_info *a, const std::type_info *b) const - { -- return a->before(*b); -+ // Comparing pointers is bad bad practice, because type_info pointers to the same types -+ // are different inside shared library and the executable that links to that library -+ return strcmp(a->name(), b->name()) > 0; - } - }; - -Index: client/CCreatureAnimation.cpp -=================================================================== ---- client/CCreatureAnimation.cpp (revision 2387) -+++ client/CCreatureAnimation.cpp (working copy) -@@ -37,15 +37,23 @@ - } - } - -+#define CHECK_LOD_MEM_BLOCK_SIZE1(S, FF, F, L) { \ -+ if( lodLength < (S) ) \ -+ tlog1<<"ERROR in " << FF << " " << F << ":" << L << ": reading past the end of LOD mem block by " << \ -+ (S) - lodLength << " bytes, fname " << fname << " size " << lodLength << std::endl; } -+#define CHECK_LOD_MEM_BLOCK_SIZE(S) CHECK_LOD_MEM_BLOCK_SIZE1(S, __FUNCTION__, __FILE__, __LINE__) -+ - CCreatureAnimation::CCreatureAnimation(std::string name) : internalFrame(0), once(false) - { -- FDef = spriteh->giveFile(name, FILE_ANIMATION); //load main file -+ FDef = spriteh->giveFile(name, FILE_ANIMATION, &lodLength); //load main file -+ fname = name; - - //init anim data - int i,j, totalInBlock; - - defName=name; - i = 0; -+ CHECK_LOD_MEM_BLOCK_SIZE(i+0x310); - DEFType = readNormalNr<4>(i,FDef); i+=4; - fullWidth = readNormalNr<4>(i,FDef); i+=4; - fullHeight = readNormalNr<4>(i,FDef); i+=4; -@@ -64,6 +72,7 @@ - totalEntries=0; - for (int z=0; z frameIDs; - int group = readNormalNr<4>(i,FDef); i+=4; //block ID - totalInBlock = readNormalNr<4>(i,FDef); i+=4; -@@ -76,6 +85,7 @@ - /*int unknown2 = readNormalNr<4>(i,FDef);*/ i+=4; //TODO use me - /*int unknown3 = readNormalNr<4>(i,FDef);*/ i+=4; //TODO use me - i+=13*totalInBlock; //ommiting names -+ CHECK_LOD_MEM_BLOCK_SIZE(i+totalInBlock*4); - for (j=0; j(i,FDef); i+=4; -@@ -173,6 +183,7 @@ - unsigned char SegmentType, SegmentLength; - - i = BaseOffset = SEntries[SIndex].offset; -+ CHECK_LOD_MEM_BLOCK_SIZE(i+32); - /*int prSize = readNormalNr<4>(i, FDef);*/ i += 4; //TODO use me - int defType2 = readNormalNr<4>(i, FDef); i += 4; - FullWidth = readNormalNr<4>(i, FDef); i += 4; -@@ -194,11 +205,12 @@ - { - ftcp += FullWidth * TopMargin; - } -- int *RLEntries = (int*)(FDef + BaseOffset); -+ unsigned char *RLEntries = (FDef + BaseOffset); - BaseOffset += sizeof(int) * SpriteHeight; - for (int i = 0; i < SpriteHeight; i++) - { -- BaseOffset = BaseOffsetor + RLEntries[i]; -+ CHECK_LOD_MEM_BLOCK_SIZE(RLEntries+i*4-FDef); -+ BaseOffset = BaseOffsetor + read_unaligned_u32(RLEntries+i*4); - if (LeftMargin > 0) - { - ftcp += LeftMargin; -@@ -213,6 +225,7 @@ - - do - { -+ CHECK_LOD_MEM_BLOCK_SIZE(BaseOffset+2); - SegmentType = FDef[BaseOffset++]; - SegmentLength = FDef[BaseOffset++]; - -@@ -227,6 +240,8 @@ - { - if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB)) - { -+ if(SegmentType == 0xff) -+ CHECK_LOD_MEM_BLOCK_SIZE(BaseOffset+k+1); - const ui8 colorNr = SegmentType == 0xff ? FDef[BaseOffset+k] : SegmentType; - putPixel(dest, xB, yB, palette[colorNr], colorNr, yellowBorder, blueBorder, aCountMod); - } -Index: client/CSndHandler.cpp -=================================================================== ---- client/CSndHandler.cpp (revision 2387) -+++ client/CSndHandler.cpp (working copy) -@@ -151,16 +151,17 @@ +--- client/Graphics.cpp (revision 2387) ++++ client/Graphics.cpp (working copy) +@@ -315,8 +315,15 @@ + tasks += GET_SURFACE(backgroundsm[id], b["bg120"].String()); } - const char *data = mfile->data(); -- unsigned int numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]); -- struct soundEntry *se = (struct soundEntry *)&data[4]; -+ unsigned int numFiles = SDL_SwapLE32(read_unaligned_u32(&data[0])); -+ struct soundEntry se; ++#ifdef ANDROID ++ // For debug make it single-threaded ++ for(int i=0;iourImages.size(); ++y) { - Entry entry; -+ memcpy(&se, &data[4+i*sizeof(se)], sizeof(se)); - -- entry.name = se->filename; -- entry.offset = SDL_SwapLE32(se->offset); -- entry.size = SDL_SwapLE32(se->size); -+ entry.name = se.filename; -+ entry.offset = SDL_SwapLE32(se.offset); -+ entry.size = SDL_SwapLE32(se.size); - entry.data = mfile->data() + entry.offset; - - entries.push_back(entry); -@@ -186,24 +187,26 @@ - return; +@@ -508,13 +515,20 @@ + pr[3].first = &Graphics::flags4; + pr[3].second+=("AF00.DEF"),("AF01.DEF"),("AF02.DEF"),("AF03.DEF"),("AF04.DEF"), + ("AF05.DEF"),("AF06.DEF"),("AF07.DEF"); ++#ifdef ANDROID ++ // We ain't no need any filthy multithreading ++ for(int g=0; g<4; g++) ++ { ++ loadHeroFlags(pr[g],true); ++ } ++#else + boost::thread_group grupa; + for(int g=3; g>=0; --g) + { + grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[g]),true)); } - const unsigned char *data = (const unsigned char *)mfile->data(); -- unsigned int numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]); -- struct videoEntry *ve = (struct videoEntry *)&data[4]; -+ unsigned int numFiles = SDL_SwapLE32(read_unaligned_u32(&data[0])); -+ struct videoEntry ve; - -- for (unsigned int i=0; ifilename; -- entry.offset = SDL_SwapLE32(ve->offset); -+ entry.name = ve.filename; -+ entry.offset = SDL_SwapLE32(ve.offset); - entry.name.erase(entry.name.find_last_of('.')); - - // There is no size, so check where the next file is - if (i == numFiles - 1) { - entry.size = mfile->size() - entry.offset; - } else { -- struct videoEntry *ve_next = ve+1; -+ struct videoEntry ve_next; -+ memcpy(&ve_next, &data[4+(i+1)*sizeof(ve)], sizeof(ve)); - -- entry.size = SDL_SwapLE32(ve_next->offset) - entry.offset; -+ entry.size = SDL_SwapLE32(ve_next.offset) - entry.offset; - } - entry.data = mfile->data() + entry.offset; - -Index: client/CAnimation.cpp -=================================================================== ---- client/CAnimation.cpp (revision 2387) -+++ client/CAnimation.cpp (working copy) -@@ -46,6 +46,8 @@ - ~SDLImageLoader(); - }; - -+// It's buggy, disabled for Android build -+/* - class CompImageLoader + grupa.join_all(); +- tlog0 << "Loading and transforming heroes' flags: "<giveFile(Name, FILE_ANIMATION); -+ fname = Name; -+ data = spriteh->giveFile(Name, FILE_ANIMATION, &lodLength); - palette = new SDL_Color[256]; - int it = 0; - -+ CHECK_LOD_MEM_BLOCK_SIZE(it+4); - unsigned int type = readNormalNr(data, it); - it+=4; - //int width = readNormalNr(data, it); it+=4;//not used - //int height = readNormalNr(data, it); it+=4; - it+=8; -+ CHECK_LOD_MEM_BLOCK_SIZE(it+4); - unsigned int totalBlocks = readNormalNr(data, it); - it+=4; - -@@ -117,6 +129,7 @@ - - for (unsigned int i=0; isecond[frame]; - -- const SSpriteDef sd = * reinterpret_cast(FDef); -+ SSpriteDef sd; -+ CHECK_LOD_MEM_BLOCK_SIZE((FDef-data)+sizeof(sd)); -+ memcpy(&sd, FDef, sizeof(sd)); - SSpriteDef sprite; - - //sprite.size = SDL_SwapLE32(sd.size);//unused -@@ -170,6 +186,7 @@ - //pixel data is not compressed, copy data to surface - for (unsigned int i=0; i(FDef+currentOffset); -+ const unsigned char * RWEntriesLoc = FDef+currentOffset; - currentOffset += sizeof(ui32) * sprite.height; - - for (unsigned int i=0; isurf->pixels + image->surf->h*image->surf->pitch >= position + size ) +- int magic = *(const int*)hlp; ++ int magic = read_unaligned_u32(hlp); + if(len < 10000 || (magic != 589598 && magic != 589599)) { - memcpy((void *)position, data, size); - position += size; -@@ -323,7 +357,7 @@ - - inline void SDLImageLoader::Load(size_t size, ui8 color) - { -- if (size) -+ if (size && (ui8 *)image->surf->pixels + image->surf->h*image->surf->pitch >= position + size) - { - memset((void *)position, color, size); - position += size; -@@ -345,6 +379,7 @@ - - //////////////////////////////////////////////////////////////////////////////// - -+/* - CompImageLoader::CompImageLoader(CompImage * Img): - image(Img), - position(NULL), -@@ -518,6 +553,7 @@ - image->surf = newPtr; - } - -+*/ - /************************************************************************* - * Classes for images, support loading from file and drawing on surface * - *************************************************************************/ -@@ -625,6 +661,8 @@ - SDL_FreeSurface(surf); - } - -+// Buggy, disabled for Android -+/* - CompImage::CompImage(const CDefFile *data, size_t frame, size_t group): - surf(NULL), - line(NULL), -@@ -845,6 +883,7 @@ - delete [] line; - delete [] palette; - } -+*/ - - /************************************************************************* - * CAnimation for animations handling, can load part of file if needed * -@@ -889,9 +928,11 @@ - //try to get image from def - if (source[group][frame].getType() == JsonNode::DATA_NULL) - { -+ /* - if (compressed) - images[group][frame] = new CompImage(file, frame, group); - else -+ */ - images[group][frame] = new SDLImage(file, frame, group); - } - else //load from separate file -Index: client/Client.h -=================================================================== ---- client/Client.h (revision 2387) -+++ client/Client.h (working copy) -@@ -43,7 +43,7 @@ - public: - timeHandler th; - boost::thread *serverThread; //thread that called system to run server -- SharedMem *shared; //interprocess memory (for waiting for server) -+ //SharedMem *shared; //interprocess memory (for waiting for server) - bool verbose; //whether to print log msgs - std::string port; //port number in text form - -Index: client/SDL_Extensions.cpp -=================================================================== ---- client/SDL_Extensions.cpp (revision 2387) -+++ client/SDL_Extensions.cpp (working copy) -@@ -119,8 +119,8 @@ - if(incrementPtr == -1) - ptr -= 2; - -- Uint16 * const px = (Uint16*)ptr; -- *px = (B>>3) + ((G>>2) << 5) + ((R>>3) << 11); //drop least significant bits of 24 bpp encoded color -+ Uint16 px = (B>>3) + ((G>>2) << 5) + ((R>>3) << 11); //drop least significant bits of 24 bpp encoded color -+ memcpy(ptr, &px, sizeof(px)); - - if(incrementPtr == 1) - ptr += 2; //bpp -@@ -150,9 +150,9 @@ - const int rmask = 0xF800, gmask = 0x7E0, bmask = 0x1F; - const int rshift = 11, gshift = 5, bshift = 0; - -- const Uint8 r5 = (*((Uint16 *)ptr) & rmask) >> rshift, -- b5 = (*((Uint16 *)ptr) & bmask) >> bshift, -- g5 = (*((Uint16 *)ptr) & gmask) >> gshift; -+ const Uint8 r5 = (read_unaligned_u16(ptr) & rmask) >> rshift, -+ b5 = (read_unaligned_u16(ptr) & bmask) >> bshift, -+ g5 = (read_unaligned_u16(ptr) & gmask) >> gshift; - - const Uint32 r8 = (r5 << (8 - rbit)) | (r5 >> (2*rbit - 8)), - g8 = (g5 << (8 - gbit)) | (g5 >> (2*gbit - 8)), -@@ -649,7 +649,7 @@ - return *p; - - case 2: -- return *(Uint16 *)p; -+ return read_unaligned_u16(p); - - case 3: - /* -@@ -661,7 +661,7 @@ - //#endif - - case 4: -- return *(Uint32 *)p; -+ return read_unaligned_u32(p); - - default: - return 0; // shouldn't happen, but avoids warnings -Index: client/CAnimation.h -=================================================================== ---- client/CAnimation.h (revision 2387) -+++ client/CAnimation.h (working copy) -@@ -47,6 +47,8 @@ - std::map > offset; - - unsigned char * data; -+ int lodLength; -+ std::string fname; - SDL_Color * palette; - - public: -@@ -125,6 +127,8 @@ - * 2nd byte = size of segment - * raw data (if any) - */ -+// Buggy, disabled for Android -+/* - class CompImage : public IImage - { - //x,y - margins, w,h - sprite size -@@ -158,8 +162,8 @@ - - friend class CompImageLoader; - }; -+*/ - -- - /// Class for handling animation - class CAnimation - { -Index: client/GUIBase.cpp -=================================================================== ---- client/GUIBase.cpp (revision 2387) -+++ client/GUIBase.cpp (working copy) -@@ -11,6 +11,7 @@ - #include "../CThreadHelper.h" - #include "CConfigHandler.h" - #include -+ - - /* - * GUIBase.cpp, part of VCMI engine -@@ -365,6 +366,26 @@ - } - } HANDLE_EXCEPTION - } -+ -+void CGuiHandler::loopInitFromMainThread() -+{ -+ setThreadName(-1, "CGuiHandler::run"); -+ CCS->curh->centerCursor(); -+ mainFPSmng->init(); // resets internal clock, needed for FPS manager -+} -+ -+bool CGuiHandler::loopFromMainThread() -+{ -+ if(terminate) -+ return false; -+ if(curInt) -+ curInt->update(); // calls a update and drawing process of the loaded game interface object at the moment -+ -+ mainFPSmng->framerateDelay(); // holds a constant FPS -+ return true; -+} -+ -+ - - CGuiHandler::CGuiHandler() - :lastClick(-500, -500) -Index: client/CCreatureAnimation.h -=================================================================== ---- client/CCreatureAnimation.h (revision 2387) -+++ client/CCreatureAnimation.h (working copy) -@@ -66,6 +66,8 @@ - int curFrame, internalFrame; //number of currently displayed frame - unsigned int frames; //number of frames - CCreatureAnim::EAnimType type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) -+ int lodLength; -+ std::string fname; - - template - int nextFrameT(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next -Index: client/Client.cpp -=================================================================== ---- client/Client.cpp (revision 2387) -+++ client/Client.cpp (working copy) -@@ -41,7 +41,7 @@ - #include "../lib/RegisterTypes.cpp" - - extern std::string NAME; --namespace intpr = boost::interprocess; -+//namespace intpr = boost::interprocess; - - /* - * Client.cpp, part of VCMI engine -@@ -476,9 +476,9 @@ - - void CClient::handlePack( CPack * pack ) - { -- CBaseForCLApply *apply = applier->apps[typeList.getTypeID(pack)]; //find the applier -- if(apply) -+ if(applier->apps.find(typeList.getTypeID(pack)) != applier->apps.end()) - { -+ CBaseForCLApply *apply = applier->apps[typeList.getTypeID(pack)]; //find the applier - apply->applyOnClBefore(this,pack); - tlog5 << "\tMade first apply on cl\n"; - gs->apply(pack); -@@ -639,18 +639,22 @@ - startServer(); - - th.update(); -+ /* - intpr::scoped_lock slock(shared->sr->mutex); - while(!shared->sr->ready) - { - shared->sr->cond.wait(slock); - } -+ */ -+ tlog0 << "Waiting for server..." << std::endl; -+ waitServerReady(); - if(verbose) - tlog0 << "Waiting for server: " << th.getDif() << std::endl; - } - - CConnection * CServerHandler::connectToServer() - { -- if(!shared->sr->ready) -+ if(!serverThread) - waitForServer(); - - th.update(); -@@ -665,27 +669,31 @@ - CServerHandler::CServerHandler(bool runServer /*= false*/) - { - serverThread = NULL; -- shared = NULL; -+ //shared = NULL; - port = boost::lexical_cast(conf.cc.port); - verbose = false; - -+ /* - boost::interprocess::shared_memory_object::remove("vcmi_memory"); //if the application has previously crashed, the memory may not have been removed. to avoid problems - try to destroy it - try - { - shared = new SharedMem(); - } HANDLE_EXCEPTIONC(tlog1 << "Cannot open interprocess memory: ";) -+ */ - } - - CServerHandler::~CServerHandler() - { -- delete shared; -+ //delete shared; - delete serverThread; //detaches, not kills thread - } - - void CServerHandler::callServer() - { -+ clearServerReady(); - setThreadName(-1, "CServerHandler::callServer"); -- std::string comm = std::string(BIN_DIR PATH_SEPARATOR SERVER_NAME " ") + port + " > server_log.txt"; -+ std::string comm = std::string("LD_LIBRARY_PATH=" LIB_DIR "/../lib " BIN_DIR PATH_SEPARATOR SERVER_NAME " ") + port + " > server_log.txt"; -+ tlog0 << "Invoking VCMI server : " << comm << std::endl; - std::system(comm.c_str()); - tlog0 << "Server finished\n"; - } + tlog1 << "Suspicious font file (length " << len <<", fname " << name << "), logging to suspicious_" << name << ".fnt\n"; Index: client/CMT.cpp =================================================================== --- client/CMT.cpp (revision 2387) @@ -1020,19 +606,6 @@ Index: client/CMT.cpp SDL_PushEvent(&ev); } + -Index: client/GUIBase.h -=================================================================== ---- client/GUIBase.h (revision 2387) -+++ client/GUIBase.h (working copy) -@@ -558,6 +558,8 @@ - CGuiHandler(); - ~CGuiHandler(); - void run(); // holds the main loop for the whole program after initialization and manages the update/rendering system -+ void loopInitFromMainThread(); -+ bool loopFromMainThread(); - - void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering - void simpleRedraw(); //update only top interface and draw background from buffer, sets a flag, method gets called at the end of the rendering Index: client/CDefHandler.cpp =================================================================== --- client/CDefHandler.cpp (revision 2387) @@ -1362,57 +935,585 @@ Index: client/CDefHandler.cpp delete [] data; return nh; } -Index: client/Graphics.cpp +Index: client/Client.h =================================================================== ---- client/Graphics.cpp (revision 2387) -+++ client/Graphics.cpp (working copy) -@@ -315,8 +315,15 @@ - tasks += GET_SURFACE(backgroundsm[id], b["bg120"].String()); - } +--- client/Client.h (revision 2387) ++++ client/Client.h (working copy) +@@ -43,7 +43,7 @@ + public: + timeHandler th; + boost::thread *serverThread; //thread that called system to run server +- SharedMem *shared; //interprocess memory (for waiting for server) ++ //SharedMem *shared; //interprocess memory (for waiting for server) + bool verbose; //whether to print log msgs + std::string port; //port number in text form -+#ifdef ANDROID -+ // For debug make it single-threaded -+ for(int i=0;iourImages.size(); ++y) + extern std::string NAME; +-namespace intpr = boost::interprocess; ++//namespace intpr = boost::interprocess; + + /* + * Client.cpp, part of VCMI engine +@@ -476,9 +476,9 @@ + + void CClient::handlePack( CPack * pack ) + { +- CBaseForCLApply *apply = applier->apps[typeList.getTypeID(pack)]; //find the applier +- if(apply) ++ if(applier->apps.find(typeList.getTypeID(pack)) != applier->apps.end()) { -@@ -508,13 +515,20 @@ - pr[3].first = &Graphics::flags4; - pr[3].second+=("AF00.DEF"),("AF01.DEF"),("AF02.DEF"),("AF03.DEF"),("AF04.DEF"), - ("AF05.DEF"),("AF06.DEF"),("AF07.DEF"); -+#ifdef ANDROID -+ // We ain't no need any filthy multithreading -+ for(int g=0; g<4; g++) -+ { -+ loadHeroFlags(pr[g],true); -+ } -+#else - boost::thread_group grupa; - for(int g=3; g>=0; --g) ++ CBaseForCLApply *apply = applier->apps[typeList.getTypeID(pack)]; //find the applier + apply->applyOnClBefore(this,pack); + tlog5 << "\tMade first apply on cl\n"; + gs->apply(pack); +@@ -639,18 +639,22 @@ + startServer(); + + th.update(); ++ /* + intpr::scoped_lock slock(shared->sr->mutex); + while(!shared->sr->ready) { - grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[g]),true)); + shared->sr->cond.wait(slock); } - grupa.join_all(); -- tlog0 << "Loading and transforming heroes' flags: "<sr->ready) ++ if(!serverThread) + waitForServer(); + + th.update(); +@@ -665,27 +669,31 @@ + CServerHandler::CServerHandler(bool runServer /*= false*/) + { + serverThread = NULL; +- shared = NULL; ++ //shared = NULL; + port = boost::lexical_cast(conf.cc.port); + verbose = false; + ++ /* + boost::interprocess::shared_memory_object::remove("vcmi_memory"); //if the application has previously crashed, the memory may not have been removed. to avoid problems - try to destroy it + try + { + shared = new SharedMem(); + } HANDLE_EXCEPTIONC(tlog1 << "Cannot open interprocess memory: ";) ++ */ + } + + CServerHandler::~CServerHandler() + { +- delete shared; ++ //delete shared; + delete serverThread; //detaches, not kills thread + } + + void CServerHandler::callServer() + { ++ clearServerReady(); + setThreadName(-1, "CServerHandler::callServer"); +- std::string comm = std::string(BIN_DIR PATH_SEPARATOR SERVER_NAME " ") + port + " > server_log.txt"; ++ std::string comm = std::string("LD_LIBRARY_PATH=" LIB_DIR "/../lib " BIN_DIR PATH_SEPARATOR SERVER_NAME " ") + port + " > server_log.txt"; ++ tlog0 << "Invoking VCMI server : " << comm << std::endl; + std::system(comm.c_str()); + tlog0 << "Server finished\n"; + } +Index: client/CSndHandler.cpp +=================================================================== +--- client/CSndHandler.cpp (revision 2387) ++++ client/CSndHandler.cpp (working copy) +@@ -151,16 +151,17 @@ } -- int magic = *(const int*)hlp; -+ int magic = read_unaligned_u32(hlp); - if(len < 10000 || (magic != 589598 && magic != 589599)) + const char *data = mfile->data(); +- unsigned int numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]); +- struct soundEntry *se = (struct soundEntry *)&data[4]; ++ unsigned int numFiles = SDL_SwapLE32(read_unaligned_u32(&data[0])); ++ struct soundEntry se; + +- for (unsigned int i=0; ifilename; +- entry.offset = SDL_SwapLE32(se->offset); +- entry.size = SDL_SwapLE32(se->size); ++ entry.name = se.filename; ++ entry.offset = SDL_SwapLE32(se.offset); ++ entry.size = SDL_SwapLE32(se.size); + entry.data = mfile->data() + entry.offset; + + entries.push_back(entry); +@@ -186,24 +187,26 @@ + return; + } + const unsigned char *data = (const unsigned char *)mfile->data(); +- unsigned int numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]); +- struct videoEntry *ve = (struct videoEntry *)&data[4]; ++ unsigned int numFiles = SDL_SwapLE32(read_unaligned_u32(&data[0])); ++ struct videoEntry ve; + +- for (unsigned int i=0; ifilename; +- entry.offset = SDL_SwapLE32(ve->offset); ++ entry.name = ve.filename; ++ entry.offset = SDL_SwapLE32(ve.offset); + entry.name.erase(entry.name.find_last_of('.')); + + // There is no size, so check where the next file is + if (i == numFiles - 1) { + entry.size = mfile->size() - entry.offset; + } else { +- struct videoEntry *ve_next = ve+1; ++ struct videoEntry ve_next; ++ memcpy(&ve_next, &data[4+(i+1)*sizeof(ve)], sizeof(ve)); + +- entry.size = SDL_SwapLE32(ve_next->offset) - entry.offset; ++ entry.size = SDL_SwapLE32(ve_next.offset) - entry.offset; + } + entry.data = mfile->data() + entry.offset; + +Index: client/CCreatureAnimation.cpp +=================================================================== +--- client/CCreatureAnimation.cpp (revision 2387) ++++ client/CCreatureAnimation.cpp (working copy) +@@ -37,15 +37,23 @@ + } + } + ++#define CHECK_LOD_MEM_BLOCK_SIZE1(S, FF, F, L) { \ ++ if( lodLength < (S) ) \ ++ tlog1<<"ERROR in " << FF << " " << F << ":" << L << ": reading past the end of LOD mem block by " << \ ++ (S) - lodLength << " bytes, fname " << fname << " size " << lodLength << std::endl; } ++#define CHECK_LOD_MEM_BLOCK_SIZE(S) CHECK_LOD_MEM_BLOCK_SIZE1(S, __FUNCTION__, __FILE__, __LINE__) ++ + CCreatureAnimation::CCreatureAnimation(std::string name) : internalFrame(0), once(false) + { +- FDef = spriteh->giveFile(name, FILE_ANIMATION); //load main file ++ FDef = spriteh->giveFile(name, FILE_ANIMATION, &lodLength); //load main file ++ fname = name; + + //init anim data + int i,j, totalInBlock; + + defName=name; + i = 0; ++ CHECK_LOD_MEM_BLOCK_SIZE(i+0x310); + DEFType = readNormalNr<4>(i,FDef); i+=4; + fullWidth = readNormalNr<4>(i,FDef); i+=4; + fullHeight = readNormalNr<4>(i,FDef); i+=4; +@@ -64,6 +72,7 @@ + totalEntries=0; + for (int z=0; z frameIDs; + int group = readNormalNr<4>(i,FDef); i+=4; //block ID + totalInBlock = readNormalNr<4>(i,FDef); i+=4; +@@ -76,6 +85,7 @@ + /*int unknown2 = readNormalNr<4>(i,FDef);*/ i+=4; //TODO use me + /*int unknown3 = readNormalNr<4>(i,FDef);*/ i+=4; //TODO use me + i+=13*totalInBlock; //ommiting names ++ CHECK_LOD_MEM_BLOCK_SIZE(i+totalInBlock*4); + for (j=0; j(i,FDef); i+=4; +@@ -173,6 +183,7 @@ + unsigned char SegmentType, SegmentLength; + + i = BaseOffset = SEntries[SIndex].offset; ++ CHECK_LOD_MEM_BLOCK_SIZE(i+32); + /*int prSize = readNormalNr<4>(i, FDef);*/ i += 4; //TODO use me + int defType2 = readNormalNr<4>(i, FDef); i += 4; + FullWidth = readNormalNr<4>(i, FDef); i += 4; +@@ -194,11 +205,12 @@ + { + ftcp += FullWidth * TopMargin; + } +- int *RLEntries = (int*)(FDef + BaseOffset); ++ unsigned char *RLEntries = (FDef + BaseOffset); + BaseOffset += sizeof(int) * SpriteHeight; + for (int i = 0; i < SpriteHeight; i++) + { +- BaseOffset = BaseOffsetor + RLEntries[i]; ++ CHECK_LOD_MEM_BLOCK_SIZE(RLEntries+i*4-FDef); ++ BaseOffset = BaseOffsetor + read_unaligned_u32(RLEntries+i*4); + if (LeftMargin > 0) + { + ftcp += LeftMargin; +@@ -213,6 +225,7 @@ + + do + { ++ CHECK_LOD_MEM_BLOCK_SIZE(BaseOffset+2); + SegmentType = FDef[BaseOffset++]; + SegmentLength = FDef[BaseOffset++]; + +@@ -227,6 +240,8 @@ + { + if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB)) + { ++ if(SegmentType == 0xff) ++ CHECK_LOD_MEM_BLOCK_SIZE(BaseOffset+k+1); + const ui8 colorNr = SegmentType == 0xff ? FDef[BaseOffset+k] : SegmentType; + putPixel(dest, xB, yB, palette[colorNr], colorNr, yellowBorder, blueBorder, aCountMod); + } +Index: client/GUIBase.h +=================================================================== +--- client/GUIBase.h (revision 2387) ++++ client/GUIBase.h (working copy) +@@ -558,6 +558,8 @@ + CGuiHandler(); + ~CGuiHandler(); + void run(); // holds the main loop for the whole program after initialization and manages the update/rendering system ++ void loopInitFromMainThread(); ++ bool loopFromMainThread(); + + void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering + void simpleRedraw(); //update only top interface and draw background from buffer, sets a flag, method gets called at the end of the rendering +Index: client/CAnimation.h +=================================================================== +--- client/CAnimation.h (revision 2387) ++++ client/CAnimation.h (working copy) +@@ -47,6 +47,8 @@ + std::map > offset; + + unsigned char * data; ++ int lodLength; ++ std::string fname; + SDL_Color * palette; + + public: +@@ -125,6 +127,8 @@ + * 2nd byte = size of segment + * raw data (if any) + */ ++// Buggy, disabled for Android ++/* + class CompImage : public IImage + { + //x,y - margins, w,h - sprite size +@@ -158,8 +162,8 @@ + + friend class CompImageLoader; + }; ++*/ + +- + /// Class for handling animation + class CAnimation + { +Index: client/CCreatureAnimation.h +=================================================================== +--- client/CCreatureAnimation.h (revision 2387) ++++ client/CCreatureAnimation.h (working copy) +@@ -66,6 +66,8 @@ + int curFrame, internalFrame; //number of currently displayed frame + unsigned int frames; //number of frames + CCreatureAnim::EAnimType type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) ++ int lodLength; ++ std::string fname; + + template + int nextFrameT(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next +Index: client/CAnimation.cpp +=================================================================== +--- client/CAnimation.cpp (revision 2387) ++++ client/CAnimation.cpp (working copy) +@@ -46,6 +46,8 @@ + ~SDLImageLoader(); + }; + ++// It's buggy, disabled for Android build ++/* + class CompImageLoader + { + CompImage * image; +@@ -69,11 +71,18 @@ + CompImageLoader(CompImage * Img); + ~CompImageLoader(); + }; +- ++*/ + /************************************************************************* + * DefFile, class used for def loading * + *************************************************************************/ + ++ ++#define CHECK_LOD_MEM_BLOCK_SIZE1(S, FF, F, L) { \ ++ if( lodLength < (S) ) \ ++ tlog1<<"ERROR in " << FF << " " << F << ":" << L << ": reading past the end of LOD mem block by " << \ ++ (S) - lodLength << " bytes, fname " << fname << " size " << lodLength << std::endl; } ++#define CHECK_LOD_MEM_BLOCK_SIZE(S) CHECK_LOD_MEM_BLOCK_SIZE1(S, __FUNCTION__, __FILE__, __LINE__) ++ + CDefFile::CDefFile(std::string Name): + data(NULL), + palette(NULL) +@@ -91,15 +100,18 @@ + { 0, 0, 0, 192} // 75% - shadow border below selection + }; + +- data = spriteh->giveFile(Name, FILE_ANIMATION); ++ fname = Name; ++ data = spriteh->giveFile(Name, FILE_ANIMATION, &lodLength); + palette = new SDL_Color[256]; + int it = 0; + ++ CHECK_LOD_MEM_BLOCK_SIZE(it+4); + unsigned int type = readNormalNr(data, it); + it+=4; + //int width = readNormalNr(data, it); it+=4;//not used + //int height = readNormalNr(data, it); it+=4; + it+=8; ++ CHECK_LOD_MEM_BLOCK_SIZE(it+4); + unsigned int totalBlocks = readNormalNr(data, it); + it+=4; + +@@ -117,6 +129,7 @@ + + for (unsigned int i=0; isecond[frame]; + +- const SSpriteDef sd = * reinterpret_cast(FDef); ++ SSpriteDef sd; ++ CHECK_LOD_MEM_BLOCK_SIZE((FDef-data)+sizeof(sd)); ++ memcpy(&sd, FDef, sizeof(sd)); + SSpriteDef sprite; + + //sprite.size = SDL_SwapLE32(sd.size);//unused +@@ -170,6 +186,7 @@ + //pixel data is not compressed, copy data to surface + for (unsigned int i=0; i(FDef+currentOffset); ++ const unsigned char * RWEntriesLoc = FDef+currentOffset; + currentOffset += sizeof(ui32) * sprite.height; + + for (unsigned int i=0; isurf->pixels + image->surf->h*image->surf->pitch >= position + size ) + { + memcpy((void *)position, data, size); + position += size; +@@ -323,7 +357,7 @@ + + inline void SDLImageLoader::Load(size_t size, ui8 color) + { +- if (size) ++ if (size && (ui8 *)image->surf->pixels + image->surf->h*image->surf->pitch >= position + size) + { + memset((void *)position, color, size); + position += size; +@@ -345,6 +379,7 @@ + + //////////////////////////////////////////////////////////////////////////////// + ++/* + CompImageLoader::CompImageLoader(CompImage * Img): + image(Img), + position(NULL), +@@ -518,6 +553,7 @@ + image->surf = newPtr; + } + ++*/ + /************************************************************************* + * Classes for images, support loading from file and drawing on surface * + *************************************************************************/ +@@ -625,6 +661,8 @@ + SDL_FreeSurface(surf); + } + ++// Buggy, disabled for Android ++/* + CompImage::CompImage(const CDefFile *data, size_t frame, size_t group): + surf(NULL), + line(NULL), +@@ -845,6 +883,7 @@ + delete [] line; + delete [] palette; + } ++*/ + + /************************************************************************* + * CAnimation for animations handling, can load part of file if needed * +@@ -889,9 +928,11 @@ + //try to get image from def + if (source[group][frame].getType() == JsonNode::DATA_NULL) + { ++ /* + if (compressed) + images[group][frame] = new CompImage(file, frame, group); + else ++ */ + images[group][frame] = new SDLImage(file, frame, group); + } + else //load from separate file +Index: client/SDL_Extensions.cpp +=================================================================== +--- client/SDL_Extensions.cpp (revision 2387) ++++ client/SDL_Extensions.cpp (working copy) +@@ -119,8 +119,8 @@ + if(incrementPtr == -1) + ptr -= 2; + +- Uint16 * const px = (Uint16*)ptr; +- *px = (B>>3) + ((G>>2) << 5) + ((R>>3) << 11); //drop least significant bits of 24 bpp encoded color ++ Uint16 px = (B>>3) + ((G>>2) << 5) + ((R>>3) << 11); //drop least significant bits of 24 bpp encoded color ++ memcpy(ptr, &px, sizeof(px)); + + if(incrementPtr == 1) + ptr += 2; //bpp +@@ -150,9 +150,9 @@ + const int rmask = 0xF800, gmask = 0x7E0, bmask = 0x1F; + const int rshift = 11, gshift = 5, bshift = 0; + +- const Uint8 r5 = (*((Uint16 *)ptr) & rmask) >> rshift, +- b5 = (*((Uint16 *)ptr) & bmask) >> bshift, +- g5 = (*((Uint16 *)ptr) & gmask) >> gshift; ++ const Uint8 r5 = (read_unaligned_u16(ptr) & rmask) >> rshift, ++ b5 = (read_unaligned_u16(ptr) & bmask) >> bshift, ++ g5 = (read_unaligned_u16(ptr) & gmask) >> gshift; + + const Uint32 r8 = (r5 << (8 - rbit)) | (r5 >> (2*rbit - 8)), + g8 = (g5 << (8 - gbit)) | (g5 >> (2*gbit - 8)), +@@ -649,7 +649,7 @@ + return *p; + + case 2: +- return *(Uint16 *)p; ++ return read_unaligned_u16(p); + + case 3: + /* +@@ -661,7 +661,7 @@ + //#endif + + case 4: +- return *(Uint32 *)p; ++ return read_unaligned_u32(p); + + default: + return 0; // shouldn't happen, but avoids warnings Index: client/CDefHandler.h =================================================================== --- client/CDefHandler.h (revision 2387) @@ -1437,6 +1538,45 @@ Index: client/CDefHandler.h CDefEssential * essentialize(); static CDefHandler * giveDef(const std::string & defName); +Index: client/GUIBase.cpp +=================================================================== +--- client/GUIBase.cpp (revision 2387) ++++ client/GUIBase.cpp (working copy) +@@ -11,6 +11,7 @@ + #include "../CThreadHelper.h" + #include "CConfigHandler.h" + #include ++ + + /* + * GUIBase.cpp, part of VCMI engine +@@ -365,6 +366,26 @@ + } + } HANDLE_EXCEPTION + } ++ ++void CGuiHandler::loopInitFromMainThread() ++{ ++ setThreadName(-1, "CGuiHandler::run"); ++ CCS->curh->centerCursor(); ++ mainFPSmng->init(); // resets internal clock, needed for FPS manager ++} ++ ++bool CGuiHandler::loopFromMainThread() ++{ ++ if(terminate) ++ return false; ++ if(curInt) ++ curInt->update(); // calls a update and drawing process of the loaded game interface object at the moment ++ ++ mainFPSmng->framerateDelay(); // holds a constant FPS ++ return true; ++} ++ ++ + + CGuiHandler::CGuiHandler() + :lastClick(-500, -500) Index: CConsoleHandler.cpp =================================================================== --- CConsoleHandler.cpp (revision 2387) @@ -1457,134 +1597,3 @@ Index: CConsoleHandler.cpp } int CConsoleHandler::run() -Index: server/CGameHandler.cpp -=================================================================== ---- server/CGameHandler.cpp (revision 2387) -+++ server/CGameHandler.cpp (working copy) -@@ -638,6 +638,7 @@ - (packType != typeList.getTypeID() || !isAllowedArrangePack((ArrangeStacks*)pack)) && // for dialogs like garrison - states[getCurrentPlayer()].queries.size()) - { -+ tlog0<<__FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << std::endl; - complain("Answer the query before attempting any further actions!"); - PackageApplied applied; - applied.result = false; -@@ -650,6 +651,7 @@ - else if(apply) - { - bool result = apply->applyOnGH(this,&c,pack); -+ tlog0<<__FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << std::endl; - tlog5 << "Message successfully applied (result=" << result << ")!\n"; - - //send confirmation that we've applied the package -@@ -1833,7 +1835,7 @@ - iw.player = h1->tempOwner; - iw.components.push_back(Component(Component::SEC_SKILL, 18, ScholarLevel, 0)); - -- iw.text.addTxt(MetaString::GENERAL_TXT, 139);//"%s, who has studied magic extensively, -+ iw.text.addTxt(MetaString::GENERAL_TXT, 139);//%s, who has studied magic extensively, - iw.text.addReplacement(h1->name); - - if (cs2.spells.size())//if found new spell - apply -Index: server/CVCMIServer.cpp -=================================================================== ---- server/CVCMIServer.cpp (revision 2387) -+++ server/CVCMIServer.cpp (working copy) -@@ -29,7 +29,7 @@ - using namespace boost; - using namespace boost::asio; - using namespace boost::asio::ip; --namespace intpr = boost::interprocess; -+//namespace intpr = boost::interprocess; - bool end2 = false; - int port = 3030; - VCMIDirs GVCMIDirs; -@@ -379,6 +379,7 @@ - - void CVCMIServer::start() - { -+ /* - ServerReady *sr = NULL; - intpr::mapped_region *mr; - try -@@ -395,13 +396,17 @@ - mr = new intpr::mapped_region(smo,intpr::read_write); - sr = new(mr->get_address())ServerReady(); - } -+ */ -+ notifyServerReady(); - - boost::system::error_code error; - tlog0<<"Listening for connections at port " << acceptor->local_endpoint().port() << std::endl; - tcp::socket * s = new tcp::socket(acceptor->get_io_service()); - boost::thread acc(boost::bind(vaccept,acceptor,s,&error)); -+ /* - sr->setToTrueAndNotify(); - delete mr; -+ */ - - acc.join(); - if (error) -Index: server/stdafx.h -=================================================================== ---- server/stdafx.h (revision 2387) -+++ server/stdafx.h (working copy) -@@ -15,8 +15,8 @@ - #include "../global.h" - - #include --#include --#include -+//#include -+//#include - #include - #include - #include -Index: global.h -=================================================================== ---- global.h (revision 2387) -+++ global.h (working copy) -@@ -4,6 +4,7 @@ - #include - #include - #include //std::find -+#include //memcpy - #include //std::find - #include - #include -@@ -725,29 +726,21 @@ - } - - --#if defined(linux) && defined(sparc) --/* SPARC does not support unaligned memory access. Let gcc know when -- * to emit the right code. */ --struct unaligned_Uint16 { ui16 val __attribute__(( packed )); }; --struct unaligned_Uint32 { ui32 val __attribute__(( packed )); }; - - static inline ui16 read_unaligned_u16(const void *p) - { -- const struct unaligned_Uint16 *v = (const struct unaligned_Uint16 *)p; -- return v->val; -+ ui16 out; -+ memcpy(&out, p, sizeof(out)); -+ return out; - } - - static inline ui32 read_unaligned_u32(const void *p) - { -- const struct unaligned_Uint32 *v = (const struct unaligned_Uint32 *)p; -- return v->val; -+ ui32 out; -+ memcpy(&out, p, sizeof(out)); -+ return out; - } - --#else --#define read_unaligned_u16(p) (* reinterpret_cast(p)) --#define read_unaligned_u32(p) (* reinterpret_cast(p)) --#endif -- - //for explicit overrides - #ifdef _MSC_VER - #define OVERRIDE override diff --git a/project/jni/boost/src b/project/jni/boost/src index e3706f6c3..be0b47661 160000 --- a/project/jni/boost/src +++ b/project/jni/boost/src @@ -1 +1 @@ -Subproject commit e3706f6c3cd6ac74fd531396d96a23cbfed37d66 +Subproject commit be0b47661179aae50114af9d998548d0f05da295 diff --git a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h index 297133041..5349394e6 100644 --- a/project/jni/sdl-1.2/include/SDL_screenkeyboard.h +++ b/project/jni/sdl-1.2/include/SDL_screenkeyboard.h @@ -136,7 +136,7 @@ extern DECLSPEC int SDLCALL SDL_IsScreenKeyboardShown(void *unused); /* Remap SDL keycodes returned by gamepad buttons. Pass the SDLK_ constants, or 0 to leave old value. On OUYA: O = A, U = X, Y = Y, A = B */ -extern DECLSPEC void SDLCALL SDL_ANDROID_SetGamepadKeymap(int A, int B, int X, int Y, int L1, int R1, int L2, int R2, int LT, int RT); +extern DECLSPEC void SDLCALL SDL_ANDROID_SetGamepadKeymap(int A, int B, int X, int Y, int L1, int R1, int L2, int R2, int LThumb, int RThumb); #ifdef __cplusplus } diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidinput.h b/project/jni/sdl-1.2/src/video/android/SDL_androidinput.h index de8326590..554c722f6 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidinput.h +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidinput.h @@ -127,6 +127,7 @@ enum { TOUCHSCREEN_KEYBOARD_PASS_EVENT_DOWN_TO_SDL = 0x40000000 }; extern unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId); extern int SDL_ANDROID_isTouchscreenKeyboardUsed; +// Default button mapping is rather random, make sure to redefine it inside AndroidAppSettings.cfg #ifndef SDL_ANDROID_KEYCODE_0 #define SDL_ANDROID_KEYCODE_0 RETURN #endif @@ -190,6 +191,38 @@ extern int SDL_ANDROID_isTouchscreenKeyboardUsed; #define SDL_ANDROID_SCREENKB_KEYCODE_9 UNKNOWN #endif +// Gamepad keys +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_0 +#define SDL_ANDROID_GAMEPAD_KEYCODE_0 SDL_ANDROID_SCREENKB_KEYCODE_0 +#endif +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_1 +#define SDL_ANDROID_GAMEPAD_KEYCODE_1 SDL_ANDROID_SCREENKB_KEYCODE_1 +#endif +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_2 +#define SDL_ANDROID_GAMEPAD_KEYCODE_2 SDL_ANDROID_SCREENKB_KEYCODE_2 +#endif +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_3 +#define SDL_ANDROID_GAMEPAD_KEYCODE_3 SDL_ANDROID_SCREENKB_KEYCODE_3 +#endif +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_4 +#define SDL_ANDROID_GAMEPAD_KEYCODE_4 SDL_ANDROID_SCREENKB_KEYCODE_5 +#endif +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_5 +#define SDL_ANDROID_GAMEPAD_KEYCODE_5 SDL_ANDROID_SCREENKB_KEYCODE_4 +#endif +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_6 +#define SDL_ANDROID_GAMEPAD_KEYCODE_6 SDL_ANDROID_KEYCODE_0 +#endif +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_7 +#define SDL_ANDROID_GAMEPAD_KEYCODE_7 SDL_ANDROID_KEYCODE_6 +#endif +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_8 +#define SDL_ANDROID_GAMEPAD_KEYCODE_8 SPACE +#endif +#ifndef SDL_ANDROID_GAMEPAD_KEYCODE_9 +#define SDL_ANDROID_GAMEPAD_KEYCODE_9 RETURN +#endif + // Queue events to main thread extern void SDL_ANDROID_MainThreadPushMouseMotion(int x, int y); extern void SDL_ANDROID_MainThreadPushMouseButton(int pressed, int button); diff --git a/project/jni/sdl-1.2/src/video/android/keymap.c b/project/jni/sdl-1.2/src/video/android/keymap.c index eca9c7a34..4e3af8986 100644 --- a/project/jni/sdl-1.2/src/video/android/keymap.c +++ b/project/jni/sdl-1.2/src/video/android/keymap.c @@ -130,18 +130,18 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap) keymap[KEYCODE_PAGE_DOWN] = SDL_KEY(PAGEDOWN); keymap[KEYCODE_PICTSYMBOLS] = SDL_KEY(LSHIFT); keymap[KEYCODE_SWITCH_CHARSET] = SDL_KEY(LSHIFT); - keymap[KEYCODE_BUTTON_A] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_0)); - keymap[KEYCODE_BUTTON_B] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_1)); + keymap[KEYCODE_BUTTON_A] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_0)); + keymap[KEYCODE_BUTTON_B] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_1)); keymap[KEYCODE_BUTTON_C] = SDL_KEY(C); - keymap[KEYCODE_BUTTON_X] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_2)); - keymap[KEYCODE_BUTTON_Y] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_3)); + keymap[KEYCODE_BUTTON_X] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_2)); + keymap[KEYCODE_BUTTON_Y] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_3)); keymap[KEYCODE_BUTTON_Z] = SDL_KEY(Z); - keymap[KEYCODE_BUTTON_L1] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_5)); - keymap[KEYCODE_BUTTON_R1] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_4)); - keymap[KEYCODE_BUTTON_L2] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_0)); - keymap[KEYCODE_BUTTON_R2] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_6)); - keymap[KEYCODE_BUTTON_THUMBL] = SDL_KEY(SPACE); - keymap[KEYCODE_BUTTON_THUMBR] = SDL_KEY(RETURN); + keymap[KEYCODE_BUTTON_L1] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_4)); + keymap[KEYCODE_BUTTON_R1] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_5)); + keymap[KEYCODE_BUTTON_L2] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_6)); + keymap[KEYCODE_BUTTON_R2] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_7)); + keymap[KEYCODE_BUTTON_THUMBL] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_8)); + keymap[KEYCODE_BUTTON_THUMBR] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_9)); keymap[KEYCODE_BUTTON_START] = SDL_KEY(RETURN); keymap[KEYCODE_BUTTON_SELECT] = SDL_KEY(ESCAPE); keymap[KEYCODE_BUTTON_MODE] = SDL_KEY(SPACE);