diff --git a/src/com/base/engine/core/LibraryLoader.java b/src/com/base/engine/core/LibraryLoader.java new file mode 100644 index 0000000..f10ad25 --- /dev/null +++ b/src/com/base/engine/core/LibraryLoader.java @@ -0,0 +1,42 @@ +package com.base.engine.core; +import java.lang.reflect.Field; +import java.util.Arrays; + + +public class LibraryLoader { + + public static void loadNativeLibrarys() throws Exception { + if(System.getProperty("os.name").equals("Mac OS X")) { + addLibraryPath("lib/natives/macosx"); + } else if(System.getProperty("os.name").equals("Linux")) { + addLibraryPath("lib/natives/linux"); + } else if(System.getProperty("os.name").equals("Solaris")) { + addLibraryPath("lib/natives/solaris"); + } else { + addLibraryPath("lib/natives/windows"); + if(System.getProperty("os.arch").equals("amd64") || System.getProperty("os.arch").equals("x86_64")) { + System.loadLibrary("OpenAL64"); + } else { + System.loadLibrary("OpenAL32"); + } + } + } + + private static void addLibraryPath(String s) throws Exception { + final Field usr_paths_field = ClassLoader.class.getDeclaredField("usr_paths"); + usr_paths_field.setAccessible(true); + + final String[] paths = (String[]) usr_paths_field.get(null); + + for(String path : paths) { + if(path.equals(s)) { + return; + } + } + + final String[] new_paths = Arrays.copyOf(paths, paths.length + 1); + new_paths[paths.length - 1] = s; + usr_paths_field.set(null, new_paths); + } + +} diff --git a/src/com/base/game/Main.java b/src/com/base/game/Main.java index b18da7b..0ef7429 100644 --- a/src/com/base/game/Main.java +++ b/src/com/base/game/Main.java @@ -6,6 +6,12 @@ public class Main { public static void main(String[] args) { + try { + LibraryLoader.loadNativeLibrarys(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } CoreEngine engine = new CoreEngine(800, 600, 60, new TestGame()); engine.createWindow("3D Game Engine"); engine.start();