From 5178cb7e387f8c521b7e72731b5ec169ecffd14a Mon Sep 17 00:00:00 2001 From: chrishansen69 Date: Mon, 1 Feb 2016 20:46:55 -0200 Subject: [PATCH] make BASS not be constantly reloaded --- BASSLoader.java | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ GameSparker.java | 1 + RadicalBASS.java | 67 ++---------------------------------------- 3 files changed, 79 insertions(+), 64 deletions(-) create mode 100644 BASSLoader.java diff --git a/BASSLoader.java b/BASSLoader.java new file mode 100644 index 0000000..b4e22de --- /dev/null +++ b/BASSLoader.java @@ -0,0 +1,75 @@ +import java.lang.reflect.Field; + +import jouvieje.bass.BassInit; +import jouvieje.bass.exceptions.BassException; + +public class BASSLoader { + + private static final String os = System.getProperty("os.name").toLowerCase(); + private static final String x64 = System.getProperty("sun.arch.data.model").equals("64") ? "64" : "32"; + private static final boolean isUnix = os.indexOf("nix") == 0 || os.indexOf("nux") == 0; + private static final boolean isWindows = os.indexOf("win") == 0; + private static final boolean isMac = os.indexOf("mac") == 0; + private static final String workingDirectory = "."; + + static void initializeBASS() { + System.out.println(System.getProperty("java.library.path")); + + try { + if (isUnix) { + System.out.println("running on a unix system"); + appendToPath(workingDirectory + "/libraries/dlls/linux" + x64 + "/"); + } else if (isMac) { + System.out.println("running on a mac system"); + appendToPath(workingDirectory + "/libraries/dlls/mac/"); + } else if (isWindows) { + System.out.println("running on a windows system"); + appendToPath(workingDirectory + "\\libraries\\dlls\\win" + x64 + "\\"); + } + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + } + + init(); + } + + //private static final String workingDirectory = System.getProperty("user.dir"); + + private static void appendToPath(final String s) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + System.setProperty( "java.library.path", System.getProperty("java.library.path") + (isWindows ? ";" : ":") + s ); + + Field fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" ); + fieldSysPath.setAccessible( true ); + fieldSysPath.set( null, null ); + } + + + private static void init() { + /* + * NativeBass Init + */ + try { + BassInit.DEBUG = true; + BassInit.loadLibraries(); + } catch (final BassException e) { + printfExit("NativeBass error! %s\n", e.getMessage()); + return; + } + + /* + * Checking NativeBass version + */ + if (BassInit.NATIVEBASS_LIBRARY_VERSION() != BassInit.NATIVEBASS_JAR_VERSION()) { + printfExit("Error! NativeBass library version (%08x) is different to jar version (%08x)\n", BassInit.NATIVEBASS_LIBRARY_VERSION(), BassInit.NATIVEBASS_JAR_VERSION()); + return; + } + + /*==================================================*/ + + RadicalBASS.init = true; + } + + private static final void printfExit(final String format, final Object... args) { + String s = String.format(format, args); + System.out.println(s); + } +} diff --git a/GameSparker.java b/GameSparker.java index 62ee30b..46a7666 100644 --- a/GameSparker.java +++ b/GameSparker.java @@ -1667,6 +1667,7 @@ private void makeMenus() { } public GameSparker() { + BASSLoader.initializeBASS(); initApplet(); setBorder(BorderFactory.createLineBorder(Color.black)); // diff --git a/RadicalBASS.java b/RadicalBASS.java index a3991cf..7623771 100644 --- a/RadicalBASS.java +++ b/RadicalBASS.java @@ -48,15 +48,12 @@ private final void error(final String text) { } private final void printfExit(final String format, final Object... args) { - //String s = String.format(format, args); - //JOptionPane.showMessageDialog(this, s); + String s = String.format(format, args); + System.out.println(s); end(); - //try { - // System.exit(0); - //} catch(SecurityException e) {}; } - private boolean init = false; + static boolean init = false; private boolean deinit = false; private final int WIDTH = 600; //Display width @@ -81,31 +78,6 @@ public void SYNCPROC(final HSYNC handle, final int channel, final int data, fina } }; - public void init() { - /* - * NativeBass Init - */ - try { - BassInit.DEBUG = true; - BassInit.loadLibraries(); - } catch (final BassException e) { - printfExit("NativeBass error! %s\n", e.getMessage()); - return; - } - - /* - * Checking NativeBass version - */ - if (BassInit.NATIVEBASS_LIBRARY_VERSION() != BassInit.NATIVEBASS_JAR_VERSION()) { - printfExit("Error! NativeBass library version (%08x) is different to jar version (%08x)\n", BassInit.NATIVEBASS_LIBRARY_VERSION(), BassInit.NATIVEBASS_JAR_VERSION()); - return; - } - - /*==================================================*/ - - init = true; - } - public void run() { if (!init) return; @@ -253,42 +225,9 @@ private int getIndexColor(final int index) { public RadicalBASS(final File songFile) { file = songFile; - System.out.println(System.getProperty("java.library.path")); - - try { - if (isUnix) { - System.out.println("running on a unix system"); - appendToPath(workingDirectory + "/libraries/dlls/linux" + x64 + "/"); - } else if (isMac) { - System.out.println("running on a mac system"); - appendToPath(workingDirectory + "/libraries/dlls/mac/"); - } else if (isWindows) { - System.out.println("running on a windows system"); - appendToPath(workingDirectory + "\\libraries\\dlls\\win" + x64 + "\\"); - } - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - } - - init(); //run(); } - private static final String os = System.getProperty("os.name").toLowerCase(); - private static final String x64 = System.getProperty("sun.arch.data.model").equals("64") ? "64" : "32"; - private static final boolean isUnix = os.indexOf("nix") == 0 || os.indexOf("nux") == 0; - private static final boolean isWindows = os.indexOf("win") == 0; - private static final boolean isMac = os.indexOf("mac") == 0; - private static final String workingDirectory = "."; - //private static final String workingDirectory = System.getProperty("user.dir"); - - private static void appendToPath(final String s) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - System.setProperty( "java.library.path", System.getProperty("java.library.path") + (isWindows ? ";" : ":") + s ); - - Field fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" ); - fieldSysPath.setAccessible( true ); - fieldSysPath.set( null, null ); - } - @Override public int getType() { // TODO Auto-generated method stub