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.
Binary file
@@ -11,6 +11,8 @@ export * from './wrappers/monoFlowField';
11
11
  export * from './wrappers/multiroomFlowField';
12
12
  export * from './wrappers/multiroomMonoFlowField';
13
13
  export * from './wrappers/path';
14
+ export type { ClockworkDistanceMap } from './wrappers/distanceMap';
15
+ export type { ClockworkMultiroomDistanceMap } from './wrappers/multiroomDistanceMap';
14
16
  /**
15
17
  * The `initialize` function should be called in your main loop before
16
18
  * using any other screeps-clockwork functions. Depending on available
@@ -1,3 +1,4 @@
1
1
  export declare function fromPacked(packedPos: number): RoomPosition;
2
2
  export declare function fromPackedRoomName(packedRoomName: number): string;
3
+ export declare function fromPackedRoomNameCached(packedRoomName: number): string;
3
4
  export declare function packRoomName(room: string): number;
@@ -0,0 +1,6 @@
1
+ export interface PackedDestination {
2
+ pos: RoomPosition;
3
+ range: number;
4
+ }
5
+ export declare function packPositions(positions: RoomPosition[]): Uint32Array;
6
+ export declare function packDestinations(destinations: PackedDestination[] | undefined): Uint32Array | undefined;
@@ -609,42 +609,6 @@ export class Path {
609
609
  */
610
610
  to_array_reversed(): Uint32Array;
611
611
  }
612
- /**
613
- * Tracks fatigue cost for each position in a path. Used to calculate move time
614
- * for a given creep build.
615
- */
616
- export class PathFatigue {
617
- /**
618
- * @param {Path} path
619
- */
620
- constructor(path: Path);
621
- __destroy_into_raw(): any;
622
- __wbg_ptr: any;
623
- free(): void;
624
- /**
625
- * @returns {number}
626
- */
627
- len(): number;
628
- /**
629
- * Calculates the total move time for the path, given a fatigue ratio.
630
- *
631
- * For unboosted creeps, the ratio is `Math.floor(moveParts * 2 / fatigueParts)`
632
- * where `fatigue_parts` are any part except MOVE and empty CARRY parts.
633
- * @param {number} fatigue_ratio
634
- * @returns {number}
635
- */
636
- moveTime(fatigue_ratio: number): number;
637
- /**
638
- * Refreshes fatigue cost for each position in the path. If the PathFatigue
639
- * has not been initialized yet, every position's fatigue cost will be set,
640
- * even if there is no vision in the room, based on terrain costs. If the
641
- * list *has* been initialized, only positions with vision will be updated.
642
- *
643
- * When there is vision, this also accounts for roads at the position.
644
- * @param {Path} path
645
- */
646
- refresh(path: Path): void;
647
- }
648
612
  /**
649
613
  * Translates the `PWR_*` constants, which are types of powers used by power
650
614
  * creeps
@@ -4,7 +4,11 @@ import { DistanceMap } from '../wasm/screeps_clockwork';
4
4
  */
