Hedgeroid_explained.wiki
author Wuzzy
Sat, 12 Oct 2019 16:39:38 +0100
changeset 2036 dedce712a325
parent 762 5d1d8c47e2c1
child 2046 51aee3026687
permissions -rw-r--r--
Sounds: Add a couple of new sounds
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
     1
#summary This pages tries to explain the interesting aspects of the Android port
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
     2
762
5d1d8c47e2c1 Hedgeroid_explained: Add title
Wuzzy
parents: 682
diff changeset
     3
= Hedgeroid =
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
     4
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.
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
     5
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
     6
==The normal way==
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
     7
682
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
     8
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.
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
     9
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
    10
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.
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    11
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    12
==Problems with the NDK==
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    13
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    14
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.
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    15
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    16
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:
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    17
682
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
    18
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.
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    19
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    20
==So what did we end up with?==
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    21
682
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
    22
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.
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    23
682
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
    24
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 author of the unofficial port has provided it for us, yay for him!
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    25
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    26
All in all everything seems to work oke right now.
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    27
682
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
    28
This picture tries to describe how information flows through the three levels (Android, C/C++ wrapper, hedgewars engine):
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    29
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    30
http://www.xelification.com/tmp/hedgewarsflow.png
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    31
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    32
==Short list on what gets handled where==
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    33
682
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
    34
 * Android
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    35
  * Opengl context creation
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    36
  * Touch/key events generation
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    37
  * Audio playback
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    38
  * Front end
682
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
    39
 * SDL
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    40
  * Touch/key events normalisation
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    41
  * Wrapper for audio playback
682
cc2971fe7264 Copy-editing
Wuzzy
parents: 127
diff changeset
    42
 * Hedgewars engine
127
5548319002e9 Little explanation of hedgeroids
richarddeurtje@gmail.com
parents:
diff changeset
    43
  * Touch/key events converted to hedgewars actions