@woosh/meep-engine 2.94.0 → 2.94.1
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/build/meep.cjs +41 -37
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +41 -37
- package/package.json +1 -1
- package/src/core/collection/heap/Uint32Heap.d.ts.map +1 -1
- package/src/core/collection/heap/Uint32Heap.js +22 -17
- package/src/engine/navigation/grid/find_path_on_grid_astar.d.ts.map +1 -1
- package/src/engine/navigation/grid/find_path_on_grid_astar.js +18 -19
- package/src/engine/navigation/grid/find_path_on_grid_astar.spec.js +2 -2
- package/src/engine/ui/GUIEngine.js +1 -1
package/build/meep.module.js
CHANGED
|
@@ -102842,7 +102842,7 @@ class GUIEngine {
|
|
|
102842
102842
|
|
|
102843
102843
|
constructor() {
|
|
102844
102844
|
|
|
102845
|
-
this.ticker.
|
|
102845
|
+
this.ticker.onTick.add(d => {
|
|
102846
102846
|
|
|
102847
102847
|
|
|
102848
102848
|
let ctx = null;
|
|
@@ -116251,17 +116251,17 @@ class Uint32Heap {
|
|
|
116251
116251
|
const size = this.__size;
|
|
116252
116252
|
|
|
116253
116253
|
while (true) {
|
|
116254
|
-
const
|
|
116255
|
-
const
|
|
116254
|
+
const left = (i << 1) + 1;
|
|
116255
|
+
const right = left + 1;
|
|
116256
116256
|
|
|
116257
116257
|
let smallest = i;
|
|
116258
116258
|
|
|
116259
|
-
if (
|
|
116260
|
-
smallest =
|
|
116259
|
+
if (left < size && this.compare(left, smallest)) {
|
|
116260
|
+
smallest = left;
|
|
116261
116261
|
}
|
|
116262
116262
|
|
|
116263
|
-
if (
|
|
116264
|
-
smallest =
|
|
116263
|
+
if (right < size && this.compare(right, smallest)) {
|
|
116264
|
+
smallest = right;
|
|
116265
116265
|
}
|
|
116266
116266
|
|
|
116267
116267
|
if (smallest === i) {
|
|
@@ -116335,19 +116335,23 @@ class Uint32Heap {
|
|
|
116335
116335
|
|
|
116336
116336
|
pop_min() {
|
|
116337
116337
|
|
|
116338
|
-
const
|
|
116338
|
+
const new_size = this.__size - 1;
|
|
116339
|
+
this.__size = new_size;
|
|
116339
116340
|
|
|
116340
|
-
this.
|
|
116341
|
+
const uint32 = this.__data_uint32;
|
|
116342
|
+
const top_id = uint32[1];
|
|
116341
116343
|
|
|
116342
|
-
|
|
116343
|
-
|
|
116344
|
-
|
|
116344
|
+
// move bottom element to the top.
|
|
116345
|
+
// the top doesn't need to be moved down as we have discarded it already
|
|
116346
|
+
const i2 = new_size << 1; // same as *2
|
|
116345
116347
|
|
|
116346
|
-
|
|
116347
|
-
|
|
116348
|
-
}
|
|
116348
|
+
uint32[0] = uint32[i2];
|
|
116349
|
+
uint32[1] = uint32[i2 + 1];
|
|
116349
116350
|
|
|
116350
|
-
|
|
116351
|
+
// re-balance
|
|
116352
|
+
this.heap_down(0);
|
|
116353
|
+
|
|
116354
|
+
return top_id;
|
|
116351
116355
|
}
|
|
116352
116356
|
|
|
116353
116357
|
/**
|
|
@@ -116365,6 +116369,7 @@ class Uint32Heap {
|
|
|
116365
116369
|
const _id = uint32[address];
|
|
116366
116370
|
|
|
116367
116371
|
if (_id === id) {
|
|
116372
|
+
// reverse address to index
|
|
116368
116373
|
return (address >>> 1);
|
|
116369
116374
|
}
|
|
116370
116375
|
}
|
|
@@ -116378,7 +116383,7 @@ class Uint32Heap {
|
|
|
116378
116383
|
* @param {number} id
|
|
116379
116384
|
* @returns {boolean}
|
|
116380
116385
|
*/
|
|
116381
|
-
contains(id){
|
|
116386
|
+
contains(id) {
|
|
116382
116387
|
return this.find_index_by_id(id) !== -1;
|
|
116383
116388
|
}
|
|
116384
116389
|
|
|
@@ -116509,7 +116514,7 @@ class Uint32Heap {
|
|
|
116509
116514
|
|
|
116510
116515
|
// insert at the end
|
|
116511
116516
|
const index = current_size;
|
|
116512
|
-
const address = index << 1;
|
|
116517
|
+
const address = index << 1; // same as *2
|
|
116513
116518
|
|
|
116514
116519
|
// write data
|
|
116515
116520
|
this.__data_float32[address] = score;
|
|
@@ -116707,6 +116712,12 @@ const open = new Uint32Heap();
|
|
|
116707
116712
|
const closed = new BitSet();
|
|
116708
116713
|
closed.preventShrink();
|
|
116709
116714
|
|
|
116715
|
+
/**
|
|
116716
|
+
* Contains refined heuristic value
|
|
116717
|
+
* @type {Float32Array}
|
|
116718
|
+
*/
|
|
116719
|
+
let g_score = new Float32Array(1024);
|
|
116720
|
+
|
|
116710
116721
|
/**
|
|
116711
116722
|
*
|
|
116712
116723
|
* @param {number[]|Uint8Array|Uint16Array|Float32Array} field
|
|
@@ -116730,14 +116741,15 @@ function find_path_on_grid_astar(
|
|
|
116730
116741
|
open.clear();
|
|
116731
116742
|
closed.reset();
|
|
116732
116743
|
|
|
116733
|
-
|
|
116734
|
-
* Contains refined heuristic value
|
|
116735
|
-
* @type {number[]}
|
|
116736
|
-
*/
|
|
116737
|
-
const g_score = [];
|
|
116744
|
+
const cell_count = width * height;
|
|
116738
116745
|
|
|
116739
|
-
g_score
|
|
116746
|
+
if (g_score.length < cell_count) {
|
|
116747
|
+
g_score = new Float32Array(cell_count);
|
|
116748
|
+
}
|
|
116740
116749
|
|
|
116750
|
+
g_score.fill(Infinity, 0, cell_count);
|
|
116751
|
+
|
|
116752
|
+
g_score[start] = 0;
|
|
116741
116753
|
|
|
116742
116754
|
open.insert(start, heuristic(start, goal, width));
|
|
116743
116755
|
|
|
@@ -116781,27 +116793,19 @@ function find_path_on_grid_astar(
|
|
|
116781
116793
|
// updated path cost
|
|
116782
116794
|
const cost_so_far = g_score[currentNode] + transition_cost;
|
|
116783
116795
|
|
|
116784
|
-
|
|
116796
|
+
if (cost_so_far < g_score[neighbor]) {
|
|
116785
116797
|
|
|
116786
|
-
|
|
116787
|
-
|
|
116788
|
-
if (not_in_open_set || cost_so_far < g_score[neighbor]) {
|
|
116789
|
-
|
|
116790
|
-
// update refined score
|
|
116798
|
+
// update actual cost
|
|
116791
116799
|
g_score[neighbor] = cost_so_far;
|
|
116792
116800
|
|
|
116793
116801
|
const remaining_heuristic = heuristic(neighbor, goal, width);
|
|
116794
116802
|
|
|
116795
116803
|
const refined_heuristic = cost_so_far + remaining_heuristic;
|
|
116796
116804
|
|
|
116797
|
-
|
|
116798
|
-
|
|
116799
|
-
open.insert(neighbor, refined_heuristic);
|
|
116800
|
-
} else {
|
|
116801
|
-
// Already seen the node, but since it has been re-scored we need to reorder it in the heap
|
|
116802
|
-
open.__update_score_by_index(index_in_open_set, refined_heuristic);
|
|
116803
|
-
}
|
|
116805
|
+
// Pushing to heap will put it in proper place based on the 'f' value.
|
|
116806
|
+
open.insert_or_update(neighbor, refined_heuristic);
|
|
116804
116807
|
}
|
|
116808
|
+
|
|
116805
116809
|
}
|
|
116806
116810
|
}
|
|
116807
116811
|
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Uint32Heap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/heap/Uint32Heap.js"],"names":[],"mappings":"AAiDA;;;;GAIG;AACH;IACI;;;OAGG;IACH,+BAFW,MAAM,EAuBhB;IAlBG,2BAA0E;IAE1E;;;;OAIG;IACH,sBAAwD;IAExD;;;;OAIG;IACH,uBAA0D;IAE1D,mBAAkC;IAClC,eAAe;IAGnB;;;OAGG;IACH,wBAsBC;IAED;;;;;OAKG;IACH,gBAOC;IAED;;;;;OAKG;IACH,aAiBC;IAED;;;OAGG;IACH,kBA6BC;IAED;;;;OAIG;IACH,gBAeC;IAED;;;OAGG;IACH,mBAEC;IAED;;;OAGG;IACH,uBAEC;IAED;;;OAGG;IACH,qBAEC;IAED;;;OAGG;IACH,YAFa,OAAO,CAInB;IAED,mBAEC;IAED,
|
|
1
|
+
{"version":3,"file":"Uint32Heap.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/heap/Uint32Heap.js"],"names":[],"mappings":"AAiDA;;;;GAIG;AACH;IACI;;;OAGG;IACH,+BAFW,MAAM,EAuBhB;IAlBG,2BAA0E;IAE1E;;;;OAIG;IACH,sBAAwD;IAExD;;;;OAIG;IACH,uBAA0D;IAE1D,mBAAkC;IAClC,eAAe;IAGnB;;;OAGG;IACH,wBAsBC;IAED;;;;;OAKG;IACH,gBAOC;IAED;;;;;OAKG;IACH,aAiBC;IAED;;;OAGG;IACH,kBA6BC;IAED;;;;OAIG;IACH,gBAeC;IAED;;;OAGG;IACH,mBAEC;IAED;;;OAGG;IACH,uBAEC;IAED;;;OAGG;IACH,qBAEC;IAED;;;OAGG;IACH,YAFa,OAAO,CAInB;IAED,mBAEC;IAED,kBAoBC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACJ,MAAM,CAmBlB;IAED;;;;OAIG;IACH,aAHW,MAAM,GACJ,OAAO,CAInB;IAED;;OAEG;IACH,cAEC;IAED;;;;OAIG;IACH,WAHW,MAAM,GACJ,OAAO,CAWnB;IAED;;;OAGG;IACH,yBAFW,MAAM,QAehB;IAED;;;;OAIG;IACH,iBAHW,MAAM,SACN,MAAM,QAUhB;IAED;;;;OAIG;IACH,+BAHW,MAAM,SACN,MAAM,QAiBhB;IAED;;;;OAIG;IACH,cAHW,MAAM,GACJ,MAAM,CAYlB;IAGD;;;;OAIG;IACH,qBAHW,MAAM,SACN,MAAM,QAUhB;IAED;;;;OAIG;IACH,WAHW,MAAM,SACN,MAAM,QA0BhB;CAGJ"}
|
|
@@ -159,17 +159,17 @@ export class Uint32Heap {
|
|
|
159
159
|
const size = this.__size;
|
|
160
160
|
|
|
161
161
|
while (true) {
|
|
162
|
-
const
|
|
163
|
-
const
|
|
162
|
+
const left = (i << 1) + 1;
|
|
163
|
+
const right = left + 1;
|
|
164
164
|
|
|
165
165
|
let smallest = i;
|
|
166
166
|
|
|
167
|
-
if (
|
|
168
|
-
smallest =
|
|
167
|
+
if (left < size && this.compare(left, smallest)) {
|
|
168
|
+
smallest = left;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
if (
|
|
172
|
-
smallest =
|
|
171
|
+
if (right < size && this.compare(right, smallest)) {
|
|
172
|
+
smallest = right;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
if (smallest === i) {
|
|
@@ -244,19 +244,23 @@ export class Uint32Heap {
|
|
|
244
244
|
pop_min() {
|
|
245
245
|
assert.greaterThan(this.__size, 0, 'heap is empty');
|
|
246
246
|
|
|
247
|
-
const
|
|
247
|
+
const new_size = this.__size - 1;
|
|
248
|
+
this.__size = new_size;
|
|
248
249
|
|
|
249
|
-
this.
|
|
250
|
+
const uint32 = this.__data_uint32;
|
|
251
|
+
const top_id = uint32[1];
|
|
250
252
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
253
|
+
// move bottom element to the top.
|
|
254
|
+
// the top doesn't need to be moved down as we have discarded it already
|
|
255
|
+
const i2 = new_size << 1; // same as *2
|
|
254
256
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
257
|
+
uint32[0] = uint32[i2];
|
|
258
|
+
uint32[1] = uint32[i2 + 1];
|
|
259
|
+
|
|
260
|
+
// re-balance
|
|
261
|
+
this.heap_down(0);
|
|
258
262
|
|
|
259
|
-
return
|
|
263
|
+
return top_id;
|
|
260
264
|
}
|
|
261
265
|
|
|
262
266
|
/**
|
|
@@ -274,6 +278,7 @@ export class Uint32Heap {
|
|
|
274
278
|
const _id = uint32[address];
|
|
275
279
|
|
|
276
280
|
if (_id === id) {
|
|
281
|
+
// reverse address to index
|
|
277
282
|
return (address >>> 1);
|
|
278
283
|
}
|
|
279
284
|
}
|
|
@@ -287,7 +292,7 @@ export class Uint32Heap {
|
|
|
287
292
|
* @param {number} id
|
|
288
293
|
* @returns {boolean}
|
|
289
294
|
*/
|
|
290
|
-
contains(id){
|
|
295
|
+
contains(id) {
|
|
291
296
|
return this.find_index_by_id(id) !== -1;
|
|
292
297
|
}
|
|
293
298
|
|
|
@@ -422,7 +427,7 @@ export class Uint32Heap {
|
|
|
422
427
|
|
|
423
428
|
// insert at the end
|
|
424
429
|
const index = current_size;
|
|
425
|
-
const address = index << 1;
|
|
430
|
+
const address = index << 1; // same as *2
|
|
426
431
|
|
|
427
432
|
// write data
|
|
428
433
|
this.__data_float32[address] = score;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find_path_on_grid_astar.d.ts","sourceRoot":"","sources":["../../../../../src/engine/navigation/grid/find_path_on_grid_astar.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"find_path_on_grid_astar.d.ts","sourceRoot":"","sources":["../../../../../src/engine/navigation/grid/find_path_on_grid_astar.js"],"names":[],"mappings":"AAkMA;;;;;;;;;;GAUG;AACH,+CATW,MAAM,EAAE,GAAC,UAAU,GAAC,WAAW,GAAC,YAAY,SAC5C,MAAM,UACN,MAAM,SACN,MAAM,QACN,MAAM,oBACN,MAAM,eACN,MAAM,GACJ,MAAO,MAAM,CAAC,CA6F1B"}
|
|
@@ -186,6 +186,12 @@ const open = new Uint32Heap();
|
|
|
186
186
|
const closed = new BitSet();
|
|
187
187
|
closed.preventShrink();
|
|
188
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Contains refined heuristic value
|
|
191
|
+
* @type {Float32Array}
|
|
192
|
+
*/
|
|
193
|
+
let g_score = new Float32Array(1024);
|
|
194
|
+
|
|
189
195
|
/**
|
|
190
196
|
*
|
|
191
197
|
* @param {number[]|Uint8Array|Uint16Array|Float32Array} field
|
|
@@ -218,14 +224,15 @@ export function find_path_on_grid_astar(
|
|
|
218
224
|
open.clear();
|
|
219
225
|
closed.reset();
|
|
220
226
|
|
|
221
|
-
|
|
222
|
-
* Contains refined heuristic value
|
|
223
|
-
* @type {number[]}
|
|
224
|
-
*/
|
|
225
|
-
const g_score = [];
|
|
227
|
+
const cell_count = width * height;
|
|
226
228
|
|
|
227
|
-
g_score
|
|
229
|
+
if (g_score.length < cell_count) {
|
|
230
|
+
g_score = new Float32Array(cell_count);
|
|
231
|
+
}
|
|
228
232
|
|
|
233
|
+
g_score.fill(Infinity, 0, cell_count);
|
|
234
|
+
|
|
235
|
+
g_score[start] = 0;
|
|
229
236
|
|
|
230
237
|
open.insert(start, heuristic(start, goal, width));
|
|
231
238
|
|
|
@@ -269,27 +276,19 @@ export function find_path_on_grid_astar(
|
|
|
269
276
|
// updated path cost
|
|
270
277
|
const cost_so_far = g_score[currentNode] + transition_cost;
|
|
271
278
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const not_in_open_set = index_in_open_set === -1;
|
|
275
|
-
|
|
276
|
-
if (not_in_open_set || cost_so_far < g_score[neighbor]) {
|
|
279
|
+
if (cost_so_far < g_score[neighbor]) {
|
|
277
280
|
|
|
278
|
-
// update
|
|
281
|
+
// update actual cost
|
|
279
282
|
g_score[neighbor] = cost_so_far;
|
|
280
283
|
|
|
281
284
|
const remaining_heuristic = heuristic(neighbor, goal, width);
|
|
282
285
|
|
|
283
286
|
const refined_heuristic = cost_so_far + remaining_heuristic;
|
|
284
287
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
open.insert(neighbor, refined_heuristic);
|
|
288
|
-
} else {
|
|
289
|
-
// Already seen the node, but since it has been re-scored we need to reorder it in the heap
|
|
290
|
-
open.__update_score_by_index(index_in_open_set, refined_heuristic);
|
|
291
|
-
}
|
|
288
|
+
// Pushing to heap will put it in proper place based on the 'f' value.
|
|
289
|
+
open.insert_or_update(neighbor, refined_heuristic)
|
|
292
290
|
}
|
|
291
|
+
|
|
293
292
|
}
|
|
294
293
|
}
|
|
295
294
|
|
|
@@ -36,7 +36,7 @@ test("path on open 3x3 grid", () => {
|
|
|
36
36
|
expect(path).toEqual([0, 3, 5, 8]);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
test("performance, 256x256 random", () => {
|
|
39
|
+
test.skip("performance, 256x256 random", () => {
|
|
40
40
|
const FIELD_SIZE = 256;
|
|
41
41
|
|
|
42
42
|
const field = new Uint8Array(FIELD_SIZE * FIELD_SIZE);
|
|
@@ -52,7 +52,7 @@ test("performance, 256x256 random", () => {
|
|
|
52
52
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const SAMPLE_COUNT =
|
|
55
|
+
const SAMPLE_COUNT = 100000;
|
|
56
56
|
|
|
57
57
|
const coordinates = new Uint32Array(SAMPLE_COUNT * 2);
|
|
58
58
|
|