http://code.google.com/p/nullpomino/source/detail?r=884
Added:
/branches/nm8/data/lib/gluegen-rt.dll
/branches/nm8/data/lib/gluegen.jar
/branches/nm8/data/lib/joal.dll
/branches/nm8/data/lib/joal.jar
/branches/nm8/data/lib/wrap_oal.dll
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/joal
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/joal/JOALSound.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/joal/JOALSoundProvider.java
Modified:
/branches/nm8/data/xml/configtool.xml
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/javasound/JSNFSound.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/lwjglal/LWJGLALSoundProvider.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/framework/NFSystem.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/niftygui/NFInputSystem.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/slick/framework/SlickNFSoundProvider.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/slick/framework/SlickNFSystem.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/swing/framework/SwingNFSystem.java
/branches/nm8/src/cx/it/nullpo/nm8/neuro/core/NEUROCore.java
/branches/nm8/src/cx/it/nullpo/nm8/tool/configtool/ConfigTool.java
/branches/nm8/src/cx/it/nullpo/nm8/util/NGlobalConfig.java
=======================================
--- /dev/null
+++ /branches/nm8/data/lib/gluegen-rt.dll Thu Nov 17 23:26:52 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /branches/nm8/data/lib/gluegen.jar Thu Nov 17 23:26:52 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /branches/nm8/data/lib/joal.dll Thu Nov 17 23:26:52 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /branches/nm8/data/lib/joal.jar Thu Nov 17 23:26:52 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /branches/nm8/data/lib/wrap_oal.dll Thu Nov 17 23:26:52 2011
Binary file, no diff available.
=======================================
--- /dev/null
+++ /branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/joal/JOALSound.java
Thu Nov 17 23:26:52 2011
@@ -0,0 +1,80 @@
+package cx.it.nullpo.nm8.gui.common.sound.joal;
+
+import cx.it.nullpo.nm8.gui.framework.NFSound;
+
+/**
+ * OpenAL (JOAL backend) implementation of NFSound.
+ * Please note this class does NOT handle most actions.
+ * Most actions are handled by JOALSoundProvider, the owner of this class.
+ */
+public class JOALSound implements NFSound {
+ private static final long serialVersionUID = -7435493109899815153L;
+
+ /** Owner of this class */
+ protected JOALSoundProvider owner = null;
+
+ /** true if disposed */
+ protected boolean isDisposed = false;
+
+ /** Buffers hold sound data */
+ protected int buffer;
+
+ /** Current Volume */
+ protected float currentVolume = 1f;
+
+ /** Current Pitch */
+ protected float currentPitch = 1f;
+
+ /**
+ * Constructor
+ * @param owner JOALSoundProvider
+ * @param buffer Buffer
+ */
+ public JOALSound(JOALSoundProvider owner, int buffer) {
+ this.owner = owner;
+ this.buffer = buffer;
+ }
+
+ public void play() {
+ owner.playSound(this, false);
+ }
+
+ public void loop() {
+ owner.playSound(this, true);
+ }
+
+ public void stop() {
+ owner.stopSound(this);
+ }
+
+ public boolean isPlaying() {
+ return owner.isPlaying(this);
+ }
+
+ public void setVolume(float volume) {
+ currentVolume = volume;
+ }
+
+ public float getVolume() {
+ return currentVolume;
+ }
+
+ public void setPitch(float pitch) {
+ currentPitch = pitch;
+ }
+
+ public float getPitch() {
+ return currentPitch;
+ }
+
+ public void dispose() {
+ if(!isDisposed) {
+ owner.al.alDeleteBuffers(1, new int[] {buffer}, 0);
+ isDisposed = true;
+ }
+ }
+
+ public int getBuffer() {
+ return buffer;
+ }
+}
=======================================
--- /dev/null
+++
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/joal/JOALSoundProvider.java
Thu Nov 17 23:26:52 2011
@@ -0,0 +1,396 @@
+package cx.it.nullpo.nm8.gui.common.sound.joal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.jogamp.openal.AL;
+import com.jogamp.openal.ALC;
+import com.jogamp.openal.ALCcontext;
+import com.jogamp.openal.ALCdevice;
+import com.jogamp.openal.ALException;
+import com.jogamp.openal.ALFactory;
+import com.jogamp.openal.util.ALut;
+
+import cx.it.nullpo.nm8.gui.framework.NFSound;
+import cx.it.nullpo.nm8.gui.framework.NFSoundProvider;
+import cx.it.nullpo.nm8.gui.framework.NFSystem;
+
+/**
+ * A NFSoundProvider that creates sound from OpenAL (Uses JOAL backend)
+ */
+public class JOALSoundProvider extends NFSoundProvider {
+ static protected final long serialVersionUID = -7684279361068321760L;
+
+ /** Log */
+ private Log log = LogFactory.getLog(JOALSoundProvider.class);
+
+ /** Number of sources to create */
+ protected static final int MAX_SOURCE = 64;
+
+ /** ALC: This object is used to access most of the OpenAL context
functionality. */
+ protected ALC alc;
+ /** AL: This object is used to access most of the OpenAL functionality. */
+ protected AL al;
+
+ /** List of JOALSound that are created from this class */
+ protected List<JOALSound> soundList = Collections.synchronizedList(new
ArrayList<JOALSound>());
+
+ /** Sources are points emitting sound. */
+ protected List<Integer> sourceList = Collections.synchronizedList(new
ArrayList<Integer>());
+
+ /** Position of the source sounds. */
+ protected float[] sourcePos = { 0.0f, 0.0f, 0.0f };
+ /** Velocity of the source sounds. */
+ protected float[] sourceVel = { 0.0f, 0.0f, 0.0f };
+ /** Position of the listener. */
+ protected float[] listenerPos = { 0.0f, 0.0f, 0.0f };
+ /** Velocity of the listener. */
+ protected float[] listenerVel = { 0.0f, 0.0f, 0.0f };
+ /** Orientation of the listener. (first 3 elements are "at", second 3
are "up") */
+ protected float[] listenerOri = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };
+
+ /**
+ * Constructor
+ */
+ public JOALSoundProvider() {
+ initOpenAL();
+ }
+
+ /**
+ * Return the AL error as a String.
+ * @param err AL error code
+ * @return AL error as a String
+ */
+ public static String getALErrorString(int err) {
+ switch (err) {
+ case AL.AL_NO_ERROR:
+ return "AL_NO_ERROR";
+ case AL.AL_INVALID_ENUM:
+ return "AL_INVALID_ENUM";
+ case AL.AL_INVALID_VALUE:
+ return "AL_INVALID_VALUE";
+ case AL.AL_INVALID_OPERATION:
+ return "AL_INVALID_OPERATION";
+ case AL.AL_OUT_OF_MEMORY:
+ return "AL_OUT_OF_MEMORY";
+ default:
+ return "Unknown AL Error Code (" + err + ")";
+ }
+ }
+
+ /**
+ * Return the ALC error as a String.
+ * @param err ALC error code
+ * @return ALC error as a String
+ */
+ public static String getALCErrorString(int err) {
+ switch (err) {
+ case ALC.ALC_NO_ERROR:
+ return "AL_NO_ERROR";
+ case ALC.ALC_INVALID_DEVICE:
+ return "ALC_INVALID_DEVICE";
+ case ALC.ALC_INVALID_CONTEXT:
+ return "ALC_INVALID_CONTEXT";
+ case ALC.ALC_INVALID_ENUM:
+ return "ALC_INVALID_ENUM";
+ case ALC.ALC_INVALID_VALUE:
+ return "ALC_INVALID_VALUE";
+ case ALC.ALC_OUT_OF_MEMORY:
+ return "ALC_OUT_OF_MEMORY";
+ default:
+ return "Unknown ALC Error Code (" + err + ")";
+ }
+ }
+
+ /**
+ * Init OpenAL
+ */
+ protected void initOpenAL() {
+ alc = ALFactory.getALC();
+ al = ALFactory.getAL();
+
+ // Get handle to default device.
+ ALCdevice device = alc.alcOpenDevice(null);
+ if(device == null) {
+ throw new ALException("OpenAL device is not available");
+ }
+
+ String deviceSpecifier = alc.alcGetString(device,
ALC.ALC_DEVICE_SPECIFIER);
+ if(deviceSpecifier == null) {
+ log.warn("Can't get specifier for default OpenAL device");
+ } else {
+ log.trace("Using device " + deviceSpecifier);
+ }
+
+ // Create audio context.
+ ALCcontext context = alc.alcCreateContext(device, null);
+ if(context == null) {
+ throw new ALException("Error creating OpenAL context");
+ }
+
+ // Set active context.
+ alc.alcMakeContextCurrent(context);
+
+ // Create sources
+ createSources();
+ }
+
+ /**
+ * Generate sources
+ */
+ protected void createSources() {
+ synchronized (sourceList) {
+ try {
+ while(sourceList.size() < MAX_SOURCE) {
+ int[] source = new int[1];
+ al.alGenSources(1, source, 0);
+
+ if(al.alGetError() != AL.AL_NO_ERROR) {
+ break;
+ }
+
+ al.alSourcef(source[0], AL.AL_PITCH, 1.0f);
+ al.alSourcef(source[0], AL.AL_GAIN, 1.0f);
+ al.alSourcefv(source[0], AL.AL_POSITION, sourcePos, 0);
+ al.alSourcefv(source[0], AL.AL_VELOCITY, sourceVel, 0);
+
+ sourceList.add(source[0]);
+ }
+ } catch (Throwable e) {}
+
+ log.info(sourceList.size() + " OpenAL sources created");
+ }
+
+ al.alListenerfv(AL.AL_POSITION, listenerPos, 0);
+ al.alListenerfv(AL.AL_VELOCITY, listenerVel, 0);
+ al.alListenerfv(AL.AL_ORIENTATION, listenerOri, 0);
+ }
+
+ /**
+ * Get a free (stopped) source
+ * @return A free (stopped) source, or -1 if all of them are currently
used
+ */
+ protected int getFreeSource() {
+ synchronized (sourceList) {
+ Iterator<Integer> it = sourceList.iterator();
+
+ while(it.hasNext()) {
+ Integer source = it.next();
+ int[] state = new int[1];
+ al.alGetSourcei(source, AL.AL_SOURCE_STATE, state, 0);
+
+ if((state[0] == AL.AL_INITIAL) || (state[0] == AL.AL_STOPPED)) {
+ return source;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ /**
+ * Get a list of sources by using buffer
+ * @param buffer Buffer
+ * @return A list of sources
+ */
+ protected List<Integer> getSourceListByBuffer(int buffer) {
+ List<Integer> list = new ArrayList<Integer>();
+
+ synchronized (sourceList) {
+ Iterator<Integer> it = sourceList.iterator();
+
+ while(it.hasNext()) {
+ Integer source = it.next();
+ int[] state = new int[1];
+ al.alGetSourcei(source, AL.AL_SOURCE_STATE, state, 0);
+
+ if((state[0] == AL.AL_PLAYING) || (state[0] == AL.AL_PAUSED)) {
+ int[] bufferID = new int[1];
+ al.alGetSourcei(source, AL.AL_BUFFER, bufferID, 0);
+
+ if(bufferID[0] == buffer) {
+ list.add(source);
+ }
+ }
+ }
+ }
+
+ return list;
+ }
+
+ /**
+ * Attempt to play sound
+ * @param sound Sound to play
+ * @param loop true to loop forever
+ */
+ public void playSound(JOALSound sound, boolean loop) {
+ int source = getFreeSource();
+ if(source == -1) return;
+ int buffer = sound.getBuffer();
+
+ al.alSourcei(source, AL.AL_BUFFER, buffer);
+ al.alSourcef(source, AL.AL_PITCH, sound.getPitch());
+ al.alSourcef(source, AL.AL_GAIN, sound.getVolume());
+ al.alSourcei(source, AL.AL_LOOPING, (loop ? AL.AL_TRUE : AL.AL_FALSE));
+
+ al.alSourcePlay(source);
+ }
+
+ /**
+ * Stop sound
+ * @param sound Sound to stop
+ */
+ public void stopSound(JOALSound sound) {
+ List<Integer> list = getSourceListByBuffer(sound.getBuffer());
+
+ Iterator<Integer> it = list.iterator();
+ while(it.hasNext()) {
+ Integer source = it.next();
+ al.alSourceStop(source);
+ }
+ }
+
+ /**
+ * Check if specified sound is playing
+ * @param sound Sound
+ * @return true if the sound is playing
+ */
+ public boolean isPlaying(JOALSound sound) {
+ synchronized (sourceList) {
+ Iterator<Integer> it = sourceList.iterator();
+
+ while(it.hasNext()) {
+ Integer source = it.next();
+ int[] state = new int[1];
+ al.alGetSourcei(source, AL.AL_SOURCE_STATE, state, 0);
+
+ if((state[0] == AL.AL_PLAYING) || (state[0] == AL.AL_PAUSED)) {
+ int[] bufferID = new int[1];
+ al.alGetSourcei(source, AL.AL_BUFFER, bufferID, 0);
+
+ if(bufferID[0] == sound.getBuffer()) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public NFSound loadSound(String filename) throws IOException {
+ // Variables to load into.
+ int[] format = new int[1];
+ int[] size = new int[1];
+ ByteBuffer[] data = new ByteBuffer[1];
+ int[] freq = new int[1];
+ int[] loop = new int[1];
+ int[] buffer = new int[1];
+
+ // Load wav data from a file
+ try {
+ ALut.alutLoadWAVFile(filename, format, data, size, freq, loop);
+ } catch (ALException e) {
+ throw new IOException("Failed to load wave file from " + filename, e);
+ }
+
+ // Load wav data into buffers.
+ al.alGenBuffers(1, buffer, 0);
+ if(al.alGetError() != AL.AL_NO_ERROR) {
+ throw new ALException("Cannot create buffer to load wave data (" +
getALErrorString(al.alGetError()) + ")");
+ }
+ al.alBufferData(buffer[0], format[0], data[0], size[0], freq[0]);
+
+ return new JOALSound(this, buffer[0]);
+ }
+
+ public NFSound loadSound(URL url) throws IOException {
+ // Variables to load into.
+ int[] format = new int[1];
+ int[] size = new int[1];
+ ByteBuffer[] data = new ByteBuffer[1];
+ int[] freq = new int[1];
+ int[] loop = new int[1];
+ int[] buffer = new int[1];
+
+ // Load wav data from a URL (using InputStream)
+ InputStream in = url.openStream();
+ try {
+ ALut.alutLoadWAVFile(in, format, data, size, freq, loop);
+ } catch (ALException e) {
+ throw new IOException("Failed to load wave file from " + url, e);
+ }
+ in.close();
+
+ // Load wav data into buffers.
+ al.alGenBuffers(1, buffer, 0);
+ if(al.alGetError() != AL.AL_NO_ERROR) {
+ throw new ALException("Cannot create buffer to load wave data (" +
getALErrorString(al.alGetError()) + ")");
+ }
+ al.alBufferData(buffer[0], format[0], data[0], size[0], freq[0]);
+
+ return new JOALSound(this, buffer[0]);
+ }
+
+ @Override
+ public String getName() {
+ return "JOAL-OpenAL";
+ }
+
+ @Override
+ public int getSoundProviderType() {
+ return NFSystem.SOUND_PROVIDER_OPENAL_LWJGL;
+ }
+
+ public int getNumberOfSoundLoaded() {
+ return soundList.size();
+ }
+
+ public void dispose() {
+ // Release all buffer data
+ synchronized (soundList) {
+ Iterator<JOALSound> it = soundList.iterator();
+ while(it.hasNext()) {
+ it.next().dispose();
+ it.remove();
+ }
+ }
+
+ // Release all source data
+ synchronized (sourceList) {
+ Iterator<Integer> it = sourceList.iterator();
+ while(it.hasNext()) {
+ al.alDeleteSources(1, new int[] {it.next().intValue()}, 0);
+ it.remove();
+ }
+ }
+
+ // Close the OpenAL
+ ALCcontext curContext;
+ ALCdevice curDevice;
+
+ // Get the current context.
+ curContext = alc.alcGetCurrentContext();
+
+ // Get the device used by that context.
+ curDevice = alc.alcGetContextsDevice(curContext);
+
+ // Reset the current context to NULL.
+ alc.alcMakeContextCurrent(null);
+
+ // Release the context and the device.
+ alc.alcDestroyContext(curContext);
+ alc.alcCloseDevice(curDevice);
+
+ log.trace("OpenAL (JOAL) disposed");
+ }
+}
=======================================
--- /branches/nm8/data/xml/configtool.xml Thu Nov 3 22:46:43 2011
+++ /branches/nm8/data/xml/configtool.xml Thu Nov 17 23:26:52 2011
@@ -33,7 +33,7 @@
</constraint>
</borderlayout>
</panel>
-
+
<!-- Sound Provider -->
<panel>
<borderlayout>
@@ -44,13 +44,14 @@
<combobox id="sys_combobox_soundprovider"
tooltiptext="@sys_combobox_soundprovider_tooltip">
<defaultcomboboxmodel setas="model">
<string text="Java Sound"/>
- <string text="OpenAL"/>
+ <string text="OpenAL (LWJGL)"/>
+ <string text="OpenAL (JOAL)"/>
</defaultcomboboxmodel>
</combobox>
</constraint>
</borderlayout>
</panel>
-
+
<!-- Sound volume -->
<panel>
<borderlayout>
@@ -62,7 +63,7 @@
</constraint>
</borderlayout>
</panel>
-
+
<!-- FPS -->
<panel>
<borderlayout>
@@ -82,7 +83,7 @@
</constraint>
</borderlayout>
</panel>
-
+
<!-- Checkboxes -->
<checkbox text="@sys_chkbox_fullscreen_label"
id="sys_chkbox_fullscreen"
@@ -205,7 +206,7 @@
<button text="@keyconfig_tools_clearall"
actionlistener="actClearAll0_0" />
</gridlayout>
</panel>
-
+
<!-- Hard drop -->
<panel>
<titledborder title="@keyconfig_key_0"/>
@@ -216,7 +217,7 @@
<textfield id="key_0_0_3_0"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Soft drop -->
<panel>
<titledborder title="@keyconfig_key_1"/>
@@ -227,7 +228,7 @@
<textfield id="key_0_0_3_1"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Move Left -->
<panel>
<titledborder title="@keyconfig_key_2"/>
@@ -238,7 +239,7 @@
<textfield id="key_0_0_3_2"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Move Right -->
<panel>
<titledborder title="@keyconfig_key_3"/>
@@ -249,7 +250,7 @@
<textfield id="key_0_0_3_3"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate Left -->
<panel>
<titledborder title="@keyconfig_key_4"/>
@@ -260,7 +261,7 @@
<textfield id="key_0_0_3_4"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate Right -->
<panel>
<titledborder title="@keyconfig_key_5"/>
@@ -271,7 +272,7 @@
<textfield id="key_0_0_3_5"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate 180 -->
<panel>
<titledborder title="@keyconfig_key_6"/>
@@ -282,7 +283,7 @@
<textfield id="key_0_0_3_6"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Hold -->
<panel>
<titledborder title="@keyconfig_key_7"/>
@@ -293,7 +294,7 @@
<textfield id="key_0_0_3_7"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Special -->
<panel>
<titledborder title="@keyconfig_key_8"/>
@@ -325,7 +326,7 @@
<button text="@keyconfig_tools_clearall"
actionlistener="actClearAll0_1" />
</gridlayout>
</panel>
-
+
<!-- Hard drop -->
<panel>
<titledborder title="@keyconfig_key_0"/>
@@ -336,7 +337,7 @@
<textfield id="key_0_1_3_0"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Soft drop -->
<panel>
<titledborder title="@keyconfig_key_1"/>
@@ -347,7 +348,7 @@
<textfield id="key_0_1_3_1"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Move Left -->
<panel>
<titledborder title="@keyconfig_key_2"/>
@@ -358,7 +359,7 @@
<textfield id="key_0_1_3_2"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Move Right -->
<panel>
<titledborder title="@keyconfig_key_3"/>
@@ -369,7 +370,7 @@
<textfield id="key_0_1_3_3"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate Left -->
<panel>
<titledborder title="@keyconfig_key_4"/>
@@ -380,7 +381,7 @@
<textfield id="key_0_1_3_4"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate Right -->
<panel>
<titledborder title="@keyconfig_key_5"/>
@@ -391,7 +392,7 @@
<textfield id="key_0_1_3_5"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate 180 -->
<panel>
<titledborder title="@keyconfig_key_6"/>
@@ -402,7 +403,7 @@
<textfield id="key_0_1_3_6"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Hold -->
<panel>
<titledborder title="@keyconfig_key_7"/>
@@ -413,7 +414,7 @@
<textfield id="key_0_1_3_7"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Special -->
<panel>
<titledborder title="@keyconfig_key_8"/>
@@ -436,7 +437,7 @@
</panel>
</tab>
<!-- End of 1P key config -->
-
+
<!-- 2P key config -->
<tab title="2P">
<panel>
@@ -458,7 +459,7 @@
<button text="@keyconfig_tools_clearall"
actionlistener="actClearAll1_0" />
</gridlayout>
</panel>
-
+
<!-- Hard drop -->
<panel>
<titledborder title="@keyconfig_key_0"/>
@@ -469,7 +470,7 @@
<textfield id="key_1_0_3_0"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Soft drop -->
<panel>
<titledborder title="@keyconfig_key_1"/>
@@ -480,7 +481,7 @@
<textfield id="key_1_0_3_1"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Move Left -->
<panel>
<titledborder title="@keyconfig_key_2"/>
@@ -491,7 +492,7 @@
<textfield id="key_1_0_3_2"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Move Right -->
<panel>
<titledborder title="@keyconfig_key_3"/>
@@ -502,7 +503,7 @@
<textfield id="key_1_0_3_3"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate Left -->
<panel>
<titledborder title="@keyconfig_key_4"/>
@@ -513,7 +514,7 @@
<textfield id="key_1_0_3_4"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate Right -->
<panel>
<titledborder title="@keyconfig_key_5"/>
@@ -524,7 +525,7 @@
<textfield id="key_1_0_3_5"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate 180 -->
<panel>
<titledborder title="@keyconfig_key_6"/>
@@ -535,7 +536,7 @@
<textfield id="key_1_0_3_6"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Hold -->
<panel>
<titledborder title="@keyconfig_key_7"/>
@@ -546,7 +547,7 @@
<textfield id="key_1_0_3_7"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Special -->
<panel>
<titledborder title="@keyconfig_key_8"/>
@@ -578,7 +579,7 @@
<button text="@keyconfig_tools_clearall"
actionlistener="actClearAll1_1" />
</gridlayout>
</panel>
-
+
<!-- Hard drop -->
<panel>
<titledborder title="@keyconfig_key_0"/>
@@ -589,7 +590,7 @@
<textfield id="key_1_1_3_0"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Soft drop -->
<panel>
<titledborder title="@keyconfig_key_1"/>
@@ -600,7 +601,7 @@
<textfield id="key_1_1_3_1"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Move Left -->
<panel>
<titledborder title="@keyconfig_key_2"/>
@@ -611,7 +612,7 @@
<textfield id="key_1_1_3_2"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Move Right -->
<panel>
<titledborder title="@keyconfig_key_3"/>
@@ -622,7 +623,7 @@
<textfield id="key_1_1_3_3"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate Left -->
<panel>
<titledborder title="@keyconfig_key_4"/>
@@ -633,7 +634,7 @@
<textfield id="key_1_1_3_4"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate Right -->
<panel>
<titledborder title="@keyconfig_key_5"/>
@@ -644,7 +645,7 @@
<textfield id="key_1_1_3_5"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Rotate 180 -->
<panel>
<titledborder title="@keyconfig_key_6"/>
@@ -655,7 +656,7 @@
<textfield id="key_1_1_3_6"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Hold -->
<panel>
<titledborder title="@keyconfig_key_7"/>
@@ -666,7 +667,7 @@
<textfield id="key_1_1_3_7"
keylistener="klKeyConfigTextField" mouselistener="maKeyConfigTextField" />
</gridlayout>
</panel>
-
+
<!-- Special -->
<panel>
<titledborder title="@keyconfig_key_8"/>
=======================================
---
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/javasound/JSNFSound.java
Mon Aug 29 01:41:28 2011
+++
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/javasound/JSNFSound.java
Thu Nov 17 23:26:52 2011
@@ -3,6 +3,9 @@
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import cx.it.nullpo.nm8.gui.framework.NFSound;
/**
@@ -11,6 +14,9 @@
public class JSNFSound implements NFSound {
private static final long serialVersionUID = 7484516954156886425L;
+ /** Log */
+ private Log log = LogFactory.getLog(JSNFSound.class);
+
/** Java Sound native Clip */
protected Clip clip;
@@ -47,8 +53,13 @@
public void setVolume(float volume) {
currentVolume = volume;
- FloatControl ctrl =
(FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
- ctrl.setValue((float)Math.log10(volume) * 20);
+
+ try {
+ FloatControl ctrl =
(FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
+ ctrl.setValue((float)Math.log10(volume) * 20);
+ } catch (IllegalArgumentException e) {
+ log.warn("Your Java Sound system does not support the control of master
gain. Volume cannot be changed.", e);
+ }
}
public float getVolume() {
=======================================
---
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/lwjglal/LWJGLALSoundProvider.java
Sun Oct 23 02:05:45 2011
+++
/branches/nm8/src/cx/it/nullpo/nm8/gui/common/sound/lwjglal/LWJGLALSoundProvider.java
Thu Nov 17 23:26:52 2011
@@ -18,6 +18,8 @@
import org.lwjgl.openal.AL;
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.ALC10;
+import org.lwjgl.openal.ALCcontext;
+import org.lwjgl.openal.ALCdevice;
import org.lwjgl.util.WaveData;
import cx.it.nullpo.nm8.gui.framework.NFSound;
@@ -304,7 +306,11 @@
@Override
public int getSoundProviderType() {
- return NFSystem.SOUND_PROVIDER_OPENAL;
+ return NFSystem.SOUND_PROVIDER_OPENAL_LWJGL;
+ }
+
+ public int getNumberOfSoundLoaded() {
+ return soundList.size();
}
@Override
@@ -369,5 +375,24 @@
it.remove();
}
}
+
+ // Close the OpenAL
+ ALCcontext curContext;
+ ALCdevice curDevice;
+
+ // Get the current context.
+ curContext = ALC10.alcGetCurrentContext();
+
+ // Get the device used by that context.
+ curDevice = ALC10.alcGetContextsDevice(curContext);
+
+ // Reset the current context to NULL.
+ ALC10.alcMakeContextCurrent(null);
+
+ // Release the context and the device.
+ ALC10.alcDestroyContext(curContext);
+ ALC10.alcCloseDevice(curDevice);
+
+ log.trace("OpenAL (LWJGL) disposed");
}
}
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/gui/framework/NFSystem.java Sat Oct
29 03:50:25 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/gui/framework/NFSystem.java Thu Nov
17 23:26:52 2011
@@ -17,8 +17,15 @@
/** Sound Provider Type: Java Sound */
public static final int SOUND_PROVIDER_JAVASOUND = 0;
- /** Sound Provider Type: OpenAL */
- public static final int SOUND_PROVIDER_OPENAL = 1;
+ /** Sound Provider Type: OpenAL (LWJGL) */
+ public static final int SOUND_PROVIDER_OPENAL_LWJGL = 1;
+ /**
+ * Sound Provider Type: OpenAL (LWJGL)
+ * @deprecated Renamed to {@link #SOUND_PROVIDER_OPENAL_LWJGL}
+ */
+ public static final int SOUND_PROVIDER_OPENAL =
SOUND_PROVIDER_OPENAL_LWJGL;
+ /** Sound Provider Type: OpenAL (JOAL) */
+ public static final int SOUND_PROVIDER_OPENAL_JOAL = 2;
/** NEURO: The event framework */
protected NEURO neuro;
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/gui/niftygui/NFInputSystem.java Sat
Oct 22 21:33:35 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/gui/niftygui/NFInputSystem.java Thu
Nov 17 23:26:52 2011
@@ -6,6 +6,9 @@
import java.util.Iterator;
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import cx.it.nullpo.nm8.gui.framework.NFKeyListener;
import cx.it.nullpo.nm8.gui.framework.NFKeyboard;
import cx.it.nullpo.nm8.gui.framework.NFMouse;
@@ -17,6 +20,8 @@
public class NFInputSystem implements InputSystem, NFKeyListener,
NFMouseListener {
private static final long serialVersionUID = 1L;
+ private Log log = LogFactory.getLog(NFInputSystem.class);
+
/** AWT->NiftyGUI keycode table. It's HUGE, and lots of keys are
unsupported. */
public static final int[] KEYTABLE =
{
@@ -562,8 +567,16 @@
}
public NFInputSystem(NFKeyboard keyboard, NFMouse mouse) {
- keyboard.addKeyListener(this);
- mouse.addMouseListener(this);
+ if(keyboard != null) {
+ keyboard.addKeyListener(this);
+ } else {
+ log.warn("keyboard is null");
+ }
+ if(mouse != null) {
+ mouse.addMouseListener(this);
+ } else {
+ log.warn("mouse is null");
+ }
}
public void forwardEvents(NiftyInputConsumer inputEventConsumer) {
=======================================
---
/branches/nm8/src/cx/it/nullpo/nm8/gui/slick/framework/SlickNFSoundProvider.java
Sun Oct 23 02:05:45 2011
+++
/branches/nm8/src/cx/it/nullpo/nm8/gui/slick/framework/SlickNFSoundProvider.java
Thu Nov 17 23:26:52 2011
@@ -29,7 +29,7 @@
@Override
public int getSoundProviderType() {
- return NFSystem.SOUND_PROVIDER_OPENAL;
+ return NFSystem.SOUND_PROVIDER_OPENAL_LWJGL;
}
@Override
=======================================
---
/branches/nm8/src/cx/it/nullpo/nm8/gui/slick/framework/SlickNFSystem.java
Fri Oct 28 07:58:07 2011
+++
/branches/nm8/src/cx/it/nullpo/nm8/gui/slick/framework/SlickNFSystem.java
Thu Nov 17 23:26:52 2011
@@ -336,7 +336,7 @@
@Override
public boolean isSoundProviderTypeSupported(int type) {
if(type == SOUND_PROVIDER_JAVASOUND) return true;
- if(type == SOUND_PROVIDER_OPENAL) return true;
+ if(type == SOUND_PROVIDER_OPENAL_LWJGL) return true;
return false;
}
@@ -345,10 +345,25 @@
try {
if(type == SOUND_PROVIDER_JAVASOUND) {
nfSoundProvider = new JSSoundProvider();
- } else if(type == SOUND_PROVIDER_OPENAL) {
+ return true;
+ } else if(type == SOUND_PROVIDER_OPENAL_LWJGL) {
nfSoundProvider = new SlickNFSoundProvider();
- }
- return true;
+ return true;
+ } else if(type == SOUND_PROVIDER_OPENAL_JOAL) {
+ try {
+ Class<?> c = null;
+ NFSoundProvider obj = null;
+
+ c =
Class.forName("cx.it.nullpo.nm8.gui.common.sound.joal.JOALSoundProvider");
+ obj = (NFSoundProvider) c.newInstance();
+
+ nfSoundProvider = obj;
+ return true;
+ } catch (Throwable e) {
+ log.error("Cannot initialize JOAL's OpenAL", e);
+ return false;
+ }
+ }
} catch (Exception e) {
log.error("Cannot set sound provider type to " + type, e);
}
=======================================
---
/branches/nm8/src/cx/it/nullpo/nm8/gui/swing/framework/SwingNFSystem.java
Thu Nov 3 22:46:43 2011
+++
/branches/nm8/src/cx/it/nullpo/nm8/gui/swing/framework/SwingNFSystem.java
Thu Nov 17 23:26:52 2011
@@ -243,7 +243,7 @@
if(type == NFSystem.SOUND_PROVIDER_JAVASOUND) {
nfSoundProvider = new JSSoundProvider();
return true;
- } else if(type == NFSystem.SOUND_PROVIDER_OPENAL) {
+ } else if(type == NFSystem.SOUND_PROVIDER_OPENAL_LWJGL) {
try {
Class<?> c = null;
NFSoundProvider obj = null;
@@ -254,7 +254,21 @@
nfSoundProvider = obj;
return true;
} catch (Throwable e) {
- log.error("Cannot initialize OpenAL", e);
+ log.error("Cannot initialize LWJGL's OpenAL", e);
+ return false;
+ }
+ } else if(type == NFSystem.SOUND_PROVIDER_OPENAL_JOAL) {
+ try {
+ Class<?> c = null;
+ NFSoundProvider obj = null;
+
+ c =
Class.forName("cx.it.nullpo.nm8.gui.common.sound.joal.JOALSoundProvider");
+ obj = (NFSoundProvider) c.newInstance();
+
+ nfSoundProvider = obj;
+ return true;
+ } catch (Throwable e) {
+ log.error("Cannot initialize JOAL's OpenAL", e);
return false;
}
}
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/neuro/core/NEUROCore.java Wed Nov 9
19:53:13 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/neuro/core/NEUROCore.java Thu Nov 17
23:26:52 2011
@@ -53,19 +53,19 @@
/** true if the overlay is currently up and want rendering. */
protected boolean overlayDrawFlag;
-
+
/** The GUI manager for this NEURO. */
protected ScreenManager manager;
-
+
/** The render device that will be used by this NEURO. */
private NFRenderDevice renderDevice;
-
+
/** The sound device that will be used by this NEURO. */
private NFSoundDevice soundDevice;
-
+
/** The input system that will be used by this NEURO. */
private NFInputSystem inputSys;
-
+
/** The time provider that will be used by this NEURO. */
private TimeProvider timeProvider;
@@ -84,20 +84,20 @@
if(sys.getJoystickManager() != null &&
sys.getJoystickManager().isInited()) {
sys.getJoystickManager().addListener(this);
}
- }
-
+ inputSys = new NFInputSystem(sys.getKeyboard(),sys.getMouse());
+ }
+
overlayUpdateFlag = false;
overlayDrawFlag = false;
-
+
manager = new DummyManager();
-
+
renderDevice = new NFRenderDevice(sys);
soundDevice = new NFSoundDevice(sys);
- inputSys = new NFInputSystem(sys.getKeyboard(),sys.getMouse());
timeProvider = new TimeProvider();
-
- }
-
+
+ }
+
@Override
public void addPlugin(NEUROPlugin p) {
if (p instanceof NFGame) {
@@ -106,7 +106,7 @@
p.initGUI(new Nifty(renderDevice,soundDevice,inputSys,timeProvider));
super.addPlugin(p);
}
-
+
@Override
public synchronized void dispatchEvent(NEUROEvent e) {
// Check if this event should trigger a quit
@@ -132,7 +132,7 @@
updateOverlay(delta);
}
}
-
+
@Override
public final void draw(NFGraphics g) {
// Draw the game
@@ -169,11 +169,11 @@
}
protected void updateOverlay(long delta) {}
-
+
protected void drawOverlay() {
manager.render();
}
-
+
protected abstract void drawLast(NFGraphics g);
// Key listener methods
@@ -242,6 +242,6 @@
public void joyButtonReleased(NFJoystick joy, int button) {
dispatchEvent(new JoyButtonEvent(this, joy, button, false));
}
-
-
-}
+
+
+}
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/tool/configtool/ConfigTool.java Thu
Nov 3 22:46:43 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/tool/configtool/ConfigTool.java Thu
Nov 17 23:26:52 2011
@@ -183,7 +183,7 @@
JComboBox comboboxResolution =
(JComboBox)getJComponent("sys_combobox_resolution");
comboboxResolution.setSelectedItem(p.getProperty("sys.resolution.string", "640x480"));
JComboBox comboboxSoundProvider =
(JComboBox)getJComponent("sys_combobox_soundprovider");
-
comboboxSoundProvider.setSelectedIndex(p.getProperty("sys.soundprovider",
NFSystem.SOUND_PROVIDER_OPENAL));
+
comboboxSoundProvider.setSelectedIndex(p.getProperty("sys.soundprovider",
NFSystem.SOUND_PROVIDER_OPENAL_LWJGL));
JTextField txtfldVolume = (JTextField)getJComponent("sys_txtfld_volume");
txtfldVolume.setText(String.valueOf(p.getProperty("sys.soundvolume",
1f)));
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/util/NGlobalConfig.java Sat Oct 29
03:50:25 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/util/NGlobalConfig.java Thu Nov 17
23:26:52 2011
@@ -98,7 +98,7 @@
*/
public static void applyNFSystem(NFSystem sys, CustomProperties prop) {
sys.setTargetFPS(prop.getProperty("sys.fps", 60));
- sys.setSoundProviderType(prop.getProperty("sys.soundprovider",
NFSystem.SOUND_PROVIDER_OPENAL));
+ sys.setSoundProviderType(prop.getProperty("sys.soundprovider",
NFSystem.SOUND_PROVIDER_OPENAL_LWJGL));
sys.setEnableAlphaImage(prop.getProperty("sys.enablealpha", true));
sys.setEnableColorFilter(prop.getProperty("sys.enablecolorfilter",
true));
sys.setEnableGradient(prop.getProperty("sys.enablegradient", true));