@n3rdw1z4rd/core 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -37,7 +37,6 @@ __export(index_exports, {
37
37
  BuildDefaultPalette: () => BuildDefaultPalette,
38
38
  CanvasRenderer: () => CanvasRenderer,
39
39
  Clock: () => Clock,
40
- ClockStats: () => ClockStats,
41
40
  Color: () => Color,
42
41
  Colors: () => Colors,
43
42
  CompileShader: () => CompileShader,
@@ -50,16 +49,17 @@ __export(index_exports, {
50
49
  CreateThreeEntity: () => CreateThreeEntity,
51
50
  CreateWebGlContext: () => CreateWebGlContext,
52
51
  CubeSphereGeometry: () => CubeSphereGeometry,
52
+ DOUBLE_PI: () => DOUBLE_PI,
53
53
  ECS: () => ECS,
54
54
  Emitter: () => Emitter,
55
- EventBus: () => EventBus,
56
55
  GenerateDoors: () => GenerateDoors,
57
56
  GenerateEntityId: () => GenerateEntityId,
58
57
  GenerateRooms: () => GenerateRooms,
59
58
  GenerateWalls: () => GenerateWalls,
60
59
  GetProgramLocations: () => GetProgramLocations,
61
60
  GetThreeComponent: () => GetThreeComponent,
62
- GlobalEmitter: () => GlobalEmitter,
61
+ GetUrlParams: () => GetUrlParams,
62
+ HALF_PI: () => HALF_PI,
63
63
  Input: () => Input,
64
64
  IsThreeEntity: () => IsThreeEntity,
65
65
  LoadTexture: () => LoadTexture,
@@ -67,14 +67,15 @@ __export(index_exports, {
67
67
  Map3D: () => Map3D,
68
68
  Noise: () => Noise,
69
69
  PI: () => PI,
70
+ ParticleRenderer: () => ParticleRenderer,
70
71
  ParticleSystem2d: () => ParticleSystem2d,
71
72
  ParticleSystem3d: () => ParticleSystem3d,
72
73
  PoissonDiskSampler: () => PoissonDiskSampler,
74
+ RADIAN_FACTOR: () => RADIAN_FACTOR,
75
+ RandomNumberGenerator: () => RandomNumberGenerator,
73
76
  Rectangle: () => Rectangle,
74
77
  RemoveThreeComponent: () => RemoveThreeComponent,
75
- Renderer: () => Renderer,
76
78
  ResizeWebGlContext: () => ResizeWebGlContext,
77
- Rng: () => Rng,
78
79
  ShaderType: () => ShaderType,
79
80
  SimplexNoise: () => SimplexNoise,
80
81
  SpatialPartition2d: () => SpatialPartition2d,
@@ -97,14 +98,15 @@ __export(index_exports, {
97
98
  clamp: () => clamp,
98
99
  cos: () => cos,
99
100
  deg2rad: () => deg2rad,
100
- distance: () => distance,
101
- eventBus: () => eventBus,
101
+ distance2d: () => distance2d,
102
+ distance3d: () => distance3d,
102
103
  floor: () => floor,
103
104
  getRedYellowGreenGradientHex: () => getRedYellowGreenGradientHex,
104
105
  hypot2: () => hypot2,
105
106
  hypot3: () => hypot3,
106
107
  imul: () => imul,
107
108
  isNullOrUndefined: () => isNullOrUndefined,
109
+ isPositiveString: () => isPositiveString,
108
110
  lerp: () => lerp,
109
111
  log: () => log,
110
112
  logdev: () => logdev,
@@ -146,10 +148,6 @@ var AStar = class {
146
148
  _key(x, y) {
147
149
  return `${x},${y}`;
148
150
  }
149
- // NOTE: ported as-is from rogue-craft. useAdjacent is currently hard-coded
150
- // to true below - the original had a known unresolved bug where setting it
151
- // to false via params caused an infinite loop, so that path is disabled
152
- // rather than exposed broken.
153
151
  findPath(a, b, params = {}) {
154
152
  const useAdjacent = true;
155
153
  const walkable = params.walkableValues ?? [0];
@@ -220,198 +218,130 @@ var AStar = class {
220
218
  }
221
219
  };
222
220
 
223
- // src/clock-stats.ts
224
- var ClockStats = class {
225
- divElement;
226
- keyColor = "gray";
227
- valueColor = "lightgray";
228
- constructor(align = "bottom", justify = "right") {
229
- this.divElement = document.createElement("div");
230
- this.divElement.setAttribute("id", "clock-stats");
231
- this.divElement.style.setProperty("position", "absolute");
232
- this.divElement.style.setProperty(align, "4px");
233
- this.divElement.style.setProperty(justify, "4px");
221
+ // src/emitter.ts
222
+ var Emitter = class {
223
+ listeners = /* @__PURE__ */ new Map();
224
+ constructor() {
234
225
  }
235
- appendTo(target) {
236
- this.divElement.parentNode?.removeChild(this.divElement);
237
- if (target) {
238
- target.appendChild(this.divElement);
239
- }
226
+ on(...eventName) {
227
+ const listener = eventName.pop();
228
+ const events = eventName.filter((ev) => typeof ev === "string");
229
+ events.forEach((event) => {
230
+ if (!this.listeners.has(event)) {
231
+ this.listeners.set(event, new Array());
232
+ }
233
+ this.listeners.get(event)?.push(listener);
234
+ });
235
+ return this;
240
236
  }
241
- update(data) {
242
- this.divElement.innerHTML = Object.entries(data).map(
243
- ([key, value]) => `<span style="color: ${this.keyColor};">${key}:</span>&nbsp;<span style="color: ${this.valueColor};">${value}</span>`
244
- ).join("<br/>");
237
+ emit(eventName, ...args) {
238
+ this.listeners.get(eventName)?.forEach((listener) => listener(...args, eventName));
239
+ return this;
240
+ }
241
+ clear(eventName) {
242
+ if (eventName) {
243
+ this.listeners.delete(eventName);
244
+ } else {
245
+ this.listeners.clear();
246
+ }
247
+ return this;
245
248
  }
246
249
  };
247
250
 
248
251
  // src/clock.ts
249
- var Clock = class {
250
- _lastFrameTime = 0;
251
- _daltaTimeMilliseconds = 0;
252
- _deltaTimeSeconds = 0;
253
- _avgDeltaTime = 0;
254
- _frameCount = 0;
255
- _frameCountTotal = 0;
252
+ var Clock = class extends Emitter {
253
+ _startTime = 0;
254
+ _time = 0;
255
+ _deltaTime = 0;
256
256
  _frameTime = 0;
257
+ _frameCount = 0;
257
258
  _fps = 0;
258
259
  _isRunning = false;
259
- _updateCallback = () => {
260
- };
261
- _statsParent;
262
- _stats;
263
- _startTime = 0;
264
- get fps() {
265
- return this._fps;
266
- }
267
- get frames() {
268
- return this._frameCountTotal;
269
- }
270
- get deltaTimeSeconds() {
271
- return this._deltaTimeSeconds;
272
- }
273
- get deltaTimeMilliseconds() {
274
- return this._daltaTimeMilliseconds;
275
- }
276
- get avgDeltaTime() {
277
- return this._avgDeltaTime;
278
- }
279
260
  get time() {
280
- return this._lastFrameTime;
261
+ return this._time;
281
262
  }
282
- get isRunning() {
283
- return this._isRunning;
263
+ get deltaTime() {
264
+ return this._deltaTime;
284
265
  }
285
- get elapsedTimeSinceStart() {
266
+ get elapsedTime() {
286
267
  return performance.now() - this._startTime;
287
268
  }
288
- constructor(statsDivParent) {
289
- this._statsParent = statsDivParent;
290
- }
291
- _update(time) {
292
- this.update(time);
293
- this._updateCallback(this._deltaTimeSeconds);
294
- if (this._isRunning) {
295
- requestAnimationFrame(this._update.bind(this));
296
- }
269
+ get fps() {
270
+ return this._fps;
297
271
  }
298
- update(time) {
299
- this._daltaTimeMilliseconds = time - this._lastFrameTime;
300
- this._deltaTimeSeconds = this._daltaTimeMilliseconds / 1e3;
301
- this._lastFrameTime = time;
302
- if (this._frameTime + 1e3 >= time) {
303
- this._frameCount += 1;
304
- } else {
305
- this._frameTime = time;
306
- this._fps = this._frameCount;
307
- this._frameCount = 0;
308
- }
309
- this._frameCountTotal++;
310
- this._avgDeltaTime = (this._avgDeltaTime * this._frameCount + this._daltaTimeMilliseconds) / (this._frameCount + 1);
272
+ get isRunning() {
273
+ return this._isRunning;
311
274
  }
312
- run(callback) {
275
+ start() {
313
276
  if (!this._isRunning) {
314
- this._frameCountTotal = 0;
315
277
  this._startTime = performance.now();
316
278
  this._isRunning = true;
317
- this._updateCallback = callback;
318
- requestAnimationFrame(this._update.bind(this));
279
+ const update = (time) => {
280
+ this._deltaTime = (time - this._time) / 1e3;
281
+ this._time = time;
282
+ if (this._frameTime + 1e3 >= time) {
283
+ this._frameCount += 1;
284
+ } else {
285
+ this._frameTime = time;
286
+ this._fps = this._frameCount;
287
+ this._frameCount = 0;
288
+ }
289
+ this.emit("frame", this._deltaTime);
290
+ if (this._isRunning) {
291
+ requestAnimationFrame(update);
292
+ }
293
+ };
294
+ requestAnimationFrame(update);
319
295
  }
320
296
  }
321
- runOnce(callback) {
322
- this._isRunning = false;
323
- this._updateCallback = callback;
324
- this._update(0);
325
- }
326
297
  stop() {
327
298
  this._isRunning = false;
328
299
  }
329
- getExecuteTime(func) {
330
- const now = performance.now();
331
- func();
332
- return performance.now() - now;
333
- }
334
- showStats(data = {}, parent) {
335
- parent = parent ?? this._statsParent ?? document.body;
336
- if (!this._stats) {
337
- this._stats = new ClockStats();
338
- this._stats.appendTo(parent);
339
- }
340
- this._stats.update({
341
- fps: this._fps,
342
- "deltaTime(s)": `${this._deltaTimeSeconds.toFixed(3)}`,
343
- "avgDeltaTime(ms)": `${this._avgDeltaTime.toFixed(3)}`,
344
- ...data
345
- });
346
- }
347
300
  };
348
301
 
349
- // src/logger.ts
350
- var logdev = console.debug.bind(console, "%c[dbg]", "font-weight: bold; color: #888;");
351
- var log = logdev;
352
- var loginf = console.log.bind(console, "%c[inf]", "font-weight: bold;");
353
- var logwrn = console.log.bind(console, "%c[wrn]", "font-weight: bold; color: orange;");
354
- var logerr = console.log.bind(console, "%c[err]", "font-weight: bold; color: red;");
355
-
356
- // src/math.ts
357
- var DEG2RAD = 0.01745329;
302
+ // src/math/math.ts
358
303
  var PI = 3.141592653589793;
359
- var TWO_PI = PI * 2;
304
+ var DOUBLE_PI = PI * 2;
360
305
  var HALF_PI = PI / 2;
361
- function abs(n) {
362
- return n < 0 ? -n : n;
363
- }
364
- function min(a, b) {
365
- return a < b ? a : b;
366
- }
367
- function max(a, b) {
368
- return a > b ? a : b;
369
- }
370
- function floor(n) {
306
+ var RADIAN_FACTOR = PI / 180;
307
+ var abs = (n) => n < 0 ? -n : n;
308
+ var min = (a, b) => a < b ? a : b;
309
+ var max = (a, b) => a > b ? a : b;
310
+ var floor = (n) => {
371
311
  const t = n | 0;
372
312
  return n < 0 && t !== n ? t - 1 : t;
373
- }
374
- function ceil(n) {
313
+ };
314
+ var ceil = (n) => {
375
315
  const t = n | 0;
376
316
  return n > 0 && t !== n ? t + 1 : t;
377
- }
378
- function round(n) {
379
- return floor(n + 0.5);
380
- }
381
- function sqrt(n) {
382
- return n ** 0.5;
383
- }
384
- function pow(base, exp) {
385
- return base ** exp;
386
- }
387
- function hypot2(x, y) {
388
- return (x * x + y * y) ** 0.5;
389
- }
390
- function hypot3(x, y, z) {
391
- return (x * x + y * y + z * z) ** 0.5;
392
- }
393
- function imul(a, b) {
317
+ };
318
+ var round = (n) => floor(n + 0.5);
319
+ var sqrt = (n) => n ** 0.5;
320
+ var pow = (base, exp) => base ** exp;
321
+ var hypot2 = (x, y) => (x * x + y * y) ** 0.5;
322
+ var hypot3 = (x, y, z) => (x * x + y * y + z * z) ** 0.5;
323
+ var imul = (a, b) => {
394
324
  b |= 0;
395
325
  let result = (a & 4194303) * b;
396
326
  if (a & 4290772992) result += (a & 4290772992) * b | 0;
397
327
  return result | 0;
398
- }
399
- function wrapAngle(n) {
400
- n = n % TWO_PI;
401
- if (n > PI) n -= TWO_PI;
402
- else if (n < -PI) n += TWO_PI;
328
+ };
329
+ var _wrapAngle = (n) => {
330
+ n = n % DOUBLE_PI;
331
+ if (n > PI) n -= DOUBLE_PI;
332
+ else if (n < -PI) n += DOUBLE_PI;
403
333
  return n;
404
- }
405
- function sinSeries(n) {
334
+ };
335
+ var _sinSeries = (n) => {
406
336
  const n2 = n * n;
407
337
  return n * (1 + n2 * (-1 / 6 + n2 * (1 / 120 + n2 * (-1 / 5040 + n2 * (1 / 362880 + n2 * (-1 / 39916800))))));
408
- }
409
- function cosSeries(n) {
338
+ };
339
+ var _cosSeries = (n) => {
410
340
  const n2 = n * n;
411
341
  return 1 + n2 * (-1 / 2 + n2 * (1 / 24 + n2 * (-1 / 720 + n2 * (1 / 40320 + n2 * (-1 / 3628800)))));
412
- }
413
- function reduceAngle(n) {
414
- let x = wrapAngle(n);
342
+ };
343
+ var _reduceAngle = (n) => {
344
+ let x = _wrapAngle(n);
415
345
  let sinSign = 1;
416
346
  if (x < 0) {
417
347
  x = -x;
@@ -423,207 +353,173 @@ function reduceAngle(n) {
423
353
  cosSign = -1;
424
354
  }
425
355
  return [x, sinSign, cosSign];
426
- }
427
- function sin(n) {
428
- const [x, sinSign] = reduceAngle(n);
429
- return sinSign * sinSeries(x);
430
- }
431
- function cos(n) {
432
- const [x, , cosSign] = reduceAngle(n);
433
- return cosSign * cosSeries(x);
434
- }
435
- function clamp(value, lo, hi) {
436
- return max(lo, min(hi, value));
437
- }
438
- function deg2rad(value) {
439
- return value * DEG2RAD;
440
- }
441
- function lerp(start, end, scale) {
442
- return start * (1 - scale) + end * scale;
443
- }
444
- function distance(x1, y1, x2, y2) {
445
- return hypot2(x2 - x1, y2 - y1);
446
- }
447
- function squaredDistance(x1, y1, x2, y2) {
356
+ };
357
+ var sin = (n) => {
358
+ const [x, sinSign] = _reduceAngle(n);
359
+ return sinSign * _sinSeries(x);
360
+ };
361
+ var cos = (n) => {
362
+ const [x, , cosSign] = _reduceAngle(n);
363
+ return cosSign * _cosSeries(x);
364
+ };
365
+ var clamp = (value, lo, hi) => max(lo, min(hi, value));
366
+ var deg2rad = (degree) => degree * RADIAN_FACTOR;
367
+ var lerp = (start, end, scale) => start * (1 - scale) + end * scale;
368
+ var distance2d = (x1, y1, x2, y2) => hypot2(x2 - x1, y2 - y1);
369
+ var distance3d = (x1, y1, z1, x2, y2, z2) => hypot3(x2 - x1, y2 - y1, z2 - z1);
370
+ var squaredDistance = (x1, y1, x2, y2) => {
448
371
  const dx = x1 - x2;
449
372
  const dy = y1 - y2;
450
373
  return dx * dx + dy * dy;
451
- }
452
- function manhattanDistance(x1, y1, x2, y2) {
453
- return abs(x1 - x2) + abs(y1 - y2);
454
- }
455
- function roundTo(value, digits, base = 10) {
374
+ };
375
+ var manhattanDistance = (x1, y1, x2, y2) => abs(x1 - x2) + abs(y1 - y2);
376
+ var roundTo = (value, digits, base = 10) => {
456
377
  const p = pow(base, digits);
457
378
  return round(value * p) / p;
458
- }
379
+ };
459
380
 
460
- // src/color.ts
461
- var Color = class _Color {
462
- _hex = "#ffffffff";
463
- _r = 255;
464
- _g = 255;
465
- _b = 255;
466
- _a = 255;
467
- get r() {
468
- return this._r;
381
+ // src/math/rectangle.ts
382
+ var Rectangle = class _Rectangle {
383
+ x;
384
+ y;
385
+ width;
386
+ height;
387
+ constructor(x = 0, y = 0, width = 1, height = 1) {
388
+ this.x = x;
389
+ this.y = y;
390
+ this.width = width;
391
+ this.height = height;
469
392
  }
470
- set r(value) {
471
- this._r = clamp(value, 0, 255);
472
- this._hex = this._to_hex();
393
+ area() {
394
+ return this.width * this.height;
473
395
  }
474
- get g() {
475
- return this._g;
396
+ contains(target, padding = 0) {
397
+ return target instanceof Vector ? target.x >= this.x - padding && target.x <= this.x + this.width + padding && target.y >= this.y - padding && target.y <= this.y + this.height + padding : target.x >= this.x + padding && target.y >= this.y + padding && target.x + target.width <= this.x + this.width - padding && target.y + target.height <= this.y + this.height - padding;
476
398
  }
477
- set g(value) {
478
- this._g = clamp(value, 0, 255);
479
- this._hex = this._to_hex();
399
+ intersects(other, padding = 0) {
400
+ return !(other.x - padding > this.x + this.width + padding || other.x + other.width + padding < this.x - padding || other.y - padding > this.y + this.height + padding || other.y + other.height + padding < this.y - padding);
480
401
  }
481
- get b() {
482
- return this._b;
402
+ center() {
403
+ return new Vector(
404
+ this.x + this.width / 2,
405
+ this.y + this.height / 2
406
+ );
483
407
  }
484
- set b(value) {
485
- this._b = clamp(value, 0, 255);
486
- this._hex = this._to_hex();
408
+ distanceTo(other) {
409
+ return this.center().distanceTo(other.center());
487
410
  }
488
- get a() {
489
- return this._a;
411
+ clone() {
412
+ return new _Rectangle(this.x, this.y, this.width, this.height);
490
413
  }
491
- set a(value) {
492
- this._a = clamp(value, 0, 255);
493
- this._hex = this._to_hex();
414
+ equals(other) {
415
+ return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
494
416
  }
495
- get hexStr() {
496
- return this._hex;
417
+ grow(padding) {
418
+ return new _Rectangle(
419
+ this.x - padding,
420
+ this.y - padding,
421
+ this.width + padding * 2,
422
+ this.height + padding * 2
423
+ );
497
424
  }
498
- set hexStr(value) {
499
- if (value.startsWith("#")) {
500
- [this._r, this._g, this._b, this._a] = this._parse_hex_color_string(value);
501
- this._hex = value;
502
- } else {
503
- logwrn(`Color: invalid color string: ${value}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Keeping the current color.`);
425
+ vectorInside(vec, padding = 0) {
426
+ return vec.x >= this.x - padding && vec.x <= this.x + this.width + padding && vec.y >= this.y - padding && vec.y <= this.y + this.height + padding;
427
+ }
428
+ };
429
+
430
+ // src/math/vector.ts
431
+ var Vector = class _Vector {
432
+ x;
433
+ y;
434
+ constructor(x = 0, y = 0) {
435
+ this.x = x;
436
+ this.y = y;
437
+ }
438
+ clone() {
439
+ return new _Vector(this.x, this.y);
440
+ }
441
+ distanceTo(that) {
442
+ return distance2d(
443
+ this.x,
444
+ this.y,
445
+ that.x,
446
+ that.y
447
+ );
448
+ }
449
+ floored() {
450
+ return new _Vector(
451
+ Math.floor(this.x),
452
+ Math.floor(this.y)
453
+ );
454
+ }
455
+ plus(x, y) {
456
+ if (x instanceof _Vector) {
457
+ y = x.y;
458
+ x = x.x;
459
+ } else if (y === void 0) {
460
+ y = x;
504
461
  }
462
+ this.x += x;
463
+ this.y += y;
464
+ return this;
505
465
  }
506
- get rgba() {
507
- return [this._r, this._g, this._b, this._a];
466
+ minus(x, y) {
467
+ if (x instanceof _Vector) {
468
+ y = x.y;
469
+ x = x.x;
470
+ } else if (y === void 0) {
471
+ y = x;
472
+ }
473
+ this.x -= x;
474
+ this.y -= y;
475
+ return this;
508
476
  }
509
- constructor(r = 255, g = 255, b = 255, a = 255) {
510
- if (typeof r === "string") {
511
- if (r.startsWith("#")) {
512
- [r, g, b, a] = this._parse_hex_color_string(r);
513
- } else {
514
- logwrn(`Color: invalid color string: ${r}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Defaulting to opaque white.`);
515
- r = g = b = a = 255;
516
- }
517
- } else {
518
- [r, g, b, a] = [r, g, b, a].map((n) => _Color._normalize(n));
477
+ times(x, y) {
478
+ if (x instanceof _Vector) {
479
+ y = x.y;
480
+ x = x.x;
481
+ } else if (y === void 0) {
482
+ y = x;
519
483
  }
520
- this.r = r;
521
- this.g = g;
522
- this.b = b;
523
- this.a = a;
484
+ this.x *= x;
485
+ this.y *= y;
486
+ return this;
524
487
  }
525
- static _normalize(value) {
526
- return clamp(0 | (value > 0 && value < 1 ? value * 255 : value), 0, 255);
488
+ dividedBy(x, y) {
489
+ if (x instanceof _Vector) {
490
+ y = x.y;
491
+ x = x.x;
492
+ } else if (y === void 0) {
493
+ y = x;
494
+ }
495
+ this.x /= x || 1;
496
+ this.y /= y || 1;
497
+ return this;
527
498
  }
528
- _to_hex() {
529
- return `#${this.r.toString(16).padStart(2, "0")}${this.g.toString(16).padStart(2, "0")}${this.b.toString(16).padStart(2, "0")}${this.a.toString(16).padStart(2, "0")}`;
499
+ static get NORTH() {
500
+ return new _Vector(0, -1);
530
501
  }
531
- _parse_hex_color_string(hex) {
532
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex);
533
- return result ? [
534
- parseInt(result[1], 16),
535
- parseInt(result[2], 16),
536
- parseInt(result[3], 16),
537
- result[4] ? parseInt(result[4], 16) : 255
538
- ] : [255, 255, 255, 255];
539
- }
540
- static fromHsv(h, s, v, a = 255) {
541
- let r = 0;
542
- let g = 0;
543
- let b = 0;
544
- let i = Math.floor(h * 6);
545
- let f = h * 6 - i;
546
- let p = v * (1 - s);
547
- let q = v * (1 - f * s);
548
- let t = v * (1 - (1 - f) * s);
549
- switch (i % 6) {
550
- case 0:
551
- r = v, g = t, b = p;
552
- break;
553
- case 1:
554
- r = q, g = v, b = p;
555
- break;
556
- case 2:
557
- r = p, g = v, b = t;
558
- break;
559
- case 3:
560
- r = p, g = q, b = v;
561
- break;
562
- case 4:
563
- r = t, g = p, b = v;
564
- break;
565
- case 5:
566
- r = v, g = p, b = q;
567
- break;
568
- }
569
- return new _Color(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
570
- }
571
- static get BLACK() {
572
- return new _Color(0, 0, 0, 255);
573
- }
574
- static get GRAY() {
575
- return new _Color(128, 128, 128, 255);
576
- }
577
- static get WHITE() {
578
- return new _Color(255, 255, 255, 255);
579
- }
580
- static get RED() {
581
- return new _Color(255, 0, 0, 255);
582
- }
583
- static get GREEN() {
584
- return new _Color(0, 255, 0, 255);
585
- }
586
- static get BLUE() {
587
- return new _Color(0, 0, 255, 255);
588
- }
589
- static get YELLOW() {
590
- return new _Color(255, 255, 0, 255);
591
- }
592
- static get ORANGE() {
593
- return new _Color(255, 128, 0, 255);
594
- }
595
- static get PURPLE() {
596
- return new _Color(128, 0, 128, 255);
597
- }
598
- static get CYAN() {
599
- return new _Color(0, 255, 255, 255);
600
- }
601
- static get MAGENTA() {
602
- return new _Color(255, 0, 255, 255);
502
+ static get SOUTH() {
503
+ return new _Vector(0, 1);
603
504
  }
604
- static fromName(name) {
605
- const element = document.createElement("div");
606
- element.style.color = name;
607
- document.body.appendChild(element);
608
- const computedColor = getComputedStyle(element).color;
609
- document.body.removeChild(element);
610
- const rgba = computedColor.match(/\d+/g);
611
- if (rgba && rgba.length === 4) {
612
- const [r, g, b, a] = rgba.map(Number);
613
- return new _Color(r, g, b, a);
614
- } else {
615
- logwrn(`Color: invalid CSS color name: ${name}. Defaulting to transparent.`);
616
- return _Color.TRANSPARENT;
617
- }
505
+ static get EAST() {
506
+ return new _Vector(1, 0);
618
507
  }
619
- static get TRANSPARENT() {
620
- return new _Color(0, 0, 0, 0);
508
+ static get WEST() {
509
+ return new _Vector(-1, 0);
621
510
  }
622
511
  };
623
512
 
624
513
  // src/dungeon-generator.ts
625
514
  var import_heap_js = require("heap-js");
626
515
 
516
+ // src/logger.ts
517
+ var logdev = console.debug.bind(console, "%c[dbg]", "font-weight: bold; color: #888;");
518
+ var log = logdev;
519
+ var loginf = console.log.bind(console, "%c[inf]", "font-weight: bold;");
520
+ var logwrn = console.log.bind(console, "%c[wrn]", "font-weight: bold; color: orange;");
521
+ var logerr = console.log.bind(console, "%c[err]", "font-weight: bold; color: red;");
522
+
627
523
  // src/map2d.ts
628
524
  var DEFAULT_VALUE = -1;
629
525
  var Map2D = class {
@@ -669,140 +565,8 @@ var Map2D = class {
669
565
  }
670
566
  };
671
567
 
672
- // src/vector.ts
673
- var Vector = class _Vector {
674
- x;
675
- y;
676
- constructor(x = 0, y = 0) {
677
- this.x = x;
678
- this.y = y;
679
- }
680
- clone() {
681
- return new _Vector(this.x, this.y);
682
- }
683
- distanceTo(that) {
684
- return distance(
685
- this.x,
686
- this.y,
687
- that.x,
688
- that.y
689
- );
690
- }
691
- floored() {
692
- return new _Vector(
693
- Math.floor(this.x),
694
- Math.floor(this.y)
695
- );
696
- }
697
- plus(x, y) {
698
- if (x instanceof _Vector) {
699
- y = x.y;
700
- x = x.x;
701
- } else if (y === void 0) {
702
- y = x;
703
- }
704
- this.x += x;
705
- this.y += y;
706
- return this;
707
- }
708
- minus(x, y) {
709
- if (x instanceof _Vector) {
710
- y = x.y;
711
- x = x.x;
712
- } else if (y === void 0) {
713
- y = x;
714
- }
715
- this.x -= x;
716
- this.y -= y;
717
- return this;
718
- }
719
- times(x, y) {
720
- if (x instanceof _Vector) {
721
- y = x.y;
722
- x = x.x;
723
- } else if (y === void 0) {
724
- y = x;
725
- }
726
- this.x *= x;
727
- this.y *= y;
728
- return this;
729
- }
730
- dividedBy(x, y) {
731
- if (x instanceof _Vector) {
732
- y = x.y;
733
- x = x.x;
734
- } else if (y === void 0) {
735
- y = x;
736
- }
737
- this.x /= x || 1;
738
- this.y /= y || 1;
739
- return this;
740
- }
741
- static get NORTH() {
742
- return new _Vector(0, -1);
743
- }
744
- static get SOUTH() {
745
- return new _Vector(0, 1);
746
- }
747
- static get EAST() {
748
- return new _Vector(1, 0);
749
- }
750
- static get WEST() {
751
- return new _Vector(-1, 0);
752
- }
753
- };
754
-
755
- // src/rectangle.ts
756
- var Rectangle = class _Rectangle {
757
- x;
758
- y;
759
- width;
760
- height;
761
- constructor(x = 0, y = 0, width = 1, height = 1) {
762
- this.x = x;
763
- this.y = y;
764
- this.width = width;
765
- this.height = height;
766
- }
767
- area() {
768
- return this.width * this.height;
769
- }
770
- contains(target, padding = 0) {
771
- return target instanceof Vector ? target.x >= this.x - padding && target.x <= this.x + this.width + padding && target.y >= this.y - padding && target.y <= this.y + this.height + padding : target.x >= this.x + padding && target.y >= this.y + padding && target.x + target.width <= this.x + this.width - padding && target.y + target.height <= this.y + this.height - padding;
772
- }
773
- intersects(other, padding = 0) {
774
- return !(other.x - padding > this.x + this.width + padding || other.x + other.width + padding < this.x - padding || other.y - padding > this.y + this.height + padding || other.y + other.height + padding < this.y - padding);
775
- }
776
- center() {
777
- return new Vector(
778
- this.x + this.width / 2,
779
- this.y + this.height / 2
780
- );
781
- }
782
- distanceTo(other) {
783
- return this.center().distanceTo(other.center());
784
- }
785
- clone() {
786
- return new _Rectangle(this.x, this.y, this.width, this.height);
787
- }
788
- equals(other) {
789
- return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
790
- }
791
- grow(padding) {
792
- return new _Rectangle(
793
- this.x - padding,
794
- this.y - padding,
795
- this.width + padding * 2,
796
- this.height + padding * 2
797
- );
798
- }
799
- vectorInside(vec, padding = 0) {
800
- return vec.x >= this.x - padding && vec.x <= this.x + this.width + padding && vec.y >= this.y - padding && vec.y <= this.y + this.height + padding;
801
- }
802
- };
803
-
804
568
  // src/rng.ts
805
- var Rng = class {
569
+ var RandomNumberGenerator = class {
806
570
  __seed;
807
571
  _seed;
808
572
  _uid_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -834,10 +598,6 @@ var Rng = class {
834
598
  get nexti() {
835
599
  return this.nextf * Number.MAX_SAFE_INTEGER | 0;
836
600
  }
837
- // NOTE: as of the core/apparatus consolidation, range(min, max) treats
838
- // max as EXCLUSIVE (previous published versions of this package treated
839
- // it as inclusive - if you're upgrading from an older @n3rdw1z4rd/core,
840
- // range(0, 10) now returns [0, 10) instead of [0, 10]).
841
601
  range(min2, max2) {
842
602
  if (max2 === void 0) {
843
603
  max2 = min2;
@@ -849,9 +609,6 @@ var Rng = class {
849
609
  const theta = this.nextf * 2 * PI;
850
610
  return [cos(theta), sin(theta)];
851
611
  }
852
- // Box-Muller-ish gaussian sample, mean 0.5 stddev 1/6 (so ~99.7% of
853
- // samples land in [0, 1]). Uses native Math.log since a pure natural-log
854
- // implementation isn't part of math.ts yet.
855
612
  parkMillerNormal() {
856
613
  const mean = 1 / 2;
857
614
  const stddev = 1 / 6;
@@ -899,7 +656,7 @@ var Rng = class {
899
656
  return rows;
900
657
  }
901
658
  };
902
- var rng = new Rng();
659
+ var rng = new RandomNumberGenerator();
903
660
 
904
661
  // src/dungeon-generator.ts
905
662
  var TILE_EMPTY = 0;
@@ -1056,7 +813,7 @@ function _getShortestPathBetweenRects(rectA, rectB) {
1056
813
  let paths = { a: edgeA[0], b: edgeB[0], distance: Infinity };
1057
814
  for (const a of edgeA) {
1058
815
  for (const b of edgeB) {
1059
- const d = distance(a.x, a.y, b.x, b.y);
816
+ const d = distance2d(a.x, a.y, b.x, b.y);
1060
817
  if (d < paths.distance) {
1061
818
  paths = { a, b, distance: d };
1062
819
  }
@@ -1334,58 +1091,19 @@ var ECS = class _ECS {
1334
1091
  }
1335
1092
  };
1336
1093
 
1337
- // src/emitter.ts
1338
- var Emitter = class {
1339
- listeners = /* @__PURE__ */ new Map();
1340
- constructor() {
1094
+ // src/input/index.ts
1095
+ var Input = class extends Emitter {
1096
+ inputThreshold = 200;
1097
+ _keyStates = {};
1098
+ _mouseButtonStates = {};
1099
+ _mousePosition = [0, 0];
1100
+ _mousePosition2 = [0, 0];
1101
+ _contextMenuTarget;
1102
+ get mousePosition() {
1103
+ return this._mousePosition;
1341
1104
  }
1342
- on(...eventName) {
1343
- const listener = eventName.pop();
1344
- const events = eventName.filter((ev) => typeof ev === "string");
1345
- events.forEach((event) => {
1346
- if (!this.listeners.has(event)) {
1347
- this.listeners.set(event, new Array());
1348
- }
1349
- this.listeners.get(event)?.push(listener);
1350
- });
1351
- return this;
1352
- }
1353
- emit(eventName, ...args) {
1354
- this.listeners.get(eventName)?.forEach((listener) => listener(...args, eventName));
1355
- return this;
1356
- }
1357
- clear(eventName) {
1358
- if (eventName) {
1359
- this.listeners.delete(eventName);
1360
- } else {
1361
- this.listeners.clear();
1362
- }
1363
- return this;
1364
- }
1365
- };
1366
- var GlobalEmitter = new Emitter();
1367
- var EventBus = class extends EventTarget {
1368
- emit(type, detail) {
1369
- this.dispatchEvent(new CustomEvent(type, { detail }));
1370
- }
1371
- on(type, cb) {
1372
- this.addEventListener(type, cb);
1373
- }
1374
- };
1375
- var eventBus = new EventBus();
1376
-
1377
- // src/input.ts
1378
- var Input = class extends Emitter {
1379
- inputThreshold = 200;
1380
- _keyStates = {};
1381
- _mouseButtonStates = {};
1382
- _mousePosition = [0, 0];
1383
- _mousePosition2 = [0, 0];
1384
- get mousePosition() {
1385
- return this._mousePosition;
1386
- }
1387
- get mousePosition2() {
1388
- return this._mousePosition2;
1105
+ get mousePosition2() {
1106
+ return this._mousePosition2;
1389
1107
  }
1390
1108
  constructor() {
1391
1109
  super();
@@ -1396,6 +1114,19 @@ var Input = class extends Emitter {
1396
1114
  window.addEventListener("mousemove", this._onMouseMove.bind(this));
1397
1115
  window.addEventListener("wheel", this._onWheel.bind(this));
1398
1116
  }
1117
+ blockContextMenu(target) {
1118
+ this.stopBlockingContextMenu();
1119
+ this._contextMenuTarget = target;
1120
+ target.addEventListener("contextmenu", this._onContextMenu);
1121
+ }
1122
+ stopBlockingContextMenu() {
1123
+ this._contextMenuTarget?.removeEventListener("contextmenu", this._onContextMenu);
1124
+ this._contextMenuTarget = void 0;
1125
+ }
1126
+ _onContextMenu = (ev) => {
1127
+ ev.preventDefault();
1128
+ this.emit("contextmenu");
1129
+ };
1399
1130
  _getCommonEventProps(ev) {
1400
1131
  const props = {
1401
1132
  timeStamp: ev.timeStamp,
@@ -1406,11 +1137,6 @@ var Input = class extends Emitter {
1406
1137
  };
1407
1138
  return props;
1408
1139
  }
1409
- // private _onContextMenu(ev: MouseEvent) {
1410
- // ev.preventDefault();
1411
- // this.emit('contextmenu');
1412
- // return false;
1413
- // }
1414
1140
  _onKeyDown(ev) {
1415
1141
  const props = this._getCommonEventProps(ev);
1416
1142
  const { code, key } = ev;
@@ -1545,6 +1271,9 @@ var Map3D = class {
1545
1271
  function isNullOrUndefined(target) {
1546
1272
  return target === null || target === void 0;
1547
1273
  }
1274
+ function isPositiveString(target) {
1275
+ return target.length > 0;
1276
+ }
1548
1277
  var getRedYellowGreenGradientHex = (min2, max2) => {
1549
1278
  if (max2 === void 0) {
1550
1279
  max2 = min2;
@@ -1569,6 +1298,14 @@ var getRedYellowGreenGradientHex = (min2, max2) => {
1569
1298
  "#00ff00"
1570
1299
  ][index];
1571
1300
  };
1301
+ function GetUrlParams() {
1302
+ const params = {};
1303
+ const url = new URLSearchParams(location.search);
1304
+ for (const [key, value] of url.entries()) {
1305
+ params[key] = value;
1306
+ }
1307
+ return params;
1308
+ }
1572
1309
 
1573
1310
  // src/noise.ts
1574
1311
  var import_simplex_noise = require("simplex-noise");
@@ -1631,57 +1368,167 @@ var Noise = class _Noise {
1631
1368
  }
1632
1369
  };
1633
1370
 
1634
- // src/particle-renderer.ts
1635
- var Renderer = class {
1636
- _screenCanvas;
1637
- _bufferCanvas;
1638
- screenContext;
1639
- bufferContext;
1640
- get width() {
1641
- return this._screenCanvas.width;
1371
+ // src/rendering/color.ts
1372
+ var Color = class _Color {
1373
+ _hex = "#ffffffff";
1374
+ _r = 255;
1375
+ _g = 255;
1376
+ _b = 255;
1377
+ _a = 255;
1378
+ get r() {
1379
+ return this._r;
1642
1380
  }
1643
- get height() {
1644
- return this._screenCanvas.height;
1381
+ set r(value) {
1382
+ this._r = clamp(value, 0, 255);
1383
+ this._hex = this._to_hex();
1645
1384
  }
1646
- constructor(canvas) {
1647
- this._screenCanvas = canvas ?? document.createElement("canvas");
1648
- this._bufferCanvas = new OffscreenCanvas(this._screenCanvas.width, this._screenCanvas.height);
1649
- this.screenContext = this._screenCanvas.getContext("2d");
1650
- this.bufferContext = this._bufferCanvas.getContext("2d");
1651
- if (!this.screenContext || !this.bufferContext) {
1652
- throw "Failed to create CanvasRenderingContext2D";
1653
- }
1385
+ get g() {
1386
+ return this._g;
1654
1387
  }
1655
- appendTo(target, autoResize = true) {
1656
- if (this._screenCanvas.parentNode) {
1657
- this._screenCanvas.parentNode.removeChild(this._screenCanvas);
1388
+ set g(value) {
1389
+ this._g = clamp(value, 0, 255);
1390
+ this._hex = this._to_hex();
1391
+ }
1392
+ get b() {
1393
+ return this._b;
1394
+ }
1395
+ set b(value) {
1396
+ this._b = clamp(value, 0, 255);
1397
+ this._hex = this._to_hex();
1398
+ }
1399
+ get a() {
1400
+ return this._a;
1401
+ }
1402
+ set a(value) {
1403
+ this._a = clamp(value, 0, 255);
1404
+ this._hex = this._to_hex();
1405
+ }
1406
+ get hexStr() {
1407
+ return this._hex;
1408
+ }
1409
+ set hexStr(value) {
1410
+ if (value.startsWith("#")) {
1411
+ [this._r, this._g, this._b, this._a] = this._parse_hex_color_string(value);
1412
+ this._hex = value;
1413
+ } else {
1414
+ logwrn(`Color: invalid color string: ${value}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Keeping the current color.`);
1658
1415
  }
1659
- target.appendChild(this._screenCanvas);
1660
- if (autoResize) {
1661
- this.resize();
1416
+ }
1417
+ get rgba() {
1418
+ return [this._r, this._g, this._b, this._a];
1419
+ }
1420
+ constructor(r = 255, g = 255, b = 255, a = 255) {
1421
+ if (typeof r === "string") {
1422
+ if (r.startsWith("#")) {
1423
+ [r, g, b, a] = this._parse_hex_color_string(r);
1424
+ } else {
1425
+ logwrn(`Color: invalid color string: ${r}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Defaulting to opaque white.`);
1426
+ r = g = b = a = 255;
1427
+ }
1428
+ } else {
1429
+ [r, g, b, a] = [r, g, b, a].map((n) => _Color._normalize(n));
1662
1430
  }
1431
+ this.r = r;
1432
+ this.g = g;
1433
+ this.b = b;
1434
+ this.a = a;
1663
1435
  }
1664
- resize(displayWidth, displayHeight) {
1665
- const { width, height } = this._screenCanvas.parentElement?.getBoundingClientRect() ?? this._screenCanvas.getBoundingClientRect();
1666
- displayWidth = 0 | (displayWidth ?? width);
1667
- displayHeight = 0 | (displayHeight ?? height);
1668
- if (this._screenCanvas.width !== displayWidth || this._screenCanvas.height !== displayHeight) {
1669
- this._screenCanvas.width = displayWidth;
1670
- this._screenCanvas.height = displayHeight;
1671
- this._bufferCanvas.width = displayWidth;
1672
- this._bufferCanvas.height = displayHeight;
1673
- return true;
1436
+ static _normalize(value) {
1437
+ return clamp(0 | (value > 0 && value < 1 ? value * 255 : value), 0, 255);
1438
+ }
1439
+ _to_hex() {
1440
+ return `#${this.r.toString(16).padStart(2, "0")}${this.g.toString(16).padStart(2, "0")}${this.b.toString(16).padStart(2, "0")}${this.a.toString(16).padStart(2, "0")}`;
1441
+ }
1442
+ _parse_hex_color_string(hex) {
1443
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex);
1444
+ return result ? [
1445
+ parseInt(result[1], 16),
1446
+ parseInt(result[2], 16),
1447
+ parseInt(result[3], 16),
1448
+ result[4] ? parseInt(result[4], 16) : 255
1449
+ ] : [255, 255, 255, 255];
1450
+ }
1451
+ static fromHsv(h, s, v, a = 255) {
1452
+ let r = 0;
1453
+ let g = 0;
1454
+ let b = 0;
1455
+ let i = Math.floor(h * 6);
1456
+ let f = h * 6 - i;
1457
+ let p = v * (1 - s);
1458
+ let q = v * (1 - f * s);
1459
+ let t = v * (1 - (1 - f) * s);
1460
+ switch (i % 6) {
1461
+ case 0:
1462
+ r = v, g = t, b = p;
1463
+ break;
1464
+ case 1:
1465
+ r = q, g = v, b = p;
1466
+ break;
1467
+ case 2:
1468
+ r = p, g = v, b = t;
1469
+ break;
1470
+ case 3:
1471
+ r = p, g = q, b = v;
1472
+ break;
1473
+ case 4:
1474
+ r = t, g = p, b = v;
1475
+ break;
1476
+ case 5:
1477
+ r = v, g = p, b = q;
1478
+ break;
1674
1479
  }
1675
- return false;
1480
+ return new _Color(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
1676
1481
  }
1677
- setPixel(x, y, color, size = 2) {
1678
- this.bufferContext.fillStyle = color.hexStr;
1679
- this.bufferContext.fillRect(x - size / 2, y - size / 2, size, size);
1482
+ static get BLACK() {
1483
+ return new _Color(0, 0, 0, 255);
1680
1484
  }
1681
- render() {
1682
- this.screenContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
1683
- this.screenContext.drawImage(this._bufferCanvas, 0, 0);
1684
- this.bufferContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
1485
+ static get GRAY() {
1486
+ return new _Color(128, 128, 128, 255);
1487
+ }
1488
+ static get WHITE() {
1489
+ return new _Color(255, 255, 255, 255);
1490
+ }
1491
+ static get RED() {
1492
+ return new _Color(255, 0, 0, 255);
1493
+ }
1494
+ static get GREEN() {
1495
+ return new _Color(0, 255, 0, 255);
1496
+ }
1497
+ static get BLUE() {
1498
+ return new _Color(0, 0, 255, 255);
1499
+ }
1500
+ static get YELLOW() {
1501
+ return new _Color(255, 255, 0, 255);
1502
+ }
1503
+ static get ORANGE() {
1504
+ return new _Color(255, 128, 0, 255);
1505
+ }
1506
+ static get PURPLE() {
1507
+ return new _Color(128, 0, 128, 255);
1508
+ }
1509
+ static get CYAN() {
1510
+ return new _Color(0, 255, 255, 255);
1511
+ }
1512
+ static get MAGENTA() {
1513
+ return new _Color(255, 0, 255, 255);
1514
+ }
1515
+ static fromName(name) {
1516
+ const element = document.createElement("div");
1517
+ element.style.color = name;
1518
+ document.body.appendChild(element);
1519
+ const computedColor = getComputedStyle(element).color;
1520
+ document.body.removeChild(element);
1521
+ const rgba = computedColor.match(/\d+/g);
1522
+ if (rgba && rgba.length === 4) {
1523
+ const [r, g, b, a] = rgba.map(Number);
1524
+ return new _Color(r, g, b, a);
1525
+ } else {
1526
+ logwrn(`Color: invalid CSS color name: ${name}. Defaulting to transparent.`);
1527
+ return _Color.TRANSPARENT;
1528
+ }
1529
+ }
1530
+ static get TRANSPARENT() {
1531
+ return new _Color(0, 0, 0, 0);
1685
1532
  }
1686
1533
  };
1687
1534
 
@@ -1908,547 +1755,212 @@ function PoissonDiskSampler(width, height, minDist, maxPoints = 30) {
1908
1755
  return samples;
1909
1756
  }
1910
1757
 
1911
- // src/renderer/canvas-renderer.ts
1758
+ // src/rendering/canvas-renderer.ts
1912
1759
  var CanvasRenderer = class {
1913
- ctx;
1914
- clearColor = "#000000";
1915
- fontName = "monospace";
1916
- fontSize = 32;
1917
- textAlign = "center";
1918
- textBaseline = "middle";
1760
+ canvas;
1761
+ context;
1762
+ drawCentered = true;
1919
1763
  get width() {
1920
- return this.ctx?.canvas.width ?? 0;
1764
+ return this.context.canvas.width;
1921
1765
  }
1922
1766
  get height() {
1923
- return this.ctx?.canvas.height ?? 0;
1924
- }
1925
- get center() {
1926
- return [this.width / 2, this.height / 2];
1767
+ return this.context.canvas.height;
1927
1768
  }
1928
1769
  constructor(canvas) {
1929
- this.ctx = (canvas ?? document.createElement("canvas")).getContext("2d");
1930
- this.ctx.canvas.style.backgroundColor = "#000000";
1931
- this.ctx.canvas.style.display = "block";
1932
- this.ctx.font = `${this.fontSize}px ${this.fontName}`;
1933
- this.ctx.textAlign = this.textAlign;
1934
- this.ctx.textBaseline = this.textBaseline;
1935
- this.resize();
1936
- this.clear();
1770
+ this.canvas = canvas ?? document.createElement("canvas");
1771
+ this.context = this.canvas.getContext("2d");
1937
1772
  }
1938
- appendTo(target, autoResize = true) {
1939
- if (this.ctx.canvas.parentElement) {
1940
- this.ctx.canvas.parentElement.removeChild(this.ctx.canvas);
1941
- }
1942
- if (target) {
1943
- target.appendChild(this.ctx.canvas);
1944
- if (autoResize) {
1945
- this.resize();
1946
- }
1773
+ appendTo(target) {
1774
+ if (this.canvas.parentNode) {
1775
+ this.canvas.parentNode.removeChild(this.canvas);
1947
1776
  }
1777
+ target.appendChild(this.canvas);
1948
1778
  }
1949
1779
  resize(displayWidth, displayHeight) {
1950
- let resized = false;
1951
- const { width, height } = this.ctx.canvas.parentElement?.getBoundingClientRect() ?? this.ctx.canvas.getBoundingClientRect();
1780
+ const { width, height } = this.canvas.parentElement?.getBoundingClientRect() ?? this.canvas.getBoundingClientRect();
1952
1781
  displayWidth = 0 | (displayWidth ?? width);
1953
1782
  displayHeight = 0 | (displayHeight ?? height);
1954
- if (this.width !== displayWidth || this.height !== displayHeight) {
1955
- this.ctx.canvas.width = displayWidth;
1956
- this.ctx.canvas.height = displayHeight;
1957
- resized = true;
1783
+ if (this.canvas.width !== displayWidth || this.canvas.height !== displayHeight) {
1784
+ this.canvas.width = displayWidth;
1785
+ this.canvas.height = displayHeight;
1786
+ return true;
1958
1787
  }
1959
- return resized;
1788
+ return false;
1960
1789
  }
1961
1790
  clear() {
1962
- this.ctx?.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
1963
- }
1964
- drawPoint(xy, params = {}) {
1965
- const [x, y] = xy;
1966
- const radius = params.radius || 1;
1967
- const fill = params.fill !== false;
1968
- const color = params.color || "#000000";
1969
- this.ctx.fillStyle = color;
1970
- this.ctx.strokeStyle = color;
1971
- this.ctx.beginPath();
1972
- this.ctx.arc(x, y, radius, 0, 2 * Math.PI);
1973
- this.ctx[fill ? "fill" : "stroke"]();
1974
- }
1975
- drawBox(xy, wh, params = {}) {
1976
- const [x, y] = xy;
1977
- const [w, h] = wh;
1978
- const fill = params.fill !== false;
1979
- const color = params.color || "#000000";
1980
- this.ctx.fillStyle = color;
1981
- this.ctx.strokeStyle = color;
1982
- this.ctx.beginPath();
1983
- this.ctx.moveTo(x, y);
1984
- this.ctx.lineTo(x + w, y);
1985
- this.ctx.lineTo(x + w, y + h);
1986
- this.ctx.lineTo(x, y + h);
1987
- this.ctx.closePath();
1988
- this.ctx[fill ? "fill" : "stroke"]();
1989
- }
1990
- drawLine(x1y1x2y2, color = "#000000") {
1991
- const [x1, y1, x2, y2] = x1y1x2y2;
1992
- this.ctx.strokeStyle = color;
1993
- this.ctx.beginPath();
1994
- this.ctx.moveTo(x1, y1);
1995
- this.ctx.lineTo(x2, y2);
1996
- this.ctx.stroke();
1997
- }
1998
- drawText(text, xy, color = "#ffffff", size = this.fontSize, font = this.fontName) {
1999
- const [x, y] = xy;
2000
- this.ctx.fillStyle = color;
2001
- this.ctx.font = `${size}px ${font}`;
2002
- this.ctx.textAlign = this.textAlign;
2003
- this.ctx.textBaseline = this.textBaseline;
2004
- this.ctx.fillText(text, x, y + 0.5);
2005
- }
2006
- // drawNamePlate(name: string, title: string, color = '#bbbbbb', s: number = 12, tile_size: number = 32) {
2007
- // let x = (actor.position.x * tile_size);
2008
- // let y = (actor.position.y * tile_size) - 18;
2009
- // let healthPercent = (actor.health / actor.maxHealth);
2010
- // let healthBarWidth = (healthPercent * tile_size)
2011
- // let healthColor = getRedYellowGreenGradientHex(actor.health, actor.maxHealth);
2012
- // this.drawBox(x, y, tile_size, 3, { fill: true, color: '#666666' });
2013
- // this.drawBox(x, y, healthBarWidth, 3, { fill: true, color: healthColor });
2014
- // if (actor.title) {
2015
- // this.drawBox(x, y - 16, actor.name.length * (this.fontSize / 5), 10, { fill: true, color: '#000000' });
2016
- // this.drawText(actor.name || '', x, y - 16, color, s);
2017
- // this.drawBox(x, y - 7, actor.title.length * (this.fontSize / 5), 10, { fill: true, color: '#000000' });
2018
- // this.drawText(`<${actor.title}>`, x, y - 6, '#00FFFF', s);
2019
- // } else {
2020
- // this.drawBox(x, y - 6, actor.name.length * (this.fontSize / 5), 10, { fill: true, color: '#000000' });
2021
- // this.drawText(actor.name || '', x, y - 6, color, s);
2022
- // }
2023
- // }
1791
+ this.context.clearRect(0, 0, this.width, this.height);
1792
+ }
1793
+ drawRect(x, y, width, height, params = {}) {
1794
+ if (this.drawCentered) {
1795
+ x -= width / 2;
1796
+ y -= height / 2;
1797
+ }
1798
+ this.context.strokeStyle = params.strokeColor ?? params.color ?? "white";
1799
+ this.context.fillStyle = params.fillColor ?? params.color ?? "white";
1800
+ this.context.lineWidth = params.size ?? 1;
1801
+ if (params.lineDash) {
1802
+ this.context.setLineDash(params.lineDash);
1803
+ }
1804
+ this.context.beginPath();
1805
+ if (params.filled === true) {
1806
+ this.context.fillRect(x, y, width, height);
1807
+ if (params.strokeColor !== void 0) this.context.strokeRect(x, y, width, height);
1808
+ } else {
1809
+ this.context.strokeRect(x, y, width, height);
1810
+ }
1811
+ if (params.lineDash) {
1812
+ this.context.setLineDash([]);
1813
+ }
1814
+ }
1815
+ drawPixel(x, y, params = {}) {
1816
+ const size = abs(params.size || 1);
1817
+ this.drawRect(x, y, size, size, {
1818
+ ...params,
1819
+ filled: true
1820
+ });
1821
+ }
1822
+ drawLine(x1, y1, x2, y2, params = {}) {
1823
+ this.context.strokeStyle = params.color ?? "white";
1824
+ this.context.lineWidth = params.size ?? 1;
1825
+ if (params.lineDash) {
1826
+ this.context.setLineDash(params.lineDash);
1827
+ }
1828
+ this.context.beginPath();
1829
+ this.context.moveTo(x1, y1);
1830
+ this.context.lineTo(x2, y2);
1831
+ this.context.stroke();
1832
+ if (params.lineDash) {
1833
+ this.context.setLineDash([]);
1834
+ }
1835
+ }
1836
+ drawCircle(x, y, radius, params = {}) {
1837
+ this.context.strokeStyle = params.strokeColor ?? params.color ?? "white";
1838
+ this.context.fillStyle = params.fillColor ?? params.color ?? "white";
1839
+ this.context.lineWidth = params.size ?? 1;
1840
+ if (params.lineDash) {
1841
+ this.context.setLineDash(params.lineDash);
1842
+ }
1843
+ this.context.beginPath();
1844
+ this.context.arc(x, y, radius, 0, 2 * PI);
1845
+ if (params.filled === true) this.context.fill();
1846
+ this.context.stroke();
1847
+ if (params.lineDash) {
1848
+ this.context.setLineDash([]);
1849
+ }
1850
+ }
1851
+ drawText(x, y, text, params = {}) {
1852
+ this.context.font = `${params.size ?? 14}px ${params.fontName ?? "monospace"}`;
1853
+ this.context.textAlign = params.textAlign ?? "left";
1854
+ this.context.textBaseline = params.textBaseline ?? "alphabetic";
1855
+ this.context.fillStyle = params.color ?? "white";
1856
+ this.context.fillText(text, x, y);
1857
+ }
2024
1858
  };
2025
1859
 
2026
- // src/renderer/webgl.ts
2027
- var ShaderType = ((ShaderType2) => {
2028
- ShaderType2[ShaderType2["VERTEX"] = WebGL2RenderingContext.VERTEX_SHADER] = "VERTEX";
2029
- ShaderType2[ShaderType2["FRAGMENT"] = WebGL2RenderingContext.FRAGMENT_SHADER] = "FRAGMENT";
2030
- return ShaderType2;
2031
- })(ShaderType || {});
2032
- function CreateWebGlContext(canvas) {
2033
- return (canvas ?? document.createElement("canvas")).getContext("webgl2");
2034
- }
2035
- function ResizeWebGlContext(gl, displayWidth, displayHeight) {
2036
- const canvas = gl.canvas;
2037
- const { width, height } = canvas.parentElement?.getBoundingClientRect() ?? canvas.getBoundingClientRect();
2038
- displayWidth = 0 | (displayWidth ?? width);
2039
- displayHeight = 0 | (displayHeight ?? height);
2040
- if (canvas.width !== displayWidth || canvas.height !== displayHeight) {
2041
- gl.canvas.width = displayWidth;
2042
- gl.canvas.height = displayHeight;
2043
- gl.viewport(0, 0, displayWidth, displayHeight);
2044
- return true;
2045
- }
2046
- return false;
2047
- }
2048
- function CompileShader(gl, type, source) {
2049
- const shader = gl.createShader(type);
2050
- gl.shaderSource(shader, source);
2051
- gl.compileShader(shader);
2052
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
2053
- throw `CompileShader: failed to compile shader: ${gl.getShaderInfoLog(shader)}`;
2054
- }
2055
- return shader;
2056
- }
2057
- function CreateProgram(gl, vertexShader2, fragmentShader2) {
2058
- if (typeof vertexShader2 === "string") {
2059
- vertexShader2 = CompileShader(gl, ShaderType.VERTEX, vertexShader2);
2060
- }
2061
- if (typeof fragmentShader2 === "string") {
2062
- fragmentShader2 = CompileShader(gl, ShaderType.FRAGMENT, fragmentShader2);
2063
- }
2064
- const program = gl.createProgram();
2065
- gl.attachShader(program, vertexShader2);
2066
- gl.attachShader(program, fragmentShader2);
2067
- gl.linkProgram(program);
2068
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
2069
- throw `CreateProgram: failed to link program: ${gl.getProgramInfoLog(program)}`;
2070
- }
2071
- return program;
2072
- }
2073
- function GetProgramLocations(gl, program) {
2074
- const attributes = {};
2075
- const attributeCount = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
2076
- for (let i = 0; i < attributeCount; i++) {
2077
- const info = gl.getActiveAttrib(program, i);
2078
- attributes[info.name] = gl.getAttribLocation(program, info.name);
2079
- }
2080
- const uniforms = {};
2081
- const uniformCount = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
2082
- for (let i = 0; i < uniformCount; i++) {
2083
- const info = gl.getActiveUniform(program, i);
2084
- uniforms[info.name] = gl.getUniformLocation(program, info.name);
2085
- }
2086
- return { attributes, uniforms };
2087
- }
2088
- function CreateProgramInfo(gl, vertexShaderSource, fragmentShaderSource) {
2089
- const program = CreateProgram(
2090
- gl,
2091
- vertexShaderSource,
2092
- fragmentShaderSource
2093
- );
2094
- const locations = GetProgramLocations(gl, program);
2095
- return { program, ...locations };
2096
- }
2097
-
2098
- // src/renderer/webgl-renderer.ts
2099
- var WebGlRenderer = class {
2100
- gl;
2101
- programInfo;
2102
- get canvas() {
2103
- return this.gl.canvas;
2104
- }
1860
+ // src/rendering/particle-renderer.ts
1861
+ var ParticleRenderer = class {
1862
+ _screenCanvas;
1863
+ _bufferCanvas;
1864
+ screenContext;
1865
+ bufferContext;
2105
1866
  get width() {
2106
- return this.gl.canvas.width;
1867
+ return this._screenCanvas.width;
2107
1868
  }
2108
1869
  get height() {
2109
- return this.gl.canvas.height;
1870
+ return this._screenCanvas.height;
2110
1871
  }
2111
- constructor() {
2112
- this.gl = CreateWebGlContext();
2113
- this.gl.enable(this.gl.DEPTH_TEST);
1872
+ constructor(canvas) {
1873
+ this._screenCanvas = canvas ?? document.createElement("canvas");
1874
+ this._bufferCanvas = new OffscreenCanvas(this._screenCanvas.width, this._screenCanvas.height);
1875
+ this.screenContext = this._screenCanvas.getContext("2d");
1876
+ this.bufferContext = this._bufferCanvas.getContext("2d");
1877
+ if (!this.screenContext || !this.bufferContext) {
1878
+ throw "Failed to create CanvasRenderingContext2D";
1879
+ }
2114
1880
  }
2115
- appendTo(htmlElement) {
2116
- if (this.canvas.parentElement) {
2117
- this.canvas.parentElement.removeChild(this.canvas);
1881
+ appendTo(target, autoResize = true) {
1882
+ if (this._screenCanvas.parentNode) {
1883
+ this._screenCanvas.parentNode.removeChild(this._screenCanvas);
2118
1884
  }
2119
- if (htmlElement) {
2120
- htmlElement.appendChild(this.canvas);
1885
+ target.appendChild(this._screenCanvas);
1886
+ if (autoResize) {
2121
1887
  this.resize();
2122
1888
  }
2123
1889
  }
2124
1890
  resize(displayWidth, displayHeight) {
2125
- const { width, height } = this.canvas.parentElement?.getBoundingClientRect() ?? this.canvas.getBoundingClientRect();
1891
+ const { width, height } = this._screenCanvas.parentElement?.getBoundingClientRect() ?? this._screenCanvas.getBoundingClientRect();
2126
1892
  displayWidth = 0 | (displayWidth ?? width);
2127
1893
  displayHeight = 0 | (displayHeight ?? height);
2128
- if (this.width !== displayWidth || this.height !== displayHeight) {
2129
- this.gl.canvas.width = displayWidth;
2130
- this.gl.canvas.height = displayHeight;
2131
- this.gl.viewport(0, 0, displayWidth, displayHeight);
1894
+ if (this._screenCanvas.width !== displayWidth || this._screenCanvas.height !== displayHeight) {
1895
+ this._screenCanvas.width = displayWidth;
1896
+ this._screenCanvas.height = displayHeight;
1897
+ this._bufferCanvas.width = displayWidth;
1898
+ this._bufferCanvas.height = displayHeight;
2132
1899
  return true;
2133
1900
  }
2134
1901
  return false;
2135
1902
  }
2136
- render(_deltaTime) {
2137
- if (this.programInfo) {
2138
- }
1903
+ setPixel(x, y, color, size = 2) {
1904
+ this.bufferContext.fillStyle = color.hexStr;
1905
+ this.bufferContext.fillRect(x - size / 2, y - size / 2, size, size);
1906
+ }
1907
+ render() {
1908
+ this.screenContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
1909
+ this.screenContext.drawImage(this._bufferCanvas, 0, 0);
1910
+ this.bufferContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
2139
1911
  }
2140
1912
  };
2141
1913
 
2142
- // src/simplex-noise.ts
2143
- var SimplexNoise = class {
2144
- grad3;
2145
- p;
2146
- perm;
2147
- constructor() {
2148
- this.grad3 = [
2149
- [1, 1, 0],
2150
- [-1, 1, 0],
2151
- [1, -1, 0],
2152
- [-1, -1, 0],
2153
- [1, 0, 1],
2154
- [-1, 0, 1],
2155
- [1, 0, -1],
2156
- [-1, 0, -1],
2157
- [0, 1, 1],
2158
- [0, -1, 1],
2159
- [0, 1, -1],
2160
- [0, -1, -1]
2161
- ];
2162
- this.p = [];
2163
- for (let i = 0; i < 256; i++) {
2164
- this.p.push(Math.floor(rng.nextf * 256));
2165
- }
2166
- this.perm = [];
2167
- for (let i = 0; i < 512; i++) {
2168
- this.perm.push(this.p[i & 255]);
1914
+ // src/rendering/three/cube-sphere-geometry.ts
1915
+ var import_three = require("three");
1916
+ var CubeSphereGeometry = class extends import_three.BoxGeometry {
1917
+ constructor(size, segments) {
1918
+ size = Math.floor(size);
1919
+ segments = Math.floor(segments);
1920
+ super(size, size, size, segments, segments, segments);
1921
+ this.size = size;
1922
+ this.segments = segments;
1923
+ this._halfSize = this.size / 2;
1924
+ const attrPositions = this.attributes.position;
1925
+ const position = new import_three.Vector3();
1926
+ for (let i = 0; i < attrPositions.count; i++) {
1927
+ position.fromBufferAttribute(attrPositions, i);
1928
+ position.normalize().multiplyScalar(this._halfSize);
1929
+ attrPositions.setXYZ(i, position.x, position.y, position.z);
2169
1930
  }
1931
+ attrPositions.needsUpdate = true;
2170
1932
  }
2171
- dot(g, x, y, z) {
2172
- return g[0] * x + g[1] * y + (typeof z === "number" ? g[2] * z : 0);
2173
- }
2174
- noise2d(xin, yin) {
2175
- let n0, n1, n2;
2176
- const F2 = 0.5 * (Math.sqrt(3) - 1);
2177
- const s = (xin + yin) * F2;
2178
- let i = Math.floor(xin + s);
2179
- let j = Math.floor(yin + s);
2180
- const G2 = (3 - Math.sqrt(3)) / 6;
2181
- const t = (i + j) * G2;
2182
- const X0 = i - t;
2183
- const Y0 = j - t;
2184
- const x0 = xin - X0;
2185
- const y0 = yin - Y0;
2186
- let i1, j1;
2187
- if (x0 > y0) {
2188
- i1 = 1;
2189
- j1 = 0;
2190
- } else {
2191
- i1 = 0;
2192
- j1 = 1;
2193
- }
2194
- const x1 = x0 - i1 + G2;
2195
- const y1 = y0 - j1 + G2;
2196
- const x2 = x0 - 1 + 2 * G2;
2197
- const y2 = y0 - 1 + 2 * G2;
2198
- const ii = i & 255;
2199
- const jj = j & 255;
2200
- const gi0 = this.perm[ii + this.perm[jj]] % 12;
2201
- const gi1 = this.perm[ii + i1 + this.perm[jj + j1]] % 12;
2202
- const gi2 = this.perm[ii + 1 + this.perm[jj + 1]] % 12;
2203
- let t0 = 0.5 - x0 * x0 - y0 * y0;
2204
- if (t0 < 0) {
2205
- n0 = 0;
2206
- } else {
2207
- t0 *= t0;
2208
- n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0);
2209
- }
2210
- let t1 = 0.5 - x1 * x1 - y1 * y1;
2211
- if (t1 < 0) {
2212
- n1 = 0;
2213
- } else {
2214
- t1 *= t1;
2215
- n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1);
1933
+ size;
1934
+ segments;
1935
+ _halfSize;
1936
+ applyFractalBrownianMotion(octaves, persistence, scale, amplitude) {
1937
+ const attrPositions = this.attributes.position;
1938
+ const position = new import_three.Vector3();
1939
+ for (let i = 0; i < attrPositions.count; i++) {
1940
+ position.fromBufferAttribute(attrPositions, i);
1941
+ position.normalize().multiplyScalar(this._halfSize);
1942
+ const noiseValue = this.fBm(position.x * scale, position.y * scale, position.z * scale, octaves, persistence);
1943
+ position.addScaledVector(position.clone().normalize(), noiseValue * amplitude);
1944
+ attrPositions.setXYZ(i, position.x, position.y, position.z);
2216
1945
  }
2217
- let t2 = 0.5 - x2 * x2 - y2 * y2;
2218
- if (t2 < 0) {
2219
- n2 = 0;
2220
- } else {
2221
- t2 *= t2;
2222
- n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2);
1946
+ attrPositions.needsUpdate = true;
1947
+ }
1948
+ fBm(x, y, z, octaves, persistence) {
1949
+ let total = 0;
1950
+ let frequency = 1;
1951
+ let amplitude = 1;
1952
+ let maxValue = 0;
1953
+ for (let i = 0; i < octaves; i++) {
1954
+ total += Noise.noise3d(x * frequency, y * frequency, z * frequency) * amplitude;
1955
+ maxValue += amplitude;
1956
+ amplitude *= persistence;
1957
+ frequency *= 2;
2223
1958
  }
2224
- return 70 * (n0 + n1 + n2);
2225
- }
2226
- // 3D simplex noise
2227
- noise3d(xin, yin, zin) {
2228
- let n0, n1, n2, n3;
2229
- const F3 = 1 / 3;
2230
- const s = (xin + yin + zin) * F3;
2231
- const i = Math.floor(xin + s);
2232
- const j = Math.floor(yin + s);
2233
- const k = Math.floor(zin + s);
2234
- const G3 = 1 / 6;
2235
- const t = (i + j + k) * G3;
2236
- const X0 = i - t;
2237
- const Y0 = j - t;
2238
- const Z0 = k - t;
2239
- const x0 = xin - X0;
2240
- const y0 = yin - Y0;
2241
- const z0 = zin - Z0;
2242
- let i1, j1, k1;
2243
- let i2, j2, k2;
2244
- if (x0 >= y0) {
2245
- if (y0 >= z0) {
2246
- i1 = 1;
2247
- j1 = 0;
2248
- k1 = 0;
2249
- i2 = 1;
2250
- j2 = 1;
2251
- k2 = 0;
2252
- } else if (x0 >= z0) {
2253
- i1 = 1;
2254
- j1 = 0;
2255
- k1 = 0;
2256
- i2 = 1;
2257
- j2 = 0;
2258
- k2 = 1;
2259
- } else {
2260
- i1 = 0;
2261
- j1 = 0;
2262
- k1 = 1;
2263
- i2 = 1;
2264
- j2 = 0;
2265
- k2 = 1;
2266
- }
2267
- } else {
2268
- if (y0 < z0) {
2269
- i1 = 0;
2270
- j1 = 0;
2271
- k1 = 1;
2272
- i2 = 0;
2273
- j2 = 1;
2274
- k2 = 1;
2275
- } else if (x0 < z0) {
2276
- i1 = 0;
2277
- j1 = 1;
2278
- k1 = 0;
2279
- i2 = 0;
2280
- j2 = 1;
2281
- k2 = 1;
2282
- } else {
2283
- i1 = 0;
2284
- j1 = 1;
2285
- k1 = 0;
2286
- i2 = 1;
2287
- j2 = 1;
2288
- k2 = 0;
2289
- }
2290
- }
2291
- const x1 = x0 - i1 + G3;
2292
- const y1 = y0 - j1 + G3;
2293
- const z1 = z0 - k1 + G3;
2294
- const x2 = x0 - i2 + 2 * G3;
2295
- const y2 = y0 - j2 + 2 * G3;
2296
- const z2 = z0 - k2 + 2 * G3;
2297
- const x3 = x0 - 1 + 3 * G3;
2298
- const y3 = y0 - 1 + 3 * G3;
2299
- const z3 = z0 - 1 + 3 * G3;
2300
- const ii = i & 255;
2301
- const jj = j & 255;
2302
- const kk = k & 255;
2303
- const gi0 = this.perm[ii + this.perm[jj + this.perm[kk]]] % 12;
2304
- const gi1 = this.perm[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]] % 12;
2305
- const gi2 = this.perm[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]] % 12;
2306
- const gi3 = this.perm[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]] % 12;
2307
- let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
2308
- if (t0 < 0) {
2309
- n0 = 0;
2310
- } else {
2311
- t0 *= t0;
2312
- n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0, z0);
2313
- }
2314
- let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
2315
- if (t1 < 0) {
2316
- n1 = 0;
2317
- } else {
2318
- t1 *= t1;
2319
- n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1, z1);
2320
- }
2321
- let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
2322
- if (t2 < 0) {
2323
- n2 = 0;
2324
- } else {
2325
- t2 *= t2;
2326
- n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2, z2);
2327
- }
2328
- let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
2329
- if (t3 < 0) {
2330
- n3 = 0;
2331
- } else {
2332
- t3 *= t3;
2333
- n3 = t3 * t3 * this.dot(this.grad3[gi3], x3, y3, z3);
2334
- }
2335
- return 32 * (n0 + n1 + n2 + n3);
2336
- }
2337
- };
2338
-
2339
- // src/spatial-partition-3d.ts
2340
- var SpatialPartition3d = class {
2341
- cells;
2342
- cellSize;
2343
- entities;
2344
- constructor(cellSize, entities) {
2345
- this.cellSize = cellSize;
2346
- this.entities = entities;
2347
- const gridSize = Math.ceil(1 / cellSize);
2348
- this.cells = Array.from(
2349
- { length: gridSize },
2350
- () => Array.from(
2351
- { length: gridSize },
2352
- () => Array.from({ length: gridSize }, () => [])
2353
- )
2354
- );
2355
- for (const entity of this.entities) {
2356
- this.addEntity(entity);
2357
- }
2358
- }
2359
- getCell(x, y, z) {
2360
- const cx = Math.floor(x / this.cellSize);
2361
- const cy = Math.floor(y / this.cellSize);
2362
- const cz = Math.floor(z / this.cellSize);
2363
- return this.cells[cz][cy][cx];
2364
- }
2365
- getCellNeighbors(cx, cy, cz) {
2366
- const neighbors = [];
2367
- const gridSize = this.cells.length;
2368
- for (let dz = -1; dz <= 1; dz++) {
2369
- for (let dy = -1; dy <= 1; dy++) {
2370
- for (let dx = -1; dx <= 1; dx++) {
2371
- let nx = (cx + dx + gridSize) % gridSize;
2372
- let ny = (cy + dy + gridSize) % gridSize;
2373
- let nz = (cz + dz + gridSize) % gridSize;
2374
- neighbors.push(this.cells[nz][ny][nx]);
2375
- }
2376
- }
2377
- }
2378
- return neighbors;
2379
- }
2380
- addEntity(entity) {
2381
- const cell = this.getCell(entity.x, entity.y, entity.z);
2382
- cell.push(entity);
2383
- }
2384
- };
2385
-
2386
- // src/tilemap.ts
2387
- var Tilemap = class {
2388
- map = /* @__PURE__ */ new Map();
2389
- _key(x, y) {
2390
- x = floor(x);
2391
- y = floor(y);
2392
- return `${x}x${y}`;
2393
- }
2394
- get(x, y) {
2395
- return this.map.get(this._key(x, y));
2396
- }
2397
- set(x, y, v) {
2398
- this.map.set(this._key(x, y), v);
2399
- }
2400
- };
2401
-
2402
- // src/three/cube-sphere-geometry.ts
2403
- var import_three = require("three");
2404
- var CubeSphereGeometry = class extends import_three.BoxGeometry {
2405
- constructor(size, segments) {
2406
- size = Math.floor(size);
2407
- segments = Math.floor(segments);
2408
- super(size, size, size, segments, segments, segments);
2409
- this.size = size;
2410
- this.segments = segments;
2411
- this._halfSize = this.size / 2;
2412
- const attrPositions = this.attributes.position;
2413
- const position = new import_three.Vector3();
2414
- for (let i = 0; i < attrPositions.count; i++) {
2415
- position.fromBufferAttribute(attrPositions, i);
2416
- position.normalize().multiplyScalar(this._halfSize);
2417
- attrPositions.setXYZ(i, position.x, position.y, position.z);
2418
- }
2419
- attrPositions.needsUpdate = true;
2420
- }
2421
- size;
2422
- segments;
2423
- _halfSize;
2424
- applyFractalBrownianMotion(octaves, persistence, scale, amplitude) {
2425
- const attrPositions = this.attributes.position;
2426
- const position = new import_three.Vector3();
2427
- for (let i = 0; i < attrPositions.count; i++) {
2428
- position.fromBufferAttribute(attrPositions, i);
2429
- position.normalize().multiplyScalar(this._halfSize);
2430
- const noiseValue = this.fBm(position.x * scale, position.y * scale, position.z * scale, octaves, persistence);
2431
- position.addScaledVector(position.clone().normalize(), noiseValue * amplitude);
2432
- attrPositions.setXYZ(i, position.x, position.y, position.z);
2433
- }
2434
- attrPositions.needsUpdate = true;
2435
- }
2436
- fBm(x, y, z, octaves, persistence) {
2437
- let total = 0;
2438
- let frequency = 1;
2439
- let amplitude = 1;
2440
- let maxValue = 0;
2441
- for (let i = 0; i < octaves; i++) {
2442
- total += Noise.noise3d(x * frequency, y * frequency, z * frequency) * amplitude;
2443
- maxValue += amplitude;
2444
- amplitude *= persistence;
2445
- frequency *= 2;
2446
- }
2447
- return total / maxValue;
1959
+ return total / maxValue;
2448
1960
  }
2449
1961
  };
2450
1962
 
2451
- // src/three/texture-atlas.ts
1963
+ // src/rendering/three/texture-atlas.ts
2452
1964
  var import_three2 = require("three");
2453
1965
  function LoadTexture(url) {
2454
1966
  return new Promise((res, rej) => {
@@ -2573,10 +2085,10 @@ var AtlasTextureMaterial = class _AtlasTextureMaterial extends import_three2.Mes
2573
2085
  }
2574
2086
  };
2575
2087
 
2576
- // src/three/threejs-boiler-plate.ts
2088
+ // src/rendering/three/threejs-boiler-plate.ts
2577
2089
  var import_three4 = require("three");
2578
2090
 
2579
- // src/three/threejs-camera-rig.ts
2091
+ // src/rendering/three/threejs-camera-rig.ts
2580
2092
  var import_three3 = require("three");
2581
2093
  var ThreeJsCameraRig = class extends import_three3.Group {
2582
2094
  gimbal;
@@ -2618,7 +2130,7 @@ var ThreeJsCameraRig = class extends import_three3.Group {
2618
2130
  }
2619
2131
  };
2620
2132
 
2621
- // src/three/threejs-boiler-plate.ts
2133
+ // src/rendering/three/threejs-boiler-plate.ts
2622
2134
  var ThreeJsBoilerPlate = class {
2623
2135
  clock = new Clock();
2624
2136
  scene = new import_three4.Scene();
@@ -2643,9 +2155,6 @@ var ThreeJsBoilerPlate = class {
2643
2155
  this.appendTo(params.parentElement);
2644
2156
  }
2645
2157
  }
2646
- // Mutually exclusive with enableOrbitControls() - pick one. Gives you
2647
- // manual orbit()/dolly() with tilt clamping and target-following, driven
2648
- // by this.input's mouse events.
2649
2158
  enableCameraRigControls() {
2650
2159
  this.orbitControls?.dispose();
2651
2160
  this.orbitControls = void 0;
@@ -2655,12 +2164,6 @@ var ThreeJsBoilerPlate = class {
2655
2164
  }
2656
2165
  }).on("mouse_wheel", ({ deltaY }) => this.cameraRig.dolly(deltaY));
2657
2166
  }
2658
- // Mutually exclusive with enableCameraRigControls() - pick one. Uses
2659
- // Three's own OrbitControls instead of the hand-rolled rig math; call
2660
- // update() once per frame in your render loop while this is active.
2661
- // Async because OrbitControls only ships as an ESM-only addon module -
2662
- // a dynamic import avoids forcing this whole package (built as both
2663
- // CJS and ESM) to statically import an ESM-only file.
2664
2167
  async enableOrbitControls() {
2665
2168
  const { OrbitControls } = await import("three/examples/jsm/Addons.js");
2666
2169
  this.orbitControls = new OrbitControls(this.camera, this.canvas);
@@ -2668,7 +2171,6 @@ var ThreeJsBoilerPlate = class {
2668
2171
  this.orbitControls.maxDistance = 100;
2669
2172
  this.orbitControls.update();
2670
2173
  }
2671
- // Call once per frame if enableOrbitControls() is active - no-op otherwise.
2672
2174
  update() {
2673
2175
  this.orbitControls?.update();
2674
2176
  }
@@ -2726,7 +2228,7 @@ var ThreeJsBoilerPlate = class {
2726
2228
  }
2727
2229
  };
2728
2230
 
2729
- // src/three/threejs-player-controller.ts
2231
+ // src/rendering/three/threejs-player-controller.ts
2730
2232
  var import_three5 = require("three");
2731
2233
  var ThreeJsPlayerController = class extends import_three5.Group {
2732
2234
  moveSpeed = 1;
@@ -2745,7 +2247,7 @@ var ThreeJsPlayerController = class extends import_three5.Group {
2745
2247
  }
2746
2248
  };
2747
2249
 
2748
- // src/three/voxel-mesh.ts
2250
+ // src/rendering/three/voxel-mesh.ts
2749
2251
  var import_three6 = require("three");
2750
2252
  var VoxelMesh = class extends import_three6.Mesh {
2751
2253
  type = "VoxelMesh";
@@ -3095,8 +2597,57 @@ var Colors = {
3095
2597
  ]
3096
2598
  };
3097
2599
 
3098
- // src/three/particle-system-3d.ts
2600
+ // src/rendering/three/particle-system-3d.ts
3099
2601
  var import_three7 = require("three");
2602
+
2603
+ // src/spatial-partition-3d.ts
2604
+ var SpatialPartition3d = class {
2605
+ cells;
2606
+ cellSize;
2607
+ entities;
2608
+ constructor(cellSize, entities) {
2609
+ this.cellSize = cellSize;
2610
+ this.entities = entities;
2611
+ const gridSize = Math.ceil(1 / cellSize);
2612
+ this.cells = Array.from(
2613
+ { length: gridSize },
2614
+ () => Array.from(
2615
+ { length: gridSize },
2616
+ () => Array.from({ length: gridSize }, () => [])
2617
+ )
2618
+ );
2619
+ for (const entity of this.entities) {
2620
+ this.addEntity(entity);
2621
+ }
2622
+ }
2623
+ getCell(x, y, z) {
2624
+ const cx = Math.floor(x / this.cellSize);
2625
+ const cy = Math.floor(y / this.cellSize);
2626
+ const cz = Math.floor(z / this.cellSize);
2627
+ return this.cells[cz][cy][cx];
2628
+ }
2629
+ getCellNeighbors(cx, cy, cz) {
2630
+ const neighbors = [];
2631
+ const gridSize = this.cells.length;
2632
+ for (let dz = -1; dz <= 1; dz++) {
2633
+ for (let dy = -1; dy <= 1; dy++) {
2634
+ for (let dx = -1; dx <= 1; dx++) {
2635
+ let nx = (cx + dx + gridSize) % gridSize;
2636
+ let ny = (cy + dy + gridSize) % gridSize;
2637
+ let nz = (cz + dz + gridSize) % gridSize;
2638
+ neighbors.push(this.cells[nz][ny][nx]);
2639
+ }
2640
+ }
2641
+ }
2642
+ return neighbors;
2643
+ }
2644
+ addEntity(entity) {
2645
+ const cell = this.getCell(entity.x, entity.y, entity.z);
2646
+ cell.push(entity);
2647
+ }
2648
+ };
2649
+
2650
+ // src/rendering/three/particle-system-3d.ts
3100
2651
  var vertexShader = `
3101
2652
  uniform float pointSize;
3102
2653
 
@@ -3285,7 +2836,7 @@ var ParticleSystem3d = class extends import_three7.Group {
3285
2836
  }
3286
2837
  };
3287
2838
 
3288
- // src/three/asteroid-mesh.ts
2839
+ // src/rendering/three/asteroid-mesh.ts
3289
2840
  var import_three8 = require("three");
3290
2841
  var import_simplex_noise2 = require("simplex-noise");
3291
2842
  var AsteroidMesh = class extends import_three8.Mesh {
@@ -3320,7 +2871,7 @@ var AsteroidMesh = class extends import_three8.Mesh {
3320
2871
  }
3321
2872
  };
3322
2873
 
3323
- // src/three/starfield.ts
2874
+ // src/rendering/three/starfield.ts
3324
2875
  var import_three9 = require("three");
3325
2876
  function CreateStarfield(radius = 1e3, count = 5e3, color = 16777215) {
3326
2877
  const geometry = new import_three9.BufferGeometry();
@@ -3359,7 +2910,7 @@ function CreateSystemStar(position) {
3359
2910
  return star;
3360
2911
  }
3361
2912
 
3362
- // src/three/palette-controller.ts
2913
+ // src/rendering/three/palette-controller.ts
3363
2914
  var import_three10 = require("three");
3364
2915
  async function CreatePaletteController(parentGui, colorPalette, onChange, folderName = "palette") {
3365
2916
  const { Controller } = await import("three/examples/jsm/libs/lil-gui.module.min.js");
@@ -3464,7 +3015,7 @@ async function CreatePaletteController(parentGui, colorPalette, onChange, folder
3464
3015
  return new PaletteControllerImpl();
3465
3016
  }
3466
3017
 
3467
- // src/three/ecs.ts
3018
+ // src/rendering/three/ecs.ts
3468
3019
  var import_three11 = require("three");
3469
3020
  var entityCounter = 0;
3470
3021
  function GenerateEntityId() {
@@ -3489,6 +3040,334 @@ function IsThreeEntity(obj) {
3489
3040
  return obj.userData.entityId !== void 0;
3490
3041
  }
3491
3042
 
3043
+ // src/rendering/webgl.ts
3044
+ var ShaderType = ((ShaderType2) => {
3045
+ ShaderType2[ShaderType2["VERTEX"] = WebGL2RenderingContext.VERTEX_SHADER] = "VERTEX";
3046
+ ShaderType2[ShaderType2["FRAGMENT"] = WebGL2RenderingContext.FRAGMENT_SHADER] = "FRAGMENT";
3047
+ return ShaderType2;
3048
+ })(ShaderType || {});
3049
+ function CreateWebGlContext(canvas) {
3050
+ return (canvas ?? document.createElement("canvas")).getContext("webgl2");
3051
+ }
3052
+ function ResizeWebGlContext(gl, displayWidth, displayHeight) {
3053
+ const canvas = gl.canvas;
3054
+ const { width, height } = canvas.parentElement?.getBoundingClientRect() ?? canvas.getBoundingClientRect();
3055
+ displayWidth = 0 | (displayWidth ?? width);
3056
+ displayHeight = 0 | (displayHeight ?? height);
3057
+ if (canvas.width !== displayWidth || canvas.height !== displayHeight) {
3058
+ gl.canvas.width = displayWidth;
3059
+ gl.canvas.height = displayHeight;
3060
+ gl.viewport(0, 0, displayWidth, displayHeight);
3061
+ return true;
3062
+ }
3063
+ return false;
3064
+ }
3065
+ function CompileShader(gl, type, source) {
3066
+ const shader = gl.createShader(type);
3067
+ gl.shaderSource(shader, source);
3068
+ gl.compileShader(shader);
3069
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
3070
+ throw `CompileShader: failed to compile shader: ${gl.getShaderInfoLog(shader)}`;
3071
+ }
3072
+ return shader;
3073
+ }
3074
+ function CreateProgram(gl, vertexShader2, fragmentShader2) {
3075
+ if (typeof vertexShader2 === "string") {
3076
+ vertexShader2 = CompileShader(gl, ShaderType.VERTEX, vertexShader2);
3077
+ }
3078
+ if (typeof fragmentShader2 === "string") {
3079
+ fragmentShader2 = CompileShader(gl, ShaderType.FRAGMENT, fragmentShader2);
3080
+ }
3081
+ const program = gl.createProgram();
3082
+ gl.attachShader(program, vertexShader2);
3083
+ gl.attachShader(program, fragmentShader2);
3084
+ gl.linkProgram(program);
3085
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
3086
+ throw `CreateProgram: failed to link program: ${gl.getProgramInfoLog(program)}`;
3087
+ }
3088
+ return program;
3089
+ }
3090
+ function GetProgramLocations(gl, program) {
3091
+ const attributes = {};
3092
+ const attributeCount = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
3093
+ for (let i = 0; i < attributeCount; i++) {
3094
+ const info = gl.getActiveAttrib(program, i);
3095
+ attributes[info.name] = gl.getAttribLocation(program, info.name);
3096
+ }
3097
+ const uniforms = {};
3098
+ const uniformCount = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
3099
+ for (let i = 0; i < uniformCount; i++) {
3100
+ const info = gl.getActiveUniform(program, i);
3101
+ uniforms[info.name] = gl.getUniformLocation(program, info.name);
3102
+ }
3103
+ return { attributes, uniforms };
3104
+ }
3105
+ function CreateProgramInfo(gl, vertexShaderSource, fragmentShaderSource) {
3106
+ const program = CreateProgram(
3107
+ gl,
3108
+ vertexShaderSource,
3109
+ fragmentShaderSource
3110
+ );
3111
+ const locations = GetProgramLocations(gl, program);
3112
+ return { program, ...locations };
3113
+ }
3114
+
3115
+ // src/rendering/webgl-renderer.ts
3116
+ var WebGlRenderer = class {
3117
+ gl;
3118
+ programInfo;
3119
+ get canvas() {
3120
+ return this.gl.canvas;
3121
+ }
3122
+ get width() {
3123
+ return this.gl.canvas.width;
3124
+ }
3125
+ get height() {
3126
+ return this.gl.canvas.height;
3127
+ }
3128
+ constructor() {
3129
+ this.gl = CreateWebGlContext();
3130
+ this.gl.enable(this.gl.DEPTH_TEST);
3131
+ }
3132
+ appendTo(htmlElement) {
3133
+ if (this.canvas.parentElement) {
3134
+ this.canvas.parentElement.removeChild(this.canvas);
3135
+ }
3136
+ if (htmlElement) {
3137
+ htmlElement.appendChild(this.canvas);
3138
+ this.resize();
3139
+ }
3140
+ }
3141
+ resize(displayWidth, displayHeight) {
3142
+ const { width, height } = this.canvas.parentElement?.getBoundingClientRect() ?? this.canvas.getBoundingClientRect();
3143
+ displayWidth = 0 | (displayWidth ?? width);
3144
+ displayHeight = 0 | (displayHeight ?? height);
3145
+ if (this.width !== displayWidth || this.height !== displayHeight) {
3146
+ this.gl.canvas.width = displayWidth;
3147
+ this.gl.canvas.height = displayHeight;
3148
+ this.gl.viewport(0, 0, displayWidth, displayHeight);
3149
+ return true;
3150
+ }
3151
+ return false;
3152
+ }
3153
+ render(_deltaTime) {
3154
+ if (this.programInfo) {
3155
+ }
3156
+ }
3157
+ };
3158
+
3159
+ // src/simplex-noise.ts
3160
+ var SimplexNoise = class {
3161
+ grad3;
3162
+ p;
3163
+ perm;
3164
+ constructor() {
3165
+ this.grad3 = [
3166
+ [1, 1, 0],
3167
+ [-1, 1, 0],
3168
+ [1, -1, 0],
3169
+ [-1, -1, 0],
3170
+ [1, 0, 1],
3171
+ [-1, 0, 1],
3172
+ [1, 0, -1],
3173
+ [-1, 0, -1],
3174
+ [0, 1, 1],
3175
+ [0, -1, 1],
3176
+ [0, 1, -1],
3177
+ [0, -1, -1]
3178
+ ];
3179
+ this.p = [];
3180
+ for (let i = 0; i < 256; i++) {
3181
+ this.p.push(Math.floor(rng.nextf * 256));
3182
+ }
3183
+ this.perm = [];
3184
+ for (let i = 0; i < 512; i++) {
3185
+ this.perm.push(this.p[i & 255]);
3186
+ }
3187
+ }
3188
+ dot(g, x, y, z) {
3189
+ return g[0] * x + g[1] * y + (typeof z === "number" ? g[2] * z : 0);
3190
+ }
3191
+ noise2d(xin, yin) {
3192
+ let n0, n1, n2;
3193
+ const F2 = 0.5 * (Math.sqrt(3) - 1);
3194
+ const s = (xin + yin) * F2;
3195
+ let i = Math.floor(xin + s);
3196
+ let j = Math.floor(yin + s);
3197
+ const G2 = (3 - Math.sqrt(3)) / 6;
3198
+ const t = (i + j) * G2;
3199
+ const X0 = i - t;
3200
+ const Y0 = j - t;
3201
+ const x0 = xin - X0;
3202
+ const y0 = yin - Y0;
3203
+ let i1, j1;
3204
+ if (x0 > y0) {
3205
+ i1 = 1;
3206
+ j1 = 0;
3207
+ } else {
3208
+ i1 = 0;
3209
+ j1 = 1;
3210
+ }
3211
+ const x1 = x0 - i1 + G2;
3212
+ const y1 = y0 - j1 + G2;
3213
+ const x2 = x0 - 1 + 2 * G2;
3214
+ const y2 = y0 - 1 + 2 * G2;
3215
+ const ii = i & 255;
3216
+ const jj = j & 255;
3217
+ const gi0 = this.perm[ii + this.perm[jj]] % 12;
3218
+ const gi1 = this.perm[ii + i1 + this.perm[jj + j1]] % 12;
3219
+ const gi2 = this.perm[ii + 1 + this.perm[jj + 1]] % 12;
3220
+ let t0 = 0.5 - x0 * x0 - y0 * y0;
3221
+ if (t0 < 0) {
3222
+ n0 = 0;
3223
+ } else {
3224
+ t0 *= t0;
3225
+ n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0);
3226
+ }
3227
+ let t1 = 0.5 - x1 * x1 - y1 * y1;
3228
+ if (t1 < 0) {
3229
+ n1 = 0;
3230
+ } else {
3231
+ t1 *= t1;
3232
+ n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1);
3233
+ }
3234
+ let t2 = 0.5 - x2 * x2 - y2 * y2;
3235
+ if (t2 < 0) {
3236
+ n2 = 0;
3237
+ } else {
3238
+ t2 *= t2;
3239
+ n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2);
3240
+ }
3241
+ return 70 * (n0 + n1 + n2);
3242
+ }
3243
+ noise3d(xin, yin, zin) {
3244
+ let n0, n1, n2, n3;
3245
+ const F3 = 1 / 3;
3246
+ const s = (xin + yin + zin) * F3;
3247
+ const i = Math.floor(xin + s);
3248
+ const j = Math.floor(yin + s);
3249
+ const k = Math.floor(zin + s);
3250
+ const G3 = 1 / 6;
3251
+ const t = (i + j + k) * G3;
3252
+ const X0 = i - t;
3253
+ const Y0 = j - t;
3254
+ const Z0 = k - t;
3255
+ const x0 = xin - X0;
3256
+ const y0 = yin - Y0;
3257
+ const z0 = zin - Z0;
3258
+ let i1, j1, k1;
3259
+ let i2, j2, k2;
3260
+ if (x0 >= y0) {
3261
+ if (y0 >= z0) {
3262
+ i1 = 1;
3263
+ j1 = 0;
3264
+ k1 = 0;
3265
+ i2 = 1;
3266
+ j2 = 1;
3267
+ k2 = 0;
3268
+ } else if (x0 >= z0) {
3269
+ i1 = 1;
3270
+ j1 = 0;
3271
+ k1 = 0;
3272
+ i2 = 1;
3273
+ j2 = 0;
3274
+ k2 = 1;
3275
+ } else {
3276
+ i1 = 0;
3277
+ j1 = 0;
3278
+ k1 = 1;
3279
+ i2 = 1;
3280
+ j2 = 0;
3281
+ k2 = 1;
3282
+ }
3283
+ } else {
3284
+ if (y0 < z0) {
3285
+ i1 = 0;
3286
+ j1 = 0;
3287
+ k1 = 1;
3288
+ i2 = 0;
3289
+ j2 = 1;
3290
+ k2 = 1;
3291
+ } else if (x0 < z0) {
3292
+ i1 = 0;
3293
+ j1 = 1;
3294
+ k1 = 0;
3295
+ i2 = 0;
3296
+ j2 = 1;
3297
+ k2 = 1;
3298
+ } else {
3299
+ i1 = 0;
3300
+ j1 = 1;
3301
+ k1 = 0;
3302
+ i2 = 1;
3303
+ j2 = 1;
3304
+ k2 = 0;
3305
+ }
3306
+ }
3307
+ const x1 = x0 - i1 + G3;
3308
+ const y1 = y0 - j1 + G3;
3309
+ const z1 = z0 - k1 + G3;
3310
+ const x2 = x0 - i2 + 2 * G3;
3311
+ const y2 = y0 - j2 + 2 * G3;
3312
+ const z2 = z0 - k2 + 2 * G3;
3313
+ const x3 = x0 - 1 + 3 * G3;
3314
+ const y3 = y0 - 1 + 3 * G3;
3315
+ const z3 = z0 - 1 + 3 * G3;
3316
+ const ii = i & 255;
3317
+ const jj = j & 255;
3318
+ const kk = k & 255;
3319
+ const gi0 = this.perm[ii + this.perm[jj + this.perm[kk]]] % 12;
3320
+ const gi1 = this.perm[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]] % 12;
3321
+ const gi2 = this.perm[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]] % 12;
3322
+ const gi3 = this.perm[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]] % 12;
3323
+ let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
3324
+ if (t0 < 0) {
3325
+ n0 = 0;
3326
+ } else {
3327
+ t0 *= t0;
3328
+ n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0, z0);
3329
+ }
3330
+ let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
3331
+ if (t1 < 0) {
3332
+ n1 = 0;
3333
+ } else {
3334
+ t1 *= t1;
3335
+ n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1, z1);
3336
+ }
3337
+ let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
3338
+ if (t2 < 0) {
3339
+ n2 = 0;
3340
+ } else {
3341
+ t2 *= t2;
3342
+ n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2, z2);
3343
+ }
3344
+ let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
3345
+ if (t3 < 0) {
3346
+ n3 = 0;
3347
+ } else {
3348
+ t3 *= t3;
3349
+ n3 = t3 * t3 * this.dot(this.grad3[gi3], x3, y3, z3);
3350
+ }
3351
+ return 32 * (n0 + n1 + n2 + n3);
3352
+ }
3353
+ };
3354
+
3355
+ // src/tilemap.ts
3356
+ var Tilemap = class {
3357
+ map = /* @__PURE__ */ new Map();
3358
+ _key(x, y) {
3359
+ x = floor(x);
3360
+ y = floor(y);
3361
+ return `${x}x${y}`;
3362
+ }
3363
+ get(x, y) {
3364
+ return this.map.get(this._key(x, y));
3365
+ }
3366
+ set(x, y, v) {
3367
+ this.map.set(this._key(x, y), v);
3368
+ }
3369
+ };
3370
+
3492
3371
  // src/worker-interface.ts
3493
3372
  var WorkerInterface = class extends Emitter {
3494
3373
  _worker;
@@ -3514,7 +3393,6 @@ var WorkerInterface = class extends Emitter {
3514
3393
  BuildDefaultPalette,
3515
3394
  CanvasRenderer,
3516
3395
  Clock,
3517
- ClockStats,
3518
3396
  Color,
3519
3397
  Colors,
3520
3398
  CompileShader,
@@ -3527,16 +3405,17 @@ var WorkerInterface = class extends Emitter {
3527
3405
  CreateThreeEntity,
3528
3406
  CreateWebGlContext,
3529
3407
  CubeSphereGeometry,
3408
+ DOUBLE_PI,
3530
3409
  ECS,
3531
3410
  Emitter,
3532
- EventBus,
3533
3411
  GenerateDoors,
3534
3412
  GenerateEntityId,
3535
3413
  GenerateRooms,
3536
3414
  GenerateWalls,
3537
3415
  GetProgramLocations,
3538
3416
  GetThreeComponent,
3539
- GlobalEmitter,
3417
+ GetUrlParams,
3418
+ HALF_PI,
3540
3419
  Input,
3541
3420
  IsThreeEntity,
3542
3421
  LoadTexture,
@@ -3544,14 +3423,15 @@ var WorkerInterface = class extends Emitter {
3544
3423
  Map3D,
3545
3424
  Noise,
3546
3425
  PI,
3426
+ ParticleRenderer,
3547
3427
  ParticleSystem2d,
3548
3428
  ParticleSystem3d,
3549
3429
  PoissonDiskSampler,
3430
+ RADIAN_FACTOR,
3431
+ RandomNumberGenerator,
3550
3432
  Rectangle,
3551
3433
  RemoveThreeComponent,
3552
- Renderer,
3553
3434
  ResizeWebGlContext,
3554
- Rng,
3555
3435
  ShaderType,
3556
3436
  SimplexNoise,
3557
3437
  SpatialPartition2d,
@@ -3574,14 +3454,15 @@ var WorkerInterface = class extends Emitter {
3574
3454
  clamp,
3575
3455
  cos,
3576
3456
  deg2rad,
3577
- distance,
3578
- eventBus,
3457
+ distance2d,
3458
+ distance3d,
3579
3459
  floor,
3580
3460
  getRedYellowGreenGradientHex,
3581
3461
  hypot2,
3582
3462
  hypot3,
3583
3463
  imul,
3584
3464
  isNullOrUndefined,
3465
+ isPositiveString,
3585
3466
  lerp,
3586
3467
  log,
3587
3468
  logdev,