Hedgeroid_explained.wiki
changeset 127 5548319002e9
child 682 cc2971fe7264
equal deleted inserted replaced
126:e57ef70926d2 127:5548319002e9
       
     1 #summary This pages tries to explain the interesting aspects of the Android port
       
     2 
       
     3 Hedgewars for Android has several peculiarities and this page will try to explain what they are, what limitations they give and how I've 'solved' them.
       
     4 
       
     5 ==The normal way==
       
     6 
       
     7 The 'normal' way  of writing applications in Android is by using the Java language which runs in the Dalivk Virtual Machine. However there's an API which goes under the name of Java Native Interface(JNI), this basically gives a method of calling exported function from a library compile to native code, this C/C++/FreePascal
       
     8 Originally JNI in Android was meant to be used for performance critical operation like calculating psysics, because the overhead to make a call to some native code is very expensive and unless using native code really gives a huge benefit it isn't worth it. All of this is usable for developers using the 'Native Development Kit' (NDK) In newer versions of Android more functionality has been added to the NDK such as opengl 1.x/2.0 and with Gingerbread you can use almost all Android APIs. However there are a few reasons why I can not use this functionality.
       
     9 
       
    10 ==Problems with the NDK==
       
    11 
       
    12 The biggest problem with using the newer NDK supported by Gingerbread is the fact that not many people have Android devices with Gingerbread, meaning I can happily code using the new NDK but only a very small percentage of people can use the app, not a very realistic idea then.
       
    13 
       
    14 So we're stuck to using the older NDK, which is just fine as shown later on we can forward Java specific functionalities forward to the native side manually, how ever the NDK only supports C and C++ but the Hedgewars engine is written in FreePascal. Which comes down to the following:
       
    15 
       
    16 Where with C/C++ you write your code, run 'ndk-build' and after a few moments a working Android app pops out freepascal needed some more work. We need a crosscompiler, some utilities which link various, and figure out what libraries we can or cannot use.
       
    17 
       
    18 ==So what did we end up with?==
       
    19 
       
    20 We ended up with a fairly simple way of compiling the engine but we cannot use pthreads, because we rely on SDL we can use SDL Threads which helps.. A working LUA Library no problems there
       
    21 
       
    22 We also got an Official SDL port, however this one is still pretty rough, it hasn't been completed just yet however sound/visuals are working, which is the important bit. Altough one part of SDL wasn't ported yet, pelya the auther of the unofficial port has provided it for us, yey for him!
       
    23 
       
    24 All in all everything seems to work oke right now.
       
    25 
       
    26 This picture tries to describe how information flows through the three levels (Android, C/C++ wrapper, hedgewars engine)
       
    27 
       
    28 http://www.xelification.com/tmp/hedgewarsflow.png
       
    29 
       
    30 ==Short list on what gets handled where==
       
    31 
       
    32 Android
       
    33   * Opengl context creation
       
    34   * Touch/key events generation
       
    35   * Audio playback
       
    36   * Front end
       
    37 
       
    38 SDL
       
    39   * Touch/key events normalisation
       
    40   * Wrapper for audio playback
       
    41 
       
    42 Hedgewars Engine
       
    43   * Touch/key events converted to hedgewars actions