@dra2020/baseclient 1.0.10 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +16 -15
- package/LICENSE +0 -21
- package/README.md +0 -26
- package/dist/all/all.d.ts +0 -20
- package/dist/baseclient.js +0 -10103
- package/dist/baseclient.js.map +0 -1
- package/dist/context/all.d.ts +0 -1
- package/dist/context/context.d.ts +0 -13
- package/dist/filterexpr/all.d.ts +0 -1
- package/dist/filterexpr/filterexpr.d.ts +0 -67
- package/dist/fsm/all.d.ts +0 -1
- package/dist/fsm/fsm.d.ts +0 -119
- package/dist/geo/all.d.ts +0 -2
- package/dist/geo/geo.d.ts +0 -67
- package/dist/geo/vfeature.d.ts +0 -4
- package/dist/logabstract/all.d.ts +0 -1
- package/dist/logabstract/log.d.ts +0 -26
- package/dist/logclient/all.d.ts +0 -1
- package/dist/logclient/log.d.ts +0 -6
- package/dist/ot-editutil/all.d.ts +0 -2
- package/dist/ot-editutil/oteditutil.d.ts +0 -14
- package/dist/ot-editutil/otmaputil.d.ts +0 -21
- package/dist/ot-js/all.d.ts +0 -9
- package/dist/ot-js/otarray.d.ts +0 -111
- package/dist/ot-js/otclientengine.d.ts +0 -38
- package/dist/ot-js/otcomposite.d.ts +0 -37
- package/dist/ot-js/otcounter.d.ts +0 -17
- package/dist/ot-js/otengine.d.ts +0 -22
- package/dist/ot-js/otmap.d.ts +0 -19
- package/dist/ot-js/otserverengine.d.ts +0 -38
- package/dist/ot-js/otsession.d.ts +0 -113
- package/dist/ot-js/ottypes.d.ts +0 -29
- package/dist/poly/all.d.ts +0 -15
- package/dist/poly/blend.d.ts +0 -1
- package/dist/poly/boundbox.d.ts +0 -16
- package/dist/poly/cartesian.d.ts +0 -5
- package/dist/poly/graham-scan.d.ts +0 -8
- package/dist/poly/hash.d.ts +0 -1
- package/dist/poly/matrix.d.ts +0 -24
- package/dist/poly/minbound.d.ts +0 -1
- package/dist/poly/poly.d.ts +0 -52
- package/dist/poly/polybin.d.ts +0 -5
- package/dist/poly/polylabel.d.ts +0 -7
- package/dist/poly/polypack.d.ts +0 -30
- package/dist/poly/polyround.d.ts +0 -1
- package/dist/poly/polysimplify.d.ts +0 -1
- package/dist/poly/quad.d.ts +0 -48
- package/dist/poly/selfintersect.d.ts +0 -1
- package/dist/poly/shamos.d.ts +0 -1
- package/dist/poly/simplify.d.ts +0 -2
- package/dist/poly/topo.d.ts +0 -46
- package/dist/poly/union.d.ts +0 -49
- package/dist/util/all.d.ts +0 -5
- package/dist/util/bintrie.d.ts +0 -93
- package/dist/util/countedhash.d.ts +0 -19
- package/dist/util/gradient.d.ts +0 -15
- package/dist/util/indexedarray.d.ts +0 -15
- package/dist/util/util.d.ts +0 -68
- package/docs/context.md +0 -2
- package/docs/filterexpr.md +0 -22
- package/docs/fsm.md +0 -243
- package/docs/logabstract.md +0 -2
- package/docs/logclient.md +0 -2
- package/docs/ot-editutil.md +0 -2
- package/docs/ot-js.md +0 -95
- package/docs/poly.md +0 -103
- package/docs/util.md +0 -2
- package/lib/all/all.ts +0 -21
- package/lib/context/all.ts +0 -1
- package/lib/context/context.ts +0 -82
- package/lib/filterexpr/all.ts +0 -1
- package/lib/filterexpr/filterexpr.ts +0 -699
- package/lib/fsm/all.ts +0 -1
- package/lib/fsm/fsm.ts +0 -559
- package/lib/geo/all.ts +0 -2
- package/lib/geo/geo.ts +0 -452
- package/lib/geo/vfeature.ts +0 -34
- package/lib/logabstract/all.ts +0 -1
- package/lib/logabstract/log.ts +0 -55
- package/lib/logclient/all.ts +0 -1
- package/lib/logclient/log.ts +0 -105
- package/lib/ot-editutil/all.ts +0 -2
- package/lib/ot-editutil/oteditutil.ts +0 -180
- package/lib/ot-editutil/otmaputil.ts +0 -209
- package/lib/ot-js/all.ts +0 -9
- package/lib/ot-js/otarray.ts +0 -1168
- package/lib/ot-js/otclientengine.ts +0 -327
- package/lib/ot-js/otcomposite.ts +0 -247
- package/lib/ot-js/otcounter.ts +0 -145
- package/lib/ot-js/otengine.ts +0 -71
- package/lib/ot-js/otmap.ts +0 -144
- package/lib/ot-js/otserverengine.ts +0 -329
- package/lib/ot-js/otsession.ts +0 -201
- package/lib/ot-js/ottypes.ts +0 -98
- package/lib/poly/all.ts +0 -15
- package/lib/poly/blend.ts +0 -27
- package/lib/poly/boundbox.ts +0 -102
- package/lib/poly/cartesian.ts +0 -130
- package/lib/poly/graham-scan.ts +0 -401
- package/lib/poly/hash.ts +0 -15
- package/lib/poly/matrix.ts +0 -309
- package/lib/poly/minbound.ts +0 -211
- package/lib/poly/poly.ts +0 -767
- package/lib/poly/polybin.ts +0 -218
- package/lib/poly/polylabel.ts +0 -204
- package/lib/poly/polypack.ts +0 -458
- package/lib/poly/polyround.ts +0 -30
- package/lib/poly/polysimplify.ts +0 -24
- package/lib/poly/quad.ts +0 -272
- package/lib/poly/selfintersect.ts +0 -87
- package/lib/poly/shamos.ts +0 -297
- package/lib/poly/simplify.ts +0 -119
- package/lib/poly/topo.ts +0 -499
- package/lib/poly/union.ts +0 -388
- package/lib/util/all.ts +0 -5
- package/lib/util/bintrie.ts +0 -603
- package/lib/util/countedhash.ts +0 -83
- package/lib/util/gradient.ts +0 -108
- package/lib/util/indexedarray.ts +0 -80
- package/lib/util/util.ts +0 -695
package/lib/fsm/fsm.ts
DELETED
|
@@ -1,559 +0,0 @@
|
|
|
1
|
-
// Shared libraries
|
|
2
|
-
import * as Util from '../util/all';
|
|
3
|
-
|
|
4
|
-
// States
|
|
5
|
-
export const FSM_STARTING: number = 0;
|
|
6
|
-
export const FSM_PENDING: number = 1<<0;
|
|
7
|
-
export const FSM_DONE: number = 1<<1;
|
|
8
|
-
export const FSM_ERROR: number = 1<<2;
|
|
9
|
-
export const FSM_RELEASED: number = 1<<3;
|
|
10
|
-
export const FSM_CUSTOM1: number = 1<<4;
|
|
11
|
-
export const FSM_CUSTOM2: number = 1<<5;
|
|
12
|
-
export const FSM_CUSTOM3: number = 1<<6;
|
|
13
|
-
export const FSM_CUSTOM4: number = 1<<7;
|
|
14
|
-
export const FSM_CUSTOM5: number = 1<<8;
|
|
15
|
-
export const FSM_CUSTOM6: number = 1<<9;
|
|
16
|
-
export const FSM_CUSTOM7: number = 1<<10;
|
|
17
|
-
export const FSM_CUSTOM8: number = 1<<11;
|
|
18
|
-
export const FSM_CUSTOM9: number = 1<<12;
|
|
19
|
-
|
|
20
|
-
// polyfill
|
|
21
|
-
let doLater: any = global && global.setImmediate ? setImmediate : (cb: any) => { setTimeout(cb, 0) };
|
|
22
|
-
|
|
23
|
-
function FsmDone(s: number): boolean
|
|
24
|
-
{
|
|
25
|
-
return (s === FSM_DONE || s === FSM_ERROR || s === FSM_RELEASED);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function FsmStateToString(state: number): string
|
|
29
|
-
{
|
|
30
|
-
let a: string[] = [];
|
|
31
|
-
|
|
32
|
-
if (state === FSM_STARTING)
|
|
33
|
-
return 'starting';
|
|
34
|
-
else
|
|
35
|
-
{
|
|
36
|
-
if (state === FSM_PENDING) a.push('pending');
|
|
37
|
-
if (state === FSM_DONE) a.push('done');
|
|
38
|
-
if (state === FSM_ERROR) a.push('error');
|
|
39
|
-
if (state === FSM_RELEASED) a.push('released');
|
|
40
|
-
if (state === FSM_CUSTOM1) a.push('custom1');
|
|
41
|
-
if (state === FSM_CUSTOM2) a.push('custom2');
|
|
42
|
-
if (state === FSM_CUSTOM3) a.push('custom3');
|
|
43
|
-
if (state === FSM_CUSTOM4) a.push('custom4');
|
|
44
|
-
if (state === FSM_CUSTOM5) a.push('custom5');
|
|
45
|
-
if (state === FSM_CUSTOM6) a.push('custom6');
|
|
46
|
-
if (state === FSM_CUSTOM7) a.push('custom7');
|
|
47
|
-
if (state === FSM_CUSTOM8) a.push('custom8');
|
|
48
|
-
if (state === FSM_CUSTOM9) a.push('custom9');
|
|
49
|
-
return a.join('|');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export type FsmIndex = { [key: number]: Fsm };
|
|
54
|
-
|
|
55
|
-
export class FsmManager
|
|
56
|
-
{
|
|
57
|
-
theId: number;
|
|
58
|
-
theEpoch: number;
|
|
59
|
-
bTickSet: boolean;
|
|
60
|
-
theTickList: FsmIndex;
|
|
61
|
-
theBusyLoopCount: number;
|
|
62
|
-
|
|
63
|
-
constructor()
|
|
64
|
-
{
|
|
65
|
-
this.theId = 0;
|
|
66
|
-
this.theEpoch = 0;
|
|
67
|
-
this.bTickSet = false;
|
|
68
|
-
this.theTickList = {};
|
|
69
|
-
this.theBusyLoopCount = 0;
|
|
70
|
-
this.doTick = this.doTick.bind(this);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
forceTick(fsm: Fsm): void
|
|
74
|
-
{
|
|
75
|
-
this.theTickList[fsm.id] = fsm;
|
|
76
|
-
if (! this.bTickSet)
|
|
77
|
-
{
|
|
78
|
-
this.bTickSet = true;
|
|
79
|
-
doLater(this.doTick);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
doTick(): void
|
|
84
|
-
{
|
|
85
|
-
this.bTickSet = false;
|
|
86
|
-
let nLoops: number = 0;
|
|
87
|
-
|
|
88
|
-
while (nLoops < 1 && !Util.isEmpty(this.theTickList))
|
|
89
|
-
{
|
|
90
|
-
nLoops++;
|
|
91
|
-
let thisTickList = this.theTickList;
|
|
92
|
-
this.theTickList = {};
|
|
93
|
-
|
|
94
|
-
for (let id in thisTickList) if (thisTickList.hasOwnProperty(id))
|
|
95
|
-
{
|
|
96
|
-
let f = thisTickList[id];
|
|
97
|
-
f.preTick();
|
|
98
|
-
f.tick();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (Util.isEmpty(this.theTickList))
|
|
103
|
-
this.theBusyLoopCount = 0;
|
|
104
|
-
else
|
|
105
|
-
this.theBusyLoopCount++;
|
|
106
|
-
|
|
107
|
-
this.theEpoch++;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface FsmEnvironment
|
|
113
|
-
{
|
|
114
|
-
fsmManager: FsmManager;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export class Fsm
|
|
118
|
-
{
|
|
119
|
-
id: number;
|
|
120
|
-
state: number;
|
|
121
|
-
dependentError: boolean;
|
|
122
|
-
epochDone: number;
|
|
123
|
-
_env: FsmEnvironment;
|
|
124
|
-
_waitOn: FsmIndex;
|
|
125
|
-
_waitedOn: FsmIndex;
|
|
126
|
-
|
|
127
|
-
constructor(env: FsmEnvironment)
|
|
128
|
-
{
|
|
129
|
-
this._env = env;
|
|
130
|
-
this.id = this.manager.theId++;
|
|
131
|
-
this.state = FSM_STARTING;
|
|
132
|
-
this.dependentError = false;
|
|
133
|
-
this.epochDone = -1;
|
|
134
|
-
this._waitOn = null;
|
|
135
|
-
this._waitedOn = null;
|
|
136
|
-
this.manager.forceTick(this);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
get env(): FsmEnvironment { return this._env; }
|
|
140
|
-
get manager(): FsmManager { return this.env.fsmManager; }
|
|
141
|
-
|
|
142
|
-
get done(): boolean
|
|
143
|
-
{
|
|
144
|
-
return FsmDone(this.state);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
get ready(): boolean
|
|
148
|
-
{
|
|
149
|
-
return !this.done && this._waitOn == null;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
get iserror(): boolean
|
|
153
|
-
{
|
|
154
|
-
return (this.state === FSM_ERROR);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
get isDependentError(): boolean
|
|
158
|
-
{
|
|
159
|
-
return this.dependentError;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
setDependentError(): void
|
|
163
|
-
{
|
|
164
|
-
this.dependentError = true;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
clearDependentError(): void
|
|
168
|
-
{
|
|
169
|
-
this.dependentError = false;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
get ticked(): boolean
|
|
173
|
-
{
|
|
174
|
-
return this.done && this.manager.theEpoch > this.epochDone;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
get nWaitOn(): number
|
|
178
|
-
{
|
|
179
|
-
return Util.countKeys(this._waitOn);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
get nWaitedOn(): number
|
|
183
|
-
{
|
|
184
|
-
return Util.countKeys(this._waitedOn);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
waitOn(fsm: Fsm | Fsm[]): Fsm
|
|
188
|
-
{
|
|
189
|
-
if (fsm == null)
|
|
190
|
-
return this;
|
|
191
|
-
else if (Array.isArray(fsm))
|
|
192
|
-
{
|
|
193
|
-
for (let i: number = 0; i < fsm.length; i++)
|
|
194
|
-
this.waitOn(fsm[i]);
|
|
195
|
-
}
|
|
196
|
-
else
|
|
197
|
-
{
|
|
198
|
-
if (fsm.done)
|
|
199
|
-
{
|
|
200
|
-
// If dependency is already done, don't add to waitOn list but ensure that
|
|
201
|
-
// this Fsm gets ticked during next epoch. This is because the dependent tick
|
|
202
|
-
// only happens when the dependency state is changed.
|
|
203
|
-
this.manager.forceTick(this);
|
|
204
|
-
if (fsm.iserror)
|
|
205
|
-
this.setDependentError();
|
|
206
|
-
}
|
|
207
|
-
else
|
|
208
|
-
{
|
|
209
|
-
if (this._waitOn == null) this._waitOn = {};
|
|
210
|
-
this._waitOn[fsm.id] = fsm;
|
|
211
|
-
if (fsm._waitedOn == null) fsm._waitedOn = {};
|
|
212
|
-
fsm._waitedOn[this.id] = this;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
setState(state: number): void
|
|
219
|
-
{
|
|
220
|
-
this.state = state;
|
|
221
|
-
if (this.done)
|
|
222
|
-
{
|
|
223
|
-
while (this._waitedOn)
|
|
224
|
-
{
|
|
225
|
-
let on = this._waitedOn;
|
|
226
|
-
this._waitedOn = null;
|
|
227
|
-
for (let id in on) if (on.hasOwnProperty(id))
|
|
228
|
-
{
|
|
229
|
-
let f = on[id];
|
|
230
|
-
if (this.iserror) f.setDependentError();
|
|
231
|
-
this.manager.forceTick(f);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
this.epochDone = this.manager.theEpoch;
|
|
236
|
-
}
|
|
237
|
-
this.manager.forceTick(this);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Can override if need to do more here
|
|
241
|
-
end(state: number = FSM_DONE): void
|
|
242
|
-
{
|
|
243
|
-
this.setState(state);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Cleans up _waitOn
|
|
247
|
-
preTick(): void
|
|
248
|
-
{
|
|
249
|
-
if (this._waitOn == null) return;
|
|
250
|
-
let bMore: boolean = false;
|
|
251
|
-
for (let id in this._waitOn) if (this._waitOn.hasOwnProperty(id))
|
|
252
|
-
{
|
|
253
|
-
let fsm = this._waitOn[id];
|
|
254
|
-
if (fsm.done)
|
|
255
|
-
delete this._waitOn[id];
|
|
256
|
-
else
|
|
257
|
-
bMore = true;
|
|
258
|
-
}
|
|
259
|
-
if (!bMore) this._waitOn = null;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
tick(): void
|
|
263
|
-
{
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Launches callback provided when the associated Fsm (or Fsm array) completes.
|
|
268
|
-
export class FsmOnDone extends Fsm
|
|
269
|
-
{
|
|
270
|
-
cb: any;
|
|
271
|
-
fsm: Fsm | Fsm[];
|
|
272
|
-
|
|
273
|
-
constructor(env: FsmEnvironment, fsm: Fsm | Fsm[], cb: any)
|
|
274
|
-
{
|
|
275
|
-
super(env);
|
|
276
|
-
this.waitOn(fsm);
|
|
277
|
-
this.fsm = fsm;
|
|
278
|
-
this.cb = cb;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
tick(): void
|
|
282
|
-
{
|
|
283
|
-
if (this.ready && this.state == FSM_STARTING)
|
|
284
|
-
{
|
|
285
|
-
this.setState(this.isDependentError ? FSM_ERROR : FSM_DONE);
|
|
286
|
-
this.cb(this.fsm);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export class FsmSleep extends Fsm
|
|
292
|
-
{
|
|
293
|
-
delay: number;
|
|
294
|
-
timeoutHandle: any;
|
|
295
|
-
|
|
296
|
-
constructor(env: FsmEnvironment, delay: number)
|
|
297
|
-
{
|
|
298
|
-
super(env);
|
|
299
|
-
this.delay = delay;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
tick(): void
|
|
303
|
-
{
|
|
304
|
-
// This allows canceling by simply setting state to done
|
|
305
|
-
if (this.done && this.timeoutHandle !== undefined)
|
|
306
|
-
{
|
|
307
|
-
clearTimeout(this.timeoutHandle);
|
|
308
|
-
delete this.timeoutHandle;
|
|
309
|
-
}
|
|
310
|
-
else if (this.ready && this.state === FSM_STARTING)
|
|
311
|
-
{
|
|
312
|
-
this.setState(FSM_PENDING);
|
|
313
|
-
this.timeoutHandle = setTimeout(() => {
|
|
314
|
-
delete this.timeoutHandle;
|
|
315
|
-
this.setState(FSM_DONE)
|
|
316
|
-
}, this.delay);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export type SerializerIndex = { [key: string]: Fsm };
|
|
322
|
-
|
|
323
|
-
export class FsmSerializer extends Fsm
|
|
324
|
-
{
|
|
325
|
-
index: SerializerIndex;
|
|
326
|
-
|
|
327
|
-
constructor(env: FsmEnvironment)
|
|
328
|
-
{
|
|
329
|
-
super(env);
|
|
330
|
-
this.index = {};
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
serialize(id: string, fsm?: Fsm): Fsm
|
|
334
|
-
{
|
|
335
|
-
let prev = this.index[id];
|
|
336
|
-
if (prev && !fsm) return prev;
|
|
337
|
-
if (prev !== undefined)
|
|
338
|
-
fsm.waitOn(prev);
|
|
339
|
-
this.index[id] = fsm;
|
|
340
|
-
if (this.done)
|
|
341
|
-
this.setState(FSM_STARTING);
|
|
342
|
-
this.waitOn(fsm);
|
|
343
|
-
return prev;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
tick(): void
|
|
347
|
-
{
|
|
348
|
-
// If fully quiescent, take advantage to clear the waiting cache.
|
|
349
|
-
if (this.ready && this.state == FSM_STARTING)
|
|
350
|
-
{
|
|
351
|
-
this.index = {};
|
|
352
|
-
this.setState(FSM_DONE);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// The FsmTracker class provides a mechanism for serializing a set of finite state
|
|
358
|
-
// machines identified by a consistent unique identifier. A finite state machine is
|
|
359
|
-
// "tracked" until completion. If any other finite state machine calls "maybeWait"
|
|
360
|
-
// while any other are tracked and pending, that FSM will wait for the others to
|
|
361
|
-
// complete.
|
|
362
|
-
//
|
|
363
|
-
|
|
364
|
-
class FsmTrackerWrap extends Fsm
|
|
365
|
-
{
|
|
366
|
-
index: FsmTracker;
|
|
367
|
-
uid: string;
|
|
368
|
-
fsm: Fsm;
|
|
369
|
-
|
|
370
|
-
constructor(env: FsmEnvironment, index: FsmTracker, uid: string, fsm: Fsm)
|
|
371
|
-
{
|
|
372
|
-
super(env);
|
|
373
|
-
this.index = index;
|
|
374
|
-
this.uid = uid;
|
|
375
|
-
this.fsm = fsm;
|
|
376
|
-
index._track(uid, fsm);
|
|
377
|
-
this.waitOn(fsm);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
tick(): void
|
|
381
|
-
{
|
|
382
|
-
if (this.ready && this.state == FSM_STARTING)
|
|
383
|
-
{
|
|
384
|
-
this.index._untrack(this.uid, this.fsm);
|
|
385
|
-
this.setState(FSM_DONE);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
type FsmArrayMap = { [key: string]: Fsm[] };
|
|
391
|
-
|
|
392
|
-
export class FsmTracker
|
|
393
|
-
{
|
|
394
|
-
env: FsmEnvironment;
|
|
395
|
-
map: FsmArrayMap;
|
|
396
|
-
|
|
397
|
-
constructor(env: FsmEnvironment)
|
|
398
|
-
{
|
|
399
|
-
this.env = env;
|
|
400
|
-
this.map = {};
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
_track(uid: string, fsm: Fsm): void
|
|
404
|
-
{
|
|
405
|
-
let a = this.map[uid];
|
|
406
|
-
if (a === undefined)
|
|
407
|
-
{
|
|
408
|
-
a = [];
|
|
409
|
-
this.map[uid] = a;
|
|
410
|
-
}
|
|
411
|
-
a.push(fsm);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
_untrack(uid: string, fsm: Fsm): void
|
|
415
|
-
{
|
|
416
|
-
let a = this.map[uid];
|
|
417
|
-
if (a)
|
|
418
|
-
{
|
|
419
|
-
for (let i: number = 0; i < a.length; i++)
|
|
420
|
-
if (a[i] === fsm)
|
|
421
|
-
{
|
|
422
|
-
if (a.length == 1)
|
|
423
|
-
delete this.map[uid];
|
|
424
|
-
else
|
|
425
|
-
a.splice(i, 1);
|
|
426
|
-
break;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
track(uid: string, fsm: Fsm): Fsm
|
|
432
|
-
{
|
|
433
|
-
return new FsmTrackerWrap(this.env, this, uid, fsm);
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
maybeWait(uid: string, fsm: Fsm): void
|
|
437
|
-
{
|
|
438
|
-
fsm.waitOn(this.map[uid]);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
// FsmLoop: repeat the Fsm passed in (resetting to STARTING state after finished) at some minimum interval.
|
|
444
|
-
// Assumes that the Fsm can be correctly reset and restarted by setting the state.
|
|
445
|
-
//
|
|
446
|
-
|
|
447
|
-
export interface LoopOptions
|
|
448
|
-
{
|
|
449
|
-
minRepeatInterval?: number;
|
|
450
|
-
exitOnError?: boolean;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
export const DefaultLoopOptions = { minRepeatInterval: 0, exitOnError: true };
|
|
454
|
-
|
|
455
|
-
const FSM_DELAYING = FSM_CUSTOM1;
|
|
456
|
-
|
|
457
|
-
export class FsmLoop extends Fsm
|
|
458
|
-
{
|
|
459
|
-
fsm: Fsm;
|
|
460
|
-
options: LoopOptions;
|
|
461
|
-
elapsed: Util.Elapsed;
|
|
462
|
-
|
|
463
|
-
constructor(env: FsmEnvironment, fsm: Fsm, options?: LoopOptions)
|
|
464
|
-
{
|
|
465
|
-
super(env);
|
|
466
|
-
this.fsm = fsm;
|
|
467
|
-
this.elapsed = new Util.Elapsed();
|
|
468
|
-
this.options = Util.shallowAssignImmutable(DefaultLoopOptions, options);
|
|
469
|
-
this.waitOn(fsm);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
tick(): void
|
|
473
|
-
{
|
|
474
|
-
if (this.ready && this.isDependentError)
|
|
475
|
-
{
|
|
476
|
-
if (this.options.exitOnError)
|
|
477
|
-
this.setState(FSM_ERROR);
|
|
478
|
-
else
|
|
479
|
-
this.clearDependentError();
|
|
480
|
-
// Fall through
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
if (this.ready)
|
|
484
|
-
{
|
|
485
|
-
switch (this.state)
|
|
486
|
-
{
|
|
487
|
-
case FSM_STARTING:
|
|
488
|
-
let msLeft = this.options.minRepeatInterval - this.elapsed.ms();
|
|
489
|
-
if (msLeft > 0)
|
|
490
|
-
this.waitOn(new FsmSleep(this.env, msLeft));
|
|
491
|
-
this.setState(FSM_DELAYING);
|
|
492
|
-
break;
|
|
493
|
-
|
|
494
|
-
case FSM_DELAYING:
|
|
495
|
-
this.elapsed.start();
|
|
496
|
-
this.fsm.setState(FSM_STARTING);
|
|
497
|
-
this.waitOn(this.fsm);
|
|
498
|
-
this.setState(FSM_STARTING);
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
export interface ISet
|
|
506
|
-
{
|
|
507
|
-
test: (o: any) => boolean;
|
|
508
|
-
reset: () => void;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
export class FsmArray extends Fsm
|
|
512
|
-
{
|
|
513
|
-
a: any[];
|
|
514
|
-
iset: ISet;
|
|
515
|
-
|
|
516
|
-
constructor(env: FsmEnvironment, iset?: ISet)
|
|
517
|
-
{
|
|
518
|
-
super(env);
|
|
519
|
-
this.iset = iset;
|
|
520
|
-
this.a = [];
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
push(o: any): void
|
|
524
|
-
{
|
|
525
|
-
if (this.iset == null || !this.iset.test(o))
|
|
526
|
-
{
|
|
527
|
-
if (! this.done) this.setState(FSM_DONE);
|
|
528
|
-
this.a.push(o);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
concat(a: any[]): void
|
|
533
|
-
{
|
|
534
|
-
if (a)
|
|
535
|
-
{
|
|
536
|
-
for (let i: number = 0; i < a.length; i++)
|
|
537
|
-
this.push(a[i]);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
splice(i?: number, n?: number): void
|
|
542
|
-
{
|
|
543
|
-
if (i === undefined)
|
|
544
|
-
this.reset();
|
|
545
|
-
else
|
|
546
|
-
{
|
|
547
|
-
this.a.splice(i, n);
|
|
548
|
-
if (this.a.length == 0)
|
|
549
|
-
this.reset();
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
reset(): void
|
|
554
|
-
{
|
|
555
|
-
this.a = [];
|
|
556
|
-
if (this.iset) this.iset.reset();
|
|
557
|
-
this.setState(FSM_STARTING);
|
|
558
|
-
}
|
|
559
|
-
}
|
package/lib/geo/all.ts
DELETED