Skip to content

Commit fe1e45b

Browse files
committed
some fixes
1 parent 0546223 commit fe1e45b

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

event-queue/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ Use the Event Queue pattern when
2626

2727
## Credits
2828

29-
* [Mihály Kuprivecz - Event Queue]
29+
* [Mihaly Kuprivecz - Event Queue] (http://gameprogrammingpatterns.com/event-queue.html)
File renamed without changes.

event-queue/model.png

-10.6 KB
Binary file not shown.

event-queue/src/main/java/com/iluwatar/event/queue/Audio.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,15 @@ public static void playSound(AudioInputStream stream, float volume) {
107107
init();
108108
// Walk the pending requests.
109109
for (int i = headIndex; i != tailIndex; i = (i + 1) % MAX_PENDING) {
110-
if (getPendingAudio()[i].stream == stream) {
110+
if (getPendingAudio()[i].getStream() == stream) {
111111
// Use the larger of the two volumes.
112-
getPendingAudio()[i].volume = Math.max(volume, getPendingAudio()[i].volume);
112+
getPendingAudio()[i].setVolume(Math.max(volume, getPendingAudio()[i].getVolume()));
113113

114114
// Don't need to enqueue.
115115
return;
116116
}
117117
}
118-
getPendingAudio()[tailIndex] = new PlayMessage();
119-
getPendingAudio()[tailIndex].stream = stream;
120-
getPendingAudio()[tailIndex].volume = volume;
118+
getPendingAudio()[tailIndex] = new PlayMessage(stream, volume);
121119
tailIndex = (tailIndex + 1) % MAX_PENDING;
122120
}
123121

@@ -132,7 +130,7 @@ public static void update() {
132130
}
133131
Clip clip = null;
134132
try {
135-
AudioInputStream audioStream = getPendingAudio()[headIndex].stream;
133+
AudioInputStream audioStream = getPendingAudio()[headIndex].getStream();
136134
headIndex++;
137135
clip = AudioSystem.getClip();
138136
clip.open(audioStream);

event-queue/src/main/java/com/iluwatar/event/queue/PlayMessage.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,29 @@
3131
*
3232
*/
3333
public class PlayMessage {
34-
AudioInputStream stream;
35-
float volume;
34+
35+
private AudioInputStream stream;
36+
37+
private float volume;
38+
39+
public PlayMessage(AudioInputStream stream, float volume) {
40+
setStream(stream);
41+
setVolume(volume);
42+
}
43+
44+
public AudioInputStream getStream() {
45+
return stream;
46+
}
47+
48+
private void setStream(AudioInputStream stream) {
49+
this.stream = stream;
50+
}
51+
52+
public float getVolume() {
53+
return volume;
54+
}
55+
56+
public void setVolume(float volume) {
57+
this.volume = volume;
58+
}
3659
}

0 commit comments

Comments
 (0)