project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Flib.java
branchhedgeroid
changeset 15534 45d6806548e9
parent 10017 de822cd3df3a
equal deleted inserted replaced
15533:fb23e49b2d4e 15534:45d6806548e9
    25 
    25 
    26 import com.sun.jna.Library;
    26 import com.sun.jna.Library;
    27 import com.sun.jna.Native;
    27 import com.sun.jna.Native;
    28 
    28 
    29 public class Flib {
    29 public class Flib {
    30     static {
    30     protected final static String[] libs = {
    31         System.loadLibrary("SDL");
    31         "SDL2",
    32         System.loadLibrary("SDL_net");
    32         "SDL2_net",
       
    33     };
       
    34 
       
    35     static{
       
    36         for (String l : libs) {
       
    37             try {
       
    38                 android.util.Log.d("org.hedgewars.hedgeroid.frontlib.Flib", "Hedgewars (class Flib) is attempting to load library '" + l + "' ...");
       
    39                 System.loadLibrary(l);
       
    40                 android.util.Log.d("org.hedgewars.hedgeroid.frontlib.Flib", "Hedgewars (class Flib) successfully loaded library '" + l + "'.");
       
    41             } catch (Exception ex) {
       
    42                 android.util.Log.e("org.hedgewars.hedgeroid.frontlib.Flib", "Hedgewars (class Flib) failed to load library '" + l + "':" + ex.getMessage());
       
    43                 throw ex;
       
    44             }
       
    45         }
    33         System.setProperty("jna.encoding", "UTF8"); // Ugly global setting, but it seems JNA doesn't allow setting this per-library...
    46         System.setProperty("jna.encoding", "UTF8"); // Ugly global setting, but it seems JNA doesn't allow setting this per-library...
    34     }
    47     }
    35     public static final Frontlib INSTANCE = (Frontlib)Native.loadLibrary("frontlib", Frontlib.class, Collections.singletonMap(Library.OPTION_TYPE_MAPPER, AndroidTypeMapper.INSTANCE));
    48     public static final Frontlib INSTANCE;
    36 
    49 
    37     static {
    50     static {
       
    51         String l = "frontlib";
       
    52         try {
       
    53             android.util.Log.d("org.hedgewars.hedgeroid.frontlib.Flib", "Hedgewars (class Flib) is attempting to singleton-load library '" + l + "' ...");
       
    54             INSTANCE = (Frontlib)Native.loadLibrary(l, Frontlib.class, Collections.singletonMap(Library.OPTION_TYPE_MAPPER, AndroidTypeMapper.INSTANCE));
       
    55             android.util.Log.d("org.hedgewars.hedgeroid.frontlib.Flib", "Hedgewars (class Flib) successfully loaded library '" + l + "'.");
       
    56         } catch (Exception ex) {
       
    57             android.util.Log.e("org.hedgewars.hedgeroid.frontlib.Flib", "Hedgewars (class Flib) failed to load library '" + l + "':" + ex.getMessage());
       
    58             throw ex;
       
    59         }
       
    60 
    38         // We'll just do it here and never quit it again...
    61         // We'll just do it here and never quit it again...
    39         if(Flib.INSTANCE.flib_init() != 0) {
    62         if(Flib.INSTANCE.flib_init() != 0) {
    40             throw new RuntimeException("Unable to initialize frontlib");
    63             throw new RuntimeException("Unable to initialize frontlib");
    41         }
    64         }
    42     }
    65     }