mod: updated to create/destroy architecture

This commit is contained in:
Brian Matzon 2002-09-03 18:54:40 +00:00
parent 760cda8c47
commit c08e72d615
4 changed files with 195 additions and 23 deletions

View file

@ -41,6 +41,8 @@ package org.lwjgl.openal;
* @version $Revision$
*/
public class ALC {
/** Has the ALC object been created? */
protected static boolean created;
/** Bad value */
public static final int INVALID = -1;
@ -92,19 +94,67 @@ public class ALC {
*/
public static final int OUT_OF_MEMORY = 0xA005;
static {
try {
System.loadLibrary(org.lwjgl.Sys.getLibraryName());
} catch (UnsatisfiedLinkError ule) {
System.out.println("Failed to load OpenAL library: " + org.lwjgl.Sys.getLibraryName());
ule.printStackTrace();
}
}
static {
initialize();
}
/** Creates a new instance of ALC */
public ALC() {
}
/**
* Override to provide any initialization code after creation.
*/
protected void init() {
}
/**
* Static initialization
*/
private static void initialize() {
System.loadLibrary(org.lwjgl.Sys.getLibraryName());
}
/**
* Creates the ALC instance
*
* @throws Exception if a failiure occured in the ALC creation process
*/
public void create() throws Exception {
if (created) {
return;
}
if (!nCreate()) {
throw new Exception("ALC instance could not be created.");
}
created = true;
init();
}
/**
* Native method to create ALC instance
*
* @return true if the ALC creation process succeeded
*/
protected native boolean nCreate();
/**
* Calls whatever destruction rutines that are needed
*/
public void destroy() {
if (!created) {
return;
}
created = false;
nDestroy();
}
/**
* Native method the destroy the ALC
*/
protected native void nDestroy();
/**
* Returns strings related to the context.
*

View file

@ -42,19 +42,70 @@
*/
public class ALUT {
static {
try {
System.loadLibrary(org.lwjgl.Sys.getLibraryName());
} catch (UnsatisfiedLinkError ule) {
System.out.println("Failed to load OpenAL library: " + org.lwjgl.Sys.getLibraryName());
ule.printStackTrace();
}
}
/** Has the ALUT object been created? */
protected static boolean created;
static {
initialize();
}
/** Creates a new instance of ALUT */
public ALUT() {
}
/**
* Override to provide any initialization code after creation.
*/
protected void init() {
}
/**
* Static initialization
*/
private static void initialize() {
System.loadLibrary(org.lwjgl.Sys.getLibraryName());
}
/**
* Creates the ALUT instance
*
* @throws Exception if a failiure occured in the ALUT creation process
*/
public void create() throws Exception {
if (created) {
return;
}
if (!nCreate()) {
throw new Exception("ALUT instance could not be created.");
}
created = true;
init();
}
/**
* Native method to create ALUT instance
*
* @return true if the ALUT creation process succeeded
*/
protected native boolean nCreate();
/**
* Calls whatever destruction rutines that are needed
*/
public void destroy() {
if (!created) {
return;
}
created = false;
nDestroy();
}
/**
* Native method the destroy the ALUT
*/
protected native void nDestroy();
/**
* Initializes the OpenAL engine
*

View file

@ -44,12 +44,63 @@
* @version $Revision$
*/
public abstract class BaseAL {
static {
try {
System.loadLibrary(org.lwjgl.Sys.getLibraryName());
} catch (UnsatisfiedLinkError ule) {
System.out.println("Failed to load OpenAL library: " + org.lwjgl.Sys.getLibraryName());
ule.printStackTrace();
/** Has the ALC object been created? */
protected static boolean created;
static {
initialize();
}
/**
* Override to provide any initialization code after creation.
*/
protected void init() {
}
/**
* Static initialization
*/
private static void initialize() {
System.loadLibrary(org.lwjgl.Sys.getLibraryName());
}
/**
* Creates the AL instance
*
* @throws Exception if a failiure occured in the AL creation process
*/
public void create() throws Exception {
if (created) {
return;
}
}
if (!nCreate()) {
throw new Exception("AL instance could not be created.");
}
created = true;
init();
}
/**
* Native method to create AL instance
*
* @return true if the AL creation process succeeded
*/
protected native boolean nCreate();
/**
* Calls whatever destruction rutines that are needed
*/
public void destroy() {
if (!created) {
return;
}
created = false;
nDestroy();
}
/**
* Native method the destroy the AL
*/
protected native void nDestroy();
}

View file

@ -71,8 +71,28 @@ public abstract class BasicTest {
*/
public BasicTest() {
al = new AL();
try {
al.create();
} catch (Exception e) {
e.printStackTrace();
return;
}
alc = new ALC();
try {
alc.create();
} catch (Exception e) {
e.printStackTrace();
return;
}
alut = new ALUT();
try {
alut.create();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
/**