summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/SoundResource.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/SoundResource.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/SoundResource.java')
-rw-r--r--NET/worlds/scape/SoundResource.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/NET/worlds/scape/SoundResource.java b/NET/worlds/scape/SoundResource.java
new file mode 100644
index 0000000..19975f2
--- /dev/null
+++ b/NET/worlds/scape/SoundResource.java
@@ -0,0 +1,89 @@
+package NET.worlds.scape;
+
+class SoundResource {
+ private static SoundResource instance = null;
+ public static final int RSX = 1;
+ public static final int RA = 2;
+ private int currentPlayer = 0;
+ private int counter = 0;
+ private boolean isShutdownTime = false;
+
+ private SoundResource() {
+ }
+
+ private static void debugOut(int n, String s) {
+ if (Sound.debugLevel > n) {
+ System.out.println(s);
+ }
+ }
+
+ public static SoundResource instance() {
+ if (instance == null) {
+ debugOut(6, "Instantiating a new SoundResource");
+ instance = new SoundResource();
+ }
+
+ return instance;
+ }
+
+ public boolean syncLock(int type) {
+ debugOut(6, "Calling syncLock with type " + type + " counter " + this.counter);
+ if (this.isShutdownTime) {
+ return false;
+ } else {
+ if (type != this.currentPlayer) {
+ this.currentPlayer = type;
+ if (this.counter > 0) {
+ this.isShutdownTime = true;
+ } else {
+ this.currentPlayer = type;
+ this.counter = 1;
+ }
+ } else {
+ this.counter++;
+ }
+
+ return true;
+ }
+ }
+
+ public synchronized void asyncLock() {
+ debugOut(6, "SoundResource::asyncLock with " + this.isShutdownTime);
+ boolean shutdown = false;
+
+ while (this.isShutdownTime) {
+ shutdown = true;
+ Thread.yield();
+ debugOut(6, "asyncLock yield");
+ }
+
+ if (shutdown) {
+ debugOut(6, "asyncLock: adding artificial delay");
+
+ try {
+ Thread.sleep(500L);
+ } catch (InterruptedException var3) {
+ }
+ }
+ }
+
+ public boolean syncUnlock() {
+ debugOut(6, "SoundResource::syncUnlock with " + this.counter);
+ boolean rv = false;
+ this.counter--;
+ if (this.counter <= 0) {
+ rv = true;
+ }
+
+ if (this.counter <= 0 && this.isShutdownTime) {
+ this.counter = 1;
+ this.isShutdownTime = false;
+ }
+
+ return rv;
+ }
+
+ public boolean isOK() {
+ return !this.isShutdownTime;
+ }
+}