@pocketrts/grid 0.0.0-stage → 0.2.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/vision.js ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Field of view on a cell raster: each viewer reveals a disc of cells. A per-cell record of the largest radius already
3
+ * stamped there lets many viewers standing in the same cell cost one stamp.
4
+ */
5
+ /**
6
+ * Mark the disc of radius `r` cells around cell (cx, cy) in `vis` (set to 1), clipped to the `w` × `h` raster.
7
+ * Row dy spans ⌊√(r² + r − dy²)⌋ cells to each side, a slightly fuller disc than r² would give. `stamped` holds, per
8
+ * cell, the largest radius stamped from it since it was last cleared; a disc no larger than that is skipped. Clear
9
+ * `vis` and `stamped` together (fill with 0) before each recomputation.
10
+ */
11
+ export function stampDisc(vis, stamped, w, h, cx, cy, r) {
12
+ const c = cy * w + cx;
13
+ if (stamped[c] >= r)
14
+ return;
15
+ stamped[c] = r;
16
+ for (let dy = -r; dy <= r; dy++) {
17
+ const yy = cy + dy;
18
+ if (yy < 0 || yy >= h)
19
+ continue;
20
+ const span = Math.floor(Math.sqrt(r * r + r - dy * dy));
21
+ let xa = cx - span, xb = cx + span;
22
+ if (xa < 0)
23
+ xa = 0;
24
+ if (xb >= w)
25
+ xb = w - 1;
26
+ const row = yy * w;
27
+ for (let xx = xa; xx <= xb; xx++)
28
+ vis[row + xx] = 1;
29
+ }
30
+ }
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@pocketrts/grid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Grid algorithms for RTS games: budgeted flow fields, bounded local A*, line reach, distance fields, bucket grids, field of view, polygons, cell chains, line formations and column march",
5
+ "license": "MIT",
6
+ "author": "Junjie Bai <bjj19851010@gmail.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/baijunjie/pocketrts.git",
10
+ "directory": "packages/grid"
11
+ },
12
+ "keywords": [
13
+ "pathfinding",
14
+ "flow-field",
15
+ "astar",
16
+ "spatial-hash",
17
+ "formation",
18
+ "rts",
19
+ "game"
20
+ ],
21
+ "type": "module",
22
+ "sideEffects": false,
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "@pocketrts/source": "./src/index.ts",
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "LICENSE"
36
+ ],
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "dependencies": {
41
+ "@pocketrts/determinism": "^0.1.0"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc -p tsconfig.build.json",
45
+ "typecheck": "tsc -p tsconfig.json --noEmit",
46
+ "test": "vitest run --maxWorkers=2"
47
+ }
6
48
  }