screeps-clockwork 0.12.0 → 0.13.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 CHANGED
@@ -852,6 +852,16 @@ Object.freeze({
852
852
  Wall: 1, "1": "Wall",
853
853
  Swamp: 2, "2": "Swamp",
854
854
  });
855
+ function clear_portals() {
856
+ wasm.clear_portals();
857
+ }
858
+ /**
859
+ * @returns {any}
860
+ */
861
+ function debug_portal_index() {
862
+ const ret = wasm.debug_portal_index();
863
+ return takeObject(ret);
864
+ }
855
865
  /**
856
866
  * Exports the global range calculation between two positions.
857
867
  * @param {number} packed_pos_1
@@ -898,6 +908,31 @@ function js_astar_multiroom_distance_map(start_packed, get_cost_matrix, max_room
898
908
  heap[stack_pointer++] = undefined;
899
909
  }
900
910
  }
911
+ /**
912
+ * @param {Uint32Array} start_packed
913
+ * @param {Function} get_cost_matrix
914
+ * @param {number} max_rooms
915
+ * @param {number} max_ops
916
+ * @param {number} max_path_cost
917
+ * @param {Uint32Array | null} [any_of_destinations]
918
+ * @param {Uint32Array | null} [all_of_destinations]
919
+ * @returns {SearchResult}
920
+ */
921
+ function js_astar_portal_multiroom_distance_map(start_packed, get_cost_matrix, max_rooms, max_ops, max_path_cost, any_of_destinations, all_of_destinations) {
922
+ try {
923
+ const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
924
+ const len0 = WASM_VECTOR_LEN;
925
+ var ptr1 = isLikeNone(any_of_destinations) ? 0 : passArray32ToWasm0(any_of_destinations, wasm.__wbindgen_malloc);
926
+ var len1 = WASM_VECTOR_LEN;
927
+ var ptr2 = isLikeNone(all_of_destinations) ? 0 : passArray32ToWasm0(all_of_destinations, wasm.__wbindgen_malloc);
928
+ var len2 = WASM_VECTOR_LEN;
929
+ const ret = wasm.js_astar_portal_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_rooms, max_ops, max_path_cost, ptr1, len1, ptr2, len2);
930
+ return SearchResult.__wrap(ret);
931
+ }
932
+ finally {
933
+ heap[stack_pointer++] = undefined;
934
+ }
935
+ }
901
936
  /**
902
937
  * WASM wrapper for the BFS multiroom distance map function.
903
938
  *
@@ -937,6 +972,31 @@ function js_bfs_multiroom_distance_map(start_packed, get_cost_matrix, max_ops, m
937
972
  heap[stack_pointer++] = undefined;
938
973
  }
939
974
  }
975
+ /**
976
+ * @param {Uint32Array} start_packed
977
+ * @param {Function} get_cost_matrix
978
+ * @param {number} max_ops
979
+ * @param {number} max_rooms
980
+ * @param {number} max_path_cost
981
+ * @param {Uint32Array | null} [any_of_destinations]
982
+ * @param {Uint32Array | null} [all_of_destinations]
983
+ * @returns {SearchResult}
984
+ */
985
+ function js_bfs_portal_multiroom_distance_map(start_packed, get_cost_matrix, max_ops, max_rooms, max_path_cost, any_of_destinations, all_of_destinations) {
986
+ try {
987
+ const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
988
+ const len0 = WASM_VECTOR_LEN;
989
+ var ptr1 = isLikeNone(any_of_destinations) ? 0 : passArray32ToWasm0(any_of_destinations, wasm.__wbindgen_malloc);
990
+ var len1 = WASM_VECTOR_LEN;
991
+ var ptr2 = isLikeNone(all_of_destinations) ? 0 : passArray32ToWasm0(all_of_destinations, wasm.__wbindgen_malloc);
992
+ var len2 = WASM_VECTOR_LEN;
993
+ const ret = wasm.js_bfs_portal_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_ops, max_rooms, max_path_cost, ptr1, len1, ptr2, len2);
994
+ return SearchResult.__wrap(ret);
995
+ }
996
+ finally {
997
+ heap[stack_pointer++] = undefined;
998
+ }
999
+ }
940
1000
  /**
941
1001
  * @param {Uint32Array} start_packed
942
1002
  * @param {Function} get_cost_matrix
@@ -962,6 +1022,31 @@ function js_dijkstra_multiroom_distance_map(start_packed, get_cost_matrix, max_o
962
1022
  heap[stack_pointer++] = undefined;
963
1023
  }
964
1024
  }
1025
+ /**
1026
+ * @param {Uint32Array} start_packed
1027
+ * @param {Function} get_cost_matrix
1028
+ * @param {number} max_ops
1029
+ * @param {number} max_rooms
1030
+ * @param {number} max_path_cost
1031
+ * @param {Uint32Array | null} [any_of_destinations]
1032
+ * @param {Uint32Array | null} [all_of_destinations]
1033
+ * @returns {SearchResult}
1034
+ */
1035
+ function js_dijkstra_portal_multiroom_distance_map(start_packed, get_cost_matrix, max_ops, max_rooms, max_path_cost, any_of_destinations, all_of_destinations) {
1036
+ try {
1037
+ const ptr0 = passArray32ToWasm0(start_packed, wasm.__wbindgen_malloc);
1038
+ const len0 = WASM_VECTOR_LEN;
1039
+ var ptr1 = isLikeNone(any_of_destinations) ? 0 : passArray32ToWasm0(any_of_destinations, wasm.__wbindgen_malloc);
1040
+ var len1 = WASM_VECTOR_LEN;
1041
+ var ptr2 = isLikeNone(all_of_destinations) ? 0 : passArray32ToWasm0(all_of_destinations, wasm.__wbindgen_malloc);
1042
+ var len2 = WASM_VECTOR_LEN;
1043
+ const ret = wasm.js_dijkstra_portal_multiroom_distance_map(ptr0, len0, addBorrowedObject(get_cost_matrix), max_ops, max_rooms, max_path_cost, ptr1, len1, ptr2, len2);
1044
+ return SearchResult.__wrap(ret);
1045
+ }
1046
+ finally {
1047
+ heap[stack_pointer++] = undefined;
1048
+ }
1049
+ }
965
1050
  /**
966
1051
  * @param {number} start
967
1052
  * @param {MultiroomDistanceMap} distance_map
@@ -985,6 +1070,29 @@ function js_path_to_multiroom_distance_map_origin(start, distance_map, direction
985
1070
  wasm.__wbindgen_add_to_stack_pointer(16);
986
1071
  }
987
1072
  }
1073
+ /**
1074
+ * @param {number} start
1075
+ * @param {MultiroomDistanceMap} distance_map
1076
+ * @param {DirectionOrder} direction_order
1077
+ * @returns {Path}
1078
+ */
1079
+ function js_path_to_multiroom_distance_map_origin_with_portals(start, distance_map, direction_order) {
1080
+ try {
1081
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1082
+ _assertClass(distance_map, MultiroomDistanceMap);
1083
+ wasm.js_path_to_multiroom_distance_map_origin_with_portals(retptr, start, distance_map.__wbg_ptr, direction_order);
1084
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1085
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1086
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1087
+ if (r2) {
1088
+ throw takeObject(r1);
1089
+ }
1090
+ return Path.__wrap(r0);
1091
+ }
1092
+ finally {
1093
+ wasm.__wbindgen_add_to_stack_pointer(16);
1094
+ }
1095
+ }
988
1096
  /**
989
1097
  * @param {number} start
990
1098
  * @param {MultiroomFlowField} flow_field
@@ -1007,6 +1115,28 @@ function js_path_to_multiroom_flow_field_origin(start, flow_field) {
1007
1115
  wasm.__wbindgen_add_to_stack_pointer(16);
1008
1116
  }
1009
1117
  }
1118
+ /**
1119
+ * @param {number} start
1120
+ * @param {MultiroomFlowField} flow_field
1121
+ * @returns {Path}
1122
+ */
1123
+ function js_path_to_multiroom_flow_field_origin_with_portals(start, flow_field) {
1124
+ try {
1125
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1126
+ _assertClass(flow_field, MultiroomFlowField);
1127
+ wasm.js_path_to_multiroom_flow_field_origin_with_portals(retptr, start, flow_field.__wbg_ptr);
1128
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1129
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1130
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1131
+ if (r2) {
1132
+ throw takeObject(r1);
1133
+ }
1134
+ return Path.__wrap(r0);
1135
+ }
1136
+ finally {
1137
+ wasm.__wbindgen_add_to_stack_pointer(16);
1138
+ }
1139
+ }
1010
1140
  /**
1011
1141
  * @param {number} start
1012
1142
  * @param {MultiroomMonoFlowField} flow_field
@@ -1029,6 +1159,28 @@ function js_path_to_multiroom_mono_flow_field_origin(start, flow_field) {
1029
1159
  wasm.__wbindgen_add_to_stack_pointer(16);
1030
1160
  }
1031
1161
  }
1162
+ /**
1163
+ * @param {number} start
1164
+ * @param {MultiroomMonoFlowField} flow_field
1165
+ * @returns {Path}
1166
+ */
1167
+ function js_path_to_multiroom_mono_flow_field_origin_with_portals(start, flow_field) {
1168
+ try {
1169
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1170
+ _assertClass(flow_field, MultiroomMonoFlowField);
1171
+ wasm.js_path_to_multiroom_mono_flow_field_origin_with_portals(retptr, start, flow_field.__wbg_ptr);
1172
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1173
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1174
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1175
+ if (r2) {
1176
+ throw takeObject(r1);
1177
+ }
1178
+ return Path.__wrap(r0);
1179
+ }
1180
+ finally {
1181
+ wasm.__wbindgen_add_to_stack_pointer(16);
1182
+ }
1183
+ }
1032
1184
  /**
1033
1185
  * Creates a flow field for the given distance map.
1034
1186
  * @param {MultiroomDistanceMap} distance_map
@@ -1051,6 +1203,40 @@ function multiroomMonoFlowField(distance_map, direction_order) {
1051
1203
  const ret = wasm.multiroomMonoFlowField(distance_map.__wbg_ptr, direction_order);
1052
1204
  return MultiroomMonoFlowField.__wrap(ret);
1053
1205
  }
1206
+ /**
1207
+ * @param {MultiroomDistanceMap} distance_map
1208
+ * @param {DirectionOrder} direction_order
1209
+ * @returns {MultiroomFlowField}
1210
+ */
1211
+ function multiroomPortalFlowField(distance_map, direction_order) {
1212
+ _assertClass(distance_map, MultiroomDistanceMap);
1213
+ const ret = wasm.multiroomPortalFlowField(distance_map.__wbg_ptr, direction_order);
1214
+ return MultiroomFlowField.__wrap(ret);
1215
+ }
1216
+ /**
1217
+ * @param {MultiroomDistanceMap} distance_map
1218
+ * @param {DirectionOrder} direction_order
1219
+ * @returns {MultiroomMonoFlowField}
1220
+ */
1221
+ function multiroomPortalMonoFlowField(distance_map, direction_order) {
1222
+ _assertClass(distance_map, MultiroomDistanceMap);
1223
+ const ret = wasm.multiroomPortalMonoFlowField(distance_map.__wbg_ptr, direction_order);
1224
+ return MultiroomMonoFlowField.__wrap(ret);
1225
+ }
1226
+ /**
1227
+ * @param {number} room_limit
1228
+ */
1229
+ function set_portal_distance_cache_room_limit(room_limit) {
1230
+ wasm.set_portal_distance_cache_room_limit(room_limit);
1231
+ }
1232
+ /**
1233
+ * @param {Uint32Array} packed_pairs
1234
+ */
1235
+ function set_portals(packed_pairs) {
1236
+ const ptr0 = passArray32ToWasm0(packed_pairs, wasm.__wbindgen_malloc);
1237
+ const len0 = WASM_VECTOR_LEN;
1238
+ wasm.set_portals(ptr0, len0);
1239
+ }
1054
1240
  /**
1055
1241
  * @returns {string}
1056
1242
  */
