summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/SoundResource.java
blob: a564a8cfc4a2c3e38647c1dd0124da56afe03059 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*     */ 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
 */