/* */ package NET.worlds.scape; /* */ /* */ import java.io.PrintStream; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ class SoundResource /* */ { /* 38 */ private static SoundResource instance = null; /* */ /* */ public static final int RSX = 1; /* */ /* */ public static final int RA = 2; /* */ /* */ private static void debugOut(int n, String s) /* */ { /* 46 */ if (Sound.debugLevel > n) System.out.println(s); /* */ } /* */ /* */ public static SoundResource instance() /* */ { /* 51 */ if (instance == null) { /* 52 */ debugOut(6, "Instantiating a new SoundResource"); /* 53 */ instance = new SoundResource(); /* */ } /* 55 */ return instance; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 64 */ private int currentPlayer = 0; /* */ /* */ /* */ /* */ /* */ /* 70 */ private int counter = 0; /* */ /* */ /* */ /* */ /* 75 */ private boolean isShutdownTime = false; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public boolean syncLock(int type) /* */ { /* 89 */ debugOut(6, "Calling syncLock with type " + type + " counter " + this.counter); /* 90 */ if (this.isShutdownTime) /* 91 */ return false; /* 92 */ if (type != this.currentPlayer) { /* 93 */ this.currentPlayer = type; /* 94 */ if (this.counter > 0) { /* 95 */ this.isShutdownTime = true; /* */ } /* */ else { /* 98 */ this.currentPlayer = type; /* 99 */ this.counter = 1; /* */ } /* */ } /* */ else { /* 103 */ this.counter += 1; } /* 104 */ return true; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ public synchronized void asyncLock() /* */ { /* 114 */ debugOut(6, "SoundResource::asyncLock with " + this.isShutdownTime); /* */ /* 116 */ boolean shutdown = false; /* 117 */ while (this.isShutdownTime) { /* 118 */ shutdown = true; /* 119 */ Thread.yield(); /* 120 */ debugOut(6, "asyncLock yield"); /* */ } /* */ /* */ /* */ /* 125 */ if (shutdown) { /* 126 */ debugOut(6, "asyncLock: adding artificial delay"); /* 127 */ try { Thread.sleep(500L); /* */ } /* */ catch (InterruptedException localInterruptedException) {} /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public boolean syncUnlock() /* */ { /* 139 */ debugOut(6, "SoundResource::syncUnlock with " + this.counter); /* */ /* 141 */ boolean rv = false; /* 142 */ this.counter -= 1; /* 143 */ if (this.counter <= 0) /* 144 */ rv = true; /* 145 */ if ((this.counter <= 0) && (this.isShutdownTime)) { /* 146 */ this.counter = 1; /* 147 */ this.isShutdownTime = false; /* */ } /* */ /* 150 */ return rv; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public boolean isOK() /* */ { /* 159 */ return !this.isShutdownTime; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\SoundResource.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */