From acab37e20ddbee5022c57c55108542e9ef9af7db Mon Sep 17 00:00:00 2001 From: jbonnett92 Date: Tue, 10 Jun 2014 17:50:58 +0100 Subject: [PATCH 1/6] Update Main.java Added Library loader, to load a particular library depending on what OS the program is running on --- src/com/base/game/Main.java | 6 ++++++ 1 file changed, 6 insertions(+) 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(); From 38bfb6c124adffea46715758febf7a1208e71224 Mon Sep 17 00:00:00 2001 From: jbonnett92 Date: Tue, 10 Jun 2014 17:56:02 +0100 Subject: [PATCH 2/6] Create LibraryLoader.java Library loader class, to load a particular library depending on the OS running the program. This means you do not have to set the native library location for the lwjgl.jar. --- src/com/base/game/LibraryLoader.java | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/com/base/game/LibraryLoader.java diff --git a/src/com/base/game/LibraryLoader.java b/src/com/base/game/LibraryLoader.java new file mode 100644 index 0000000..30e95e8 --- /dev/null +++ b/src/com/base/game/LibraryLoader.java @@ -0,0 +1,40 @@ +package com.base.game; +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("natives/macosx"); + } else if(System.getProperty("os.name").equals("Linux")) { + addLibraryPath("natives/linux"); + } else { + addLibraryPath("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); + } + +} From e00d9ec502122fae0ad74a88dbfa877c0b23eaa6 Mon Sep 17 00:00:00 2001 From: jbonnett92 Date: Wed, 11 Jun 2014 19:35:55 +0100 Subject: [PATCH 3/6] Update LibraryLoader.java --- src/com/base/game/LibraryLoader.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/base/game/LibraryLoader.java b/src/com/base/game/LibraryLoader.java index 30e95e8..a363adb 100644 --- a/src/com/base/game/LibraryLoader.java +++ b/src/com/base/game/LibraryLoader.java @@ -7,11 +7,11 @@ public class LibraryLoader { public static void loadNativeLibrarys() throws Exception { if(System.getProperty("os.name").equals("Mac OS X")) { - addLibraryPath("natives/macosx"); + addLibraryPath("lib/natives/macosx"); } else if(System.getProperty("os.name").equals("Linux")) { - addLibraryPath("natives/linux"); + addLibraryPath("lib/natives/linux"); } else { - addLibraryPath("natives/windows"); + addLibraryPath("lib/natives/windows"); if(System.getProperty("os.arch").equals("amd64") || System.getProperty("os.arch").equals("x86_64")) { System.loadLibrary("OpenAL64"); } else { From 5900f069296f1b8a999377eb4b685aaa7e1ad021 Mon Sep 17 00:00:00 2001 From: jbonnett92 Date: Thu, 12 Jun 2014 09:11:21 +0100 Subject: [PATCH 4/6] Update LibraryLoader.java --- src/com/base/game/LibraryLoader.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/com/base/game/LibraryLoader.java b/src/com/base/game/LibraryLoader.java index a363adb..b76bf1a 100644 --- a/src/com/base/game/LibraryLoader.java +++ b/src/com/base/game/LibraryLoader.java @@ -10,6 +10,8 @@ public static void loadNativeLibrarys() throws Exception { 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")) { From 04420403c01a49e1bbdf1634c670f9153d124c15 Mon Sep 17 00:00:00 2001 From: jbonnett92 Date: Thu, 12 Jun 2014 09:15:53 +0100 Subject: [PATCH 5/6] Create LibraryLoader.java Moved from com.base.game... Allows you to automatically load native libraries rather than hard coding them into "lwjgl.jar" via native library location. --- src/com/base/engine/core/LibraryLoader.java | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/com/base/engine/core/LibraryLoader.java 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); + } + +} From 2e6eaa15ae1a3fd0443266479fe90c5cf52e7428 Mon Sep 17 00:00:00 2001 From: jbonnett92 Date: Thu, 12 Jun 2014 09:19:04 +0100 Subject: [PATCH 6/6] Delete LibraryLoader.java --- src/com/base/game/LibraryLoader.java | 42 ---------------------------- 1 file changed, 42 deletions(-) delete mode 100644 src/com/base/game/LibraryLoader.java diff --git a/src/com/base/game/LibraryLoader.java b/src/com/base/game/LibraryLoader.java deleted file mode 100644 index b76bf1a..0000000 --- a/src/com/base/game/LibraryLoader.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.base.game; -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); - } - -}