@codexo/exojs-tilemap 0.19.0 → 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.
Files changed (157) hide show
  1. package/README.md +7 -163
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +12 -20
  5. package/dist/esm/ChunkSource.d.ts +0 -33
  6. package/dist/esm/ChunkSource.d.ts.map +0 -1
  7. package/dist/esm/ChunkStreamer.d.ts +0 -104
  8. package/dist/esm/ChunkStreamer.d.ts.map +0 -1
  9. package/dist/esm/ChunkStreamer.js +0 -229
  10. package/dist/esm/ChunkStreamer.js.map +0 -1
  11. package/dist/esm/ImageLayer.d.ts +0 -89
  12. package/dist/esm/ImageLayer.d.ts.map +0 -1
  13. package/dist/esm/ImageLayer.js +0 -74
  14. package/dist/esm/ImageLayer.js.map +0 -1
  15. package/dist/esm/ImageLayerNode.d.ts +0 -91
  16. package/dist/esm/ImageLayerNode.d.ts.map +0 -1
  17. package/dist/esm/ImageLayerNode.js +0 -210
  18. package/dist/esm/ImageLayerNode.js.map +0 -1
  19. package/dist/esm/MapObject.d.ts +0 -70
  20. package/dist/esm/MapObject.d.ts.map +0 -1
  21. package/dist/esm/MapObject.js +0 -34
  22. package/dist/esm/MapObject.js.map +0 -1
  23. package/dist/esm/MapObjectSpawner.d.ts +0 -133
  24. package/dist/esm/MapObjectSpawner.d.ts.map +0 -1
  25. package/dist/esm/MapObjectSpawner.js +0 -147
  26. package/dist/esm/MapObjectSpawner.js.map +0 -1
  27. package/dist/esm/MapSpawnSession.d.ts +0 -46
  28. package/dist/esm/MapSpawnSession.d.ts.map +0 -1
  29. package/dist/esm/MapSpawnSession.js +0 -88
  30. package/dist/esm/MapSpawnSession.js.map +0 -1
  31. package/dist/esm/MapWorld.d.ts +0 -134
  32. package/dist/esm/MapWorld.d.ts.map +0 -1
  33. package/dist/esm/MapWorld.js +0 -150
  34. package/dist/esm/MapWorld.js.map +0 -1
  35. package/dist/esm/MapWorldRuntime.d.ts +0 -180
  36. package/dist/esm/MapWorldRuntime.d.ts.map +0 -1
  37. package/dist/esm/MapWorldRuntime.js +0 -261
  38. package/dist/esm/MapWorldRuntime.js.map +0 -1
  39. package/dist/esm/ObjectLayer.d.ts +0 -379
  40. package/dist/esm/ObjectLayer.d.ts.map +0 -1
  41. package/dist/esm/ObjectLayer.js +0 -221
  42. package/dist/esm/ObjectLayer.js.map +0 -1
  43. package/dist/esm/SampledChunkSource.d.ts +0 -43
  44. package/dist/esm/SampledChunkSource.d.ts.map +0 -1
  45. package/dist/esm/SampledChunkSource.js +0 -48
  46. package/dist/esm/SampledChunkSource.js.map +0 -1
  47. package/dist/esm/TileAnimator.d.ts +0 -72
  48. package/dist/esm/TileAnimator.d.ts.map +0 -1
  49. package/dist/esm/TileAnimator.js +0 -158
  50. package/dist/esm/TileAnimator.js.map +0 -1
  51. package/dist/esm/TileChunk.d.ts +0 -103
  52. package/dist/esm/TileChunk.d.ts.map +0 -1
  53. package/dist/esm/TileChunk.js +0 -194
  54. package/dist/esm/TileChunk.js.map +0 -1
  55. package/dist/esm/TileChunkNode.d.ts +0 -2
  56. package/dist/esm/TileChunkNode.d.ts.map +0 -1
  57. package/dist/esm/TileChunkNode.js +0 -145
  58. package/dist/esm/TileChunkNode.js.map +0 -1
  59. package/dist/esm/TileLayer.d.ts +0 -286
  60. package/dist/esm/TileLayer.d.ts.map +0 -1
  61. package/dist/esm/TileLayer.js +0 -526
  62. package/dist/esm/TileLayer.js.map +0 -1
  63. package/dist/esm/TileLayerNode.d.ts +0 -129
  64. package/dist/esm/TileLayerNode.d.ts.map +0 -1
  65. package/dist/esm/TileLayerNode.js +0 -245
  66. package/dist/esm/TileLayerNode.js.map +0 -1
  67. package/dist/esm/TileMap.d.ts +0 -317
  68. package/dist/esm/TileMap.d.ts.map +0 -1
  69. package/dist/esm/TileMap.js +0 -406
  70. package/dist/esm/TileMap.js.map +0 -1
  71. package/dist/esm/TileMapBand.d.ts +0 -80
  72. package/dist/esm/TileMapBand.d.ts.map +0 -1
  73. package/dist/esm/TileMapBand.js +0 -155
  74. package/dist/esm/TileMapBand.js.map +0 -1
  75. package/dist/esm/TileMapNode.d.ts +0 -92
  76. package/dist/esm/TileMapNode.d.ts.map +0 -1
  77. package/dist/esm/TileMapNode.js +0 -134
  78. package/dist/esm/TileMapNode.js.map +0 -1
  79. package/dist/esm/TileMapView.d.ts +0 -248
  80. package/dist/esm/TileMapView.d.ts.map +0 -1
  81. package/dist/esm/TileMapView.js +0 -394
  82. package/dist/esm/TileMapView.js.map +0 -1
  83. package/dist/esm/TileProjection.d.ts +0 -59
  84. package/dist/esm/TileProjection.d.ts.map +0 -1
  85. package/dist/esm/TileProjection.js +0 -106
  86. package/dist/esm/TileProjection.js.map +0 -1
  87. package/dist/esm/TileSet.d.ts +0 -116
  88. package/dist/esm/TileSet.d.ts.map +0 -1
  89. package/dist/esm/TileSet.js +0 -168
  90. package/dist/esm/TileSet.js.map +0 -1
  91. package/dist/esm/WangSet.d.ts +0 -80
  92. package/dist/esm/WangSet.d.ts.map +0 -1
  93. package/dist/esm/WangSet.js +0 -73
  94. package/dist/esm/WangSet.js.map +0 -1
  95. package/dist/esm/WorkerSampledChunkSource.d.ts +0 -94
  96. package/dist/esm/WorkerSampledChunkSource.d.ts.map +0 -1
  97. package/dist/esm/WorkerSampledChunkSource.js +0 -113
  98. package/dist/esm/WorkerSampledChunkSource.js.map +0 -1
  99. package/dist/esm/autoTile.d.ts +0 -88
  100. package/dist/esm/autoTile.d.ts.map +0 -1
  101. package/dist/esm/autoTile.js +0 -173
  102. package/dist/esm/autoTile.js.map +0 -1
  103. package/dist/esm/chunkGeometry.d.ts +0 -2
  104. package/dist/esm/chunkGeometry.d.ts.map +0 -1
  105. package/dist/esm/chunkGeometry.js +0 -116
  106. package/dist/esm/chunkGeometry.js.map +0 -1
  107. package/dist/esm/index.d.ts +0 -2
  108. package/dist/esm/index.d.ts.map +0 -1
  109. package/dist/esm/index.js +0 -27
  110. package/dist/esm/nodeBounds.d.ts +0 -2
  111. package/dist/esm/nodeBounds.d.ts.map +0 -1
  112. package/dist/esm/nodeBounds.js +0 -40
  113. package/dist/esm/nodeBounds.js.map +0 -1
  114. package/dist/esm/pixelSnap.d.ts +0 -2
  115. package/dist/esm/pixelSnap.d.ts.map +0 -1
  116. package/dist/esm/pixelSnap.js +0 -21
  117. package/dist/esm/pixelSnap.js.map +0 -1
  118. package/dist/esm/projectObject.d.ts +0 -4
  119. package/dist/esm/projectObject.d.ts.map +0 -1
  120. package/dist/esm/projectObject.js +0 -87
  121. package/dist/esm/projectObject.js.map +0 -1
  122. package/dist/esm/public.d.ts +0 -48
  123. package/dist/esm/public.d.ts.map +0 -1
  124. package/dist/esm/tileCollision.d.ts +0 -190
  125. package/dist/esm/tileCollision.d.ts.map +0 -1
  126. package/dist/esm/tileCollision.js +0 -399
  127. package/dist/esm/tileCollision.js.map +0 -1
  128. package/dist/esm/tileWord.d.ts +0 -2
  129. package/dist/esm/tileWord.d.ts.map +0 -1
  130. package/dist/esm/tileWord.js +0 -16
  131. package/dist/esm/tileWord.js.map +0 -1
  132. package/dist/esm/tilemapExtension.d.ts +0 -20
  133. package/dist/esm/tilemapExtension.d.ts.map +0 -1
  134. package/dist/esm/tilemapExtension.js +0 -53
  135. package/dist/esm/tilemapExtension.js.map +0 -1
  136. package/dist/esm/tilemapSerializers.d.ts +0 -2
  137. package/dist/esm/tilemapSerializers.d.ts.map +0 -1
  138. package/dist/esm/tilemapSerializers.js +0 -54
  139. package/dist/esm/tilemapSerializers.js.map +0 -1
  140. package/dist/esm/types.d.ts +0 -231
  141. package/dist/esm/types.d.ts.map +0 -1
  142. package/dist/esm/types.js +0 -129
  143. package/dist/esm/types.js.map +0 -1
  144. package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts +0 -2
  145. package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts.map +0 -1
  146. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +0 -376
  147. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +0 -1
  148. package/dist/esm/webgl2/shaders/tile-chunk.frag.js +0 -6
  149. package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +0 -1
  150. package/dist/esm/webgl2/shaders/tile-chunk.vert.js +0 -6
  151. package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +0 -1
  152. package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts +0 -2
  153. package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts.map +0 -1
  154. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +0 -539
  155. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +0 -1
  156. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +0 -6
  157. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +0 -1
@@ -1,113 +0,0 @@
1
- import { packTile } from "./types.js";
2
- import { InlineWorker } from "@codexo/exojs";
3
-
4
- //#region src/WorkerSampledChunkSource.ts
5
- const isWorkerErrorMessage = (message) => "error" in message;
6
- /**
7
- * Build a {@link import('./ChunkStreamer').ChunkStreamer}-ready
8
- * {@link ChunkSource} that samples off the main thread via a Web Worker -
9
- * the async counterpart to
10
- * {@link import('./SampledChunkSource').createSampledChunkSource}, for
11
- * sampling functions expensive enough to want off-thread execution.
12
- *
13
- * Unlike the synchronous provider, sampling logic cannot be passed as a
14
- * live function - functions cannot cross a `postMessage` boundary. Instead
15
- * {@link WorkerSampledChunkSourceOptions.workerSource} is a self-contained
16
- * worker script string; see its documentation for the protocol.
17
- *
18
- * The returned value's `destroy()` MUST be called when done with it - the
19
- * underlying `Worker` is a real resource that leaks otherwise.
20
- * {@link import('./ChunkStreamer').ChunkStreamer} does not own the source it
21
- * is given and never calls this for you: `ChunkSource` itself has no
22
- * lifecycle hook, so nothing ties the two together automatically. Call it
23
- * yourself alongside your own `ChunkStreamer.destroy()` call.
24
- *
25
- * `workerSource` runs through {@link import('@codexo/exojs').InlineWorker},
26
- * so it needs no bundler support of its own but does need a
27
- * Content-Security-Policy that permits `blob:` in `worker-src` if your
28
- * deployment sets one; the constructor names that cause when it is refused.
29
- * @advanced
30
- */
31
- const createWorkerSampledChunkSource = (layer, options) => {
32
- const mapValueToTile = options.mapValueToTile.bind(options);
33
- const inline = new InlineWorker(options.workerSource, { name: "exojs-tilemap-chunk-sampler" });
34
- const worker = inline.worker;
35
- if (options.initMessage !== void 0) inline.postMessage(options.initMessage);
36
- let requestCounter = 0;
37
- const pending = /* @__PURE__ */ new Map();
38
- const composePayload = (values, request) => {
39
- const { cx, cy, chunkWidth, chunkHeight } = request;
40
- const startTx = cx * chunkWidth;
41
- const startTy = cy * chunkHeight;
42
- let out = null;
43
- for (let ty = startTy; ty < startTy + chunkHeight; ty++) for (let tx = startTx; tx < startTx + chunkWidth; tx++) {
44
- if (layer.width !== void 0 && layer.height !== void 0 && (tx >= layer.width || ty >= layer.height)) continue;
45
- const localIndex = (ty - startTy) * chunkWidth + (tx - startTx);
46
- const value = values[localIndex];
47
- if (value === void 0) continue;
48
- const resolved = mapValueToTile(value, tx, ty);
49
- if (!resolved) continue;
50
- out ??= new Uint32Array(chunkWidth * chunkHeight);
51
- const tilesetIndex = layer.tilesets.indexOf(resolved.tileset);
52
- out[localIndex] = packTile(tilesetIndex, resolved.localTileId, resolved.transform);
53
- }
54
- return out === null ? null : {
55
- width: chunkWidth,
56
- height: chunkHeight,
57
- tiles: out
58
- };
59
- };
60
- worker.onmessage = (event) => {
61
- const message = event.data;
62
- const entry = pending.get(message.requestId);
63
- if (!entry) return;
64
- pending.delete(message.requestId);
65
- if (isWorkerErrorMessage(message)) {
66
- entry.reject(new Error(message.error));
67
- return;
68
- }
69
- entry.resolve(composePayload(message.values, entry));
70
- };
71
- worker.onerror = (event) => {
72
- const error = /* @__PURE__ */ new Error(`WorkerSampledChunkSource worker error: ${event.message}`);
73
- for (const entry of pending.values()) entry.reject(error);
74
- pending.clear();
75
- };
76
- return {
77
- getChunk(cx, cy) {
78
- if (inline.destroyed) return Promise.reject(/* @__PURE__ */ new Error("WorkerSampledChunkSource: getChunk() called after destroy()."));
79
- const chunkWidth = layer.chunkWidth;
80
- const chunkHeight = layer.chunkHeight;
81
- const requestId = ++requestCounter;
82
- return new Promise((resolve, reject) => {
83
- pending.set(requestId, {
84
- resolve,
85
- reject,
86
- cx,
87
- cy,
88
- chunkWidth,
89
- chunkHeight
90
- });
91
- const request = {
92
- requestId,
93
- cx,
94
- cy,
95
- chunkWidth,
96
- chunkHeight
97
- };
98
- inline.postMessage(request);
99
- });
100
- },
101
- destroy() {
102
- if (inline.destroyed) return;
103
- const error = /* @__PURE__ */ new Error("WorkerSampledChunkSource destroyed.");
104
- for (const entry of pending.values()) entry.reject(error);
105
- pending.clear();
106
- inline.destroy();
107
- }
108
- };
109
- };
110
-
111
- //#endregion
112
- export { createWorkerSampledChunkSource };
113
- //# sourceMappingURL=WorkerSampledChunkSource.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkerSampledChunkSource.js","names":[],"sources":["../../src/WorkerSampledChunkSource.ts"],"sourcesContent":["import { InlineWorker } from '@codexo/exojs';\n\nimport type { ChunkPayload, ChunkSource } from './ChunkSource';\nimport type { TileLayer } from './TileLayer';\nimport type { ResolvedTile } from './types';\nimport { packTile } from './types';\n\n/**\n * Options for {@link createWorkerSampledChunkSource}.\n * @advanced\n */\nexport interface WorkerSampledChunkSourceOptions {\n /**\n * Complete worker script source as a single self-contained string, Blob-URL'd\n * into a real `Worker` at construction time - the same technique\n * {@link import('@codexo/exojs').WorkletEffect} uses for AudioWorklet\n * processors. No separate worker asset is fetched and no bundler-specific\n * worker-import syntax is involved.\n *\n * Producing that string by hand-writing JavaScript into a template literal\n * works but gives up type checking, linting and shared code. Prefer a build\n * step that bundles a real module into a string: this repository's own\n * examples are authored as `*.worker.ts` and imported through a `?worker`\n * query, which is why they can `import` the sampling functions the main\n * thread uses instead of restating them.\n *\n * Must implement this request/response protocol:\n * - Request (received via `self.onmessage`):\n * `{ requestId: number; cx: number; cy: number; chunkWidth: number; chunkHeight: number }`.\n * - Response, success (send via `self.postMessage`, transferring the\n * buffer for a zero-copy handoff - `postMessage(response, [response.values.buffer])`):\n * `{ requestId: number; values: Float64Array }`, `values.length ===\n * chunkWidth * chunkHeight`, row-major (`localTy * chunkWidth + localTx`),\n * one sampled value per tile in the requested chunk. Compute each tile's\n * absolute coordinate as `cx * chunkWidth + localTx` /\n * `cy * chunkHeight + localTy`.\n * - Response, error (one request failed without crashing the worker):\n * `{ requestId: number; error: string }`.\n *\n * Your worker must reply to every request with exactly one success or\n * error message bearing the same `requestId`. A request left unanswered\n * leaves that chunk permanently unfetched - there is no timeout - since\n * `ChunkStreamer` tracks it as still in flight and never retries it.\n */\n workerSource: string;\n /**\n * Posted to the worker once, before any chunk request, when present.\n *\n * The transport for whatever the sampler needs to know that is not per-chunk\n * - a seed, a feature size, a cost knob. Without it those values would have\n * to be interpolated into {@link WorkerSampledChunkSourceOptions.workerSource}\n * as literals, which turns every parameter change into a source rebuild and a\n * new `Worker`.\n *\n * `postMessage` delivery is ordered, so the worker is guaranteed to see this\n * before the first request. Distinguish it from a chunk request by its own\n * shape; requests carry a `requestId`.\n */\n initMessage?: unknown;\n /**\n * Convert a sampled value (and its absolute tile coordinate) into a\n * resolved tile, or `null` for an empty cell. Always runs on the main\n * thread - a `ResolvedTile` references a `TileSet`/`Texture`, neither of\n * which can cross a `postMessage` boundary. Must be pure and\n * deterministic, same requirement as\n * {@link import('./SampledChunkSource').SampledChunkSourceOptions.mapValueToTile}.\n */\n mapValueToTile(value: number, tx: number, ty: number): ResolvedTile | null;\n}\n\ninterface WorkerRequestMessage {\n readonly requestId: number;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\ninterface WorkerSuccessMessage {\n readonly requestId: number;\n readonly values: Float64Array;\n}\n\ninterface WorkerErrorMessage {\n readonly requestId: number;\n readonly error: string;\n}\n\ntype WorkerResponseMessage = WorkerSuccessMessage | WorkerErrorMessage;\n\nconst isWorkerErrorMessage = (message: WorkerResponseMessage): message is WorkerErrorMessage => 'error' in message;\n\ninterface PendingRequest {\n readonly resolve: (payload: ChunkPayload | null) => void;\n readonly reject: (error: Error) => void;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\n/**\n * Build a {@link import('./ChunkStreamer').ChunkStreamer}-ready\n * {@link ChunkSource} that samples off the main thread via a Web Worker -\n * the async counterpart to\n * {@link import('./SampledChunkSource').createSampledChunkSource}, for\n * sampling functions expensive enough to want off-thread execution.\n *\n * Unlike the synchronous provider, sampling logic cannot be passed as a\n * live function - functions cannot cross a `postMessage` boundary. Instead\n * {@link WorkerSampledChunkSourceOptions.workerSource} is a self-contained\n * worker script string; see its documentation for the protocol.\n *\n * The returned value's `destroy()` MUST be called when done with it - the\n * underlying `Worker` is a real resource that leaks otherwise.\n * {@link import('./ChunkStreamer').ChunkStreamer} does not own the source it\n * is given and never calls this for you: `ChunkSource` itself has no\n * lifecycle hook, so nothing ties the two together automatically. Call it\n * yourself alongside your own `ChunkStreamer.destroy()` call.\n *\n * `workerSource` runs through {@link import('@codexo/exojs').InlineWorker},\n * so it needs no bundler support of its own but does need a\n * Content-Security-Policy that permits `blob:` in `worker-src` if your\n * deployment sets one; the constructor names that cause when it is refused.\n * @advanced\n */\nexport const createWorkerSampledChunkSource = (layer: TileLayer, options: WorkerSampledChunkSourceOptions): ChunkSource & { destroy(): void } => {\n const mapValueToTile = options.mapValueToTile.bind(options);\n\n const inline = new InlineWorker(options.workerSource, { name: 'exojs-tilemap-chunk-sampler' });\n const worker = inline.worker;\n\n if (options.initMessage !== undefined) {\n inline.postMessage(options.initMessage);\n }\n\n let requestCounter = 0;\n const pending = new Map<number, PendingRequest>();\n\n const composePayload = (values: Float64Array, request: PendingRequest): ChunkPayload | null => {\n const { cx, cy, chunkWidth, chunkHeight } = request;\n const startTx = cx * chunkWidth;\n const startTy = cy * chunkHeight;\n\n let out: Uint32Array | null = null;\n for (let ty = startTy; ty < startTy + chunkHeight; ty++) {\n for (let tx = startTx; tx < startTx + chunkWidth; tx++) {\n // Bounded-layer edge chunks may be smaller than a full chunk - same\n // clamp createSampledChunkSource applies, computed here (not asked\n // of the worker) since only this side knows the layer's bounds.\n if (layer.width !== undefined && layer.height !== undefined && (tx >= layer.width || ty >= layer.height)) continue;\n\n const localIndex = (ty - startTy) * chunkWidth + (tx - startTx);\n const value = values[localIndex];\n if (value === undefined) continue; // defensive: malformed/short values array\n const resolved = mapValueToTile(value, tx, ty);\n if (!resolved) continue;\n\n out ??= new Uint32Array(chunkWidth * chunkHeight);\n const tilesetIndex = layer.tilesets.indexOf(resolved.tileset);\n out[localIndex] = packTile(tilesetIndex, resolved.localTileId, resolved.transform);\n }\n }\n\n return out === null ? null : { width: chunkWidth, height: chunkHeight, tiles: out };\n };\n\n worker.onmessage = (event: MessageEvent<WorkerResponseMessage>): void => {\n const message = event.data;\n const entry = pending.get(message.requestId);\n if (!entry) return; // stale/unknown requestId (e.g. arrived after destroy())\n pending.delete(message.requestId);\n\n if (isWorkerErrorMessage(message)) {\n entry.reject(new Error(message.error));\n return;\n }\n\n entry.resolve(composePayload(message.values, entry));\n };\n\n worker.onerror = (event: ErrorEvent): void => {\n const error = new Error(`WorkerSampledChunkSource worker error: ${event.message}`);\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n };\n\n return {\n getChunk(cx: number, cy: number): Promise<ChunkPayload | null> {\n if (inline.destroyed) {\n return Promise.reject(new Error('WorkerSampledChunkSource: getChunk() called after destroy().'));\n }\n\n const chunkWidth = layer.chunkWidth;\n const chunkHeight = layer.chunkHeight;\n const requestId = ++requestCounter;\n\n return new Promise<ChunkPayload | null>((resolve, reject) => {\n pending.set(requestId, { resolve, reject, cx, cy, chunkWidth, chunkHeight });\n const request: WorkerRequestMessage = { requestId, cx, cy, chunkWidth, chunkHeight };\n inline.postMessage(request);\n });\n },\n\n destroy(): void {\n if (inline.destroyed) return;\n const error = new Error('WorkerSampledChunkSource destroyed.');\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n inline.destroy();\n },\n };\n};\n"],"mappings":";;;;AA0FA,MAAM,wBAAwB,YAAkE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;AAoC3G,MAAa,kCAAkC,OAAkB,YAAgF;CAC/I,MAAM,iBAAiB,QAAQ,eAAe,KAAK,OAAO;CAE1D,MAAM,SAAS,IAAI,aAAa,QAAQ,cAAc,EAAE,MAAM,8BAA8B,CAAC;CAC7F,MAAM,SAAS,OAAO;CAEtB,IAAI,QAAQ,gBAAgB,QAC1B,OAAO,YAAY,QAAQ,WAAW;CAGxC,IAAI,iBAAiB;CACrB,MAAM,0BAAU,IAAI,IAA4B;CAEhD,MAAM,kBAAkB,QAAsB,YAAiD;EAC7F,MAAM,EAAE,IAAI,IAAI,YAAY,gBAAgB;EAC5C,MAAM,UAAU,KAAK;EACrB,MAAM,UAAU,KAAK;EAErB,IAAI,MAA0B;EAC9B,KAAK,IAAI,KAAK,SAAS,KAAK,UAAU,aAAa,MACjD,KAAK,IAAI,KAAK,SAAS,KAAK,UAAU,YAAY,MAAM;GAItD,IAAI,MAAM,UAAU,UAAa,MAAM,WAAW,WAAc,MAAM,MAAM,SAAS,MAAM,MAAM,SAAS;GAE1G,MAAM,cAAc,KAAK,WAAW,cAAc,KAAK;GACvD,MAAM,QAAQ,OAAO;GACrB,IAAI,UAAU,QAAW;GACzB,MAAM,WAAW,eAAe,OAAO,IAAI,EAAE;GAC7C,IAAI,CAAC,UAAU;GAEf,QAAQ,IAAI,YAAY,aAAa,WAAW;GAChD,MAAM,eAAe,MAAM,SAAS,QAAQ,SAAS,OAAO;GAC5D,IAAI,cAAc,SAAS,cAAc,SAAS,aAAa,SAAS,SAAS;EACnF;EAGF,OAAO,QAAQ,OAAO,OAAO;GAAE,OAAO;GAAY,QAAQ;GAAa,OAAO;EAAI;CACpF;CAEA,OAAO,aAAa,UAAqD;EACvE,MAAM,UAAU,MAAM;EACtB,MAAM,QAAQ,QAAQ,IAAI,QAAQ,SAAS;EAC3C,IAAI,CAAC,OAAO;EACZ,QAAQ,OAAO,QAAQ,SAAS;EAEhC,IAAI,qBAAqB,OAAO,GAAG;GACjC,MAAM,OAAO,IAAI,MAAM,QAAQ,KAAK,CAAC;GACrC;EACF;EAEA,MAAM,QAAQ,eAAe,QAAQ,QAAQ,KAAK,CAAC;CACrD;CAEA,OAAO,WAAW,UAA4B;EAC5C,MAAM,wBAAQ,IAAI,MAAM,0CAA0C,MAAM,SAAS;EACjF,KAAK,MAAM,SAAS,QAAQ,OAAO,GACjC,MAAM,OAAO,KAAK;EAEpB,QAAQ,MAAM;CAChB;CAEA,OAAO;EACL,SAAS,IAAY,IAA0C;GAC7D,IAAI,OAAO,WACT,OAAO,QAAQ,uBAAO,IAAI,MAAM,8DAA8D,CAAC;GAGjG,MAAM,aAAa,MAAM;GACzB,MAAM,cAAc,MAAM;GAC1B,MAAM,YAAY,EAAE;GAEpB,OAAO,IAAI,SAA8B,SAAS,WAAW;IAC3D,QAAQ,IAAI,WAAW;KAAE;KAAS;KAAQ;KAAI;KAAI;KAAY;IAAY,CAAC;IAC3E,MAAM,UAAgC;KAAE;KAAW;KAAI;KAAI;KAAY;IAAY;IACnF,OAAO,YAAY,OAAO;GAC5B,CAAC;EACH;EAEA,UAAgB;GACd,IAAI,OAAO,WAAW;GACtB,MAAM,wBAAQ,IAAI,MAAM,qCAAqC;GAC7D,KAAK,MAAM,SAAS,QAAQ,OAAO,GACjC,MAAM,OAAO,KAAK;GAEpB,QAAQ,MAAM;GACd,OAAO,QAAQ;EACjB;CACF;AACF"}
@@ -1,88 +0,0 @@
1
- import type { TileLayer } from './TileLayer';
2
- import type { WangSet } from './WangSet';
3
- /**
4
- * Options for {@link autoTile} and {@link refreshCell}.
5
- */
6
- export interface AutoTileOptions {
7
- /**
8
- * When provided, only cells for which `matchFn` returns `true` are treated
9
- * as part of the Wang group. The function receives the cell's `localTileId`,
10
- * `tilesetIndex`, and tile coordinates `(x, y)`.
11
- *
12
- * If omitted, group membership defaults to {@link WangSet.isMember} on the
13
- * cell's `localTileId` (and a matching `tilesetIndex`). That default is
14
- * *variant-stable* - every autotiled variant counts as a member - which is
15
- * what makes {@link refreshCell} correct. If you supply a `matchFn` for use
16
- * with `refreshCell`, it MUST likewise be variant-stable (independent of the
17
- * currently-rendered variant), e.g. keyed on a separate logical-terrain grid
18
- * or a tile property.
19
- */
20
- matchFn?: (localTileId: number, tilesetIndex: number, x: number, y: number) => boolean;
21
- /**
22
- * When `true` (default), out-of-bounds neighbors are treated as though
23
- * they belong to the Wang group, so border tiles fill correctly to the
24
- * layer edge. Set to `false` to leave border tiles visually open.
25
- */
26
- wrapBorder?: boolean;
27
- }
28
- /**
29
- * Apply Wang autotiling to `layer` using `wangSet`.
30
- *
31
- * Iterates every cell in the layer. For each cell that belongs to the Wang
32
- * group, computes a neighbor bitmask and looks up the correct local tile ID
33
- * from {@link WangSet.blobMap}. The layer is mutated in place; cells whose
34
- * computed bitmask has no mapping in the blobMap are left unchanged.
35
- *
36
- * The function performs two passes (snapshot then write) so neighbor tests
37
- * always reflect the pre-call state regardless of processing order.
38
- *
39
- * **Group membership.** With no `matchFn`, a cell belongs to the group when its
40
- * `tilesetIndex` matches {@link WangSet.tilesetIndex} and its `localTileId` is a
41
- * {@link WangSet.isMember member} of the set. Membership covers every variant
42
- * the set can produce, so re-running `autoTile` (or {@link refreshCell}) on
43
- * already-autotiled data is stable. Paint with a tile ID that is a member (a
44
- * blobMap value, or one listed in {@link WangSetOptions.members}).
45
- *
46
- * **Blob mode bitmask (bit positions):**
47
- * ```
48
- * 1 | 2 | 4
49
- * 8 | -- | 16
50
- * 32 | 64 | 128
51
- * ```
52
- * Diagonal bits (1, 4, 32, 128) are only set when both adjacent cardinals
53
- * are also set (the "corner dependency" rule that reduces 256 raw
54
- * combinations to 47 valid blob states).
55
- *
56
- * **Edge mode bitmask (bit positions):** Top=1, Right=2, Bottom=4, Left=8.
57
- *
58
- * @throws If `layer` is unbounded (no fixed width/height) - there is no
59
- * "whole layer" to sweep. Use {@link refreshCell} to autotile an unbounded
60
- * layer incrementally, one edited cell at a time.
61
- */
62
- export declare const autoTile: (layer: TileLayer, wangSet: WangSet, options?: AutoTileOptions) => void;
63
- /**
64
- * Incrementally re-autotile a single cell and its eight neighbours after an
65
- * edit, instead of re-running {@link autoTile} over the whole layer.
66
- *
67
- * A cell's blob/edge mask depends only on its immediate neighbours, so painting
68
- * or erasing cell `(x, y)` can change the variant of that cell and of the (up
69
- * to) eight cells that have it as a neighbour - but nothing further out. This
70
- * recomputes exactly that 3×3 neighbourhood, touching only the 1-4 chunks it
71
- * spans (and rebuilding geometry only for chunks whose tiles actually change).
72
- * For a paint operation this is O(1) work versus `autoTile`'s O(width·height).
73
- *
74
- * Membership is read live from the layer, so the membership test MUST be
75
- * variant-stable: the default ({@link WangSet.isMember}) is, and any custom
76
- * `matchFn` you pass must be too (see {@link AutoTileOptions.matchFn}).
77
- *
78
- * Typical editor use: write the painted tile with `layer.setTileAt(...)` using
79
- * a member tile ID, then call `refreshCell(layer, x, y, wangSet)`.
80
- *
81
- * @param layer The layer to update in place.
82
- * @param x Tile X of the edited cell.
83
- * @param y Tile Y of the edited cell.
84
- * @param wangSet The Wang set to resolve variants from.
85
- * @param options Membership / border options (shared with {@link autoTile}).
86
- */
87
- export declare const refreshCell: (layer: TileLayer, x: number, y: number, wangSet: WangSet, options?: AutoTileOptions) => void;
88
- //# sourceMappingURL=autoTile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"autoTile.d.ts","sourceRoot":"","sources":["../../src/autoTile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;IACvF;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AA0ED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,QAAQ,UAAW,SAAS,WAAW,OAAO,YAAY,eAAe,KAAG,IAuDxF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,WAAW,UAAW,SAAS,KAAK,MAAM,KAAK,MAAM,WAAW,OAAO,YAAY,eAAe,KAAG,IA0BjH,CAAC"}
@@ -1,173 +0,0 @@
1
- import { TILE_TRANSFORM_IDENTITY, unpackTile } from "./types.js";
2
-
3
- //#region src/autoTile.ts
4
- /**
5
- * Compute a 4-bit edge bitmask for the cell at `(tx, ty)`.
6
- * Top=1, Right=2, Bottom=4, Left=8.
7
- */
8
- const computeEdgeMask = (tx, ty, inGroup) => {
9
- let mask = 0;
10
- if (inGroup(tx, ty - 1)) mask |= 1;
11
- if (inGroup(tx + 1, ty)) mask |= 2;
12
- if (inGroup(tx, ty + 1)) mask |= 4;
13
- if (inGroup(tx - 1, ty)) mask |= 8;
14
- return mask;
15
- };
16
- /**
17
- * Compute an 8-bit blob bitmask for the cell at `(tx, ty)` using the
18
- * corner-dependency rule: diagonal bits are only set when both adjacent
19
- * cardinal directions are also set.
20
- *
21
- * Bit layout:
22
- * ```
23
- * 1 | 2 | 4
24
- * 8 | -- | 16
25
- * 32 | 64 | 128
26
- * ```
27
- */
28
- const computeBlobMask = (tx, ty, inGroup) => {
29
- const top = inGroup(tx, ty - 1);
30
- const right = inGroup(tx + 1, ty);
31
- const bottom = inGroup(tx, ty + 1);
32
- const left = inGroup(tx - 1, ty);
33
- let mask = 0;
34
- if (top) mask |= 2;
35
- if (right) mask |= 16;
36
- if (bottom) mask |= 64;
37
- if (left) mask |= 8;
38
- if (top && left && inGroup(tx - 1, ty - 1)) mask |= 1;
39
- if (top && right && inGroup(tx + 1, ty - 1)) mask |= 4;
40
- if (bottom && left && inGroup(tx - 1, ty + 1)) mask |= 32;
41
- if (bottom && right && inGroup(tx + 1, ty + 1)) mask |= 128;
42
- return mask;
43
- };
44
- /** Compute the mask for a cell given the Wang mode and a membership predicate. */
45
- const computeMask = (wangSet, tx, ty, inGroup) => wangSet.type === "edge" ? computeEdgeMask(tx, ty, inGroup) : computeBlobMask(tx, ty, inGroup);
46
- /**
47
- * Apply the variant computed for cell `(tx, ty)` to `layer`, preserving the
48
- * cell's current orientation transform. No-op if the mask has no mapping or
49
- * the target tileset is missing.
50
- */
51
- const applyVariant = (layer, wangSet, tx, ty, inGroup) => {
52
- const newLocalTileId = wangSet.getTileId(computeMask(wangSet, tx, ty, inGroup));
53
- if (newLocalTileId === void 0) return;
54
- const tileset = layer.tilesets[wangSet.tilesetIndex];
55
- if (!tileset) return;
56
- const existing = layer.getTileAt(tx, ty);
57
- layer.setTileAt(tx, ty, {
58
- localTileId: newLocalTileId,
59
- tileset,
60
- transform: existing ? existing.transform : TILE_TRANSFORM_IDENTITY
61
- });
62
- };
63
- /**
64
- * Apply Wang autotiling to `layer` using `wangSet`.
65
- *
66
- * Iterates every cell in the layer. For each cell that belongs to the Wang
67
- * group, computes a neighbor bitmask and looks up the correct local tile ID
68
- * from {@link WangSet.blobMap}. The layer is mutated in place; cells whose
69
- * computed bitmask has no mapping in the blobMap are left unchanged.
70
- *
71
- * The function performs two passes (snapshot then write) so neighbor tests
72
- * always reflect the pre-call state regardless of processing order.
73
- *
74
- * **Group membership.** With no `matchFn`, a cell belongs to the group when its
75
- * `tilesetIndex` matches {@link WangSet.tilesetIndex} and its `localTileId` is a
76
- * {@link WangSet.isMember member} of the set. Membership covers every variant
77
- * the set can produce, so re-running `autoTile` (or {@link refreshCell}) on
78
- * already-autotiled data is stable. Paint with a tile ID that is a member (a
79
- * blobMap value, or one listed in {@link WangSetOptions.members}).
80
- *
81
- * **Blob mode bitmask (bit positions):**
82
- * ```
83
- * 1 | 2 | 4
84
- * 8 | -- | 16
85
- * 32 | 64 | 128
86
- * ```
87
- * Diagonal bits (1, 4, 32, 128) are only set when both adjacent cardinals
88
- * are also set (the "corner dependency" rule that reduces 256 raw
89
- * combinations to 47 valid blob states).
90
- *
91
- * **Edge mode bitmask (bit positions):** Top=1, Right=2, Bottom=4, Left=8.
92
- *
93
- * @throws If `layer` is unbounded (no fixed width/height) - there is no
94
- * "whole layer" to sweep. Use {@link refreshCell} to autotile an unbounded
95
- * layer incrementally, one edited cell at a time.
96
- */
97
- const autoTile = (layer, wangSet, options) => {
98
- const matchFn = options?.matchFn;
99
- const wrapBorder = options?.wrapBorder ?? true;
100
- const w = layer.width;
101
- const h = layer.height;
102
- if (w === void 0 || h === void 0) throw new Error("autoTile() requires a bounded layer (sweeps the whole layer) — use refreshCell() on an unbounded layer instead.");
103
- const snapshot = /* @__PURE__ */ new Map();
104
- for (let ty = 0; ty < h; ty++) for (let tx = 0; tx < w; tx++) {
105
- const packed = layer.getRawTileAt(tx, ty);
106
- if (packed === 0) continue;
107
- const decoded = unpackTile(packed);
108
- if (!decoded) continue;
109
- snapshot.set(ty * w + tx, decoded);
110
- }
111
- const isInGroup = (nx, ny) => {
112
- if (nx < 0 || nx >= w || ny < 0 || ny >= h) return wrapBorder;
113
- const cell = snapshot.get(ny * w + nx);
114
- if (!cell) return false;
115
- if (matchFn) return matchFn(cell.localTileId, cell.tilesetIndex, nx, ny);
116
- return cell.tilesetIndex === wangSet.tilesetIndex && wangSet.isMember(cell.localTileId);
117
- };
118
- for (let ty = 0; ty < h; ty++) for (let tx = 0; tx < w; tx++) {
119
- const cellInfo = snapshot.get(ty * w + tx);
120
- if (!cellInfo) continue;
121
- if (!(matchFn ? matchFn(cellInfo.localTileId, cellInfo.tilesetIndex, tx, ty) : cellInfo.tilesetIndex === wangSet.tilesetIndex && wangSet.isMember(cellInfo.localTileId))) continue;
122
- applyVariant(layer, wangSet, tx, ty, isInGroup);
123
- }
124
- };
125
- /**
126
- * Incrementally re-autotile a single cell and its eight neighbours after an
127
- * edit, instead of re-running {@link autoTile} over the whole layer.
128
- *
129
- * A cell's blob/edge mask depends only on its immediate neighbours, so painting
130
- * or erasing cell `(x, y)` can change the variant of that cell and of the (up
131
- * to) eight cells that have it as a neighbour - but nothing further out. This
132
- * recomputes exactly that 3×3 neighbourhood, touching only the 1-4 chunks it
133
- * spans (and rebuilding geometry only for chunks whose tiles actually change).
134
- * For a paint operation this is O(1) work versus `autoTile`'s O(width·height).
135
- *
136
- * Membership is read live from the layer, so the membership test MUST be
137
- * variant-stable: the default ({@link WangSet.isMember}) is, and any custom
138
- * `matchFn` you pass must be too (see {@link AutoTileOptions.matchFn}).
139
- *
140
- * Typical editor use: write the painted tile with `layer.setTileAt(...)` using
141
- * a member tile ID, then call `refreshCell(layer, x, y, wangSet)`.
142
- *
143
- * @param layer The layer to update in place.
144
- * @param x Tile X of the edited cell.
145
- * @param y Tile Y of the edited cell.
146
- * @param wangSet The Wang set to resolve variants from.
147
- * @param options Membership / border options (shared with {@link autoTile}).
148
- */
149
- const refreshCell = (layer, x, y, wangSet, options) => {
150
- const matchFn = options?.matchFn;
151
- const wrapBorder = options?.wrapBorder ?? true;
152
- const w = layer.width;
153
- const h = layer.height;
154
- const isInGroup = (nx, ny) => {
155
- if (w !== void 0 && (nx < 0 || nx >= w) || h !== void 0 && (ny < 0 || ny >= h)) return wrapBorder;
156
- const tile = layer.getTileAt(nx, ny);
157
- if (!tile) return false;
158
- const tsi = layer.tilesets.indexOf(tile.tileset);
159
- if (matchFn) return matchFn(tile.localTileId, tsi, nx, ny);
160
- return tsi === wangSet.tilesetIndex && wangSet.isMember(tile.localTileId);
161
- };
162
- for (let dy = -1; dy <= 1; dy++) for (let dx = -1; dx <= 1; dx++) {
163
- const tx = x + dx;
164
- const ty = y + dy;
165
- if (!layer.inBounds(tx, ty)) continue;
166
- if (!isInGroup(tx, ty)) continue;
167
- applyVariant(layer, wangSet, tx, ty, isInGroup);
168
- }
169
- };
170
-
171
- //#endregion
172
- export { autoTile, refreshCell };
173
- //# sourceMappingURL=autoTile.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"autoTile.js","names":[],"sources":["../../src/autoTile.ts"],"sourcesContent":["import type { TileLayer } from './TileLayer';\nimport { TILE_TRANSFORM_IDENTITY, unpackTile } from './types';\nimport type { WangSet } from './WangSet';\n\n/**\n * Options for {@link autoTile} and {@link refreshCell}.\n */\nexport interface AutoTileOptions {\n /**\n * When provided, only cells for which `matchFn` returns `true` are treated\n * as part of the Wang group. The function receives the cell's `localTileId`,\n * `tilesetIndex`, and tile coordinates `(x, y)`.\n *\n * If omitted, group membership defaults to {@link WangSet.isMember} on the\n * cell's `localTileId` (and a matching `tilesetIndex`). That default is\n * *variant-stable* - every autotiled variant counts as a member - which is\n * what makes {@link refreshCell} correct. If you supply a `matchFn` for use\n * with `refreshCell`, it MUST likewise be variant-stable (independent of the\n * currently-rendered variant), e.g. keyed on a separate logical-terrain grid\n * or a tile property.\n */\n matchFn?: (localTileId: number, tilesetIndex: number, x: number, y: number) => boolean;\n /**\n * When `true` (default), out-of-bounds neighbors are treated as though\n * they belong to the Wang group, so border tiles fill correctly to the\n * layer edge. Set to `false` to leave border tiles visually open.\n */\n wrapBorder?: boolean;\n}\n\n// ── Module-level mask helpers ─────────────────────────────────────────────\n\n/**\n * Compute a 4-bit edge bitmask for the cell at `(tx, ty)`.\n * Top=1, Right=2, Bottom=4, Left=8.\n */\nconst computeEdgeMask = (tx: number, ty: number, inGroup: (nx: number, ny: number) => boolean): number => {\n let mask = 0;\n if (inGroup(tx, ty - 1)) mask |= 1;\n if (inGroup(tx + 1, ty)) mask |= 2;\n if (inGroup(tx, ty + 1)) mask |= 4;\n if (inGroup(tx - 1, ty)) mask |= 8;\n return mask;\n};\n\n/**\n * Compute an 8-bit blob bitmask for the cell at `(tx, ty)` using the\n * corner-dependency rule: diagonal bits are only set when both adjacent\n * cardinal directions are also set.\n *\n * Bit layout:\n * ```\n * 1 | 2 | 4\n * 8 | -- | 16\n * 32 | 64 | 128\n * ```\n */\nconst computeBlobMask = (tx: number, ty: number, inGroup: (nx: number, ny: number) => boolean): number => {\n const top = inGroup(tx, ty - 1);\n const right = inGroup(tx + 1, ty);\n const bottom = inGroup(tx, ty + 1);\n const left = inGroup(tx - 1, ty);\n let mask = 0;\n if (top) mask |= 2;\n if (right) mask |= 16;\n if (bottom) mask |= 64;\n if (left) mask |= 8;\n // Corner bits: only when BOTH adjacent cardinals are set.\n if (top && left && inGroup(tx - 1, ty - 1)) mask |= 1;\n if (top && right && inGroup(tx + 1, ty - 1)) mask |= 4;\n if (bottom && left && inGroup(tx - 1, ty + 1)) mask |= 32;\n if (bottom && right && inGroup(tx + 1, ty + 1)) mask |= 128;\n return mask;\n};\n\n/** Compute the mask for a cell given the Wang mode and a membership predicate. */\nconst computeMask = (wangSet: WangSet, tx: number, ty: number, inGroup: (nx: number, ny: number) => boolean): number =>\n wangSet.type === 'edge' ? computeEdgeMask(tx, ty, inGroup) : computeBlobMask(tx, ty, inGroup);\n\n/**\n * Apply the variant computed for cell `(tx, ty)` to `layer`, preserving the\n * cell's current orientation transform. No-op if the mask has no mapping or\n * the target tileset is missing.\n */\nconst applyVariant = (layer: TileLayer, wangSet: WangSet, tx: number, ty: number, inGroup: (nx: number, ny: number) => boolean): void => {\n const newLocalTileId = wangSet.getTileId(computeMask(wangSet, tx, ty, inGroup));\n if (newLocalTileId === undefined) return;\n\n const tileset = layer.tilesets[wangSet.tilesetIndex];\n if (!tileset) return;\n\n // Preserve the existing orientation transform if the cell already holds one.\n const existing = layer.getTileAt(tx, ty);\n layer.setTileAt(tx, ty, {\n localTileId: newLocalTileId,\n tileset,\n transform: existing ? existing.transform : TILE_TRANSFORM_IDENTITY,\n });\n};\n\n// ── Public API ────────────────────────────────────────────────────────────\n\n/**\n * Apply Wang autotiling to `layer` using `wangSet`.\n *\n * Iterates every cell in the layer. For each cell that belongs to the Wang\n * group, computes a neighbor bitmask and looks up the correct local tile ID\n * from {@link WangSet.blobMap}. The layer is mutated in place; cells whose\n * computed bitmask has no mapping in the blobMap are left unchanged.\n *\n * The function performs two passes (snapshot then write) so neighbor tests\n * always reflect the pre-call state regardless of processing order.\n *\n * **Group membership.** With no `matchFn`, a cell belongs to the group when its\n * `tilesetIndex` matches {@link WangSet.tilesetIndex} and its `localTileId` is a\n * {@link WangSet.isMember member} of the set. Membership covers every variant\n * the set can produce, so re-running `autoTile` (or {@link refreshCell}) on\n * already-autotiled data is stable. Paint with a tile ID that is a member (a\n * blobMap value, or one listed in {@link WangSetOptions.members}).\n *\n * **Blob mode bitmask (bit positions):**\n * ```\n * 1 | 2 | 4\n * 8 | -- | 16\n * 32 | 64 | 128\n * ```\n * Diagonal bits (1, 4, 32, 128) are only set when both adjacent cardinals\n * are also set (the \"corner dependency\" rule that reduces 256 raw\n * combinations to 47 valid blob states).\n *\n * **Edge mode bitmask (bit positions):** Top=1, Right=2, Bottom=4, Left=8.\n *\n * @throws If `layer` is unbounded (no fixed width/height) - there is no\n * \"whole layer\" to sweep. Use {@link refreshCell} to autotile an unbounded\n * layer incrementally, one edited cell at a time.\n */\nexport const autoTile = (layer: TileLayer, wangSet: WangSet, options?: AutoTileOptions): void => {\n const matchFn = options?.matchFn;\n const wrapBorder = options?.wrapBorder ?? true;\n const w = layer.width;\n const h = layer.height;\n if (w === undefined || h === undefined) {\n throw new Error('autoTile() requires a bounded layer (sweeps the whole layer) — use refreshCell() on an unbounded layer instead.');\n }\n\n // ── Pass 1: snapshot ─────────────────────────────────────────────────\n // Capture each cell's (tilesetIndex, localTileId) before any writes so\n // that neighbor membership tests always see pre-mutation state.\n\n interface CellInfo {\n tilesetIndex: number;\n localTileId: number;\n }\n const snapshot = new Map<number, CellInfo>();\n\n for (let ty = 0; ty < h; ty++) {\n for (let tx = 0; tx < w; tx++) {\n const packed = layer.getRawTileAt(tx, ty);\n if (packed === 0) continue;\n const decoded = unpackTile(packed);\n if (!decoded) continue;\n snapshot.set(ty * w + tx, decoded);\n }\n }\n\n // ── Membership test (reads the snapshot) ─────────────────────────────\n\n const isInGroup = (nx: number, ny: number): boolean => {\n if (nx < 0 || nx >= w || ny < 0 || ny >= h) return wrapBorder;\n const cell = snapshot.get(ny * w + nx);\n if (!cell) return false;\n if (matchFn) return matchFn(cell.localTileId, cell.tilesetIndex, nx, ny);\n return cell.tilesetIndex === wangSet.tilesetIndex && wangSet.isMember(cell.localTileId);\n };\n\n // ── Pass 2: compute masks and write ──────────────────────────────────\n\n for (let ty = 0; ty < h; ty++) {\n for (let tx = 0; tx < w; tx++) {\n const cellInfo = snapshot.get(ty * w + tx);\n if (!cellInfo) continue;\n\n // Skip cells that are not part of the group.\n const isMember = matchFn\n ? matchFn(cellInfo.localTileId, cellInfo.tilesetIndex, tx, ty)\n : cellInfo.tilesetIndex === wangSet.tilesetIndex && wangSet.isMember(cellInfo.localTileId);\n if (!isMember) continue;\n\n applyVariant(layer, wangSet, tx, ty, isInGroup);\n }\n }\n};\n\n/**\n * Incrementally re-autotile a single cell and its eight neighbours after an\n * edit, instead of re-running {@link autoTile} over the whole layer.\n *\n * A cell's blob/edge mask depends only on its immediate neighbours, so painting\n * or erasing cell `(x, y)` can change the variant of that cell and of the (up\n * to) eight cells that have it as a neighbour - but nothing further out. This\n * recomputes exactly that 3×3 neighbourhood, touching only the 1-4 chunks it\n * spans (and rebuilding geometry only for chunks whose tiles actually change).\n * For a paint operation this is O(1) work versus `autoTile`'s O(width·height).\n *\n * Membership is read live from the layer, so the membership test MUST be\n * variant-stable: the default ({@link WangSet.isMember}) is, and any custom\n * `matchFn` you pass must be too (see {@link AutoTileOptions.matchFn}).\n *\n * Typical editor use: write the painted tile with `layer.setTileAt(...)` using\n * a member tile ID, then call `refreshCell(layer, x, y, wangSet)`.\n *\n * @param layer The layer to update in place.\n * @param x Tile X of the edited cell.\n * @param y Tile Y of the edited cell.\n * @param wangSet The Wang set to resolve variants from.\n * @param options Membership / border options (shared with {@link autoTile}).\n */\nexport const refreshCell = (layer: TileLayer, x: number, y: number, wangSet: WangSet, options?: AutoTileOptions): void => {\n const matchFn = options?.matchFn;\n const wrapBorder = options?.wrapBorder ?? true;\n const w = layer.width;\n const h = layer.height;\n\n // Live membership test (reads the current layer; variant-stable by default).\n const isInGroup = (nx: number, ny: number): boolean => {\n if ((w !== undefined && (nx < 0 || nx >= w)) || (h !== undefined && (ny < 0 || ny >= h))) return wrapBorder;\n const tile = layer.getTileAt(nx, ny);\n if (!tile) return false;\n const tsi = layer.tilesets.indexOf(tile.tileset);\n if (matchFn) return matchFn(tile.localTileId, tsi, nx, ny);\n return tsi === wangSet.tilesetIndex && wangSet.isMember(tile.localTileId);\n };\n\n // Recompute the edited cell and its eight neighbours.\n for (let dy = -1; dy <= 1; dy++) {\n for (let dx = -1; dx <= 1; dx++) {\n const tx = x + dx;\n const ty = y + dy;\n if (!layer.inBounds(tx, ty)) continue;\n if (!isInGroup(tx, ty)) continue;\n applyVariant(layer, wangSet, tx, ty, isInGroup);\n }\n }\n};\n"],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=chunkGeometry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunkGeometry.d.ts","sourceRoot":"","sources":["../../src/chunkGeometry.ts"],"names":[],"mappings":""}
@@ -1,116 +0,0 @@
1
- import { unpackTile } from "./types.js";
2
-
3
- //#region src/chunkGeometry.ts
4
- /** Pack a {@link TileTransform} into a 3-bit orientation code. @internal */
5
- const orientCode = (transform) => (transform.flipX ? 1 : 0) | (transform.flipY ? 2 : 0) | (transform.diagonal ? 4 : 0);
6
- let tileGeometryRebuildCount = 0;
7
- const drawableTileset = (tilesets, tilesetIndex, localTileId) => {
8
- const tileset = tilesets[tilesetIndex];
9
- if (tileset === void 0 || localTileId >= tileset.tileCount) return void 0;
10
- const texture = tileset.texture.texture;
11
- if (texture.width <= 0 || texture.height <= 0) return void 0;
12
- return tileset;
13
- };
14
- const pageQuads = (tileset, isometric, buckets, ordered) => {
15
- let bucket;
16
- if (isometric) {
17
- const previous = ordered[ordered.length - 1];
18
- if (previous?.tileset === tileset) bucket = previous.quads;
19
- } else bucket = buckets.get(tileset);
20
- if (bucket === void 0) {
21
- bucket = [];
22
- buckets.set(tileset, bucket);
23
- if (isometric) ordered.push({
24
- tileset,
25
- texture: tileset.texture.texture,
26
- quads: bucket
27
- });
28
- }
29
- return bucket;
30
- };
31
- const tilesetPages = (tilesets, buckets) => {
32
- const pages = [];
33
- for (const tileset of tilesets) {
34
- const quads = buckets.get(tileset);
35
- if (quads !== void 0 && quads.length > 0) pages.push({
36
- tileset,
37
- texture: tileset.texture.texture,
38
- quads
39
- });
40
- }
41
- return pages;
42
- };
43
- /**
44
- * Build per-tileset page geometry for a single chunk.
45
- *
46
- * Iterates packed cells in row-major or isometric diagonal order, skipping
47
- * empties, out-of-range tilesets, and out-of-range local tile ids (all treated
48
- * as empty - this is the renderer's half of the G-GID contract). Each surviving
49
- * cell is resolved to its source UV rect (from `tileset.getTileRect` + the
50
- * tileset `TextureRegion`) and a chunk-local destination rect (bottom-left
51
- * aligned per Tiled orthogonal semantics, so tilesets whose tiles are taller
52
- * than the map grid extend upward).
53
- *
54
- * Allocation happens here only - the result is cached on the owning
55
- * {@link import('./TileChunkNode').TileChunkNode} keyed by `chunk.revision`, so
56
- * unchanged chunks never rebuild and the per-frame path stays allocation-free.
57
- *
58
- * @param chunk The readonly chunk view to build from.
59
- * @param tilesets The layer's tileset array (packed `tilesetIndex` selects one).
60
- * @param tileWidth Map/layer tile cell width in pixels.
61
- * @param tileHeight Map/layer tile cell height in pixels.
62
- * @internal
63
- */
64
- const buildChunkPages = (chunk, tilesets, tileWidth, tileHeight, projection, diagonal, geometryX = 0, geometryY = 0) => {
65
- tileGeometryRebuildCount++;
66
- if (chunk.empty) return [];
67
- const buckets = /* @__PURE__ */ new Map();
68
- const ordered = [];
69
- const isometric = projection?.orientation === "isometric";
70
- const width = chunk.width;
71
- const height = chunk.height;
72
- for (let row = 0; row < (isometric ? width + height - 1 : height); row++) {
73
- if (diagonal !== void 0 && row !== diagonal) continue;
74
- for (let lx = 0; lx < width; lx++) {
75
- const ly = isometric ? row - lx : row;
76
- if (ly < 0 || ly >= height) continue;
77
- const packed = chunk.getRawAt(lx, ly);
78
- if (packed === 0) continue;
79
- const decoded = unpackTile(packed);
80
- if (decoded === null) continue;
81
- const tileset = drawableTileset(tilesets, decoded.tilesetIndex, decoded.localTileId);
82
- if (tileset === void 0) continue;
83
- const region = tileset.texture;
84
- const texture = region.texture;
85
- const textureWidth = texture.width;
86
- const textureHeight = texture.height;
87
- const rect = tileset.getTileRect(decoded.localTileId);
88
- const sx = region.x + rect.x;
89
- const sy = region.y + rect.y;
90
- const u0 = sx / textureWidth;
91
- const v0 = sy / textureHeight;
92
- const u1 = (sx + rect.width) / textureWidth;
93
- const v1 = (sy + rect.height) / textureHeight;
94
- const x0 = geometryX + (isometric ? (lx - ly) * tileWidth / 2 - tileWidth / 2 : lx * tileWidth) + tileset.offsetX;
95
- const y0 = geometryY + (isometric ? (lx + ly) * tileHeight / 2 : ly * tileHeight) + tileHeight - rect.height + tileset.offsetY;
96
- const x1 = x0 + rect.width;
97
- const y1 = y0 + rect.height;
98
- pageQuads(tileset, isometric, buckets, ordered).push({
99
- x0,
100
- y0,
101
- x1,
102
- y1,
103
- u0,
104
- v0,
105
- u1,
106
- v1,
107
- orient: orientCode(decoded.transform)
108
- });
109
- }
110
- }
111
- return isometric ? ordered : tilesetPages(tilesets, buckets);
112
- };
113
-
114
- //#endregion
115
- export { buildChunkPages, orientCode };
116
- //# sourceMappingURL=chunkGeometry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunkGeometry.js","names":[],"sources":["../../src/chunkGeometry.ts"],"sourcesContent":["import type { Texture } from '@codexo/exojs';\n\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport type { TileProjection } from './TileProjection';\nimport type { TileSet } from './TileSet';\nimport type { TileTransform } from './types';\nimport { unpackTile } from './types';\n\n/**\n * One textured tile quad in chunk-local pixel space.\n *\n * `u0/v0/u1/v1` are the raw (min/max) source UV bounds of the tile within its\n * tileset texture - flip/orientation is **not** baked here; it travels in\n * {@link TileQuad.orient} and is applied by the per-backend renderer (flipX/Y\n * via UV-corner swap, diagonal via an axis swap in the shader). Keeping the\n * geometry orientation-neutral lets both backends share one CPU builder.\n * @internal\n */\nexport interface TileQuad {\n /** Local destination rect, left/top (chunk-local pixels). */\n readonly x0: number;\n readonly y0: number;\n /** Local destination rect, right/bottom (chunk-local pixels). */\n readonly x1: number;\n readonly y1: number;\n /** Normalised source UV bounds (always min ≤ max). */\n readonly u0: number;\n readonly v0: number;\n readonly u1: number;\n readonly v1: number;\n /** Orientation code: bit0 = flipX, bit1 = flipY, bit2 = diagonal. */\n readonly orient: number;\n}\n\n/**\n * Geometry sharing one tileset texture. Orthogonal chunks group tiles by\n * tileset; isometric chunks keep consecutive runs to preserve painter order.\n * @internal\n */\nexport interface ChunkPage {\n /** The tileset all quads in this page draw from. */\n readonly tileset: TileSet;\n /** The underlying GPU texture (the tileset's atlas), bound once per page. */\n readonly texture: Texture;\n /** The tile quads in deterministic projection-specific draw order. */\n readonly quads: readonly TileQuad[];\n}\n\n/** Pack a {@link TileTransform} into a 3-bit orientation code. @internal */\nexport const orientCode = (transform: TileTransform): number => (transform.flipX ? 1 : 0) | (transform.flipY ? 2 : 0) | (transform.diagonal ? 4 : 0);\n\n// Test/perf-only instrumentation: counts CPU chunk-geometry rebuilds. A rebuild\n// happens once per {@link buildChunkPages} call - i.e. when a chunk node sees a\n// changed `chunk.revision`. Lets benchmarks/regression tests assert that a camera\n// pan rebuilds nothing and a single tile mutation rebuilds exactly one chunk.\n// Near-zero cost (one integer increment on the already-expensive rebuild path).\nlet tileGeometryRebuildCount = 0;\n\n/** Read the cumulative chunk-geometry rebuild count. @internal */\nexport const getTileGeometryRebuildCount = (): number => tileGeometryRebuildCount;\n\n/** Reset the chunk-geometry rebuild counter (call before a measured frame). @internal */\nexport const resetTileGeometryRebuildCount = (): void => {\n tileGeometryRebuildCount = 0;\n};\n\nconst drawableTileset = (tilesets: readonly TileSet[], tilesetIndex: number, localTileId: number): TileSet | undefined => {\n const tileset = tilesets[tilesetIndex];\n\n // getTileRect throws for an invalid id; malformed cells must remain empty.\n if (tileset === undefined || localTileId >= tileset.tileCount) return undefined;\n const texture = tileset.texture.texture;\n if (texture.width <= 0 || texture.height <= 0) return undefined;\n return tileset;\n};\n\nconst pageQuads = (tileset: TileSet, isometric: boolean, buckets: Map<TileSet, TileQuad[]>, ordered: ChunkPage[]): TileQuad[] => {\n let bucket: TileQuad[] | undefined;\n if (isometric) {\n const previous = ordered[ordered.length - 1];\n if (previous?.tileset === tileset) bucket = previous.quads as TileQuad[];\n } else {\n bucket = buckets.get(tileset);\n }\n\n if (bucket === undefined) {\n bucket = [];\n buckets.set(tileset, bucket);\n if (isometric) ordered.push({ tileset, texture: tileset.texture.texture, quads: bucket });\n }\n return bucket;\n};\n\nconst tilesetPages = (tilesets: readonly TileSet[], buckets: ReadonlyMap<TileSet, TileQuad[]>): ChunkPage[] => {\n const pages: ChunkPage[] = [];\n for (const tileset of tilesets) {\n const quads = buckets.get(tileset);\n if (quads !== undefined && quads.length > 0) {\n pages.push({ tileset, texture: tileset.texture.texture, quads });\n }\n }\n return pages;\n};\n\n/**\n * Build per-tileset page geometry for a single chunk.\n *\n * Iterates packed cells in row-major or isometric diagonal order, skipping\n * empties, out-of-range tilesets, and out-of-range local tile ids (all treated\n * as empty - this is the renderer's half of the G-GID contract). Each surviving\n * cell is resolved to its source UV rect (from `tileset.getTileRect` + the\n * tileset `TextureRegion`) and a chunk-local destination rect (bottom-left\n * aligned per Tiled orthogonal semantics, so tilesets whose tiles are taller\n * than the map grid extend upward).\n *\n * Allocation happens here only - the result is cached on the owning\n * {@link import('./TileChunkNode').TileChunkNode} keyed by `chunk.revision`, so\n * unchanged chunks never rebuild and the per-frame path stays allocation-free.\n *\n * @param chunk The readonly chunk view to build from.\n * @param tilesets The layer's tileset array (packed `tilesetIndex` selects one).\n * @param tileWidth Map/layer tile cell width in pixels.\n * @param tileHeight Map/layer tile cell height in pixels.\n * @internal\n */\nexport const buildChunkPages = (\n chunk: ReadonlyTileChunk,\n tilesets: readonly TileSet[],\n tileWidth: number,\n tileHeight: number,\n projection?: TileProjection,\n diagonal?: number,\n geometryX = 0,\n geometryY = 0,\n): ChunkPage[] => {\n tileGeometryRebuildCount++;\n\n if (chunk.empty) {\n return [];\n }\n\n const buckets = new Map<TileSet, TileQuad[]>();\n const ordered: ChunkPage[] = [];\n const isometric = projection?.orientation === 'isometric';\n const width = chunk.width;\n const height = chunk.height;\n\n for (let row = 0; row < (isometric ? width + height - 1 : height); row++) {\n if (diagonal !== undefined && row !== diagonal) continue;\n for (let lx = 0; lx < width; lx++) {\n const ly = isometric ? row - lx : row;\n if (ly < 0 || ly >= height) continue;\n const packed = chunk.getRawAt(lx, ly);\n\n if (packed === 0) {\n continue;\n }\n\n const decoded = unpackTile(packed);\n\n if (decoded === null) {\n continue;\n }\n\n const tileset = drawableTileset(tilesets, decoded.tilesetIndex, decoded.localTileId);\n if (tileset === undefined) {\n continue;\n }\n\n const region = tileset.texture;\n const texture = region.texture;\n const textureWidth = texture.width;\n const textureHeight = texture.height;\n\n const rect = tileset.getTileRect(decoded.localTileId);\n\n // Absolute source pixel rect = tileset-region offset + in-atlas tile rect.\n const sx = region.x + rect.x;\n const sy = region.y + rect.y;\n // Exact tile UVs, no half-texel inset. This assumes NEAREST filtering on\n // the tileset atlas (the typical pixel-art case). Under LINEAR/mipmap\n // filtering an atlas WITHOUT extrusion padding can bleed neighbouring\n // tiles at the edges; author tilesets with extruded margins for linear\n // sampling. (Extrusion-aware tilemap UV insetting - already done on the\n // NineSlice/RepeatingSprite geometry paths - is a v0.14 follow-up.)\n const u0 = sx / textureWidth;\n const v0 = sy / textureHeight;\n const u1 = (sx + rect.width) / textureWidth;\n const v1 = (sy + rect.height) / textureHeight;\n\n // Isometric cells start at their top vertex; artwork is bottom-aligned\n // with the cell base before applying the tileset's display offset.\n const x0 = geometryX + (isometric ? ((lx - ly) * tileWidth) / 2 - tileWidth / 2 : lx * tileWidth) + tileset.offsetX;\n const y0 = geometryY + (isometric ? ((lx + ly) * tileHeight) / 2 : ly * tileHeight) + tileHeight - rect.height + tileset.offsetY;\n const x1 = x0 + rect.width;\n const y1 = y0 + rect.height;\n\n const bucket = pageQuads(tileset, isometric, buckets, ordered);\n bucket.push({ x0, y0, x1, y1, u0, v0, u1, v1, orient: orientCode(decoded.transform) });\n }\n }\n\n return isometric ? ordered : tilesetPages(tilesets, buckets);\n};\n"],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export * from './public';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAC"}
package/dist/esm/index.js DELETED
@@ -1,27 +0,0 @@
1
- import { TILE_TRANSFORM_IDENTITY, TilePropertyKind, packTile, tileToChunkCoord, tileToLocalInChunk, unpackTile } from "./types.js";
2
- import { TileProjection } from "./TileProjection.js";
3
- import { ImageLayer } from "./ImageLayer.js";
4
- import { ImageLayerNode } from "./ImageLayerNode.js";
5
- import { TileLayerNode } from "./TileLayerNode.js";
6
- import { TileMapNode } from "./TileMapNode.js";
7
- import { TileLayer } from "./TileLayer.js";
8
- import { TileMapBand } from "./TileMapBand.js";
9
- import { TileMapView } from "./TileMapView.js";
10
- import { TileSet } from "./TileSet.js";
11
- import { TileMap } from "./TileMap.js";
12
- import { tilemapExtension } from "./tilemapExtension.js";
13
- import { ObjectKind, ObjectLayer } from "./ObjectLayer.js";
14
- import { MapLevelSide, MapWorld } from "./MapWorld.js";
15
- import { MapLevelRuntime, MapWorldRuntime } from "./MapWorldRuntime.js";
16
- import { mapObjectDescriptor, mapObjectDescriptors } from "./MapObject.js";
17
- import { MapSpawnSession } from "./MapSpawnSession.js";
18
- import { MapObjectSpawner, MapSpawnError } from "./MapObjectSpawner.js";
19
- import { TileAnimator } from "./TileAnimator.js";
20
- import { buildTileCollisionGeometry } from "./tileCollision.js";
21
- import { ChunkStreamer } from "./ChunkStreamer.js";
22
- import { createSampledChunkSource } from "./SampledChunkSource.js";
23
- import { createWorkerSampledChunkSource } from "./WorkerSampledChunkSource.js";
24
- import { autoTile, refreshCell } from "./autoTile.js";
25
- import { WangSet } from "./WangSet.js";
26
-
27
- export { ChunkStreamer, ImageLayer, ImageLayerNode, MapLevelRuntime, MapLevelSide, MapObjectSpawner, MapSpawnError, MapSpawnSession, MapWorld, MapWorldRuntime, ObjectKind, ObjectLayer, TILE_TRANSFORM_IDENTITY, TileAnimator, TileLayer, TileLayerNode, TileMap, TileMapBand, TileMapNode, TileMapView, TileProjection, TilePropertyKind, TileSet, WangSet, autoTile, buildTileCollisionGeometry, createSampledChunkSource, createWorkerSampledChunkSource, mapObjectDescriptor, mapObjectDescriptors, packTile, refreshCell, tileToChunkCoord, tileToLocalInChunk, tilemapExtension, unpackTile };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=nodeBounds.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodeBounds.d.ts","sourceRoot":"","sources":["../../src/nodeBounds.ts"],"names":[],"mappings":""}