Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
make BASS not be constantly reloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
uwx committed Feb 1, 2016
1 parent 85fad17 commit 5178cb7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 64 deletions.
75 changes: 75 additions & 0 deletions BASSLoader.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions GameSparker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,7 @@ private void makeMenus() {
}

public GameSparker() {
BASSLoader.initializeBASS();
initApplet();
setBorder(BorderFactory.createLineBorder(Color.black));
//
Expand Down
67 changes: 3 additions & 64 deletions RadicalBASS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5178cb7

Please sign in to comment.