screeps-clockwork 0.10.0 → 0.12.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 +154 -149
- package/dist/index.js.map +1 -1
- package/dist/screeps_clockwork.wasm +0 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/utils/fromPacked.d.ts +1 -0
- package/dist/src/utils/packedArrays.d.ts +6 -0
- package/dist/src/wasm/screeps_clockwork.d.ts +0 -36
- package/dist/src/wrappers/distanceMap.d.ts +5 -1
- package/dist/src/wrappers/flowField.d.ts +5 -1
- package/dist/src/wrappers/freeable.d.ts +5 -0
- package/dist/src/wrappers/monoFlowField.d.ts +5 -1
- package/dist/src/wrappers/multiroomDistanceMap.d.ts +5 -1
- package/dist/src/wrappers/multiroomFlowField.d.ts +5 -1
- package/dist/src/wrappers/multiroomMonoFlowField.d.ts +5 -1
- package/dist/src/wrappers/path.d.ts +5 -1
- package/package.json +31 -3
- /package/dist/src/wasm/snippets/{screeps-clockwork-06a106842c1b3122 → screeps-clockwork-977757b5f554a65d}/inline0.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1074,10 +1074,6 @@ function version() {
|
|
|
1074
1074
|
function __wbg_get_imports() {
|
|
1075
1075
|
const import0 = {
|
|
1076
1076
|
__proto__: null,
|
|
1077
|
-
__wbg___wbindgen_is_null_2042690d351e14f0: function (arg0) {
|
|
1078
|
-
const ret = getObject(arg0) === null;
|
|
1079
|
-
return ret;
|
|
1080
|
-
},
|
|
1081
1077
|
__wbg___wbindgen_is_undefined_35bb9f4c7fd651d5: function (arg0) {
|
|
1082
1078
|
const ret = getObject(arg0) === undefined;
|
|
1083
1079
|
return ret;
|
|
@@ -1100,11 +1096,7 @@ function __wbg_get_imports() {
|
|
|
1100
1096
|
return addHeapObject(ret);
|
|
1101
1097
|
}, arguments);
|
|
1102
1098
|
},
|
|
1103
|
-
|
|
1104
|
-
const ret = Math.ceil(arg0);
|
|
1105
|
-
return ret;
|
|
1106
|
-
},
|
|
1107
|
-
__wbg_clockworkcostmatrix_get_pointer_0e40dd616e7e32da: function (arg0) {
|
|
1099
|
+
__wbg_clockworkcostmatrix_get_pointer_bb635b319c5f0508: function (arg0) {
|
|
1108
1100
|
const ret = clockworkcostmatrix_get_pointer(takeObject(arg0));
|
|
1109
1101
|
return ret;
|
|
1110
1102
|
},
|
|
@@ -1128,37 +1120,6 @@ function __wbg_get_imports() {
|
|
|
1128
1120
|
const ret = getObject(arg0).getRawBuffer(getObject(arg1));
|
|
1129
1121
|
return addHeapObject(ret);
|
|
1130
1122
|
},
|
|
1131
|
-
__wbg_getRoomTerrain_ff542df2ea2015b1: function () {
|
|
1132
|
-
return handleError(function (arg0) {
|
|
1133
|
-
const ret = Game.map.getRoomTerrain(getObject(arg0));
|
|
1134
|
-
return addHeapObject(ret);
|
|
1135
|
-
}, arguments);
|
|
1136
|
-
},
|
|
1137
|
-
__wbg_get_8f8e5734959cd5fc: function (arg0, arg1, arg2) {
|
|
1138
|
-
const ret = getObject(arg0).get(arg1, arg2);
|
|
1139
|
-
return ret;
|
|
1140
|
-
},
|
|
1141
|
-
__wbg_get_unchecked_1dfe6d05ad91d9b7: function (arg0, arg1) {
|
|
1142
|
-
const ret = getObject(arg0)[arg1 >>> 0];
|
|
1143
|
-
return addHeapObject(ret);
|
|
1144
|
-
},
|
|
1145
|
-
__wbg_get_value_3083233b2ad9f36e: function (arg0, arg1) {
|
|
1146
|
-
const ret = getObject(arg0)[getObject(arg1)];
|
|
1147
|
-
return addHeapObject(ret);
|
|
1148
|
-
},
|
|
1149
|
-
__wbg_length_2591a0f4f659a55c: function (arg0) {
|
|
1150
|
-
const ret = getObject(arg0).length;
|
|
1151
|
-
return ret;
|
|
1152
|
-
},
|
|
1153
|
-
__wbg_log_c012383707c9fbe6: function (arg0, arg1) {
|
|
1154
|
-
console.log(getStringFromWasm0(arg0, arg1));
|
|
1155
|
-
},
|
|
1156
|
-
__wbg_lookFor_0ddc4d9f22e9bfe5: function () {
|
|
1157
|
-
return handleError(function (arg0, arg1) {
|
|
1158
|
-
const ret = getObject(arg0).lookFor(__wbindgen_enum_Look[arg1]);
|
|
1159
|
-
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
1160
|
-
}, arguments);
|
|
1161
|
-
},
|
|
1162
1123
|
__wbg_new_1f236d63ba0c4784: function (arg0, arg1) {
|
|
1163
1124
|
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
1164
1125
|
return addHeapObject(ret);
|
|
@@ -1173,10 +1134,6 @@ function __wbg_get_imports() {
|
|
|
1173
1134
|
return addHeapObject(ret);
|
|
1174
1135
|
}, arguments);
|
|
1175
1136
|
},
|
|
1176
|
-
__wbg_rooms_c5dbffde521939da: function () {
|
|
1177
|
-
const ret = Game.rooms;
|
|
1178
|
-
return addHeapObject(ret);
|
|
1179
|
-
},
|
|
1180
1137
|
__wbg_set_packed_cc769b1ab2aa7e8e: function (arg0, arg1) {
|
|
1181
1138
|
getObject(arg0).__packedPos = arg1 >>> 0;
|
|
1182
1139
|
},
|
|
@@ -1191,10 +1148,6 @@ function __wbg_get_imports() {
|
|
|
1191
1148
|
const ret = RoomPosition.prototype;
|
|
1192
1149
|
return addHeapObject(ret);
|
|
1193
1150
|
},
|
|
1194
|
-
__wbg_structure_type_dbc211ed19dd8423: function (arg0) {
|
|
1195
|
-
const ret = getObject(arg0).structureType;
|
|
1196
|
-
return (__wbindgen_enum_StructureType.indexOf(ret) + 1 || 22) - 1;
|
|
1197
|
-
},
|
|
1198
1151
|
__wbindgen_cast_0000000000000001: function (arg0) {
|
|
1199
1152
|
// Cast intrinsic for `F64 -> Externref`.
|
|
1200
1153
|
const ret = arg0;
|
|
@@ -1219,8 +1172,6 @@ function __wbg_get_imports() {
|
|
|
1219
1172
|
"./screeps_clockwork_bg.js": import0,
|
|
1220
1173
|
};
|
|
1221
1174
|
}
|
|
1222
|
-
const __wbindgen_enum_Look = ["creep", "energy", "resource", "source", "mineral", "structure", "flag", "constructionSite", "nuke", "terrain", "tombstone", "powerCreep", "deposit", "ruin", "scoreContainer", "scoreCollector", "symbolContainer", "symbolDecoder", "reactor"];
|
|
1223
|
-
const __wbindgen_enum_StructureType = ["spawn", "extension", "road", "constructedWall", "rampart", "keeperLair", "portal", "controller", "link", "storage", "tower", "observer", "powerBank", "powerSpawn", "extractor", "lab", "terminal", "container", "nuker", "factory", "invaderCore"];
|
|
1224
1175
|
const ClockworkCostMatrixFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1225
1176
|
? { register: () => { }, unregister: () => { } }
|
|
1226
1177
|
: new FinalizationRegistry(ptr => wasm.__wbg_clockworkcostmatrix_free(ptr, 1));
|
|
@@ -1245,9 +1196,6 @@ const MultiroomMonoFlowFieldFinalization = (typeof FinalizationRegistry === 'und
|
|
|
1245
1196
|
const PathFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1246
1197
|
? { register: () => { }, unregister: () => { } }
|
|
1247
1198
|
: new FinalizationRegistry(ptr => wasm.__wbg_path_free(ptr, 1));
|
|
1248
|
-
(typeof FinalizationRegistry === 'undefined')
|
|
1249
|
-
? { register: () => { }, unregister: () => { } }
|
|
1250
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_pathfatigue_free(ptr, 1));
|
|
1251
1199
|
(typeof FinalizationRegistry === 'undefined')
|
|
1252
1200
|
? { register: () => { }, unregister: () => { } }
|
|
1253
1201
|
: new FinalizationRegistry(ptr => wasm.__wbg_searchgoal_free(ptr, 1));
|
|
@@ -1472,6 +1420,15 @@ function fromPackedRoomName(packedRoomName) {
|
|
|
1472
1420
|
const result = (x_coord >= 0 ? `E${x_coord}` : `W${~x_coord}`) + (y_coord >= 0 ? `S${y_coord}` : `N${~y_coord}`);
|
|
1473
1421
|
return result;
|
|
1474
1422
|
}
|
|
1423
|
+
const roomNameCache = new Map();
|
|
1424
|
+
function fromPackedRoomNameCached(packedRoomName) {
|
|
1425
|
+
let roomName = roomNameCache.get(packedRoomName);
|
|
1426
|
+
if (roomName === undefined) {
|
|
1427
|
+
roomName = fromPackedRoomName(packedRoomName);
|
|
1428
|
+
roomNameCache.set(packedRoomName, roomName);
|
|
1429
|
+
}
|
|
1430
|
+
return roomName;
|
|
1431
|
+
}
|
|
1475
1432
|
function packRoomName(room) {
|
|
1476
1433
|
// Handle sim room case
|
|
1477
1434
|
if (room === 'sim') {
|
|
@@ -1492,30 +1449,67 @@ function packRoomName(room) {
|
|
|
1492
1449
|
return (x << 8) | y;
|
|
1493
1450
|
}
|
|
1494
1451
|
|
|
1452
|
+
function packPositions(positions) {
|
|
1453
|
+
const packed = new Uint32Array(positions.length);
|
|
1454
|
+
for (let i = 0; i < positions.length; i++) {
|
|
1455
|
+
packed[i] = positions[i].__packedPos;
|
|
1456
|
+
}
|
|
1457
|
+
return packed;
|
|
1458
|
+
}
|
|
1459
|
+
function packDestinations(destinations) {
|
|
1460
|
+
if (!destinations) {
|
|
1461
|
+
return undefined;
|
|
1462
|
+
}
|
|
1463
|
+
const packed = new Uint32Array(destinations.length * 2);
|
|
1464
|
+
for (let i = 0; i < destinations.length; i++) {
|
|
1465
|
+
const offset = i * 2;
|
|
1466
|
+
packed[offset] = destinations[i].pos.__packedPos;
|
|
1467
|
+
packed[offset + 1] = destinations[i].range;
|
|
1468
|
+
}
|
|
1469
|
+
return packed;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
function assertNotFreed(handle, label) {
|
|
1473
|
+
if (!handle) {
|
|
1474
|
+
throw new Error(`${label} has been freed`);
|
|
1475
|
+
}
|
|
1476
|
+
return handle;
|
|
1477
|
+
}
|
|
1478
|
+
function freeHandle(handle) {
|
|
1479
|
+
handle === null || handle === void 0 ? void 0 : handle.free();
|
|
1480
|
+
return undefined;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1495
1483
|
/**
|
|
1496
1484
|
* A distance map for a single room.
|
|
1497
1485
|
*/
|
|
1498
1486
|
class ClockworkDistanceMap {
|
|
1499
|
-
constructor(
|
|
1500
|
-
this._map =
|
|
1487
|
+
constructor(map) {
|
|
1488
|
+
this._map = map;
|
|
1489
|
+
}
|
|
1490
|
+
/**
|
|
1491
|
+
* Frees the underlying WASM distance map allocation.
|
|
1492
|
+
*/
|
|
1493
|
+
free() {
|
|
1494
|
+
this._map = freeHandle(this._map);
|
|
1501
1495
|
}
|
|
1502
1496
|
/**
|
|
1503
1497
|
* Gets the distance value at a given position.
|
|
1504
1498
|
*/
|
|
1505
1499
|
get(x, y) {
|
|
1506
|
-
return this._map.get(x, y);
|
|
1500
|
+
return assertNotFreed(this._map, 'ClockworkDistanceMap').get(x, y);
|
|
1507
1501
|
}
|
|
1508
1502
|
/**
|
|
1509
1503
|
* Sets the distance value at a given position.
|
|
1510
1504
|
*/
|
|
1511
1505
|
set(x, y, value) {
|
|
1512
|
-
this._map.set(x, y, value);
|
|
1506
|
+
assertNotFreed(this._map, 'ClockworkDistanceMap').set(x, y, value);
|
|
1513
1507
|
}
|
|
1514
1508
|
/**
|
|
1515
1509
|
* Converts the distance map into a flat array of distances.
|
|
1516
1510
|
*/
|
|
1517
1511
|
toArray() {
|
|
1518
|
-
return this._map.toArray();
|
|
1512
|
+
return assertNotFreed(this._map, 'ClockworkDistanceMap').toArray();
|
|
1519
1513
|
}
|
|
1520
1514
|
}
|
|
1521
1515
|
|
|
@@ -1523,38 +1517,44 @@ class ClockworkDistanceMap {
|
|
|
1523
1517
|
* A flow field for a single room that stores multiple directions per tile.
|
|
1524
1518
|
*/
|
|
1525
1519
|
class ClockworkFlowField {
|
|
1526
|
-
constructor(
|
|
1527
|
-
this._flowField =
|
|
1520
|
+
constructor(flowField) {
|
|
1521
|
+
this._flowField = flowField;
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Frees the underlying WASM flow field allocation.
|
|
1525
|
+
*/
|
|
1526
|
+
free() {
|
|
1527
|
+
this._flowField = freeHandle(this._flowField);
|
|
1528
1528
|
}
|
|
1529
1529
|
/**
|
|
1530
1530
|
* Get the internal value for a given coordinate.
|
|
1531
1531
|
*/
|
|
1532
1532
|
get(x, y) {
|
|
1533
|
-
return this._flowField.get(x, y);
|
|
1533
|
+
return assertNotFreed(this._flowField, 'ClockworkFlowField').get(x, y);
|
|
1534
1534
|
}
|
|
1535
1535
|
/**
|
|
1536
1536
|
* Set the internal value for a given coordinate.
|
|
1537
1537
|
*/
|
|
1538
1538
|
set(x, y, value) {
|
|
1539
|
-
this._flowField.set(x, y, value);
|
|
1539
|
+
assertNotFreed(this._flowField, 'ClockworkFlowField').set(x, y, value);
|
|
1540
1540
|
}
|
|
1541
1541
|
/**
|
|
1542
1542
|
* Get the list of valid directions for a given coordinate.
|
|
1543
1543
|
*/
|
|
1544
1544
|
getDirections(x, y) {
|
|
1545
|
-
return this._flowField.getDirections(x, y);
|
|
1545
|
+
return assertNotFreed(this._flowField, 'ClockworkFlowField').getDirections(x, y);
|
|
1546
1546
|
}
|
|
1547
1547
|
/**
|
|
1548
1548
|
* Set the list of valid directions for a given coordinate.
|
|
1549
1549
|
*/
|
|
1550
1550
|
setDirections(x, y, directions) {
|
|
1551
|
-
this._flowField.setDirections(x, y, directions);
|
|
1551
|
+
assertNotFreed(this._flowField, 'ClockworkFlowField').setDirections(x, y, directions);
|
|
1552
1552
|
}
|
|
1553
1553
|
/**
|
|
1554
1554
|
* Add a direction to the list of valid directions for a given coordinate.
|
|
1555
1555
|
*/
|
|
1556
1556
|
addDirection(x, y, direction) {
|
|
1557
|
-
this._flowField.addDirection(x, y, direction);
|
|
1557
|
+
assertNotFreed(this._flowField, 'ClockworkFlowField').addDirection(x, y, direction);
|
|
1558
1558
|
}
|
|
1559
1559
|
}
|
|
1560
1560
|
|
|
@@ -1566,6 +1566,12 @@ class ClockworkPath {
|
|
|
1566
1566
|
constructor(path) {
|
|
1567
1567
|
this.path = path;
|
|
1568
1568
|
}
|
|
1569
|
+
/**
|
|
1570
|
+
* Frees the underlying WASM path allocation.
|
|
1571
|
+
*/
|
|
1572
|
+
free() {
|
|
1573
|
+
this.path = freeHandle(this.path);
|
|
1574
|
+
}
|
|
1569
1575
|
/**
|
|
1570
1576
|
* Iterate over the path.
|
|
1571
1577
|
*
|
|
@@ -1617,7 +1623,7 @@ class ClockworkPath {
|
|
|
1617
1623
|
* Get the position at a given index.
|
|
1618
1624
|
*/
|
|
1619
1625
|
get(index) {
|
|
1620
|
-
const packedPos = this.path.get(index);
|
|
1626
|
+
const packedPos = assertNotFreed(this.path, 'ClockworkPath').get(index);
|
|
1621
1627
|
if (packedPos === undefined) {
|
|
1622
1628
|
throw new Error('Index out of bounds');
|
|
1623
1629
|
}
|
|
@@ -1627,20 +1633,20 @@ class ClockworkPath {
|
|
|
1627
1633
|
* Get the length of the path.
|
|
1628
1634
|
*/
|
|
1629
1635
|
get length() {
|
|
1630
|
-
return this.path.len();
|
|
1636
|
+
return assertNotFreed(this.path, 'ClockworkPath').len();
|
|
1631
1637
|
}
|
|
1632
1638
|
/**
|
|
1633
1639
|
* Given a current position, find the index of the next position in the path.
|
|
1634
1640
|
*/
|
|
1635
1641
|
findNextIndex(pos) {
|
|
1636
|
-
return this.path.find_next_index(pos.__packedPos);
|
|
1642
|
+
return assertNotFreed(this.path, 'ClockworkPath').find_next_index(pos.__packedPos);
|
|
1637
1643
|
}
|
|
1638
1644
|
/**
|
|
1639
1645
|
* Convert the path to an array of positions.
|
|
1640
1646
|
*/
|
|
1641
1647
|
toArray() {
|
|
1642
1648
|
const result = [];
|
|
1643
|
-
for (const packedPos of this.path.to_array()) {
|
|
1649
|
+
for (const packedPos of assertNotFreed(this.path, 'ClockworkPath').to_array()) {
|
|
1644
1650
|
result.push(fromPacked(packedPos));
|
|
1645
1651
|
}
|
|
1646
1652
|
return result;
|
|
@@ -1650,7 +1656,7 @@ class ClockworkPath {
|
|
|
1650
1656
|
*/
|
|
1651
1657
|
toArrayReversed() {
|
|
1652
1658
|
const result = [];
|
|
1653
|
-
for (const packedPos of this.path.to_array_reversed()) {
|
|
1659
|
+
for (const packedPos of assertNotFreed(this.path, 'ClockworkPath').to_array_reversed()) {
|
|
1654
1660
|
result.push(fromPacked(packedPos));
|
|
1655
1661
|
}
|
|
1656
1662
|
return result;
|
|
@@ -1661,45 +1667,51 @@ class ClockworkPath {
|
|
|
1661
1667
|
* A flow field that spans multiple rooms, storing multiple directions per tile.
|
|
1662
1668
|
*/
|
|
1663
1669
|
class ClockworkMultiroomFlowField {
|
|
1664
|
-
constructor(
|
|
1665
|
-
this._flowField =
|
|
1670
|
+
constructor(flowField) {
|
|
1671
|
+
this._flowField = flowField;
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Frees the underlying WASM multiroom flow field allocation.
|
|
1675
|
+
*/
|
|
1676
|
+
free() {
|
|
1677
|
+
this._flowField = freeHandle(this._flowField);
|
|
1666
1678
|
}
|
|
1667
1679
|
/**
|
|
1668
1680
|
* Get the flow field value at a given position.
|
|
1669
1681
|
*/
|
|
1670
1682
|
get(pos) {
|
|
1671
|
-
return this._flowField.get(pos.__packedPos);
|
|
1683
|
+
return assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField').get(pos.__packedPos);
|
|
1672
1684
|
}
|
|
1673
1685
|
/**
|
|
1674
1686
|
* Set the flow field value at a given position.
|
|
1675
1687
|
*/
|
|
1676
1688
|
set(pos, value) {
|
|
1677
|
-
this._flowField.set(pos.__packedPos, value);
|
|
1689
|
+
assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField').set(pos.__packedPos, value);
|
|
1678
1690
|
}
|
|
1679
1691
|
/**
|
|
1680
1692
|
* Get the list of valid directions at a given position.
|
|
1681
1693
|
*/
|
|
1682
1694
|
getDirections(pos) {
|
|
1683
|
-
return this._flowField.getDirections(pos.__packedPos);
|
|
1695
|
+
return assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField').getDirections(pos.__packedPos);
|
|
1684
1696
|
}
|
|
1685
1697
|
/**
|
|
1686
1698
|
* Set the list of valid directions at a given position.
|
|
1687
1699
|
*/
|
|
1688
1700
|
setDirections(pos, directions) {
|
|
1689
|
-
this._flowField.setDirections(pos.__packedPos, directions);
|
|
1701
|
+
assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField').setDirections(pos.__packedPos, directions);
|
|
1690
1702
|
}
|
|
1691
1703
|
/**
|
|
1692
1704
|
* Add a direction to the list of valid directions at a given position.
|
|
1693
1705
|
*/
|
|
1694
1706
|
addDirection(pos, direction) {
|
|
1695
|
-
this._flowField.addDirection(pos.__packedPos, direction);
|
|
1707
|
+
assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField').addDirection(pos.__packedPos, direction);
|
|
1696
1708
|
}
|
|
1697
1709
|
/**
|
|
1698
1710
|
* Get the list of rooms in the flow field.
|
|
1699
1711
|
*/
|
|
1700
1712
|
getRooms() {
|
|
1701
1713
|
const rooms = [];
|
|
1702
|
-
for (const packedRoomName of this._flowField.getRooms()) {
|
|
1714
|
+
for (const packedRoomName of assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField').getRooms()) {
|
|
1703
1715
|
rooms.push(fromPackedRoomName(packedRoomName));
|
|
1704
1716
|
}
|
|
1705
1717
|
return rooms;
|
|
@@ -1708,14 +1720,14 @@ class ClockworkMultiroomFlowField {
|
|
|
1708
1720
|
* Get the flow field for a given room.
|
|
1709
1721
|
*/
|
|
1710
1722
|
getRoom(roomName) {
|
|
1711
|
-
const flowField = this._flowField.getRoom(packRoomName(roomName));
|
|
1723
|
+
const flowField = assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField').getRoom(packRoomName(roomName));
|
|
1712
1724
|
return flowField ? new ClockworkFlowField(flowField) : null;
|
|
1713
1725
|
}
|
|
1714
1726
|
/**
|
|
1715
1727
|
* Find a path from a given position to the origin of the flow field.
|
|
1716
1728
|
*/
|
|
1717
1729
|
pathToOrigin(start) {
|
|
1718
|
-
return new ClockworkPath(js_path_to_multiroom_flow_field_origin(start.__packedPos, this._flowField));
|
|
1730
|
+
return new ClockworkPath(js_path_to_multiroom_flow_field_origin(start.__packedPos, assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField')));
|
|
1719
1731
|
}
|
|
1720
1732
|
}
|
|
1721
1733
|
|
|
@@ -1723,20 +1735,26 @@ class ClockworkMultiroomFlowField {
|
|
|
1723
1735
|
* A flow field for a single room that stores one direction per tile.
|
|
1724
1736
|
*/
|
|
1725
1737
|
class ClockworkMonoFlowField {
|
|
1726
|
-
constructor(
|
|
1727
|
-
this._flowField =
|
|
1738
|
+
constructor(flowField) {
|
|
1739
|
+
this._flowField = flowField;
|
|
1740
|
+
}
|
|
1741
|
+
/**
|
|
1742
|
+
* Frees the underlying WASM flow field allocation.
|
|
1743
|
+
*/
|
|
1744
|
+
free() {
|
|
1745
|
+
this._flowField = freeHandle(this._flowField);
|
|
1728
1746
|
}
|
|
1729
1747
|
/**
|
|
1730
1748
|
* Get the direction for a given coordinate.
|
|
1731
1749
|
*/
|
|
1732
1750
|
get(x, y) {
|
|
1733
|
-
return this._flowField.get(x, y);
|
|
1751
|
+
return assertNotFreed(this._flowField, 'ClockworkMonoFlowField').get(x, y);
|
|
1734
1752
|
}
|
|
1735
1753
|
/**
|
|
1736
1754
|
* Set the direction for a given coordinate.
|
|
1737
1755
|
*/
|
|
1738
1756
|
set(x, y, value) {
|
|
1739
|
-
this._flowField.set(x, y, value);
|
|
1757
|
+
assertNotFreed(this._flowField, 'ClockworkMonoFlowField').set(x, y, value);
|
|
1740
1758
|
}
|
|
1741
1759
|
}
|
|
1742
1760
|
|
|
@@ -1744,28 +1762,34 @@ class ClockworkMonoFlowField {
|
|
|
1744
1762
|
* A flow field that spans multiple rooms, storing a single direction per tile.
|
|
1745
1763
|
*/
|
|
1746
1764
|
class ClockworkMultiroomMonoFlowField {
|
|
1747
|
-
constructor(
|
|
1748
|
-
this._flowField =
|
|
1765
|
+
constructor(flowField) {
|
|
1766
|
+
this._flowField = flowField;
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Frees the underlying WASM multiroom flow field allocation.
|
|
1770
|
+
*/
|
|
1771
|
+
free() {
|
|
1772
|
+
this._flowField = freeHandle(this._flowField);
|
|
1749
1773
|
}
|
|
1750
1774
|
/**
|
|
1751
1775
|
* Get the direction at a given position.
|
|
1752
1776
|
*/
|
|
1753
1777
|
get(pos) {
|
|
1754
1778
|
var _a;
|
|
1755
|
-
return (_a = this._flowField.get(pos.__packedPos)) !== null && _a !== void 0 ? _a : null;
|
|
1779
|
+
return (_a = assertNotFreed(this._flowField, 'ClockworkMultiroomMonoFlowField').get(pos.__packedPos)) !== null && _a !== void 0 ? _a : null;
|
|
1756
1780
|
}
|
|
1757
1781
|
/**
|
|
1758
1782
|
* Set the direction at a given position.
|
|
1759
1783
|
*/
|
|
1760
1784
|
set(pos, direction) {
|
|
1761
|
-
this._flowField.set(pos.__packedPos, direction !== null && direction !== void 0 ? direction : undefined);
|
|
1785
|
+
assertNotFreed(this._flowField, 'ClockworkMultiroomMonoFlowField').set(pos.__packedPos, direction !== null && direction !== void 0 ? direction : undefined);
|
|
1762
1786
|
}
|
|
1763
1787
|
/**
|
|
1764
1788
|
* Get the list of rooms in the flow field.
|
|
1765
1789
|
*/
|
|
1766
1790
|
getRooms() {
|
|
1767
1791
|
const rooms = [];
|
|
1768
|
-
for (const packedRoomName of this._flowField.getRooms()) {
|
|
1792
|
+
for (const packedRoomName of assertNotFreed(this._flowField, 'ClockworkMultiroomMonoFlowField').getRooms()) {
|
|
1769
1793
|
rooms.push(fromPackedRoomName(packedRoomName));
|
|
1770
1794
|
}
|
|
1771
1795
|
return rooms;
|
|
@@ -1774,14 +1798,14 @@ class ClockworkMultiroomMonoFlowField {
|
|
|
1774
1798
|
* Get the flow field for a given room.
|
|
1775
1799
|
*/
|
|
1776
1800
|
getRoom(roomName) {
|
|
1777
|
-
const flowField = this._flowField.getRoom(packRoomName(roomName));
|
|
1801
|
+
const flowField = assertNotFreed(this._flowField, 'ClockworkMultiroomMonoFlowField').getRoom(packRoomName(roomName));
|
|
1778
1802
|
return flowField ? new ClockworkMonoFlowField(flowField) : null;
|
|
1779
1803
|
}
|
|
1780
1804
|
/**
|
|
1781
1805
|
* Find a path from a given position to the origin of the flow field.
|
|
1782
1806
|
*/
|
|
1783
1807
|
pathToOrigin(start) {
|
|
1784
|
-
return new ClockworkPath(js_path_to_multiroom_mono_flow_field_origin(start.__packedPos, this._flowField));
|
|
1808
|
+
return new ClockworkPath(js_path_to_multiroom_mono_flow_field_origin(start.__packedPos, assertNotFreed(this._flowField, 'ClockworkMultiroomMonoFlowField')));
|
|
1785
1809
|
}
|
|
1786
1810
|
}
|
|
1787
1811
|
|
|
@@ -1791,33 +1815,39 @@ const DEFAULT_DIRECTION_ORDER = DirectionOrder.CardinalFirst;
|
|
|
1791
1815
|
* like `bfsMultiroomDistanceMap` rather than created directly.
|
|
1792
1816
|
*/
|
|
1793
1817
|
class ClockworkMultiroomDistanceMap {
|
|
1794
|
-
constructor(
|
|
1795
|
-
this._map =
|
|
1818
|
+
constructor(map) {
|
|
1819
|
+
this._map = map;
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Frees the underlying WASM multiroom distance map allocation.
|
|
1823
|
+
*/
|
|
1824
|
+
free() {
|
|
1825
|
+
this._map = freeHandle(this._map);
|
|
1796
1826
|
}
|
|
1797
1827
|
/**
|
|
1798
1828
|
* Get the stored value for a given position.
|
|
1799
1829
|
*/
|
|
1800
1830
|
get(pos) {
|
|
1801
|
-
return this._map.get(pos.__packedPos);
|
|
1831
|
+
return assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap').get(pos.__packedPos);
|
|
1802
1832
|
}
|
|
1803
1833
|
/**
|
|
1804
1834
|
* Set the stored value for a given position.
|
|
1805
1835
|
*/
|
|
1806
1836
|
set(pos, value) {
|
|
1807
|
-
this._map.set(pos.__packedPos, value);
|
|
1837
|
+
assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap').set(pos.__packedPos, value);
|
|
1808
1838
|
}
|
|
1809
1839
|
/**
|
|
1810
1840
|
* Get the DistanceMap for a given room.
|
|
1811
1841
|
*/
|
|
1812
1842
|
getRoom(room) {
|
|
1813
|
-
const map = this._map.get_room(packRoomName(room));
|
|
1843
|
+
const map = assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap').get_room(packRoomName(room));
|
|
1814
1844
|
return map ? new ClockworkDistanceMap(map) : undefined;
|
|
1815
1845
|
}
|
|
1816
1846
|
/**
|
|
1817
1847
|
* List all the rooms covered by this distance map.
|
|
1818
1848
|
*/
|
|
1819
1849
|
getRooms() {
|
|
1820
|
-
return [...this._map.get_rooms()].map(room => fromPackedRoomName(room));
|
|
1850
|
+
return [...assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap').get_rooms()].map(room => fromPackedRoomName(room));
|
|
1821
1851
|
}
|
|
1822
1852
|
/**
|
|
1823
1853
|
* Path to the origin from a given position.
|
|
@@ -1825,7 +1855,7 @@ class ClockworkMultiroomDistanceMap {
|
|
|
1825
1855
|
*/
|
|
1826
1856
|
pathToOrigin(start, options = {}) {
|
|
1827
1857
|
var _a;
|
|
1828
|
-
return new ClockworkPath(js_path_to_multiroom_distance_map_origin(start.__packedPos, this._map, (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
|
|
1858
|
+
return new ClockworkPath(js_path_to_multiroom_distance_map_origin(start.__packedPos, assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap'), (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
|
|
1829
1859
|
}
|
|
1830
1860
|
/**
|
|
1831
1861
|
* Flow field for this distance map.
|
|
@@ -1833,7 +1863,7 @@ class ClockworkMultiroomDistanceMap {
|
|
|
1833
1863
|
*/
|
|
1834
1864
|
toFlowField(options = {}) {
|
|
1835
1865
|
var _a;
|
|
1836
|
-
return new ClockworkMultiroomFlowField(multiroomFlowField(this._map, (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
|
|
1866
|
+
return new ClockworkMultiroomFlowField(multiroomFlowField(assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap'), (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
|
|
1837
1867
|
}
|
|
1838
1868
|
/**
|
|
1839
1869
|
* Mono-directional flow field for this distance map.
|
|
@@ -1841,22 +1871,27 @@ class ClockworkMultiroomDistanceMap {
|
|
|
1841
1871
|
*/
|
|
1842
1872
|
toMonoFlowField(options = {}) {
|
|
1843
1873
|
var _a;
|
|
1844
|
-
return new ClockworkMultiroomMonoFlowField(multiroomMonoFlowField(this._map, (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
|
|
1874
|
+
return new ClockworkMultiroomMonoFlowField(multiroomMonoFlowField(assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap'), (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
|
|
1845
1875
|
}
|
|
1846
1876
|
}
|
|
1847
1877
|
|
|
1848
1878
|
function fromPackedSearchResult(result) {
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1879
|
+
try {
|
|
1880
|
+
const foundTargets = result.found_targets.reduce((acc, pos) => {
|
|
1881
|
+
acc.push(fromPacked(pos));
|
|
1882
|
+
return acc;
|
|
1883
|
+
}, []);
|
|
1884
|
+
const distanceMap = new ClockworkMultiroomDistanceMap(result.distance_map);
|
|
1885
|
+
const ops = result.ops;
|
|
1886
|
+
return {
|
|
1887
|
+
distanceMap,
|
|
1888
|
+
foundTargets,
|
|
1889
|
+
ops
|
|
1890
|
+
};
|
|
1891
|
+
}
|
|
1892
|
+
finally {
|
|
1893
|
+
result.free();
|
|
1894
|
+
}
|
|
1860
1895
|
}
|
|
1861
1896
|
|
|
1862
1897
|
/**
|
|
@@ -1879,18 +1914,8 @@ function astarMultiroomDistanceMap(start, { costMatrixCallback, maxRooms = MAX_U
|
|
|
1879
1914
|
if ([maxRooms, maxOps, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
|
|
1880
1915
|
throw new Error('At least one of maxRooms, maxOps, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
|
|
1881
1916
|
}
|
|
1882
|
-
const startPacked =
|
|
1883
|
-
const result = js_astar_multiroom_distance_map(startPacked, (room) => costMatrixCallback(
|
|
1884
|
-
? new Uint32Array(anyOfDestinations.reduce((acc, { pos, range }) => {
|
|
1885
|
-
acc.push(pos.__packedPos, range);
|
|
1886
|
-
return acc;
|
|
1887
|
-
}, []))
|
|
1888
|
-
: undefined, allOfDestinations
|
|
1889
|
-
? new Uint32Array(allOfDestinations.reduce((acc, { pos, range }) => {
|
|
1890
|
-
acc.push(pos.__packedPos, range);
|
|
1891
|
-
return acc;
|
|
1892
|
-
}, []))
|
|
1893
|
-
: undefined);
|
|
1917
|
+
const startPacked = packPositions(start);
|
|
1918
|
+
const result = js_astar_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomNameCached(room)), maxRooms, maxOps, maxPathCost, packDestinations(anyOfDestinations), packDestinations(allOfDestinations));
|
|
1894
1919
|
return fromPackedSearchResult(result);
|
|
1895
1920
|
}
|
|
1896
1921
|
|
|
@@ -1914,18 +1939,8 @@ function bfsMultiroomDistanceMap(start, { costMatrixCallback, maxOps = MAX_USIZE
|
|
|
1914
1939
|
if ([maxOps, maxRooms, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
|
|
1915
1940
|
throw new Error('At least one of maxOps, maxRooms, maxRoomDistance, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
|
|
1916
1941
|
}
|
|
1917
|
-
const startPacked =
|
|
1918
|
-
const result = js_bfs_multiroom_distance_map(startPacked, (room) => costMatrixCallback(
|
|
1919
|
-
? new Uint32Array(anyOfDestinations.reduce((acc, { pos, range }) => {
|
|
1920
|
-
acc.push(pos.__packedPos, range);
|
|
1921
|
-
return acc;
|
|
1922
|
-
}, []))
|
|
1923
|
-
: undefined, allOfDestinations
|
|
1924
|
-
? new Uint32Array(allOfDestinations.reduce((acc, { pos, range }) => {
|
|
1925
|
-
acc.push(pos.__packedPos, range);
|
|
1926
|
-
return acc;
|
|
1927
|
-
}, []))
|
|
1928
|
-
: undefined);
|
|
1942
|
+
const startPacked = packPositions(start);
|
|
1943
|
+
const result = js_bfs_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomNameCached(room)), maxOps, maxRooms, maxPathCost, packDestinations(anyOfDestinations), packDestinations(allOfDestinations));
|
|
1929
1944
|
return fromPackedSearchResult(result);
|
|
1930
1945
|
}
|
|
1931
1946
|
|
|
@@ -1948,18 +1963,8 @@ function dijkstraMultiroomDistanceMap(start, { costMatrixCallback, maxOps = MAX_
|
|
|
1948
1963
|
if ([maxOps, maxRooms, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
|
|
1949
1964
|
throw new Error('At least one of maxOps, maxRooms, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
|
|
1950
1965
|
}
|
|
1951
|
-
const startPacked =
|
|
1952
|
-
const result = js_dijkstra_multiroom_distance_map(startPacked, (room) => costMatrixCallback(
|
|
1953
|
-
? new Uint32Array(anyOfDestinations.reduce((acc, { pos, range }) => {
|
|
1954
|
-
acc.push(pos.__packedPos, range);
|
|
1955
|
-
return acc;
|
|
1956
|
-
}, []))
|
|
1957
|
-
: undefined, allOfDestinations
|
|
1958
|
-
? new Uint32Array(allOfDestinations.reduce((acc, { pos, range }) => {
|
|
1959
|
-
acc.push(pos.__packedPos, range);
|
|
1960
|
-
return acc;
|
|
1961
|
-
}, []))
|
|
1962
|
-
: undefined);
|
|
1966
|
+
const startPacked = packPositions(start);
|
|
1967
|
+
const result = js_dijkstra_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomNameCached(room)), maxOps, maxRooms, maxPathCost, packDestinations(anyOfDestinations), packDestinations(allOfDestinations));
|
|
1963
1968
|
return fromPackedSearchResult(result);
|
|
1964
1969
|
}
|
|
1965
1970
|
|
|
@@ -2019,8 +2024,8 @@ function initialize(verbose = false) {
|
|
|
2019
2024
|
// information that wasm_bindgen only passes here.
|
|
2020
2025
|
//
|
|
2021
2026
|
// There is nothing special about this function and it may also be used by any JS/Rust code as a convenience.
|
|
2022
|
-
function console_error() {
|
|
2023
|
-
const processedArgs =
|
|
2027
|
+
function console_error(...args) {
|
|
2028
|
+
const processedArgs = args
|
|
2024
2029
|
.map(arg => {
|
|
2025
2030
|
if (arg instanceof Error) {
|
|
2026
2031
|
// On this version of Node, the `stack` property of errors contains
|