aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/sound
diff options
context:
space:
mode:
authorCarsten Weisse <[email protected]>2006-12-08 18:13:45 +0000
committerCarsten Weisse <[email protected]>2006-12-08 18:13:45 +0000
commit2a660035e89e6914e2485efad187636008bdc664 (patch)
tree515c20814938c42e60affefb680345c677abd274 /src/jake2/sound
parente862a6fab0809a695cc4cf8fa12ce49c723dafad (diff)
this is a hack for linux open the OpenAL device only once and never close at runtime of the whole game
Diffstat (limited to 'src/jake2/sound')
-rw-r--r--src/jake2/sound/joal/ALut.java69
-rw-r--r--src/jake2/sound/joal/JOALSoundImpl.java13
2 files changed, 11 insertions, 71 deletions
diff --git a/src/jake2/sound/joal/ALut.java b/src/jake2/sound/joal/ALut.java
deleted file mode 100644
index 7d419f7..0000000
--- a/src/jake2/sound/joal/ALut.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package jake2.sound.joal;
-
-
-import net.java.games.joal.*;
-
-/**
- * @author Athomas Goldberg
- *
- */
-public final class ALut {
-
- private static ALC alc;
- private static ALCdevice device;
- private static ALCcontext context;
- private static Thread initializingThread;
-
- private ALut() { }
-
- /** Initializes the OpenAL Utility Toolkit, creates an OpenAL
- context and makes it current on the current thread. The ALut may
- only be initialized on one thread at any given time. */
- public static synchronized void alutInit() throws ALException {
- if (context != null) {
- throw new ALException("Already initialized on thread " + initializingThread.getName());
- }
- if (alc == null) {
- alc = ALFactory.getALC();
- }
- String deviceName = null;
- ALCdevice d = alc.alcOpenDevice(deviceName);
- if (d == null) {
- throw new ALException("Error opening default OpenAL device");
- }
- ALCcontext c = alc.alcCreateContext(d, null);
- if (c == null) {
- alc.alcCloseDevice(d);
- throw new ALException("Error creating OpenAL context");
- }
- alc.alcMakeContextCurrent(c);
- if (alc.alcGetError(d) != 0) {
- alc.alcDestroyContext(c);
- alc.alcCloseDevice(d);
- throw new ALException("Error making OpenAL context current");
- }
- // Fully initialized; finish setup
- device = d;
- context = c;
- initializingThread = Thread.currentThread();
- }
-
- /** Shuts down the OpenAL Utility Toolkit; releases and destroys the
- internal OpenAL context and closes the output device. Must be
- called from the same thread as alutInit(). Most applications
- should not need to call this; only those which wish to toggle
- sound on / off at run time by initializing and un-initializing
- OpenAL need to call it. */
- public static synchronized void alutExit() throws ALException {
- if (context == null) {
- throw new ALException("Not initialized");
- }
- alc.alcMakeContextCurrent(null);
- alc.alcDestroyContext(context);
- alc.alcCloseDevice(device);
- context = null;
- device = null;
- initializingThread = null;
- }
-
-}
diff --git a/src/jake2/sound/joal/JOALSoundImpl.java b/src/jake2/sound/joal/JOALSoundImpl.java
index 2bbf3d7..5d84580 100644
--- a/src/jake2/sound/joal/JOALSoundImpl.java
+++ b/src/jake2/sound/joal/JOALSoundImpl.java
@@ -18,6 +18,7 @@ import java.nio.*;
import net.java.games.joal.*;
import net.java.games.joal.eax.EAX;
import net.java.games.joal.eax.EAXFactory;
+import net.java.games.joal.util.ALut;
/**
* JOALSoundImpl
@@ -35,9 +36,12 @@ public final class JOALSoundImpl implements Sound {
cvar_t s_volume;
private int[] buffers = new int[MAX_SFX + STREAM_QUEUE];
+
+ private boolean initialized;
private JOALSoundImpl() {
// singleton
+ this.initialized = false;
}
/* (non-Javadoc)
@@ -46,7 +50,11 @@ public final class JOALSoundImpl implements Sound {
public boolean Init() {
try {
- ALut.alutInit();
+ // TODO this a linux hack
+ if (!initialized) {
+ ALut.alutInit();
+ initialized = true;
+ }
al = ALFactory.getAL();
alc = ALFactory.getALC();
checkError();
@@ -151,7 +159,8 @@ public final class JOALSoundImpl implements Sound {
StopAllSounds();
Channel.shutdown();
al.alDeleteBuffers(buffers.length, buffers, 0);
- ALut.alutExit();
+ // TODO this is a linux hack
+ // ALut.alutExit();
Cmd.RemoveCommand("play");
Cmd.RemoveCommand("stopsound");