summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/ParallelAction.java
blob: 74ecc839502217c8db5ae62c5c3202bdc73f4772 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*     */ package NET.worlds.scape;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.util.Enumeration;
/*     */ import java.util.Vector;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ParallelAction
/*     */   extends Action
/*     */   implements RunningActionCallback
/*     */ {
/*     */   protected static final int NONE = 0;
/*     */   protected static final int FIRST = 1;
/*     */   protected static final int ALL = -1;
/*  40 */   protected Vector<Action> actions = new Vector();
/*     */   
/*     */ 
/*  43 */   protected int waitState = -1;
/*     */   
/*     */ 
/*  46 */   protected int waitingFor = 0;
/*     */   
/*     */ 
/*  49 */   protected Object currentRun = null;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Persister trigger(Event evt, Persister seqID)
/*     */   {
/*  66 */     if (seqID == null) {
/*  67 */       if (this.waitingFor == 0) {
/*  68 */         this.currentRun = new Object();
/*  69 */         if (this.waitState == -1) {
/*  70 */           this.waitingFor = this.actions.size();
/*  71 */           seqID = this;
/*  72 */         } else if (this.waitState == 1) {
/*  73 */           this.waitingFor = 1;
/*  74 */           seqID = this;
/*     */         } else {
/*  76 */           this.waitingFor = 0;
/*  77 */           seqID = null;
/*     */         }
/*  79 */         RunningActionHandler.trigger(this.actions, getWorld(), evt, 
/*  80 */           this, this.currentRun);
/*     */       }
/*     */     }
/*  83 */     else if (this.waitingFor == 0) {
/*  84 */       seqID = null;
/*     */     }
/*  86 */     return seqID;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void actionDone(Action a, Event e, Object o)
/*     */   {
/* 101 */     if ((this.waitingFor > 0) && (o == this.currentRun)) {
/* 102 */       this.waitingFor -= 1;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 110 */   public void setWaitForAll() { this.waitState = -1; }
/* 111 */   public void setWaitForFirst() { this.waitState = 1; }
/* 112 */   public void setWaitForNone() { this.waitState = 0; }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void addComponent(Action act)
/*     */   {
/* 121 */     assert (act != null);
/* 122 */     this.actions.addElement(act);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void insertComponent(Action act, int index)
/*     */   {
/* 131 */     assert (act != null);
/* 132 */     this.actions.insertElementAt(act, index);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean removeComponent(Action act)
/*     */   {
/* 141 */     assert (act != null);
/* 142 */     return this.actions.removeElement(act);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public Enumeration<Action> getComponents()
/*     */   {
/* 150 */     return this.actions.elements();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Object properties(int index, int offset, int mode, Object value)
/*     */     throws NoSuchPropertyException
/*     */   {
/* 160 */     Object ret = null;
/* 161 */     switch (index - offset) {
/*     */     case 0: 
/* 163 */       if (mode == 0) {
/* 164 */         ret = ObjectPropertyAdder.make(
/* 165 */           new VectorProperty(this, index, "Components"), 
/* 166 */           getRoot(), "NET.worlds.scape.Action");
/* 167 */       } else if (mode == 1) {
/* 168 */         ret = this.actions.clone();
/* 169 */       } else if (mode == 4) {
/* 170 */         this.actions.removeElement(value);
/* 171 */       } else if (mode == 3)
/* 172 */         this.actions.addElement((Action)value);
/* 173 */       break;
/*     */     case 1: 
/* 175 */       if (mode == 0) {
/* 176 */         String[] names = { "None", "First", "All" };
/* 177 */         int[] values = { 0, 1, -1 };
/* 178 */         ret = EnumPropertyEditor.make(
/* 179 */           new Property(this, index, "Wait for"), 
/* 180 */           names, values);
/* 181 */       } else if (mode == 1) {
/* 182 */         ret = new Integer(this.waitState);
/* 183 */       } else if (mode == 2) {
/* 184 */         this.waitState = ((Integer)value).intValue(); }
/* 185 */       break;
/*     */     default: 
/* 187 */       ret = super.properties(index, offset + 2, mode, value);
/*     */     }
/* 189 */     return ret;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/* 194 */   private static Object classCookie = new Object();
/*     */   
/*     */   public void saveState(Saver s) throws IOException
/*     */   {
/* 198 */     s.saveVersion(2, classCookie);
/* 199 */     super.saveState(s);
/* 200 */     s.saveVector(this.actions);
/* 201 */     s.saveInt(this.waitState);
/*     */   }
/*     */   
/*     */   public void restoreState(Restorer r) throws IOException, TooNewException
/*     */   {
/* 206 */     switch (r.restoreVersion(classCookie)) {
/*     */     case 2: 
/* 208 */       super.restoreState(r);
/* 209 */       this.actions = r.restoreVectorActions();
/* 210 */       this.waitState = r.restoreInt();
/* 211 */       break;
/*     */     case 1: 
/* 213 */       super.restoreState(r);
/* 214 */       this.actions = r.restoreVectorActions();
/* 215 */       break;
/*     */     default: 
/* 217 */       throw new TooNewException();
/*     */     }
/*     */   }
/*     */ }


/* Location:              C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\ParallelAction.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */