@codexo/exojs-tilemap-physics 0.19.1 → 0.20.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/README.md CHANGED
@@ -1,127 +1,13 @@
1
1
  # @codexo/exojs-tilemap-physics
2
2
 
3
- Static physics colliders from ExoJS tilemap collision geometry.
3
+ Since ExoJS v0.20, import from @codexo/exojs/tilemap-physics. This package is a compatibility shim for the 0.20 line; no independent feature development.
4
4
 
5
- > A peer-dependency library on top of `@codexo/exojs`, `@codexo/exojs-tilemap` and `@codexo/exojs-physics` — construct its API directly. Importing it registers nothing.
5
+ Every export of this package is the very binding its Core entry exports, so code that still imports `@codexo/exojs-tilemap-physics` shares one engine instance with code that already imports `@codexo/exojs/tilemap-physics`. The package contains no implementation of its own and depends on nothing but its `@codexo/exojs` peer.
6
6
 
7
- `@codexo/exojs-tilemap` never imports physics and `@codexo/exojs-physics` never imports tilemap; this package is the seam between them, so both stay usable on their own.
7
+ | Import | Replace with | Forwards |
8
+ | --- | --- | --- |
9
+ | `@codexo/exojs-tilemap-physics` | `@codexo/exojs/tilemap-physics` | everything |
8
10
 
9
- ## Installation
11
+ ## Migrating
10
12
 
11
- ```sh
12
- npm install @codexo/exojs @codexo/exojs-tilemap @codexo/exojs-physics @codexo/exojs-tilemap-physics
13
- ```
14
-
15
- ## Tile layers
16
-
17
- `TileColliderStreamer` keeps a physics world's static tile colliders in sync with a `TileLayer`: one static body per chunk-sized partition of the layer, rebuilt when that partition is edited, destroyed when its chunk is evicted.
18
-
19
- ```ts
20
- import { PhysicsWorld } from '@codexo/exojs-physics';
21
- import { TileColliderStreamer } from '@codexo/exojs-tilemap-physics';
22
-
23
- const world = new PhysicsWorld({ gravity: { x: 0, y: 1600 } });
24
- const colliders = new TileColliderStreamer(world, groundLayer);
25
-
26
- scene.systems.add({
27
- update: delta => {
28
- colliders.sync();
29
- world.step(delta);
30
- },
31
- });
32
- ```
33
-
34
- `sync()` is cheap to call every frame: with no change since the last call it returns immediately and does no work. It observes the layer through its public revision counters, so it works with `ChunkStreamer`, a hand-rolled loader, or a bounded layer that is fully resident.
35
-
36
- Call `destroy()` to remove every body the bridge created. Bodies it did not create are untouched.
37
-
38
- ## Collision authored per cell
39
-
40
- Some editors author collision per grid cell rather than per tile - LDtk's `IntGrid` is the common case. Pass a `cells` source and the bridge covers the whole bounded layer, including partitions that hold no tiles at all:
41
-
42
- ```ts
43
- import { createLdtkIntGridCellSource } from '@codexo/exojs-ldtk';
44
-
45
- const colliders = new TileColliderStreamer(world, collisionLayer, {
46
- cells: createLdtkIntGridCellSource(collisionLayer),
47
- material: ({ type }) => (type === 'Water' ? { isSensor: true } : null),
48
- });
49
- ```
50
-
51
- A cell source is a plain `(tx, ty) => string | null`, so a procedural or hand-rolled grid works the same way. The returned string is a classification, never a meaning: it is the merge key for adjacent cells and it is what the `material` resolver sees. Nothing in this package knows what `Solid` or `Water` are supposed to do.
52
-
53
- The source is sampled while a partition is built and is expected to answer identically for the lifetime of the bridge. Changing what it returns does not invalidate colliders that already exist - rebuild by recreating the bridge.
54
-
55
- ## Object layers
56
-
57
- An object layer is static data with no residency, so it gets a one-shot build:
58
-
59
- ```ts
60
- import { buildObjectLayerColliders } from '@codexo/exojs-tilemap-physics';
61
-
62
- const built = buildObjectLayerColliders(world, triggersLayer, {
63
- isSensor: true,
64
- });
65
-
66
- for (const { object, body } of built) {
67
- // `object` is the source object: name, type, custom properties.
68
- }
69
- ```
70
-
71
- ## Isometric presentation
72
-
73
- Tile and object colliders use logical coordinates. Isometric logical cells are squares of side `tileHeight`; image-space tile collision shapes are inverse-projected before collider generation. Display layer offsets become logical translation vectors, and streamed collider bodies retain the same cell/chunk ownership rules. Orthogonal behavior is unchanged.
74
-
75
- Create a `TilePhysicsBinding(body, node, map.projection)` explicitly and call `sync()` after physics updates, or `syncInterpolated(alpha)` with the fixed-step interpolation fraction. The node's parent must use map display coordinates. The binding only writes node position, owns nothing, and leaves sprite rotation/scale to the application; a projected logical rotation is not a rigid sprite rotation. Do not attach the same node through `PhysicsWorld.attach()`, which binds directly to unprojected world coordinates.
76
-
77
- Object-layer `objects` remain logical geometry; `getDisplayObject()` is for rendering and must not be fed back into the collider builder. The Isometric Landscape example shows both representations.
78
-
79
- ## Geometry mapping
80
-
81
- | Source | Collider |
82
- | -------------------------------------------------- | ---------------------------------------------------- |
83
- | Merged whole-cell region (`regionMode: 'boxes'`) | one box per merged rectangle |
84
- | Merged whole-cell region (`regionMode: 'outline'`) | one closed chain per boundary loop |
85
- | Rectangle | box |
86
- | Ellipse | capsule along the major axis, or a circle when round |
87
- | Convex polygon | one polygon |
88
- | Concave polygon | several convex polygons on the same body |
89
- | Polyline | open chain; closed chain when its endpoints coincide |
90
- | Point | nothing |
91
-
92
- An ellipse maps to the capsule with the minor semi-axis as its radius and the difference of the semi-axes as its spine. That capsule contains the ellipse and is contained in the circumscribed circle, so it covers the source without a tuning constant, and degenerates to a circle when the ellipse is round.
93
-
94
- ## Region modes
95
-
96
- `regionMode: 'boxes'` (the default) keeps merged rectangles as solid boxes. The region has an interior, so point queries, overlaps and sensors behave, and a body that starts inside solid tiles is pushed out. Where the merge cannot merge — neighbouring cells with different collision semantics, staircase profiles, partial cells — adjacent boxes share an internal edge that a body sliding across can catch on.
97
-
98
- `regionMode: 'outline'` traces the boundary of each solid region into closed one-sided chains, which have no internal edges at all. It removes intra-chunk seams between adjacent cells that resolve to the same collision semantics; boundaries between regions with different resolved semantics remain separate, as do chunk boundaries. The trade-off is that a chain is a boundary, not an area: queries inside the region find nothing, and a body spawned inside it falls through.
99
-
100
- ## Materials
101
-
102
- Friction, restitution, density, the sensor flag and the collision filter are call-level defaults, optionally overridden per object:
103
-
104
- ```ts
105
- new TileColliderStreamer(world, groundLayer, {
106
- friction: 0.8,
107
- material: ({ type }) => (type === 'ice' ? { friction: 0.02 } : null),
108
- });
109
- ```
110
-
111
- The resolver is a build-time mapping, not a live rule: it runs only while a chunk is being built or rebuilt. Changing what it would return has no effect until the layer itself changes. An unrecognised `type` is not an error — it reaches the resolver like any other and falls back to the defaults.
112
-
113
- In `outline` mode the resolved material also decides what may share a boundary: cells whose colliders would be indistinguishable are traced into one chain, and cells that resolve differently keep their own.
114
-
115
- ## Things to know before shipping a level
116
-
117
- - **Merging never crosses a chunk boundary.** A solid run spanning two chunks is at least two rectangles. That is what makes the result independent of the order chunks were loaded in.
118
- - **A dynamic body resting on an evicted chunk falls.** Eviction is the chunk source's decision; widen its unload radius if that matters.
119
- - **Order is stable, part counts are not.** For a given layer and resident chunk set the colliders are identical regardless of load order, and `bodies()` iterates in `(cy, cx)` chunk order. The number of convex parts a concave polygon decomposes into, and the exact rectangle decomposition of a merged region, are not contractual.
120
-
121
- ## Core compatibility
122
-
123
- This package follows the Core lockstep release line. Its Core, tilemap, and physics peer dependencies require the matching minor release.
124
-
125
- ## License
126
-
127
- MIT © Codexo
13
+ Change each import to the Core entry in the table, then remove this package with `npm uninstall @codexo/exojs-tilemap-physics`. `@codexo/exojs` already contains the module; there is nothing else to install. The migration guide on the ExoJS site lists every renamed import.
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@codexo/exojs/tilemap-physics';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@codexo/exojs/tilemap-physics';
package/package.json CHANGED
@@ -1,52 +1,38 @@
1
1
  {
2
2
  "name": "@codexo/exojs-tilemap-physics",
3
- "version": "0.19.1",
4
- "description": "Static physics colliders from ExoJS tilemap collision geometry.",
3
+ "version": "0.20.0",
4
+ "description": "Compatibility shim that forwards to @codexo/exojs/tilemap-physics. Since ExoJS v0.20, import from @codexo/exojs/tilemap-physics.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/Exoridus/ExoJS.git",
8
- "directory": "packages/exojs-tilemap-physics"
8
+ "directory": "packages/legacy/exojs-tilemap-physics"
9
9
  },
