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 kurosu » Fri Aug 13, 2010 8:02 pm

KEYCODE_FOCUS and KEYCODE_CAMERA are both mappable, but on my phone they are the click up and down of the same physical camera button, so they can't be set properly at the same time.

KEYCODE_ENDCALL and KEYCODE_POWER are not mappable on my phone (intercepted by the OS/Home?)
kurosu
Experienced Developer
Experienced Developer
 
Posts: 94
Joined: Sat Jun 12, 2010 1:56 pm

Top

Re: SDL port for Android SDK/NDK 1.6

Postby kurosu » Sun Aug 15, 2010 10:08 pm

I finally released a preview version of the port. More information on the Wormux forum.

Once it is deemed enjoyable and playable, I'll see about publishing in on the market.

Thanks again pelya for making this possible. I also dropped the curl dependency by using JNI and studying your code ;)
kurosu
Experienced Developer
Experienced Developer
 
Posts: 94
Joined: Sat Jun 12, 2010 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Mon Aug 16, 2010 9:51 am

kurosu wrote:I finally released a preview version of the port. More information on the Wormux forum.

Once it is deemed enjoyable and playable, I'll see about publishing in on the market.

Thanks again pelya for making this possible. I also dropped the curl dependency by using JNI and studying your code ;)


That's nice, I'll check it when I'll have some time
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 pelya » Tue Aug 17, 2010 4:59 pm

kurosu wrote:I finally released a preview version of the port.


F/Wormux ( 2643): Error in /home/adm/wormux2/project/jni/application/tool/resource_manager.cpp:198 (Wormux svn) : ResourceManager: can't load profile /sdcard/Wormux//data/wormux_default_config.xml

I've installed the app data to phone storage, plz don't use absolute paths.
Tomorrow I'll try with SDCard.
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 kurosu » Wed Aug 18, 2010 9:40 am

pelya wrote:F/Wormux ( 2643): Error in /home/adm/wormux2/project/jni/application/tool/resource_manager.cpp:198 (Wormux svn) : ResourceManager: can't load profile /sdcard/Wormux//data/wormux_default_config.xml

I've installed the app data to phone storage, plz don't use absolute paths.
Tomorrow I'll try with SDCard.


Yeah, sorry about wasting your time, I'm precisely improving the code after feedback from other persons. I updated without renaming the apk and data zip, both should be downloaded again.

The reasoning, that I'm reverting (an user tested that on his Donut Archos 5 tablet), was that:
  • The data is massive (though I shrinked it from 95MB to 36), I personally would not install it on my phone internal memory (which free space ranges from 50 to 60MB at the moment); thus I willfully suffer from long loading time
  • There are files created (much like what sdl_main does, ie creating std{out,err}.txt in the curdir) that are relevant to bug reports, and having them in the phone /data is unpractical; probably I should redirect std{out,err} to /sdcard/Wormux/ instead (but needing to create the folders then), which is harmless if there's no sd card anyway
  • Custom maps, teams & co can be added (either through the game or download) by hand, and for this it is again more practical to have it sit on the sd card; maybe I should set it unconditionally to /sdcard/Wormux in that case

