@n3rdw1z4rd/core 0.14.1 → 0.16.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.mjs CHANGED
@@ -20,10 +20,6 @@ var AStar = class {
20
20
  _key(x, y) {
21
21
  return `${x},${y}`;
22
22
  }
23
- // NOTE: ported as-is from rogue-craft. useAdjacent is currently hard-coded
24
- // to true below - the original had a known unresolved bug where setting it
25
- // to false via params caused an infinite loop, so that path is disabled
26
- // rather than exposed broken.
27
23
  findPath(a, b, params = {}) {
28
24
  const useAdjacent = true;
29
25
  const walkable = params.walkableValues ?? [0];
@@ -94,198 +90,131 @@ var AStar = class {
94
90
  }
95
91
  };
96
92
 
97
- // src/clock-stats.ts
98
- var ClockStats = class {
99
- divElement;
100
- keyColor = "gray";
101
- valueColor = "lightgray";
102
- constructor(align = "bottom", justify = "right") {
103
- this.divElement = document.createElement("div");
104
- this.divElement.setAttribute("id", "clock-stats");
105
- this.divElement.style.setProperty("position", "absolute");
106
- this.divElement.style.setProperty(align, "4px");
107
- this.divElement.style.setProperty(justify, "4px");
93
+ // src/emitter.ts
94
+ var Emitter = class {
95
+ listeners = /* @__PURE__ */ new Map();
96
+ constructor() {
108
97
  }
109
- appendTo(target) {
110
- this.divElement.parentNode?.removeChild(this.divElement);
111
- if (target) {
112
- target.appendChild(this.divElement);
113
- }
98
+ on(...eventName) {
99
+ const listener = eventName.pop();
100
+ const events = eventName.filter((ev) => typeof ev === "string");
101
+ events.forEach((event) => {
102
+ if (!this.listeners.has(event)) {
103
+ this.listeners.set(event, new Array());
104
+ }
105
+ this.listeners.get(event)?.push(listener);
106
+ });
107
+ return this;
114
108
  }
115
- update(data) {
116
- this.divElement.innerHTML = Object.entries(data).map(
117
- ([key, value]) => `<span style="color: ${this.keyColor};">${key}:</span>&nbsp;<span style="color: ${this.valueColor};">${value}</span>`
118
- ).join("<br/>");
109
+ emit(eventName, ...args) {
110
+ this.listeners.get(eventName)?.forEach((listener) => listener(...args, eventName));
111
+ return this;
112
+ }
113
+ clear(eventName) {
114
+ if (eventName) {
115
+ this.listeners.delete(eventName);
116
+ } else {
117
+ this.listeners.clear();
118
+ }
119
+ return this;
119
120
  }
120
121
  };
121
122
 
122
123
  // src/clock.ts
123
- var Clock = class {
124
- _lastFrameTime = 0;
125
- _daltaTimeMilliseconds = 0;
126
- _deltaTimeSeconds = 0;
127
- _avgDeltaTime = 0;
128
- _frameCount = 0;
129
- _frameCountTotal = 0;
124
+ var Clock = class extends Emitter {
125
+ _startTime = 0;
126
+ _time = 0;
127
+ _deltaTime = 0;
130
128
  _frameTime = 0;
129
+ _frameCount = 0;
131
130
  _fps = 0;
132
131
  _isRunning = false;
133
- _updateCallback = () => {
134
- };
135
- _statsParent;
136
- _stats;
137
- _startTime = 0;
138
- get fps() {
139
- return this._fps;
140
- }
141
- get frames() {
142
- return this._frameCountTotal;
143
- }
144
- get deltaTimeSeconds() {
145
- return this._deltaTimeSeconds;
146
- }
147
- get deltaTimeMilliseconds() {
148
- return this._daltaTimeMilliseconds;
149
- }
150
- get avgDeltaTime() {
151
- return this._avgDeltaTime;
152
- }
153
132
  get time() {
154
- return this._lastFrameTime;
133
+ return this._time;
155
134
  }
156
- get isRunning() {
157
- return this._isRunning;
135
+ get deltaTime() {
136
+ return this._deltaTime;
158
137
  }
159
- get elapsedTimeSinceStart() {
138
+ get elapsedTime() {
160
139
  return performance.now() - this._startTime;
161
140
  }
162
- constructor(statsDivParent) {
163
- this._statsParent = statsDivParent;
164
- }
165
- _update(time) {
166
- this.update(time);
167
- this._updateCallback(this._deltaTimeSeconds);
168
- if (this._isRunning) {
169
- requestAnimationFrame(this._update.bind(this));
170
- }
141
+ get fps() {
142
+ return this._fps;
171
143
  }
172
- update(time) {
173
- this._daltaTimeMilliseconds = time - this._lastFrameTime;
174
- this._deltaTimeSeconds = this._daltaTimeMilliseconds / 1e3;
175
- this._lastFrameTime = time;
176
- if (this._frameTime + 1e3 >= time) {
177
- this._frameCount += 1;
178
- } else {
179
- this._frameTime = time;
180
- this._fps = this._frameCount;
181
- this._frameCount = 0;
182
- }
183
- this._frameCountTotal++;
184
- this._avgDeltaTime = (this._avgDeltaTime * this._frameCount + this._daltaTimeMilliseconds) / (this._frameCount + 1);
144
+ get isRunning() {
145
+ return this._isRunning;
185
146
  }
186
- run(callback) {
147
+ start() {
187
148
  if (!this._isRunning) {
188
- this._frameCountTotal = 0;
189
149
  this._startTime = performance.now();
190
150
  this._isRunning = true;
191
- this._updateCallback = callback;
192
- requestAnimationFrame(this._update.bind(this));
151
+ const update = (time) => {
152
+ this._deltaTime = (time - this._time) / 1e3;
153
+ this._time = time;
154
+ if (this._frameTime + 1e3 >= time) {
155
+ this._frameCount += 1;
156
+ } else {
157
+ this._frameTime = time;
158
+ this._fps = this._frameCount;
159
+ this._frameCount = 0;
160
+ }
161
+ this.emit("frame", this._deltaTime);
162
+ if (this._isRunning) {
163
+ requestAnimationFrame(update);
164
+ }
165
+ };
166
+ requestAnimationFrame(update);
193
167
  }
194
- }
195
- runOnce(callback) {
196
- this._isRunning = false;
197
- this._updateCallback = callback;
198
- this._update(0);
168
+ return this;
199
169
  }
200
170
  stop() {
201
171
  this._isRunning = false;
202
172
  }
203
- getExecuteTime(func) {
204
- const now = performance.now();
205
- func();
206
- return performance.now() - now;
207
- }
208
- showStats(data = {}, parent) {
209
- parent = parent ?? this._statsParent ?? document.body;
210
- if (!this._stats) {
211
- this._stats = new ClockStats();
212
- this._stats.appendTo(parent);
213
- }
214
- this._stats.update({
215
- fps: this._fps,
216
- "deltaTime(s)": `${this._deltaTimeSeconds.toFixed(3)}`,
217
- "avgDeltaTime(ms)": `${this._avgDeltaTime.toFixed(3)}`,
218
- ...data
219
- });
220
- }
221
173
  };
222
174
 
223
- // src/logger.ts
224
- var logdev = console.debug.bind(console, "%c[dbg]", "font-weight: bold; color: #888;");
225
- var log = logdev;
226
- var loginf = console.log.bind(console, "%c[inf]", "font-weight: bold;");
227
- var logwrn = console.log.bind(console, "%c[wrn]", "font-weight: bold; color: orange;");
228
- var logerr = console.log.bind(console, "%c[err]", "font-weight: bold; color: red;");
229
-
230
- // src/math.ts
231
- var DEG2RAD = 0.01745329;
175
+ // src/math/math.ts
232
176
  var PI = 3.141592653589793;
233
- var TWO_PI = PI * 2;
177
+ var DOUBLE_PI = PI * 2;
234
178
  var HALF_PI = PI / 2;
235
- function abs(n) {
236
- return n < 0 ? -n : n;
237
- }
238
- function min(a, b) {
239
- return a < b ? a : b;
240
- }
241
- function max(a, b) {
242
- return a > b ? a : b;
243
- }
244
- function floor(n) {
179
+ var RADIAN_FACTOR = PI / 180;
180
+ var abs = (n) => n < 0 ? -n : n;
181
+ var min = (a, b) => a < b ? a : b;
182
+ var max = (a, b) => a > b ? a : b;
183
+ var floor = (n) => {
245
184
  const t = n | 0;
246
185
  return n < 0 && t !== n ? t - 1 : t;
247
- }
248
- function ceil(n) {
186
+ };
187
+ var ceil = (n) => {
249
188
  const t = n | 0;
250
189
  return n > 0 && t !== n ? t + 1 : t;
251
- }
252
- function round(n) {
253
- return floor(n + 0.5);
254
- }
255
- function sqrt(n) {
256
- return n ** 0.5;
257
- }
258
- function pow(base, exp) {
259
- return base ** exp;
260
- }
261
- function hypot2(x, y) {
262
- return (x * x + y * y) ** 0.5;
263
- }
264
- function hypot3(x, y, z) {
265
- return (x * x + y * y + z * z) ** 0.5;
266
- }
267
- function imul(a, b) {
190
+ };
191
+ var round = (n) => floor(n + 0.5);
192
+ var sqrt = (n) => n ** 0.5;
193
+ var pow = (base, exp) => base ** exp;
194
+ var hypot2 = (x, y) => (x * x + y * y) ** 0.5;
195
+ var hypot3 = (x, y, z) => (x * x + y * y + z * z) ** 0.5;
196
+ var imul = (a, b) => {
268
197
  b |= 0;
269
198
  let result = (a & 4194303) * b;
270
199
  if (a & 4290772992) result += (a & 4290772992) * b | 0;
271
200
  return result | 0;
272
- }
273
- function wrapAngle(n) {
274
- n = n % TWO_PI;
275
- if (n > PI) n -= TWO_PI;
276
- else if (n < -PI) n += TWO_PI;
201
+ };
202
+ var _wrapAngle = (n) => {
203
+ n = n % DOUBLE_PI;
204
+ if (n > PI) n -= DOUBLE_PI;
205
+ else if (n < -PI) n += DOUBLE_PI;
277
206
  return n;
278
- }
279
- function sinSeries(n) {
207
+ };
208
+ var _sinSeries = (n) => {
280
209
  const n2 = n * n;
281
210
  return n * (1 + n2 * (-1 / 6 + n2 * (1 / 120 + n2 * (-1 / 5040 + n2 * (1 / 362880 + n2 * (-1 / 39916800))))));
282
- }
283
- function cosSeries(n) {
211
+ };
212
+ var _cosSeries = (n) => {
284
213
  const n2 = n * n;
285
214
  return 1 + n2 * (-1 / 2 + n2 * (1 / 24 + n2 * (-1 / 720 + n2 * (1 / 40320 + n2 * (-1 / 3628800)))));
286
- }
287
- function reduceAngle(n) {
288
- let x = wrapAngle(n);
215
+ };
216
+ var _reduceAngle = (n) => {
217
+ let x = _wrapAngle(n);
289
218
  let sinSign = 1;
290
219
  if (x < 0) {
291
220
  x = -x;
@@ -297,287 +226,115 @@ function reduceAngle(n) {
297
226
  cosSign = -1;
298
227
  }
299
228
  return [x, sinSign, cosSign];
300
- }
301
- function sin(n) {
302
- const [x, sinSign] = reduceAngle(n);
303
- return sinSign * sinSeries(x);
304
- }
305
- function cos(n) {
306
- const [x, , cosSign] = reduceAngle(n);
307
- return cosSign * cosSeries(x);
308
- }
309
- function clamp(value, lo, hi) {
310
- return max(lo, min(hi, value));
311
- }
312
- function deg2rad(value) {
313
- return value * DEG2RAD;
314
- }
315
- function lerp(start, end, scale) {
316
- return start * (1 - scale) + end * scale;
317
- }
318
- function distance(x1, y1, x2, y2) {
319
- return hypot2(x2 - x1, y2 - y1);
320
- }
321
- function squaredDistance(x1, y1, x2, y2) {
229
+ };
230
+ var sin = (n) => {
231
+ const [x, sinSign] = _reduceAngle(n);
232
+ return sinSign * _sinSeries(x);
233
+ };
234
+ var cos = (n) => {
235
+ const [x, , cosSign] = _reduceAngle(n);
236
+ return cosSign * _cosSeries(x);
237
+ };
238
+ var clamp = (value, lo, hi) => max(lo, min(hi, value));
239
+ var deg2rad = (degree) => degree * RADIAN_FACTOR;
240
+ var lerp = (start, end, scale) => start * (1 - scale) + end * scale;
241
+ var distance2d = (x1, y1, x2, y2) => hypot2(x2 - x1, y2 - y1);
242
+ var distance3d = (x1, y1, z1, x2, y2, z2) => hypot3(x2 - x1, y2 - y1, z2 - z1);
243
+ var squaredDistance = (x1, y1, x2, y2) => {
322
244
  const dx = x1 - x2;
323
245
  const dy = y1 - y2;
324
246
  return dx * dx + dy * dy;
325
- }
326
- function manhattanDistance(x1, y1, x2, y2) {
327
- return abs(x1 - x2) + abs(y1 - y2);
328
- }
329
- function roundTo(value, digits, base = 10) {
247
+ };
248
+ var manhattanDistance = (x1, y1, x2, y2) => abs(x1 - x2) + abs(y1 - y2);
249
+ var roundTo = (value, digits, base = 10) => {
330
250
  const p = pow(base, digits);
331
251
  return round(value * p) / p;
332
- }
252
+ };
333
253
 
334
- // src/color.ts
335
- var Color = class _Color {
336
- _hex = "#ffffffff";
337
- _r = 255;
338
- _g = 255;
339
- _b = 255;
340
- _a = 255;
341
- get r() {
342
- return this._r;
343
- }
344
- set r(value) {
345
- this._r = clamp(value, 0, 255);
346
- this._hex = this._to_hex();
254
+ // src/math/rectangle.ts
255
+ var Rectangle = class _Rectangle {
256
+ x;
257
+ y;
258
+ width;
259
+ height;
260
+ constructor(x = 0, y = 0, width = 1, height = 1) {
261
+ this.x = x;
262
+ this.y = y;
263
+ this.width = width;
264
+ this.height = height;
347
265
  }
348
- get g() {
349
- return this._g;
266
+ area() {
267
+ return this.width * this.height;
350
268
  }
351
- set g(value) {
352
- this._g = clamp(value, 0, 255);
353
- this._hex = this._to_hex();
269
+ contains(target, padding = 0) {
270
+ 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;
354
271
  }
355
- get b() {
356
- return this._b;
272
+ intersects(other, padding = 0) {
273
+ 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);
357
274
  }
358
- set b(value) {
359
- this._b = clamp(value, 0, 255);
360
- this._hex = this._to_hex();
275
+ center() {
276
+ return new Vector(
277
+ this.x + this.width / 2,
278
+ this.y + this.height / 2
279
+ );
361
280
  }
362
- get a() {
363
- return this._a;
281
+ distanceTo(other) {
282
+ return this.center().distanceTo(other.center());
364
283
  }
365
- set a(value) {
366
- this._a = clamp(value, 0, 255);
367
- this._hex = this._to_hex();
284
+ clone() {
285
+ return new _Rectangle(this.x, this.y, this.width, this.height);
368
286
  }
369
- get hexStr() {
370
- return this._hex;
287
+ equals(other) {
288
+ return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
371
289
  }
372
- set hexStr(value) {
373
- if (value.startsWith("#")) {
374
- [this._r, this._g, this._b, this._a] = this._parse_hex_color_string(value);
375
- this._hex = value;
376
- } else {
377
- logwrn(`Color: invalid color string: ${value}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Keeping the current color.`);
378
- }
290
+ grow(padding) {
291
+ return new _Rectangle(
292
+ this.x - padding,
293
+ this.y - padding,
294
+ this.width + padding * 2,
295
+ this.height + padding * 2
296
+ );
379
297
  }
380
- get rgba() {
381
- return [this._r, this._g, this._b, this._a];
298
+ vectorInside(vec, padding = 0) {
299
+ 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;
382
300
  }
383
- constructor(r = 255, g = 255, b = 255, a = 255) {
384
- if (typeof r === "string") {
385
- if (r.startsWith("#")) {
386
- [r, g, b, a] = this._parse_hex_color_string(r);
387
- } else {
388
- logwrn(`Color: invalid color string: ${r}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Defaulting to opaque white.`);
389
- r = g = b = a = 255;
390
- }
391
- } else {
392
- [r, g, b, a] = [r, g, b, a].map((n) => _Color._normalize(n));
393
- }
394
- this.r = r;
395
- this.g = g;
396
- this.b = b;
397
- this.a = a;
301
+ };
302
+
303
+ // src/math/vector.ts
304
+ var Vector = class _Vector {
305
+ x;
306
+ y;
307
+ constructor(x = 0, y = 0) {
308
+ this.x = x;
309
+ this.y = y;
398
310
  }
399
- static _normalize(value) {
400
- return clamp(0 | (value > 0 && value < 1 ? value * 255 : value), 0, 255);
311
+ clone() {
312
+ return new _Vector(this.x, this.y);
401
313
  }
402
- _to_hex() {
403
- 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")}`;
314
+ distanceTo(that) {
315
+ return distance2d(
316
+ this.x,
317
+ this.y,
318
+ that.x,
319
+ that.y
320
+ );
404
321
  }
405
- _parse_hex_color_string(hex) {
406
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex);
407
- return result ? [
408
- parseInt(result[1], 16),
409
- parseInt(result[2], 16),
410
- parseInt(result[3], 16),
411
- result[4] ? parseInt(result[4], 16) : 255
412
- ] : [255, 255, 255, 255];
322
+ floored() {
323
+ return new _Vector(
324
+ Math.floor(this.x),
325
+ Math.floor(this.y)
326
+ );
413
327
  }
414
- static fromHsv(h, s, v, a = 255) {
415
- let r = 0;
416
- let g = 0;
417
- let b = 0;
418
- let i = Math.floor(h * 6);
419
- let f = h * 6 - i;
420
- let p = v * (1 - s);
421
- let q = v * (1 - f * s);
422
- let t = v * (1 - (1 - f) * s);
423
- switch (i % 6) {
424
- case 0:
425
- r = v, g = t, b = p;
426
- break;
427
- case 1:
428
- r = q, g = v, b = p;
429
- break;
430
- case 2:
431
- r = p, g = v, b = t;
432
- break;
433
- case 3:
434
- r = p, g = q, b = v;
435
- break;
436
- case 4:
437
- r = t, g = p, b = v;
438
- break;
439
- case 5:
440
- r = v, g = p, b = q;
441
- break;
328
+ plus(x, y) {
329
+ if (x instanceof _Vector) {
330
+ y = x.y;
331
+ x = x.x;
332
+ } else if (y === void 0) {
333
+ y = x;
442
334
  }
443
- return new _Color(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
444
- }
445
- static get BLACK() {
446
- return new _Color(0, 0, 0, 255);
447
- }
448
- static get GRAY() {
449
- return new _Color(128, 128, 128, 255);
450
- }
451
- static get WHITE() {
452
- return new _Color(255, 255, 255, 255);
453
- }
454
- static get RED() {
455
- return new _Color(255, 0, 0, 255);
456
- }
457
- static get GREEN() {
458
- return new _Color(0, 255, 0, 255);
459
- }
460
- static get BLUE() {
461
- return new _Color(0, 0, 255, 255);
462
- }
463
- static get YELLOW() {
464
- return new _Color(255, 255, 0, 255);
465
- }
466
- static get ORANGE() {
467
- return new _Color(255, 128, 0, 255);
468
- }
469
- static get PURPLE() {
470
- return new _Color(128, 0, 128, 255);
471
- }
472
- static get CYAN() {
473
- return new _Color(0, 255, 255, 255);
474
- }
475
- static get MAGENTA() {
476
- return new _Color(255, 0, 255, 255);
477
- }
478
- static fromName(name) {
479
- const element = document.createElement("div");
480
- element.style.color = name;
481
- document.body.appendChild(element);
482
- const computedColor = getComputedStyle(element).color;
483
- document.body.removeChild(element);
484
- const rgba = computedColor.match(/\d+/g);
485
- if (rgba && rgba.length === 4) {
486
- const [r, g, b, a] = rgba.map(Number);
487
- return new _Color(r, g, b, a);
488
- } else {
489
- logwrn(`Color: invalid CSS color name: ${name}. Defaulting to transparent.`);
490
- return _Color.TRANSPARENT;
491
- }
492
- }
493
- static get TRANSPARENT() {
494
- return new _Color(0, 0, 0, 0);
495
- }
496
- };
497
-
498
- // src/dungeon-generator.ts
499
- import { Heap } from "heap-js";
500
-
501
- // src/map2d.ts
502
- var DEFAULT_VALUE = -1;
503
- var Map2D = class {
504
- defaultValue;
505
- _data;
506
- get size() {
507
- return this._data.size;
508
- }
509
- constructor(defaultValue = DEFAULT_VALUE) {
510
- this.defaultValue = defaultValue;
511
- this._data = /* @__PURE__ */ new Map();
512
- }
513
- _floor(x, y) {
514
- return [floor(x), floor(y)];
515
- }
516
- _key(x, y) {
517
- return `${x},${y}`;
518
- }
519
- _pos(key) {
520
- return key.split(",").map((v) => parseInt(v));
521
- }
522
- clear() {
523
- this._data.clear();
524
- }
525
- get(x, y, defaultValue = this.defaultValue) {
526
- [x, y] = this._floor(x, y);
527
- return this._data.get(this._key(x, y)) ?? defaultValue;
528
- }
529
- set(x, y, value = this.defaultValue) {
530
- [x, y] = this._floor(x, y);
531
- const key = this._key(x, y);
532
- if (value === this.defaultValue) {
533
- this._data.delete(key);
534
- } else {
535
- this._data.set(key, value);
536
- }
537
- }
538
- forEach(callback) {
539
- this._data.forEach((v, key) => {
540
- const [x, y] = this._pos(key);
541
- callback(x, y, v);
542
- });
543
- }
544
- };
545
-
546
- // src/vector.ts
547
- var Vector = class _Vector {
548
- x;
549
- y;
550
- constructor(x = 0, y = 0) {
551
- this.x = x;
552
- this.y = y;
553
- }
554
- clone() {
555
- return new _Vector(this.x, this.y);
556
- }
557
- distanceTo(that) {
558
- return distance(
559
- this.x,
560
- this.y,
561
- that.x,
562
- that.y
563
- );
564
- }
565
- floored() {
566
- return new _Vector(
567
- Math.floor(this.x),
568
- Math.floor(this.y)
569
- );
570
- }
571
- plus(x, y) {
572
- if (x instanceof _Vector) {
573
- y = x.y;
574
- x = x.x;
575
- } else if (y === void 0) {
576
- y = x;
577
- }
578
- this.x += x;
579
- this.y += y;
580
- return this;
335
+ this.x += x;
336
+ this.y += y;
337
+ return this;
581
338
  }
582
339
  minus(x, y) {
583
340
  if (x instanceof _Vector) {
@@ -626,57 +383,63 @@ var Vector = class _Vector {
626
383
  }
627
384
  };
628
385
 
629
- // src/rectangle.ts
630
- var Rectangle = class _Rectangle {
631
- x;
632
- y;
633
- width;
634
- height;
635
- constructor(x = 0, y = 0, width = 1, height = 1) {
636
- this.x = x;
637
- this.y = y;
638
- this.width = width;
639
- this.height = height;
640
- }
641
- area() {
642
- return this.width * this.height;
386
+ // src/dungeon-generator.ts
387
+ import { Heap } from "heap-js";
388
+
389
+ // src/log.ts
390
+ var log = console.debug.bind(
391
+ console,
392
+ "%c[dev]",
393
+ "font-weight: bold; color: #888;"
394
+ );
395
+
396
+ // src/map2d.ts
397
+ var DEFAULT_VALUE = -1;
398
+ var Map2D = class {
399
+ defaultValue;
400
+ _data;
401
+ get size() {
402
+ return this._data.size;
643
403
  }
644
- contains(target, padding = 0) {
645
- 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;
404
+ constructor(defaultValue = DEFAULT_VALUE) {
405
+ this.defaultValue = defaultValue;
406
+ this._data = /* @__PURE__ */ new Map();
646
407
  }
647
- intersects(other, padding = 0) {
648
- 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);
408
+ _floor(x, y) {
409
+ return [floor(x), floor(y)];
649
410
  }
650
- center() {
651
- return new Vector(
652
- this.x + this.width / 2,
653
- this.y + this.height / 2
654
- );
411
+ _key(x, y) {
412
+ return `${x},${y}`;
655
413
  }
656
- distanceTo(other) {
657
- return this.center().distanceTo(other.center());
414
+ _pos(key) {
415
+ return key.split(",").map((v) => parseInt(v));
658
416
  }
659
- clone() {
660
- return new _Rectangle(this.x, this.y, this.width, this.height);
417
+ clear() {
418
+ this._data.clear();
661
419
  }
662
- equals(other) {
663
- return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
420
+ get(x, y, defaultValue = this.defaultValue) {
421
+ [x, y] = this._floor(x, y);
422
+ return this._data.get(this._key(x, y)) ?? defaultValue;
664
423
  }
665
- grow(padding) {
666
- return new _Rectangle(
667
- this.x - padding,
668
- this.y - padding,
669
- this.width + padding * 2,
670
- this.height + padding * 2
671
- );
424
+ set(x, y, value = this.defaultValue) {
425
+ [x, y] = this._floor(x, y);
426
+ const key = this._key(x, y);
427
+ if (value === this.defaultValue) {
428
+ this._data.delete(key);
429
+ } else {
430
+ this._data.set(key, value);
431
+ }
672
432
  }
673
- vectorInside(vec, padding = 0) {
674
- 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;
433
+ forEach(callback) {
434
+ this._data.forEach((v, key) => {
435
+ const [x, y] = this._pos(key);
436
+ callback(x, y, v);
437
+ });
675
438
  }
676
439
  };
677
440
 
678
441
  // src/rng.ts
679
- var Rng = class {
442
+ var RandomNumberGenerator = class {
680
443
  __seed;
681
444
  _seed;
682
445
  _uid_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -708,10 +471,6 @@ var Rng = class {
708
471
  get nexti() {
709
472
  return this.nextf * Number.MAX_SAFE_INTEGER | 0;
710
473
  }
711
- // NOTE: as of the core/apparatus consolidation, range(min, max) treats
712
- // max as EXCLUSIVE (previous published versions of this package treated
713
- // it as inclusive - if you're upgrading from an older @n3rdw1z4rd/core,
714
- // range(0, 10) now returns [0, 10) instead of [0, 10]).
715
474
  range(min2, max2) {
716
475
  if (max2 === void 0) {
717
476
  max2 = min2;
@@ -723,9 +482,6 @@ var Rng = class {
723
482
  const theta = this.nextf * 2 * PI;
724
483
  return [cos(theta), sin(theta)];
725
484
  }
726
- // Box-Muller-ish gaussian sample, mean 0.5 stddev 1/6 (so ~99.7% of
727
- // samples land in [0, 1]). Uses native Math.log since a pure natural-log
728
- // implementation isn't part of math.ts yet.
729
485
  parkMillerNormal() {
730
486
  const mean = 1 / 2;
731
487
  const stddev = 1 / 6;
@@ -773,7 +529,7 @@ var Rng = class {
773
529
  return rows;
774
530
  }
775
531
  };
776
- var rng = new Rng();
532
+ var rng = new RandomNumberGenerator();
777
533
 
778
534
  // src/dungeon-generator.ts
779
535
  var TILE_EMPTY = 0;
@@ -930,7 +686,7 @@ function _getShortestPathBetweenRects(rectA, rectB) {
930
686
  let paths = { a: edgeA[0], b: edgeB[0], distance: Infinity };
931
687
  for (const a of edgeA) {
932
688
  for (const b of edgeB) {
933
- const d = distance(a.x, a.y, b.x, b.y);
689
+ const d = distance2d(a.x, a.y, b.x, b.y);
934
690
  if (d < paths.distance) {
935
691
  paths = { a, b, distance: d };
936
692
  }
@@ -989,384 +745,100 @@ function GenerateWalls(map) {
989
745
  }
990
746
 
991
747
  // src/ecs.ts
992
- var ECS = class _ECS {
993
- _globals = /* @__PURE__ */ new Map();
994
- _entities = /* @__PURE__ */ new Map();
995
- _components = /* @__PURE__ */ new Map();
996
- _defaultComponents = [];
997
- _systems = /* @__PURE__ */ new Map();
998
- _onTickStartCallbacks = [];
999
- _onTickEndCallbacks = [];
1000
- get components() {
1001
- return [...this._components.keys()];
1002
- }
1003
- get systems() {
1004
- return [...this._systems.keys()];
1005
- }
1006
- get entities() {
1007
- return [...this._entities.values()];
1008
- }
1009
- uid(length = 8) {
1010
- const numBytes = Math.ceil(length / 2);
1011
- const buffer = new Uint8Array(numBytes);
1012
- window.crypto.getRandomValues(buffer);
1013
- let uid = "";
1014
- for (let i = 0; i < buffer.length; i++) {
1015
- uid += buffer[i].toString(16).padStart(2, "0");
1016
- }
1017
- return uid.substring(0, length);
1018
- }
1019
- createComponent(uid, data = null) {
1020
- if (!this._components.has(uid)) {
1021
- this._components.set(uid, data);
1022
- log("created component:", { uid, data });
1023
- } else {
1024
- logwrn("createComponent: a component already exists with uid:", uid);
1025
- }
1026
- return this;
1027
- }
1028
- includeAsDefaultComponents(...components) {
1029
- components.forEach((component) => {
1030
- if (!this._defaultComponents.includes(component)) {
1031
- this._defaultComponents.push(component);
1032
- log("includeAsDefaultComponents:", component);
1033
- } else {
1034
- log("includeAsDefaultComponents: already exists:", component);
1035
- }
1036
- });
1037
- return this;
1038
- }
1039
- createSystem(uid, ...components) {
1040
- const callback = components.pop();
1041
- const comps = components.filter((comp) => typeof comp === "string");
1042
- if (!this._systems.has(uid)) {
1043
- this._systems.set(uid, { components: comps, callback });
1044
- log("created system:", { uid, components, callback });
1045
- } else {
1046
- logwrn("createSystem: a system already exists with uid:", uid);
1047
- }
1048
- return this;
1049
- }
1050
- createEntityWithUid(uid, ...components) {
1051
- if (!this._entities.has(uid)) {
1052
- const componentList = [
1053
- .../* @__PURE__ */ new Set([
1054
- ...this._defaultComponents,
1055
- ...components
1056
- ])
1057
- ];
1058
- const comps = /* @__PURE__ */ new Map();
1059
- componentList.forEach((component) => {
1060
- if (this._components.has(component)) {
1061
- const componentData = this._components.get(component);
1062
- const data = {};
1063
- for (const uid2 in componentData) {
1064
- const value = componentData[uid2];
1065
- data[uid2] = typeof value === "function" ? value(uid2) : value;
1066
- }
1067
- comps.set(component, data);
1068
- } else {
1069
- logwrn("createEntityWithUid: missing component:", component);
1070
- }
1071
- });
1072
- if (comps.size === componentList.length) {
1073
- const entity = { uid, components: comps };
1074
- this._entities.set(uid, entity);
1075
- log("created entity:", entity);
1076
- } else {
1077
- logwrn("createEntityWithUid: failed to create an entity with missing components");
748
+ var ECS = class {
749
+ nextEntityId = 1;
750
+ components = /* @__PURE__ */ new Map();
751
+ createEntity() {
752
+ return this.nextEntityId++;
753
+ }
754
+ addComponent(entity, name, data) {
755
+ if (!this.components.has(name)) {
756
+ this.components.set(name, /* @__PURE__ */ new Map());
757
+ }
758
+ this.components.get(name).set(entity, data);
759
+ }
760
+ getComponent(entity, name) {
761
+ return this.components.get(name)?.get(entity);
762
+ }
763
+ removeComponent(entity, name) {
764
+ this.components.get(name)?.delete(entity);
765
+ }
766
+ getEntitiesWithComponents(...componentNames) {
767
+ if (componentNames.length === 0) return [];
768
+ const first = this.components.get(componentNames[0]);
769
+ if (!first) return [];
770
+ const result = [];
771
+ for (const entity of first.keys()) {
772
+ if (componentNames.every((name) => this.components.get(name)?.has(entity))) {
773
+ result.push(entity);
1078
774
  }
1079
- } else {
1080
- logwrn("createEntityWithUid: an entity already exists with uid:", uid);
1081
775
  }
1082
- return this;
776
+ return result;
1083
777
  }
1084
- createEntity(...components) {
1085
- const uid = this.uid();
1086
- return this.createEntityWithUid(uid, ...components);
778
+ };
779
+
780
+ // src/input/index.ts
781
+ var Input = class extends Emitter {
782
+ _down = /* @__PURE__ */ new Map();
783
+ _pointerPosition = new Vector();
784
+ inputThreshold = 200;
785
+ get down() {
786
+ return this._down;
1087
787
  }
1088
- createEntities(count, ...components) {
1089
- for (; count > 0; count--) {
1090
- this.createEntity(...components);
1091
- }
1092
- return this;
788
+ get pointerPosition() {
789
+ return this._pointerPosition;
1093
790
  }
1094
- getEntity(uid) {
1095
- return this._entities.get(uid);
1096
- }
1097
- getEntitiesWithComponents(...components) {
1098
- const filter = components.pop();
1099
- const uids = components.filter((component) => typeof component === "string");
1100
- const entities = [];
1101
- this._entities.forEach((entity) => {
1102
- if (uids.every(
1103
- (component) => [...entity.components.keys()].includes(component)
1104
- )) {
1105
- for (const filterComponent in filter) {
1106
- for (const filterKey in filter[filterComponent]) {
1107
- const entityValue = entity.components.get(filterComponent)[filterKey];
1108
- const filterValue = filter[filterComponent][filterKey];
1109
- if (entityValue === filterValue) {
1110
- entities.push(entity);
1111
- }
1112
- }
1113
- }
791
+ constructor() {
792
+ super();
793
+ window.addEventListener("contextmenu", (ev) => {
794
+ log("contextmenu:", ev);
795
+ });
796
+ window.addEventListener("keydown", (ev) => {
797
+ const { code, repeat, timeStamp } = ev;
798
+ if (!repeat) {
799
+ this._down.set(code, { state: 1, time: timeStamp });
800
+ this.emit("key_down", code, ev);
1114
801
  }
1115
802
  });
1116
- return entities;
1117
- }
1118
- addComponent(uid, component, values = {}) {
1119
- const entity = this._entities.get(uid);
1120
- if (entity) {
1121
- if (this._components.has(component)) {
1122
- const comp = this._components.get(component);
1123
- const componentData = {
1124
- ...comp,
1125
- ...values
1126
- };
1127
- entity.components.set(component, componentData);
1128
- log("addComponent: added component:", component, "to entity:", uid);
1129
- } else {
1130
- logwrn("addComponent: component not found:", component);
803
+ window.addEventListener("keyup", (ev) => {
804
+ const { code, timeStamp } = ev;
805
+ const delta = timeStamp - (this._down.get(code)?.time ?? 0);
806
+ this._down.set(code, { state: 0, time: timeStamp });
807
+ this.emit("key_up", code, ev);
808
+ if (delta < this.inputThreshold) {
809
+ this.emit("key_pressed", code, ev);
1131
810
  }
1132
- } else {
1133
- logwrn("addComponent: entity not found:", uid);
1134
- }
1135
- return this;
1136
- }
1137
- onAllEntitiesNow(callback) {
1138
- this._entities.forEach((entity) => callback(entity));
1139
- log("onAllEntitiesNow: executed on all entities:", callback);
1140
- return this;
1141
- }
1142
- duplicateEntity(uid, count = 1, deep = false) {
1143
- const entity = this._entities.get(uid);
1144
- if (entity) {
1145
- if (!deep) {
1146
- for (let i = 0; i < count; i++) this.createEntity(...entity.components.keys());
1147
- } else {
1148
- for (let i = 0; i < count; i++) {
1149
- const newEntity = { uid: this.uid(), components: /* @__PURE__ */ new Map() };
1150
- entity.components.forEach((value, key) => {
1151
- newEntity.components.set(key, value);
1152
- });
1153
- this._entities.set(newEntity.uid, newEntity);
1154
- }
1155
- ;
811
+ });
812
+ window.addEventListener("pointerdown", (ev) => {
813
+ const { button, timeStamp } = ev;
814
+ const code = `Button${button}`;
815
+ if (!this._down.get(code)) {
816
+ this._down.set(code, { state: 1, time: timeStamp });
817
+ this.emit("pointer_down", code, ev);
1156
818
  }
1157
- log("duplicateEntity: duplicated entity:", uid);
1158
- } else {
1159
- logwrn("duplicateEntity: entity not found:", uid);
1160
- }
1161
- return this;
819
+ });
820
+ window.addEventListener("pointerup", (ev) => {
821
+ const { button, timeStamp } = ev;
822
+ const code = `Button${button}`;
823
+ const delta = timeStamp - (this._down.get(code)?.time ?? 0);
824
+ this._down.set(code, { state: 0, time: timeStamp });
825
+ if (delta < this.inputThreshold) {
826
+ this.emit("button_clicked", code, ev);
827
+ }
828
+ });
829
+ window.addEventListener("mousemove", (ev) => {
830
+ const { offsetX, offsetY, movementX, movementY } = ev;
831
+ this._pointerPosition.x = offsetX;
832
+ this._pointerPosition.y = offsetY;
833
+ this.emit("pointer_move", movementX, movementY, ev);
834
+ });
835
+ window.addEventListener("wheel", (ev) => {
836
+ const { deltaY } = ev;
837
+ this.emit("wheel", deltaY, ev);
838
+ });
1162
839
  }
1163
- getGlobal(key) {
1164
- return this._globals.get(key);
1165
- }
1166
- setGlobal(key, value) {
1167
- this._globals.set(key, value);
1168
- return this;
1169
- }
1170
- beforeTick(callback) {
1171
- this._onTickStartCallbacks.push(callback);
1172
- log("beforeTick: added:", callback);
1173
- return this;
1174
- }
1175
- afterTick(callback) {
1176
- this._onTickEndCallbacks.push(callback);
1177
- log("afterTick: added:", callback);
1178
- return this;
1179
- }
1180
- runSystem(uid) {
1181
- const system = this._systems.get(uid);
1182
- if (system) {
1183
- this._entities.forEach((entity) => {
1184
- if (system.components.every(
1185
- (component) => [...entity.components.keys()].includes(component)
1186
- )) {
1187
- system.callback(entity, Object.fromEntries(entity.components));
1188
- }
1189
- });
1190
- } else {
1191
- logwrn("runSystem: system not found:", uid);
1192
- }
1193
- return this;
1194
- }
1195
- update() {
1196
- this._onTickStartCallbacks.forEach((cb) => cb());
1197
- this._systems.forEach((_, uid) => this.runSystem(uid));
1198
- this._onTickEndCallbacks.forEach((cb) => cb());
1199
- }
1200
- static get instance() {
1201
- if (!_ECS._instance) {
1202
- _ECS._instance = new _ECS();
1203
- }
1204
- return _ECS._instance;
1205
- }
1206
- static _instance;
1207
- constructor() {
1208
- }
1209
- };
1210
-
1211
- // src/emitter.ts
1212
- var Emitter = class {
1213
- listeners = /* @__PURE__ */ new Map();
1214
- constructor() {
1215
- }
1216
- on(...eventName) {
1217
- const listener = eventName.pop();
1218
- const events = eventName.filter((ev) => typeof ev === "string");
1219
- events.forEach((event) => {
1220
- if (!this.listeners.has(event)) {
1221
- this.listeners.set(event, new Array());
1222
- }
1223
- this.listeners.get(event)?.push(listener);
1224
- });
1225
- return this;
1226
- }
1227
- emit(eventName, ...args) {
1228
- this.listeners.get(eventName)?.forEach((listener) => listener(...args, eventName));
1229
- return this;
1230
- }
1231
- clear(eventName) {
1232
- if (eventName) {
1233
- this.listeners.delete(eventName);
1234
- } else {
1235
- this.listeners.clear();
1236
- }
1237
- return this;
1238
- }
1239
- };
1240
- var GlobalEmitter = new Emitter();
1241
- var EventBus = class extends EventTarget {
1242
- emit(type, detail) {
1243
- this.dispatchEvent(new CustomEvent(type, { detail }));
1244
- }
1245
- on(type, cb) {
1246
- this.addEventListener(type, cb);
1247
- }
1248
- };
1249
- var eventBus = new EventBus();
1250
-
1251
- // src/input.ts
1252
- var Input = class extends Emitter {
1253
- inputThreshold = 200;
1254
- _keyStates = {};
1255
- _mouseButtonStates = {};
1256
- _mousePosition = [0, 0];
1257
- _mousePosition2 = [0, 0];
1258
- get mousePosition() {
1259
- return this._mousePosition;
1260
- }
1261
- get mousePosition2() {
1262
- return this._mousePosition2;
1263
- }
1264
- constructor() {
1265
- super();
1266
- window.addEventListener("keydown", this._onKeyDown.bind(this));
1267
- window.addEventListener("keyup", this._onKeyUp.bind(this));
1268
- window.addEventListener("mousedown", this._onMouseButtonDown.bind(this));
1269
- window.addEventListener("mouseup", this._onMouseButtonUp.bind(this));
1270
- window.addEventListener("mousemove", this._onMouseMove.bind(this));
1271
- window.addEventListener("wheel", this._onWheel.bind(this));
1272
- }
1273
- _getCommonEventProps(ev) {
1274
- const props = {
1275
- timeStamp: ev.timeStamp,
1276
- altKey: ev.altKey,
1277
- ctrlKey: ev.ctrlKey,
1278
- metaKey: ev.metaKey,
1279
- shiftKey: ev.shiftKey
1280
- };
1281
- return props;
1282
- }
1283
- // private _onContextMenu(ev: MouseEvent) {
1284
- // ev.preventDefault();
1285
- // this.emit('contextmenu');
1286
- // return false;
1287
- // }
1288
- _onKeyDown(ev) {
1289
- const props = this._getCommonEventProps(ev);
1290
- const { code, key } = ev;
1291
- if (!ev.repeat) {
1292
- this._keyStates[code] = { state: 1, timeStamp: props.timeStamp };
1293
- this.emit("key_down", { ...props, code, key });
1294
- this.emit(`${code.toLowerCase()}_down`, props);
1295
- }
1296
- }
1297
- _onKeyUp(ev) {
1298
- const props = this._getCommonEventProps(ev);
1299
- const { code, key } = ev;
1300
- const deltaStamp = props.timeStamp - (this._keyStates[code]?.timeStamp ?? 0);
1301
- this._keyStates[code] = { state: 0, timeStamp: props.timeStamp };
1302
- this.emit("key_up", { ...props, code, key });
1303
- this.emit(`${code.toLowerCase()}_up`, props);
1304
- if (deltaStamp < this.inputThreshold) {
1305
- this.emit("key_pressed", { ...props, code, key });
1306
- this.emit(`${code.toLowerCase()}_pressed`, props);
1307
- }
1308
- }
1309
- _onMouseButtonDown(ev) {
1310
- const props = this._getCommonEventProps(ev);
1311
- const { button } = ev;
1312
- if (!this._mouseButtonStates[button]?.state) {
1313
- this._mouseButtonStates[button] = { state: 1, timeStamp: props.timeStamp };
1314
- this.emit("mouse_button_down", { ...props, button });
1315
- this.emit(`mouse_button_${button}_down`, props);
1316
- }
1317
- }
1318
- _onMouseButtonUp(ev) {
1319
- const props = this._getCommonEventProps(ev);
1320
- const { button } = ev;
1321
- const deltaStamp = props.timeStamp - (this._mouseButtonStates[button]?.timeStamp ?? 0);
1322
- this._mouseButtonStates[button] = { state: 0, timeStamp: props.timeStamp };
1323
- this.emit("mouse_button_up", { ...props, button });
1324
- this.emit(`mouse_button_${button}_up`, props);
1325
- if (deltaStamp < this.inputThreshold) {
1326
- this.emit("mouse_button_clicked", { ...props, button });
1327
- this.emit(`mouse_button_${button}_clicked`, props);
1328
- }
1329
- }
1330
- _onMouseMove(ev) {
1331
- const props = this._getCommonEventProps(ev);
1332
- const { buttons, offsetX, offsetY, movementX, movementY } = ev;
1333
- this._mousePosition = [offsetX, offsetY];
1334
- const width = window.innerWidth;
1335
- const height = window.innerHeight;
1336
- this._mousePosition2 = [
1337
- ev.clientX / width * 2 - 1,
1338
- -(ev.clientY / height) * 2 + 1
1339
- ];
1340
- this.emit("mouse_move", {
1341
- ...props,
1342
- buttons,
1343
- x: offsetX,
1344
- y: offsetY,
1345
- deltaX: movementX,
1346
- deltaY: movementY
1347
- });
1348
- }
1349
- _onWheel(ev) {
1350
- const props = this._getCommonEventProps(ev);
1351
- const { deltaX, deltaY, deltaZ } = ev;
1352
- this.emit("mouse_wheel", {
1353
- ...props,
1354
- deltaX,
1355
- deltaY,
1356
- deltaZ
1357
- });
1358
- }
1359
- isKeyDown(keyCode) {
1360
- return this._keyStates[keyCode]?.state === 1 ? true : false;
1361
- }
1362
- getKeyState(keyCode) {
1363
- return this._keyStates[keyCode]?.state ?? 0;
1364
- }
1365
- isMouseButtonDown(mouseButton) {
1366
- return this._mouseButtonStates[mouseButton]?.state === 1 ? true : false;
1367
- }
1368
- getMouseButtonState(button) {
1369
- return this._mouseButtonStates[button]?.state ?? 0;
840
+ isDown(name) {
841
+ return this._down.get(name) ? true : false;
1370
842
  }
1371
843
  };
1372
844
 
@@ -1419,6 +891,9 @@ var Map3D = class {
1419
891
  function isNullOrUndefined(target) {
1420
892
  return target === null || target === void 0;
1421
893
  }
894
+ function isPositiveString(target) {
895
+ return target.length > 0;
896
+ }
1422
897
  var getRedYellowGreenGradientHex = (min2, max2) => {
1423
898
  if (max2 === void 0) {
1424
899
  max2 = min2;
@@ -1443,6 +918,18 @@ var getRedYellowGreenGradientHex = (min2, max2) => {
1443
918
  "#00ff00"
1444
919
  ][index];
1445
920
  };
921
+ function GetUrlParams() {
922
+ const params = {};
923
+ const url = new URLSearchParams(location.search);
924
+ for (const [key, value] of url.entries()) {
925
+ params[key] = value;
926
+ }
927
+ return params;
928
+ }
929
+ var xy2k = (x, y, delimiter = ",") => `${x}${delimiter}${y}`;
930
+ var k2xy = (key, delimiter = ",") => key.split(delimiter).map(parseFloat);
931
+ var xyz2k = (x, y, z, delimiter = ",") => `${x}${delimiter},${y},${delimiter},${z}`;
932
+ var k2xyz = (key, delimiter = ",") => key.split(delimiter).map(parseFloat);
1446
933
 
1447
934
  // src/noise.ts
1448
935
  import { createNoise2D, createNoise3D, createNoise4D } from "simplex-noise";
@@ -1505,154 +992,264 @@ var Noise = class _Noise {
1505
992
  }
1506
993
  };
1507
994
 
1508
- // src/particle-renderer.ts
1509
- var Renderer = class {
1510
- _screenCanvas;
1511
- _bufferCanvas;
1512
- screenContext;
1513
- bufferContext;
1514
- get width() {
1515
- return this._screenCanvas.width;
995
+ // src/rendering/color.ts
996
+ var Color = class _Color {
997
+ _hex = "#ffffffff";
998
+ _r = 255;
999
+ _g = 255;
1000
+ _b = 255;
1001
+ _a = 255;
1002
+ get r() {
1003
+ return this._r;
1516
1004
  }
1517
- get height() {
1518
- return this._screenCanvas.height;
1005
+ set r(value) {
1006
+ this._r = clamp(value, 0, 255);
1007
+ this._hex = this._to_hex();
1519
1008
  }
1520
- constructor(canvas) {
1521
- this._screenCanvas = canvas ?? document.createElement("canvas");
1522
- this._bufferCanvas = new OffscreenCanvas(this._screenCanvas.width, this._screenCanvas.height);
1523
- this.screenContext = this._screenCanvas.getContext("2d");
1524
- this.bufferContext = this._bufferCanvas.getContext("2d");
1525
- if (!this.screenContext || !this.bufferContext) {
1526
- throw "Failed to create CanvasRenderingContext2D";
1527
- }
1009
+ get g() {
1010
+ return this._g;
1528
1011
  }
1529
- appendTo(target, autoResize = true) {
1530
- if (this._screenCanvas.parentNode) {
1531
- this._screenCanvas.parentNode.removeChild(this._screenCanvas);
1532
- }
1533
- target.appendChild(this._screenCanvas);
1534
- if (autoResize) {
1535
- this.resize();
1536
- }
1012
+ set g(value) {
1013
+ this._g = clamp(value, 0, 255);
1014
+ this._hex = this._to_hex();
1537
1015
  }
1538
- resize(displayWidth, displayHeight) {
1539
- const { width, height } = this._screenCanvas.parentElement?.getBoundingClientRect() ?? this._screenCanvas.getBoundingClientRect();
1540
- displayWidth = 0 | (displayWidth ?? width);
1541
- displayHeight = 0 | (displayHeight ?? height);
1542
- if (this._screenCanvas.width !== displayWidth || this._screenCanvas.height !== displayHeight) {
1543
- this._screenCanvas.width = displayWidth;
1544
- this._screenCanvas.height = displayHeight;
1545
- this._bufferCanvas.width = displayWidth;
1546
- this._bufferCanvas.height = displayHeight;
1547
- return true;
1548
- }
1549
- return false;
1016
+ get b() {
1017
+ return this._b;
1550
1018
  }
1551
- setPixel(x, y, color, size = 2) {
1552
- this.bufferContext.fillStyle = color.hexStr;
1553
- this.bufferContext.fillRect(x - size / 2, y - size / 2, size, size);
1019
+ set b(value) {
1020
+ this._b = clamp(value, 0, 255);
1021
+ this._hex = this._to_hex();
1554
1022
  }
1555
- render() {
1556
- this.screenContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
1557
- this.screenContext.drawImage(this._bufferCanvas, 0, 0);
1558
- this.bufferContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
1023
+ get a() {
1024
+ return this._a;
1559
1025
  }
1560
- };
1561
-
1562
- // src/spatial-partition-2d.ts
1563
- var SpatialPartition2d = class {
1564
- cells;
1565
- cellSize;
1566
- entities;
1567
- constructor(cellSize, entities) {
1568
- this.cellSize = cellSize;
1569
- this.entities = entities;
1570
- this.cells = Array.from(
1571
- { length: Math.ceil(1 / cellSize) },
1572
- () => Array.from({ length: Math.ceil(1 / cellSize) }, () => [])
1573
- );
1574
- for (const entity of this.entities) {
1575
- this.addEntity(entity);
1576
- }
1026
+ set a(value) {
1027
+ this._a = clamp(value, 0, 255);
1028
+ this._hex = this._to_hex();
1577
1029
  }
1578
- addEntity(entity) {
1579
- const cell = this.getCell(entity.x, entity.y);
1580
- cell.push(entity);
1030
+ get hexStr() {
1031
+ return this._hex;
1581
1032
  }
1582
- getCell(x, y) {
1583
- const cellX = Math.floor(x / this.cellSize);
1584
- const cellY = Math.floor(y / this.cellSize);
1585
- return this.cells[cellY][cellX];
1033
+ set hexStr(value) {
1034
+ if (value.startsWith("#")) {
1035
+ [this._r, this._g, this._b, this._a] = this._parse_hex_color_string(value);
1036
+ this._hex = value;
1037
+ } else {
1038
+ log(`Color: invalid color string: ${value}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Keeping the current color.`);
1039
+ }
1586
1040
  }
1587
- getCellNeighbors(x, y) {
1588
- const neighbors = [];
1589
- for (let dy = -1; dy <= 1; dy++) {
1590
- for (let dx = -1; dx <= 1; dx++) {
1591
- let nx = x + dx;
1592
- let ny = y + dy;
1593
- if (nx < 0) nx = this.cells[0].length - 1;
1594
- else if (nx >= this.cells[0].length) nx = 0;
1595
- if (ny < 0) ny = this.cells.length - 1;
1596
- else if (ny >= this.cells.length) ny = 0;
1597
- neighbors.push(this.cells[ny][nx]);
1041
+ get rgba() {
1042
+ return [this._r, this._g, this._b, this._a];
1043
+ }
1044
+ constructor(r = 255, g = 255, b = 255, a = 255) {
1045
+ if (typeof r === "string") {
1046
+ if (r.startsWith("#")) {
1047
+ [r, g, b, a] = this._parse_hex_color_string(r);
1048
+ } else {
1049
+ log(`Color: invalid color string: ${r}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Defaulting to opaque white.`);
1050
+ r = g = b = a = 255;
1598
1051
  }
1052
+ } else {
1053
+ [r, g, b, a] = [r, g, b, a].map((n) => _Color._normalize(n));
1599
1054
  }
1600
- return neighbors;
1055
+ this.r = r;
1056
+ this.g = g;
1057
+ this.b = b;
1058
+ this.a = a;
1601
1059
  }
1602
- };
1603
-
1604
- // src/particle-system-2d.ts
1605
- var colors = [
1606
- Color.RED,
1607
- Color.GREEN,
1608
- Color.BLUE,
1609
- Color.YELLOW,
1610
- Color.MAGENTA
1611
- ];
1612
- var ParticleSystem2d = class {
1613
- particleCount = 2e3;
1614
- _particleSize = 2;
1615
- _frictionHalfLife = 0.04;
1616
- _range = 0.1;
1617
- _rangeFactor = 0.1;
1618
- _attractionMatrix = rng.randomMatrix(colors.length);
1619
- _particles = [];
1620
- _spatialPartition;
1621
- constructor() {
1622
- for (let i = 0; i < this.particleCount; i++) {
1623
- this._particles.push({
1624
- x: rng.nextf,
1625
- y: rng.nextf,
1626
- vx: 0,
1627
- vy: 0,
1628
- color: rng.range(colors.length)
1629
- });
1630
- }
1631
- this._spatialPartition = new SpatialPartition2d(this._range, this._particles);
1060
+ static _normalize(value) {
1061
+ return clamp(0 | (value > 0 && value < 1 ? value * 255 : value), 0, 255);
1632
1062
  }
1633
- _calcForce(r, a, beta = 0.3) {
1634
- let f = 0;
1635
- if (r < beta) {
1636
- f = r / beta - 1;
1637
- } else if (beta < r && r < 1) {
1638
- f = a * (1 - Math.abs(2 * r - 1 - beta) / (1 - beta));
1639
- }
1640
- return f;
1063
+ _to_hex() {
1064
+ 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")}`;
1641
1065
  }
1642
- _updateVelocities(deltaTimeSeconds) {
1643
- const frictionFactor = Math.pow(
1644
- 0.5,
1645
- deltaTimeSeconds / this._frictionHalfLife
1646
- );
1647
- for (let y = 0; y < this._spatialPartition.cells.length; y++) {
1648
- for (let x = 0; x < this._spatialPartition.cells[y].length; x++) {
1649
- const cell = this._spatialPartition.cells[y][x];
1650
- for (let i = 0; i < cell.length; i++) {
1651
- let fx = 0;
1652
- let fy = 0;
1653
- const p1 = cell[i];
1654
- const neighborCells = this._spatialPartition.getCellNeighbors(x, y);
1655
- for (const neighborCell of neighborCells) {
1066
+ _parse_hex_color_string(hex) {
1067
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex);
1068
+ return result ? [
1069
+ parseInt(result[1], 16),
1070
+ parseInt(result[2], 16),
1071
+ parseInt(result[3], 16),
1072
+ result[4] ? parseInt(result[4], 16) : 255
1073
+ ] : [255, 255, 255, 255];
1074
+ }
1075
+ static fromHsv(h, s, v, a = 255) {
1076
+ let r = 0;
1077
+ let g = 0;
1078
+ let b = 0;
1079
+ let i = Math.floor(h * 6);
1080
+ let f = h * 6 - i;
1081
+ let p = v * (1 - s);
1082
+ let q = v * (1 - f * s);
1083
+ let t = v * (1 - (1 - f) * s);
1084
+ switch (i % 6) {
1085
+ case 0:
1086
+ r = v, g = t, b = p;
1087
+ break;
1088
+ case 1:
1089
+ r = q, g = v, b = p;
1090
+ break;
1091
+ case 2:
1092
+ r = p, g = v, b = t;
1093
+ break;
1094
+ case 3:
1095
+ r = p, g = q, b = v;
1096
+ break;
1097
+ case 4:
1098
+ r = t, g = p, b = v;
1099
+ break;
1100
+ case 5:
1101
+ r = v, g = p, b = q;
1102
+ break;
1103
+ }
1104
+ return new _Color(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
1105
+ }
1106
+ static get BLACK() {
1107
+ return new _Color(0, 0, 0, 255);
1108
+ }
1109
+ static get GRAY() {
1110
+ return new _Color(128, 128, 128, 255);
1111
+ }
1112
+ static get WHITE() {
1113
+ return new _Color(255, 255, 255, 255);
1114
+ }
1115
+ static get RED() {
1116
+ return new _Color(255, 0, 0, 255);
1117
+ }
1118
+ static get GREEN() {
1119
+ return new _Color(0, 255, 0, 255);
1120
+ }
1121
+ static get BLUE() {
1122
+ return new _Color(0, 0, 255, 255);
1123
+ }
1124
+ static get YELLOW() {
1125
+ return new _Color(255, 255, 0, 255);
1126
+ }
1127
+ static get ORANGE() {
1128
+ return new _Color(255, 128, 0, 255);
1129
+ }
1130
+ static get PURPLE() {
1131
+ return new _Color(128, 0, 128, 255);
1132
+ }
1133
+ static get CYAN() {
1134
+ return new _Color(0, 255, 255, 255);
1135
+ }
1136
+ static get MAGENTA() {
1137
+ return new _Color(255, 0, 255, 255);
1138
+ }
1139
+ static fromName(name) {
1140
+ const element = document.createElement("div");
1141
+ element.style.color = name;
1142
+ document.body.appendChild(element);
1143
+ const computedColor = getComputedStyle(element).color;
1144
+ document.body.removeChild(element);
1145
+ const rgba = computedColor.match(/\d+/g);
1146
+ if (rgba && rgba.length === 4) {
1147
+ const [r, g, b, a] = rgba.map(Number);
1148
+ return new _Color(r, g, b, a);
1149
+ } else {
1150
+ log(`Color: invalid CSS color name: ${name}. Defaulting to transparent.`);
1151
+ return _Color.TRANSPARENT;
1152
+ }
1153
+ }
1154
+ static get TRANSPARENT() {
1155
+ return new _Color(0, 0, 0, 0);
1156
+ }
1157
+ };
1158
+
1159
+ // src/spatial-partition-2d.ts
1160
+ var SpatialPartition2d = class {
1161
+ cells;
1162
+ cellSize;
1163
+ entities;
1164
+ constructor(cellSize, entities) {
1165
+ this.cellSize = cellSize;
1166
+ this.entities = entities;
1167
+ this.cells = Array.from(
1168
+ { length: Math.ceil(1 / cellSize) },
1169
+ () => Array.from({ length: Math.ceil(1 / cellSize) }, () => [])
1170
+ );
1171
+ for (const entity of this.entities) {
1172
+ this.addEntity(entity);
1173
+ }
1174
+ }
1175
+ addEntity(entity) {
1176
+ const cell = this.getCell(entity.x, entity.y);
1177
+ cell.push(entity);
1178
+ }
1179
+ getCell(x, y) {
1180
+ const cellX = Math.floor(x / this.cellSize);
1181
+ const cellY = Math.floor(y / this.cellSize);
1182
+ return this.cells[cellY][cellX];
1183
+ }
1184
+ getCellNeighbors(x, y) {
1185
+ const neighbors = [];
1186
+ for (let dy = -1; dy <= 1; dy++) {
1187
+ for (let dx = -1; dx <= 1; dx++) {
1188
+ let nx = x + dx;
1189
+ let ny = y + dy;
1190
+ if (nx < 0) nx = this.cells[0].length - 1;
1191
+ else if (nx >= this.cells[0].length) nx = 0;
1192
+ if (ny < 0) ny = this.cells.length - 1;
1193
+ else if (ny >= this.cells.length) ny = 0;
1194
+ neighbors.push(this.cells[ny][nx]);
1195
+ }
1196
+ }
1197
+ return neighbors;
1198
+ }
1199
+ };
1200
+
1201
+ // src/particle-system-2d.ts
1202
+ var colors = [
1203
+ Color.RED,
1204
+ Color.GREEN,
1205
+ Color.BLUE,
1206
+ Color.YELLOW,
1207
+ Color.MAGENTA
1208
+ ];
1209
+ var ParticleSystem2d = class {
1210
+ particleCount = 2e3;
1211
+ _particleSize = 2;
1212
+ _frictionHalfLife = 0.04;
1213
+ _range = 0.1;
1214
+ _rangeFactor = 0.1;
1215
+ _attractionMatrix = rng.randomMatrix(colors.length);
1216
+ _particles = [];
1217
+ _spatialPartition;
1218
+ constructor() {
1219
+ for (let i = 0; i < this.particleCount; i++) {
1220
+ this._particles.push({
1221
+ x: rng.nextf,
1222
+ y: rng.nextf,
1223
+ vx: 0,
1224
+ vy: 0,
1225
+ color: rng.range(colors.length)
1226
+ });
1227
+ }
1228
+ this._spatialPartition = new SpatialPartition2d(this._range, this._particles);
1229
+ }
1230
+ _calcForce(r, a, beta = 0.3) {
1231
+ let f = 0;
1232
+ if (r < beta) {
1233
+ f = r / beta - 1;
1234
+ } else if (beta < r && r < 1) {
1235
+ f = a * (1 - Math.abs(2 * r - 1 - beta) / (1 - beta));
1236
+ }
1237
+ return f;
1238
+ }
1239
+ _updateVelocities(deltaTimeSeconds) {
1240
+ const frictionFactor = Math.pow(
1241
+ 0.5,
1242
+ deltaTimeSeconds / this._frictionHalfLife
1243
+ );
1244
+ for (let y = 0; y < this._spatialPartition.cells.length; y++) {
1245
+ for (let x = 0; x < this._spatialPartition.cells[y].length; x++) {
1246
+ const cell = this._spatialPartition.cells[y][x];
1247
+ for (let i = 0; i < cell.length; i++) {
1248
+ let fx = 0;
1249
+ let fy = 0;
1250
+ const p1 = cell[i];
1251
+ const neighborCells = this._spatialPartition.getCellNeighbors(x, y);
1252
+ for (const neighborCell of neighborCells) {
1656
1253
  for (let j = 0; j < neighborCell.length; j++) {
1657
1254
  if (cell === neighborCell && i === j) continue;
1658
1255
  const p2 = neighborCell[j];
@@ -1782,547 +1379,212 @@ function PoissonDiskSampler(width, height, minDist, maxPoints = 30) {
1782
1379
  return samples;
1783
1380
  }
1784
1381
 
1785
- // src/renderer/canvas-renderer.ts
1382
+ // src/rendering/canvas-renderer.ts
1786
1383
  var CanvasRenderer = class {
1787
- ctx;
1788
- clearColor = "#000000";
1789
- fontName = "monospace";
1790
- fontSize = 32;
1791
- textAlign = "center";
1792
- textBaseline = "middle";
1384
+ canvas;
1385
+ context;
1386
+ drawCentered = true;
1793
1387
  get width() {
1794
- return this.ctx?.canvas.width ?? 0;
1388
+ return this.context.canvas.width;
1795
1389
  }
1796
1390
  get height() {
1797
- return this.ctx?.canvas.height ?? 0;
1798
- }
1799
- get center() {
1800
- return [this.width / 2, this.height / 2];
1391
+ return this.context.canvas.height;
1801
1392
  }
1802
1393
  constructor(canvas) {
1803
- this.ctx = (canvas ?? document.createElement("canvas")).getContext("2d");
1804
- this.ctx.canvas.style.backgroundColor = "#000000";
1805
- this.ctx.canvas.style.display = "block";
1806
- this.ctx.font = `${this.fontSize}px ${this.fontName}`;
1807
- this.ctx.textAlign = this.textAlign;
1808
- this.ctx.textBaseline = this.textBaseline;
1809
- this.resize();
1810
- this.clear();
1394
+ this.canvas = canvas ?? document.createElement("canvas");
1395
+ this.context = this.canvas.getContext("2d");
1811
1396
  }
1812
- appendTo(target, autoResize = true) {
1813
- if (this.ctx.canvas.parentElement) {
1814
- this.ctx.canvas.parentElement.removeChild(this.ctx.canvas);
1815
- }
1816
- if (target) {
1817
- target.appendChild(this.ctx.canvas);
1818
- if (autoResize) {
1819
- this.resize();
1820
- }
1397
+ appendTo(target) {
1398
+ if (this.canvas.parentNode) {
1399
+ this.canvas.parentNode.removeChild(this.canvas);
1821
1400
  }
1401
+ target.appendChild(this.canvas);
1822
1402
  }
1823
1403
  resize(displayWidth, displayHeight) {
1824
- let resized = false;
1825
- const { width, height } = this.ctx.canvas.parentElement?.getBoundingClientRect() ?? this.ctx.canvas.getBoundingClientRect();
1404
+ const { width, height } = this.canvas.parentElement?.getBoundingClientRect() ?? this.canvas.getBoundingClientRect();
1826
1405
  displayWidth = 0 | (displayWidth ?? width);
1827
1406
  displayHeight = 0 | (displayHeight ?? height);
1828
- if (this.width !== displayWidth || this.height !== displayHeight) {
1829
- this.ctx.canvas.width = displayWidth;
1830
- this.ctx.canvas.height = displayHeight;
1831
- resized = true;
1407
+ if (this.canvas.width !== displayWidth || this.canvas.height !== displayHeight) {
1408
+ this.canvas.width = displayWidth;
1409
+ this.canvas.height = displayHeight;
1410
+ return true;
1832
1411
  }
1833
- return resized;
1412
+ return false;
1834
1413
  }
1835
1414
  clear() {
1836
- this.ctx?.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
1837
- }
1838
- drawPoint(xy, params = {}) {
1839
- const [x, y] = xy;
1840
- const radius = params.radius || 1;
1841
- const fill = params.fill !== false;
1842
- const color = params.color || "#000000";
1843
- this.ctx.fillStyle = color;
1844
- this.ctx.strokeStyle = color;
1845
- this.ctx.beginPath();
1846
- this.ctx.arc(x, y, radius, 0, 2 * Math.PI);
1847
- this.ctx[fill ? "fill" : "stroke"]();
1848
- }
1849
- drawBox(xy, wh, params = {}) {
1850
- const [x, y] = xy;
1851
- const [w, h] = wh;
1852
- const fill = params.fill !== false;
1853
- const color = params.color || "#000000";
1854
- this.ctx.fillStyle = color;
1855
- this.ctx.strokeStyle = color;
1856
- this.ctx.beginPath();
1857
- this.ctx.moveTo(x, y);
1858
- this.ctx.lineTo(x + w, y);
1859
- this.ctx.lineTo(x + w, y + h);
1860
- this.ctx.lineTo(x, y + h);
1861
- this.ctx.closePath();
1862
- this.ctx[fill ? "fill" : "stroke"]();
1863
- }
1864
- drawLine(x1y1x2y2, color = "#000000") {
1865
- const [x1, y1, x2, y2] = x1y1x2y2;
1866
- this.ctx.strokeStyle = color;
1867
- this.ctx.beginPath();
1868
- this.ctx.moveTo(x1, y1);
1869
- this.ctx.lineTo(x2, y2);
1870
- this.ctx.stroke();
1871
- }
1872
- drawText(text, xy, color = "#ffffff", size = this.fontSize, font = this.fontName) {
1873
- const [x, y] = xy;
1874
- this.ctx.fillStyle = color;
1875
- this.ctx.font = `${size}px ${font}`;
1876
- this.ctx.textAlign = this.textAlign;
1877
- this.ctx.textBaseline = this.textBaseline;
1878
- this.ctx.fillText(text, x, y + 0.5);
1879
- }
1880
- // drawNamePlate(name: string, title: string, color = '#bbbbbb', s: number = 12, tile_size: number = 32) {
1881
- // let x = (actor.position.x * tile_size);
1882
- // let y = (actor.position.y * tile_size) - 18;
1883
- // let healthPercent = (actor.health / actor.maxHealth);
1884
- // let healthBarWidth = (healthPercent * tile_size)
1885
- // let healthColor = getRedYellowGreenGradientHex(actor.health, actor.maxHealth);
1886
- // this.drawBox(x, y, tile_size, 3, { fill: true, color: '#666666' });
1887
- // this.drawBox(x, y, healthBarWidth, 3, { fill: true, color: healthColor });
1888
- // if (actor.title) {
1889
- // this.drawBox(x, y - 16, actor.name.length * (this.fontSize / 5), 10, { fill: true, color: '#000000' });
1890
- // this.drawText(actor.name || '', x, y - 16, color, s);
1891
- // this.drawBox(x, y - 7, actor.title.length * (this.fontSize / 5), 10, { fill: true, color: '#000000' });
1892
- // this.drawText(`<${actor.title}>`, x, y - 6, '#00FFFF', s);
1893
- // } else {
1894
- // this.drawBox(x, y - 6, actor.name.length * (this.fontSize / 5), 10, { fill: true, color: '#000000' });
1895
- // this.drawText(actor.name || '', x, y - 6, color, s);
1896
- // }
1897
- // }
1898
- };
1899
-
1900
- // src/renderer/webgl.ts
1901
- var ShaderType = ((ShaderType2) => {
1902
- ShaderType2[ShaderType2["VERTEX"] = WebGL2RenderingContext.VERTEX_SHADER] = "VERTEX";
1903
- ShaderType2[ShaderType2["FRAGMENT"] = WebGL2RenderingContext.FRAGMENT_SHADER] = "FRAGMENT";
1904
- return ShaderType2;
1905
- })(ShaderType || {});
1906
- function CreateWebGlContext(canvas) {
1907
- return (canvas ?? document.createElement("canvas")).getContext("webgl2");
1908
- }
1909
- function ResizeWebGlContext(gl, displayWidth, displayHeight) {
1910
- const canvas = gl.canvas;
1911
- const { width, height } = canvas.parentElement?.getBoundingClientRect() ?? canvas.getBoundingClientRect();
1912
- displayWidth = 0 | (displayWidth ?? width);
1913
- displayHeight = 0 | (displayHeight ?? height);
1914
- if (canvas.width !== displayWidth || canvas.height !== displayHeight) {
1915
- gl.canvas.width = displayWidth;
1916
- gl.canvas.height = displayHeight;
1917
- gl.viewport(0, 0, displayWidth, displayHeight);
1918
- return true;
1415
+ this.context.clearRect(0, 0, this.width, this.height);
1416
+ }
1417
+ drawRect(x, y, width, height, params = {}) {
1418
+ if (this.drawCentered) {
1419
+ x -= width / 2;
1420
+ y -= height / 2;
1421
+ }
1422
+ this.context.strokeStyle = params.strokeColor ?? params.color ?? "white";
1423
+ this.context.fillStyle = params.fillColor ?? params.color ?? "white";
1424
+ this.context.lineWidth = params.size ?? 1;
1425
+ if (params.lineDash) {
1426
+ this.context.setLineDash(params.lineDash);
1427
+ }
1428
+ this.context.beginPath();
1429
+ if (params.filled === true) {
1430
+ this.context.fillRect(x, y, width, height);
1431
+ if (params.strokeColor !== void 0) this.context.strokeRect(x, y, width, height);
1432
+ } else {
1433
+ this.context.strokeRect(x, y, width, height);
1434
+ }
1435
+ if (params.lineDash) {
1436
+ this.context.setLineDash([]);
1437
+ }
1919
1438
  }
1920
- return false;
1921
- }
1922
- function CompileShader(gl, type, source) {
1923
- const shader = gl.createShader(type);
1924
- gl.shaderSource(shader, source);
1925
- gl.compileShader(shader);
1926
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
1927
- throw `CompileShader: failed to compile shader: ${gl.getShaderInfoLog(shader)}`;
1439
+ drawPixel(x, y, params = {}) {
1440
+ const size = abs(params.size || 1);
1441
+ this.drawRect(x, y, size, size, {
1442
+ ...params,
1443
+ filled: true
1444
+ });
1928
1445
  }
1929
- return shader;
1930
- }
1931
- function CreateProgram(gl, vertexShader2, fragmentShader2) {
1932
- if (typeof vertexShader2 === "string") {
1933
- vertexShader2 = CompileShader(gl, ShaderType.VERTEX, vertexShader2);
1446
+ drawLine(x1, y1, x2, y2, params = {}) {
1447
+ this.context.strokeStyle = params.color ?? "white";
1448
+ this.context.lineWidth = params.size ?? 1;
1449
+ if (params.lineDash) {
1450
+ this.context.setLineDash(params.lineDash);
1451
+ }
1452
+ this.context.beginPath();
1453
+ this.context.moveTo(x1, y1);
1454
+ this.context.lineTo(x2, y2);
1455
+ this.context.stroke();
1456
+ if (params.lineDash) {
1457
+ this.context.setLineDash([]);
1458
+ }
1459
+ }
1460
+ drawCircle(x, y, radius, params = {}) {
1461
+ this.context.strokeStyle = params.strokeColor ?? params.color ?? "white";
1462
+ this.context.fillStyle = params.fillColor ?? params.color ?? "white";
1463
+ this.context.lineWidth = params.size ?? 1;
1464
+ if (params.lineDash) {
1465
+ this.context.setLineDash(params.lineDash);
1466
+ }
1467
+ this.context.beginPath();
1468
+ this.context.arc(x, y, radius, 0, 2 * PI);
1469
+ if (params.filled === true) this.context.fill();
1470
+ this.context.stroke();
1471
+ if (params.lineDash) {
1472
+ this.context.setLineDash([]);
1473
+ }
1474
+ }
1475
+ drawText(x, y, text, params = {}) {
1476
+ this.context.font = `${params.size ?? 14}px ${params.fontName ?? "monospace"}`;
1477
+ this.context.textAlign = params.textAlign ?? "left";
1478
+ this.context.textBaseline = params.textBaseline ?? "alphabetic";
1479
+ this.context.fillStyle = params.color ?? "white";
1480
+ this.context.fillText(text, x, y);
1934
1481
  }
1935
- if (typeof fragmentShader2 === "string") {
1936
- fragmentShader2 = CompileShader(gl, ShaderType.FRAGMENT, fragmentShader2);
1482
+ };
1483
+
1484
+ // src/rendering/particle-renderer.ts
1485
+ var ParticleRenderer = class {
1486
+ _screenCanvas;
1487
+ _bufferCanvas;
1488
+ screenContext;
1489
+ bufferContext;
1490
+ get width() {
1491
+ return this._screenCanvas.width;
1937
1492
  }
1938
- const program = gl.createProgram();
1939
- gl.attachShader(program, vertexShader2);
1940
- gl.attachShader(program, fragmentShader2);
1941
- gl.linkProgram(program);
1942
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
1943
- throw `CreateProgram: failed to link program: ${gl.getProgramInfoLog(program)}`;
1493
+ get height() {
1494
+ return this._screenCanvas.height;
1944
1495
  }
1945
- return program;
1946
- }
1947
- function GetProgramLocations(gl, program) {
1948
- const attributes = {};
1949
- const attributeCount = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
1950
- for (let i = 0; i < attributeCount; i++) {
1951
- const info = gl.getActiveAttrib(program, i);
1952
- attributes[info.name] = gl.getAttribLocation(program, info.name);
1953
- }
1954
- const uniforms = {};
1955
- const uniformCount = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
1956
- for (let i = 0; i < uniformCount; i++) {
1957
- const info = gl.getActiveUniform(program, i);
1958
- uniforms[info.name] = gl.getUniformLocation(program, info.name);
1959
- }
1960
- return { attributes, uniforms };
1961
- }
1962
- function CreateProgramInfo(gl, vertexShaderSource, fragmentShaderSource) {
1963
- const program = CreateProgram(
1964
- gl,
1965
- vertexShaderSource,
1966
- fragmentShaderSource
1967
- );
1968
- const locations = GetProgramLocations(gl, program);
1969
- return { program, ...locations };
1970
- }
1971
-
1972
- // src/renderer/webgl-renderer.ts
1973
- var WebGlRenderer = class {
1974
- gl;
1975
- programInfo;
1976
- get canvas() {
1977
- return this.gl.canvas;
1978
- }
1979
- get width() {
1980
- return this.gl.canvas.width;
1981
- }
1982
- get height() {
1983
- return this.gl.canvas.height;
1984
- }
1985
- constructor() {
1986
- this.gl = CreateWebGlContext();
1987
- this.gl.enable(this.gl.DEPTH_TEST);
1496
+ constructor(canvas) {
1497
+ this._screenCanvas = canvas ?? document.createElement("canvas");
1498
+ this._bufferCanvas = new OffscreenCanvas(this._screenCanvas.width, this._screenCanvas.height);
1499
+ this.screenContext = this._screenCanvas.getContext("2d");
1500
+ this.bufferContext = this._bufferCanvas.getContext("2d");
1501
+ if (!this.screenContext || !this.bufferContext) {
1502
+ throw "Failed to create CanvasRenderingContext2D";
1503
+ }
1988
1504
  }
1989
- appendTo(htmlElement) {
1990
- if (this.canvas.parentElement) {
1991
- this.canvas.parentElement.removeChild(this.canvas);
1505
+ appendTo(target, autoResize = true) {
1506
+ if (this._screenCanvas.parentNode) {
1507
+ this._screenCanvas.parentNode.removeChild(this._screenCanvas);
1992
1508
  }
1993
- if (htmlElement) {
1994
- htmlElement.appendChild(this.canvas);
1509
+ target.appendChild(this._screenCanvas);
1510
+ if (autoResize) {
1995
1511
  this.resize();
1996
1512
  }
1997
1513
  }
1998
1514
  resize(displayWidth, displayHeight) {
1999
- const { width, height } = this.canvas.parentElement?.getBoundingClientRect() ?? this.canvas.getBoundingClientRect();
1515
+ const { width, height } = this._screenCanvas.parentElement?.getBoundingClientRect() ?? this._screenCanvas.getBoundingClientRect();
2000
1516
  displayWidth = 0 | (displayWidth ?? width);
2001
1517
  displayHeight = 0 | (displayHeight ?? height);
2002
- if (this.width !== displayWidth || this.height !== displayHeight) {
2003
- this.gl.canvas.width = displayWidth;
2004
- this.gl.canvas.height = displayHeight;
2005
- this.gl.viewport(0, 0, displayWidth, displayHeight);
1518
+ if (this._screenCanvas.width !== displayWidth || this._screenCanvas.height !== displayHeight) {
1519
+ this._screenCanvas.width = displayWidth;
1520
+ this._screenCanvas.height = displayHeight;
1521
+ this._bufferCanvas.width = displayWidth;
1522
+ this._bufferCanvas.height = displayHeight;
2006
1523
  return true;
2007
1524
  }
2008
1525
  return false;
2009
1526
  }
2010
- render(_deltaTime) {
2011
- if (this.programInfo) {
2012
- }
1527
+ setPixel(x, y, color, size = 2) {
1528
+ this.bufferContext.fillStyle = color.hexStr;
1529
+ this.bufferContext.fillRect(x - size / 2, y - size / 2, size, size);
1530
+ }
1531
+ render() {
1532
+ this.screenContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
1533
+ this.screenContext.drawImage(this._bufferCanvas, 0, 0);
1534
+ this.bufferContext.clearRect(0, 0, this._screenCanvas.width, this._screenCanvas.height);
2013
1535
  }
2014
1536
  };
2015
1537
 
2016
- // src/simplex-noise.ts
2017
- var SimplexNoise = class {
2018
- grad3;
2019
- p;
2020
- perm;
2021
- constructor() {
2022
- this.grad3 = [
2023
- [1, 1, 0],
2024
- [-1, 1, 0],
2025
- [1, -1, 0],
2026
- [-1, -1, 0],
2027
- [1, 0, 1],
2028
- [-1, 0, 1],
2029
- [1, 0, -1],
2030
- [-1, 0, -1],
2031
- [0, 1, 1],
2032
- [0, -1, 1],
2033
- [0, 1, -1],
2034
- [0, -1, -1]
2035
- ];
2036
- this.p = [];
2037
- for (let i = 0; i < 256; i++) {
2038
- this.p.push(Math.floor(rng.nextf * 256));
2039
- }
2040
- this.perm = [];
2041
- for (let i = 0; i < 512; i++) {
2042
- this.perm.push(this.p[i & 255]);
1538
+ // src/rendering/three/cube-sphere-geometry.ts
1539
+ import { BoxGeometry, Vector3 } from "three";
1540
+ var CubeSphereGeometry = class extends BoxGeometry {
1541
+ constructor(size, segments) {
1542
+ size = Math.floor(size);
1543
+ segments = Math.floor(segments);
1544
+ super(size, size, size, segments, segments, segments);
1545
+ this.size = size;
1546
+ this.segments = segments;
1547
+ this._halfSize = this.size / 2;
1548
+ const attrPositions = this.attributes.position;
1549
+ const position = new Vector3();
1550
+ for (let i = 0; i < attrPositions.count; i++) {
1551
+ position.fromBufferAttribute(attrPositions, i);
1552
+ position.normalize().multiplyScalar(this._halfSize);
1553
+ attrPositions.setXYZ(i, position.x, position.y, position.z);
2043
1554
  }
1555
+ attrPositions.needsUpdate = true;
2044
1556
  }
2045
- dot(g, x, y, z) {
2046
- return g[0] * x + g[1] * y + (typeof z === "number" ? g[2] * z : 0);
2047
- }
2048
- noise2d(xin, yin) {
2049
- let n0, n1, n2;
2050
- const F2 = 0.5 * (Math.sqrt(3) - 1);
2051
- const s = (xin + yin) * F2;
2052
- let i = Math.floor(xin + s);
2053
- let j = Math.floor(yin + s);
2054
- const G2 = (3 - Math.sqrt(3)) / 6;
2055
- const t = (i + j) * G2;
2056
- const X0 = i - t;
2057
- const Y0 = j - t;
2058
- const x0 = xin - X0;
2059
- const y0 = yin - Y0;
2060
- let i1, j1;
2061
- if (x0 > y0) {
2062
- i1 = 1;
2063
- j1 = 0;
2064
- } else {
2065
- i1 = 0;
2066
- j1 = 1;
2067
- }
2068
- const x1 = x0 - i1 + G2;
2069
- const y1 = y0 - j1 + G2;
2070
- const x2 = x0 - 1 + 2 * G2;
2071
- const y2 = y0 - 1 + 2 * G2;
2072
- const ii = i & 255;
2073
- const jj = j & 255;
2074
- const gi0 = this.perm[ii + this.perm[jj]] % 12;
2075
- const gi1 = this.perm[ii + i1 + this.perm[jj + j1]] % 12;
2076
- const gi2 = this.perm[ii + 1 + this.perm[jj + 1]] % 12;
2077
- let t0 = 0.5 - x0 * x0 - y0 * y0;
2078
- if (t0 < 0) {
2079
- n0 = 0;
2080
- } else {
2081
- t0 *= t0;
2082
- n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0);
2083
- }
2084
- let t1 = 0.5 - x1 * x1 - y1 * y1;
2085
- if (t1 < 0) {
2086
- n1 = 0;
2087
- } else {
2088
- t1 *= t1;
2089
- n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1);
1557
+ size;
1558
+ segments;
1559
+ _halfSize;
1560
+ applyFractalBrownianMotion(octaves, persistence, scale, amplitude) {
1561
+ const attrPositions = this.attributes.position;
1562
+ const position = new Vector3();
1563
+ for (let i = 0; i < attrPositions.count; i++) {
1564
+ position.fromBufferAttribute(attrPositions, i);
1565
+ position.normalize().multiplyScalar(this._halfSize);
1566
+ const noiseValue = this.fBm(position.x * scale, position.y * scale, position.z * scale, octaves, persistence);
1567
+ position.addScaledVector(position.clone().normalize(), noiseValue * amplitude);
1568
+ attrPositions.setXYZ(i, position.x, position.y, position.z);
2090
1569
  }
2091
- let t2 = 0.5 - x2 * x2 - y2 * y2;
2092
- if (t2 < 0) {
2093
- n2 = 0;
2094
- } else {
2095
- t2 *= t2;
2096
- n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2);
1570
+ attrPositions.needsUpdate = true;
1571
+ }
1572
+ fBm(x, y, z, octaves, persistence) {
1573
+ let total = 0;
1574
+ let frequency = 1;
1575
+ let amplitude = 1;
1576
+ let maxValue = 0;
1577
+ for (let i = 0; i < octaves; i++) {
1578
+ total += Noise.noise3d(x * frequency, y * frequency, z * frequency) * amplitude;
1579
+ maxValue += amplitude;
1580
+ amplitude *= persistence;
1581
+ frequency *= 2;
2097
1582
  }
2098
- return 70 * (n0 + n1 + n2);
2099
- }
2100
- // 3D simplex noise
2101
- noise3d(xin, yin, zin) {
2102
- let n0, n1, n2, n3;
2103
- const F3 = 1 / 3;
2104
- const s = (xin + yin + zin) * F3;
2105
- const i = Math.floor(xin + s);
2106
- const j = Math.floor(yin + s);
2107
- const k = Math.floor(zin + s);
2108
- const G3 = 1 / 6;
2109
- const t = (i + j + k) * G3;
2110
- const X0 = i - t;
2111
- const Y0 = j - t;
2112
- const Z0 = k - t;
2113
- const x0 = xin - X0;
2114
- const y0 = yin - Y0;
2115
- const z0 = zin - Z0;
2116
- let i1, j1, k1;
2117
- let i2, j2, k2;
2118
- if (x0 >= y0) {
2119
- if (y0 >= z0) {
2120
- i1 = 1;
2121
- j1 = 0;
2122
- k1 = 0;
2123
- i2 = 1;
2124
- j2 = 1;
2125
- k2 = 0;
2126
- } else if (x0 >= z0) {
2127
- i1 = 1;
2128
- j1 = 0;
2129
- k1 = 0;
2130
- i2 = 1;
2131
- j2 = 0;
2132
- k2 = 1;
2133
- } else {
2134
- i1 = 0;
2135
- j1 = 0;
2136
- k1 = 1;
2137
- i2 = 1;
2138
- j2 = 0;
2139
- k2 = 1;
2140
- }
2141
- } else {
2142
- if (y0 < z0) {
2143
- i1 = 0;
2144
- j1 = 0;
2145
- k1 = 1;
2146
- i2 = 0;
2147
- j2 = 1;
2148
- k2 = 1;
2149
- } else if (x0 < z0) {
2150
- i1 = 0;
2151
- j1 = 1;
2152
- k1 = 0;
2153
- i2 = 0;
2154
- j2 = 1;
2155
- k2 = 1;
2156
- } else {
2157
- i1 = 0;
2158
- j1 = 1;
2159
- k1 = 0;
2160
- i2 = 1;
2161
- j2 = 1;
2162
- k2 = 0;
2163
- }
2164
- }
2165
- const x1 = x0 - i1 + G3;
2166
- const y1 = y0 - j1 + G3;
2167
- const z1 = z0 - k1 + G3;
2168
- const x2 = x0 - i2 + 2 * G3;
2169
- const y2 = y0 - j2 + 2 * G3;
2170
- const z2 = z0 - k2 + 2 * G3;
2171
- const x3 = x0 - 1 + 3 * G3;
2172
- const y3 = y0 - 1 + 3 * G3;
2173
- const z3 = z0 - 1 + 3 * G3;
2174
- const ii = i & 255;
2175
- const jj = j & 255;
2176
- const kk = k & 255;
2177
- const gi0 = this.perm[ii + this.perm[jj + this.perm[kk]]] % 12;
2178
- const gi1 = this.perm[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]] % 12;
2179
- const gi2 = this.perm[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]] % 12;
2180
- const gi3 = this.perm[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]] % 12;
2181
- let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
2182
- if (t0 < 0) {
2183
- n0 = 0;
2184
- } else {
2185
- t0 *= t0;
2186
- n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0, z0);
2187
- }
2188
- let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
2189
- if (t1 < 0) {
2190
- n1 = 0;
2191
- } else {
2192
- t1 *= t1;
2193
- n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1, z1);
2194
- }
2195
- let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
2196
- if (t2 < 0) {
2197
- n2 = 0;
2198
- } else {
2199
- t2 *= t2;
2200
- n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2, z2);
2201
- }
2202
- let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
2203
- if (t3 < 0) {
2204
- n3 = 0;
2205
- } else {
2206
- t3 *= t3;
2207
- n3 = t3 * t3 * this.dot(this.grad3[gi3], x3, y3, z3);
2208
- }
2209
- return 32 * (n0 + n1 + n2 + n3);
2210
- }
2211
- };
2212
-
2213
- // src/spatial-partition-3d.ts
2214
- var SpatialPartition3d = class {
2215
- cells;
2216
- cellSize;
2217
- entities;
2218
- constructor(cellSize, entities) {
2219
- this.cellSize = cellSize;
2220
- this.entities = entities;
2221
- const gridSize = Math.ceil(1 / cellSize);
2222
- this.cells = Array.from(
2223
- { length: gridSize },
2224
- () => Array.from(
2225
- { length: gridSize },
2226
- () => Array.from({ length: gridSize }, () => [])
2227
- )
2228
- );
2229
- for (const entity of this.entities) {
2230
- this.addEntity(entity);
2231
- }
2232
- }
2233
- getCell(x, y, z) {
2234
- const cx = Math.floor(x / this.cellSize);
2235
- const cy = Math.floor(y / this.cellSize);
2236
- const cz = Math.floor(z / this.cellSize);
2237
- return this.cells[cz][cy][cx];
2238
- }
2239
- getCellNeighbors(cx, cy, cz) {
2240
- const neighbors = [];
2241
- const gridSize = this.cells.length;
2242
- for (let dz = -1; dz <= 1; dz++) {
2243
- for (let dy = -1; dy <= 1; dy++) {
2244
- for (let dx = -1; dx <= 1; dx++) {
2245
- let nx = (cx + dx + gridSize) % gridSize;
2246
- let ny = (cy + dy + gridSize) % gridSize;
2247
- let nz = (cz + dz + gridSize) % gridSize;
2248
- neighbors.push(this.cells[nz][ny][nx]);
2249
- }
2250
- }
2251
- }
2252
- return neighbors;
2253
- }
2254
- addEntity(entity) {
2255
- const cell = this.getCell(entity.x, entity.y, entity.z);
2256
- cell.push(entity);
2257
- }
2258
- };
2259
-
2260
- // src/tilemap.ts
2261
- var Tilemap = class {
2262
- map = /* @__PURE__ */ new Map();
2263
- _key(x, y) {
2264
- x = floor(x);
2265
- y = floor(y);
2266
- return `${x}x${y}`;
2267
- }
2268
- get(x, y) {
2269
- return this.map.get(this._key(x, y));
2270
- }
2271
- set(x, y, v) {
2272
- this.map.set(this._key(x, y), v);
2273
- }
2274
- };
2275
-
2276
- // src/three/cube-sphere-geometry.ts
2277
- import { BoxGeometry, Vector3 } from "three";
2278
- var CubeSphereGeometry = class extends BoxGeometry {
2279
- constructor(size, segments) {
2280
- size = Math.floor(size);
2281
- segments = Math.floor(segments);
2282
- super(size, size, size, segments, segments, segments);
2283
- this.size = size;
2284
- this.segments = segments;
2285
- this._halfSize = this.size / 2;
2286
- const attrPositions = this.attributes.position;
2287
- const position = new Vector3();
2288
- for (let i = 0; i < attrPositions.count; i++) {
2289
- position.fromBufferAttribute(attrPositions, i);
2290
- position.normalize().multiplyScalar(this._halfSize);
2291
- attrPositions.setXYZ(i, position.x, position.y, position.z);
2292
- }
2293
- attrPositions.needsUpdate = true;
2294
- }
2295
- size;
2296
- segments;
2297
- _halfSize;
2298
- applyFractalBrownianMotion(octaves, persistence, scale, amplitude) {
2299
- const attrPositions = this.attributes.position;
2300
- const position = new Vector3();
2301
- for (let i = 0; i < attrPositions.count; i++) {
2302
- position.fromBufferAttribute(attrPositions, i);
2303
- position.normalize().multiplyScalar(this._halfSize);
2304
- const noiseValue = this.fBm(position.x * scale, position.y * scale, position.z * scale, octaves, persistence);
2305
- position.addScaledVector(position.clone().normalize(), noiseValue * amplitude);
2306
- attrPositions.setXYZ(i, position.x, position.y, position.z);
2307
- }
2308
- attrPositions.needsUpdate = true;
2309
- }
2310
- fBm(x, y, z, octaves, persistence) {
2311
- let total = 0;
2312
- let frequency = 1;
2313
- let amplitude = 1;
2314
- let maxValue = 0;
2315
- for (let i = 0; i < octaves; i++) {
2316
- total += Noise.noise3d(x * frequency, y * frequency, z * frequency) * amplitude;
2317
- maxValue += amplitude;
2318
- amplitude *= persistence;
2319
- frequency *= 2;
2320
- }
2321
- return total / maxValue;
1583
+ return total / maxValue;
2322
1584
  }
2323
1585
  };
2324
1586
 
2325
- // src/three/texture-atlas.ts
1587
+ // src/rendering/three/texture-atlas.ts
2326
1588
  import { TextureLoader, MeshLambertMaterial, NearestFilter, RepeatWrapping } from "three";
2327
1589
  function LoadTexture(url) {
2328
1590
  return new Promise((res, rej) => {
@@ -2447,10 +1709,10 @@ var AtlasTextureMaterial = class _AtlasTextureMaterial extends MeshLambertMateri
2447
1709
  }
2448
1710
  };
2449
1711
 
2450
- // src/three/threejs-boiler-plate.ts
1712
+ // src/rendering/three/threejs-boiler-plate.ts
2451
1713
  import { AmbientLight, BoxGeometry as BoxGeometry2, DirectionalLight, GridHelper, Mesh, MeshLambertMaterial as MeshLambertMaterial2, PlaneGeometry, Raycaster, Scene, Vector2, WebGLRenderer } from "three";
2452
1714
 
2453
- // src/three/threejs-camera-rig.ts
1715
+ // src/rendering/three/threejs-camera-rig.ts
2454
1716
  import { PerspectiveCamera, Group } from "three";
2455
1717
  var ThreeJsCameraRig = class extends Group {
2456
1718
  gimbal;
@@ -2492,7 +1754,7 @@ var ThreeJsCameraRig = class extends Group {
2492
1754
  }
2493
1755
  };
2494
1756
 
2495
- // src/three/threejs-boiler-plate.ts
1757
+ // src/rendering/three/threejs-boiler-plate.ts
2496
1758
  var ThreeJsBoilerPlate = class {
2497
1759
  clock = new Clock();
2498
1760
  scene = new Scene();
@@ -2517,24 +1779,15 @@ var ThreeJsBoilerPlate = class {
2517
1779
  this.appendTo(params.parentElement);
2518
1780
  }
2519
1781
  }
2520
- // Mutually exclusive with enableOrbitControls() - pick one. Gives you
2521
- // manual orbit()/dolly() with tilt clamping and target-following, driven
2522
- // by this.input's mouse events.
2523
1782
  enableCameraRigControls() {
2524
1783
  this.orbitControls?.dispose();
2525
1784
  this.orbitControls = void 0;
2526
1785
  this.input.on("mouse_move", ({ deltaX, deltaY }) => {
2527
- if (this.input.isMouseButtonDown(0)) {
1786
+ if (this.input.isDown("Button0")) {
2528
1787
  this.cameraRig.orbit(deltaX, deltaY);
2529
1788
  }
2530
1789
  }).on("mouse_wheel", ({ deltaY }) => this.cameraRig.dolly(deltaY));
2531
1790
  }
2532
- // Mutually exclusive with enableCameraRigControls() - pick one. Uses
2533
- // Three's own OrbitControls instead of the hand-rolled rig math; call
2534
- // update() once per frame in your render loop while this is active.
2535
- // Async because OrbitControls only ships as an ESM-only addon module -
2536
- // a dynamic import avoids forcing this whole package (built as both
2537
- // CJS and ESM) to statically import an ESM-only file.
2538
1791
  async enableOrbitControls() {
2539
1792
  const { OrbitControls } = await import("three/examples/jsm/Addons.js");
2540
1793
  this.orbitControls = new OrbitControls(this.camera, this.canvas);
@@ -2542,7 +1795,6 @@ var ThreeJsBoilerPlate = class {
2542
1795
  this.orbitControls.maxDistance = 100;
2543
1796
  this.orbitControls.update();
2544
1797
  }
2545
- // Call once per frame if enableOrbitControls() is active - no-op otherwise.
2546
1798
  update() {
2547
1799
  this.orbitControls?.update();
2548
1800
  }
@@ -2578,8 +1830,8 @@ var ThreeJsBoilerPlate = class {
2578
1830
  }
2579
1831
  }
2580
1832
  pick() {
2581
- const pickX = this.input.mousePosition[0] / this.renderer.domElement.width * 2 - 1;
2582
- const pickY = -(this.input.mousePosition[1] / this.renderer.domElement.height) * 2 + 1;
1833
+ const pickX = this.input.pointerPosition.x / this.renderer.domElement.width * 2 - 1;
1834
+ const pickY = -(this.input.pointerPosition.y / this.renderer.domElement.height) * 2 + 1;
2583
1835
  this.raycaster.setFromCamera(new Vector2(pickX, pickY), this.cameraRig.camera);
2584
1836
  const intersected = this.raycaster.intersectObjects(this.scene.children);
2585
1837
  return intersected.length ? intersected[0] : null;
@@ -2600,7 +1852,7 @@ var ThreeJsBoilerPlate = class {
2600
1852
  }
2601
1853
  };
2602
1854
 
2603
- // src/three/threejs-player-controller.ts
1855
+ // src/rendering/three/threejs-player-controller.ts
2604
1856
  import { Group as Group2, Vector3 as Vector32 } from "three";
2605
1857
  var ThreeJsPlayerController = class extends Group2 {
2606
1858
  moveSpeed = 1;
@@ -2619,7 +1871,7 @@ var ThreeJsPlayerController = class extends Group2 {
2619
1871
  }
2620
1872
  };
2621
1873
 
2622
- // src/three/voxel-mesh.ts
1874
+ // src/rendering/three/voxel-mesh.ts
2623
1875
  import { BufferAttribute, BufferGeometry, Color as Color2, Mesh as Mesh2 } from "three";
2624
1876
  var VoxelMesh = class extends Mesh2 {
2625
1877
  type = "VoxelMesh";
@@ -2969,8 +2221,57 @@ var Colors = {
2969
2221
  ]
2970
2222
  };
2971
2223
 
2972
- // src/three/particle-system-3d.ts
2224
+ // src/rendering/three/particle-system-3d.ts
2973
2225
  import { BufferGeometry as BufferGeometry2, Float32BufferAttribute, Group as Group3, Points, ShaderMaterial, Vector3 as Vector33 } from "three";
2226
+
2227
+ // src/spatial-partition-3d.ts
2228
+ var SpatialPartition3d = class {
2229
+ cells;
2230
+ cellSize;
2231
+ entities;
2232
+ constructor(cellSize, entities) {
2233
+ this.cellSize = cellSize;
2234
+ this.entities = entities;
2235
+ const gridSize = Math.ceil(1 / cellSize);
2236
+ this.cells = Array.from(
2237
+ { length: gridSize },
2238
+ () => Array.from(
2239
+ { length: gridSize },
2240
+ () => Array.from({ length: gridSize }, () => [])
2241
+ )
2242
+ );
2243
+ for (const entity of this.entities) {
2244
+ this.addEntity(entity);
2245
+ }
2246
+ }
2247
+ getCell(x, y, z) {
2248
+ const cx = Math.floor(x / this.cellSize);
2249
+ const cy = Math.floor(y / this.cellSize);
2250
+ const cz = Math.floor(z / this.cellSize);
2251
+ return this.cells[cz][cy][cx];
2252
+ }
2253
+ getCellNeighbors(cx, cy, cz) {
2254
+ const neighbors = [];
2255
+ const gridSize = this.cells.length;
2256
+ for (let dz = -1; dz <= 1; dz++) {
2257
+ for (let dy = -1; dy <= 1; dy++) {
2258
+ for (let dx = -1; dx <= 1; dx++) {
2259
+ let nx = (cx + dx + gridSize) % gridSize;
2260
+ let ny = (cy + dy + gridSize) % gridSize;
2261
+ let nz = (cz + dz + gridSize) % gridSize;
2262
+ neighbors.push(this.cells[nz][ny][nx]);
2263
+ }
2264
+ }
2265
+ }
2266
+ return neighbors;
2267
+ }
2268
+ addEntity(entity) {
2269
+ const cell = this.getCell(entity.x, entity.y, entity.z);
2270
+ cell.push(entity);
2271
+ }
2272
+ };
2273
+
2274
+ // src/rendering/three/particle-system-3d.ts
2974
2275
  var vertexShader = `
2975
2276
  uniform float pointSize;
2976
2277
 
@@ -3159,7 +2460,7 @@ var ParticleSystem3d = class extends Group3 {
3159
2460
  }
3160
2461
  };
3161
2462
 
3162
- // src/three/asteroid-mesh.ts
2463
+ // src/rendering/three/asteroid-mesh.ts
3163
2464
  import { IcosahedronGeometry, Mesh as Mesh3, MeshStandardMaterial as MeshStandardMaterial2 } from "three";
3164
2465
  import { createNoise3D as createNoise3D2 } from "simplex-noise";
3165
2466
  var AsteroidMesh = class extends Mesh3 {
@@ -3194,7 +2495,7 @@ var AsteroidMesh = class extends Mesh3 {
3194
2495
  }
3195
2496
  };
3196
2497
 
3197
- // src/three/starfield.ts
2498
+ // src/rendering/three/starfield.ts
3198
2499
  import { BufferAttribute as BufferAttribute2, BufferGeometry as BufferGeometry3, Group as Group4, Mesh as Mesh4, MeshBasicMaterial as MeshBasicMaterial2, PointLight, Points as Points2, PointsMaterial, SphereGeometry, Vector3 as Vector34 } from "three";
3199
2500
  function CreateStarfield(radius = 1e3, count = 5e3, color = 16777215) {
3200
2501
  const geometry = new BufferGeometry3();
@@ -3233,7 +2534,7 @@ function CreateSystemStar(position) {
3233
2534
  return star;
3234
2535
  }
3235
2536
 
3236
- // src/three/palette-controller.ts
2537
+ // src/rendering/three/palette-controller.ts
3237
2538
  import { Color as Color3, Vector3 as Vector35 } from "three";
3238
2539
  async function CreatePaletteController(parentGui, colorPalette, onChange, folderName = "palette") {
3239
2540
  const { Controller } = await import("three/examples/jsm/libs/lil-gui.module.min.js");
@@ -3338,7 +2639,7 @@ async function CreatePaletteController(parentGui, colorPalette, onChange, folder
3338
2639
  return new PaletteControllerImpl();
3339
2640
  }
3340
2641
 
3341
- // src/three/ecs.ts
2642
+ // src/rendering/three/ecs.ts
3342
2643
  import { Group as Group5 } from "three";
3343
2644
  var entityCounter = 0;
3344
2645
  function GenerateEntityId() {
@@ -3363,6 +2664,334 @@ function IsThreeEntity(obj) {
3363
2664
  return obj.userData.entityId !== void 0;
3364
2665
  }
3365
2666
 
2667
+ // src/rendering/webgl.ts
2668
+ var ShaderType = ((ShaderType2) => {
2669
+ ShaderType2[ShaderType2["VERTEX"] = WebGL2RenderingContext.VERTEX_SHADER] = "VERTEX";
2670
+ ShaderType2[ShaderType2["FRAGMENT"] = WebGL2RenderingContext.FRAGMENT_SHADER] = "FRAGMENT";
2671
+ return ShaderType2;
2672
+ })(ShaderType || {});
2673
+ function CreateWebGlContext(canvas) {
2674
+ return (canvas ?? document.createElement("canvas")).getContext("webgl2");
2675
+ }
2676
+ function ResizeWebGlContext(gl, displayWidth, displayHeight) {
2677
+ const canvas = gl.canvas;
2678
+ const { width, height } = canvas.parentElement?.getBoundingClientRect() ?? canvas.getBoundingClientRect();
2679
+ displayWidth = 0 | (displayWidth ?? width);
2680
+ displayHeight = 0 | (displayHeight ?? height);
2681
+ if (canvas.width !== displayWidth || canvas.height !== displayHeight) {
2682
+ gl.canvas.width = displayWidth;
2683
+ gl.canvas.height = displayHeight;
2684
+ gl.viewport(0, 0, displayWidth, displayHeight);
2685
+ return true;
2686
+ }
2687
+ return false;
2688
+ }
2689
+ function CompileShader(gl, type, source) {
2690
+ const shader = gl.createShader(type);
2691
+ gl.shaderSource(shader, source);
2692
+ gl.compileShader(shader);
2693
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
2694
+ throw `CompileShader: failed to compile shader: ${gl.getShaderInfoLog(shader)}`;
2695
+ }
2696
+ return shader;
2697
+ }
2698
+ function CreateProgram(gl, vertexShader2, fragmentShader2) {
2699
+ if (typeof vertexShader2 === "string") {
2700
+ vertexShader2 = CompileShader(gl, ShaderType.VERTEX, vertexShader2);
2701
+ }
2702
+ if (typeof fragmentShader2 === "string") {
2703
+ fragmentShader2 = CompileShader(gl, ShaderType.FRAGMENT, fragmentShader2);
2704
+ }
2705
+ const program = gl.createProgram();
2706
+ gl.attachShader(program, vertexShader2);
2707
+ gl.attachShader(program, fragmentShader2);
2708
+ gl.linkProgram(program);
2709
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
2710
+ throw `CreateProgram: failed to link program: ${gl.getProgramInfoLog(program)}`;
2711
+ }
2712
+ return program;
2713
+ }
2714
+ function GetProgramLocations(gl, program) {
2715
+ const attributes = {};
2716
+ const attributeCount = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
2717
+ for (let i = 0; i < attributeCount; i++) {
2718
+ const info = gl.getActiveAttrib(program, i);
2719
+ attributes[info.name] = gl.getAttribLocation(program, info.name);
2720
+ }
2721
+ const uniforms = {};
2722
+ const uniformCount = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
2723
+ for (let i = 0; i < uniformCount; i++) {
2724
+ const info = gl.getActiveUniform(program, i);
2725
+ uniforms[info.name] = gl.getUniformLocation(program, info.name);
2726
+ }
2727
+ return { attributes, uniforms };
2728
+ }
2729
+ function CreateProgramInfo(gl, vertexShaderSource, fragmentShaderSource) {
2730
+ const program = CreateProgram(
2731
+ gl,
2732
+ vertexShaderSource,
2733
+ fragmentShaderSource
2734
+ );
2735
+ const locations = GetProgramLocations(gl, program);
2736
+ return { program, ...locations };
2737
+ }
2738
+
2739
+ // src/rendering/webgl-renderer.ts
2740
+ var WebGlRenderer = class {
2741
+ gl;
2742
+ programInfo;
2743
+ get canvas() {
2744
+ return this.gl.canvas;
2745
+ }
2746
+ get width() {
2747
+ return this.gl.canvas.width;
2748
+ }
2749
+ get height() {
2750
+ return this.gl.canvas.height;
2751
+ }
2752
+ constructor() {
2753
+ this.gl = CreateWebGlContext();
2754
+ this.gl.enable(this.gl.DEPTH_TEST);
2755
+ }
2756
+ appendTo(htmlElement) {
2757
+ if (this.canvas.parentElement) {
2758
+ this.canvas.parentElement.removeChild(this.canvas);
2759
+ }
2760
+ if (htmlElement) {
2761
+ htmlElement.appendChild(this.canvas);
2762
+ this.resize();
2763
+ }
2764
+ }
2765
+ resize(displayWidth, displayHeight) {
2766
+ const { width, height } = this.canvas.parentElement?.getBoundingClientRect() ?? this.canvas.getBoundingClientRect();
2767
+ displayWidth = 0 | (displayWidth ?? width);
2768
+ displayHeight = 0 | (displayHeight ?? height);
2769
+ if (this.width !== displayWidth || this.height !== displayHeight) {
2770
+ this.gl.canvas.width = displayWidth;
2771
+ this.gl.canvas.height = displayHeight;
2772
+ this.gl.viewport(0, 0, displayWidth, displayHeight);
2773
+ return true;
2774
+ }
2775
+ return false;
2776
+ }
2777
+ render(_deltaTime) {
2778
+ if (this.programInfo) {
2779
+ }
2780
+ }
2781
+ };
2782
+
2783
+ // src/simplex-noise.ts
2784
+ var SimplexNoise = class {
2785
+ grad3;
2786
+ p;
2787
+ perm;
2788
+ constructor() {
2789
+ this.grad3 = [
2790
+ [1, 1, 0],
2791
+ [-1, 1, 0],
2792
+ [1, -1, 0],
2793
+ [-1, -1, 0],
2794
+ [1, 0, 1],
2795
+ [-1, 0, 1],
2796
+ [1, 0, -1],
2797
+ [-1, 0, -1],
2798
+ [0, 1, 1],
2799
+ [0, -1, 1],
2800
+ [0, 1, -1],
2801
+ [0, -1, -1]
2802
+ ];
2803
+ this.p = [];
2804
+ for (let i = 0; i < 256; i++) {
2805
+ this.p.push(Math.floor(rng.nextf * 256));
2806
+ }
2807
+ this.perm = [];
2808
+ for (let i = 0; i < 512; i++) {
2809
+ this.perm.push(this.p[i & 255]);
2810
+ }
2811
+ }
2812
+ dot(g, x, y, z) {
2813
+ return g[0] * x + g[1] * y + (typeof z === "number" ? g[2] * z : 0);
2814
+ }
2815
+ noise2d(xin, yin) {
2816
+ let n0, n1, n2;
2817
+ const F2 = 0.5 * (Math.sqrt(3) - 1);
2818
+ const s = (xin + yin) * F2;
2819
+ let i = Math.floor(xin + s);
2820
+ let j = Math.floor(yin + s);
2821
+ const G2 = (3 - Math.sqrt(3)) / 6;
2822
+ const t = (i + j) * G2;
2823
+ const X0 = i - t;
2824
+ const Y0 = j - t;
2825
+ const x0 = xin - X0;
2826
+ const y0 = yin - Y0;
2827
+ let i1, j1;
2828
+ if (x0 > y0) {
2829
+ i1 = 1;
2830
+ j1 = 0;
2831
+ } else {
2832
+ i1 = 0;
2833
+ j1 = 1;
2834
+ }
2835
+ const x1 = x0 - i1 + G2;
2836
+ const y1 = y0 - j1 + G2;
2837
+ const x2 = x0 - 1 + 2 * G2;
2838
+ const y2 = y0 - 1 + 2 * G2;
2839
+ const ii = i & 255;
2840
+ const jj = j & 255;
2841
+ const gi0 = this.perm[ii + this.perm[jj]] % 12;
2842
+ const gi1 = this.perm[ii + i1 + this.perm[jj + j1]] % 12;
2843
+ const gi2 = this.perm[ii + 1 + this.perm[jj + 1]] % 12;
2844
+ let t0 = 0.5 - x0 * x0 - y0 * y0;
2845
+ if (t0 < 0) {
2846
+ n0 = 0;
2847
+ } else {
2848
+ t0 *= t0;
2849
+ n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0);
2850
+ }
2851
+ let t1 = 0.5 - x1 * x1 - y1 * y1;
2852
+ if (t1 < 0) {
2853
+ n1 = 0;
2854
+ } else {
2855
+ t1 *= t1;
2856
+ n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1);
2857
+ }
2858
+ let t2 = 0.5 - x2 * x2 - y2 * y2;
2859
+ if (t2 < 0) {
2860
+ n2 = 0;
2861
+ } else {
2862
+ t2 *= t2;
2863
+ n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2);
2864
+ }
2865
+ return 70 * (n0 + n1 + n2);
2866
+ }
2867
+ noise3d(xin, yin, zin) {
2868
+ let n0, n1, n2, n3;
2869
+ const F3 = 1 / 3;
2870
+ const s = (xin + yin + zin) * F3;
2871
+ const i = Math.floor(xin + s);
2872
+ const j = Math.floor(yin + s);
2873
+ const k = Math.floor(zin + s);
2874
+ const G3 = 1 / 6;
2875
+ const t = (i + j + k) * G3;
2876
+ const X0 = i - t;
2877
+ const Y0 = j - t;
2878
+ const Z0 = k - t;
2879
+ const x0 = xin - X0;
2880
+ const y0 = yin - Y0;
2881
+ const z0 = zin - Z0;
2882
+ let i1, j1, k1;
2883
+ let i2, j2, k2;
2884
+ if (x0 >= y0) {
2885
+ if (y0 >= z0) {
2886
+ i1 = 1;
2887
+ j1 = 0;
2888
+ k1 = 0;
2889
+ i2 = 1;
2890
+ j2 = 1;
2891
+ k2 = 0;
2892
+ } else if (x0 >= z0) {
2893
+ i1 = 1;
2894
+ j1 = 0;
2895
+ k1 = 0;
2896
+ i2 = 1;
2897
+ j2 = 0;
2898
+ k2 = 1;
2899
+ } else {
2900
+ i1 = 0;
2901
+ j1 = 0;
2902
+ k1 = 1;
2903
+ i2 = 1;
2904
+ j2 = 0;
2905
+ k2 = 1;
2906
+ }
2907
+ } else {
2908
+ if (y0 < z0) {
2909
+ i1 = 0;
2910
+ j1 = 0;
2911
+ k1 = 1;
2912
+ i2 = 0;
2913
+ j2 = 1;
2914
+ k2 = 1;
2915
+ } else if (x0 < z0) {
2916
+ i1 = 0;
2917
+ j1 = 1;
2918
+ k1 = 0;
2919
+ i2 = 0;
2920
+ j2 = 1;
2921
+ k2 = 1;
2922
+ } else {
2923
+ i1 = 0;
2924
+ j1 = 1;
2925
+ k1 = 0;
2926
+ i2 = 1;
2927
+ j2 = 1;
2928
+ k2 = 0;
2929
+ }
2930
+ }
2931
+ const x1 = x0 - i1 + G3;
2932
+ const y1 = y0 - j1 + G3;
2933
+ const z1 = z0 - k1 + G3;
2934
+ const x2 = x0 - i2 + 2 * G3;
2935
+ const y2 = y0 - j2 + 2 * G3;
2936
+ const z2 = z0 - k2 + 2 * G3;
2937
+ const x3 = x0 - 1 + 3 * G3;
2938
+ const y3 = y0 - 1 + 3 * G3;
2939
+ const z3 = z0 - 1 + 3 * G3;
2940
+ const ii = i & 255;
2941
+ const jj = j & 255;
2942
+ const kk = k & 255;
2943
+ const gi0 = this.perm[ii + this.perm[jj + this.perm[kk]]] % 12;
2944
+ const gi1 = this.perm[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]] % 12;
2945
+ const gi2 = this.perm[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]] % 12;
2946
+ const gi3 = this.perm[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]] % 12;
2947
+ let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
2948
+ if (t0 < 0) {
2949
+ n0 = 0;
2950
+ } else {
2951
+ t0 *= t0;
2952
+ n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0, z0);
2953
+ }
2954
+ let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
2955
+ if (t1 < 0) {
2956
+ n1 = 0;
2957
+ } else {
2958
+ t1 *= t1;
2959
+ n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1, z1);
2960
+ }
2961
+ let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
2962
+ if (t2 < 0) {
2963
+ n2 = 0;
2964
+ } else {
2965
+ t2 *= t2;
2966
+ n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2, z2);
2967
+ }
2968
+ let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
2969
+ if (t3 < 0) {
2970
+ n3 = 0;
2971
+ } else {
2972
+ t3 *= t3;
2973
+ n3 = t3 * t3 * this.dot(this.grad3[gi3], x3, y3, z3);
2974
+ }
2975
+ return 32 * (n0 + n1 + n2 + n3);
2976
+ }
2977
+ };
2978
+
2979
+ // src/tilemap.ts
2980
+ var Tilemap = class {
2981
+ map = /* @__PURE__ */ new Map();
2982
+ _key(x, y) {
2983
+ x = floor(x);
2984
+ y = floor(y);
2985
+ return `${x}x${y}`;
2986
+ }
2987
+ get(x, y) {
2988
+ return this.map.get(this._key(x, y));
2989
+ }
2990
+ set(x, y, v) {
2991
+ this.map.set(this._key(x, y), v);
2992
+ }
2993
+ };
2994
+
3366
2995
  // src/worker-interface.ts
3367
2996
  var WorkerInterface = class extends Emitter {
3368
2997
  _worker;
@@ -3387,7 +3016,6 @@ export {
3387
3016
  BuildDefaultPalette,
3388
3017
  CanvasRenderer,
3389
3018
  Clock,
3390
- ClockStats,
3391
3019
  Color,
3392
3020
  Colors,
3393
3021
  CompileShader,
@@ -3400,16 +3028,17 @@ export {
3400
3028
  CreateThreeEntity,
3401
3029
  CreateWebGlContext,
3402
3030
  CubeSphereGeometry,
3031
+ DOUBLE_PI,
3403
3032
  ECS,
3404
3033
  Emitter,
3405
- EventBus,
3406
3034
  GenerateDoors,
3407
3035
  GenerateEntityId,
3408
3036
  GenerateRooms,
3409
3037
  GenerateWalls,
3410
3038
  GetProgramLocations,
3411
3039
  GetThreeComponent,
3412
- GlobalEmitter,
3040
+ GetUrlParams,
3041
+ HALF_PI,
3413
3042
  Input,
3414
3043
  IsThreeEntity,
3415
3044
  LoadTexture,
@@ -3417,14 +3046,15 @@ export {
3417
3046
  Map3D,
3418
3047
  Noise,
3419
3048
  PI,
3049
+ ParticleRenderer,
3420
3050
  ParticleSystem2d,
3421
3051
  ParticleSystem3d,
3422
3052
  PoissonDiskSampler,
3053
+ RADIAN_FACTOR,
3054
+ RandomNumberGenerator,
3423
3055
  Rectangle,
3424
3056
  RemoveThreeComponent,
3425
- Renderer,
3426
3057
  ResizeWebGlContext,
3427
- Rng,
3428
3058
  ShaderType,
3429
3059
  SimplexNoise,
3430
3060
  SpatialPartition2d,
@@ -3447,20 +3077,19 @@ export {
3447
3077
  clamp,
3448
3078
  cos,
3449
3079
  deg2rad,
3450
- distance,
3451
- eventBus,
3080
+ distance2d,
3081
+ distance3d,
3452
3082
  floor,
3453
3083
  getRedYellowGreenGradientHex,
3454
3084
  hypot2,
3455
3085
  hypot3,
3456
3086
  imul,
3457
3087
  isNullOrUndefined,
3088
+ isPositiveString,
3089
+ k2xy,
3090
+ k2xyz,
3458
3091
  lerp,
3459
3092
  log,
3460
- logdev,
3461
- logerr,
3462
- loginf,
3463
- logwrn,
3464
3093
  manhattanDistance,
3465
3094
  max,
3466
3095
  min,
@@ -3470,5 +3099,7 @@ export {
3470
3099
  roundTo,
3471
3100
  sin,
3472
3101
  sqrt,
3473
- squaredDistance
3102
+ squaredDistance,
3103
+ xy2k,
3104
+ xyz2k
3474
3105
  };