@@ -1074,6 +1260,13 @@ function version() {
1074
1260
  function __wbg_get_imports() {
1075
1261
  const import0 = {
1076
1262
  __proto__: null,
1263
+ __wbg___wbindgen_debug_string_edece8177ad01481: function (arg0, arg1) {
1264
+ const ret = debugString(getObject(arg1));
1265
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1266
+ const len1 = WASM_VECTOR_LEN;
1267
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1268
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1269
+ },
1077
1270
  __wbg___wbindgen_is_undefined_35bb9f4c7fd651d5: function (arg0) {
1078
1271
  const ret = getObject(arg0) === undefined;
1079
1272
  return ret;
@@ -1096,7 +1289,7 @@ function __wbg_get_imports() {
1096
1289
  return addHeapObject(ret);
1097
1290
  }, arguments);
1098
1291
  },
1099
- __wbg_clockworkcostmatrix_get_pointer_bb635b319c5f0508: function (arg0) {
1292
+ __wbg_clockworkcostmatrix_get_pointer_20f0153b006cac1d: function (arg0) {
1100
1293
  const ret = clockworkcostmatrix_get_pointer(takeObject(arg0));
1101
1294
  return ret;
1102
1295
  },
@@ -1120,6 +1313,10 @@ function __wbg_get_imports() {
1120
1313
  const ret = getObject(arg0).getRawBuffer(getObject(arg1));
1121
1314
  return addHeapObject(ret);
1122
1315
  },
1316
+ __wbg_new_02d162bc6cf02f60: function () {
1317
+ const ret = new Object();
1318
+ return addHeapObject(ret);
1319
+ },
1123
1320
  __wbg_new_1f236d63ba0c4784: function (arg0, arg1) {
1124
1321
  const ret = new Error(getStringFromWasm0(arg0, arg1));
1125
1322
  return addHeapObject(ret);
@@ -1134,6 +1331,12 @@ function __wbg_get_imports() {
1134
1331
  return addHeapObject(ret);
1135
1332
  }, arguments);
1136
1333
  },
1334
+ __wbg_set_a0e911be3da02782: function () {
1335
+ return handleError(function (arg0, arg1, arg2) {
1336
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
1337
+ return ret;
1338
+ }, arguments);
1339
+ },
1137
1340
  __wbg_set_packed_cc769b1ab2aa7e8e: function (arg0, arg1) {
1138
1341
  getObject(arg0).__packedPos = arg1 >>> 0;
1139
1342
  },
@@ -1221,6 +1424,74 @@ function addBorrowedObject(obj) {
1221
1424
  heap[--stack_pointer] = obj;
1222
1425
  return stack_pointer;
1223
1426
  }
1427
+ function debugString(val) {
1428
+ // primitive types
1429
+ const type = typeof val;
1430
+ if (type == 'number' || type == 'boolean' || val == null) {
1431
+ return `${val}`;
1432
+ }
1433
+ if (type == 'string') {
1434
+ return `"${val}"`;
1435
+ }
1436
+ if (type == 'symbol') {
1437
+ const description = val.description;
1438
+ if (description == null) {
1439
+ return 'Symbol';
1440
+ }
1441
+ else {
1442
+ return `Symbol(${description})`;
1443
+ }
1444
+ }
1445
+ if (type == 'function') {
1446
+ const name = val.name;
1447
+ if (typeof name == 'string' && name.length > 0) {
1448
+ return `Function(${name})`;
1449
+ }
1450
+ else {
1451
+ return 'Function';
1452
+ }
1453
+ }
1454
+ // objects
1455
+ if (Array.isArray(val)) {
1456
+ const length = val.length;
1457
+ let debug = '[';
1458
+ if (length > 0) {
1459
+ debug += debugString(val[0]);
1460
+ }
1461
+ for (let i = 1; i < length; i++) {
1462
+ debug += ', ' + debugString(val[i]);
1463
+ }
1464
+ debug += ']';
1465
+ return debug;
1466
+ }
1467
+ // Test for built-in
1468
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
1469
+ let className;
1470
+ if (builtInMatches && builtInMatches.length > 1) {
1471
+ className = builtInMatches[1];
1472
+ }
1473
+ else {
1474
+ // Failed to match the standard '[object ClassName]'
1475
+ return toString.call(val);
1476
+ }
1477
+ if (className == 'Object') {
1478
+ // we're a user defined class or Object
1479
+ // JSON.stringify avoids problems with cycles, and is generally much
1480
+ // easier than looping through ownProperties of `val`.
1481
+ try {
1482
+ return 'Object(' + JSON.stringify(val) + ')';
1483
+ }
1484
+ catch (_) {
1485
+ return 'Object';
1486
+ }
1487
+ }
1488
+ // errors
1489
+ if (val instanceof Error) {
1490
+ return `${val.name}: ${val.message}\n${val.stack}`;
1491
+ }
1492
+ // TODO we could test for more things here, like `Set`s and `Map`s.
1493
+ return className;
1494
+ }
1224
1495
  function dropObject(idx) {
1225
1496
  if (idx < 1028)
1226
1497
  return;
@@ -1399,6 +1670,35 @@ function initSync(module) {
1399
1670
  return __wbg_finalize_init(instance);
1400
1671
  }
1401
1672
 
1673
+ function packPositions(positions) {
1674
+ const packed = new Uint32Array(positions.length);
1675
+ for (let i = 0; i < positions.length; i++) {
1676
+ packed[i] = positions[i].__packedPos;
1677
+ }
1678
+ return packed;
1679
+ }
1680
+ function packDestinations(destinations) {
1681
+ if (!destinations) {
1682
+ return undefined;
1683
+ }
1684
+ const packed = new Uint32Array(destinations.length * 2);
1685
+ for (let i = 0; i < destinations.length; i++) {
1686
+ const offset = i * 2;
1687
+ packed[offset] = destinations[i].pos.__packedPos;
1688
+ packed[offset + 1] = destinations[i].range;
1689
+ }
1690
+ return packed;
1691
+ }
1692
+ function packPortalPairs(portals) {
1693
+ const packed = new Uint32Array(portals.length * 2);
1694
+ for (let i = 0; i < portals.length; i++) {
1695
+ const offset = i * 2;
1696
+ packed[offset] = portals[i][0].__packedPos;
1697
+ packed[offset + 1] = portals[i][1].__packedPos;
1698
+ }
1699
+ return packed;
1700
+ }
1701
+
1402
1702
  const MAX_USIZE = 0xffffffff;
1403
1703
 
1404
1704
  function fromPacked(packedPos) {
@@ -1449,26 +1749,6 @@ function packRoomName(room) {
1449
1749
  return (x << 8) | y;
1450
1750
  }
1451
1751
 
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
1752
  function assertNotFreed(handle, label) {
1473
1753
  if (!handle) {
1474
1754
  throw new Error(`${label} has been freed`);
@@ -1729,6 +2009,12 @@ class ClockworkMultiroomFlowField {
1729
2009
  pathToOrigin(start) {
1730
2010
  return new ClockworkPath(js_path_to_multiroom_flow_field_origin(start.__packedPos, assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField')));
1731
2011
  }
2012
+ /**
2013
+ * Find a portal-aware path from a given position to the origin of the flow field.
2014
+ */
2015
+ pathToOriginWithPortals(start) {
2016
+ return new ClockworkPath(js_path_to_multiroom_flow_field_origin_with_portals(start.__packedPos, assertNotFreed(this._flowField, 'ClockworkMultiroomFlowField')));
2017
+ }
1732
2018
  }
1733
2019
 
1734
2020
  /**
@@ -1807,6 +2093,12 @@ class ClockworkMultiroomMonoFlowField {
1807
2093
  pathToOrigin(start) {
1808
2094
  return new ClockworkPath(js_path_to_multiroom_mono_flow_field_origin(start.__packedPos, assertNotFreed(this._flowField, 'ClockworkMultiroomMonoFlowField')));
1809
2095
  }
2096
+ /**
2097
+ * Find a portal-aware path from a given position to the origin of the flow field.
2098
+ */
2099
+ pathToOriginWithPortals(start) {
2100
+ return new ClockworkPath(js_path_to_multiroom_mono_flow_field_origin_with_portals(start.__packedPos, assertNotFreed(this._flowField, 'ClockworkMultiroomMonoFlowField')));
2101
+ }
1810
2102
  }
1811
2103
 
1812
2104
  const DEFAULT_DIRECTION_ORDER = DirectionOrder.CardinalFirst;
@@ -1857,6 +2149,14 @@ class ClockworkMultiroomDistanceMap {
1857
2149
  var _a;
1858
2150
  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));
1859
2151
  }
2152
+ /**
2153
+ * Portal-aware path to the origin from a given position.
2154
+ * Pass `DirectionOrder.DiagonalFirst` to prefer diagonal steps when multiple neighbors are equally close.
2155
+ */
2156
+ pathToOriginWithPortals(start, options = {}) {
2157
+ var _a;
2158
+ return new ClockworkPath(js_path_to_multiroom_distance_map_origin_with_portals(start.__packedPos, assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap'), (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
2159
+ }
1860
2160
  /**
1861
2161
  * Flow field for this distance map.
1862
2162
  * Pass `DirectionOrder.DiagonalFirst` to prefer diagonal directions when multiple neighbors are equally close.
@@ -1865,6 +2165,14 @@ class ClockworkMultiroomDistanceMap {
1865
2165
  var _a;
1866
2166
  return new ClockworkMultiroomFlowField(multiroomFlowField(assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap'), (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
1867
2167
  }
2168
+ /**
2169
+ * Portal-aware flow field for this distance map.
2170
+ * Pass `DirectionOrder.DiagonalFirst` to prefer diagonal directions when multiple neighbors are equally close.
2171
+ */
2172
+ toFlowFieldWithPortals(options = {}) {
2173
+ var _a;
2174
+ return new ClockworkMultiroomFlowField(multiroomPortalFlowField(assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap'), (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
2175
+ }
1868
2176
  /**
1869
2177
  * Mono-directional flow field for this distance map.
1870
2178
  * Pass `DirectionOrder.DiagonalFirst` to prefer diagonal directions when multiple neighbors are equally close.
@@ -1873,6 +2181,14 @@ class ClockworkMultiroomDistanceMap {
1873
2181
  var _a;
1874
2182
  return new ClockworkMultiroomMonoFlowField(multiroomMonoFlowField(assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap'), (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
1875
2183
  }
2184
+ /**
2185
+ * Portal-aware monodirectional flow field for this distance map.
2186
+ * Pass `DirectionOrder.DiagonalFirst` to prefer diagonal directions when multiple neighbors are equally close.
2187
+ */
2188
+ toMonoFlowFieldWithPortals(options = {}) {
2189
+ var _a;
2190
+ return new ClockworkMultiroomMonoFlowField(multiroomPortalMonoFlowField(assertNotFreed(this._map, 'ClockworkMultiroomDistanceMap'), (_a = options.directionOrder) !== null && _a !== void 0 ? _a : DEFAULT_DIRECTION_ORDER));
2191
+ }
1876
2192
  }
1877
2193
 
1878
2194
  function fromPackedSearchResult(result) {
@@ -1918,6 +2234,32 @@ function astarMultiroomDistanceMap(start, { costMatrixCallback, maxRooms = MAX_U
1918
2234
  const result = js_astar_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomNameCached(room)), maxRooms, maxOps, maxPathCost, packDestinations(anyOfDestinations), packDestinations(allOfDestinations));
1919
2235
  return fromPackedSearchResult(result);
1920
2236
  }
2237
+ /**
2238
+ * Create a portal-aware distance map for the given start positions, using A* to
2239
+ * optimize the search toward the given destinations.
2240
+ *
2241
+ * Portals configured with `initialize({ portals })` or `setPortals` are treated
2242
+ * like exits: stepping onto a portal entrance lands on its paired exit.
2243
+ *
2244
+ * This calculates a distance map across multiple rooms, with a few configurable limits:
2245
+ * - `maxOps`: The maximum number of pathfinding operations to perform.
2246
+ * - `maxRooms`: The maximum number of rooms to explore.
2247
+ * - `maxPathCost`: Don't explore tiles with a greater path cost than this.
2248
+ *
2249
+ * At least one of these limits or destination lists must be set.
2250
+ *
2251
+ * @param start - The starting positions.
2252
+ * @param options - The options for the distance map.
2253
+ * @returns A multi-room distance map.
2254
+ */
2255
+ function astarPortalMultiroomDistanceMap(start, { costMatrixCallback, maxRooms = MAX_USIZE, maxOps = MAX_USIZE, maxPathCost = MAX_USIZE, anyOfDestinations, allOfDestinations }) {
2256
+ if ([maxRooms, maxOps, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
2257
+ throw new Error('At least one of maxRooms, maxOps, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
2258
+ }
2259
+ const startPacked = packPositions(start);
2260
+ const result = js_astar_portal_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomNameCached(room)), maxRooms, maxOps, maxPathCost, packDestinations(anyOfDestinations), packDestinations(allOfDestinations));
2261
+ return fromPackedSearchResult(result);
2262
+ }
1921
2263
 
1922
2264
  /**
1923
2265
  * Create a distance map for the given start positions, using a breadth-first search.
@@ -1937,12 +2279,39 @@ function astarMultiroomDistanceMap(start, { costMatrixCallback, maxRooms = MAX_U
1937
2279
  */
1938
2280
  function bfsMultiroomDistanceMap(start, { costMatrixCallback, maxOps = MAX_USIZE, maxRooms = MAX_USIZE, maxPathCost = MAX_USIZE, anyOfDestinations, allOfDestinations }) {
1939
2281
  if ([maxOps, maxRooms, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
1940
- throw new Error('At least one of maxOps, maxRooms, maxRoomDistance, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
2282
+ throw new Error('At least one of maxOps, maxRooms, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
1941
2283
  }
1942
2284
  const startPacked = packPositions(start);
1943
2285
  const result = js_bfs_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomNameCached(room)), maxOps, maxRooms, maxPathCost, packDestinations(anyOfDestinations), packDestinations(allOfDestinations));
1944
2286
  return fromPackedSearchResult(result);
1945
2287
  }
2288
+ /**
2289
+ * Create a portal-aware distance map for the given start positions, using a breadth-first search.
2290
+ * This does not factor in terrain costs (treating anything less than 255 in the cost
2291
+ * matrix as passable), so it's faster but less useful than Dijkstra's algorithm.
2292
+ *
2293
+ * Portals configured with `initialize({ portals })` or `setPortals` are treated
2294
+ * like exits: stepping onto a portal entrance lands on its paired exit.
2295
+ *
2296
+ * This calculates a distance map across multiple rooms, with a few configurable limits:
2297
+ * - `maxOps`: The maximum number of pathfinding operations to perform.
2298
+ * - `maxRooms`: The maximum number of rooms to explore.
2299
+ * - `maxPathCost`: Don't explore tiles with a greater path cost than this.
2300
+ *
2301
+ * At least one of these limits or destination lists must be set.
2302
+ *
2303
+ * @param start - The starting positions.
2304
+ * @param options - The options for the distance map.
2305
+ * @returns A multi-room distance map.
2306
+ */
2307
+ function bfsPortalMultiroomDistanceMap(start, { costMatrixCallback, maxOps = MAX_USIZE, maxRooms = MAX_USIZE, maxPathCost = MAX_USIZE, anyOfDestinations, allOfDestinations }) {
2308
+ if ([maxOps, maxRooms, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
2309
+ throw new Error('At least one of maxOps, maxRooms, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
2310
+ }
2311
+ const startPacked = packPositions(start);
2312
+ const result = js_bfs_portal_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomNameCached(room)), maxOps, maxRooms, maxPathCost, packDestinations(anyOfDestinations), packDestinations(allOfDestinations));
2313
+ return fromPackedSearchResult(result);
2314
+ }
1946
2315
 
1947
2316
  /**
1948
2317
  * Create a distance map for the given start positions, using Dijkstra's algorithm to
@@ -1967,6 +2336,32 @@ function dijkstraMultiroomDistanceMap(start, { costMatrixCallback, maxOps = MAX_
1967
2336
  const result = js_dijkstra_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomNameCached(room)), maxOps, maxRooms, maxPathCost, packDestinations(anyOfDestinations), packDestinations(allOfDestinations));
1968
2337
  return fromPackedSearchResult(result);
1969
2338
  }
2339
+ /**
2340
+ * Create a portal-aware distance map for the given start positions, using Dijkstra's
2341
+ * algorithm to factor in terrain costs (0-255, where 255 is impassable).
2342
+ *
2343
+ * Portals configured with `initialize({ portals })` or `setPortals` are treated
2344
+ * like exits: stepping onto a portal entrance lands on its paired exit.
2345
+ *
2346
+ * This calculates a distance map across multiple rooms, with a few configurable limits:
2347
+ * - `maxOps`: The maximum number of pathfinding operations to perform.
2348
+ * - `maxRooms`: The maximum number of rooms to explore.
2349
+ * - `maxPathCost`: Don't explore tiles with a greater path cost than this.
2350
+ *
2351
+ * At least one of these limits or destination lists must be set.
2352
+ *
2353
+ * @param start - The starting positions.
2354
+ * @param options - The options for the distance map.
2355
+ * @returns A multi-room distance map.
2356
+ */
2357
+ function dijkstraPortalMultiroomDistanceMap(start, { costMatrixCallback, maxOps = MAX_USIZE, maxRooms = MAX_USIZE, maxPathCost = MAX_USIZE, anyOfDestinations, allOfDestinations }) {
2358
+ if ([maxOps, maxRooms, maxPathCost].every(n => n === MAX_USIZE) && !anyOfDestinations && !allOfDestinations) {
2359
+ throw new Error('At least one of maxOps, maxRooms, maxPathCost, anyOfDestinations, or allOfDestinations must be set');
2360
+ }
2361
+ const startPacked = packPositions(start);
2362
+ const result = js_dijkstra_portal_multiroom_distance_map(startPacked, (room) => costMatrixCallback(fromPackedRoomNameCached(room)), maxOps, maxRooms, maxPathCost, packDestinations(anyOfDestinations), packDestinations(allOfDestinations));
2363
+ return fromPackedSearchResult(result);
2364
+ }
1970
2365
 
1971
2366
  /**
1972
2367
  * Get the global range between two positions. This is different
@@ -1990,15 +2385,31 @@ let wasm_bytes;
1990
2385
  let wasm_module;
1991
2386
  let wasm_instance;
1992
2387
  let initialized = false;
2388
+ let initializeOptionsApplied = false;
2389
+ let pendingInitializeOptions;
2390
+ let configuredPortalList;
2391
+ let configuredPortalDistanceCacheRoomLimit;
1993
2392
  /**
1994
- * The `initialize` function should be called in your main loop before
1995
- * using any other screeps-clockwork functions. Depending on available
1996
- * CPU, it may not load the WASM module completely in the first tick,
1997
- * but it will pick back up where it left off if the script times out.
2393
+ * The `initialize` function initializes the WASM module and applies global
2394
+ * setup options. Call it in your main loop before using any other
2395
+ * screeps-clockwork functions. Depending on available CPU, it may not load the
2396
+ * WASM module completely in the first tick, but it will pick back up where it
2397
+ * left off if the script times out.
2398
+ *
2399
+ * It is safe to call this function repeatedly, but setup options such as
2400
+ * portals and portal cache sizing are applied only once, after WASM
2401
+ * initialization has completed. Use `setPortals` when you intentionally need
2402
+ * to reconfigure portals later.
1998
2403
  *
1999
- * @param verbose - If true, will log the state of the WASM module as it loads.
2404
+ * @param options - Pass `true` or `{ verbose: true }` to log WASM loading;
2405
+ * provide portals and cache sizing to apply them once after WASM initialization.
2000
2406
  */
2001
- function initialize(verbose = false) {
2407
+ function initialize(options = false) {
2408
+ var _a;
2409
+ const verbose = typeof options === 'boolean' ? options : ((_a = options.verbose) !== null && _a !== void 0 ? _a : false);
2410
+ if (typeof options !== 'boolean') {
2411
+ recordInitializeOptions(options);
2412
+ }
2002
2413
  // need to freshly override the fake console object each tick
2003
2414
  console.error = console_error;
2004
2415
  const start = Game.cpu.getUsed();
@@ -2017,6 +2428,77 @@ function initialize(verbose = false) {
2017
2428
  console.logUnsafe(`[clockwork] version ${version()} initialized with ${(Game.cpu.getUsed() - start).toFixed(2)} CPU`);
2018
2429
  }
2019
2430
  initialized = true;
2431
+ applyInitializeOptions();
2432
+ }
2433
+ function recordInitializeOptions(options) {
2434
+ var _a, _b;
2435
+ if (options.portalDistanceCacheRoomLimit === undefined && options.portals === undefined) {
2436
+ return;
2437
+ }
2438
+ pendingInitializeOptions = {
2439
+ portals: (_a = options.portals) !== null && _a !== void 0 ? _a : pendingInitializeOptions === null || pendingInitializeOptions === void 0 ? void 0 : pendingInitializeOptions.portals,
2440
+ portalDistanceCacheRoomLimit: (_b = options.portalDistanceCacheRoomLimit) !== null && _b !== void 0 ? _b : pendingInitializeOptions === null || pendingInitializeOptions === void 0 ? void 0 : pendingInitializeOptions.portalDistanceCacheRoomLimit
2441
+ };
2442
+ }
2443
+ function applyInitializeOptions() {
2444
+ if (!initialized || initializeOptionsApplied || !pendingInitializeOptions) {
2445
+ return;
2446
+ }
2447
+ const options = pendingInitializeOptions;
2448
+ if (options.portalDistanceCacheRoomLimit !== undefined || options.portals !== undefined) {
2449
+ if (options.portalDistanceCacheRoomLimit !== undefined &&
2450
+ options.portalDistanceCacheRoomLimit !== configuredPortalDistanceCacheRoomLimit) {
2451
+ applyPortalDistanceCacheRoomLimit(options.portalDistanceCacheRoomLimit);
2452
+ }
2453
+ if (options.portals && options.portals !== configuredPortalList) {
2454
+ setPortals(options.portals);
2455
+ }
2456
+ initializeOptionsApplied = true;
2457
+ }
2458
+ }
2459
+ /**
2460
+ * Configure the portal pairs used by portal-aware pathfinding functions.
2461
+ * Each pair is installed bidirectionally.
2462
+ */
2463
+ function setPortals(portals) {
2464
+ set_portals(packPortalPairs(portals));
2465
+ configuredPortalList = portals;
2466
+ }
2467
+ function applyPortalDistanceCacheRoomLimit(roomLimit) {
2468
+ if (!Number.isFinite(roomLimit) || roomLimit < 0 || Math.floor(roomLimit) !== roomLimit) {
2469
+ throw new Error('Portal distance cache room limit must be a non-negative integer');
2470
+ }
2471
+ set_portal_distance_cache_room_limit(roomLimit);
2472
+ configuredPortalDistanceCacheRoomLimit = roomLimit;
2473
+ }
2474
+ /**
2475
+ * Remove all configured portal pairs while preserving the initialize-time cache limit.
2476
+ */
2477
+ function clearPortals() {
2478
+ clear_portals();
2479
+ configuredPortalList = undefined;
2480
+ }
2481
+ /**
2482
+ * Return debug counters for the configured portal index and its nearest-portal cache.
2483
+ * `totalSize` is an approximate in-memory size formatted for logs; `totalSizeBytes`
2484
+ * preserves the raw byte estimate.
2485
+ */
2486
+ function debugPortalIndex() {
2487
+ const info = debug_portal_index();
2488
+ return Object.assign(Object.assign({}, info), { totalSize: formatBytes(info.totalSizeBytes) });
2489
+ }
2490
+ function formatBytes(bytes) {
2491
+ const units = ['B', 'KiB', 'MiB', 'GiB'];
2492
+ let value = bytes;
2493
+ let unitIndex = 0;
2494
+ while (value >= 1024 && unitIndex < units.length - 1) {
2495
+ value /= 1024;
2496
+ unitIndex++;
2497
+ }
2498
+ if (unitIndex === 0) {
2499
+ return `${bytes} B`;
2500
+ }
2501
+ return `${value.toFixed(2)} ${units[unitIndex]}`;
2020
2502
  }
2021
2503
  // This provides the function `console.error` that wasm_bindgen sometimes expects to exist,
2022
2504
  // especially with type checks in debug mode. An alternative is to have this be `function () {}`
@@ -2048,9 +2530,15 @@ exports.ClockworkMultiroomMonoFlowField = ClockworkMultiroomMonoFlowField;
2048
2530
  exports.ClockworkPath = ClockworkPath;
2049
2531
  exports.DirectionOrder = DirectionOrder;
2050
2532
  exports.astarMultiroomDistanceMap = astarMultiroomDistanceMap;
2533
+ exports.astarPortalMultiroomDistanceMap = astarPortalMultiroomDistanceMap;
2051
2534
  exports.bfsMultiroomDistanceMap = bfsMultiroomDistanceMap;
2535
+ exports.bfsPortalMultiroomDistanceMap = bfsPortalMultiroomDistanceMap;
2536
+ exports.clearPortals = clearPortals;
2537
+ exports.debugPortalIndex = debugPortalIndex;
2052
2538
  exports.dijkstraMultiroomDistanceMap = dijkstraMultiroomDistanceMap;
2539
+ exports.dijkstraPortalMultiroomDistanceMap = dijkstraPortalMultiroomDistanceMap;
2053
2540
  exports.getRange = getRange;
2054
2541
  exports.getTerrainCostMatrix = getTerrainCostMatrix;
2055
2542
  exports.initialize = initialize;
2543
+ exports.setPortals = setPortals;
2056
2544
  //# sourceMappingURL=index.js.map