diff --git a/client/src/main/java/com/aapeli/client/Class87.java b/client/src/main/java/com/aapeli/client/Class87.java deleted file mode 100644 index 87f6fb1a..00000000 --- a/client/src/main/java/com/aapeli/client/Class87.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.aapeli.client; - -import com.aapeli.client.SoundPlayer; - -class Class87 { - - private String aString1480; - private long aLong1481; - private final SoundPlayer aSoundPlayer1482; - - - public Class87(SoundPlayer var1, String var2, int var3) { - this.aSoundPlayer1482 = var1; - this.aString1480 = var2; - this.aLong1481 = System.currentTimeMillis() + (long) var3; - } - - protected String method1685() { - return this.aString1480; - } - - protected long method1686() { - return this.aLong1481; - } -} diff --git a/client/src/main/java/com/aapeli/client/ClipPlaybackTask.java b/client/src/main/java/com/aapeli/client/ClipPlaybackTask.java new file mode 100755 index 00000000..8eb8b25c --- /dev/null +++ b/client/src/main/java/com/aapeli/client/ClipPlaybackTask.java @@ -0,0 +1,21 @@ +package com.aapeli.client; + +class ClipPlaybackTask { + + private String clipName; + private long timeoutTimestamp; + + + public ClipPlaybackTask(String clipName, int timeoutMs) { + this.clipName = clipName; + this.timeoutTimestamp = System.currentTimeMillis() + (long) timeoutMs; + } + + protected String getClipName() { + return this.clipName; + } + + protected long getTimeoutTimestamp() { + return this.timeoutTimestamp; + } +} diff --git a/client/src/main/java/com/aapeli/client/SoundPlayer.java b/client/src/main/java/com/aapeli/client/SoundPlayer.java index e05fa57a..4ee3f654 100644 --- a/client/src/main/java/com/aapeli/client/SoundPlayer.java +++ b/client/src/main/java/com/aapeli/client/SoundPlayer.java @@ -1,126 +1,117 @@ package com.aapeli.client; -import com.aapeli.client.Class87; -import com.aapeli.client.SoundManager; import com.aapeli.tools.Tools; import java.util.Vector; public final class SoundPlayer implements Runnable { - private SoundManager aSoundManager1494; - private Vector[] aVectorArray1495; - private boolean aBoolean1496; - private Thread aThread1497; - private static final String[] aStringArray1498 = new String[4]; + private final SoundManager soundManager; + private final Vector[] soundQueues; // index of queue == priority, higher == more important + private boolean stayAlive; + private final Thread thread; - public SoundPlayer(SoundManager var1) { - this.aSoundManager1494 = var1; - this.aVectorArray1495 = new Vector[10]; + public SoundPlayer(SoundManager soundManager) { + this.soundManager = soundManager; + this.soundQueues = new Vector[10]; - for (int var2 = 0; var2 < 10; ++var2) { - this.aVectorArray1495[var2] = new Vector(); + for (int i = 0; i < 10; ++i) { + this.soundQueues[i] = new Vector<>(); } - this.aBoolean1496 = true; - this.aThread1497 = new Thread(this); - this.aThread1497.setDaemon(true); - this.aThread1497.start(); + this.stayAlive = true; + this.thread = new Thread(this); + this.thread.setDaemon(true); + this.thread.start(); } + @Override public void run() { - if (this.aSoundManager1494.isDebug()) { + if (this.soundManager.isDebug()) { System.out.println("SoundPlayer: Started"); } do { Tools.sleep(1000L); - String var1; - if (this.aBoolean1496) { - while ((var1 = this.method1695()) != null) { - this.aSoundManager1494.play(var1); + String nextClipName; + if (this.stayAlive) { + while ((nextClipName = this.getNextClip()) != null) { + this.soundManager.play(nextClipName); } } - } while (this.aBoolean1496); + } while (this.stayAlive); - if (this.aSoundManager1494.isDebug()) { + if (this.soundManager.isDebug()) { System.out.println("SoundPlayer: Stopped"); } } - public void play(String var1) { - this.play(var1, 5, 1000); + public void play(String clipName) { + this.play(clipName, 5, 1000); } - public void play(String var1, int var2) { - this.play(var1, var2, 1000); + public void play(String clipName, int priority) { + this.play(clipName, priority, 1000); } - public void play(String var1, int var2, int var3) { - if (var2 < 0) { - var2 = 0; + public void play(String clipName, int priority, int timeoutMs) { + if (priority < 0) { + priority = 0; } - if (var2 >= 10) { - var2 = 9; + if (priority >= 10) { + priority = 9; } - if (var3 < 0) { - var3 = 0; + if (timeoutMs < 0) { + timeoutMs = 0; } - Class87 var4 = new Class87(this, var1, var3); - synchronized (this.aVectorArray1495[var2]) { - this.aVectorArray1495[var2].addElement(var4); + ClipPlaybackTask clipPlaybackTask = new ClipPlaybackTask(clipName, timeoutMs); + synchronized (this.soundQueues[priority]) { + this.soundQueues[priority].addElement(clipPlaybackTask); } - this.aThread1497.interrupt(); + this.thread.interrupt(); } public void stop() { - this.aBoolean1496 = false; + this.stayAlive = false; } - private String method1695() { - for (int var2 = 9; var2 >= 0; --var2) { - String var1 = this.method1696(this.aVectorArray1495[var2]); - if (var1 != null) { - return var1; + private String getNextClip() { + for (int i = 9; i >= 0; --i) { + String soundTask = this.getFirstTaskFromQueue(this.soundQueues[i]); + if (soundTask != null) { + return soundTask; } } return null; } - private String method1696(Vector var1) { - Class87 var2; - synchronized (var1) { - if (var1.size() == 0) { + private String getFirstTaskFromQueue(Vector soundQueue) { + ClipPlaybackTask clipPlaybackTask; + synchronized (soundQueue) { + if (soundQueue.size() == 0) { return null; } - var2 = (Class87) ((Class87) var1.elementAt(0)); - var1.removeElementAt(0); + clipPlaybackTask = soundQueue.elementAt(0); + soundQueue.removeElementAt(0); } - String var3 = var2.method1685(); - if (System.currentTimeMillis() > var2.method1686()) { - if (this.aSoundManager1494.isDebug()) { - System.out.println("SoundPlayer: \"" + var3 + "\" timed out"); + String clipName = clipPlaybackTask.getClipName(); + if (System.currentTimeMillis() > clipPlaybackTask.getTimeoutTimestamp()) { + if (this.soundManager.isDebug()) { + System.out.println("SoundPlayer: \"" + clipName + "\" timed out"); } - return this.method1696(var1); + return this.getFirstTaskFromQueue(soundQueue); } else { - return var3; + return clipName; } } - - static { - aStringArray1498[0] = "SoundPlayer: Started"; - aStringArray1498[1] = "SoundPlayer: Stopped"; - aStringArray1498[2] = "\" timed out"; - aStringArray1498[3] = "SoundPlayer: \""; - } }