10
10
  "type": "module",
11
11
  "sideEffects": false,
12
- "main": "./dist/esm/index.js",
13
- "module": "./dist/esm/index.js",
14
- "types": "./dist/esm/index.d.ts",
12
+ "main": "./index.js",
13
+ "types": "./index.d.ts",
15
14
  "exports": {
16
15
  ".": {
17
- "types": "./dist/esm/index.d.ts",
18
- "import": "./dist/esm/index.js",
19
- "default": "./dist/esm/index.js"
16
+ "types": "./index.d.ts",
17
+ "import": "./index.js",
18
+ "default": "./index.js"
20
19
  },
21
20
  "./package.json": "./package.json"
22
21
  },
23
22
  "files": [
24
- "dist/esm/",
23
+ "index.js",
24
+ "index.d.ts",
25
25
  "README.md",
26
26
  "LICENSE"
27
27
  ],
28
28
  "peerDependencies": {
29
- "@codexo/exojs": "0.19.x",
30
- "@codexo/exojs-physics": "0.19.x",
31
- "@codexo/exojs-tilemap": "0.19.x"
29
+ "@codexo/exojs": "0.20.x"
32
30
  },
33
31
  "devDependencies": {
34
- "@codexo/exojs": "0.19.1",
35
- "@codexo/exojs-physics": "0.19.1",
36
- "@codexo/exojs-ldtk": "0.19.1",
37
- "@codexo/exojs-tiled": "0.19.1",
38
- "@codexo/exojs-config": "0.0.0",
39
- "@codexo/exojs-tilemap": "0.19.1"
32
+ "@codexo/exojs": "0.20.0"
40
33
  },
41
34
  "license": "MIT",