You can find update in the thread I linked earlier, but here are the problems I was investigating, not related directly to your port:
  • There is a strange interaction with the list of resolution wormux enforces (sometimes SDL doesn't report them but do manage them), fullscreen or not, and what the SDL does; in one case, the display had black borders but was only a portion of the expected display
  • when editing the key bindings, SDLK_UNKNOWN (instead of 'NONE') was registered to some actions, and for the keys for which I return that (for instance the focus key, as explained in a previous post), the first action having 'none' key was triggered... (fixed, normally)

By the way, I have added libintl (used for NLS/i18n) to the android build. An unclean dump of my work tree (except the Wormux folder one should checkout from svn) is available here

I was also thinking of something that might be useful for some ports: if the application only reports errors to std{out,err}, maybe adding a JNI call to create a dialog (like the ones seen during first run) could be useful. Wormux has its own error display, so it doesn't matter for me.
kurosu
Experienced Developer
Experienced Developer
 
Posts: 94
Joined: Sat Jun 12, 2010 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Wed Aug 18, 2010 5:18 pm

F/Wormux ( 2712): Error in /home/adm/wormux/project/jni/application/tool/resource_manager.cpp:198 (Wormux svn) : ResourceManager: can't load profile ./data/wormux_default_android_config.xml

Still the same error
BTW can you please give me libintl and SDL_gfx so I'll include them to my GIT? The link you've posted before is to game data file.

BTW I've implemented on-screen keyboard, it's very crude though: alienblaster.apk
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Top

Re: SDL port for Android SDK/NDK 1.6

Postby kurosu » Wed Aug 18, 2010 6:14 pm

pelya wrote:F/Wormux ( 2712): Error in /home/adm/wormux/project/jni/application/tool/resource_manager.cpp:198 (Wormux svn) : ResourceManager: can't load profile ./data/wormux_default_android_config.xml


Again, sorry, you need to redownload both the apk and the data files, so simply wipe /sdcard/Wormux. Anyway, there was a showstopper bug in there: display wouldn't initialize properly for anything but 480x320.

For now, wormux outputs the generated files to /sdcard/Wormux/Wormux, so if you need to edit them, here there are. It's still not yet completely clear where I intend to put things though. May change, as I consider those versions unstable.

BTW can you please give me libintl and SDL_gfx so I'll include them to my GIT? The link you've posted before is to game data file.

Really? To save you some trouble, here's a link to just that, to unpack in project/jni of course. There are several twists though:
  • Android does not actually support locale (setlocale returns NULL for instance), so I configure intl to not rely on it, but the application must properly set env variables itself (ie LANG=fr or LANGUAGE=fr for instance). That's also a drawback, we don't know the actual OS locale.
  • I stripped most files unneeded for compilation, in particular licenses. You remember intl is from gettext, ie a GNU project? :mrgreen:

BTW I've implemented on-screen keyboard, it's very crude though: alienblaster.apk

I shall look at that.

edit: ok, this is your previous idea of overlaid controls, which doesn't appeal much to me. Besides, this means a bit too many updates, while I'm eager to propose this to a wider yet still computer-savvy community.
kurosu
Experienced Developer
Experienced Developer
 
Posts: 94
Joined: Sat Jun 12, 2010 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby kurosu » Wed Aug 18, 2010 7:14 pm

I have a report from an user experimenting with Wormux and my version of your SDL port, about the accelerometer. In SDL_androidinput.c, he mentions that this initialization is better:
static const float dx = 0.2, dy = 0.25, dz = 0.25;

But maybe this more related to the kind of precision Wormux requires compared to AlienBlaster & co.
kurosu
Experienced Developer
Experienced Developer
 
Posts: 94
Joined: Sat Jun 12, 2010 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby kurosu » Wed Aug 18, 2010 10:21 pm

About sdl_ttf and freetype, I don't know what you use, if you tested it etc, but I either use my own font, or I rely on fonts in /system/fonts
Using them allows to support some asian languages, but not adding a 3MB font file to the apk.
kurosu
Experienced Developer
Experienced Developer
 
Posts: 94
Joined: Sat Jun 12, 2010 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Thu Aug 19, 2010 11:06 am

Still does not start without SDCard, same error.
I've tried with SD card - gives 5 FPS on Evo, also requires alot of keys to play (and Evo has only 4 of them). Otherwise seems playable.

I haven't noticed images with complicated per-pixel transparency in the game - everything you need can be drawn by setting colorkey, and then setting per-image alpha, then you can use HW acceleration.
Only kaboom.png and smoke.png have per-pixel transparency, but since each animation frame have fixed transparency value they can be split to several images with constant per-image transparency (or just loaded to different SDL surfaces with some tricky routine).
Current on-screen keyboard covers all screen, and you won't be able to use mouse with it. I'm planning to add more config options, like smaller keyboard size, or switching it on/off with some HW key or from game itself.

Well anyway, I can publish that release you've made if you want, with comment that it requires SD card and HW keyboard.

The phone configurations may vary greatly - for example my Evo phone has 250 Mb free on internal storage, and my ADP1 phone has 60 Mb free and a wireless modem glued to SDcard slot (don't ask :roll: ).

Why don't they design all Android devices like this? Image I imagine some external USB keyboard with the big hole where you can click-insert your phone (just like you're inserting battery to the phone itself). Oh, it also can have huge external battery, to remedy the Evo's damn short worktime without charger.

Edit: I've included libintl and sdl_gfx to my Git, also I've added setting LANG variable from Java code. I also want to set USER variable to Google account user name, but I cannot find Java API to do that that works for 1.6 devices.
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 kurosu » Thu Aug 19, 2010 3:02 pm

pelya wrote:Still does not start without SDCard, same error.


OK, I shall test that then.

I've tried with SD card - gives 5 FPS on Evo


I think the more pixels it has to display, the slower it is. My wimpy Spica (ARMv6 1176 at 800Mhz) displays the game at 15-25fps, but it only has a 480x320 display (compared to 800x480). A Nexus One (ARMv7 at 1GHz) has equivalent performance to yours. A better GPU doesn't cut anything, CPU performance is mostly similar (roughly 50% performance I guess), so the screen size is the most prevalant performance parameter.

also requires alot of keys to play (and Evo has only 4 of them). Otherwise seems playable.

I've decided to use vol up/down as ctrl/shift. Because one can map any modifier+key as an action, if you have 2 more keys in addition to volume, this becomes num(no modifier,shift,ctrl)*(4-2)=6 actions instead of 4.

Did you notice you can tap at the bottom of the screen so as to display a menu bar, and then click on some of the icons to generate some actions? Help isn't ready to describe this, unfortunately...

I haven't noticed images with complicated per-pixel transparency in the game

There is though, untill I convert them manually:
  • map data is converted to ARGB8888 to RGB565 with colorkey (dropping the alpha blending smoothing display)
  • map data must be sometimes handled in software because:
    • we read its alpha channel to determine if a pixel is blocking
    • we read all of its data to compute a reduced view (the minimap)
    • we write to it to dig/darken the ground
    In particular, the minimap downsamples blocks of 64x64 pixels, and we must read the block pixels knowing their colorformat and produce pixels in the minimap with again expected colorformat, all by hand
  • We decorate some boxes such as the ingame menu and the minimap and to render this, we must:
    1. render the decoration onto the minimap with a particular function (playing with SDL_SRCALPHA and the way the SDL_SurfaceBlit are done doesn't work)
    2. render the output of this onto the screen
  • I haven't yet found a clean way to distinguish image we really need alpha blending from those where colorkey is ok

everything you need can be drawn by setting colorkey, and then setting per-image alpha, then you can use HW acceleration.

It's probably possible, but I still have to adapt step by step some of this code: we want the same codebase and this codebase shall also allow rendering in RGBA8888 with alphablending.

But all in all, it's not something I can solve quickly, nor that should hold me from releasing to people wanting to test it out. Indeed, to support some of the things you see, I had to deeply modify some part of the code, and it's a bit fragile now. So, the testing I envision is more about fixing the stuff I broke than improving performance.

But I really want to test the things you proposed. It's just I'm more worried about other things.

Only kaboom.png and smoke.png have per-pixel transparency, but since each animation frame have fixed transparency value they can be split to several images with constant per-image transparency (or just loaded to different SDL surfaces with some tricky routine).

You went quite deep into your study! There really are parts of the code I don't know well, so I can't comment on this very much.

Current on-screen keyboard covers all screen, and you won't be able to use mouse with it. I'm planning to add more config options, like smaller keyboard size, or switching it on/off with some HW key or from game itself.

I believe Wormux can dispend with such a keyboard:
  • If you have to use it, you loose in ergonomy what you win in additional actions available.
  • With accelerometer, all you have to map on HW keys are limited actions:
    • shoot, jump are required
    • it would be interesting to also have back jump, high jump and precise aiming (usually a modifier key + aim)

But the real reason i'm not planning to integrate it now is that it would require to update a working code and risk breaking things in it.

Well anyway, I can publish that release you've made if you want, with comment that it requires SD card and HW keyboard.

There's one more blocking issue to solve I think besides the debugging. Wormux controls are not natural, and there are many hidden things not obvious that help gameplay (see the post in the Wormux forum I linked earlier):
  • Clicks on the ingame menubar
  • Clicks on the minimap or a character
While people will be testing the game and reporting bugs, I'll try to see what can be done with the help. So I think it's not completely ready for prime time.

The phone configurations may vary greatly - for example my Evo phone has 250 Mb free on internal storage, and my ADP1 phone has 60 Mb free and a wireless modem glued to SDcard slot (don't ask :roll: ).

Why don't they design all Android devices like this? Image I imagine some external USB keyboard with the big hole where you can click-insert your phone (just like you're inserting battery to the phone itself). Oh, it also can have huge external battery, to remedy the Evo's damn short worktime without charger.


This underlines how Android vs iPhone is similar to PC vs console: consoles (and iPhones) have rather precise features, and so less things to handle.

Edit: I've included libintl and sdl_gfx to my Git, also I've added setting LANG variable from Java code. I also want to set USER variable to Google account user name, but I cannot find Java API to do that that works for 1.6 devices.

So the Java code does all the job, no need to go the JNI way? Fine with me, this part is probably rather small and non-intrusive, so I'll check out how you do that and merge the code.
kurosu
Experienced Developer
Experienced Developer
 
Posts: 94
Joined: Sat Jun 12, 2010 1:56 pm

Re: SDL port for Android SDK/NDK 1.6

Postby dxk22 » Thu Aug 19, 2010 3:49 pm

Hey pelya:

Just wanted first say, great job with this port! I am finding it very useful for the project I am working on.

However, I have been struggling to get the GL+SDL combo to work with OpenGL ES 2.0. No matter what I seem to try, any OpenGL 2 calls I make result in "called unimplemented OpenGL ES API" with this port. (I seem to have the NDK portion linked correctly with 2.0 as well). I think it may have to do with GLSurfaceView_SDL being only setup for ES1.1? Do you know how I might be able to modify this so that it works with 2.0? I tried simply changing the context initialization, but that didn't work either.

Thanks a bunch!
dxk22
Freshman
Freshman
 
Posts: 2
Joined: Thu Aug 19, 2010 3:45 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Thu Aug 19, 2010 5:09 pm

kurosu wrote:
Edit: I've included libintl and sdl_gfx to my Git, also I've added setting LANG variable from Java code. I also want to set USER variable to Google account user name, but I cannot find Java API to do that that works for 1.6 devices.

So the Java code does all the job, no need to go the JNI way? Fine with me, this part is probably rather small and non-intrusive, so I'll check out how you do that and merge the code.


Well it uses JNI anyway, it just gets the value from Java locale.

You can try to draw to lower screen resolution, say 320x240, and SDL will resize the picture using OpenGL - it will be fast but pixelated.

Also I think small on-screen arrow keys in the upper-right corner of screen won't hurt playability - I'll try to make on-screen keyboard configurable. People seem to hate accelerometer controls with OpenTyrian.

dxk22 wrote:However, I have been struggling to get the GL+SDL combo to work with OpenGL ES 2.0. No matter what I seem to try, any OpenGL 2 calls I make result in "called unimplemented OpenGL ES API" with this port. (I seem to have the NDK portion linked correctly with 2.0 as well). I think it may have to do with GLSurfaceView_SDL being only setup for ES1.1? Do you know how I might be able to modify this so that it works with 2.0? I tried simply changing the context initialization, but that didn't work either.


Check out NDK - there is example hello-gl2, compare it to my code and check what is missing.

There is one magic chunk of code inside that example:
Code: Select all
class GL2JNIView extends GLSurfaceView {
[.....]
    private void init(boolean translucent, int depth, int stencil) {
        [.....]
        /* Setup the context factory for 2.0 rendering.
         * See ContextFactory class definition below
         */
        setEGLContextFactory(new ContextFactory());
        [.....]
     }
[.....]
    private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
        private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
        public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
            Log.w(TAG, "creating OpenGL ES 2.0 context");
            checkEglError("Before eglCreateContext", egl);
            int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
            EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
            checkEglError("After eglCreateContext", egl);
            return context;
        }
       
        public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
            egl.eglDestroyContext(display, context);
        }
    }
