11## 🧩 Pathfinding Worker
2+
23[ ![ Version] ( https://badgen.net/npm/v/pathfinding-worker )] ( https://npmjs.com/package/pathfinding-worker )
34[ ![ Small size] ( https://img.badgesize.io/neki-dev/pathfinding-worker/main/dist/index.js )] ( https://github.com/neki-dev/pathfinding-worker/blob/main/dist/index.js )
45[ ![ Build] ( https://github.com/neki-dev/pathfinding-worker/actions/workflows/build.yml/badge.svg )] ( https://github.com/neki-dev/pathfinding-worker/actions/workflows/build.yml )
@@ -10,13 +11,13 @@ Fast node.js pathfinding on workers for grid-based games.
1011
1112Documentation
1213
13- * [ Install] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#install )
14- * [ General] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#general )
15- * [ Layers] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#layers )
16- * [ Finding] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#finding )
17- * [ Tile walkable] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#tile-walkable )
18- * [ Tile weight] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#tile-weight )
19- * [ Example] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#example )
14+ - [ Install] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#install )
15+ - [ General] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#general )
16+ - [ Layers] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#layers )
17+ - [ Finding] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#finding )
18+ - [ Tile walkable] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#tile-walkable )
19+ - [ Tile weight] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#tile-weight )
20+ - [ Example] ( https://github.com/neki-dev/pathfinding-worker?tab=readme-ov-file#example )
2021
2122.
2223
@@ -31,131 +32,155 @@ npm i pathfinding-worker
3132## General
3233
3334### ⚡️ Create worker thread
35+
3436``` ts
3537const pathfinding = new Pathfinding (
3638 config : PathfindingConfig
3739)
3840```
39- * ` config ` - _ Pathfinding configuration_
40-
41- | Prop | Description | Default |
42- | ---- | ----------- | ------- |
43- | loopRate | Finding loop rate | 200 ms |
44- | resourceLimits | Worker resource limits | - |
41+
42+ - ` config ` - _ Pathfinding configuration_
43+
44+ | Prop | Description | Default |
45+ | --------------- | ---------------------- | ------- |
46+ | loopRate | Finding next task rate | 100 ms |
47+ | taskProcessRate | Processing task rate | 0 ms |
48+ | resourceLimits | Worker resource limits | - |
4549
4650### ⚡️ Terminate worker thread
51+
4752``` ts
48- pathfinding .destroy ()
53+ pathfinding .destroy ();
4954```
5055
5156.
5257
5358## Layers
5459
5560### ⚡️ Create a new layer of grid
61+
5662``` ts
5763const layer = pathfinding .createLayer (
5864 grid : PathfindingGrid ,
5965)
6066```
61- * ` grid ` - _ Grid with walkable tiles_
67+
68+ - ` grid ` - _ Grid with walkable tiles_
6269
6370### ⚡️ Get list of created layers
71+
6472``` ts
65- pathfinding .getLayers ()
73+ pathfinding .getLayers ();
6674```
6775
6876### ⚡️ Get layer by id
77+
6978``` ts
7079pathfinding .getLayer (
7180 id : string
7281)
7382```
74- * ` id ` - _ Layer id_
83+
84+ - ` id ` - _ Layer id_
7585
7686### ⚡️ Remove exist layer of grid
87+
7788``` ts
78- layer .remove ()
89+ layer .remove ();
7990```
8091
8192.
8293
8394## Finding
8495
8596### ⚡️ Create pathfinder task
97+
8698``` ts
8799const idTask = layer .findPath (
88100 config : PathfindingTaskConfig ,
89101 callback : PathfindingTaskCallback ,
90102)
91103```
92- * ` config ` - _ Task configuration_
93-
94- | Prop | Description | Default |
95- | ---- | ----------- | ------- |
96- | from | Begin tile position | |
97- | to | End tile position | |
98- | diagonals | Allow diagonal directions | true |
99104
100- * ` callback ` - _ Callback with result_
105+ - ` config ` - _ Task configuration_
106+
107+ | Prop | Description | Default |
108+ | --------- | ------------------------- | ------- |
109+ | from | Begin tile position | |
110+ | to | End tile position | |
111+ | diagonals | Allow diagonal directions | true |
112+
113+ - ` callback ` - _ Callback with result_
101114
102115### ⚡️ Cancel pathfinder task
116+
103117``` ts
104118layer .cancel (id : number )
105119```
106- * ` id ` - _ Task id_
120+
121+ - ` id ` - _ Task id_
107122
108123.
109124
110125## Tile walkable
111126
112127### ⚡️ Set walkable state
128+
113129``` ts
114130layer .setWalkable (
115131 position : PathfindingPosition ,
116132 value : number ,
117133)
118134```
119- * ` position ` - _ Tile position_
120- * ` state ` - _ Walkable state_
135+
136+ - ` position ` - _ Tile position_
137+ - ` state ` - _ Walkable state_
121138
122139### ⚡️ Get walkable state
140+
123141``` ts
124142const walkable = pathfinder .isWalkable (
125143 position : PathfindingPosition ,
126144)
127145```
128- * ` position ` - _ Tile position_
146+
147+ - ` position ` - _ Tile position_
129148
130149.
131150
132151## Tile weight
133152
134153### ⚡️ Set weight
154+
135155``` ts
136156layer .setWeight (
137157 position : PathfindingPosition ,
138158 value : number ,
139159)
140160```
141- * ` position ` - _ Tile position_
142- * ` value ` - _ New weight_
161+
162+ - ` position ` - _ Tile position_
163+ - ` value ` - _ New weight_
143164
144165### ⚡️ Reset weight
166+
145167``` ts
146168layer .resetWeight (
147169 position : PathfindingPosition ,
148170)
149171```
150- * ` position ` - _ Tile position_
172+
173+ - ` position ` - _ Tile position_
151174
152175### ⚡️ Get weight
176+
153177``` ts
154178const weight = layer .getWeight (
155179 position : PathfindingPosition ,
156180)
157181```
158- * ` position ` - _ Tile position_
182+
183+ - ` position ` - _ Tile position_
159184
160185.
161186
@@ -167,17 +192,20 @@ const pathfinding = new Pathfinding({
167192});
168193
169194const layer = pathfinding .createLayer ([
170- [true , true , true , true ],
171- [true , true , false , true ],
195+ [true , true , true , true ],
196+ [true , true , false , true ],
172197 [true , false , false , true ],
173198 [true , false , false , false ],
174199]);
175200
176- layer .findPath ({
177- from: { x: 0 , y: 0 },
178- to: { x: 3 , y: 2 },
179- }, ({ path , cost }) => {
180- console .log (' Result path:' , path );
181- console .log (' Total cost:' , cost );
182- })
201+ layer .findPath (
202+ {
203+ from: { x: 0 , y: 0 },
204+ to: { x: 3 , y: 2 },
205+ },
206+ ({ path , cost }) => {
207+ console .log (" Result path:" , path );
208+ console .log (" Total cost:" , cost );
209+ }
210+ );
183211```
0 commit comments