SDL port for Android SDK/NDK 1.6

Quickly share your Android Code Snippets here...

Re: SDL port for Android SDK/NDK 1.6

Postby jenergy » Thu Sep 06, 2012 11:54 pm

Oh-oh..you know, I started to develop it some months ago, I compiled all project was with libsdl 2.0, downloaded with command "hg clone http://hg.libsdl.org/SDL".. I found this thread only yesterday. :-)
I'll try to compile with your libsdl port, and I'm gonna also try your apps to check 44100khz audio, but I'm sure that they will work. I hope now to be able to compile with your port :-)
Anyway, for the moment thank you, I'll let you know..
jenergy
Freshman
Freshman
 
Posts: 3
Joined: Wed Sep 05, 2012 6:54 pm

Top

Re: SDL port for Android SDK/NDK 1.6

Postby jenergy » Mon Sep 10, 2012 11:56 pm

Ok, I finally reached the target to compile your libsdl port. I tried 'testmusic', which is a ballfield + music, and logcat clearly says that it's playing at 44100 Khz..it seems to be a midi, but I think that it's the same. I tried to compile openttd but without success, with this error:

SharedLibrary : libsdl-1.2.so
echo Launching script jni/../jni/application/AndroidBuild.sh
Launching script jni/../jni/application/AndroidBuild.sh
cd jni/../jni/application/src && ./AndroidBuild.sh
sh: line 0: cd: openttd: File o directory non esistente
sh: line 0: cd: openttd: File o directory non esistente
Run: sudo apt-get install liblzma-dev - it is needed only for configure script
sh: line 0: cd: openttd: File o directory non esistente
make: *** [jni/../jni/application/src/libapplication.so] Error 1

I don't know if it can be the reason, but ./ChangeAppSettings.sh -a does not ask me questions as before (advertisment, screen size etc..) Now it says me:


If you will supply empty string as answer the previous value will be used

Patching Accelerometer.java
Patching Advertisement.java
Patching Audio.java
Patching DataDownloader.java
Patching Globals.java
Patching GLSurfaceView_SDL.java
Patching Keycodes.java
Patching MainActivity.java
Patching Settings.java
Patching Video.java
Patching project/AndroidManifest.xml
Patching project/src/Globals.java
Patching project/jni/Settings.mk
Patching strings.xml
Cleaning up dependencies
Done

without questions

I just have to study a little but how all your port work, it seems to be a little complex (and at the same time very strong!!) to me. I tried to see gitk for openttd to understand the problem but without success..at least for the moment.
I think that I'll have to 'remap' my eclipse project into your 'skeleton' mechanism of files, for example I've got ALL the calls (Audiotrack too) in my SDL_Activity.java, since the standard is like this. And I think I'll have to split them into more file like you did... In order to make my eclipse project compile under standard libsdl 2.0 I had to change some libsdl calls, since original jzintv is under libsdl 1.3..but since you have a port of 1.2 and 1.3 I think I'll have to revert my changes. I hope to solve my problem, audio at 22050khz is not the best
jenergy
Freshman
Freshman
 
Posts: 3
Joined: Wed Sep 05, 2012 6:54 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Tue Sep 11, 2012 8:48 am

To compile OpenTTD you need to download OpenTTD source release into the directory project/jni/application/openttd/openttd, and also apply the patch from the same directory.. There was a readme in that dir I believe.
ChangeAppSettings without arguments will ask you a lot of questions, and will modify AndroidAppSettings.cfg, with -a parameter it will just update project files, it's usually easier to just edit AndroidAppSettings.cfg by hand.
And it asked you about advertisement options because I've added that feature recently, and settings files for most projects are not updated.
That complicated script is needed, because I needed to support multiple projects within the same SDL port, and you need to change package name in Java files, and modify AndroidManifest.xml for each project.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby slvn » Fri Sep 14, 2012 10:02 pm

Hey,

