some fixes
This commit is contained in:
parent
0546223bba
commit
fe1e45bd69
@ -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 |
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user