42
35
  "publishConfig": {
43
36
  "access": "public"
44
- },
45
- "scripts": {
46
- "build": "tsx ../../scripts/build-extension.ts",
47
- "build:dev": "tsx ../../scripts/build-extension.ts --dev",
48
- "typecheck": "exo-tsc --noEmit && exo-tsc --noEmit -p tsconfig.test.json",
49
- "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
50
- "test": "vitest run --root ../.. --project=exojs-tilemap-physics"
51
37
  }
52
38
  }
@@ -1,108 +0,0 @@
1
- import { PhysicsBody, type PhysicsWorld } from '@codexo/exojs-physics';
2
- import type { TileCellSource, TileLayer, TileMapObject } from '@codexo/exojs-tilemap';
3
- import type { ColliderDefaults, TileRegionMode } from './types';
4
- /** Options for a {@link TileColliderStreamer}. All optional. */
5
- export interface TileColliderOptions extends ColliderDefaults {
6
- /** How solid whole-cell regions are represented. Default `'boxes'`. */
7
- regionMode?: TileRegionMode;
8
- /**
9
- * Merge adjacent whole-cell boxes sharing a `type` into larger rectangles.
10
- * Default `true`. Merging never crosses a chunk boundary.
11
- */
12
- merge?: boolean;
13
- /** Drop a source shape before any collider is built for it. */
14
- accept?: (object: TileMapObject, tx: number, ty: number) => boolean;
15
- /**
16
- * Per-cell collision classification, for layers whose collision is authored
17
- * per cell rather than per tile. On a bounded layer this makes the bridge
18
- * cover the whole layer, including partitions that hold no tiles at all.
19
- *
20
- * Sampled while a partition is built and expected to answer identically for
21
- * the lifetime of this bridge: changing what it returns does not invalidate
22
- * colliders that already exist. Rebuild by recreating the bridge.
23
- */
24
- cells?: TileCellSource | undefined;
25
- }
26
- /**
27
- * Keeps a physics world's static tile colliders in sync with a
28
- * {@link TileLayer}: one static body per chunk-sized partition of the layer,
29
- * rebuilt when that partition changes, destroyed when it is evicted.
30
- *
31
- * The bridge owns every body it creates and nothing else. It observes the layer
32
- * through its public revision counters, so it works with any chunk source -
33
- * {@link import('@codexo/exojs-tilemap').ChunkStreamer}, a hand-rolled loader,
34
- * or a fully resident bounded layer.
35
- *
36
- * Tick it from `preFrame`, before the frame's fixed steps run - not from
37
- * `update`, which runs after them:
38
- *
39
- * ```ts
40
- * const colliders = new TileColliderStreamer(world, layer);
41
- * scene.systems.add({ preFrame: () => colliders.sync() });
42
- * ```
43
- *
44
- * `SceneScope` runs `preFrame` once per frame, before any of that frame's
45
- * fixed steps, and `update` after all of them. A chunk that becomes resident
46
- * this frame needs its collider body built before the world steps over the
47
- * hole, and a chunk evicted this frame must not keep its body for a whole
48
- * extra frame of stepping - `update` gets both of those one step too late.
49
- * Wiring `sync()` into `fixedUpdate` instead (ordered before
50
- * {@link SystemOrder.Physics}) also works, and additionally re-syncs on
51
- * every fixed step within a frame rather than once per frame.
52
- *
53
- * Two consequences worth knowing before shipping a level:
54
- *
55
- * - Whole-cell merging never crosses a partition boundary, so a solid run
56
- * spanning two of them is at least two rectangles. This is what makes the
57
- * result independent of the order chunks were loaded in.
58
- * - A dynamic body resting on a chunk that gets evicted falls. Eviction is the
59
- * chunk source's decision; widen its unload radius if that matters.
60
- * - With {@link TileColliderOptions.cells}, a bounded layer's partitions are
61
- * all covered, resident or not - collision authored per cell does not depend
62
- * on tiles being placed.
63
- */
64
- export declare class TileColliderStreamer {
65
- private readonly _world;
66
- private readonly _layer;
67
- private readonly _options;
68
- private readonly _defaults;
69
- private readonly _regionMode;
70
- private readonly _built;
71
- private readonly _seen;
72
- private _layerRevision;
73
- private _offsetX;
74
- private _offsetY;
75
- private _destroyed;
76
- constructor(world: PhysicsWorld, layer: TileLayer, options?: TileColliderOptions);
77
- /** Number of bodies currently owned by this bridge. */
78
- get bodyCount(): number;
79
- /**
80
- * The bodies this bridge owns, in `(cy, cx)` partition order - independent of
81
- * the order the chunks became resident in.
82
- */
83
- bodies(): IterableIterator<PhysicsBody>;
84
- /**
85
- * Bring the world's tile colliders up to date with the layer: build bodies
86
- * for newly resident chunks, rebuild edited ones, destroy evicted ones.
87
- *
88
- * Cheap to call every frame. With no change since the last call it performs
89
- * no work and allocates nothing. No-op once {@link destroy}ed or once the
90
- * layer is destroyed.
91
- */
92
- sync(): void;
93
- /**
94
- * Destroy every body this bridge created and stop responding to
95
- * {@link sync}. Bodies it did not create are untouched. Idempotent.
96
- */
97
- destroy(): void;
98
- private _clear;
99
- /**
100
- * Reconcile one build block against what was built for it before. Skips
101
- * without sampling anything when neither the backing chunk nor its revision
102
- * moved - which is what keeps an empty cell-only block from re-walking its
103
- * cells on every unrelated layer change.
104
- */
105
- private _syncBlock;
106
- private _buildBlock;
107
- }
108
- //# sourceMappingURL=TileColliderStreamer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TileColliderStreamer.d.ts","sourceRoot":"","sources":["../../src/TileColliderStreamer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CA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AAC,CAM9C;IAED;;;;;;;OAOG;IACI,IAAI,IAAI,IAAI,CAgDlB;IAED;;;OAGG;IACI,OAAO,IAAI,IAAI,CAIrB;IAED,OAAO,CAAC,MAAM;IASd;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAqBlB,OAAO,CAAC,WAAW;CAuCpB"}
@@ -1,202 +0,0 @@
1
- import { resolveDefaults } from "./material.js";
2
- import { buildTileColliders } from "./buildColliders.js";
3
- import { PhysicsBody } from "@codexo/exojs-physics";
4
- import { buildTileCollisionGeometry } from "@codexo/exojs-tilemap";
5
-
6
- //#region src/TileColliderStreamer.ts
7
- const chunkKey = (cx, cy) => `${cx},${cy}`;
8
- /**
9
- * Tile extent of a build block along one axis. Edge blocks of a bounded layer
10
- * are clipped, matching the dimensions the layer gives an edge chunk, so a
11
- * cell-only block never walks cells outside the layer.
12
- */
13
- const blockExtent = (chunkExtent, layerExtent, start) => layerExtent === void 0 ? chunkExtent : Math.min(chunkExtent, layerExtent - start);
14
- /**
15
- * Keeps a physics world's static tile colliders in sync with a
16
- * {@link TileLayer}: one static body per chunk-sized partition of the layer,
17
- * rebuilt when that partition changes, destroyed when it is evicted.
18
- *
19
- * The bridge owns every body it creates and nothing else. It observes the layer
20
- * through its public revision counters, so it works with any chunk source -
21
- * {@link import('@codexo/exojs-tilemap').ChunkStreamer}, a hand-rolled loader,
22
- * or a fully resident bounded layer.
23
- *
24
- * Tick it from `preFrame`, before the frame's fixed steps run - not from
25
- * `update`, which runs after them:
26
- *
27
- * ```ts
28
- * const colliders = new TileColliderStreamer(world, layer);
29
- * scene.systems.add({ preFrame: () => colliders.sync() });
30
- * ```
31
- *
32
- * `SceneScope` runs `preFrame` once per frame, before any of that frame's
33
- * fixed steps, and `update` after all of them. A chunk that becomes resident
34
- * this frame needs its collider body built before the world steps over the
35
- * hole, and a chunk evicted this frame must not keep its body for a whole
36
- * extra frame of stepping - `update` gets both of those one step too late.
37
- * Wiring `sync()` into `fixedUpdate` instead (ordered before
38
- * {@link SystemOrder.Physics}) also works, and additionally re-syncs on
39
- * every fixed step within a frame rather than once per frame.
40
- *
41
- * Two consequences worth knowing before shipping a level:
42
- *
43
- * - Whole-cell merging never crosses a partition boundary, so a solid run
44
- * spanning two of them is at least two rectangles. This is what makes the
45
- * result independent of the order chunks were loaded in.
46
- * - A dynamic body resting on a chunk that gets evicted falls. Eviction is the
47
- * chunk source's decision; widen its unload radius if that matters.
48
- * - With {@link TileColliderOptions.cells}, a bounded layer's partitions are
49
- * all covered, resident or not - collision authored per cell does not depend
50
- * on tiles being placed.
51
- */
52
- var TileColliderStreamer = class {
53
- _world;
54
- _layer;
55
- _options;
56
- _defaults;
57
- _regionMode;
58
- _built = /* @__PURE__ */ new Map();
59
- _seen = /* @__PURE__ */ new Set();
60
- _layerRevision = -1;
61
- _offsetX;
62
- _offsetY;
63
- _destroyed = false;
64
- constructor(world, layer, options = {}) {
65
- this._world = world;
66
- this._layer = layer;
67
- this._options = options;
68
- this._defaults = resolveDefaults(options);
69
- this._regionMode = options.regionMode ?? "boxes";
70
- this._offsetX = layer.offsetX;
71
- this._offsetY = layer.offsetY;
72
- }
73
- /** Number of bodies currently owned by this bridge. */
74
- get bodyCount() {
75
- let count = 0;
76
- for (const entry of this._built.values()) if (entry.body !== null) count++;
77
- return count;
78
- }
79
- /**
80
- * The bodies this bridge owns, in `(cy, cx)` partition order - independent of
81
- * the order the chunks became resident in.
82
- */
83
- *bodies() {
84
- const ordered = [...this._built.values()].sort((a, b) => a.cy - b.cy || a.cx - b.cx);
85
- for (const entry of ordered) if (entry.body !== null) yield entry.body;
86
- }
87
- /**
88
- * Bring the world's tile colliders up to date with the layer: build bodies
89
- * for newly resident chunks, rebuild edited ones, destroy evicted ones.
90
- *
91
- * Cheap to call every frame. With no change since the last call it performs
92
- * no work and allocates nothing. No-op once {@link destroy}ed or once the
93
- * layer is destroyed.
94
- */
95
- sync() {
96
- if (this._destroyed || this._layer.destroyed) return;
97
- const layer = this._layer;
98
- const offsetChanged = layer.offsetX !== this._offsetX || layer.offsetY !== this._offsetY;
99
- if (!offsetChanged && layer.revision === this._layerRevision) return;
100
- if (offsetChanged) {
101
- this._clear();
102
- this._offsetX = layer.offsetX;
103
- this._offsetY = layer.offsetY;
104
- }
105
- const seen = this._seen;
106
- seen.clear();
107
- for (const chunk of layer.loadedChunks()) this._syncBlock(chunk.cx, chunk.cy, chunk);
108
- if (this._options.cells !== void 0) {
109
- const range = layer.chunkRange();
110
- if (range !== null) for (let cy = range.minCy; cy <= range.maxCy; cy++) for (let cx = range.minCx; cx <= range.maxCx; cx++) this._syncBlock(cx, cy, layer.getChunk(cx, cy) ?? null);
111
- }
112
- for (const [key, entry] of this._built) {
113
- if (seen.has(key)) continue;
114
- if (entry.body !== null) this._world.destroyBody(entry.body);
115
- this._built.delete(key);
116
- }
117
- this._layerRevision = layer.revision;
118
- }
119
- /**
120
- * Destroy every body this bridge created and stop responding to
121
- * {@link sync}. Bodies it did not create are untouched. Idempotent.
122
- */
123
- destroy() {
124
- if (this._destroyed) return;
125
- this._destroyed = true;
126
- this._clear();
127
- }
128
- _clear() {
129
- for (const entry of this._built.values()) if (entry.body !== null) this._world.destroyBody(entry.body);
130
- this._built.clear();
131
- this._layerRevision = -1;
132
- }
133
- /**
134
- * Reconcile one build block against what was built for it before. Skips
135
- * without sampling anything when neither the backing chunk nor its revision
136
- * moved - which is what keeps an empty cell-only block from re-walking its
137
- * cells on every unrelated layer change.
138
- */
139
- _syncBlock(cx, cy, chunk) {
140
- const key = chunkKey(cx, cy);
141
- if (this._seen.has(key)) return;
142
- this._seen.add(key);
143
- const entry = this._built.get(key);
144
- const revision = chunk?.revision ?? -1;
145
- if (entry?.chunk === chunk && entry.revision === revision) return;
146
- if (entry?.body != null) this._world.destroyBody(entry.body);
147
- this._built.set(key, {
148
- cx,
149
- cy,
150
- chunk,
151
- revision,
152
- body: this._buildBlock(cx, cy, chunk)
153
- });
154
- }
155
- _buildBlock(cx, cy, chunk) {
156
- const layer = this._layer;
157
- const options = this._options;
158
- const startTx = cx * layer.chunkWidth;
159
- const startTy = cy * layer.chunkHeight;
160
- const width = chunk?.width ?? blockExtent(layer.chunkWidth, layer.width, startTx);
161
- const height = chunk?.height ?? blockExtent(layer.chunkHeight, layer.height, startTy);
162
- const geometry = buildTileCollisionGeometry(layer, {
163
- region: {
164
- x: startTx,
165
- y: startTy,
166
- width,
167
- height
168
- },
169
- ...options.merge !== void 0 && { merge: options.merge },
170
- ...options.accept !== void 0 && { accept: options.accept },
171
- ...options.cells !== void 0 && { cells: options.cells }
172
- });
173
- if (geometry.rects.length === 0 && geometry.shapes.length === 0) return null;
174
- const offset = layer.logicalOffset;
175
- const x = startTx * layer.projection.logicalTileWidth + offset.x;
176
- const y = startTy * layer.projection.logicalTileHeight + offset.y;
177
- const colliders = buildTileColliders(geometry, {
178
- x,
179
- y,
180
- tileWidth: layer.projection.logicalTileWidth,
181
- tileHeight: layer.projection.logicalTileHeight,
182
- layerOffsetX: offset.x,
183
- layerOffsetY: offset.y,
184
- regionMode: this._regionMode,
185
- defaults: this._defaults,
186
- material: options.material
187
- });
188
- if (colliders.length === 0) return null;
189
- return this._world.add(new PhysicsBody({
190
- type: "static",
191
- position: {
192
- x,
193
- y
194
- },
195
- colliders
196
- }));
197
- }
198
- };
199
-
200
- //#endregion
201
- export { TileColliderStreamer };
202
- //# sourceMappingURL=TileColliderStreamer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TileColliderStreamer.js","names":[],"sources":["../../src/TileColliderStreamer.ts"],"sourcesContent":["import { PhysicsBody, type PhysicsWorld } from '@codexo/exojs-physics';\nimport type { ReadonlyTileChunk, TileCellSource, TileLayer, TileMapObject } from '@codexo/exojs-tilemap';\nimport { buildTileCollisionGeometry } from '@codexo/exojs-tilemap';\n\nimport { buildTileColliders } from './buildColliders';\nimport { resolveDefaults, type ResolvedMaterial } from './material';\nimport type { ColliderDefaults, TileRegionMode } from './types';\n\n/** Options for a {@link TileColliderStreamer}. All optional. */\nexport interface TileColliderOptions extends ColliderDefaults {\n /** How solid whole-cell regions are represented. Default `'boxes'`. */\n regionMode?: TileRegionMode;\n /**\n * Merge adjacent whole-cell boxes sharing a `type` into larger rectangles.\n * Default `true`. Merging never crosses a chunk boundary.\n */\n merge?: boolean;\n /** Drop a source shape before any collider is built for it. */\n accept?: (object: TileMapObject, tx: number, ty: number) => boolean;\n /**\n * Per-cell collision classification, for layers whose collision is authored\n * per cell rather than per tile. On a bounded layer this makes the bridge\n * cover the whole layer, including partitions that hold no tiles at all.\n *\n * Sampled while a partition is built and expected to answer identically for\n * the lifetime of this bridge: changing what it returns does not invalidate\n * colliders that already exist. Rebuild by recreating the bridge.\n */\n cells?: TileCellSource | undefined;\n}\n\n/**\n * One collision build block: the deterministic spatial partition this bridge\n * may own a body for. A partition is not the same thing as tile residency - a\n * cell source covers partitions that hold no {@link ReadonlyTileChunk} at all,\n * and nothing here makes a non-resident chunk look resident.\n *\n * An entry with `body === null` is a cached empty result, not an absence: it\n * is what keeps an unrelated layer revision from re-walking every cell of\n * every empty partition.\n */\ninterface BlockEntry {\n readonly cx: number;\n readonly cy: number;\n /** The chunk the body was built from; `null` for a cell-only partition. A re-adopted chunk is a new one. */\n readonly chunk: ReadonlyTileChunk | null;\n readonly revision: number;\n /** `null` when the partition holds no collision geometry at all. */\n readonly body: PhysicsBody | null;\n}\n\nconst chunkKey = (cx: number, cy: number): string => `${cx},${cy}`;\n\n/**\n * Tile extent of a build block along one axis. Edge blocks of a bounded layer\n * are clipped, matching the dimensions the layer gives an edge chunk, so a\n * cell-only block never walks cells outside the layer.\n */\nconst blockExtent = (chunkExtent: number, layerExtent: number | undefined, start: number): number =>\n layerExtent === undefined ? chunkExtent : Math.min(chunkExtent, layerExtent - start);\n\n/**\n * Keeps a physics world's static tile colliders in sync with a\n * {@link TileLayer}: one static body per chunk-sized partition of the layer,\n * rebuilt when that partition changes, destroyed when it is evicted.\n *\n * The bridge owns every body it creates and nothing else. It observes the layer\n * through its public revision counters, so it works with any chunk source -\n * {@link import('@codexo/exojs-tilemap').ChunkStreamer}, a hand-rolled loader,\n * or a fully resident bounded layer.\n *\n * Tick it from `preFrame`, before the frame's fixed steps run - not from\n * `update`, which runs after them:\n *\n * ```ts\n * const colliders = new TileColliderStreamer(world, layer);\n * scene.systems.add({ preFrame: () => colliders.sync() });\n * ```\n *\n * `SceneScope` runs `preFrame` once per frame, before any of that frame's\n * fixed steps, and `update` after all of them. A chunk that becomes resident\n * this frame needs its collider body built before the world steps over the\n * hole, and a chunk evicted this frame must not keep its body for a whole\n * extra frame of stepping - `update` gets both of those one step too late.\n * Wiring `sync()` into `fixedUpdate` instead (ordered before\n * {@link SystemOrder.Physics}) also works, and additionally re-syncs on\n * every fixed step within a frame rather than once per frame.\n *\n * Two consequences worth knowing before shipping a level:\n *\n * - Whole-cell merging never crosses a partition boundary, so a solid run\n * spanning two of them is at least two rectangles. This is what makes the\n * result independent of the order chunks were loaded in.\n * - A dynamic body resting on a chunk that gets evicted falls. Eviction is the\n * chunk source's decision; widen its unload radius if that matters.\n * - With {@link TileColliderOptions.cells}, a bounded layer's partitions are\n * all covered, resident or not - collision authored per cell does not depend\n * on tiles being placed.\n */\nexport class TileColliderStreamer {\n private readonly _world: PhysicsWorld;\n private readonly _layer: TileLayer;\n private readonly _options: TileColliderOptions;\n private readonly _defaults: ResolvedMaterial;\n private readonly _regionMode: TileRegionMode;\n\n private readonly _built = new Map<string, BlockEntry>();\n private readonly _seen = new Set<string>();\n\n private _layerRevision = -1;\n private _offsetX: number;\n private _offsetY: number;\n private _destroyed = false;\n\n public constructor(world: PhysicsWorld, layer: TileLayer, options: TileColliderOptions = {}) {\n this._world = world;\n this._layer = layer;\n this._options = options;\n this._defaults = resolveDefaults(options);\n this._regionMode = options.regionMode ?? 'boxes';\n this._offsetX = layer.offsetX;\n this._offsetY = layer.offsetY;\n }\n\n /** Number of bodies currently owned by this bridge. */\n public get bodyCount(): number {\n let count = 0;\n\n for (const entry of this._built.values()) {\n if (entry.body !== null) count++;\n }\n\n return count;\n }\n\n /**\n * The bodies this bridge owns, in `(cy, cx)` partition order - independent of\n * the order the chunks became resident in.\n */\n public *bodies(): IterableIterator<PhysicsBody> {\n const ordered = [...this._built.values()].sort((a, b) => a.cy - b.cy || a.cx - b.cx);\n\n for (const entry of ordered) {\n if (entry.body !== null) yield entry.body;\n }\n }\n\n /**\n * Bring the world's tile colliders up to date with the layer: build bodies\n * for newly resident chunks, rebuild edited ones, destroy evicted ones.\n *\n * Cheap to call every frame. With no change since the last call it performs\n * no work and allocates nothing. No-op once {@link destroy}ed or once the\n * layer is destroyed.\n */\n public sync(): void {\n if (this._destroyed || this._layer.destroyed) return;\n\n const layer = this._layer;\n const offsetChanged = layer.offsetX !== this._offsetX || layer.offsetY !== this._offsetY;\n\n if (!offsetChanged && layer.revision === this._layerRevision) return;\n\n if (offsetChanged) {\n // Geometry is emitted in layer pixel space, so a moved layer invalidates\n // every collider - and moving a layer does not bump its revision.\n this._clear();\n this._offsetX = layer.offsetX;\n this._offsetY = layer.offsetY;\n }\n\n const seen = this._seen;\n\n seen.clear();\n\n for (const chunk of layer.loadedChunks()) {\n this._syncBlock(chunk.cx, chunk.cy, chunk);\n }\n\n // A cell source covers the layer, not its residency: every partition of a\n // bounded layer is a build block, whether or not tiles were ever placed in\n // it. Without this the canonical case - collision authored per cell on a\n // layer that renders nothing - would produce no bodies at all.\n if (this._options.cells !== undefined) {\n const range = layer.chunkRange();\n\n if (range !== null) {\n for (let cy = range.minCy; cy <= range.maxCy; cy++) {\n for (let cx = range.minCx; cx <= range.maxCx; cx++) {\n this._syncBlock(cx, cy, layer.getChunk(cx, cy) ?? null);\n }\n }\n }\n }\n\n for (const [key, entry] of this._built) {\n if (seen.has(key)) continue;\n\n if (entry.body !== null) this._world.destroyBody(entry.body);\n this._built.delete(key);\n }\n\n this._layerRevision = layer.revision;\n }\n\n /**\n * Destroy every body this bridge created and stop responding to\n * {@link sync}. Bodies it did not create are untouched. Idempotent.\n */\n public destroy(): void {\n if (this._destroyed) return;\n this._destroyed = true;\n this._clear();\n }\n\n private _clear(): void {\n for (const entry of this._built.values()) {\n if (entry.body !== null) this._world.destroyBody(entry.body);\n }\n\n this._built.clear();\n this._layerRevision = -1;\n }\n\n /**\n * Reconcile one build block against what was built for it before. Skips\n * without sampling anything when neither the backing chunk nor its revision\n * moved - which is what keeps an empty cell-only block from re-walking its\n * cells on every unrelated layer change.\n */\n private _syncBlock(cx: number, cy: number, chunk: ReadonlyTileChunk | null): void {\n const key = chunkKey(cx, cy);\n\n if (this._seen.has(key)) return;\n\n this._seen.add(key);\n\n const entry = this._built.get(key);\n const revision = chunk?.revision ?? -1;\n\n if (entry?.chunk === chunk && entry.revision === revision) {\n return;\n }\n\n if (entry?.body != null) {\n this._world.destroyBody(entry.body);\n }\n\n this._built.set(key, { cx, cy, chunk, revision, body: this._buildBlock(cx, cy, chunk) });\n }\n\n private _buildBlock(cx: number, cy: number, chunk: ReadonlyTileChunk | null): PhysicsBody | null {\n const layer = this._layer;\n const options = this._options;\n const startTx = cx * layer.chunkWidth;\n const startTy = cy * layer.chunkHeight;\n const width = chunk?.width ?? blockExtent(layer.chunkWidth, layer.width, startTx);\n const height = chunk?.height ?? blockExtent(layer.chunkHeight, layer.height, startTy);\n const geometry = buildTileCollisionGeometry(layer, {\n region: { x: startTx, y: startTy, width, height },\n ...(options.merge !== undefined && { merge: options.merge }),\n ...(options.accept !== undefined && { accept: options.accept }),\n ...(options.cells !== undefined && { cells: options.cells }),\n });\n\n if (geometry.rects.length === 0 && geometry.shapes.length === 0) {\n return null;\n }\n\n const offset = layer.logicalOffset;\n const x = startTx * layer.projection.logicalTileWidth + offset.x;\n const y = startTy * layer.projection.logicalTileHeight + offset.y;\n const colliders = buildTileColliders(geometry, {\n x,\n y,\n tileWidth: layer.projection.logicalTileWidth,\n tileHeight: layer.projection.logicalTileHeight,\n layerOffsetX: offset.x,\n layerOffsetY: offset.y,\n regionMode: this._regionMode,\n defaults: this._defaults,\n material: options.material,\n });\n\n if (colliders.length === 0) {\n return null;\n }\n\n return this._world.add(new PhysicsBody({ type: 'static', position: { x, y }, colliders }));\n }\n}\n"],"mappings":";;;;;;AAmDA,MAAM,YAAY,IAAY,OAAuB,GAAG,GAAG,GAAG;;;;;;AAO9D,MAAM,eAAe,aAAqB,aAAiC,UACzE,gBAAgB,SAAY,cAAc,KAAK,IAAI,aAAa,cAAc,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCrF,IAAa,uBAAb,MAAkC;CAChC,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAiB,yBAAS,IAAI,IAAwB;CACtD,AAAiB,wBAAQ,IAAI,IAAY;CAEzC,AAAQ,iBAAiB;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ,aAAa;CAErB,AAAO,YAAY,OAAqB,OAAkB,UAA+B,CAAC,GAAG;EAC3F,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,WAAW;EAChB,KAAK,YAAY,gBAAgB,OAAO;EACxC,KAAK,cAAc,QAAQ,cAAc;EACzC,KAAK,WAAW,MAAM;EACtB,KAAK,WAAW,MAAM;CACxB;;CAGA,IAAW,YAAoB;EAC7B,IAAI,QAAQ;EAEZ,KAAK,MAAM,SAAS,KAAK,OAAO,OAAO,GACrC,IAAI,MAAM,SAAS,MAAM;EAG3B,OAAO;CACT;;;;;CAMA,CAAQ,SAAwC;EAC9C,MAAM,UAAU,CAAC,GAAG,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;EAEnF,KAAK,MAAM,SAAS,SAClB,IAAI,MAAM,SAAS,MAAM,MAAM,MAAM;CAEzC;;;;;;;;;CAUA,AAAO,OAAa;EAClB,IAAI,KAAK,cAAc,KAAK,OAAO,WAAW;EAE9C,MAAM,QAAQ,KAAK;EACnB,MAAM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QAAQ;EACpB,CAAC;EAED,IAAI,UAAU,WAAW,GACvB,OAAO;EAGT,OAAO,KAAK,OAAO,IAAI,IAAI,YAAY;GAAE,MAAM;GAAU,UAAU;IAAE;IAAG;GAAE;GAAG;EAAU,CAAC,CAAC;CAC3F;AACF"}
@@ -1,21 +0,0 @@
1
- import type { SceneNode } from '@codexo/exojs';
2
- import type { PhysicsBody } from '@codexo/exojs-physics';
3
- import type { TileProjection } from '@codexo/exojs-tilemap';
4
- /**
5
- * Explicit presentation of a logical physics body through a tile projection.
6
- * Call after stepping the world, or use syncInterpolated with the fixed-step
7
- * interpolation fraction. The node's parent must use map display coordinates.
8
- * Owns neither body nor node; does not register with the world. Sprite rotation
9
- * and scale remain application-owned because projection is not a rigid rotation.
10
- */
11
- export declare class TilePhysicsBinding {
12
- readonly body: PhysicsBody;
13
- readonly node: SceneNode;
14
- readonly projection: TileProjection;
15
- constructor(body: PhysicsBody, node: SceneNode, projection: TileProjection);
16
- sync(): void;
17
- /** Interpolates logical positions before projection; teleport semantics follow PhysicsBody. */
18
- syncInterpolated(alpha: number): void;
19
- private _sync;
20
- }
21
- //# sourceMappingURL=TilePhysicsBinding.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TilePhysicsBinding.d.ts","sourceRoot":"","sources":["../../src/TilePhysicsBinding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;;GAMG;AACH,qBAAa,kBAAkB;aAEX,IAAI,EAAE,WAAW;aACjB,IAAI,EAAE,SAAS;aACf,UAAU,EAAE,cAAc;IAH5C,YACkB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,SAAS,EACf,UAAU,EAAE,cAAc,EACxC;IAEG,IAAI,IAAI,IAAI,CAElB;IAED,+FAA+F;IACxF,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAG3C;IAED,OAAO,CAAC,KAAK;CAQd"}
@@ -1,35 +0,0 @@
1
- //#region src/TilePhysicsBinding.ts
2
- /**
3
- * Explicit presentation of a logical physics body through a tile projection.
4
- * Call after stepping the world, or use syncInterpolated with the fixed-step
5
- * interpolation fraction. The node's parent must use map display coordinates.
6
- * Owns neither body nor node; does not register with the world. Sprite rotation
7
- * and scale remain application-owned because projection is not a rigid rotation.
8
- */
9
- var TilePhysicsBinding = class {
10
- body;
11
- node;
12
- projection;
13
- constructor(body, node, projection) {
14
- this.body = body;
15
- this.node = node;
16
- this.projection = projection;
17
- }
18
- sync() {
19
- this._sync(this.body.x, this.body.y);
20
- }
21
- /** Interpolates logical positions before projection; teleport semantics follow PhysicsBody. */
22
- syncInterpolated(alpha) {
23
- const body = this.body;
24
- this._sync(body.previousX + (body.x - body.previousX) * alpha, body.previousY + (body.y - body.previousY) * alpha);
25
- }
26
- _sync(x, y) {
27
- const p = this.projection;
28
- if (p.orientation === "isometric") this.node.setPosition(p.originX + (x - y) * p.tileWidth / (2 * p.tileHeight), p.originY + (x + y) / 2);
29
- else this.node.setPosition(p.originX + x, p.originY + y);
30
- }
31
- };
32
-
33
- //#endregion
34
- export { TilePhysicsBinding };
35
- //# sourceMappingURL=TilePhysicsBinding.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TilePhysicsBinding.js","names":[],"sources":["../../src/TilePhysicsBinding.ts"],"sourcesContent":["import type { SceneNode } from '@codexo/exojs';\nimport type { PhysicsBody } from '@codexo/exojs-physics';\nimport type { TileProjection } from '@codexo/exojs-tilemap';\n\n/**\n * Explicit presentation of a logical physics body through a tile projection.\n * Call after stepping the world, or use syncInterpolated with the fixed-step\n * interpolation fraction. The node's parent must use map display coordinates.\n * Owns neither body nor node; does not register with the world. Sprite rotation\n * and scale remain application-owned because projection is not a rigid rotation.\n */\nexport class TilePhysicsBinding {\n public constructor(\n public readonly body: PhysicsBody,\n public readonly node: SceneNode,\n public readonly projection: TileProjection,\n ) {}\n\n public sync(): void {\n this._sync(this.body.x, this.body.y);\n }\n\n /** Interpolates logical positions before projection; teleport semantics follow PhysicsBody. */\n public syncInterpolated(alpha: number): void {\n const body = this.body;\n this._sync(body.previousX + (body.x - body.previousX) * alpha, body.previousY + (body.y - body.previousY) * alpha);\n }\n\n private _sync(x: number, y: number): void {\n const p = this.projection;\n if (p.orientation === 'isometric') {\n this.node.setPosition(p.originX + ((x - y) * p.tileWidth) / (2 * p.tileHeight), p.originY + (x + y) / 2);\n } else {\n this.node.setPosition(p.originX + x, p.originY + y);\n }\n }\n}\n"],"mappings":";;;;;;;;AAWA,IAAa,qBAAb,MAAgC;CAEZ;CACA;CACA;CAHlB,AAAO,YACL,AAAgB,MAChB,AAAgB,MAChB,AAAgB,YAChB;EAHgB;EACA;EACA;CACf;CAEH,AAAO,OAAa;EAClB,KAAK,MAAM,KAAK,KAAK,GAAG,KAAK,KAAK,CAAC;CACrC;;CAGA,AAAO,iBAAiB,OAAqB;EAC3C,MAAM,OAAO,KAAK;EAClB,KAAK,MAAM,KAAK,aAAa,KAAK,IAAI,KAAK,aAAa,OAAO,KAAK,aAAa,KAAK,IAAI,KAAK,aAAa,KAAK;CACnH;CAEA,AAAQ,MAAM,GAAW,GAAiB;EACxC,MAAM,IAAI,KAAK;EACf,IAAI,EAAE,gBAAgB,aACpB,KAAK,KAAK,YAAY,EAAE,WAAY,IAAI,KAAK,EAAE,aAAc,IAAI,EAAE,aAAa,EAAE,WAAW,IAAI,KAAK,CAAC;OAEvG,KAAK,KAAK,YAAY,EAAE,UAAU,GAAG,EAAE,UAAU,CAAC;CAEtD;AACF"}