some fixes

This commit is contained in:
Mihály Kuprivecz 2017-05-15 10:40:12 +02:00
parent 0546223bba
commit fe1e45bd69
5 changed files with 30 additions and 9 deletions

View File

@ -26,4 +26,4 @@ Use the Event Queue pattern when
## Credits
* [Mihály Kuprivecz - Event Queue]
* [Mihaly Kuprivecz - Event Queue] (http://gameprogrammingpatterns.com/event-queue.html)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View File

@ -107,17 +107,15 @@ public class Audio {
init();
// Walk the pending requests.
for (int i = headIndex; i != tailIndex; i = (i + 1) % MAX_PENDING) {
if (getPendingAudio()[i].stream == stream) {
if (getPendingAudio()[i].getStream() == stream) {
// Use the larger of the two volumes.
getPendingAudio()[i].volume = Math.max(volume, getPendingAudio()[i].volume);
getPendingAudio()[i].setVolume(Math.max(volume, getPendingAudio()[i].getVolume()));
// Don't need to enqueue.
return;
}
}
getPendingAudio()[tailIndex] = new PlayMessage();
getPendingAudio()[tailIndex].stream = stream;
getPendingAudio()[tailIndex].volume = volume;
getPendingAudio()[tailIndex] = new PlayMessage(stream, volume);
tailIndex = (tailIndex + 1) % MAX_PENDING;
}
@ -132,7 +130,7 @@ public class Audio {
}
Clip clip = null;
try {
AudioInputStream audioStream = getPendingAudio()[headIndex].stream;
AudioInputStream audioStream = getPendingAudio()[headIndex].getStream();
headIndex++;
clip = AudioSystem.getClip();
clip.open(audioStream);

View File

@ -31,6 +31,29 @@ import javax.sound.sampled.AudioInputStream;
*
*/
public class PlayMessage {
AudioInputStream stream;
float volume;
private AudioInputStream stream;
private float volume;
public PlayMessage(AudioInputStream stream, float volume) {
setStream(stream);
setVolume(volume);
}
public AudioInputStream getStream() {
return stream;
}
private void setStream(AudioInputStream stream) {
this.stream = stream;
}
public float getVolume() {
return volume;
}
public void setVolume(float volume) {
this.volume = volume;
}
}