5
5
  export declare class ClockworkDistanceMap {
6
6
  private _map;
7
- constructor(_map: DistanceMap);
7
+ constructor(map: DistanceMap);
8
+ /**
9
+ * Frees the underlying WASM distance map allocation.
10
+ */
11
+ free(): void;
8
12
  /**
9
13
  * Gets the distance value at a given position.
10
14
  */
@@ -4,7 +4,11 @@ import { FlowField } from '../wasm/screeps_clockwork';
4
4
  */
5
5
  export declare class ClockworkFlowField {
6
6
  private _flowField;
7
- constructor(_flowField: FlowField);
7
+ constructor(flowField: FlowField);
8
+ /**
9
+ * Frees the underlying WASM flow field allocation.
10
+ */
11
+ free(): void;
8
12
  /**
9
13
  * Get the internal value for a given coordinate.
10
14
  */
@@ -0,0 +1,5 @@
1
+ export interface FreeableWasmHandle {
2
+ free(): void;
3
+ }
4
+ export declare function assertNotFreed<T>(handle: T | undefined, label: string): T;
5
+ export declare function freeHandle<T extends FreeableWasmHandle>(handle: T | undefined): undefined;
@@ -4,7 +4,11 @@ import { MonoFlowField } from '../wasm/screeps_clockwork';
4
4
  */
5
5
  export declare class ClockworkMonoFlowField {
6
6
  private _flowField;
7
- constructor(_flowField: MonoFlowField);
7
+ constructor(flowField: MonoFlowField);
8
+ /**
9
+ * Frees the underlying WASM flow field allocation.
10
+ */
11
+ free(): void;
8
12
  /**
9
13
  * Get the direction for a given coordinate.
10
14
  */
@@ -12,7 +12,11 @@ export interface DirectionOrderOptions {
12
12
  */
13
13
  export declare class ClockworkMultiroomDistanceMap {
14
14
  private _map;
15
- constructor(_map: MultiroomDistanceMap);
15
+ constructor(map: MultiroomDistanceMap);
16
+ /**
17
+ * Frees the underlying WASM multiroom distance map allocation.
18
+ */
19
+ free(): void;
16
20
  /**
17
21
  * Get the stored value for a given position.
18
22
  */
@@ -6,7 +6,11 @@ import { ClockworkPath } from './path';
6
6
  */
7
7
  export declare class ClockworkMultiroomFlowField {
8
8
  private _flowField;
9
- constructor(_flowField: MultiroomFlowField);
9
+ constructor(flowField: MultiroomFlowField);
10
+ /**
11
+ * Frees the underlying WASM multiroom flow field allocation.
12
+ */
13
+ free(): void;
10
14
  /**
11
15
  * Get the flow field value at a given position.
12
16
  */
@@ -6,7 +6,11 @@ import { ClockworkPath } from './path';
6
6
  */
7
7
  export declare class ClockworkMultiroomMonoFlowField {
8
8
  private _flowField;
9
- constructor(_flowField: MultiroomMonoFlowField);
9
+ constructor(flowField: MultiroomMonoFlowField);
10
+ /**
11
+ * Frees the underlying WASM multiroom flow field allocation.
12
+ */
13
+ free(): void;
10
14
  /**
11
15
  * Get the direction at a given position.
12
16
  */
@@ -4,8 +4,12 @@ import { Path } from '../wasm/screeps_clockwork';
4
4
  * function like `ClockworkMultiroomFlowField.pathToOrigin` rather than created directly.
5
5
  */
6
6
  export declare class ClockworkPath {
7
- private readonly path;
7
+ private path;
8
8
  constructor(path: Path);
9
+ /**
10
+ * Frees the underlying WASM path allocation.
11
+ */
12
+ free(): void;
9
13
  /**
10
14
  * Iterate over the path.
11
15
  *
package/package.json CHANGED
@@ -1,14 +1,41 @@
1
1
  {
2
2
  "name": "screeps-clockwork",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "A WASM movement library for Screeps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "scripts": {
8
+ "check": "run-s lint format:check typecheck",
9
+ "lint": "run-s lint:ts lint:rust",
10
+ "lint:ts": "eslint src test \"benches/**/*.ts\" types.d.ts",
11
+ "lint:rust": "cargo clippy --target wasm32-unknown-unknown --all-features -- -D warnings",
12
+ "format": "run-s format:ts format:rust",
13
+ "format:ts": "prettier --write . --ignore-unknown",
14
+ "format:rust": "cargo fmt",
15
+ "format:check": "run-s format:check:ts format:check:rust",
16
+ "format:check:ts": "prettier --check . --ignore-unknown",
17
+ "format:check:rust": "cargo fmt --check",
18
+ "typecheck": "run-s typecheck:ts typecheck:rust",
19
+ "typecheck:ts": "run-s typecheck:ts:src typecheck:ts:test",
20
+ "typecheck:ts:src": "tsc -p tsconfig.src.json --noEmit",
21
+ "typecheck:ts:test": "tsc -p tsconfig.test.json --noEmit",
22
+ "typecheck:rust": "cargo check --target wasm32-unknown-unknown --all-features",
23
+ "check:wasm-types": "run-s check:wasm-types:present check:wasm-types:src check:wasm-types:bench",
24
+ "check:wasm-types:present": "test -f src/wasm/screeps_clockwork.d.ts && test -f src/wasm/screeps_clockwork_bg.wasm.d.ts && test -f benches/wasm/pkg/screeps_clockwork.d.ts && test -f benches/wasm/pkg/screeps_clockwork_bg.wasm.d.ts",
25
+ "check:wasm-types:src": "npm run build:lib && git diff --exit-code -- src/wasm/screeps_clockwork.d.ts src/wasm/screeps_clockwork_bg.wasm.d.ts",
26
+ "check:wasm-types:bench": "npm run bench:wasm:build && git diff --exit-code -- benches/wasm/pkg/screeps_clockwork.d.ts benches/wasm/pkg/screeps_clockwork_bg.wasm.d.ts",
8
27
  "build": "run-s build:lib build:src",
9
- "build:lib": "wasm-pack build --target web --out-dir src/wasm --config build.rustflags=[\\'-Ctarget-feature=-reference-types\\',\\'-Ctarget-feature=-multivalue\\',\\'-Ctarget-feature=-sign-ext\\'] -Z build-std=std,panic_abort",
28
+ "build:lib": "wasm-pack build --target web --out-dir src/wasm --config build.rustflags=[\\'-Ctarget-feature=-reference-types\\',\\'-Ctarget-feature=-multivalue\\',\\'-Ctarget-feature=-sign-ext\\'] -Z build-std=std,panic_abort && printf '*\\n!*.d.ts\\n' > src/wasm/.gitignore",
10
29
  "build:src": "rollup -c",
11
30
  "build:docs": "typedoc",
31
+ "bench:rust": "cargo bench --features bench --bench distance_map",
32
+ "bench:wasm:build": "wasm-pack build --target nodejs --out-dir benches/wasm/pkg --config \"build.rustflags=['-Ctarget-feature=-reference-types','-Ctarget-feature=-multivalue','-Ctarget-feature=-sign-ext']\" -Z build-std=std,panic_abort && printf '*\\n!*.d.ts\\n' > benches/wasm/pkg/.gitignore && cp benches/wasm/pkg/screeps_clockwork.js benches/wasm/pkg/screeps_clockwork.cjs",
33
+ "bench:wasm:run": "node --no-liftoff --no-wasm-lazy-compilation --wasm-wrapper-tiering-budget=0 ./node_modules/vitest/vitest.mjs bench benches/wasm",
34
+ "bench:wasm": "run-s bench:wasm:build bench:wasm:run",
35
+ "bench:wasm:save": "run-s bench:wasm:build bench:wasm:save:run",
36
+ "bench:wasm:save:run": "mkdir -p target/wasm-bench && node --no-liftoff --no-wasm-lazy-compilation --wasm-wrapper-tiering-budget=0 ./node_modules/vitest/vitest.mjs bench benches/wasm --outputJson target/wasm-bench/main.json",
37
+ "bench:wasm:compare": "run-s bench:wasm:build bench:wasm:compare:run",
38
+ "bench:wasm:compare:run": "node --no-liftoff --no-wasm-lazy-compilation --wasm-wrapper-tiering-budget=0 ./node_modules/vitest/vitest.mjs bench benches/wasm --compare target/wasm-bench/main.json",
12
39
  "build:pserver": "run-s build:lib build:src && rollup -c --environment DEST:pserver",
13
40
  "watch": "run-s build watch:both",
14
41
  "watch:lib": "bacon --headless -j build-lib",
@@ -51,7 +78,8 @@
51
78
  "source-map": "0.6.1",
52
79
  "tslib": "^2.8.1",
53
80
  "typedoc": "^0.28.5",
54
- "typescript": "^6.0.3"
81
+ "typescript": "^6.0.3",
82
+ "vitest": "4.1.6"
55
83
  },
56
84
  "dependencies": {
57
85
  "fastestsmallesttextencoderdecoder-encodeinto": "^1.0.22"