@recast-navigation/core 0.18.1 → 0.19.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.
@@ -17,6 +17,19 @@ export type CylinderObstacle = {
17
17
  radius: number;
18
18
  height: number;
19
19
  };
20
+ export type AddObstacleResult<T> = {
21
+ success: true;
22
+ status: number;
23
+ obstacle: T;
24
+ } | {
25
+ success: false;
26
+ status: number;
27
+ obstacle?: T;
28
+ };
29
+ export type RemoveObstacleResult = {
30
+ success: boolean;
31
+ status: number;
32
+ };
20
33
  export type Obstacle = BoxObstacle | CylinderObstacle;
21
34
  export type TileCacheParamsType = {
22
35
  orig: ReadonlyArray<number>;
@@ -37,6 +50,7 @@ export declare class DetourTileCacheParams {
37
50
  static create(config: TileCacheParamsType): DetourTileCacheParams;
38
51
  }
39
52
  export type TileCacheUpdateResult = {
53
+ success: boolean;
40
54
  status: number;
41
55
  upToDate: boolean;
42
56
  };
@@ -51,21 +65,37 @@ export declare class TileCache {
51
65
  init(params: DetourTileCacheParams, alloc: R.RecastLinearAllocator, compressor: R.RecastFastLZCompressor, meshProcess: TileCacheMeshProcess): boolean;
52
66
  /**
53
67
  * Updates the tile cache by rebuilding tiles touched by unfinished obstacle requests.
54
- * This should be called after adding or removing obstacles.
68
+ *
69
+ * After adding or removing obstacles you can call `tileCache.update(navMesh)` to rebuild navmesh tiles.
70
+ *
71
+ * Adding or removing an obstacle will internally create an "obstacle request".
72
+ * TileCache supports queuing up to 64 obstacle requests.
73
+ *
74
+ * The `tileCache.update` method returns `upToDate`, whether the tile cache is fully up to date with obstacle requests and tile rebuilds.
75
+ * Each update call processes up to 64 tiles touched by added or removed obstacles.
76
+ * If the tile cache isn't up to date another call will continue processing obstacle requests and tile rebuilds; otherwise it will have no effect.
77
+ *
78
+ * If not many obstacle requests occur between updates, an easy pattern is to call `tileCache.update` periodically, such as every game update.
79
+ * If many obstacle requests have been made and you need to avoid reaching the 64 obstacle request limit, you can call `tileCache.update` multiple times, bailing out when `upToDate` is true or after a maximum number of updates.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const { success, status, upToDate } = tileCache.update(navMesh);
84
+ * ```
55
85
  */
56
86
  update(navMesh: NavMesh): TileCacheUpdateResult;
57
87
  /**
58
88
  * Creates a cylinder obstacle and adds it to the navigation mesh.
59
89
  */
60
- addCylinderObstacle(position: Vector3, radius: number, height: number): CylinderObstacle;
90
+ addCylinderObstacle(position: Vector3, radius: number, height: number): AddObstacleResult<CylinderObstacle>;
61
91
  /**
62
92
  * Creates a box obstacle and adds it to the navigation mesh.
63
93
  */
64
- addBoxObstacle(position: Vector3, extent: Vector3, angle: number): BoxObstacle;
94
+ addBoxObstacle(position: Vector3, extent: Vector3, angle: number): AddObstacleResult<BoxObstacle>;
65
95
  /**
66
96
  * Removes an obstacle from the navigation mesh.
67
97
  */
68
- removeObstacle(obstacle: Obstacle | ObstacleRef): void;
98
+ removeObstacle(obstacle: Obstacle | ObstacleRef): RemoveObstacleResult;
69
99
  addTile(data: R.UnsignedCharArray, flags?: number): R.TileCacheAddTileResult;
70
100
  buildNavMeshTile(ref: R.dtCompressedTileRef, navMesh: NavMesh): number;
71
101
  buildNavMeshTilesAt(tx: number, ty: number, navMesh: NavMesh): number;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "email": "isaac@isaacmason.com",
7
7
  "url": "https://isaacmason.com/"
8
8
  },
9
- "version": "0.18.1",
9
+ "version": "0.19.0",
10
10
  "license": "MIT",
11
11
  "homepage": "https://github.com/isaac-mason/recast-navigation-js",
12
12
  "bugs": {
@@ -26,7 +26,7 @@
26
26
  "lint": "eslint --ext .ts src"
27
27
  },
28
28
  "dependencies": {
29
- "@recast-navigation/wasm": "0.18.1"
29
+ "@recast-navigation/wasm": "0.19.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@babel/core": "^7.23.9",
@@ -39,7 +39,7 @@
39
39
  "babel-loader": "^9.1.3",
40
40
  "eslint": "^8.56.0",
41
41
  "prettier": "^3.1.0",
42
- "rollup": "^4.9.2",
42
+ "rollup": "^4.14.0",
43
43
  "rollup-plugin-copy": "^3.4.0",
44
44
  "rollup-plugin-filesize": "^10.0.0",
45
45
  "typescript": "^5.4.3"