Latest version is great, thanks for all the releases !
I did not update for a while, though, here's a strange behavior on my side :

With a game in portrait mode, a screen resolution of 480x854, and an Ad,
when going to background then foreground, the ad is then shifted of 20 pixels (within it's own view/container).
The SDL view/container is shifted of 20 pixels (also toward the bottom)

the problem does not appear in landscape mode.
the problem does not appear if the ad doesnt load (for, instance because of no wifi).
the problem does not appear in portrait mode with a tablet !


Otherwise, some remarks and questions :

in Video.java, the limitEventRate seems to create "lag". Especially, when you touch the screen to pull an object, the movement is jerky. -> I need to decrease the wait value to get something better !


In order to make a jni call to a java function, I need to use the JavaEnv variable of the sdl-1.2. What is the correct way to get it ( instead of removing the "static" keyword of the c-variable) ?


Even if I put "StartupMenuButtonTimeout=0", I can see the "change configuration" button for let's say 500ms, which can let the user re-configure some parameters.

In the AndroidManifestTemplate.xml file : the "debuggable" is set to "true", shouldn't it be false ?!


thanks,
Last edited by slvn on Sun Sep 16, 2012 8:37 am, edited 1 time in total.
slvn
Developer
Developer
 
Posts: 33
Joined: Thu Jul 28, 2011 7:45 am

Re: SDL port for Android SDK/NDK 1.6

Postby fl1313 » Sat Sep 15, 2012 7:00 pm

hi,
i have some problems :
It does not appear in landscape mode.
It does not appear if the ad doesnt load (for, instance because of no wifi).
It does not appear in portrait mode with a tablet !

please help me :(
fl1313
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Sep 15, 2012 6:57 pm

Re: SDL port for Android SDK/NDK 1.6

Postby slvn » Sun Sep 16, 2012 10:57 am

Hey,

I get the same probleme with the demo app test-advertisments, by putting the following parameters :

ScreenOrientation=v
InhibitSuspend=y
SwVideoMode=n

And commenting the ad movement :
//SDL_ANDROID_SetAdvertisementPosition(adX, adY);


But on my app, neither modifying InhibitSuspend nor adding a "SetAdvertisementPosition" call can solve the problem.

thanks,
slvn
Developer
Developer
 
Posts: 33
Joined: Thu Jul 28, 2011 7:45 am

Top

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Mon Sep 17, 2012 2:38 pm

I cannot reproduce the errors with the ad usage you're describing, on my HTC Evo and on the emulator. The portrait mode works just fine with advertisement, InhibitSuspend or SwVideoMode does not affect it.
Could you please give me the .apk file of the example, which fails for you? Which device are you using? Does it have physical or on-screen Home/Back buttons?

I've removed the limitEventRate call for Froyo and newer phones, please tell me if it has any effect on the lag.
Also I've fixed the bug with StartupMenuButtonTimeout=0 still showing the config button.
To get Java environment, you can call SDL_ANDROID_JniEnv() - it's defined in SDL_android.h, I've removed it some time ago, and added back now (and I won't be removing it again, because it's got it's own header now).
I did not find any disadvantage for keeping debuggable="true" inside AndroidManifest.xml, the C compiler optimizes all the code anyway, and Java compiler does not do any optimizations, as far as I know. There is a flag --no-optimize to the DX compiler, however it's not used by the Android SDK. And the advantage is that you can debug your apk file :) .
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby slvn » Mon Sep 17, 2012 9:34 pm

hey,

Thanks for the commits ! haven't tried the new version yet, but i will let you know !

I will provide an APK with the bug as I see it !
I added all the modifications, step by step, and the bug appears because of the two calls to :

_ad.getView().setFocusableInTouchMode(true);

So I commented them out !
slvn
Developer
Developer
 
Posts: 33
Joined: Thu Jul 28, 2011 7:45 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Tue Sep 18, 2012 7:48 am

If the advertisement still can be clicked after disabling setFocusableInTouchMode, it's probably better just to push your changes to the repository. I can apply a patch, if you'll give it to me, or I can give you a write access to my repo, if you'll tell me your Github account name.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby slvn » Tue Sep 18, 2012 8:23 pm

Hey !

Your modifications for the ad are ok on my side ! dont have the shift effect anymore !! thanks

About the limitRate :
- new modification seems to work (no lag anymore).
Previously, I solved the problem by reducing the wait time to 50ms in video.java ! I thought that was a bug for older Sdk/Phones (dont know exactly).
But you seem to apply the patch of limiting event to all verrsion >= Froyo !! I am afraid that phones >= froyo get the same problems ?

thanks,
slvn
Developer
Developer
 
Posts: 33
Joined: Thu Jul 28, 2011 7:45 am

Re: SDL port for Android SDK/NDK 1.6

Postby slvn » Tue Sep 18, 2012 8:26 pm

Any idea of modification to get more "motion" events ? for instance to have a smoother movement of objects while touching the phone ?!
slvn
Developer
Developer
 
Posts: 33
Joined: Thu Jul 28, 2011 7:45 am

Re: SDL port for Android SDK/NDK 1.6

Postby shishanjiu » Thu Sep 20, 2012 4:10 am

pelya, thank you for your effort on SDL port. I'm using it. :)

There's a problem on Android 4.0. When app gets paused and resumed (e.g. by the user hitting the home key and then switch back to app), the app's interface becomes black. Though its sound is normal and can still responds to click, the screen is black and keeps black.

The bug had been reported in SDL 2.0, and had been fixed. Do you have any patch for it? or method to resolve it?

Thank advance!
shishanjiu
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Sep 20, 2012 3:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby slvn » Thu Sep 20, 2012 7:01 am

Hello,

I think you need to call sdl_flip often, even if there is nothing new to draw (for instance at 1 Hz), the "pause" (pressing home button) will appear within the next following flip.
Maybe this can be confirmed.
slvn
Developer
Developer
 
Posts: 33
Joined: Thu Jul 28, 2011 7:45 am

Re: SDL port for Android SDK/NDK 1.6

Postby shishanjiu » Thu Sep 20, 2012 11:56 am

I've downloaded the latest code: pelya-commandergenius-android-market-release-10-758-g42a9f2e.tar.gz

And tried on it, the demo project of ballfield runs well on Android 4.0.3. When click home key to switch to main interface of Android and then switch back to ballfield, it resumes normally. But for my app, when switching back, only black screen is left, though its sound resumes and can still responds to click. When responds to my click ,there're so many SDL_BlitSurface and SDL_UpdateRects operations in my codes, and from the sound of operations, I can know it runs normally, but the screen keeps black. That is all are normal, expect nothing is shown.

I found onWindowFocusChanged was added in MainActivity.java, which is not in my old version. But it has not done its effect on my code. Does any especial code need in app's code to solve the pause/resume issue?

Furthermore, the pause/resume is ok after hibernation. The unmormal is only happen after press home key and switch back.
shishanjiu
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Sep 20, 2012 3:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Thu Sep 20, 2012 12:11 pm

Are you using HW video mode? Try setting SwVideoMode=y inside AndroidAppSettings.cfg
What SDL version are you using? 1.2 or 1.3/2.0? I mostly test 1.2, 1.3 might have bugs.
Any idea of modification to get more "motion" events ? for instance to have a smoother movement of objects while touching the phone ?!

Android framework sends touch events with a full history of events that happened when the current frame was rendering, SDL is currently discarding that history and only use the latest touch coordinates. I can make a setting to push all that history as a mouse/touch SDL events, that may impact a speed a bit though (and I would rather enable it by default for fast devices).
It's mostly important for drawing programs, where you need to precisely track the path of a finger on screen.
So, do you need such feature?
Last edited by pelya on Thu Sep 20, 2012 12:16 pm, edited 1 time in total.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Top
PreviousNext

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 3 guests