[.....]
}


If you'll make it work please submit your changes back so I can add them to my GLSurfaceView_SDL.java with some optional compilation flag in ChangeAppSettings.

BTW can someone please draw a nicer font for on-screen keyboard for me?
Go to my GIT/project/sdl/fonteditor and launch editor.exe (yeah I've even compiled Win32 EXE for convenience).
Left-click puts line, right-click removes last line. Click on the right side of editor window to select different symbol to edit.

For now I need arrows drawn straight, and some simple nice pictograms to be used as keys - 8 are enough for now. In the future I'm planning to add full QWERTY keyboard, so it will become full ASCII font.

BTW did you notice that you can toggle auto-fire mode in OpenTyrian and Alien Blaster? Just slide your finger across Fire button until it changes color. Do you have any ideas how to make it more visible to user? Draw some hint when you're pressing Fire button? Or maybe make the pictogram rotating when finger moves, so the user will wonder what happens if it's rotated 90 degrees?
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 dxk22 » Thu Aug 19, 2010 6:16 pm

Thanks.... I have made those changes, however the emulator crashes after doing so. I wonder if it lacks 2.0 support? I am going to debug some more, and if I get something working I will post it.
dxk22
Freshman
Freshman
 
Posts: 2
Joined: Thu Aug 19, 2010 3:45 pm

Re: SDL port for Android SDK/NDK 1.6

Postby kurosu » Thu Aug 19, 2010 9:39 pm

pelya wrote:Edit: I've included libintl and sdl_gfx to my Git, also I've added setting LANG variable from Java code. I also want to set USER variable to Google account user name, but I cannot find Java API to do that that works for 1.6 devices.


In fact this won't completely work. setlocale(LC_ALL, "") resets to the default language. So a program that would set the language would either pass "" or the actual language. But with getenv/putenv, the original value is overwritten, and there's no way to retrieve except having specific code. It's therefore going to break most programs if they don't have such code.
kurosu
Experienced Developer
Experienced Developer
 
Posts: 94
Joined: Sat Jun 12, 2010 1:56 pm

Top
PreviousNext

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 8 guests