screeps-clockwork 0.4.0 → 0.5.0
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/dist/index.js +1529 -362
- package/dist/index.js.map +1 -1
- package/dist/screeps_clockwork.wasm +0 -0
- package/dist/src/index.d.ts +4 -3
- package/dist/src/utils/constants.d.ts +1 -0
- package/dist/src/utils/fromPacked.d.ts +2 -0
- package/dist/src/wasm/screeps_clockwork.d.ts +174 -131
- package/dist/src/wrappers/bfsDistanceMap.d.ts +27 -1
- package/dist/src/wrappers/bfsFlowField.d.ts +50 -2
- package/dist/src/wrappers/dijkstraDistanceMap.d.ts +26 -1
- package/dist/src/wrappers/dijkstraFlowField.d.ts +46 -2
- package/dist/src/wrappers/distanceMap.d.ts +29 -0
- package/dist/src/wrappers/flowField.d.ts +38 -0
- package/dist/src/wrappers/monoFlowField.d.ts +26 -0
- package/dist/src/wrappers/multiroomDistanceMap.d.ts +34 -0
- package/dist/src/wrappers/multiroomFlowField.d.ts +46 -0
- package/dist/src/wrappers/multiroomMonoFlowField.d.ts +34 -0
- package/dist/src/wrappers/path.d.ts +41 -2
- package/package.json +7 -7
- package/dist/src/wrappers/pathtoDistanceMapOrigin.d.ts +0 -3
- package/dist/src/wrappers/pathtoFlowFieldOrigin.d.ts +0 -3
- package/dist/src/wrappers/pathtoMonoFlowFieldOrigin.d.ts +0 -3
package/dist/index.js
CHANGED
@@ -24,6 +24,16 @@ function requireEncoderDecoderTogether_min () {
|
|
24
24
|
|
25
25
|
requireEncoderDecoderTogether_min();
|
26
26
|
|
27
|
+
function clockworkcostmatrix_get_pointer(value) {
|
28
|
+
if (!value ||
|
29
|
+
typeof value !== 'object' ||
|
30
|
+
!('__wbg_ptr' in value) ||
|
31
|
+
value.constructor.name !== 'ClockworkCostMatrix') {
|
32
|
+
return 0;
|
33
|
+
}
|
34
|
+
return value.__wbg_ptr;
|
35
|
+
}
|
36
|
+
|
27
37
|
let wasm;
|
28
38
|
|
29
39
|
const heap = new Array(128).fill(undefined);
|
@@ -34,6 +44,23 @@ function getObject(idx) { return heap[idx]; }
|
|
34
44
|
|
35
45
|
let heap_next = heap.length;
|
36
46
|
|
47
|
+
function addHeapObject(obj) {
|
48
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
49
|
+
const idx = heap_next;
|
50
|
+
heap_next = heap[idx];
|
51
|
+
|
52
|
+
heap[idx] = obj;
|
53
|
+
return idx;
|
54
|
+
}
|
55
|
+
|
56
|
+
function handleError(f, args) {
|
57
|
+
try {
|
58
|
+
return f.apply(this, args);
|
59
|
+
} catch (e) {
|
60
|
+
wasm.__wbindgen_exn_store(addHeapObject(e));
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
37
64
|
function dropObject(idx) {
|
38
65
|
if (idx < 132) return;
|
39
66
|
heap[idx] = heap_next;
|
@@ -46,28 +73,6 @@ function takeObject(idx) {
|
|
46
73
|
return ret;
|
47
74
|
}
|
48
75
|
|
49
|
-
function isLikeNone(x) {
|
50
|
-
return x === undefined || x === null;
|
51
|
-
}
|
52
|
-
|
53
|
-
let cachedDataViewMemory0 = null;
|
54
|
-
|
55
|
-
function getDataViewMemory0() {
|
56
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
57
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
58
|
-
}
|
59
|
-
return cachedDataViewMemory0;
|
60
|
-
}
|
61
|
-
|
62
|
-
function addHeapObject(obj) {
|
63
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
64
|
-
const idx = heap_next;
|
65
|
-
heap_next = heap[idx];
|
66
|
-
|
67
|
-
heap[idx] = obj;
|
68
|
-
return idx;
|
69
|
-
}
|
70
|
-
|
71
76
|
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
72
77
|
|
73
78
|
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }
|
@@ -85,6 +90,75 @@ function getStringFromWasm0(ptr, len) {
|
|
85
90
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
86
91
|
}
|
87
92
|
|
93
|
+
function isLikeNone(x) {
|
94
|
+
return x === undefined || x === null;
|
95
|
+
}
|
96
|
+
|
97
|
+
let WASM_VECTOR_LEN = 0;
|
98
|
+
|
99
|
+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
100
|
+
|
101
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
102
|
+
? function (arg, view) {
|
103
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
104
|
+
}
|
105
|
+
: function (arg, view) {
|
106
|
+
const buf = cachedTextEncoder.encode(arg);
|
107
|
+
view.set(buf);
|
108
|
+
return {
|
109
|
+
read: arg.length,
|
110
|
+
written: buf.length
|
111
|
+
};
|
112
|
+
});
|
113
|
+
|
114
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
115
|
+
|
116
|
+
if (realloc === undefined) {
|
117
|
+
const buf = cachedTextEncoder.encode(arg);
|
118
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
119
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
120
|
+
WASM_VECTOR_LEN = buf.length;
|
121
|
+
return ptr;
|
122
|
+
}
|
123
|
+
|
124
|
+
let len = arg.length;
|
125
|
+
let ptr = malloc(len, 1) >>> 0;
|
126
|
+
|
127
|
+
const mem = getUint8ArrayMemory0();
|
128
|
+
|
129
|
+
let offset = 0;
|
130
|
+
|
131
|
+
for (; offset < len; offset++) {
|
132
|
+
const code = arg.charCodeAt(offset);
|
133
|
+
if (code > 0x7F) break;
|
134
|
+
mem[ptr + offset] = code;
|
135
|
+
}
|
136
|
+
|
137
|
+
if (offset !== len) {
|
138
|
+
if (offset !== 0) {
|
139
|
+
arg = arg.slice(offset);
|
140
|
+
}
|
141
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
142
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
143
|
+
const ret = encodeString(arg, view);
|
144
|
+
|
145
|
+
offset += ret.written;
|
146
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
147
|
+
}
|
148
|
+
|
149
|
+
WASM_VECTOR_LEN = offset;
|
150
|
+
return ptr;
|
151
|
+
}
|
152
|
+
|
153
|
+
let cachedDataViewMemory0 = null;
|
154
|
+
|
155
|
+
function getDataViewMemory0() {
|
156
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
157
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
158
|
+
}
|
159
|
+
return cachedDataViewMemory0;
|
160
|
+
}
|
161
|
+
|
88
162
|
let cachedUint32ArrayMemory0 = null;
|
89
163
|
|
90
164
|
function getUint32ArrayMemory0() {
|
@@ -94,38 +168,69 @@ function getUint32ArrayMemory0() {
|
|
94
168
|
return cachedUint32ArrayMemory0;
|
95
169
|
}
|
96
170
|
|
97
|
-
function
|
98
|
-
ptr =
|
99
|
-
|
171
|
+
function passArray32ToWasm0(arg, malloc) {
|
172
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
173
|
+
getUint32ArrayMemory0().set(arg, ptr / 4);
|
174
|
+
WASM_VECTOR_LEN = arg.length;
|
175
|
+
return ptr;
|
176
|
+
}
|
177
|
+
|
178
|
+
let stack_pointer = 128;
|
179
|
+
|
180
|
+
function addBorrowedObject(obj) {
|
181
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
182
|
+
heap[--stack_pointer] = obj;
|
183
|
+
return stack_pointer;
|
184
|
+
}
|
185
|
+
/**
|
186
|
+
* WASM wrapper for the BFS multiroom flow field function.
|
187
|
+
* @param {Uint32Array} start_packed
|
188
|
+
* @param {Function} get_cost_matrix
|
189
|
+
* @param {number} max_tiles
|
190
|
+
* @param {number} max_rooms
|
191
|
+
* @param {number} max_room_distance
|
192
|
+
* @param {number} max_tile_distance
|
193
|
+
* @returns {MultiroomFlowField}
|
194
|
+
*/
|
195
|
+
function js_bfs_multiroom_flow_field(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
|
196
|
+
try {
|
197
|
+
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
198
|
+
const len0 = WASM_VECTOR_LEN;
|
199
|
+
const ret = wasm.js_bfs_multiroom_flow_field(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
|
200
|
+
return MultiroomFlowField.__wrap(ret);
|
201
|
+
} finally {
|
202
|
+
heap[stack_pointer++] = undefined;
|
203
|
+
}
|
100
204
|
}
|
101
205
|
|
102
206
|
function _assertClass(instance, klass) {
|
103
207
|
if (!(instance instanceof klass)) {
|
104
208
|
throw new Error(`expected instance of ${klass.name}`);
|
105
209
|
}
|
106
|
-
return instance.ptr;
|
107
|
-
}
|
108
|
-
|
109
|
-
let WASM_VECTOR_LEN = 0;
|
110
|
-
|
111
|
-
function passArray32ToWasm0(arg, malloc) {
|
112
|
-
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
113
|
-
getUint32ArrayMemory0().set(arg, ptr / 4);
|
114
|
-
WASM_VECTOR_LEN = arg.length;
|
115
|
-
return ptr;
|
116
210
|
}
|
117
211
|
/**
|
118
|
-
* WASM wrapper for the Dijkstra
|
212
|
+
* WASM wrapper for the Dijkstra distance map function.
|
119
213
|
* @param {Uint32Array} start_packed
|
120
214
|
* @param {ClockworkCostMatrix} cost_matrix
|
121
|
-
* @returns {
|
215
|
+
* @returns {DistanceMap}
|
122
216
|
*/
|
123
|
-
function
|
217
|
+
function js_dijkstra_distance_map(start_packed, cost_matrix) {
|
124
218
|
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
125
219
|
const len0 = WASM_VECTOR_LEN;
|
126
220
|
_assertClass(cost_matrix, ClockworkCostMatrix);
|
127
|
-
const ret = wasm.
|
128
|
-
return
|
221
|
+
const ret = wasm.js_dijkstra_distance_map(ptr0, len0, cost_matrix.__wbg_ptr);
|
222
|
+
return DistanceMap.__wrap(ret);
|
223
|
+
}
|
224
|
+
|
225
|
+
/**
|
226
|
+
* @param {number} start
|
227
|
+
* @param {FlowField} flow_field
|
228
|
+
* @returns {Path}
|
229
|
+
*/
|
230
|
+
function js_path_to_flow_field_origin(start, flow_field) {
|
231
|
+
_assertClass(flow_field, FlowField);
|
232
|
+
const ret = wasm.js_path_to_flow_field_origin(start, flow_field.__wbg_ptr);
|
233
|
+
return Path$1.__wrap(ret);
|
129
234
|
}
|
130
235
|
|
131
236
|
function getArrayJsValueFromWasm0(ptr, len) {
|
@@ -148,98 +253,123 @@ function passArrayJsValueToWasm0(array, malloc) {
|
|
148
253
|
return ptr;
|
149
254
|
}
|
150
255
|
/**
|
151
|
-
*
|
152
|
-
* @param {MonoFlowField} flow_field
|
153
|
-
* @returns {Path}
|
154
|
-
*/
|
155
|
-
function js_path_to_mono_flow_field_origin(start, flow_field) {
|
156
|
-
_assertClass(flow_field, MonoFlowField);
|
157
|
-
const ret = wasm.js_path_to_mono_flow_field_origin(start, flow_field.__wbg_ptr);
|
158
|
-
return Path$1.__wrap(ret);
|
159
|
-
}
|
160
|
-
|
161
|
-
/**
|
162
|
-
* WASM wrapper for the Dijkstra distance map function.
|
256
|
+
* WASM wrapper for the BFS distance map function.
|
163
257
|
* @param {Uint32Array} start_packed
|
164
258
|
* @param {ClockworkCostMatrix} cost_matrix
|
165
259
|
* @returns {DistanceMap}
|
166
260
|
*/
|
167
|
-
function
|
261
|
+
function js_bfs_distance_map(start_packed, cost_matrix) {
|
168
262
|
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
169
263
|
const len0 = WASM_VECTOR_LEN;
|
170
264
|
_assertClass(cost_matrix, ClockworkCostMatrix);
|
171
|
-
const ret = wasm.
|
265
|
+
const ret = wasm.js_bfs_distance_map(ptr0, len0, cost_matrix.__wbg_ptr);
|
172
266
|
return DistanceMap.__wrap(ret);
|
173
267
|
}
|
174
268
|
|
175
269
|
/**
|
176
|
-
* WASM wrapper for the BFS mono flow field function.
|
177
270
|
* @param {Uint32Array} start_packed
|
178
|
-
* @param {
|
179
|
-
* @
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
_assertClass(cost_matrix, ClockworkCostMatrix);
|
185
|
-
const ret = wasm.js_bfs_mono_flow_field(ptr0, len0, cost_matrix.__wbg_ptr);
|
186
|
-
return MonoFlowField.__wrap(ret);
|
187
|
-
}
|
188
|
-
|
189
|
-
/**
|
190
|
-
* @param {number} start
|
191
|
-
* @param {DistanceMap} distance_map
|
192
|
-
* @returns {Path}
|
271
|
+
* @param {Function} get_cost_matrix
|
272
|
+
* @param {number} max_tiles
|
273
|
+
* @param {number} max_rooms
|
274
|
+
* @param {number} max_room_distance
|
275
|
+
* @param {number} max_tile_distance
|
276
|
+
* @returns {MultiroomDistanceMap}
|
193
277
|
*/
|
194
|
-
function
|
195
|
-
|
196
|
-
|
197
|
-
|
278
|
+
function js_dijkstra_multiroom_distance_map(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
|
279
|
+
try {
|
280
|
+
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
281
|
+
const len0 = WASM_VECTOR_LEN;
|
282
|
+
const ret = wasm.js_dijkstra_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
|
283
|
+
return MultiroomDistanceMap.__wrap(ret);
|
284
|
+
} finally {
|
285
|
+
heap[stack_pointer++] = undefined;
|
286
|
+
}
|
198
287
|
}
|
199
288
|
|
200
289
|
/**
|
201
|
-
* @
|
290
|
+
* @param {Uint32Array} start_packed
|
291
|
+
* @param {Function} get_cost_matrix
|
292
|
+
* @param {number} max_tiles
|
293
|
+
* @param {number} max_rooms
|
294
|
+
* @param {number} max_room_distance
|
295
|
+
* @param {number} max_tile_distance
|
296
|
+
* @returns {MultiroomFlowField}
|
202
297
|
*/
|
203
|
-
function
|
204
|
-
let deferred1_0;
|
205
|
-
let deferred1_1;
|
298
|
+
function js_dijkstra_multiroom_flow_field(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
|
206
299
|
try {
|
207
|
-
const
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
deferred1_0 = r0;
|
212
|
-
deferred1_1 = r1;
|
213
|
-
return getStringFromWasm0(r0, r1);
|
300
|
+
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
301
|
+
const len0 = WASM_VECTOR_LEN;
|
302
|
+
const ret = wasm.js_dijkstra_multiroom_flow_field(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
|
303
|
+
return MultiroomFlowField.__wrap(ret);
|
214
304
|
} finally {
|
215
|
-
|
216
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
305
|
+
heap[stack_pointer++] = undefined;
|
217
306
|
}
|
218
307
|
}
|
219
308
|
|
220
309
|
/**
|
221
|
-
*
|
222
|
-
* @param {
|
223
|
-
* @param {
|
224
|
-
* @
|
310
|
+
* WASM wrapper for the BFS multiroom distance map function.
|
311
|
+
* @param {Uint32Array} start_packed
|
312
|
+
* @param {Function} get_cost_matrix
|
313
|
+
* @param {number} max_tiles
|
314
|
+
* @param {number} max_rooms
|
315
|
+
* @param {number} max_room_distance
|
316
|
+
* @param {number} max_tile_distance
|
317
|
+
* @returns {MultiroomDistanceMap}
|
225
318
|
*/
|
226
|
-
function
|
227
|
-
|
228
|
-
|
319
|
+
function js_bfs_multiroom_distance_map(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
|
320
|
+
try {
|
321
|
+
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
322
|
+
const len0 = WASM_VECTOR_LEN;
|
323
|
+
const ret = wasm.js_bfs_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
|
324
|
+
return MultiroomDistanceMap.__wrap(ret);
|
325
|
+
} finally {
|
326
|
+
heap[stack_pointer++] = undefined;
|
327
|
+
}
|
229
328
|
}
|
230
329
|
|
231
330
|
/**
|
232
|
-
* WASM wrapper for the
|
331
|
+
* WASM wrapper for the Dijkstra flow field function.
|
233
332
|
* @param {Uint32Array} start_packed
|
234
333
|
* @param {ClockworkCostMatrix} cost_matrix
|
235
|
-
* @returns {
|
334
|
+
* @returns {FlowField}
|
236
335
|
*/
|
237
|
-
function
|
336
|
+
function js_dijkstra_flow_field(start_packed, cost_matrix) {
|
238
337
|
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
239
338
|
const len0 = WASM_VECTOR_LEN;
|
240
339
|
_assertClass(cost_matrix, ClockworkCostMatrix);
|
241
|
-
const ret = wasm.
|
242
|
-
return
|
340
|
+
const ret = wasm.js_dijkstra_flow_field(ptr0, len0, cost_matrix.__wbg_ptr);
|
341
|
+
return FlowField.__wrap(ret);
|
342
|
+
}
|
343
|
+
|
344
|
+
/**
|
345
|
+
* @param {Uint32Array} start_packed
|
346
|
+
* @param {Function} get_cost_matrix
|
347
|
+
* @param {number} max_tiles
|
348
|
+
* @param {number} max_rooms
|
349
|
+
* @param {number} max_room_distance
|
350
|
+
* @param {number} max_tile_distance
|
351
|
+
* @returns {MultiroomMonoFlowField}
|
352
|
+
*/
|
353
|
+
function js_dijkstra_multiroom_mono_flow_field(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
|
354
|
+
try {
|
355
|
+
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
356
|
+
const len0 = WASM_VECTOR_LEN;
|
357
|
+
const ret = wasm.js_dijkstra_multiroom_mono_flow_field(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
|
358
|
+
return MultiroomMonoFlowField.__wrap(ret);
|
359
|
+
} finally {
|
360
|
+
heap[stack_pointer++] = undefined;
|
361
|
+
}
|
362
|
+
}
|
363
|
+
|
364
|
+
/**
|
365
|
+
* @param {number} start
|
366
|
+
* @param {MultiroomDistanceMap} distance_map
|
367
|
+
* @returns {Path}
|
368
|
+
*/
|
369
|
+
function js_path_to_multiroom_distance_map_origin(start, distance_map) {
|
370
|
+
_assertClass(distance_map, MultiroomDistanceMap);
|
371
|
+
const ret = wasm.js_path_to_multiroom_distance_map_origin(start, distance_map.__wbg_ptr);
|
372
|
+
return Path$1.__wrap(ret);
|
243
373
|
}
|
244
374
|
|
245
375
|
/**
|
@@ -257,51 +387,186 @@ function js_bfs_flow_field(start_packed, cost_matrix) {
|
|
257
387
|
}
|
258
388
|
|
259
389
|
/**
|
260
|
-
*
|
261
|
-
* @param {
|
262
|
-
* @
|
263
|
-
* @returns {MonoFlowField}
|
390
|
+
* @param {number} start
|
391
|
+
* @param {MonoFlowField} flow_field
|
392
|
+
* @returns {Path}
|
264
393
|
*/
|
265
|
-
function
|
266
|
-
|
267
|
-
const
|
268
|
-
|
269
|
-
const ret = wasm.js_dijkstra_mono_flow_field(ptr0, len0, cost_matrix.__wbg_ptr);
|
270
|
-
return MonoFlowField.__wrap(ret);
|
394
|
+
function js_path_to_mono_flow_field_origin(start, flow_field) {
|
395
|
+
_assertClass(flow_field, MonoFlowField);
|
396
|
+
const ret = wasm.js_path_to_mono_flow_field_origin(start, flow_field.__wbg_ptr);
|
397
|
+
return Path$1.__wrap(ret);
|
271
398
|
}
|
272
399
|
|
273
400
|
/**
|
274
401
|
* @param {number} start
|
275
|
-
* @param {
|
402
|
+
* @param {MultiroomMonoFlowField} flow_field
|
276
403
|
* @returns {Path}
|
277
404
|
*/
|
278
|
-
function
|
279
|
-
_assertClass(flow_field,
|
280
|
-
const ret = wasm.
|
405
|
+
function js_path_to_multiroom_mono_flow_field_origin(start, flow_field) {
|
406
|
+
_assertClass(flow_field, MultiroomMonoFlowField);
|
407
|
+
const ret = wasm.js_path_to_multiroom_mono_flow_field_origin(start, flow_field.__wbg_ptr);
|
281
408
|
return Path$1.__wrap(ret);
|
282
409
|
}
|
283
410
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
wasm.
|
411
|
+
let cachedUint16ArrayMemory0 = null;
|
412
|
+
|
413
|
+
function getUint16ArrayMemory0() {
|
414
|
+
if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
|
415
|
+
cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
|
289
416
|
}
|
417
|
+
return cachedUint16ArrayMemory0;
|
290
418
|
}
|
291
419
|
|
292
|
-
function
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
Object.freeze({ Red:1,"1":"Red",Purple:2,"2":"Purple",Blue:3,"3":"Blue",Cyan:4,"4":"Cyan",Green:5,"5":"Green",Yellow:6,"6":"Yellow",Orange:7,"7":"Orange",Brown:8,"8":"Brown",Grey:9,"9":"Grey",White:10,"10":"White", });
|
420
|
+
function getArrayU16FromWasm0(ptr, len) {
|
421
|
+
ptr = ptr >>> 0;
|
422
|
+
return getUint16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
|
423
|
+
}
|
297
424
|
/**
|
298
|
-
*
|
425
|
+
* WASM wrapper for the BFS multiroom monodirectional flow field function.
|
426
|
+
* @param {Uint32Array} start_packed
|
427
|
+
* @param {Function} get_cost_matrix
|
428
|
+
* @param {number} max_tiles
|
429
|
+
* @param {number} max_rooms
|
430
|
+
* @param {number} max_room_distance
|
431
|
+
* @param {number} max_tile_distance
|
432
|
+
* @returns {MultiroomMonoFlowField}
|
299
433
|
*/
|
300
|
-
|
301
|
-
|
302
|
-
|
434
|
+
function js_bfs_multiroom_mono_flow_field(start_packed, get_cost_matrix, max_tiles, max_rooms, max_room_distance, max_tile_distance) {
|
435
|
+
try {
|
436
|
+
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
437
|
+
const len0 = WASM_VECTOR_LEN;
|
438
|
+
const ret = wasm.js_bfs_multiroom_mono_flow_field(ptr0, len0, addBorrowedObject(get_cost_matrix), max_tiles, max_rooms, max_room_distance, max_tile_distance);
|
439
|
+
return MultiroomMonoFlowField.__wrap(ret);
|
440
|
+
} finally {
|
441
|
+
heap[stack_pointer++] = undefined;
|
442
|
+
}
|
443
|
+
}
|
444
|
+
|
445
|
+
/**
|
446
|
+
* WASM wrapper for the BFS mono flow field function.
|
447
|
+
* @param {Uint32Array} start_packed
|
448
|
+
* @param {ClockworkCostMatrix} cost_matrix
|
449
|
+
* @returns {MonoFlowField}
|
450
|
+
*/
|
451
|
+
function js_bfs_mono_flow_field(start_packed, cost_matrix) {
|
452
|
+
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
453
|
+
const len0 = WASM_VECTOR_LEN;
|
454
|
+
_assertClass(cost_matrix, ClockworkCostMatrix);
|
455
|
+
const ret = wasm.js_bfs_mono_flow_field(ptr0, len0, cost_matrix.__wbg_ptr);
|
456
|
+
return MonoFlowField.__wrap(ret);
|
457
|
+
}
|
458
|
+
|
459
|
+
/**
|
460
|
+
* @param {number} start
|
461
|
+
* @param {DistanceMap} distance_map
|
462
|
+
* @returns {Path}
|
463
|
+
*/
|
464
|
+
function js_path_to_distance_map_origin(start, distance_map) {
|
465
|
+
_assertClass(distance_map, DistanceMap);
|
466
|
+
const ret = wasm.js_path_to_distance_map_origin(start, distance_map.__wbg_ptr);
|
467
|
+
return Path$1.__wrap(ret);
|
468
|
+
}
|
469
|
+
|
470
|
+
/**
|
471
|
+
* @param {number} start
|
472
|
+
* @param {MultiroomFlowField} flow_field
|
473
|
+
* @returns {Path}
|
474
|
+
*/
|
475
|
+
function js_path_to_multiroom_flow_field_origin(start, flow_field) {
|
476
|
+
_assertClass(flow_field, MultiroomFlowField);
|
477
|
+
const ret = wasm.js_path_to_multiroom_flow_field_origin(start, flow_field.__wbg_ptr);
|
478
|
+
return Path$1.__wrap(ret);
|
479
|
+
}
|
480
|
+
|
481
|
+
/**
|
482
|
+
* WASM wrapper for the Dijkstra mono flow field function.
|
483
|
+
* @param {Uint32Array} start_packed
|
484
|
+
* @param {ClockworkCostMatrix} cost_matrix
|
485
|
+
* @returns {MonoFlowField}
|
486
|
+
*/
|
487
|
+
function js_dijkstra_mono_flow_field(start_packed, cost_matrix) {
|
488
|
+
const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
|
489
|
+
const len0 = WASM_VECTOR_LEN;
|
490
|
+
_assertClass(cost_matrix, ClockworkCostMatrix);
|
491
|
+
const ret = wasm.js_dijkstra_mono_flow_field(ptr0, len0, cost_matrix.__wbg_ptr);
|
492
|
+
return MonoFlowField.__wrap(ret);
|
493
|
+
}
|
494
|
+
|
495
|
+
function getArrayU32FromWasm0(ptr, len) {
|
496
|
+
ptr = ptr >>> 0;
|
497
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
498
|
+
}
|
499
|
+
/**
|
500
|
+
* @returns {string}
|
501
|
+
*/
|
502
|
+
function version() {
|
503
|
+
let deferred1_0;
|
504
|
+
let deferred1_1;
|
505
|
+
try {
|
506
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
507
|
+
wasm.version(retptr);
|
508
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
509
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
510
|
+
deferred1_0 = r0;
|
511
|
+
deferred1_1 = r1;
|
512
|
+
return getStringFromWasm0(r0, r1);
|
513
|
+
} finally {
|
514
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
515
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
516
|
+
}
|
517
|
+
}
|
518
|
+
|
519
|
+
/**
|
520
|
+
* Exports the global range calculation between two positions.
|
521
|
+
* @param {number} packed_pos_1
|
522
|
+
* @param {number} packed_pos_2
|
523
|
+
* @returns {number}
|
524
|
+
*/
|
525
|
+
function get_range(packed_pos_1, packed_pos_2) {
|
526
|
+
const ret = wasm.get_range(packed_pos_1, packed_pos_2);
|
527
|
+
return ret >>> 0;
|
528
|
+
}
|
529
|
+
|
530
|
+
/**
|
531
|
+
* Translates `COLOR_*` and `COLORS_ALL` constants.
|
532
|
+
* @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}
|
533
|
+
*/
|
534
|
+
Object.freeze({
|
535
|
+
Red: 1, "1": "Red",
|
536
|
+
Purple: 2, "2": "Purple",
|
537
|
+
Blue: 3, "3": "Blue",
|
538
|
+
Cyan: 4, "4": "Cyan",
|
539
|
+
Green: 5, "5": "Green",
|
540
|
+
Yellow: 6, "6": "Yellow",
|
541
|
+
Orange: 7, "7": "Orange",
|
542
|
+
Brown: 8, "8": "Brown",
|
543
|
+
Grey: 9, "9": "Grey",
|
544
|
+
White: 10, "10": "White",
|
545
|
+
});
|
546
|
+
/**
|
547
|
+
* Translates the `DENSITY_*` constants.
|
548
|
+
* @enum {1 | 2 | 3 | 4}
|
549
|
+
*/
|
550
|
+
Object.freeze({
|
551
|
+
Low: 1, "1": "Low",
|
552
|
+
Moderate: 2, "2": "Moderate",
|
553
|
+
High: 3, "3": "High",
|
554
|
+
Ultra: 4, "4": "Ultra",
|
555
|
+
});
|
556
|
+
/**
|
557
|
+
* Translates direction constants.
|
558
|
+
* @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8}
|
303
559
|
*/
|
304
|
-
Object.freeze({
|
560
|
+
Object.freeze({
|
561
|
+
Top: 1, "1": "Top",
|
562
|
+
TopRight: 2, "2": "TopRight",
|
563
|
+
Right: 3, "3": "Right",
|
564
|
+
BottomRight: 4, "4": "BottomRight",
|
565
|
+
Bottom: 5, "5": "Bottom",
|
566
|
+
BottomLeft: 6, "6": "BottomLeft",
|
567
|
+
Left: 7, "7": "Left",
|
568
|
+
TopLeft: 8, "8": "TopLeft",
|
569
|
+
});
|
305
570
|
/**
|
306
571
|
* Type used for when the game returns a direction to an exit.
|
307
572
|
*
|
@@ -313,8 +578,14 @@ Object.freeze({ Top:1,"1":"Top",TopRight:2,"2":"TopRight",Right:3,"3":"Right",Bo
|
|
313
578
|
*
|
314
579
|
* [`Room::find`]: crate::objects::Room::find
|
315
580
|
* [`Room::find_exit_to`]: crate::objects::Room::find_exit_to
|
581
|
+
* @enum {1 | 3 | 5 | 7}
|
316
582
|
*/
|
317
|
-
Object.freeze({
|
583
|
+
Object.freeze({
|
584
|
+
Top: 1, "1": "Top",
|
585
|
+
Right: 3, "3": "Right",
|
586
|
+
Bottom: 5, "5": "Bottom",
|
587
|
+
Left: 7, "7": "Left",
|
588
|
+
});
|
318
589
|
/**
|
319
590
|
* Translates `FIND_*` constants for interal API calls
|
320
591
|
*
|
@@ -324,25 +595,88 @@ Object.freeze({ Top:1,"1":"Top",Right:3,"3":"Right",Bottom:5,"5":"Bottom",Left:7
|
|
324
595
|
*
|
325
596
|
* This is hidden from the documentation to avoid confusion due to its narrow
|
326
597
|
* use case, but wasm_bindgen requires it remain public.
|
598
|
+
* @enum {1 | 3 | 5 | 7 | 10 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 10011 | 10012 | 10021 | 10022 | 10051}
|
327
599
|
*/
|
328
600
|
Object.freeze({
|
329
|
-
/**
|
330
|
-
|
331
|
-
|
332
|
-
ExitTop:1,"1":"ExitTop",
|
601
|
+
/**
|
602
|
+
* Find all exit positions at the top of the room
|
603
|
+
*/
|
604
|
+
ExitTop: 1, "1": "ExitTop",
|
605
|
+
ExitRight: 3, "3": "ExitRight",
|
606
|
+
ExitBottom: 5, "5": "ExitBottom",
|
607
|
+
ExitLeft: 7, "7": "ExitLeft",
|
608
|
+
Exit: 10, "10": "Exit",
|
609
|
+
Creeps: 101, "101": "Creeps",
|
610
|
+
MyCreeps: 102, "102": "MyCreeps",
|
611
|
+
HostileCreeps: 103, "103": "HostileCreeps",
|
612
|
+
SourcesActive: 104, "104": "SourcesActive",
|
613
|
+
Sources: 105, "105": "Sources",
|
614
|
+
DroppedResources: 106, "106": "DroppedResources",
|
615
|
+
Structures: 107, "107": "Structures",
|
616
|
+
MyStructures: 108, "108": "MyStructures",
|
617
|
+
HostileStructures: 109, "109": "HostileStructures",
|
618
|
+
Flags: 110, "110": "Flags",
|
619
|
+
ConstructionSites: 111, "111": "ConstructionSites",
|
620
|
+
MySpawns: 112, "112": "MySpawns",
|
621
|
+
HostileSpawns: 113, "113": "HostileSpawns",
|
622
|
+
MyConstructionSites: 114, "114": "MyConstructionSites",
|
623
|
+
HostileConstructionSites: 115, "115": "HostileConstructionSites",
|
624
|
+
Minerals: 116, "116": "Minerals",
|
625
|
+
Nukes: 117, "117": "Nukes",
|
626
|
+
Tombstones: 118, "118": "Tombstones",
|
627
|
+
PowerCreeps: 119, "119": "PowerCreeps",
|
628
|
+
MyPowerCreeps: 120, "120": "MyPowerCreeps",
|
629
|
+
HostilePowerCreeps: 121, "121": "HostilePowerCreeps",
|
630
|
+
Deposits: 122, "122": "Deposits",
|
631
|
+
Ruins: 123, "123": "Ruins",
|
632
|
+
ScoreContainers: 10011, "10011": "ScoreContainers",
|
633
|
+
ScoreCollectors: 10012, "10012": "ScoreCollectors",
|
634
|
+
SymbolContainers: 10021, "10021": "SymbolContainers",
|
635
|
+
SymbolDecoders: 10022, "10022": "SymbolDecoders",
|
636
|
+
Reactors: 10051, "10051": "Reactors",
|
637
|
+
});
|
333
638
|
/**
|
334
639
|
* Translates the `EFFECT_*` constants, which are natural effect types
|
640
|
+
* @enum {1001 | 1002}
|
335
641
|
*/
|
336
|
-
Object.freeze({
|
642
|
+
Object.freeze({
|
643
|
+
Invulnerability: 1001, "1001": "Invulnerability",
|
644
|
+
CollapseTimer: 1002, "1002": "CollapseTimer",
|
645
|
+
});
|
337
646
|
/**
|
338
647
|
* Translates the `PWR_*` constants, which are types of powers used by power
|
339
648
|
* creeps
|
649
|
+
* @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19}
|
340
650
|
*/
|
341
|
-
Object.freeze({
|
651
|
+
Object.freeze({
|
652
|
+
GenerateOps: 1, "1": "GenerateOps",
|
653
|
+
OperateSpawn: 2, "2": "OperateSpawn",
|
654
|
+
OperateTower: 3, "3": "OperateTower",
|
655
|
+
OperateStorage: 4, "4": "OperateStorage",
|
656
|
+
OperateLab: 5, "5": "OperateLab",
|
657
|
+
OperateExtension: 6, "6": "OperateExtension",
|
658
|
+
OperateObserver: 7, "7": "OperateObserver",
|
659
|
+
OperateTerminal: 8, "8": "OperateTerminal",
|
660
|
+
DisruptSpawn: 9, "9": "DisruptSpawn",
|
661
|
+
DisruptTower: 10, "10": "DisruptTower",
|
662
|
+
Shield: 12, "12": "Shield",
|
663
|
+
RegenSource: 13, "13": "RegenSource",
|
664
|
+
RegenMineral: 14, "14": "RegenMineral",
|
665
|
+
DisruptTerminal: 15, "15": "DisruptTerminal",
|
666
|
+
OperatePower: 16, "16": "OperatePower",
|
667
|
+
Fortify: 17, "17": "Fortify",
|
668
|
+
OperateController: 18, "18": "OperateController",
|
669
|
+
OperateFactory: 19, "19": "OperateFactory",
|
670
|
+
});
|
342
671
|
/**
|
343
672
|
* Translates `TERRAIN_*` constants.
|
673
|
+
* @enum {0 | 1 | 2}
|
344
674
|
*/
|
345
|
-
Object.freeze({
|
675
|
+
Object.freeze({
|
676
|
+
Plain: 0, "0": "Plain",
|
677
|
+
Wall: 1, "1": "Wall",
|
678
|
+
Swamp: 2, "2": "Swamp",
|
679
|
+
});
|
346
680
|
|
347
681
|
const __wbindgen_enum_Look = ["creep", "energy", "resource", "source", "mineral", "structure", "flag", "constructionSite", "nuke", "terrain", "tombstone", "powerCreep", "deposit", "ruin", "scoreContainer", "scoreCollector", "symbolContainer", "symbolDecoder", "reactor"];
|
348
682
|
|
@@ -607,90 +941,178 @@ class MonoFlowField {
|
|
607
941
|
}
|
608
942
|
}
|
609
943
|
|
610
|
-
const
|
944
|
+
const MultiroomDistanceMapFinalization = (typeof FinalizationRegistry === 'undefined')
|
611
945
|
? { register: () => {}, unregister: () => {} }
|
612
|
-
: new FinalizationRegistry(ptr => wasm.
|
946
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_multiroomdistancemap_free(ptr >>> 0, 1));
|
613
947
|
/**
|
614
|
-
*
|
948
|
+
* Maps distance values across multiple rooms, storing a DistanceMap for each room
|
615
949
|
*/
|
616
|
-
class
|
950
|
+
class MultiroomDistanceMap {
|
617
951
|
|
618
952
|
static __wrap(ptr) {
|
619
953
|
ptr = ptr >>> 0;
|
620
|
-
const obj = Object.create(
|
954
|
+
const obj = Object.create(MultiroomDistanceMap.prototype);
|
621
955
|
obj.__wbg_ptr = ptr;
|
622
|
-
|
956
|
+
MultiroomDistanceMapFinalization.register(obj, obj.__wbg_ptr, obj);
|
623
957
|
return obj;
|
624
958
|
}
|
625
959
|
|
626
960
|
__destroy_into_raw() {
|
627
961
|
const ptr = this.__wbg_ptr;
|
628
962
|
this.__wbg_ptr = 0;
|
629
|
-
|
963
|
+
MultiroomDistanceMapFinalization.unregister(this);
|
630
964
|
return ptr;
|
631
965
|
}
|
632
966
|
|
633
967
|
free() {
|
634
968
|
const ptr = this.__destroy_into_raw();
|
635
|
-
wasm.
|
969
|
+
wasm.__wbg_multiroomdistancemap_free(ptr, 0);
|
636
970
|
}
|
637
971
|
/**
|
638
|
-
*
|
972
|
+
* Creates a new empty multiroom distance map (JavaScript constructor)
|
639
973
|
*/
|
640
|
-
|
641
|
-
wasm.
|
974
|
+
constructor() {
|
975
|
+
const ret = wasm.multiroomdistancemap_js_new();
|
976
|
+
this.__wbg_ptr = ret >>> 0;
|
977
|
+
MultiroomDistanceMapFinalization.register(this, this.__wbg_ptr, this);
|
978
|
+
return this;
|
642
979
|
}
|
643
980
|
/**
|
644
|
-
*
|
645
|
-
* @
|
981
|
+
* Gets the distance value at a given position
|
982
|
+
* @param {number} packed_pos
|
983
|
+
* @returns {number}
|
646
984
|
*/
|
647
|
-
get(
|
985
|
+
get(packed_pos) {
|
986
|
+
const ret = wasm.multiroomdistancemap_get(this.__wbg_ptr, packed_pos);
|
987
|
+
return ret >>> 0;
|
988
|
+
}
|
989
|
+
/**
|
990
|
+
* Sets the distance value at a given position
|
991
|
+
* @param {number} packed_pos
|
992
|
+
* @param {number} value
|
993
|
+
*/
|
994
|
+
set(packed_pos, value) {
|
995
|
+
wasm.multiroomdistancemap_set(this.__wbg_ptr, packed_pos, value);
|
996
|
+
}
|
997
|
+
/**
|
998
|
+
* Gets the list of rooms in the map
|
999
|
+
* @returns {Uint16Array}
|
1000
|
+
*/
|
1001
|
+
get_rooms() {
|
648
1002
|
try {
|
649
1003
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
650
|
-
wasm.
|
1004
|
+
wasm.multiroomdistancemap_get_rooms(retptr, this.__wbg_ptr);
|
651
1005
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
652
1006
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
653
|
-
|
1007
|
+
var v1 = getArrayU16FromWasm0(r0, r1).slice();
|
1008
|
+
wasm.__wbindgen_free(r0, r1 * 2, 2);
|
1009
|
+
return v1;
|
654
1010
|
} finally {
|
655
1011
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
656
1012
|
}
|
657
1013
|
}
|
658
1014
|
/**
|
1015
|
+
* Gets the DistanceMap for a given room
|
1016
|
+
* @param {number} room_name
|
1017
|
+
* @returns {DistanceMap | undefined}
|
1018
|
+
*/
|
1019
|
+
get_room(room_name) {
|
1020
|
+
const ret = wasm.multiroomdistancemap_get_room(this.__wbg_ptr, room_name);
|
1021
|
+
return ret === 0 ? undefined : DistanceMap.__wrap(ret);
|
1022
|
+
}
|
1023
|
+
}
|
1024
|
+
|
1025
|
+
const MultiroomFlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
|
1026
|
+
? { register: () => {}, unregister: () => {} }
|
1027
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_multiroomflowfield_free(ptr >>> 0, 1));
|
1028
|
+
/**
|
1029
|
+
* Maps flow field values across multiple rooms, storing a FlowField for each room
|
1030
|
+
*/
|
1031
|
+
class MultiroomFlowField {
|
1032
|
+
|
1033
|
+
static __wrap(ptr) {
|
1034
|
+
ptr = ptr >>> 0;
|
1035
|
+
const obj = Object.create(MultiroomFlowField.prototype);
|
1036
|
+
obj.__wbg_ptr = ptr;
|
1037
|
+
MultiroomFlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
|
1038
|
+
return obj;
|
1039
|
+
}
|
1040
|
+
|
1041
|
+
__destroy_into_raw() {
|
1042
|
+
const ptr = this.__wbg_ptr;
|
1043
|
+
this.__wbg_ptr = 0;
|
1044
|
+
MultiroomFlowFieldFinalization.unregister(this);
|
1045
|
+
return ptr;
|
1046
|
+
}
|
1047
|
+
|
1048
|
+
free() {
|
1049
|
+
const ptr = this.__destroy_into_raw();
|
1050
|
+
wasm.__wbg_multiroomflowfield_free(ptr, 0);
|
1051
|
+
}
|
1052
|
+
/**
|
1053
|
+
* Creates a new empty multiroom flow field (JavaScript constructor)
|
1054
|
+
*/
|
1055
|
+
constructor() {
|
1056
|
+
const ret = wasm.multiroomflowfield_js_new();
|
1057
|
+
this.__wbg_ptr = ret >>> 0;
|
1058
|
+
MultiroomFlowFieldFinalization.register(this, this.__wbg_ptr, this);
|
1059
|
+
return this;
|
1060
|
+
}
|
1061
|
+
/**
|
1062
|
+
* Gets the flow field value at a given position
|
1063
|
+
* @param {number} packed_pos
|
659
1064
|
* @returns {number}
|
660
1065
|
*/
|
661
|
-
|
662
|
-
const ret = wasm.
|
663
|
-
return ret
|
1066
|
+
get(packed_pos) {
|
1067
|
+
const ret = wasm.multiroomflowfield_get(this.__wbg_ptr, packed_pos);
|
1068
|
+
return ret;
|
664
1069
|
}
|
665
1070
|
/**
|
666
|
-
*
|
667
|
-
*
|
668
|
-
*
|
669
|
-
* the position is neither on nor adjacent to the path, return None.
|
670
|
-
* @param {number} packed_position
|
671
|
-
* @returns {number | undefined}
|
1071
|
+
* Sets the flow field value at a given position
|
1072
|
+
* @param {number} packed_pos
|
1073
|
+
* @param {number} value
|
672
1074
|
*/
|
673
|
-
|
1075
|
+
set(packed_pos, value) {
|
1076
|
+
wasm.multiroomflowfield_set(this.__wbg_ptr, packed_pos, value);
|
1077
|
+
}
|
1078
|
+
/**
|
1079
|
+
* Gets the list of rooms in the flow field
|
1080
|
+
* @returns {Uint16Array}
|
1081
|
+
*/
|
1082
|
+
getRooms() {
|
674
1083
|
try {
|
675
1084
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
676
|
-
wasm.
|
1085
|
+
wasm.multiroomflowfield_getRooms(retptr, this.__wbg_ptr);
|
677
1086
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
678
1087
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
679
|
-
|
1088
|
+
var v1 = getArrayU16FromWasm0(r0, r1).slice();
|
1089
|
+
wasm.__wbindgen_free(r0, r1 * 2, 2);
|
1090
|
+
return v1;
|
680
1091
|
} finally {
|
681
1092
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
682
1093
|
}
|
683
1094
|
}
|
684
1095
|
/**
|
685
|
-
*
|
1096
|
+
* Gets the FlowField for a given room
|
1097
|
+
* @param {number} room_name
|
1098
|
+
* @returns {FlowField | undefined}
|
686
1099
|
*/
|
687
|
-
|
1100
|
+
getRoom(room_name) {
|
1101
|
+
const ret = wasm.multiroomflowfield_getRoom(this.__wbg_ptr, room_name);
|
1102
|
+
return ret === 0 ? undefined : FlowField.__wrap(ret);
|
1103
|
+
}
|
1104
|
+
/**
|
1105
|
+
* Gets the list of valid directions at a given position (JavaScript)
|
1106
|
+
* @param {number} packed_pos
|
1107
|
+
* @returns {any[]}
|
1108
|
+
*/
|
1109
|
+
getDirections(packed_pos) {
|
688
1110
|
try {
|
689
1111
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
690
|
-
wasm.
|
1112
|
+
wasm.multiroomflowfield_getDirections(retptr, this.__wbg_ptr, packed_pos);
|
691
1113
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
692
1114
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
693
|
-
var v1 =
|
1115
|
+
var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
|
694
1116
|
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
695
1117
|
return v1;
|
696
1118
|
} finally {
|
@@ -698,36 +1120,290 @@ class Path$1 {
|
|
698
1120
|
}
|
699
1121
|
}
|
700
1122
|
/**
|
701
|
-
*
|
1123
|
+
* Sets the list of valid directions at a given position (JavaScript)
|
1124
|
+
* @param {number} packed_pos
|
1125
|
+
* @param {any[]} directions
|
702
1126
|
*/
|
703
|
-
|
1127
|
+
setDirections(packed_pos, directions) {
|
1128
|
+
const ptr0 = passArrayJsValueToWasm0(directions, wasm.__wbindgen_malloc);
|
1129
|
+
const len0 = WASM_VECTOR_LEN;
|
1130
|
+
wasm.multiroomflowfield_setDirections(this.__wbg_ptr, packed_pos, ptr0, len0);
|
1131
|
+
}
|
1132
|
+
/**
|
1133
|
+
* Adds a direction to the list of valid directions at a given position (JavaScript)
|
1134
|
+
* @param {number} packed_pos
|
1135
|
+
* @param {Direction} direction
|
1136
|
+
*/
|
1137
|
+
addDirection(packed_pos, direction) {
|
1138
|
+
wasm.multiroomflowfield_addDirection(this.__wbg_ptr, packed_pos, direction);
|
1139
|
+
}
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
const MultiroomMonoFlowFieldFinalization = (typeof FinalizationRegistry === 'undefined')
|
1143
|
+
? { register: () => {}, unregister: () => {} }
|
1144
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_multiroommonoflowfield_free(ptr >>> 0, 1));
|
1145
|
+
/**
|
1146
|
+
* Maps monodirectional flow field values across multiple rooms, storing a MonoFlowField for each room
|
1147
|
+
*/
|
1148
|
+
class MultiroomMonoFlowField {
|
1149
|
+
|
1150
|
+
static __wrap(ptr) {
|
1151
|
+
ptr = ptr >>> 0;
|
1152
|
+
const obj = Object.create(MultiroomMonoFlowField.prototype);
|
1153
|
+
obj.__wbg_ptr = ptr;
|
1154
|
+
MultiroomMonoFlowFieldFinalization.register(obj, obj.__wbg_ptr, obj);
|
1155
|
+
return obj;
|
1156
|
+
}
|
1157
|
+
|
1158
|
+
__destroy_into_raw() {
|
1159
|
+
const ptr = this.__wbg_ptr;
|
1160
|
+
this.__wbg_ptr = 0;
|
1161
|
+
MultiroomMonoFlowFieldFinalization.unregister(this);
|
1162
|
+
return ptr;
|
1163
|
+
}
|
1164
|
+
|
1165
|
+
free() {
|
1166
|
+
const ptr = this.__destroy_into_raw();
|
1167
|
+
wasm.__wbg_multiroommonoflowfield_free(ptr, 0);
|
1168
|
+
}
|
1169
|
+
/**
|
1170
|
+
* Creates a new empty multiroom monodirectional flow field (JavaScript constructor)
|
1171
|
+
*/
|
1172
|
+
constructor() {
|
1173
|
+
const ret = wasm.multiroomdistancemap_js_new();
|
1174
|
+
this.__wbg_ptr = ret >>> 0;
|
1175
|
+
MultiroomMonoFlowFieldFinalization.register(this, this.__wbg_ptr, this);
|
1176
|
+
return this;
|
1177
|
+
}
|
1178
|
+
/**
|
1179
|
+
* Gets the direction at a given position
|
1180
|
+
* @param {number} packed_pos
|
1181
|
+
* @returns {Direction | undefined}
|
1182
|
+
*/
|
1183
|
+
get(packed_pos) {
|
1184
|
+
const ret = wasm.multiroommonoflowfield_get(this.__wbg_ptr, packed_pos);
|
1185
|
+
return ret === 0 ? undefined : ret;
|
1186
|
+
}
|
1187
|
+
/**
|
1188
|
+
* Sets the direction at a given position
|
1189
|
+
* @param {number} packed_pos
|
1190
|
+
* @param {Direction | undefined} [direction]
|
1191
|
+
*/
|
1192
|
+
set(packed_pos, direction) {
|
1193
|
+
wasm.multiroommonoflowfield_set(this.__wbg_ptr, packed_pos, isLikeNone(direction) ? 0 : direction);
|
1194
|
+
}
|
1195
|
+
/**
|
1196
|
+
* Gets the list of rooms in the flow field
|
1197
|
+
* @returns {Uint16Array}
|
1198
|
+
*/
|
1199
|
+
getRooms() {
|
704
1200
|
try {
|
705
1201
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
706
|
-
wasm.
|
1202
|
+
wasm.multiroommonoflowfield_getRooms(retptr, this.__wbg_ptr);
|
707
1203
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
708
1204
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
709
|
-
var v1 =
|
710
|
-
wasm.__wbindgen_free(r0, r1 *
|
1205
|
+
var v1 = getArrayU16FromWasm0(r0, r1).slice();
|
1206
|
+
wasm.__wbindgen_free(r0, r1 * 2, 2);
|
711
1207
|
return v1;
|
712
1208
|
} finally {
|
713
1209
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
714
1210
|
}
|
715
1211
|
}
|
1212
|
+
/**
|
1213
|
+
* Gets the MonoFlowField for a given room
|
1214
|
+
* @param {number} room_name
|
1215
|
+
* @returns {MonoFlowField | undefined}
|
1216
|
+
*/
|
1217
|
+
getRoom(room_name) {
|
1218
|
+
const ret = wasm.multiroommonoflowfield_getRoom(this.__wbg_ptr, room_name);
|
1219
|
+
return ret === 0 ? undefined : MonoFlowField.__wrap(ret);
|
1220
|
+
}
|
716
1221
|
}
|
717
1222
|
|
718
|
-
(typeof FinalizationRegistry === 'undefined')
|
1223
|
+
const PathFinalization = (typeof FinalizationRegistry === 'undefined')
|
719
1224
|
? { register: () => {}, unregister: () => {} }
|
720
|
-
: new FinalizationRegistry(ptr => wasm.
|
1225
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_path_free(ptr >>> 0, 1));
|
1226
|
+
/**
|
1227
|
+
* A list of positions representing a path.
|
1228
|
+
*/
|
1229
|
+
class Path$1 {
|
721
1230
|
|
722
|
-
(
|
723
|
-
|
724
|
-
|
1231
|
+
static __wrap(ptr) {
|
1232
|
+
ptr = ptr >>> 0;
|
1233
|
+
const obj = Object.create(Path$1.prototype);
|
1234
|
+
obj.__wbg_ptr = ptr;
|
1235
|
+
PathFinalization.register(obj, obj.__wbg_ptr, obj);
|
1236
|
+
return obj;
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
__destroy_into_raw() {
|
1240
|
+
const ptr = this.__wbg_ptr;
|
1241
|
+
this.__wbg_ptr = 0;
|
1242
|
+
PathFinalization.unregister(this);
|
1243
|
+
return ptr;
|
1244
|
+
}
|
1245
|
+
|
1246
|
+
free() {
|
1247
|
+
const ptr = this.__destroy_into_raw();
|
1248
|
+
wasm.__wbg_path_free(ptr, 0);
|
1249
|
+
}
|
1250
|
+
/**
|
1251
|
+
* @param {number} packed_position
|
1252
|
+
*/
|
1253
|
+
add(packed_position) {
|
1254
|
+
wasm.path_add(this.__wbg_ptr, packed_position);
|
1255
|
+
}
|
1256
|
+
/**
|
1257
|
+
* @param {number} index
|
1258
|
+
* @returns {number | undefined}
|
1259
|
+
*/
|
1260
|
+
get(index) {
|
1261
|
+
const ret = wasm.path_get(this.__wbg_ptr, index);
|
1262
|
+
return ret === 0x100000001 ? undefined : ret;
|
1263
|
+
}
|
1264
|
+
/**
|
1265
|
+
* @returns {number}
|
1266
|
+
*/
|
1267
|
+
len() {
|
1268
|
+
const ret = wasm.path_len(this.__wbg_ptr);
|
1269
|
+
return ret >>> 0;
|
1270
|
+
}
|
1271
|
+
/**
|
1272
|
+
* Given a position, find the index of the next adjacent position
|
1273
|
+
* in the path. If the position is not in the path, the target is
|
1274
|
+
* the next adjacent position closest to the end of the path. If
|
1275
|
+
* the position is neither on nor adjacent to the path, return None.
|
1276
|
+
* @param {number} packed_position
|
1277
|
+
* @returns {number | undefined}
|
1278
|
+
*/
|
1279
|
+
find_next_index(packed_position) {
|
1280
|
+
const ret = wasm.path_find_next_index(this.__wbg_ptr, packed_position);
|
1281
|
+
return ret === 0x100000001 ? undefined : ret;
|
1282
|
+
}
|
1283
|
+
/**
|
1284
|
+
* @returns {Uint32Array}
|
1285
|
+
*/
|
1286
|
+
to_array() {
|
1287
|
+
try {
|
1288
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
1289
|
+
wasm.path_to_array(retptr, this.__wbg_ptr);
|
1290
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
1291
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
1292
|
+
var v1 = getArrayU32FromWasm0(r0, r1).slice();
|
1293
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
1294
|
+
return v1;
|
1295
|
+
} finally {
|
1296
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
1297
|
+
}
|
1298
|
+
}
|
1299
|
+
/**
|
1300
|
+
* @returns {Uint32Array}
|
1301
|
+
*/
|
1302
|
+
to_array_reversed() {
|
1303
|
+
try {
|
1304
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
1305
|
+
wasm.path_to_array_reversed(retptr, this.__wbg_ptr);
|
1306
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
1307
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
1308
|
+
var v1 = getArrayU32FromWasm0(r0, r1).slice();
|
1309
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
1310
|
+
return v1;
|
1311
|
+
} finally {
|
1312
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
1313
|
+
}
|
1314
|
+
}
|
1315
|
+
}
|
1316
|
+
|
1317
|
+
(typeof FinalizationRegistry === 'undefined')
|
1318
|
+
? { register: () => {}, unregister: () => {} }
|
1319
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_pathfatigue_free(ptr >>> 0, 1));
|
1320
|
+
|
1321
|
+
(typeof FinalizationRegistry === 'undefined')
|
1322
|
+
? { register: () => {}, unregister: () => {} }
|
1323
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_searchgoal_free(ptr >>> 0, 1));
|
725
1324
|
|
726
1325
|
function __wbg_get_imports() {
|
727
1326
|
const imports = {};
|
728
1327
|
imports.wbg = {};
|
729
|
-
imports.wbg.
|
730
|
-
|
1328
|
+
imports.wbg.__wbg_call_0411c0c3c424db9a = function() { return handleError(function (arg0, arg1, arg2) {
|
1329
|
+
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
|
1330
|
+
return addHeapObject(ret);
|
1331
|
+
}, arguments) };
|
1332
|
+
imports.wbg.__wbg_ceil_73d048b08f059b46 = function(arg0) {
|
1333
|
+
const ret = Math.ceil(arg0);
|
1334
|
+
return ret;
|
1335
|
+
};
|
1336
|
+
imports.wbg.__wbg_clockworkcostmatrixgetpointer_79ff2a01ab0022a6 = function(arg0) {
|
1337
|
+
const ret = clockworkcostmatrix_get_pointer(takeObject(arg0));
|
1338
|
+
return ret;
|
1339
|
+
};
|
1340
|
+
imports.wbg.__wbg_create_7616c10d022615b4 = function(arg0) {
|
1341
|
+
const ret = Object.create(getObject(arg0));
|
1342
|
+
return addHeapObject(ret);
|
1343
|
+
};
|
1344
|
+
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
1345
|
+
let deferred0_0;
|
1346
|
+
let deferred0_1;
|
1347
|
+
try {
|
1348
|
+
deferred0_0 = arg0;
|
1349
|
+
deferred0_1 = arg1;
|
1350
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
1351
|
+
} finally {
|
1352
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
1353
|
+
}
|
1354
|
+
};
|
1355
|
+
imports.wbg.__wbg_getRoomTerrain_82fcc54e35a8985e = function() { return handleError(function (arg0) {
|
1356
|
+
const ret = Game.map.getRoomTerrain(getObject(arg0));
|
1357
|
+
return addHeapObject(ret);
|
1358
|
+
}, arguments) };
|
1359
|
+
imports.wbg.__wbg_get_1f5a4efd15e39f01 = function(arg0, arg1, arg2) {
|
1360
|
+
const ret = getObject(arg0).get(arg1, arg2);
|
1361
|
+
return ret;
|
1362
|
+
};
|
1363
|
+
imports.wbg.__wbg_get_68aa371864aa301a = function(arg0, arg1) {
|
1364
|
+
const ret = getObject(arg0)[arg1 >>> 0];
|
1365
|
+
return addHeapObject(ret);
|
1366
|
+
};
|
1367
|
+
imports.wbg.__wbg_getvalue_a18eaf2c77e125e4 = function(arg0, arg1) {
|
1368
|
+
const ret = getObject(arg0)[getObject(arg1)];
|
1369
|
+
return addHeapObject(ret);
|
1370
|
+
};
|
1371
|
+
imports.wbg.__wbg_length_e74df4881604f1d9 = function(arg0) {
|
1372
|
+
const ret = getObject(arg0).length;
|
1373
|
+
return ret;
|
1374
|
+
};
|
1375
|
+
imports.wbg.__wbg_log_e9cc7e18c0c70cf4 = function(arg0, arg1) {
|
1376
|
+
console.log(getStringFromWasm0(arg0, arg1));
|
1377
|
+
};
|
1378
|
+
imports.wbg.__wbg_lookFor_04c5885fea38e9b2 = function() { return handleError(function (arg0, arg1) {
|
1379
|
+
const ret = getObject(arg0).lookFor(__wbindgen_enum_Look[arg1]);
|
1380
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
1381
|
+
}, arguments) };
|
1382
|
+
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
1383
|
+
const ret = new Error();
|
1384
|
+
return addHeapObject(ret);
|
1385
|
+
};
|
1386
|
+
imports.wbg.__wbg_rooms_c7983d4650f28959 = function() {
|
1387
|
+
const ret = Game.rooms;
|
1388
|
+
return addHeapObject(ret);
|
1389
|
+
};
|
1390
|
+
imports.wbg.__wbg_setpacked_50526296a5796941 = function(arg0, arg1) {
|
1391
|
+
getObject(arg0).__packedPos = arg1 >>> 0;
|
1392
|
+
};
|
1393
|
+
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
1394
|
+
const ret = getObject(arg1).stack;
|
1395
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
1396
|
+
const len1 = WASM_VECTOR_LEN;
|
1397
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
1398
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
1399
|
+
};
|
1400
|
+
imports.wbg.__wbg_static_accessor_ROOM_POSITION_PROTOTYPE_359d8a1531b99b4c = function() {
|
1401
|
+
const ret = RoomPosition.prototype;
|
1402
|
+
return addHeapObject(ret);
|
1403
|
+
};
|
1404
|
+
imports.wbg.__wbg_structuretype_d5991613c372a27e = function(arg0) {
|
1405
|
+
const ret = getObject(arg0).structureType;
|
1406
|
+
return (__wbindgen_enum_StructureType.indexOf(ret) + 1 || 22) - 1;
|
731
1407
|
};
|
732
1408
|
imports.wbg.__wbindgen_is_null = function(arg0) {
|
733
1409
|
const ret = getObject(arg0) === null;
|
@@ -747,70 +1423,33 @@ function __wbg_get_imports() {
|
|
747
1423
|
const ret = arg0;
|
748
1424
|
return addHeapObject(ret);
|
749
1425
|
};
|
1426
|
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
1427
|
+
takeObject(arg0);
|
1428
|
+
};
|
1429
|
+
imports.wbg.__wbindgen_rethrow = function(arg0) {
|
1430
|
+
throw takeObject(arg0);
|
1431
|
+
};
|
1432
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
1433
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
1434
|
+
return addHeapObject(ret);
|
1435
|
+
};
|
1436
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
1437
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
1438
|
+
};
|
750
1439
|
imports.wbg.__wbindgen_try_into_number = function(arg0) {
|
751
1440
|
let result;
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
};
|
756
|
-
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
757
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
758
|
-
return addHeapObject(ret);
|
759
|
-
};
|
760
|
-
imports.wbg.__wbg_setpacked_e36387710a3ff5bb = function(arg0, arg1) {
|
761
|
-
getObject(arg0).__packedPos = arg1 >>> 0;
|
762
|
-
};
|
763
|
-
imports.wbg.__wbg_getvalue_b80bdd3552834f00 = function(arg0, arg1) {
|
764
|
-
const ret = getObject(arg0)[getObject(arg1)];
|
765
|
-
return addHeapObject(ret);
|
766
|
-
};
|
767
|
-
imports.wbg.__wbg_getRoomTerrain_de7e854c5bcae92b = function() { return handleError(function (arg0) {
|
768
|
-
const ret = Game.map.getRoomTerrain(getObject(arg0));
|
769
|
-
return addHeapObject(ret);
|
770
|
-
}, arguments) };
|
771
|
-
imports.wbg.__wbg_lookFor_649f089b6bfdb0c7 = function() { return handleError(function (arg0, arg1) {
|
772
|
-
const ret = getObject(arg0).lookFor(__wbindgen_enum_Look[arg1]);
|
773
|
-
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
774
|
-
}, arguments) };
|
775
|
-
imports.wbg.__wbg_rooms_8265844828084f14 = function() {
|
776
|
-
const ret = Game.rooms;
|
777
|
-
return addHeapObject(ret);
|
778
|
-
};
|
779
|
-
imports.wbg.__wbg_static_accessor_ROOM_POSITION_PROTOTYPE_359d8a1531b99b4c = function() {
|
780
|
-
const ret = RoomPosition.prototype;
|
781
|
-
return addHeapObject(ret);
|
782
|
-
};
|
783
|
-
imports.wbg.__wbg_structuretype_f649797e27122f54 = function(arg0) {
|
784
|
-
const ret = getObject(arg0).structureType;
|
785
|
-
return (__wbindgen_enum_StructureType.indexOf(ret) + 1 || 22) - 1;
|
786
|
-
};
|
787
|
-
imports.wbg.__wbg_get_ac6072ecac1ab4ec = function(arg0, arg1, arg2) {
|
788
|
-
const ret = getObject(arg0).get(arg1, arg2);
|
789
|
-
return ret;
|
790
|
-
};
|
791
|
-
imports.wbg.__wbg_get_5419cf6b954aa11d = function(arg0, arg1) {
|
792
|
-
const ret = getObject(arg0)[arg1 >>> 0];
|
793
|
-
return addHeapObject(ret);
|
794
|
-
};
|
795
|
-
imports.wbg.__wbg_length_f217bbbf7e8e4df4 = function(arg0) {
|
796
|
-
const ret = getObject(arg0).length;
|
797
|
-
return ret;
|
798
|
-
};
|
799
|
-
imports.wbg.__wbg_create_70ef5302cb22a5c4 = function(arg0) {
|
800
|
-
const ret = Object.create(getObject(arg0));
|
801
|
-
return addHeapObject(ret);
|
802
|
-
};
|
803
|
-
imports.wbg.__wbg_ceil_f6b5b24722eb28de = typeof Math.ceil == 'function' ? Math.ceil : notDefined('Math.ceil');
|
804
|
-
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
805
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
806
|
-
};
|
1441
|
+
try { result = +getObject(arg0); } catch (e) { result = e; }
|
1442
|
+
const ret = result;
|
1443
|
+
return addHeapObject(ret);
|
1444
|
+
};
|
807
1445
|
|
808
|
-
return imports;
|
1446
|
+
return imports;
|
809
1447
|
}
|
810
1448
|
|
811
1449
|
function __wbg_finalize_init(instance, module) {
|
812
1450
|
wasm = instance.exports;
|
813
1451
|
cachedDataViewMemory0 = null;
|
1452
|
+
cachedUint16ArrayMemory0 = null;
|
814
1453
|
cachedUint32ArrayMemory0 = null;
|
815
1454
|
cachedUint8ArrayMemory0 = null;
|
816
1455
|
|
@@ -819,31 +1458,513 @@ function __wbg_finalize_init(instance, module) {
|
|
819
1458
|
return wasm;
|
820
1459
|
}
|
821
1460
|
|
822
|
-
function initSync(module) {
|
823
|
-
if (wasm !== undefined) return wasm;
|
824
|
-
|
1461
|
+
function initSync(module) {
|
1462
|
+
if (wasm !== undefined) return wasm;
|
1463
|
+
|
1464
|
+
|
1465
|
+
if (typeof module !== 'undefined') {
|
1466
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
1467
|
+
({module} = module);
|
1468
|
+
} else {
|
1469
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead');
|
1470
|
+
}
|
1471
|
+
}
|
1472
|
+
|
1473
|
+
const imports = __wbg_get_imports();
|
1474
|
+
|
1475
|
+
if (!(module instanceof WebAssembly.Module)) {
|
1476
|
+
module = new WebAssembly.Module(module);
|
1477
|
+
}
|
1478
|
+
|
1479
|
+
const instance = new WebAssembly.Instance(module, imports);
|
1480
|
+
|
1481
|
+
return __wbg_finalize_init(instance);
|
1482
|
+
}
|
1483
|
+
|
1484
|
+
const MAX_USIZE = 0xffffffff;
|
1485
|
+
|
1486
|
+
function fromPacked(packedPos) {
|
1487
|
+
const pos = Object.create(RoomPosition.prototype);
|
1488
|
+
pos.__packedPos = packedPos;
|
1489
|
+
return pos;
|
1490
|
+
}
|
1491
|
+
function fromPackedRoomName(packedRoomName) {
|
1492
|
+
// Handle sim room case
|
1493
|
+
if (packedRoomName === 0) {
|
1494
|
+
return 'sim';
|
1495
|
+
}
|
1496
|
+
const HALF_WORLD_SIZE = 128;
|
1497
|
+
const x_coord = ((packedRoomName >> 8) & 0xff) - HALF_WORLD_SIZE;
|
1498
|
+
const y_coord = (packedRoomName & 0xff) - HALF_WORLD_SIZE;
|
1499
|
+
const result = (x_coord >= 0 ? `E${x_coord}` : `W${~x_coord}`) + (y_coord >= 0 ? `S${y_coord}` : `N${~y_coord}`);
|
1500
|
+
return result;
|
1501
|
+
}
|
1502
|
+
function packRoomName(room) {
|
1503
|
+
// Handle sim room case
|
1504
|
+
if (room === 'sim') {
|
1505
|
+
return 0;
|
1506
|
+
}
|
1507
|
+
const HALF_WORLD_SIZE = 128;
|
1508
|
+
const [, h_dir, h_coord, v_dir, v_coord] = room.match(/^([WE])(\d+)([NS])(\d+)$/);
|
1509
|
+
let x = parseInt(h_coord);
|
1510
|
+
if (h_dir === 'W') {
|
1511
|
+
x = ~x;
|
1512
|
+
}
|
1513
|
+
let y = parseInt(v_coord);
|
1514
|
+
if (v_dir === 'N') {
|
1515
|
+
y = ~y;
|
1516
|
+
}
|
1517
|
+
x += HALF_WORLD_SIZE;
|
1518
|
+
y += HALF_WORLD_SIZE;
|
1519
|
+
return (x << 8) | y;
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
/**
|
1523
|
+
* A path from a start position to an end position. Typically returned by a
|
1524
|
+
* function like `pathToFlowFieldOrigin` rather than created directly.
|
1525
|
+
*/
|
1526
|
+
class Path {
|
1527
|
+
constructor(path) {
|
1528
|
+
this.path = path;
|
1529
|
+
}
|
1530
|
+
/**
|
1531
|
+
* Iterate over the path.
|
1532
|
+
*
|
1533
|
+
* @example
|
1534
|
+
* ```typescript
|
1535
|
+
* for (const pos of path) {
|
1536
|
+
* console.log(pos);
|
1537
|
+
* }
|
1538
|
+
* ```
|
1539
|
+
*/
|
1540
|
+
[Symbol.iterator]() {
|
1541
|
+
let index = 0;
|
1542
|
+
const length = this.length;
|
1543
|
+
return {
|
1544
|
+
next: () => {
|
1545
|
+
if (index < length - 1) {
|
1546
|
+
return { value: this.get(index++), done: false };
|
1547
|
+
}
|
1548
|
+
else {
|
1549
|
+
return { value: this.get(index++), done: true };
|
1550
|
+
}
|
1551
|
+
}
|
1552
|
+
};
|
1553
|
+
}
|
1554
|
+
/**
|
1555
|
+
* Iterate over the path in reverse order.
|
1556
|
+
*
|
1557
|
+
* @example
|
1558
|
+
* ```typescript
|
1559
|
+
* for (const pos of path.reversed()) {
|
1560
|
+
* console.log(pos);
|
1561
|
+
* }
|
1562
|
+
* ```
|
1563
|
+
*/
|
1564
|
+
*reversed() {
|
1565
|
+
let index = this.length - 1;
|
1566
|
+
return {
|
1567
|
+
next: () => {
|
1568
|
+
if (index > 0) {
|
1569
|
+
return { value: this.get(index--), done: false };
|
1570
|
+
}
|
1571
|
+
else {
|
1572
|
+
return { value: this.get(index--), done: true };
|
1573
|
+
}
|
1574
|
+
}
|
1575
|
+
};
|
1576
|
+
}
|
1577
|
+
/**
|
1578
|
+
* Get the position at a given index.
|
1579
|
+
*/
|
1580
|
+
get(index) {
|
1581
|
+
const packedPos = this.path.get(index);
|
1582
|
+
if (packedPos === undefined) {
|
1583
|
+
throw new Error('Index out of bounds');
|
1584
|
+
}
|
1585
|
+
return fromPacked(packedPos);
|
1586
|
+
}
|
1587
|
+
/**
|
1588
|
+
* Get the length of the path.
|
1589
|
+
*/
|
1590
|
+
get length() {
|
1591
|
+
return this.path.len();
|
1592
|
+
}
|
1593
|
+
/**
|
1594
|
+
* Given a current position, find the index of the next position in the path.
|
1595
|
+
*/
|
1596
|
+
findNextIndex(pos) {
|
1597
|
+
return this.path.find_next_index(pos.__packedPos);
|
1598
|
+
}
|
1599
|
+
/**
|
1600
|
+
* Convert the path to an array of positions.
|
1601
|
+
*/
|
1602
|
+
toArray() {
|
1603
|
+
const result = [];
|
1604
|
+
for (const packedPos of this.path.to_array()) {
|
1605
|
+
result.push(fromPacked(packedPos));
|
1606
|
+
}
|
1607
|
+
return result;
|
1608
|
+
}
|
1609
|
+
/**
|
1610
|
+
* Convert the path to an array of positions in reverse order.
|
1611
|
+
*/
|
1612
|
+
toArrayReversed() {
|
1613
|
+
const result = [];
|
1614
|
+
for (const packedPos of this.path.to_array_reversed()) {
|
1615
|
+
result.push(fromPacked(packedPos));
|
1616
|
+
}
|
1617
|
+
return result;
|
1618
|
+
}
|
1619
|
+
/**
|
1620
|
+
* Free the memory allocated for this path.
|
1621
|
+
*/
|
1622
|
+
free() {
|
1623
|
+
this.path.free();
|
1624
|
+
}
|
1625
|
+
}
|
1626
|
+
|
1627
|
+
/**
|
1628
|
+
* A distance map for a single room.
|
1629
|
+
*/
|
1630
|
+
class ClockworkDistanceMap {
|
1631
|
+
constructor(_map) {
|
1632
|
+
this._map = _map;
|
1633
|
+
}
|
1634
|
+
/**
|
1635
|
+
* Gets the distance value at a given position.
|
1636
|
+
*/
|
1637
|
+
get(x, y) {
|
1638
|
+
return this._map.get(x, y);
|
1639
|
+
}
|
1640
|
+
/**
|
1641
|
+
* Sets the distance value at a given position.
|
1642
|
+
*/
|
1643
|
+
set(x, y, value) {
|
1644
|
+
this._map.set(x, y, value);
|
1645
|
+
}
|
1646
|
+
/**
|
1647
|
+
* Converts the distance map into a flat array of distances.
|
1648
|
+
*/
|
1649
|
+
toArray() {
|
1650
|
+
return this._map.toArray();
|
1651
|
+
}
|
1652
|
+
/**
|
1653
|
+
* Frees the memory allocated for this distance map.
|
1654
|
+
*/
|
1655
|
+
free() {
|
1656
|
+
this._map.free();
|
1657
|
+
}
|
1658
|
+
/**
|
1659
|
+
* Path to the origin from a given position.
|
1660
|
+
*/
|
1661
|
+
pathToOrigin(start) {
|
1662
|
+
return new Path(js_path_to_distance_map_origin(start.__packedPos, this._map));
|
1663
|
+
}
|
1664
|
+
}
|
1665
|
+
|
1666
|
+
/**
|
1667
|
+
* A distance map that covers multiple rooms. Typically returned by a function
|
1668
|
+
* like `bfsMultiroomDistanceMap` rather than created directly.
|
1669
|
+
*/
|
1670
|
+
class ClockworkMultiroomDistanceMap {
|
1671
|
+
constructor(_map) {
|
1672
|
+
this._map = _map;
|
1673
|
+
}
|
1674
|
+
/**
|
1675
|
+
* Get the stored value for a given position.
|
1676
|
+
*/
|
1677
|
+
get(pos) {
|
1678
|
+
return this._map.get(pos.__packedPos);
|
1679
|
+
}
|
1680
|
+
/**
|
1681
|
+
* Set the stored value for a given position.
|
1682
|
+
*/
|
1683
|
+
set(pos, value) {
|
1684
|
+
this._map.set(pos.__packedPos, value);
|
1685
|
+
}
|
1686
|
+
/**
|
1687
|
+
* Get the DistanceMap for a given room.
|
1688
|
+
*/
|
1689
|
+
getRoom(room) {
|
1690
|
+
return this._map.get_room(packRoomName(room));
|
1691
|
+
}
|
1692
|
+
/**
|
1693
|
+
* List all the rooms covered by this distance map.
|
1694
|
+
*/
|
1695
|
+
getRooms() {
|
1696
|
+
return [...this._map.get_rooms()].map(room => fromPackedRoomName(room));
|
1697
|
+
}
|
1698
|
+
/**
|
1699
|
+
* Free the memory allocated for this distance map.
|
1700
|
+
*/
|
1701
|
+
free() {
|
1702
|
+
this._map.free();
|
1703
|
+
}
|
1704
|
+
/**
|
1705
|
+
* Path to the origin from a given position.
|
1706
|
+
*/
|
1707
|
+
pathToOrigin(start) {
|
1708
|
+
return new Path(js_path_to_multiroom_distance_map_origin(start.__packedPos, this._map));
|
1709
|
+
}
|
1710
|
+
}
|
1711
|
+
|
1712
|
+
/**
|
1713
|
+
* Generate a [distance map](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html) for a set of positions
|
1714
|
+
* using a breadth-first search algorithm.
|
1715
|
+
*
|
1716
|
+
* The BFS algorithm doesn't include variable costs, and only considers
|
1717
|
+
* values of 255 (impassible) in the provided cost matrix. Any other
|
1718
|
+
* values are ignored.
|
1719
|
+
*
|
1720
|
+
* This might be useful for creeps with only MOVE parts and/or empty
|
1721
|
+
* CARRY parts, which don't generate fatigue.
|
1722
|
+
*
|
1723
|
+
* Note that the `roomName` on start positions is ignored - all positions
|
1724
|
+
* are assumed to be in the same room as the cost matrix.
|
1725
|
+
*
|
1726
|
+
* @param start - The starting positions.
|
1727
|
+
* @param costMatrix - The cost matrix to use for the flow field.
|
1728
|
+
* @returns The flow field.
|
1729
|
+
*/
|
1730
|
+
function bfsDistanceMap(start, costMatrix) {
|
1731
|
+
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
1732
|
+
const result = js_bfs_distance_map(startPacked, costMatrix);
|
1733
|
+
return new ClockworkDistanceMap(result);
|
1734
|
+
}
|
1735
|
+
/**
|
1736
|
+
* Create a distance map for the given start positions, using a breadth-first search.
|
1737
|
+
* This does not factor in terrain costs (treating anything less than 255 in the cost
|
1738
|
+
* matrix as passable), so it's faster but less useful than Dijkstra's algorithm.
|
1739
|
+
*
|
1740
|
+
* This calculates a distance map across multiple rooms, with a few configurable limits:
|
1741
|
+
* - `maxTiles`: The maximum number of tiles to explore.
|
1742
|
+
* - `maxRooms`: The maximum number of rooms to explore.
|
1743
|
+
* - `maxRoomDistance`: Don't explore rooms further (in Manhattan distance) than this.
|
1744
|
+
* - `maxTileDistance`: Don't explore tiles further (in Chebyshev distance) than this.
|
1745
|
+
*
|
1746
|
+
* At least one of these limits must be set.
|
1747
|
+
*
|
1748
|
+
* @param start - The starting positions.
|
1749
|
+
* @param options - The options for the distance map.
|
1750
|
+
* @returns A multi-room distance map.
|
1751
|
+
*/
|
1752
|
+
function bfsMultiroomDistanceMap(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
|
1753
|
+
if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
|
1754
|
+
throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
|
1755
|
+
}
|
1756
|
+
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
1757
|
+
const result = js_bfs_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomName(room)), maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
|
1758
|
+
return new ClockworkMultiroomDistanceMap(result);
|
1759
|
+
}
|
1760
|
+
|
1761
|
+
/**
|
1762
|
+
* A flow field for a single room that stores multiple directions per tile.
|
1763
|
+
*/
|
1764
|
+
class ClockworkFlowField {
|
1765
|
+
constructor(_flowField) {
|
1766
|
+
this._flowField = _flowField;
|
1767
|
+
}
|
1768
|
+
/**
|
1769
|
+
* Get the internal value for a given coordinate.
|
1770
|
+
*/
|
1771
|
+
get(x, y) {
|
1772
|
+
return this._flowField.get(x, y);
|
1773
|
+
}
|
1774
|
+
/**
|
1775
|
+
* Set the internal value for a given coordinate.
|
1776
|
+
*/
|
1777
|
+
set(x, y, value) {
|
1778
|
+
this._flowField.set(x, y, value);
|
1779
|
+
}
|
1780
|
+
/**
|
1781
|
+
* Get the list of valid directions for a given coordinate.
|
1782
|
+
*/
|
1783
|
+
getDirections(x, y) {
|
1784
|
+
return this._flowField.getDirections(x, y);
|
1785
|
+
}
|
1786
|
+
/**
|
1787
|
+
* Set the list of valid directions for a given coordinate.
|
1788
|
+
*/
|
1789
|
+
setDirections(x, y, directions) {
|
1790
|
+
this._flowField.setDirections(x, y, directions);
|
1791
|
+
}
|
1792
|
+
/**
|
1793
|
+
* Add a direction to the list of valid directions for a given coordinate.
|
1794
|
+
*/
|
1795
|
+
addDirection(x, y, direction) {
|
1796
|
+
this._flowField.addDirection(x, y, direction);
|
1797
|
+
}
|
1798
|
+
/**
|
1799
|
+
* Free the memory allocated for this flow field.
|
1800
|
+
*/
|
1801
|
+
free() {
|
1802
|
+
this._flowField.free();
|
1803
|
+
}
|
1804
|
+
/**
|
1805
|
+
* Given a flow field (for a single room), find the path from a given position to
|
1806
|
+
* the origin. Never paths through other rooms.
|
1807
|
+
*/
|
1808
|
+
pathToOrigin(start) {
|
1809
|
+
return new Path(js_path_to_flow_field_origin(start.__packedPos, this._flowField));
|
1810
|
+
}
|
1811
|
+
}
|
1812
|
+
|
1813
|
+
/**
|
1814
|
+
* A flow field for a single room that stores one direction per tile.
|
1815
|
+
*/
|
1816
|
+
class ClockworkMonoFlowField {
|
1817
|
+
constructor(_flowField) {
|
1818
|
+
this._flowField = _flowField;
|
1819
|
+
}
|
1820
|
+
/**
|
1821
|
+
* Get the direction for a given coordinate.
|
1822
|
+
*/
|
1823
|
+
get(x, y) {
|
1824
|
+
return this._flowField.get(x, y);
|
1825
|
+
}
|
1826
|
+
/**
|
1827
|
+
* Set the direction for a given coordinate.
|
1828
|
+
*/
|
1829
|
+
set(x, y, value) {
|
1830
|
+
this._flowField.set(x, y, value);
|
1831
|
+
}
|
1832
|
+
/**
|
1833
|
+
* Free the memory allocated for this flow field.
|
1834
|
+
*/
|
1835
|
+
free() {
|
1836
|
+
this._flowField.free();
|
1837
|
+
}
|
1838
|
+
/**
|
1839
|
+
* Given a monodirectional flow field (for a single room), find the path from a given position to
|
1840
|
+
* the origin. Never paths through other rooms.
|
1841
|
+
*/
|
1842
|
+
pathToOrigin(start) {
|
1843
|
+
return new Path(js_path_to_mono_flow_field_origin(start.__packedPos, this._flowField));
|
1844
|
+
}
|
1845
|
+
}
|
825
1846
|
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
1847
|
+
/**
|
1848
|
+
* A flow field that spans multiple rooms, storing multiple directions per tile.
|
1849
|
+
*/
|
1850
|
+
class ClockworkMultiroomFlowField {
|
1851
|
+
constructor(_flowField) {
|
1852
|
+
this._flowField = _flowField;
|
1853
|
+
}
|
1854
|
+
/**
|
1855
|
+
* Get the flow field value at a given position.
|
1856
|
+
*/
|
1857
|
+
get(pos) {
|
1858
|
+
return this._flowField.get(pos.__packedPos);
|
1859
|
+
}
|
1860
|
+
/**
|
1861
|
+
* Set the flow field value at a given position.
|
1862
|
+
*/
|
1863
|
+
set(pos, value) {
|
1864
|
+
this._flowField.set(pos.__packedPos, value);
|
1865
|
+
}
|
1866
|
+
/**
|
1867
|
+
* Get the list of valid directions at a given position.
|
1868
|
+
*/
|
1869
|
+
getDirections(pos) {
|
1870
|
+
return this._flowField.getDirections(pos.__packedPos);
|
1871
|
+
}
|
1872
|
+
/**
|
1873
|
+
* Set the list of valid directions at a given position.
|
1874
|
+
*/
|
1875
|
+
setDirections(pos, directions) {
|
1876
|
+
this._flowField.setDirections(pos.__packedPos, directions);
|
1877
|
+
}
|
1878
|
+
/**
|
1879
|
+
* Add a direction to the list of valid directions at a given position.
|
1880
|
+
*/
|
1881
|
+
addDirection(pos, direction) {
|
1882
|
+
this._flowField.addDirection(pos.__packedPos, direction);
|
1883
|
+
}
|
1884
|
+
/**
|
1885
|
+
* Get the list of rooms in the flow field.
|
1886
|
+
*/
|
1887
|
+
getRooms() {
|
1888
|
+
const rooms = [];
|
1889
|
+
for (const packedRoomName of this._flowField.getRooms()) {
|
1890
|
+
rooms.push(fromPackedRoomName(packedRoomName));
|
831
1891
|
}
|
1892
|
+
return rooms;
|
832
1893
|
}
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
1894
|
+
/**
|
1895
|
+
* Get the flow field for a given room.
|
1896
|
+
*/
|
1897
|
+
getRoom(roomName) {
|
1898
|
+
const flowField = this._flowField.getRoom(packRoomName(roomName));
|
1899
|
+
return flowField ? new ClockworkFlowField(flowField) : null;
|
838
1900
|
}
|
1901
|
+
/**
|
1902
|
+
* Find a path from a given position to the origin of the flow field.
|
1903
|
+
*/
|
1904
|
+
pathToOrigin(start) {
|
1905
|
+
return new Path(js_path_to_multiroom_flow_field_origin(start.__packedPos, this._flowField));
|
1906
|
+
}
|
1907
|
+
/**
|
1908
|
+
* Free the memory allocated for this flow field.
|
1909
|
+
*/
|
1910
|
+
free() {
|
1911
|
+
this._flowField.free();
|
1912
|
+
}
|
1913
|
+
}
|
839
1914
|
|
840
|
-
|
841
|
-
|
842
|
-
|
1915
|
+
/**
|
1916
|
+
* A flow field that spans multiple rooms, storing a single direction per tile.
|
1917
|
+
*/
|
1918
|
+
class ClockworkMultiroomMonoFlowField {
|
1919
|
+
constructor(_flowField) {
|
1920
|
+
this._flowField = _flowField;
|
1921
|
+
}
|
1922
|
+
/**
|
1923
|
+
* Get the direction at a given position.
|
1924
|
+
*/
|
1925
|
+
get(pos) {
|
1926
|
+
var _a;
|
1927
|
+
return (_a = this._flowField.get(pos.__packedPos)) !== null && _a !== void 0 ? _a : null;
|
1928
|
+
}
|
1929
|
+
/**
|
1930
|
+
* Set the direction at a given position.
|
1931
|
+
*/
|
1932
|
+
set(pos, direction) {
|
1933
|
+
this._flowField.set(pos.__packedPos, direction !== null && direction !== void 0 ? direction : undefined);
|
1934
|
+
}
|
1935
|
+
/**
|
1936
|
+
* Get the list of rooms in the flow field.
|
1937
|
+
*/
|
1938
|
+
getRooms() {
|
1939
|
+
const rooms = [];
|
1940
|
+
for (const packedRoomName of this._flowField.getRooms()) {
|
1941
|
+
rooms.push(fromPackedRoomName(packedRoomName));
|
1942
|
+
}
|
1943
|
+
return rooms;
|
1944
|
+
}
|
1945
|
+
/**
|
1946
|
+
* Get the flow field for a given room.
|
1947
|
+
*/
|
1948
|
+
getRoom(roomName) {
|
1949
|
+
const flowField = this._flowField.getRoom(packRoomName(roomName));
|
1950
|
+
return flowField ? new ClockworkMonoFlowField(flowField) : null;
|
1951
|
+
}
|
1952
|
+
/**
|
1953
|
+
* Find a path from a given position to the origin of the flow field.
|
1954
|
+
*/
|
1955
|
+
pathToOrigin(start) {
|
1956
|
+
return new Path(js_path_to_multiroom_mono_flow_field_origin(start.__packedPos, this._flowField));
|
1957
|
+
}
|
1958
|
+
/**
|
1959
|
+
* Free the memory allocated for this flow field.
|
1960
|
+
*/
|
1961
|
+
free() {
|
1962
|
+
this._flowField.free();
|
1963
|
+
}
|
843
1964
|
}
|
844
1965
|
|
845
1966
|
/**
|
846
|
-
* Generate a [
|
1967
|
+
* Generate a [flow field](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html) for a set of positions
|
847
1968
|
* using a breadth-first search algorithm.
|
848
1969
|
*
|
849
1970
|
* The BFS algorithm doesn't include variable costs, and only considers
|
@@ -853,6 +1974,26 @@ function initSync(module) {
|
|
853
1974
|
* This might be useful for creeps with only MOVE parts and/or empty
|
854
1975
|
* CARRY parts, which don't generate fatigue.
|
855
1976
|
*
|
1977
|
+
* @param start - The starting positions.
|
1978
|
+
* @param costMatrix - The cost matrix to use for the flow field.
|
1979
|
+
* @returns The flow field.
|
1980
|
+
*/
|
1981
|
+
function bfsFlowField(start, costMatrix) {
|
1982
|
+
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
1983
|
+
const result = js_bfs_flow_field(startPacked, costMatrix);
|
1984
|
+
return new ClockworkFlowField(result);
|
1985
|
+
}
|
1986
|
+
/**
|
1987
|
+
* Generate a [mono-directional flow field](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html)
|
1988
|
+
* for a set of positions using a breadth-first search algorithm.
|
1989
|
+
*
|
1990
|
+
* The BFS algorithm doesn't include variable costs, and only considers
|
1991
|
+
* values of 255 (impassible) in the provided cost matrix. Any other
|
1992
|
+
* values are ignored.
|
1993
|
+
*
|
1994
|
+
* This might be useful for creeps with only MOVE parts and/or empty
|
1995
|
+
* CARRY parts, which don't generate fatigue.
|
1996
|
+
*
|
856
1997
|
* Note that the `roomName` on start positions is ignored - all positions
|
857
1998
|
* are assumed to be in the same room as the cost matrix.
|
858
1999
|
*
|
@@ -860,15 +2001,13 @@ function initSync(module) {
|
|
860
2001
|
* @param costMatrix - The cost matrix to use for the flow field.
|
861
2002
|
* @returns The flow field.
|
862
2003
|
*/
|
863
|
-
function
|
2004
|
+
function bfsMonoFlowField(start, costMatrix) {
|
864
2005
|
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
865
|
-
const result =
|
866
|
-
return result;
|
2006
|
+
const result = js_bfs_mono_flow_field(startPacked, costMatrix);
|
2007
|
+
return new ClockworkMonoFlowField(result);
|
867
2008
|
}
|
868
|
-
|
869
2009
|
/**
|
870
|
-
* Generate a
|
871
|
-
* using a breadth-first search algorithm.
|
2010
|
+
* Generate a multiroom flow field for a set of positions using a breadth-first search algorithm.
|
872
2011
|
*
|
873
2012
|
* The BFS algorithm doesn't include variable costs, and only considers
|
874
2013
|
* values of 255 (impassible) in the provided cost matrix. Any other
|
@@ -878,17 +2017,23 @@ function bfsDistanceMap(start, costMatrix) {
|
|
878
2017
|
* CARRY parts, which don't generate fatigue.
|
879
2018
|
*
|
880
2019
|
* @param start - The starting positions.
|
881
|
-
* @param
|
2020
|
+
* @param costMatrixCallback - A function that returns a cost matrix for a given room name.
|
2021
|
+
* @param options - Options for the flow field generation.
|
882
2022
|
* @returns The flow field.
|
883
2023
|
*/
|
884
|
-
function
|
2024
|
+
function bfsMultiroomFlowField(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
|
2025
|
+
if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
|
2026
|
+
throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
|
2027
|
+
}
|
885
2028
|
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
886
|
-
const result =
|
887
|
-
|
2029
|
+
const result = js_bfs_multiroom_flow_field(startPacked, (packedRoomName) => {
|
2030
|
+
const roomName = fromPackedRoomName(packedRoomName);
|
2031
|
+
return costMatrixCallback(roomName);
|
2032
|
+
}, maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
|
2033
|
+
return new ClockworkMultiroomFlowField(result);
|
888
2034
|
}
|
889
2035
|
/**
|
890
|
-
* Generate a
|
891
|
-
* for a set of positions using a breadth-first search algorithm.
|
2036
|
+
* Generate a multiroom mono-directional flow field for a set of positions using a breadth-first search algorithm.
|
892
2037
|
*
|
893
2038
|
* The BFS algorithm doesn't include variable costs, and only considers
|
894
2039
|
* values of 255 (impassible) in the provided cost matrix. Any other
|
@@ -897,17 +2042,21 @@ function bfsFlowField(start, costMatrix) {
|
|
897
2042
|
* This might be useful for creeps with only MOVE parts and/or empty
|
898
2043
|
* CARRY parts, which don't generate fatigue.
|
899
2044
|
*
|
900
|
-
* Note that the `roomName` on start positions is ignored - all positions
|
901
|
-
* are assumed to be in the same room as the cost matrix.
|
902
|
-
*
|
903
2045
|
* @param start - The starting positions.
|
904
|
-
* @param
|
2046
|
+
* @param getCostMatrix - A function that returns a cost matrix for a given room name.
|
2047
|
+
* @param options - Options for the flow field generation.
|
905
2048
|
* @returns The flow field.
|
906
2049
|
*/
|
907
|
-
function
|
2050
|
+
function bfsMultiroomMonoFlowField(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
|
2051
|
+
if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
|
2052
|
+
throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
|
2053
|
+
}
|
908
2054
|
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
909
|
-
const result =
|
910
|
-
|
2055
|
+
const result = js_bfs_multiroom_mono_flow_field(startPacked, (packedRoomName) => {
|
2056
|
+
const roomName = fromPackedRoomName(packedRoomName);
|
2057
|
+
return costMatrixCallback(roomName);
|
2058
|
+
}, maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
|
2059
|
+
return new ClockworkMultiroomMonoFlowField(result);
|
911
2060
|
}
|
912
2061
|
|
913
2062
|
/**
|
@@ -929,7 +2078,31 @@ function bfsMonoFlowField(start, costMatrix) {
|
|
929
2078
|
function dijkstraDistanceMap(start, costMatrix) {
|
930
2079
|
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
931
2080
|
const result = js_dijkstra_distance_map(startPacked, costMatrix);
|
932
|
-
return result;
|
2081
|
+
return new ClockworkDistanceMap(result);
|
2082
|
+
}
|
2083
|
+
/**
|
2084
|
+
* Create a distance map for the given start positions, using Dijkstra's algorithm to
|
2085
|
+
* factor in terrain costs (0-255, where 255 is impassable).
|
2086
|
+
*
|
2087
|
+
* This calculates a distance map across multiple rooms, with a few configurable limits:
|
2088
|
+
* - `maxTiles`: The maximum number of tiles to explore.
|
2089
|
+
* - `maxRooms`: The maximum number of rooms to explore.
|
2090
|
+
* - `maxRoomDistance`: Don't explore rooms further (in Manhattan distance) than this.
|
2091
|
+
* - `maxTileDistance`: Don't explore tiles further (in accumulated cost) than this.
|
2092
|
+
*
|
2093
|
+
* At least one of these limits must be set.
|
2094
|
+
*
|
2095
|
+
* @param start - The starting positions.
|
2096
|
+
* @param options - The options for the distance map.
|
2097
|
+
* @returns A multi-room distance map.
|
2098
|
+
*/
|
2099
|
+
function dijkstraMultiroomDistanceMap(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
|
2100
|
+
if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
|
2101
|
+
throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
|
2102
|
+
}
|
2103
|
+
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
2104
|
+
const result = js_dijkstra_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomName(room)), maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
|
2105
|
+
return new ClockworkMultiroomDistanceMap(result);
|
933
2106
|
}
|
934
2107
|
|
935
2108
|
/**
|
@@ -948,7 +2121,7 @@ function dijkstraDistanceMap(start, costMatrix) {
|
|
948
2121
|
function dijkstraFlowField(start, costMatrix) {
|
949
2122
|
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
950
2123
|
const result = js_dijkstra_flow_field(startPacked, costMatrix);
|
951
|
-
return result;
|
2124
|
+
return new ClockworkFlowField(result);
|
952
2125
|
}
|
953
2126
|
/**
|
954
2127
|
* Generate a [mono-directional flow field](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html)
|
@@ -969,7 +2142,55 @@ function dijkstraFlowField(start, costMatrix) {
|
|
969
2142
|
function dijkstraMonoFlowField(start, costMatrix) {
|
970
2143
|
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
971
2144
|
const result = js_dijkstra_mono_flow_field(startPacked, costMatrix);
|
972
|
-
return result;
|
2145
|
+
return new ClockworkMonoFlowField(result);
|
2146
|
+
}
|
2147
|
+
/**
|
2148
|
+
* Generate a multiroom flow field for a set of positions using Dijkstra's algorithm.
|
2149
|
+
*
|
2150
|
+
* Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
|
2151
|
+
*
|
2152
|
+
* Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
|
2153
|
+
* a cost matrix with a default value of at least 1.
|
2154
|
+
*
|
2155
|
+
* @param start - The starting positions.
|
2156
|
+
* @param costMatrixCallback - A function that returns a cost matrix for a given room name.
|
2157
|
+
* @param options - Options for the flow field generation.
|
2158
|
+
* @returns The flow field.
|
2159
|
+
*/
|
2160
|
+
function dijkstraMultiroomFlowField(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
|
2161
|
+
if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
|
2162
|
+
throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
|
2163
|
+
}
|
2164
|
+
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
2165
|
+
const result = js_dijkstra_multiroom_flow_field(startPacked, (packedRoomName) => {
|
2166
|
+
const roomName = fromPackedRoomName(packedRoomName);
|
2167
|
+
return costMatrixCallback(roomName);
|
2168
|
+
}, maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
|
2169
|
+
return new ClockworkMultiroomFlowField(result);
|
2170
|
+
}
|
2171
|
+
/**
|
2172
|
+
* Generate a multiroom mono-directional flow field for a set of positions using Dijkstra's algorithm.
|
2173
|
+
*
|
2174
|
+
* Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
|
2175
|
+
*
|
2176
|
+
* Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
|
2177
|
+
* a cost matrix with a default value of at least 1.
|
2178
|
+
*
|
2179
|
+
* @param start - The starting positions.
|
2180
|
+
* @param costMatrixCallback - A function that returns a cost matrix for a given room name.
|
2181
|
+
* @param options - Options for the flow field generation.
|
2182
|
+
* @returns The flow field.
|
2183
|
+
*/
|
2184
|
+
function dijkstraMultiroomMonoFlowField(start, { costMatrixCallback, maxTiles = MAX_USIZE, maxRooms = MAX_USIZE, maxRoomDistance = MAX_USIZE, maxTileDistance = MAX_USIZE }) {
|
2185
|
+
if ([maxTiles, maxRooms, maxRoomDistance, maxTileDistance].every(n => n === MAX_USIZE)) {
|
2186
|
+
throw new Error('At least one of maxTiles, maxRooms, maxRoomDistance, or maxTileDistance must be set');
|
2187
|
+
}
|
2188
|
+
const startPacked = new Uint32Array(start.map(pos => pos.__packedPos));
|
2189
|
+
const result = js_dijkstra_multiroom_mono_flow_field(startPacked, (packedRoomName) => {
|
2190
|
+
const roomName = fromPackedRoomName(packedRoomName);
|
2191
|
+
return costMatrixCallback(roomName);
|
2192
|
+
}, maxTiles, maxRooms, maxRoomDistance, maxTileDistance);
|
2193
|
+
return new ClockworkMultiroomMonoFlowField(result);
|
973
2194
|
}
|
974
2195
|
|
975
2196
|
/**
|
@@ -985,90 +2206,6 @@ function getRange(pos1, pos2) {
|
|
985
2206
|
return get_range(pos1.__packedPos, pos2.__packedPos);
|
986
2207
|
}
|
987
2208
|
|
988
|
-
function fromPacked(packedPos) {
|
989
|
-
const pos = Object.create(RoomPosition.prototype);
|
990
|
-
pos.__packedPos = packedPos;
|
991
|
-
return pos;
|
992
|
-
}
|
993
|
-
|
994
|
-
class Path {
|
995
|
-
constructor(path) {
|
996
|
-
this.path = path;
|
997
|
-
}
|
998
|
-
[Symbol.iterator]() {
|
999
|
-
let index = 0;
|
1000
|
-
const length = this.length;
|
1001
|
-
return {
|
1002
|
-
next: () => {
|
1003
|
-
if (index < length - 1) {
|
1004
|
-
return { value: this.get(index++), done: false };
|
1005
|
-
}
|
1006
|
-
else {
|
1007
|
-
return { value: this.get(index++), done: true };
|
1008
|
-
}
|
1009
|
-
}
|
1010
|
-
};
|
1011
|
-
}
|
1012
|
-
/**
|
1013
|
-
* Iterate over the path in reverse order
|
1014
|
-
*/
|
1015
|
-
*reversed() {
|
1016
|
-
let index = this.length - 1;
|
1017
|
-
return {
|
1018
|
-
next: () => {
|
1019
|
-
if (index > 0) {
|
1020
|
-
return { value: this.get(index--), done: false };
|
1021
|
-
}
|
1022
|
-
else {
|
1023
|
-
return { value: this.get(index--), done: true };
|
1024
|
-
}
|
1025
|
-
}
|
1026
|
-
};
|
1027
|
-
}
|
1028
|
-
get(index) {
|
1029
|
-
const packedPos = this.path.get(index);
|
1030
|
-
if (packedPos === undefined) {
|
1031
|
-
throw new Error('Index out of bounds');
|
1032
|
-
}
|
1033
|
-
return fromPacked(packedPos);
|
1034
|
-
}
|
1035
|
-
get length() {
|
1036
|
-
return this.path.len();
|
1037
|
-
}
|
1038
|
-
findNextIndex(index) {
|
1039
|
-
return this.path.find_next_index(index);
|
1040
|
-
}
|
1041
|
-
toArray() {
|
1042
|
-
const result = [];
|
1043
|
-
for (const packedPos of this.path.to_array()) {
|
1044
|
-
result.push(fromPacked(packedPos));
|
1045
|
-
}
|
1046
|
-
return result;
|
1047
|
-
}
|
1048
|
-
toArrayReversed() {
|
1049
|
-
const result = [];
|
1050
|
-
for (const packedPos of this.path.to_array_reversed()) {
|
1051
|
-
result.push(fromPacked(packedPos));
|
1052
|
-
}
|
1053
|
-
return result;
|
1054
|
-
}
|
1055
|
-
free() {
|
1056
|
-
this.path.free();
|
1057
|
-
}
|
1058
|
-
}
|
1059
|
-
|
1060
|
-
function pathToDistanceMapOrigin(start, distanceMap) {
|
1061
|
-
return new Path(js_path_to_distance_map_origin(start.__packedPos, distanceMap));
|
1062
|
-
}
|
1063
|
-
|
1064
|
-
function pathToFlowFieldOrigin(start, flowField) {
|
1065
|
-
return new Path(js_path_to_flow_field_origin(start.__packedPos, flowField));
|
1066
|
-
}
|
1067
|
-
|
1068
|
-
function pathToMonoFlowFieldOrigin(start, flowField) {
|
1069
|
-
return new Path(js_path_to_mono_flow_field_origin(start.__packedPos, flowField));
|
1070
|
-
}
|
1071
|
-
|
1072
2209
|
let wasm_bytes;
|
1073
2210
|
let wasm_module;
|
1074
2211
|
let wasm_instance;
|
@@ -1082,6 +2219,8 @@ let initialized = false;
|
|
1082
2219
|
* @param verbose - If true, will log the state of the WASM module as it loads.
|
1083
2220
|
*/
|
1084
2221
|
function initialize(verbose = false) {
|
2222
|
+
// need to freshly override the fake console object each tick
|
2223
|
+
console.error = console_error;
|
1085
2224
|
if (!wasm_bytes)
|
1086
2225
|
wasm_bytes = require('screeps_clockwork.wasm');
|
1087
2226
|
if (verbose && !initialized)
|
@@ -1098,8 +2237,33 @@ function initialize(verbose = false) {
|
|
1098
2237
|
}
|
1099
2238
|
initialized = true;
|
1100
2239
|
}
|
2240
|
+
// This provides the function `console.error` that wasm_bindgen sometimes expects to exist,
|
2241
|
+
// especially with type checks in debug mode. An alternative is to have this be `function () {}`
|
2242
|
+
// and let the exception handler log the thrown JS exceptions, but there is some additional
|
2243
|
+
// information that wasm_bindgen only passes here.
|
2244
|
+
//
|
2245
|
+
// There is nothing special about this function and it may also be used by any JS/Rust code as a convenience.
|
2246
|
+
function console_error() {
|
2247
|
+
const processedArgs = Array.from(arguments)
|
2248
|
+
.map(arg => {
|
2249
|
+
if (arg instanceof Error) {
|
2250
|
+
// On this version of Node, the `stack` property of errors contains
|
2251
|
+
// the message as well.
|
2252
|
+
return arg.stack;
|
2253
|
+
}
|
2254
|
+
else {
|
2255
|
+
return arg;
|
2256
|
+
}
|
2257
|
+
})
|
2258
|
+
.join(' ');
|
2259
|
+
console.log('ERROR:', processedArgs);
|
2260
|
+
}
|
1101
2261
|
|
1102
2262
|
exports.ClockworkCostMatrix = ClockworkCostMatrix;
|
2263
|
+
exports.ClockworkFlowField = ClockworkFlowField;
|
2264
|
+
exports.ClockworkMonoFlowField = ClockworkMonoFlowField;
|
2265
|
+
exports.ClockworkMultiroomFlowField = ClockworkMultiroomFlowField;
|
2266
|
+
exports.ClockworkMultiroomMonoFlowField = ClockworkMultiroomMonoFlowField;
|
1103
2267
|
exports.DistanceMap = DistanceMap;
|
1104
2268
|
exports.FlowField = FlowField;
|
1105
2269
|
exports.MonoFlowField = MonoFlowField;
|
@@ -1107,12 +2271,15 @@ exports.Path = Path;
|
|
1107
2271
|
exports.bfsDistanceMap = bfsDistanceMap;
|
1108
2272
|
exports.bfsFlowField = bfsFlowField;
|
1109
2273
|
exports.bfsMonoFlowField = bfsMonoFlowField;
|
2274
|
+
exports.bfsMultiroomDistanceMap = bfsMultiroomDistanceMap;
|
2275
|
+
exports.bfsMultiroomFlowField = bfsMultiroomFlowField;
|
2276
|
+
exports.bfsMultiroomMonoFlowField = bfsMultiroomMonoFlowField;
|
1110
2277
|
exports.dijkstraDistanceMap = dijkstraDistanceMap;
|
1111
2278
|
exports.dijkstraFlowField = dijkstraFlowField;
|
1112
2279
|
exports.dijkstraMonoFlowField = dijkstraMonoFlowField;
|
2280
|
+
exports.dijkstraMultiroomDistanceMap = dijkstraMultiroomDistanceMap;
|
2281
|
+
exports.dijkstraMultiroomFlowField = dijkstraMultiroomFlowField;
|
2282
|
+
exports.dijkstraMultiroomMonoFlowField = dijkstraMultiroomMonoFlowField;
|
1113
2283
|
exports.getRange = getRange;
|
1114
2284
|
exports.initialize = initialize;
|
1115
|
-
exports.pathToDistanceMapOrigin = pathToDistanceMapOrigin;
|
1116
|
-
exports.pathToFlowFieldOrigin = pathToFlowFieldOrigin;
|
1117
|
-
exports.pathToMonoFlowFieldOrigin = pathToMonoFlowFieldOrigin;
|
1118
2285
|
//# sourceMappingURL=index.js.map
|