@n3rdw1z4rd/core 0.16.3 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/css/index.ts +0 -1
- package/dist/index.d.mts +228 -99
- package/dist/index.d.ts +228 -99
- package/dist/index.js +897 -469
- package/dist/index.mjs +1013 -460
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,286 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
10
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
11
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
12
|
+
};
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __reExport = (target, mod2, secondTarget) => (__copyProps(target, mod2, "default"), secondTarget && __copyProps(secondTarget, mod2, "default"));
|
|
26
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
32
|
+
mod2
|
|
33
|
+
));
|
|
34
|
+
|
|
35
|
+
// src/css/main.css
|
|
36
|
+
var init_main = __esm({
|
|
37
|
+
"src/css/main.css"() {
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// src/css/index.ts
|
|
42
|
+
var require_css = __commonJS({
|
|
43
|
+
"src/css/index.ts"() {
|
|
44
|
+
"use strict";
|
|
45
|
+
init_main();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// src/index.ts
|
|
50
|
+
var index_exports = {};
|
|
51
|
+
__export(index_exports, {
|
|
52
|
+
AStar: () => AStar,
|
|
53
|
+
AddThreeComponent: () => AddThreeComponent,
|
|
54
|
+
AsteroidMesh: () => AsteroidMesh,
|
|
55
|
+
AtlasTextureMaterial: () => AtlasTextureMaterial,
|
|
56
|
+
BuildDefaultPalette: () => BuildDefaultPalette,
|
|
57
|
+
CanvasRenderer: () => CanvasRenderer,
|
|
58
|
+
Clock: () => Clock,
|
|
59
|
+
Color: () => Color,
|
|
60
|
+
Colors: () => Colors,
|
|
61
|
+
CompileShader: () => CompileShader,
|
|
62
|
+
CreatePaletteController: () => CreatePaletteController,
|
|
63
|
+
CreateProgram: () => CreateProgram,
|
|
64
|
+
CreateProgramInfo: () => CreateProgramInfo,
|
|
65
|
+
CreateStarfield: () => CreateStarfield,
|
|
66
|
+
CreateSubTexture: () => CreateSubTexture,
|
|
67
|
+
CreateSystemStar: () => CreateSystemStar,
|
|
68
|
+
CreateThreeEntity: () => CreateThreeEntity,
|
|
69
|
+
CreateWebGlContext: () => CreateWebGlContext,
|
|
70
|
+
CubeSphereGeometry: () => CubeSphereGeometry,
|
|
71
|
+
DEFAULT_COLOR: () => DEFAULT_COLOR,
|
|
72
|
+
DEFAULT_FONT: () => DEFAULT_FONT,
|
|
73
|
+
DEFAULT_PIXEL_SIZE: () => DEFAULT_PIXEL_SIZE,
|
|
74
|
+
DEFAULT_TEXTALIGN: () => DEFAULT_TEXTALIGN,
|
|
75
|
+
DEFAULT_TEXTBASELINE: () => DEFAULT_TEXTBASELINE,
|
|
76
|
+
DEG2RAD: () => DEG2RAD,
|
|
77
|
+
DOWN: () => DOWN,
|
|
78
|
+
Disposable: () => Disposable,
|
|
79
|
+
E: () => E,
|
|
80
|
+
ECS: () => ECS,
|
|
81
|
+
EPSILON: () => EPSILON,
|
|
82
|
+
EventQueue: () => EventQueue,
|
|
83
|
+
GenerateDoors: () => GenerateDoors,
|
|
84
|
+
GenerateEntityId: () => GenerateEntityId,
|
|
85
|
+
GenerateRooms: () => GenerateRooms,
|
|
86
|
+
GenerateWalls: () => GenerateWalls,
|
|
87
|
+
GetProgramLocations: () => GetProgramLocations,
|
|
88
|
+
GetThreeComponent: () => GetThreeComponent,
|
|
89
|
+
GetUrlParams: () => GetUrlParams,
|
|
90
|
+
HALF_PI: () => HALF_PI,
|
|
91
|
+
Input: () => Input,
|
|
92
|
+
IsThreeEntity: () => IsThreeEntity,
|
|
93
|
+
LN10: () => LN10,
|
|
94
|
+
LN2: () => LN2,
|
|
95
|
+
LOG10E: () => LOG10E,
|
|
96
|
+
LOG2E: () => LOG2E,
|
|
97
|
+
LoadTexture: () => LoadTexture,
|
|
98
|
+
Map2D: () => Map2D,
|
|
99
|
+
Map3D: () => Map3D,
|
|
100
|
+
Noise: () => Noise,
|
|
101
|
+
Observable: () => Observable,
|
|
102
|
+
PI: () => PI,
|
|
103
|
+
ParticleRenderer: () => ParticleRenderer,
|
|
104
|
+
ParticleSystem2d: () => ParticleSystem2d,
|
|
105
|
+
ParticleSystem3d: () => ParticleSystem3d,
|
|
106
|
+
PoissonDiskSampler: () => PoissonDiskSampler,
|
|
107
|
+
QUARTER_PI: () => QUARTER_PI,
|
|
108
|
+
RAD2DEG: () => RAD2DEG,
|
|
109
|
+
Random: () => Random,
|
|
110
|
+
RandomTools: () => RandomTools,
|
|
111
|
+
Rectangle: () => Rectangle,
|
|
112
|
+
RemoveThreeComponent: () => RemoveThreeComponent,
|
|
113
|
+
ResizeWebGlContext: () => ResizeWebGlContext,
|
|
114
|
+
SQRT1_2: () => SQRT1_2,
|
|
115
|
+
SQRT2: () => SQRT2,
|
|
116
|
+
ShaderType: () => ShaderType,
|
|
117
|
+
Signal: () => Signal,
|
|
118
|
+
SimplexNoise: () => SimplexNoise,
|
|
119
|
+
SpatialPartition2d: () => SpatialPartition2d,
|
|
120
|
+
SpatialPartition3d: () => SpatialPartition3d,
|
|
121
|
+
TAU: () => TAU,
|
|
122
|
+
TILE_EMPTY: () => TILE_EMPTY,
|
|
123
|
+
TILE_FLOOR: () => TILE_FLOOR,
|
|
124
|
+
TILE_PATH: () => TILE_PATH,
|
|
125
|
+
TextureAtlas: () => TextureAtlas,
|
|
126
|
+
ThreeJsBoilerPlate: () => ThreeJsBoilerPlate,
|
|
127
|
+
ThreeJsCameraRig: () => ThreeJsCameraRig,
|
|
128
|
+
ThreeJsPlayerController: () => ThreeJsPlayerController,
|
|
129
|
+
Tilemap: () => Tilemap,
|
|
130
|
+
UP: () => UP,
|
|
131
|
+
Vector: () => Vector,
|
|
132
|
+
VoxelFaces: () => VoxelFaces,
|
|
133
|
+
VoxelMesh: () => VoxelMesh,
|
|
134
|
+
WebGlRenderer: () => WebGlRenderer,
|
|
135
|
+
WorkerInterface: () => WorkerInterface,
|
|
136
|
+
abs: () => abs,
|
|
137
|
+
acos: () => acos,
|
|
138
|
+
asin: () => asin,
|
|
139
|
+
atan: () => atan,
|
|
140
|
+
atan2: () => atan2,
|
|
141
|
+
cbrt: () => cbrt,
|
|
142
|
+
ceil: () => ceil,
|
|
143
|
+
clamp: () => clamp,
|
|
144
|
+
cos: () => cos,
|
|
145
|
+
cosh: () => cosh,
|
|
146
|
+
degrees: () => degrees,
|
|
147
|
+
distance2d: () => distance2d,
|
|
148
|
+
distance3d: () => distance3d,
|
|
149
|
+
exp: () => exp,
|
|
150
|
+
expm1: () => expm1,
|
|
151
|
+
floor: () => floor,
|
|
152
|
+
fract: () => fract,
|
|
153
|
+
getRedYellowGreenGradientHex: () => getRedYellowGreenGradientHex,
|
|
154
|
+
hypot: () => hypot,
|
|
155
|
+
hypot2: () => hypot2,
|
|
156
|
+
hypot3: () => hypot3,
|
|
157
|
+
imul: () => imul,
|
|
158
|
+
inverseLerp: () => inverseLerp,
|
|
159
|
+
isFinite: () => isFinite,
|
|
160
|
+
isInteger: () => isInteger,
|
|
161
|
+
isNaN: () => isNaN,
|
|
162
|
+
isNullOrUndefined: () => isNullOrUndefined,
|
|
163
|
+
isPositiveString: () => isPositiveString,
|
|
164
|
+
k2xy: () => k2xy,
|
|
165
|
+
k2xyz: () => k2xyz,
|
|
166
|
+
lerp: () => lerp,
|
|
167
|
+
log: () => log,
|
|
168
|
+
log10: () => log10,
|
|
169
|
+
log1p: () => log1p,
|
|
170
|
+
log2: () => log2,
|
|
171
|
+
manhattanDistance: () => manhattanDistance,
|
|
172
|
+
map: () => map,
|
|
173
|
+
max: () => max,
|
|
174
|
+
min: () => min,
|
|
175
|
+
mod: () => mod,
|
|
176
|
+
nearlyEqual: () => nearlyEqual,
|
|
177
|
+
normalizeRadians: () => normalizeRadians,
|
|
178
|
+
pow: () => pow,
|
|
179
|
+
radians: () => radians,
|
|
180
|
+
randomMatrix: () => randomMatrix,
|
|
181
|
+
rng: () => rng,
|
|
182
|
+
round: () => round,
|
|
183
|
+
roundTo: () => roundTo,
|
|
184
|
+
saturate: () => saturate,
|
|
185
|
+
sign: () => sign,
|
|
186
|
+
sin: () => sin,
|
|
187
|
+
sinh: () => sinh,
|
|
188
|
+
smoothstep: () => smoothstep,
|
|
189
|
+
sqrt: () => sqrt,
|
|
190
|
+
squaredDistance: () => squaredDistance,
|
|
191
|
+
tan: () => tan,
|
|
192
|
+
tanh: () => tanh,
|
|
193
|
+
trunc: () => trunc,
|
|
194
|
+
wrap: () => wrap,
|
|
195
|
+
xy2k: () => xy2k,
|
|
196
|
+
xyz2k: () => xyz2k
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// src/math.ts
|
|
200
|
+
var PI = Math.PI;
|
|
201
|
+
var TAU = Math.PI * 2;
|
|
202
|
+
var HALF_PI = Math.PI / 2;
|
|
203
|
+
var QUARTER_PI = Math.PI / 4;
|
|
204
|
+
var E = Math.E;
|
|
205
|
+
var DEG2RAD = PI / 180;
|
|
206
|
+
var RAD2DEG = 180 / PI;
|
|
207
|
+
var LN2 = Math.LN2;
|
|
208
|
+
var LN10 = Math.LN10;
|
|
209
|
+
var LOG2E = Math.LOG2E;
|
|
210
|
+
var LOG10E = Math.LOG10E;
|
|
211
|
+
var SQRT2 = Math.SQRT2;
|
|
212
|
+
var SQRT1_2 = Math.SQRT1_2;
|
|
213
|
+
var EPSILON = Number.EPSILON;
|
|
214
|
+
var abs = Math.abs;
|
|
215
|
+
var min = Math.min;
|
|
216
|
+
var max = Math.max;
|
|
217
|
+
var floor = Math.floor;
|
|
218
|
+
var ceil = Math.ceil;
|
|
219
|
+
var round = Math.round;
|
|
220
|
+
var trunc = Math.trunc;
|
|
221
|
+
var sign = Math.sign;
|
|
222
|
+
var sqrt = Math.sqrt;
|
|
223
|
+
var cbrt = Math.cbrt;
|
|
224
|
+
var pow = Math.pow;
|
|
225
|
+
var exp = Math.exp;
|
|
226
|
+
var expm1 = Math.expm1;
|
|
227
|
+
var log = Math.log;
|
|
228
|
+
var log1p = Math.log1p;
|
|
229
|
+
var log2 = Math.log2;
|
|
230
|
+
var log10 = Math.log10;
|
|
231
|
+
var hypot = Math.hypot;
|
|
232
|
+
var imul = Math.imul;
|
|
233
|
+
var sin = Math.sin;
|
|
234
|
+
var cos = Math.cos;
|
|
235
|
+
var tan = Math.tan;
|
|
236
|
+
var asin = Math.asin;
|
|
237
|
+
var acos = Math.acos;
|
|
238
|
+
var atan = Math.atan;
|
|
239
|
+
var atan2 = Math.atan2;
|
|
240
|
+
var sinh = Math.sinh;
|
|
241
|
+
var cosh = Math.cosh;
|
|
242
|
+
var tanh = Math.tanh;
|
|
243
|
+
var clamp = (value, minValue, maxValue) => min(max(value, minValue), maxValue);
|
|
244
|
+
var saturate = (value) => clamp(value, 0, 1);
|
|
245
|
+
var lerp = (start, end, t) => start + (end - start) * t;
|
|
246
|
+
var inverseLerp = (start, end, value) => (value - start) / (end - start);
|
|
247
|
+
var map = (value, inMin, inMax, outMin, outMax) => outMin + (value - inMin) * (outMax - outMin) / (inMax - inMin);
|
|
248
|
+
var smoothstep = (edge0, edge1, value) => {
|
|
249
|
+
const t = saturate((value - edge0) / (edge1 - edge0));
|
|
250
|
+
return t * t * (3 - 2 * t);
|
|
251
|
+
};
|
|
252
|
+
var fract = (value) => value - floor(value);
|
|
253
|
+
var mod = (value, divisor) => (value % divisor + divisor) % divisor;
|
|
254
|
+
var wrap = (value, minValue, maxValue) => {
|
|
255
|
+
const range = maxValue - minValue;
|
|
256
|
+
return minValue + mod(value - minValue, range);
|
|
257
|
+
};
|
|
258
|
+
var radians = (degrees2) => degrees2 * DEG2RAD;
|
|
259
|
+
var degrees = (radians2) => radians2 * RAD2DEG;
|
|
260
|
+
var normalizeRadians = (radians2) => wrap(radians2, -PI, PI);
|
|
261
|
+
var hypot2 = (x, y) => hypot(x, y);
|
|
262
|
+
var hypot3 = (x, y, z) => hypot(x, y, z);
|
|
263
|
+
var distance2d = (x1, y1, x2, y2) => hypot(x2 - x1, y2 - y1);
|
|
264
|
+
var distance3d = (x1, y1, z1, x2, y2, z2) => hypot(
|
|
265
|
+
x2 - x1,
|
|
266
|
+
y2 - y1,
|
|
267
|
+
z2 - z1
|
|
268
|
+
);
|
|
269
|
+
var squaredDistance = (x1, y1, x2, y2) => {
|
|
270
|
+
const dx = x2 - x1;
|
|
271
|
+
const dy = y2 - y1;
|
|
272
|
+
return dx * dx + dy * dy;
|
|
273
|
+
};
|
|
274
|
+
var manhattanDistance = (x1, y1, x2, y2) => abs(x2 - x1) + abs(y2 - y1);
|
|
275
|
+
var nearlyEqual = (a, b, epsilon = EPSILON) => abs(a - b) <= epsilon;
|
|
276
|
+
var roundTo = (value, digits = 0) => {
|
|
277
|
+
const factor = 10 ** digits;
|
|
278
|
+
return round(value * factor) / factor;
|
|
279
|
+
};
|
|
280
|
+
var isFinite = Number.isFinite;
|
|
281
|
+
var isInteger = Number.isInteger;
|
|
282
|
+
var isNaN = Number.isNaN;
|
|
283
|
+
|
|
1
284
|
// src/astar.ts
|
|
2
285
|
var DIRECTIONS_4_WAY = [
|
|
3
286
|
{ x: 0, y: -1 },
|
|
@@ -7,11 +290,11 @@ var DIRECTIONS_4_WAY = [
|
|
|
7
290
|
];
|
|
8
291
|
var AStar = class {
|
|
9
292
|
map;
|
|
10
|
-
constructor(
|
|
11
|
-
this.map =
|
|
293
|
+
constructor(map2) {
|
|
294
|
+
this.map = map2;
|
|
12
295
|
}
|
|
13
296
|
_manhattan(a, b) {
|
|
14
|
-
return
|
|
297
|
+
return abs(a.x - b.x) + abs(a.y - b.y);
|
|
15
298
|
}
|
|
16
299
|
_isWalkable(point, walkable = [0]) {
|
|
17
300
|
const value = this.map.get(point.x, point.y);
|
|
@@ -90,38 +373,35 @@ var AStar = class {
|
|
|
90
373
|
}
|
|
91
374
|
};
|
|
92
375
|
|
|
93
|
-
// src/
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
this.listeners.get(event)?.push(listener);
|
|
376
|
+
// src/observable.ts
|
|
377
|
+
var Observable = class {
|
|
378
|
+
observers = /* @__PURE__ */ new Set();
|
|
379
|
+
subscribe(observer) {
|
|
380
|
+
this.observers.add(observer);
|
|
381
|
+
return () => this.observers.delete(observer);
|
|
382
|
+
}
|
|
383
|
+
once(observer, ...args) {
|
|
384
|
+
const unsubscribe = this.subscribe((value) => {
|
|
385
|
+
unsubscribe();
|
|
386
|
+
observer(value, ...args);
|
|
106
387
|
});
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
emit(eventName, ...args) {
|
|
110
|
-
this.listeners.get(eventName)?.forEach((listener) => listener(...args, eventName));
|
|
111
|
-
return this;
|
|
388
|
+
return unsubscribe;
|
|
112
389
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
} else {
|
|
117
|
-
this.listeners.clear();
|
|
390
|
+
notify(value, ...args) {
|
|
391
|
+
for (const observer of [...this.observers]) {
|
|
392
|
+
observer(value, ...args);
|
|
118
393
|
}
|
|
119
|
-
|
|
394
|
+
}
|
|
395
|
+
clear() {
|
|
396
|
+
this.observers.clear();
|
|
397
|
+
}
|
|
398
|
+
get size() {
|
|
399
|
+
return this.observers.size;
|
|
120
400
|
}
|
|
121
401
|
};
|
|
122
402
|
|
|
123
403
|
// src/clock.ts
|
|
124
|
-
var Clock = class
|
|
404
|
+
var Clock = class {
|
|
125
405
|
_startTime = 0;
|
|
126
406
|
_time = 0;
|
|
127
407
|
_deltaTime = 0;
|
|
@@ -144,6 +424,7 @@ var Clock = class extends Emitter {
|
|
|
144
424
|
get isRunning() {
|
|
145
425
|
return this._isRunning;
|
|
146
426
|
}
|
|
427
|
+
onFrame = new Observable();
|
|
147
428
|
start() {
|
|
148
429
|
if (!this._isRunning) {
|
|
149
430
|
this._startTime = performance.now();
|
|
@@ -158,7 +439,7 @@ var Clock = class extends Emitter {
|
|
|
158
439
|
this._fps = this._frameCount;
|
|
159
440
|
this._frameCount = 0;
|
|
160
441
|
}
|
|
161
|
-
this.
|
|
442
|
+
this.onFrame.notify(this);
|
|
162
443
|
if (this._isRunning) {
|
|
163
444
|
requestAnimationFrame(update);
|
|
164
445
|
}
|
|
@@ -172,135 +453,294 @@ var Clock = class extends Emitter {
|
|
|
172
453
|
}
|
|
173
454
|
};
|
|
174
455
|
|
|
175
|
-
// src/
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return n > 0 && t !== n ? t + 1 : t;
|
|
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) => {
|
|
197
|
-
b |= 0;
|
|
198
|
-
let result = (a & 4194303) * b;
|
|
199
|
-
if (a & 4290772992) result += (a & 4290772992) * b | 0;
|
|
200
|
-
return result | 0;
|
|
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;
|
|
206
|
-
return n;
|
|
207
|
-
};
|
|
208
|
-
var _sinSeries = (n) => {
|
|
209
|
-
const n2 = n * n;
|
|
210
|
-
return n * (1 + n2 * (-1 / 6 + n2 * (1 / 120 + n2 * (-1 / 5040 + n2 * (1 / 362880 + n2 * (-1 / 39916800))))));
|
|
211
|
-
};
|
|
212
|
-
var _cosSeries = (n) => {
|
|
213
|
-
const n2 = n * n;
|
|
214
|
-
return 1 + n2 * (-1 / 2 + n2 * (1 / 24 + n2 * (-1 / 720 + n2 * (1 / 40320 + n2 * (-1 / 3628800)))));
|
|
215
|
-
};
|
|
216
|
-
var _reduceAngle = (n) => {
|
|
217
|
-
let x = _wrapAngle(n);
|
|
218
|
-
let sinSign = 1;
|
|
219
|
-
if (x < 0) {
|
|
220
|
-
x = -x;
|
|
221
|
-
sinSign = -1;
|
|
222
|
-
}
|
|
223
|
-
let cosSign = 1;
|
|
224
|
-
if (x > HALF_PI) {
|
|
225
|
-
x = PI - x;
|
|
226
|
-
cosSign = -1;
|
|
227
|
-
}
|
|
228
|
-
return [x, sinSign, cosSign];
|
|
229
|
-
};
|
|
230
|
-
var sin = (n) => {
|
|
231
|
-
const [x, sinSign] = _reduceAngle(n);
|
|
232
|
-
return sinSign * _sinSeries(x);
|
|
456
|
+
// src/index.ts
|
|
457
|
+
__reExport(index_exports, __toESM(require_css()));
|
|
458
|
+
|
|
459
|
+
// src/disposable.ts
|
|
460
|
+
var Disposable = class {
|
|
461
|
+
disposers = [];
|
|
462
|
+
add(disposer) {
|
|
463
|
+
this.disposers.push(disposer);
|
|
464
|
+
}
|
|
465
|
+
dispose() {
|
|
466
|
+
while (this.disposers.length) {
|
|
467
|
+
this.disposers.pop()?.();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
233
470
|
};
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
471
|
+
|
|
472
|
+
// src/dungeon-generator.ts
|
|
473
|
+
import { Heap } from "heap-js";
|
|
474
|
+
|
|
475
|
+
// src/map2d.ts
|
|
476
|
+
var DEFAULT_VALUE = -1;
|
|
477
|
+
var BASE_2D = 2097152;
|
|
478
|
+
var OFFSET_2D = 1048576;
|
|
479
|
+
var Map2D = class {
|
|
480
|
+
defaultValue;
|
|
481
|
+
_data;
|
|
482
|
+
get data() {
|
|
483
|
+
return this._data;
|
|
484
|
+
}
|
|
485
|
+
get size() {
|
|
486
|
+
return this._data.size;
|
|
487
|
+
}
|
|
488
|
+
constructor(defaultValue = DEFAULT_VALUE) {
|
|
489
|
+
this.defaultValue = defaultValue;
|
|
490
|
+
this._data = /* @__PURE__ */ new Map();
|
|
491
|
+
}
|
|
492
|
+
_floor(x, y) {
|
|
493
|
+
return [floor(x), floor(y)];
|
|
494
|
+
}
|
|
495
|
+
_key(x, y) {
|
|
496
|
+
const X = x + OFFSET_2D & BASE_2D - 1;
|
|
497
|
+
const Y = y + OFFSET_2D & BASE_2D - 1;
|
|
498
|
+
return X * BASE_2D + Y;
|
|
499
|
+
}
|
|
500
|
+
_pos(key) {
|
|
501
|
+
const Y = key % BASE_2D;
|
|
502
|
+
const X = floor(key / BASE_2D);
|
|
503
|
+
return [X - OFFSET_2D, Y - OFFSET_2D];
|
|
504
|
+
}
|
|
505
|
+
clear() {
|
|
506
|
+
this._data.clear();
|
|
507
|
+
}
|
|
508
|
+
get(x, y, defaultValue = this.defaultValue) {
|
|
509
|
+
[x, y] = this._floor(x, y);
|
|
510
|
+
return this._data.get(this._key(x, y)) ?? defaultValue;
|
|
511
|
+
}
|
|
512
|
+
set(x, y, value = this.defaultValue) {
|
|
513
|
+
[x, y] = this._floor(x, y);
|
|
514
|
+
const key = this._key(x, y);
|
|
515
|
+
if (value === this.defaultValue) {
|
|
516
|
+
this._data.delete(key);
|
|
517
|
+
} else {
|
|
518
|
+
this._data.set(key, value);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
forEach(callback) {
|
|
522
|
+
this._data.forEach((v, key) => {
|
|
523
|
+
const [x, y] = this._pos(key);
|
|
524
|
+
callback(x, y, v);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
237
527
|
};
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
var
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
528
|
+
|
|
529
|
+
// src/random.ts
|
|
530
|
+
var hash32 = (seed) => {
|
|
531
|
+
seed |= 0;
|
|
532
|
+
seed ^= seed >>> 16;
|
|
533
|
+
seed = imul(seed, 2246822507);
|
|
534
|
+
seed ^= seed >>> 13;
|
|
535
|
+
seed = imul(seed, 3266489909);
|
|
536
|
+
seed ^= seed >>> 16;
|
|
537
|
+
return seed >>> 0;
|
|
247
538
|
};
|
|
248
|
-
var
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
539
|
+
var Random = class _Random {
|
|
540
|
+
_seed;
|
|
541
|
+
constructor(seed = Date.now()) {
|
|
542
|
+
this._seed = seed | 0;
|
|
543
|
+
}
|
|
544
|
+
get seed() {
|
|
545
|
+
return this._seed;
|
|
546
|
+
}
|
|
547
|
+
set seed(value) {
|
|
548
|
+
this._seed = value | 0;
|
|
549
|
+
}
|
|
550
|
+
//--------------------------------------------------------------------------
|
|
551
|
+
// Internal
|
|
552
|
+
//--------------------------------------------------------------------------
|
|
553
|
+
static _mix(...values) {
|
|
554
|
+
let seed = 0;
|
|
555
|
+
for (const value of values) {
|
|
556
|
+
seed ^= value | 0;
|
|
557
|
+
seed = hash32(seed);
|
|
558
|
+
}
|
|
559
|
+
return seed;
|
|
560
|
+
}
|
|
561
|
+
//--------------------------------------------------------------------------
|
|
562
|
+
// Stateless
|
|
563
|
+
//--------------------------------------------------------------------------
|
|
564
|
+
static hash(...values) {
|
|
565
|
+
return this._mix(...values);
|
|
566
|
+
}
|
|
567
|
+
static uint(...values) {
|
|
568
|
+
return this._mix(...values);
|
|
569
|
+
}
|
|
570
|
+
static float(...values) {
|
|
571
|
+
return this._mix(...values) / 4294967296;
|
|
572
|
+
}
|
|
573
|
+
static bool(...values) {
|
|
574
|
+
return (this._mix(...values) & 1) !== 0;
|
|
575
|
+
}
|
|
576
|
+
static sign(...values) {
|
|
577
|
+
return this.bool(...values) ? 1 : -1;
|
|
578
|
+
}
|
|
579
|
+
static angle(...values) {
|
|
580
|
+
return this.float(...values) * TAU;
|
|
581
|
+
}
|
|
582
|
+
//--------------------------------------------------------------------------
|
|
583
|
+
// Stateful
|
|
584
|
+
//--------------------------------------------------------------------------
|
|
585
|
+
uint() {
|
|
586
|
+
return _Random.uint(this._seed++);
|
|
587
|
+
}
|
|
588
|
+
float() {
|
|
589
|
+
return _Random.float(this._seed++);
|
|
590
|
+
}
|
|
591
|
+
bool() {
|
|
592
|
+
return _Random.bool(this._seed++);
|
|
593
|
+
}
|
|
594
|
+
sign() {
|
|
595
|
+
return _Random.sign(this._seed++);
|
|
596
|
+
}
|
|
597
|
+
angle() {
|
|
598
|
+
return _Random.angle(this._seed++);
|
|
599
|
+
}
|
|
252
600
|
};
|
|
253
601
|
|
|
254
|
-
// src/
|
|
255
|
-
var
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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;
|
|
602
|
+
// src/rng.ts
|
|
603
|
+
var RandomTools = class {
|
|
604
|
+
rng;
|
|
605
|
+
get seed() {
|
|
606
|
+
return this.rng.seed;
|
|
265
607
|
}
|
|
266
|
-
|
|
267
|
-
|
|
608
|
+
set seed(seed) {
|
|
609
|
+
this.rng.seed = seed;
|
|
268
610
|
}
|
|
269
|
-
|
|
270
|
-
|
|
611
|
+
constructor(seed) {
|
|
612
|
+
this.rng = seed instanceof Random ? seed : new Random(seed);
|
|
271
613
|
}
|
|
272
|
-
|
|
273
|
-
|
|
614
|
+
//----------------------------------------------------------------------
|
|
615
|
+
// Numbers
|
|
616
|
+
//----------------------------------------------------------------------
|
|
617
|
+
nextFloat() {
|
|
618
|
+
return this.rng.float();
|
|
274
619
|
}
|
|
275
|
-
|
|
276
|
-
return
|
|
277
|
-
this.x + this.width / 2,
|
|
278
|
-
this.y + this.height / 2
|
|
279
|
-
);
|
|
620
|
+
nextUint() {
|
|
621
|
+
return this.rng.uint();
|
|
280
622
|
}
|
|
281
|
-
|
|
282
|
-
|
|
623
|
+
floatRange(min2, max2) {
|
|
624
|
+
if (typeof max2 !== "number") {
|
|
625
|
+
max2 = min2;
|
|
626
|
+
min2 = 0;
|
|
627
|
+
}
|
|
628
|
+
return min2 + this.rng.float() * (max2 - min2);
|
|
283
629
|
}
|
|
284
|
-
|
|
285
|
-
|
|
630
|
+
range(min2, max2) {
|
|
631
|
+
if (typeof max2 !== "number") {
|
|
632
|
+
max2 = min2;
|
|
633
|
+
min2 = 0;
|
|
634
|
+
}
|
|
635
|
+
return floor(this.floatRange(min2, max2 + 1));
|
|
286
636
|
}
|
|
287
|
-
|
|
288
|
-
|
|
637
|
+
//----------------------------------------------------------------------
|
|
638
|
+
// Collections
|
|
639
|
+
//----------------------------------------------------------------------
|
|
640
|
+
pick(array) {
|
|
641
|
+
return array[this.range(0, array.length - 1)];
|
|
289
642
|
}
|
|
290
|
-
|
|
291
|
-
return
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
643
|
+
sample(array, count) {
|
|
644
|
+
return this.shuffle(array).slice(0, count);
|
|
645
|
+
}
|
|
646
|
+
shuffle(array) {
|
|
647
|
+
const result = [...array];
|
|
648
|
+
for (let i = result.length - 1; i > 0; --i) {
|
|
649
|
+
const j = this.range(0, i);
|
|
650
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
651
|
+
}
|
|
652
|
+
return result;
|
|
653
|
+
}
|
|
654
|
+
chance(probability) {
|
|
655
|
+
return this.rng.float() < probability;
|
|
656
|
+
}
|
|
657
|
+
//----------------------------------------------------------------------
|
|
658
|
+
// Geometry
|
|
659
|
+
//----------------------------------------------------------------------
|
|
660
|
+
vector2() {
|
|
661
|
+
const \u03B8 = this.rng.angle();
|
|
662
|
+
return [
|
|
663
|
+
cos(\u03B8),
|
|
664
|
+
sin(\u03B8)
|
|
665
|
+
];
|
|
666
|
+
}
|
|
667
|
+
pointOnCircle(radius = 1) {
|
|
668
|
+
const \u03B8 = this.rng.angle();
|
|
669
|
+
return [
|
|
670
|
+
radius * cos(\u03B8),
|
|
671
|
+
radius * sin(\u03B8)
|
|
672
|
+
];
|
|
673
|
+
}
|
|
674
|
+
pointInCircle(radius = 1) {
|
|
675
|
+
const \u03B8 = this.rng.angle();
|
|
676
|
+
const r = sqrt(this.rng.float()) * radius;
|
|
677
|
+
return [
|
|
678
|
+
r * cos(\u03B8),
|
|
679
|
+
r * sin(\u03B8)
|
|
680
|
+
];
|
|
681
|
+
}
|
|
682
|
+
pointOnSphere(radius = 1) {
|
|
683
|
+
const u = this.rng.float();
|
|
684
|
+
const v = this.rng.float();
|
|
685
|
+
const \u03B8 = TAU * u;
|
|
686
|
+
const \u03C6 = acos(2 * v - 1);
|
|
687
|
+
const s = sin(\u03C6);
|
|
688
|
+
return [
|
|
689
|
+
radius * s * cos(\u03B8),
|
|
690
|
+
radius * s * sin(\u03B8),
|
|
691
|
+
radius * cos(\u03C6)
|
|
692
|
+
];
|
|
693
|
+
}
|
|
694
|
+
pointInSphere(radius = 1) {
|
|
695
|
+
const u = this.rng.float();
|
|
696
|
+
const v = this.rng.float();
|
|
697
|
+
const \u03B8 = TAU * u;
|
|
698
|
+
const \u03C6 = acos(2 * v - 1);
|
|
699
|
+
const r = radius * cbrt(this.rng.float());
|
|
700
|
+
const s = sin(\u03C6);
|
|
701
|
+
return [
|
|
702
|
+
r * s * cos(\u03B8),
|
|
703
|
+
r * s * sin(\u03B8),
|
|
704
|
+
r * cos(\u03C6)
|
|
705
|
+
];
|
|
706
|
+
}
|
|
707
|
+
//----------------------------------------------------------------------
|
|
708
|
+
// Distributions
|
|
709
|
+
//----------------------------------------------------------------------
|
|
710
|
+
gaussian(mean = 0, standardDeviation = 1) {
|
|
711
|
+
let u = 0;
|
|
712
|
+
let v = 0;
|
|
713
|
+
while (u === 0) u = this.rng.float();
|
|
714
|
+
while (v === 0) v = this.rng.float();
|
|
715
|
+
const z = sqrt(-2 * Math.log(u)) * cos(TAU * v);
|
|
716
|
+
return mean + z * standardDeviation;
|
|
717
|
+
}
|
|
718
|
+
//----------------------------------------------------------------------
|
|
719
|
+
// Matrices
|
|
720
|
+
//----------------------------------------------------------------------
|
|
721
|
+
matrix(rows, columns = rows, min2 = 0, max2 = 1) {
|
|
722
|
+
return Array.from(
|
|
723
|
+
{ length: rows },
|
|
724
|
+
() => Array.from(
|
|
725
|
+
{ length: columns },
|
|
726
|
+
() => this.floatRange(min2, max2)
|
|
727
|
+
)
|
|
296
728
|
);
|
|
297
729
|
}
|
|
298
|
-
|
|
299
|
-
return
|
|
730
|
+
transformMatrix(rows, columns = rows) {
|
|
731
|
+
return this.matrix(rows, columns, -1, 1);
|
|
300
732
|
}
|
|
301
733
|
};
|
|
734
|
+
var rng = new RandomTools();
|
|
735
|
+
|
|
736
|
+
// src/logger.ts
|
|
737
|
+
var logger_default = console.debug.bind(
|
|
738
|
+
console,
|
|
739
|
+
"%c[dev]",
|
|
740
|
+
"font-weight: bold; color: #888;"
|
|
741
|
+
);
|
|
302
742
|
|
|
303
|
-
// src/
|
|
743
|
+
// src/vector.ts
|
|
304
744
|
var Vector = class _Vector {
|
|
305
745
|
x;
|
|
306
746
|
y;
|
|
@@ -311,6 +751,24 @@ var Vector = class _Vector {
|
|
|
311
751
|
clone() {
|
|
312
752
|
return new _Vector(this.x, this.y);
|
|
313
753
|
}
|
|
754
|
+
copy(that) {
|
|
755
|
+
this.x = that.x;
|
|
756
|
+
this.y = that.y;
|
|
757
|
+
return this;
|
|
758
|
+
}
|
|
759
|
+
copyTo(target) {
|
|
760
|
+
target.x = this.x;
|
|
761
|
+
target.y = this.y;
|
|
762
|
+
return this;
|
|
763
|
+
}
|
|
764
|
+
set(x, y) {
|
|
765
|
+
this.x = x;
|
|
766
|
+
this.y = y;
|
|
767
|
+
return this;
|
|
768
|
+
}
|
|
769
|
+
equals(that) {
|
|
770
|
+
return this.x === that.x && this.y === that.y;
|
|
771
|
+
}
|
|
314
772
|
distanceTo(that) {
|
|
315
773
|
return distance2d(
|
|
316
774
|
this.x,
|
|
@@ -319,6 +777,44 @@ var Vector = class _Vector {
|
|
|
319
777
|
that.y
|
|
320
778
|
);
|
|
321
779
|
}
|
|
780
|
+
length() {
|
|
781
|
+
return Math.hypot(this.x, this.y);
|
|
782
|
+
}
|
|
783
|
+
normalize() {
|
|
784
|
+
const length = this.length();
|
|
785
|
+
if (length > 0) {
|
|
786
|
+
this.dividedBy(length);
|
|
787
|
+
}
|
|
788
|
+
return this;
|
|
789
|
+
}
|
|
790
|
+
setLength(length) {
|
|
791
|
+
return this.normalize().times(length);
|
|
792
|
+
}
|
|
793
|
+
dot(that) {
|
|
794
|
+
return this.x * that.x + this.y * that.y;
|
|
795
|
+
}
|
|
796
|
+
angle() {
|
|
797
|
+
return Math.atan2(this.y, this.x);
|
|
798
|
+
}
|
|
799
|
+
angleTo(that) {
|
|
800
|
+
const denominator = this.length() * that.length();
|
|
801
|
+
if (denominator === 0) {
|
|
802
|
+
return 0;
|
|
803
|
+
}
|
|
804
|
+
const theta = this.dot(that) / denominator;
|
|
805
|
+
return Math.acos(Math.min(1, Math.max(-1, theta)));
|
|
806
|
+
}
|
|
807
|
+
rotate(radians2) {
|
|
808
|
+
const cos2 = Math.cos(radians2);
|
|
809
|
+
const sin2 = Math.sin(radians2);
|
|
810
|
+
const { x, y } = this;
|
|
811
|
+
this.x = x * cos2 - y * sin2;
|
|
812
|
+
this.y = x * sin2 + y * cos2;
|
|
813
|
+
return this;
|
|
814
|
+
}
|
|
815
|
+
rotateAround(origin, radians2) {
|
|
816
|
+
return this.minus(origin).rotate(radians2).plus(origin);
|
|
817
|
+
}
|
|
322
818
|
floored() {
|
|
323
819
|
return new _Vector(
|
|
324
820
|
Math.floor(this.x),
|
|
@@ -369,6 +865,12 @@ var Vector = class _Vector {
|
|
|
369
865
|
this.y /= y || 1;
|
|
370
866
|
return this;
|
|
371
867
|
}
|
|
868
|
+
static from(value) {
|
|
869
|
+
return new _Vector(value.x, value.y);
|
|
870
|
+
}
|
|
871
|
+
static get ZERO() {
|
|
872
|
+
return new _Vector(0, 0);
|
|
873
|
+
}
|
|
372
874
|
static get NORTH() {
|
|
373
875
|
return new _Vector(0, -1);
|
|
374
876
|
}
|
|
@@ -383,175 +885,54 @@ var Vector = class _Vector {
|
|
|
383
885
|
}
|
|
384
886
|
};
|
|
385
887
|
|
|
386
|
-
// src/
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
var DEFAULT_VALUE = -1;
|
|
398
|
-
var Map2D = class {
|
|
399
|
-
defaultValue;
|
|
400
|
-
_data;
|
|
401
|
-
get size() {
|
|
402
|
-
return this._data.size;
|
|
403
|
-
}
|
|
404
|
-
constructor(defaultValue = DEFAULT_VALUE) {
|
|
405
|
-
this.defaultValue = defaultValue;
|
|
406
|
-
this._data = /* @__PURE__ */ new Map();
|
|
407
|
-
}
|
|
408
|
-
_floor(x, y) {
|
|
409
|
-
return [floor(x), floor(y)];
|
|
410
|
-
}
|
|
411
|
-
_key(x, y) {
|
|
412
|
-
return `${x},${y}`;
|
|
413
|
-
}
|
|
414
|
-
_pos(key) {
|
|
415
|
-
return key.split(",").map((v) => parseInt(v));
|
|
416
|
-
}
|
|
417
|
-
clear() {
|
|
418
|
-
this._data.clear();
|
|
419
|
-
}
|
|
420
|
-
get(x, y, defaultValue = this.defaultValue) {
|
|
421
|
-
[x, y] = this._floor(x, y);
|
|
422
|
-
return this._data.get(this._key(x, y)) ?? defaultValue;
|
|
423
|
-
}
|
|
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
|
-
}
|
|
432
|
-
}
|
|
433
|
-
forEach(callback) {
|
|
434
|
-
this._data.forEach((v, key) => {
|
|
435
|
-
const [x, y] = this._pos(key);
|
|
436
|
-
callback(x, y, v);
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
// src/rng.ts
|
|
442
|
-
var RandomNumberGenerator = class {
|
|
443
|
-
__seed;
|
|
444
|
-
_seed;
|
|
445
|
-
_uid_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
446
|
-
constructor() {
|
|
447
|
-
this._seed = Date.now();
|
|
448
|
-
this.__seed = this._seed;
|
|
449
|
-
this._uid_characters = this.shuffle(this._uid_characters);
|
|
450
|
-
this.seed = this.nexti;
|
|
888
|
+
// src/rectangle.ts
|
|
889
|
+
var Rectangle = class _Rectangle {
|
|
890
|
+
x;
|
|
891
|
+
y;
|
|
892
|
+
width;
|
|
893
|
+
height;
|
|
894
|
+
constructor(x = 0, y = 0, width = 1, height = 1) {
|
|
895
|
+
this.x = x;
|
|
896
|
+
this.y = y;
|
|
897
|
+
this.width = width;
|
|
898
|
+
this.height = height;
|
|
451
899
|
}
|
|
452
|
-
|
|
453
|
-
return this.
|
|
900
|
+
area() {
|
|
901
|
+
return this.width * this.height;
|
|
454
902
|
}
|
|
455
|
-
|
|
456
|
-
this.
|
|
457
|
-
this.__seed = this._seed;
|
|
903
|
+
contains(target, padding = 0) {
|
|
904
|
+
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;
|
|
458
905
|
}
|
|
459
|
-
|
|
460
|
-
return this.
|
|
906
|
+
intersects(other, padding = 0) {
|
|
907
|
+
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);
|
|
461
908
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
t = t ^ t >>> 15;
|
|
468
|
-
t = imul(t, 1935289751);
|
|
469
|
-
return ((t = t ^ t >>> 15) >>> 0) / 4294967296;
|
|
909
|
+
center() {
|
|
910
|
+
return new Vector(
|
|
911
|
+
this.x + this.width / 2,
|
|
912
|
+
this.y + this.height / 2
|
|
913
|
+
);
|
|
470
914
|
}
|
|
471
|
-
|
|
472
|
-
return this.
|
|
915
|
+
distanceTo(other) {
|
|
916
|
+
return this.center().distanceTo(other.center());
|
|
473
917
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
max2 = min2;
|
|
477
|
-
min2 = 0;
|
|
478
|
-
}
|
|
479
|
-
return min2 + this.nextf * (max2 - min2) | 0;
|
|
480
|
-
}
|
|
481
|
-
randomUnitVector() {
|
|
482
|
-
const theta = this.nextf * 2 * PI;
|
|
483
|
-
return [cos(theta), sin(theta)];
|
|
484
|
-
}
|
|
485
|
-
pointInUnitCircle(radius = 1, floored = false) {
|
|
486
|
-
const theta = this.nextf * 2 * PI;
|
|
487
|
-
const r = sqrt(this.nextf) * radius;
|
|
488
|
-
const x = r * cos(theta);
|
|
489
|
-
const y = r * sin(theta);
|
|
490
|
-
return !floored ? [x, y] : [floor(x), floor(y)];
|
|
491
|
-
}
|
|
492
|
-
pointInUnitSphere(radius = 1, floored = false) {
|
|
493
|
-
var u = this.nextf;
|
|
494
|
-
var v = this.nextf;
|
|
495
|
-
var theta = u * 2 * PI;
|
|
496
|
-
var phi = Math.acos(2 * v - 1);
|
|
497
|
-
var r = radius * Math.cbrt(rng.nextf);
|
|
498
|
-
var sinTheta = sin(theta);
|
|
499
|
-
var cosTheta = cos(theta);
|
|
500
|
-
var sinPhi = sin(phi);
|
|
501
|
-
var cosPhi = cos(phi);
|
|
502
|
-
var x = r * sinPhi * cosTheta;
|
|
503
|
-
var y = r * sinPhi * sinTheta;
|
|
504
|
-
var z = r * cosPhi;
|
|
505
|
-
return !floored ? [x, y, z] : [floor(x), floor(y), floor(z)];
|
|
506
|
-
}
|
|
507
|
-
parkMillerNormal() {
|
|
508
|
-
const mean = 1 / 2;
|
|
509
|
-
const stddev = 1 / 6;
|
|
510
|
-
let u = 0;
|
|
511
|
-
let v = 0;
|
|
512
|
-
while (u === 0) u = this.nextf;
|
|
513
|
-
while (v === 0) v = this.nextf;
|
|
514
|
-
const n = sqrt(-2 * Math.log(u)) * cos(2 * PI * v);
|
|
515
|
-
return n * stddev + mean;
|
|
516
|
-
}
|
|
517
|
-
choose(...args) {
|
|
518
|
-
if (args.length === 1) {
|
|
519
|
-
if (Array.isArray(args[0])) {
|
|
520
|
-
return args[0][this.range(args[0].length - 1)];
|
|
521
|
-
} else if (typeof args[0] === "string") {
|
|
522
|
-
return args[0].charAt(this.range(args[0].length - 1));
|
|
523
|
-
} else {
|
|
524
|
-
return args[0];
|
|
525
|
-
}
|
|
526
|
-
} else {
|
|
527
|
-
return args[this.range(args.length - 1)];
|
|
528
|
-
}
|
|
918
|
+
clone() {
|
|
919
|
+
return new _Rectangle(this.x, this.y, this.width, this.height);
|
|
529
920
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
return value.sort(() => 0.5 - this.nextf);
|
|
533
|
-
} else {
|
|
534
|
-
return value.split("").sort(() => 0.5 - this.nextf).join("");
|
|
535
|
-
}
|
|
921
|
+
equals(other) {
|
|
922
|
+
return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
|
|
536
923
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
924
|
+
grow(padding) {
|
|
925
|
+
return new _Rectangle(
|
|
926
|
+
this.x - padding,
|
|
927
|
+
this.y - padding,
|
|
928
|
+
this.width + padding * 2,
|
|
929
|
+
this.height + padding * 2
|
|
930
|
+
);
|
|
541
931
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
for (let i = 0; i < size; i++) {
|
|
545
|
-
const row = [];
|
|
546
|
-
for (let j = 0; j < size; j++) {
|
|
547
|
-
row.push(this.nextf * 2 - 1);
|
|
548
|
-
}
|
|
549
|
-
rows.push(row);
|
|
550
|
-
}
|
|
551
|
-
return rows;
|
|
932
|
+
vectorInside(vec, padding = 0) {
|
|
933
|
+
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;
|
|
552
934
|
}
|
|
553
935
|
};
|
|
554
|
-
var rng = new RandomNumberGenerator();
|
|
555
936
|
|
|
556
937
|
// src/dungeon-generator.ts
|
|
557
938
|
var TILE_EMPTY = 0;
|
|
@@ -584,20 +965,20 @@ var DIRECTIONS_8_WAY = [
|
|
|
584
965
|
{ x: -1, y: 1 }
|
|
585
966
|
// down-left
|
|
586
967
|
];
|
|
587
|
-
function _plot(
|
|
968
|
+
function _plot(map2, data, tile) {
|
|
588
969
|
data.forEach((element) => {
|
|
589
970
|
if (element instanceof Rectangle) {
|
|
590
971
|
for (let y = 0; y < element.height; y++) {
|
|
591
972
|
for (let x = 0; x < element.width; x++) {
|
|
592
|
-
|
|
973
|
+
map2.set(element.x + x, element.y + y, tile);
|
|
593
974
|
}
|
|
594
975
|
}
|
|
595
976
|
} else if (Array.isArray(element)) {
|
|
596
977
|
element.forEach((point) => {
|
|
597
|
-
|
|
978
|
+
map2.set(point.x, point.y, tile);
|
|
598
979
|
});
|
|
599
980
|
} else {
|
|
600
|
-
|
|
981
|
+
map2.set(element.x, element.y, tile);
|
|
601
982
|
}
|
|
602
983
|
});
|
|
603
984
|
}
|
|
@@ -611,11 +992,11 @@ function _generateRooms(params = {}) {
|
|
|
611
992
|
let iterations = 0;
|
|
612
993
|
while (iterations < maxIterations) {
|
|
613
994
|
const baseSize = rng.range(minRoomSize, maxRoomSize);
|
|
614
|
-
const aspectRatio = 0.75 + rng.
|
|
615
|
-
const width =
|
|
616
|
-
const height =
|
|
617
|
-
const x =
|
|
618
|
-
const y =
|
|
995
|
+
const aspectRatio = 0.75 + rng.gaussian() * 0.5;
|
|
996
|
+
const width = min(maxRoomSize, max(minRoomSize, round(baseSize * aspectRatio)));
|
|
997
|
+
const height = min(maxRoomSize, max(minRoomSize, round(baseSize / aspectRatio)));
|
|
998
|
+
const x = floor(rng.range(1 + padding, size - width - padding));
|
|
999
|
+
const y = floor(rng.range(1 + padding, size - height - padding));
|
|
619
1000
|
const room = new Rectangle(x, y, width, height);
|
|
620
1001
|
if (!rooms.some((existing) => room.intersects(existing, padding))) {
|
|
621
1002
|
rooms.push(room);
|
|
@@ -679,7 +1060,7 @@ function _generateMST(rooms, params = {}) {
|
|
|
679
1060
|
const remainingEdges = heap.toArray().sort((a, b) => a.cost - b.cost);
|
|
680
1061
|
for (let i = 0; i < extraPathLevels && i < remainingEdges.length; i++) {
|
|
681
1062
|
const e = remainingEdges[i];
|
|
682
|
-
if (rng.
|
|
1063
|
+
if (rng.nextFloat() < extraPathDensity) {
|
|
683
1064
|
extraPaths.push({
|
|
684
1065
|
a: rooms[e.from],
|
|
685
1066
|
b: rooms[e.to]
|
|
@@ -716,8 +1097,8 @@ function _getShortestPathBetweenRects(rectA, rectB) {
|
|
|
716
1097
|
}
|
|
717
1098
|
return { a: paths.a, b: paths.b };
|
|
718
1099
|
}
|
|
719
|
-
function _generatePaths(
|
|
720
|
-
const aStar = new AStar(
|
|
1100
|
+
function _generatePaths(map2, rooms, params = {}) {
|
|
1101
|
+
const aStar = new AStar(map2);
|
|
721
1102
|
const paths = [];
|
|
722
1103
|
_generateMST(rooms, params).forEach((rects) => {
|
|
723
1104
|
const { a, b } = _getShortestPathBetweenRects(rects.a, rects.b);
|
|
@@ -727,15 +1108,15 @@ function _generatePaths(map, rooms, params = {}) {
|
|
|
727
1108
|
}
|
|
728
1109
|
function GenerateRooms(params = {}) {
|
|
729
1110
|
const startTime = Date.now();
|
|
730
|
-
const
|
|
1111
|
+
const map2 = params.map ?? new Map2D(TILE_EMPTY);
|
|
731
1112
|
const rooms = _generateRooms(params.rooms);
|
|
732
|
-
_plot(
|
|
733
|
-
const paths = _generatePaths(
|
|
734
|
-
_plot(
|
|
735
|
-
|
|
736
|
-
return { map, rooms, paths };
|
|
1113
|
+
_plot(map2, rooms, TILE_FLOOR);
|
|
1114
|
+
const paths = _generatePaths(map2, rooms, params.paths);
|
|
1115
|
+
_plot(map2, paths, TILE_PATH);
|
|
1116
|
+
logger_default("GenerateRooms: done:", Date.now() - startTime, "ms");
|
|
1117
|
+
return { map: map2, rooms, paths };
|
|
737
1118
|
}
|
|
738
|
-
function GenerateDoors(
|
|
1119
|
+
function GenerateDoors(map2, paths, params = {}) {
|
|
739
1120
|
const chanceExists = params.chanceExists ?? DEFAULT_DOOR_CHANCE_EXISTS;
|
|
740
1121
|
const possibleDoorPoints = [];
|
|
741
1122
|
paths.forEach((points) => {
|
|
@@ -746,19 +1127,19 @@ function GenerateDoors(map, paths, params = {}) {
|
|
|
746
1127
|
});
|
|
747
1128
|
const doors = [];
|
|
748
1129
|
possibleDoorPoints.forEach((doorPoint) => {
|
|
749
|
-
if (rng.
|
|
1130
|
+
if (rng.nextFloat() < chanceExists && (map2.get(doorPoint.x, doorPoint.y - 1) === map2.defaultValue && map2.get(doorPoint.x, doorPoint.y + 1) === map2.defaultValue || map2.get(doorPoint.x - 1, doorPoint.y) === map2.defaultValue && map2.get(doorPoint.x + 1, doorPoint.y) === map2.defaultValue)) {
|
|
750
1131
|
doors.push(doorPoint);
|
|
751
1132
|
}
|
|
752
1133
|
});
|
|
753
1134
|
return doors;
|
|
754
1135
|
}
|
|
755
|
-
function GenerateWalls(
|
|
1136
|
+
function GenerateWalls(map2) {
|
|
756
1137
|
const walls = [];
|
|
757
|
-
|
|
1138
|
+
map2.forEach((x, y, _v) => {
|
|
758
1139
|
DIRECTIONS_8_WAY.forEach((dir) => {
|
|
759
1140
|
const nx = dir.x + x;
|
|
760
1141
|
const ny = dir.y + y;
|
|
761
|
-
if (
|
|
1142
|
+
if (map2.get(nx, ny) === map2.defaultValue) {
|
|
762
1143
|
walls.push({ x: nx, y: ny });
|
|
763
1144
|
}
|
|
764
1145
|
});
|
|
@@ -799,79 +1180,118 @@ var ECS = class {
|
|
|
799
1180
|
}
|
|
800
1181
|
};
|
|
801
1182
|
|
|
802
|
-
// src/
|
|
803
|
-
var
|
|
804
|
-
|
|
1183
|
+
// src/event-queue.ts
|
|
1184
|
+
var EventQueue = class {
|
|
1185
|
+
events = [];
|
|
1186
|
+
emit(event) {
|
|
1187
|
+
this.events.push(event);
|
|
1188
|
+
}
|
|
1189
|
+
consume() {
|
|
1190
|
+
return this.events;
|
|
1191
|
+
}
|
|
1192
|
+
clear() {
|
|
1193
|
+
this.events.length = 0;
|
|
1194
|
+
}
|
|
1195
|
+
drain() {
|
|
1196
|
+
return this.events.splice(0);
|
|
1197
|
+
}
|
|
1198
|
+
get size() {
|
|
1199
|
+
return this.events.length;
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
// src/input.ts
|
|
1204
|
+
var DOWN = 1;
|
|
1205
|
+
var UP = 0;
|
|
1206
|
+
var Input = class _Input {
|
|
1207
|
+
static _instance;
|
|
1208
|
+
static get instance() {
|
|
1209
|
+
if (!_Input._instance) {
|
|
1210
|
+
_Input._instance = new _Input();
|
|
1211
|
+
}
|
|
1212
|
+
return _Input._instance;
|
|
1213
|
+
}
|
|
1214
|
+
_keyStates;
|
|
1215
|
+
_buttonStates;
|
|
805
1216
|
_pointerPosition = new Vector();
|
|
806
1217
|
inputThreshold = 200;
|
|
807
|
-
get down() {
|
|
808
|
-
return this._down;
|
|
809
|
-
}
|
|
810
1218
|
get pointerPosition() {
|
|
811
|
-
return this._pointerPosition;
|
|
812
|
-
}
|
|
1219
|
+
return this._pointerPosition.clone();
|
|
1220
|
+
}
|
|
1221
|
+
// get mouseWorldPosition(): Vector {
|
|
1222
|
+
// return new Vector(
|
|
1223
|
+
// (this._mousePosition.x / this.canvasWidth) * 2 - 1,
|
|
1224
|
+
// -(this._mousePosition.y / this.canvasHeight) * 2 + 1,
|
|
1225
|
+
// )
|
|
1226
|
+
// }
|
|
1227
|
+
onKeyDown = new Observable();
|
|
1228
|
+
onKeyUp = new Observable();
|
|
1229
|
+
onKeyPressed = new Observable();
|
|
1230
|
+
onPointerDown = new Observable();
|
|
1231
|
+
onPointerUp = new Observable();
|
|
1232
|
+
onPointerPressed = new Observable();
|
|
1233
|
+
onPointerMove = new Observable();
|
|
1234
|
+
onWheel = new Observable();
|
|
813
1235
|
constructor() {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
log("contextmenu:", ev);
|
|
817
|
-
});
|
|
1236
|
+
this._keyStates = /* @__PURE__ */ new Map();
|
|
1237
|
+
this._buttonStates = /* @__PURE__ */ new Map();
|
|
818
1238
|
window.addEventListener("keydown", (ev) => {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
this.
|
|
822
|
-
this.emit("key_down", code, ev);
|
|
1239
|
+
if (!ev.repeat) {
|
|
1240
|
+
this._keyStates.set(ev.code, { state: DOWN, time: ev.timeStamp });
|
|
1241
|
+
this.onKeyDown.notify(this, ev);
|
|
823
1242
|
}
|
|
824
1243
|
});
|
|
825
1244
|
window.addEventListener("keyup", (ev) => {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
this.
|
|
829
|
-
this.emit("key_up", code, ev);
|
|
1245
|
+
this._keyStates.set(ev.code, { state: UP, time: ev.timeStamp });
|
|
1246
|
+
this.onKeyUp.notify(this, ev);
|
|
1247
|
+
const delta = ev.timeStamp - (this._keyStates.get(ev.code)?.time ?? 0);
|
|
830
1248
|
if (delta < this.inputThreshold) {
|
|
831
|
-
this.
|
|
1249
|
+
this.onKeyPressed.notify(this, ev);
|
|
832
1250
|
}
|
|
833
1251
|
});
|
|
834
1252
|
window.addEventListener("pointerdown", (ev) => {
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
this.
|
|
839
|
-
this.emit("pointer_down", code, ev);
|
|
1253
|
+
const code = `Button${ev.button}`;
|
|
1254
|
+
if (!this._buttonStates.get(code)) {
|
|
1255
|
+
this._buttonStates.set(code, { state: DOWN, time: ev.timeStamp });
|
|
1256
|
+
this.onPointerDown.notify(this, ev);
|
|
840
1257
|
}
|
|
841
1258
|
});
|
|
842
1259
|
window.addEventListener("pointerup", (ev) => {
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
this.
|
|
1260
|
+
const code = `Button${ev.button}`;
|
|
1261
|
+
this._buttonStates.set(code, { state: UP, time: ev.timeStamp });
|
|
1262
|
+
this.onPointerUp.notify(this, ev);
|
|
1263
|
+
const delta = ev.timeStamp - (this._buttonStates.get(code)?.time ?? 0);
|
|
847
1264
|
if (delta < this.inputThreshold) {
|
|
848
|
-
this.
|
|
1265
|
+
this.onPointerPressed.notify(this, ev);
|
|
849
1266
|
}
|
|
850
1267
|
});
|
|
851
1268
|
window.addEventListener("pointermove", (ev) => {
|
|
852
|
-
|
|
853
|
-
this._pointerPosition.
|
|
854
|
-
this.
|
|
855
|
-
this.emit("pointer_move", movementX, movementY, ev);
|
|
1269
|
+
this._pointerPosition.x = ev.offsetX;
|
|
1270
|
+
this._pointerPosition.y = ev.offsetY;
|
|
1271
|
+
this.onPointerMove.notify(this, ev);
|
|
856
1272
|
});
|
|
857
1273
|
window.addEventListener("wheel", (ev) => {
|
|
858
|
-
|
|
859
|
-
this.emit("wheel", deltaY, ev);
|
|
1274
|
+
this.onWheel.notify(this, ev);
|
|
860
1275
|
});
|
|
861
1276
|
}
|
|
862
|
-
isDown(
|
|
863
|
-
return this.
|
|
1277
|
+
isDown(key) {
|
|
1278
|
+
return (this._keyStates.get(key) ?? this._buttonStates.get(key))?.state === 1;
|
|
864
1279
|
}
|
|
865
1280
|
};
|
|
866
1281
|
|
|
867
1282
|
// src/map3d.ts
|
|
868
1283
|
var DEFAULT_VALUE2 = -1;
|
|
1284
|
+
var BASE_3D = 131072;
|
|
1285
|
+
var OFFSET_3D = 65536;
|
|
869
1286
|
var Map3D = class {
|
|
870
1287
|
defaultValue;
|
|
871
1288
|
_data;
|
|
872
1289
|
get data() {
|
|
873
1290
|
return this._data;
|
|
874
1291
|
}
|
|
1292
|
+
get size() {
|
|
1293
|
+
return this._data.size;
|
|
1294
|
+
}
|
|
875
1295
|
constructor(defaultValue = DEFAULT_VALUE2) {
|
|
876
1296
|
this.defaultValue = defaultValue;
|
|
877
1297
|
this._data = /* @__PURE__ */ new Map();
|
|
@@ -880,10 +1300,16 @@ var Map3D = class {
|
|
|
880
1300
|
return [floor(x), floor(y), floor(z)];
|
|
881
1301
|
}
|
|
882
1302
|
_key(x, y, z) {
|
|
883
|
-
|
|
1303
|
+
const X = x + OFFSET_3D & BASE_3D - 1;
|
|
1304
|
+
const Y = y + OFFSET_3D & BASE_3D - 1;
|
|
1305
|
+
const Z = z + OFFSET_3D & BASE_3D - 1;
|
|
1306
|
+
return X * BASE_3D * BASE_3D + Y * BASE_3D + Z;
|
|
884
1307
|
}
|
|
885
1308
|
_pos(key) {
|
|
886
|
-
|
|
1309
|
+
const Z = key % BASE_3D;
|
|
1310
|
+
const Y = floor(key / BASE_3D) % BASE_3D;
|
|
1311
|
+
const X = floor(key / (BASE_3D * BASE_3D));
|
|
1312
|
+
return [X - OFFSET_3D, Y - OFFSET_3D, Z - OFFSET_3D];
|
|
887
1313
|
}
|
|
888
1314
|
clear() {
|
|
889
1315
|
this._data.clear();
|
|
@@ -925,7 +1351,7 @@ var getRedYellowGreenGradientHex = (min2, max2) => {
|
|
|
925
1351
|
max2 = 1;
|
|
926
1352
|
}
|
|
927
1353
|
const percent = min2 / max2;
|
|
928
|
-
const index = clamp(
|
|
1354
|
+
const index = clamp(floor(percent * 10), 0, 10);
|
|
929
1355
|
return [
|
|
930
1356
|
"#ff0000",
|
|
931
1357
|
"#ff3300",
|
|
@@ -961,19 +1387,19 @@ var Noise = class _Noise {
|
|
|
961
1387
|
static _n4d;
|
|
962
1388
|
static noise2d(x, y) {
|
|
963
1389
|
if (!_Noise._n2d) {
|
|
964
|
-
_Noise._n2d = createNoise2D(() => rng.
|
|
1390
|
+
_Noise._n2d = createNoise2D(() => rng.nextFloat());
|
|
965
1391
|
}
|
|
966
1392
|
return _Noise._n2d(x, y);
|
|
967
1393
|
}
|
|
968
1394
|
static noise3d(x, y, z) {
|
|
969
1395
|
if (!_Noise._n3d) {
|
|
970
|
-
_Noise._n3d = createNoise3D(() => rng.
|
|
1396
|
+
_Noise._n3d = createNoise3D(() => rng.nextFloat());
|
|
971
1397
|
}
|
|
972
1398
|
return _Noise._n3d(x, y, z);
|
|
973
1399
|
}
|
|
974
1400
|
static noise4d(x, y, z, w) {
|
|
975
1401
|
if (!_Noise._n4d) {
|
|
976
|
-
_Noise._n4d = createNoise4D(() => rng.
|
|
1402
|
+
_Noise._n4d = createNoise4D(() => rng.nextFloat());
|
|
977
1403
|
}
|
|
978
1404
|
return _Noise._n4d(x, y, z, w);
|
|
979
1405
|
}
|
|
@@ -1057,7 +1483,7 @@ var Color = class _Color {
|
|
|
1057
1483
|
[this._r, this._g, this._b, this._a] = this._parse_hex_color_string(value);
|
|
1058
1484
|
this._hex = value;
|
|
1059
1485
|
} else {
|
|
1060
|
-
|
|
1486
|
+
logger_default(`Color: invalid color string: ${value}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Keeping the current color.`);
|
|
1061
1487
|
}
|
|
1062
1488
|
}
|
|
1063
1489
|
get rgba() {
|
|
@@ -1068,7 +1494,7 @@ var Color = class _Color {
|
|
|
1068
1494
|
if (r.startsWith("#")) {
|
|
1069
1495
|
[r, g, b, a] = this._parse_hex_color_string(r);
|
|
1070
1496
|
} else {
|
|
1071
|
-
|
|
1497
|
+
logger_default(`Color: invalid color string: ${r}. Should be a hexadecimal color string (i.e.: '#ffffff' or '#ffffffff'). Defaulting to opaque white.`);
|
|
1072
1498
|
r = g = b = a = 255;
|
|
1073
1499
|
}
|
|
1074
1500
|
} else {
|
|
@@ -1169,7 +1595,7 @@ var Color = class _Color {
|
|
|
1169
1595
|
const [r, g, b, a] = rgba.map(Number);
|
|
1170
1596
|
return new _Color(r, g, b, a);
|
|
1171
1597
|
} else {
|
|
1172
|
-
|
|
1598
|
+
logger_default(`Color: invalid CSS color name: ${name}. Defaulting to transparent.`);
|
|
1173
1599
|
return _Color.TRANSPARENT;
|
|
1174
1600
|
}
|
|
1175
1601
|
}
|
|
@@ -1221,6 +1647,17 @@ var SpatialPartition2d = class {
|
|
|
1221
1647
|
};
|
|
1222
1648
|
|
|
1223
1649
|
// src/particle-system-2d.ts
|
|
1650
|
+
function randomMatrix(size) {
|
|
1651
|
+
const rows = [];
|
|
1652
|
+
for (let i = 0; i < size; i++) {
|
|
1653
|
+
const row = [];
|
|
1654
|
+
for (let j = 0; j < size; j++) {
|
|
1655
|
+
row.push(Random.float(i, j) * 2 - 1);
|
|
1656
|
+
}
|
|
1657
|
+
rows.push(row);
|
|
1658
|
+
}
|
|
1659
|
+
return rows;
|
|
1660
|
+
}
|
|
1224
1661
|
var colors = [
|
|
1225
1662
|
Color.RED,
|
|
1226
1663
|
Color.GREEN,
|
|
@@ -1234,14 +1671,14 @@ var ParticleSystem2d = class {
|
|
|
1234
1671
|
_frictionHalfLife = 0.04;
|
|
1235
1672
|
_range = 0.1;
|
|
1236
1673
|
_rangeFactor = 0.1;
|
|
1237
|
-
_attractionMatrix =
|
|
1674
|
+
_attractionMatrix = randomMatrix(colors.length);
|
|
1238
1675
|
_particles = [];
|
|
1239
1676
|
_spatialPartition;
|
|
1240
1677
|
constructor() {
|
|
1241
1678
|
for (let i = 0; i < this.particleCount; i++) {
|
|
1242
1679
|
this._particles.push({
|
|
1243
|
-
x:
|
|
1244
|
-
y:
|
|
1680
|
+
x: Random.float(i),
|
|
1681
|
+
y: Random.float(i + 1),
|
|
1245
1682
|
vx: 0,
|
|
1246
1683
|
vy: 0,
|
|
1247
1684
|
color: rng.range(colors.length)
|
|
@@ -1254,12 +1691,12 @@ var ParticleSystem2d = class {
|
|
|
1254
1691
|
if (r < beta) {
|
|
1255
1692
|
f = r / beta - 1;
|
|
1256
1693
|
} else if (beta < r && r < 1) {
|
|
1257
|
-
f = a * (1 -
|
|
1694
|
+
f = a * (1 - abs(2 * r - 1 - beta) / (1 - beta));
|
|
1258
1695
|
}
|
|
1259
1696
|
return f;
|
|
1260
1697
|
}
|
|
1261
1698
|
_updateVelocities(deltaTimeSeconds) {
|
|
1262
|
-
const frictionFactor =
|
|
1699
|
+
const frictionFactor = pow(
|
|
1263
1700
|
0.5,
|
|
1264
1701
|
deltaTimeSeconds / this._frictionHalfLife
|
|
1265
1702
|
);
|
|
@@ -1276,10 +1713,10 @@ var ParticleSystem2d = class {
|
|
|
1276
1713
|
if (cell === neighborCell && i === j) continue;
|
|
1277
1714
|
const p2 = neighborCell[j];
|
|
1278
1715
|
let rx = p2.x - p1.x;
|
|
1279
|
-
if (
|
|
1716
|
+
if (abs(rx) > 0.5) rx = rx > 0 ? rx - 1 : rx + 1;
|
|
1280
1717
|
let ry = p2.y - p1.y;
|
|
1281
|
-
if (
|
|
1282
|
-
const d =
|
|
1718
|
+
if (abs(ry) > 0.5) ry = ry > 0 ? ry - 1 : ry + 1;
|
|
1719
|
+
const d = hypot2(rx, ry);
|
|
1283
1720
|
if (d > 0 && d < this._range) {
|
|
1284
1721
|
const f = this._calcForce(
|
|
1285
1722
|
d / this._range,
|
|
@@ -1335,9 +1772,9 @@ var ParticleSystem2d = class {
|
|
|
1335
1772
|
// src/poisson-disk-sampler.ts
|
|
1336
1773
|
function PoissonDiskSampler(width, height, minDist, maxPoints = 30) {
|
|
1337
1774
|
const k = maxPoints;
|
|
1338
|
-
const cellSize = minDist /
|
|
1339
|
-
const gridWidth =
|
|
1340
|
-
const gridHeight =
|
|
1775
|
+
const cellSize = minDist / SQRT2;
|
|
1776
|
+
const gridWidth = ceil(width / cellSize);
|
|
1777
|
+
const gridHeight = ceil(height / cellSize);
|
|
1341
1778
|
const grid = Array.from(
|
|
1342
1779
|
{ length: gridWidth },
|
|
1343
1780
|
() => Array(gridHeight).fill(null)
|
|
@@ -1346,8 +1783,8 @@ function PoissonDiskSampler(width, height, minDist, maxPoints = 30) {
|
|
|
1346
1783
|
const active = [];
|
|
1347
1784
|
function gridIndex(p) {
|
|
1348
1785
|
return {
|
|
1349
|
-
i:
|
|
1350
|
-
j:
|
|
1786
|
+
i: floor(p.x / cellSize),
|
|
1787
|
+
j: floor(p.y / cellSize)
|
|
1351
1788
|
};
|
|
1352
1789
|
}
|
|
1353
1790
|
function isFarEnough(p) {
|
|
@@ -1375,15 +1812,15 @@ function PoissonDiskSampler(width, height, minDist, maxPoints = 30) {
|
|
|
1375
1812
|
samples.push(initial);
|
|
1376
1813
|
active.push(initial);
|
|
1377
1814
|
while (active.length) {
|
|
1378
|
-
const index =
|
|
1815
|
+
const index = floor(rng.range(0, active.length));
|
|
1379
1816
|
const point = active[index];
|
|
1380
1817
|
let found = false;
|
|
1381
1818
|
for (let n = 0; n < k; n++) {
|
|
1382
|
-
const angle = rng.range(0,
|
|
1819
|
+
const angle = rng.range(0, PI * 2);
|
|
1383
1820
|
const dist = rng.range(minDist, 2 * minDist);
|
|
1384
1821
|
const newPoint = {
|
|
1385
|
-
x: point.x +
|
|
1386
|
-
y: point.y +
|
|
1822
|
+
x: point.x + cos(angle) * dist,
|
|
1823
|
+
y: point.y + sin(angle) * dist
|
|
1387
1824
|
};
|
|
1388
1825
|
if (newPoint.x >= 0 && newPoint.y >= 0 && newPoint.x < width && newPoint.y < height && isFarEnough(newPoint)) {
|
|
1389
1826
|
const { i, j } = gridIndex(newPoint);
|
|
@@ -1402,71 +1839,86 @@ function PoissonDiskSampler(width, height, minDist, maxPoints = 30) {
|
|
|
1402
1839
|
}
|
|
1403
1840
|
|
|
1404
1841
|
// src/rendering/canvas-renderer.ts
|
|
1842
|
+
var DEFAULT_COLOR = "white";
|
|
1843
|
+
var DEFAULT_PIXEL_SIZE = 1;
|
|
1844
|
+
var DEFAULT_FONT = "18px monospace";
|
|
1845
|
+
var DEFAULT_TEXTALIGN = "left";
|
|
1846
|
+
var DEFAULT_TEXTBASELINE = "alphabetic";
|
|
1405
1847
|
var CanvasRenderer = class {
|
|
1406
|
-
canvas;
|
|
1407
1848
|
context;
|
|
1408
|
-
|
|
1849
|
+
get canvas() {
|
|
1850
|
+
return this.context.canvas;
|
|
1851
|
+
}
|
|
1409
1852
|
get width() {
|
|
1410
|
-
return this.
|
|
1853
|
+
return this.canvas.width;
|
|
1411
1854
|
}
|
|
1412
1855
|
get height() {
|
|
1413
|
-
return this.
|
|
1856
|
+
return this.canvas.height;
|
|
1414
1857
|
}
|
|
1415
1858
|
constructor(canvas) {
|
|
1416
|
-
this.
|
|
1417
|
-
this.context =
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
if (this.canvas.parentNode) {
|
|
1421
|
-
this.canvas.parentNode.removeChild(this.canvas);
|
|
1422
|
-
}
|
|
1423
|
-
target.appendChild(this.canvas);
|
|
1859
|
+
this.context = (canvas ?? document.createElement("canvas")).getContext("2d");
|
|
1860
|
+
this.context.font = DEFAULT_FONT;
|
|
1861
|
+
this.context.textAlign = DEFAULT_TEXTALIGN;
|
|
1862
|
+
this.context.textBaseline = DEFAULT_TEXTBASELINE;
|
|
1424
1863
|
}
|
|
1425
|
-
resize(
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
if (this.canvas.width
|
|
1430
|
-
this.canvas.width =
|
|
1431
|
-
this.canvas.height =
|
|
1432
|
-
|
|
1864
|
+
resize(width, height) {
|
|
1865
|
+
let resized = false;
|
|
1866
|
+
width = width ?? this.canvas.parentElement?.clientWidth ?? this.width;
|
|
1867
|
+
height = height ?? this.canvas.parentElement?.clientHeight ?? this.height;
|
|
1868
|
+
if (this.canvas.width != width || this.canvas.height != height) {
|
|
1869
|
+
this.canvas.width = width;
|
|
1870
|
+
this.canvas.height = height;
|
|
1871
|
+
resized = true;
|
|
1433
1872
|
}
|
|
1434
|
-
return
|
|
1873
|
+
return resized;
|
|
1435
1874
|
}
|
|
1436
1875
|
clear() {
|
|
1437
1876
|
this.context.clearRect(0, 0, this.width, this.height);
|
|
1438
1877
|
}
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1878
|
+
drawPath(buildPath, params = {}) {
|
|
1879
|
+
this.context.fillStyle = params.color ?? DEFAULT_COLOR;
|
|
1880
|
+
this.context.strokeStyle = params.color ?? DEFAULT_COLOR;
|
|
1881
|
+
this.context.lineWidth = params.size ?? 1;
|
|
1882
|
+
if (params.lineDash) {
|
|
1883
|
+
this.context.setLineDash(params.lineDash);
|
|
1884
|
+
}
|
|
1885
|
+
this.context.beginPath();
|
|
1886
|
+
buildPath();
|
|
1887
|
+
this.context.stroke();
|
|
1888
|
+
if (params.filled) {
|
|
1889
|
+
this.context.fill();
|
|
1890
|
+
}
|
|
1891
|
+
if (params.lineDash) {
|
|
1892
|
+
this.context.setLineDash([]);
|
|
1443
1893
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1894
|
+
}
|
|
1895
|
+
drawRect(x, y, width, height, params = {}) {
|
|
1896
|
+
x -= width / 2;
|
|
1897
|
+
y -= height / 2;
|
|
1898
|
+
this.context.fillStyle = params.color ?? DEFAULT_COLOR;
|
|
1899
|
+
this.context.strokeStyle = params.color ?? DEFAULT_COLOR;
|
|
1446
1900
|
this.context.lineWidth = params.size ?? 1;
|
|
1447
1901
|
if (params.lineDash) {
|
|
1448
1902
|
this.context.setLineDash(params.lineDash);
|
|
1449
1903
|
}
|
|
1450
1904
|
this.context.beginPath();
|
|
1451
|
-
|
|
1905
|
+
this.context.strokeRect(x, y, width, height);
|
|
1906
|
+
if (params.filled) {
|
|
1452
1907
|
this.context.fillRect(x, y, width, height);
|
|
1453
|
-
if (params.strokeColor !== void 0) this.context.strokeRect(x, y, width, height);
|
|
1454
|
-
} else {
|
|
1455
|
-
this.context.strokeRect(x, y, width, height);
|
|
1456
1908
|
}
|
|
1457
1909
|
if (params.lineDash) {
|
|
1458
1910
|
this.context.setLineDash([]);
|
|
1459
1911
|
}
|
|
1460
1912
|
}
|
|
1461
1913
|
drawPixel(x, y, params = {}) {
|
|
1462
|
-
const size = abs(params.size ||
|
|
1914
|
+
const size = abs(params.size || DEFAULT_PIXEL_SIZE);
|
|
1463
1915
|
this.drawRect(x, y, size, size, {
|
|
1464
1916
|
...params,
|
|
1465
1917
|
filled: true
|
|
1466
1918
|
});
|
|
1467
1919
|
}
|
|
1468
1920
|
drawLine(x1, y1, x2, y2, params = {}) {
|
|
1469
|
-
this.context.strokeStyle = params.color ??
|
|
1921
|
+
this.context.strokeStyle = params.color ?? DEFAULT_COLOR;
|
|
1470
1922
|
this.context.lineWidth = params.size ?? 1;
|
|
1471
1923
|
if (params.lineDash) {
|
|
1472
1924
|
this.context.setLineDash(params.lineDash);
|
|
@@ -1480,27 +1932,49 @@ var CanvasRenderer = class {
|
|
|
1480
1932
|
}
|
|
1481
1933
|
}
|
|
1482
1934
|
drawCircle(x, y, radius, params = {}) {
|
|
1483
|
-
this.
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
this.
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1935
|
+
this.drawPath(() => {
|
|
1936
|
+
this.context.arc(x, y, radius, 0, TAU);
|
|
1937
|
+
}, params);
|
|
1938
|
+
}
|
|
1939
|
+
drawPolygon(x, y, radius, sides, params = {}) {
|
|
1940
|
+
sides = floor(clamp(sides, 3, 36));
|
|
1941
|
+
this.drawPath(() => {
|
|
1942
|
+
for (let i = 0; i < sides; i++) {
|
|
1943
|
+
const angle = i / sides * TAU - PI / 2;
|
|
1944
|
+
const px = x + cos(angle) * radius;
|
|
1945
|
+
const py = y + sin(angle) * radius;
|
|
1946
|
+
if (i === 0) {
|
|
1947
|
+
this.context.moveTo(px, py);
|
|
1948
|
+
} else {
|
|
1949
|
+
this.context.lineTo(px, py);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
this.context.closePath();
|
|
1953
|
+
}, params);
|
|
1496
1954
|
}
|
|
1497
1955
|
drawText(x, y, text, params = {}) {
|
|
1498
|
-
this.context.
|
|
1499
|
-
this.context.textAlign = params.textAlign ?? "left";
|
|
1500
|
-
this.context.textBaseline = params.textBaseline ?? "alphabetic";
|
|
1501
|
-
this.context.fillStyle = params.color ?? "white";
|
|
1956
|
+
this.context.fillStyle = params.color ?? DEFAULT_COLOR;
|
|
1502
1957
|
this.context.fillText(text, x, y);
|
|
1503
1958
|
}
|
|
1959
|
+
drawSprite(x, y, image, width, height, params = {}) {
|
|
1960
|
+
x -= width / 2;
|
|
1961
|
+
y -= height / 2;
|
|
1962
|
+
if (params.sourceWidth !== void 0 && params.sourceHeight !== void 0) {
|
|
1963
|
+
this.context.drawImage(
|
|
1964
|
+
image,
|
|
1965
|
+
params.sourceX ?? 0,
|
|
1966
|
+
params.sourceY ?? 0,
|
|
1967
|
+
params.sourceWidth,
|
|
1968
|
+
params.sourceHeight,
|
|
1969
|
+
x,
|
|
1970
|
+
y,
|
|
1971
|
+
width,
|
|
1972
|
+
height
|
|
1973
|
+
);
|
|
1974
|
+
} else {
|
|
1975
|
+
this.context.drawImage(image, x, y, width, height);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1504
1978
|
};
|
|
1505
1979
|
|
|
1506
1980
|
// src/rendering/particle-renderer.ts
|
|
@@ -1732,6 +2206,7 @@ var AtlasTextureMaterial = class _AtlasTextureMaterial extends MeshLambertMateri
|
|
|
1732
2206
|
};
|
|
1733
2207
|
|
|
1734
2208
|
// src/rendering/three/threejs-boiler-plate.ts
|
|
2209
|
+
init_main();
|
|
1735
2210
|
import { AmbientLight, BoxGeometry as BoxGeometry2, DirectionalLight, GridHelper, Mesh, MeshLambertMaterial as MeshLambertMaterial2, PlaneGeometry, Raycaster, Scene, Vector2, WebGLRenderer } from "three";
|
|
1736
2211
|
|
|
1737
2212
|
// src/rendering/three/threejs-camera-rig.ts
|
|
@@ -1744,8 +2219,8 @@ var ThreeJsCameraRig = class extends Group {
|
|
|
1744
2219
|
wheelSensitivity = 0.02;
|
|
1745
2220
|
minCameraDistance = 2;
|
|
1746
2221
|
maxCameraDistance = 100;
|
|
1747
|
-
minTiltAngle =
|
|
1748
|
-
maxTiltAngle =
|
|
2222
|
+
minTiltAngle = degrees(-90);
|
|
2223
|
+
maxTiltAngle = degrees(0);
|
|
1749
2224
|
clampTiltAngle = false;
|
|
1750
2225
|
constructor(params) {
|
|
1751
2226
|
super();
|
|
@@ -1780,7 +2255,7 @@ var ThreeJsCameraRig = class extends Group {
|
|
|
1780
2255
|
var ThreeJsBoilerPlate = class {
|
|
1781
2256
|
clock = new Clock();
|
|
1782
2257
|
scene = new Scene();
|
|
1783
|
-
input =
|
|
2258
|
+
input = Input.instance;
|
|
1784
2259
|
raycaster = new Raycaster();
|
|
1785
2260
|
renderer;
|
|
1786
2261
|
cameraRig;
|
|
@@ -1804,11 +2279,12 @@ var ThreeJsBoilerPlate = class {
|
|
|
1804
2279
|
enableCameraRigControls() {
|
|
1805
2280
|
this.orbitControls?.dispose();
|
|
1806
2281
|
this.orbitControls = void 0;
|
|
1807
|
-
this.input.
|
|
2282
|
+
this.input.onPointerMove.subscribe((_, ev) => {
|
|
1808
2283
|
if (this.input.isDown("Button0")) {
|
|
1809
|
-
this.cameraRig.orbit(
|
|
2284
|
+
this.cameraRig.orbit(ev.movementX, ev.movementY);
|
|
1810
2285
|
}
|
|
1811
|
-
})
|
|
2286
|
+
});
|
|
2287
|
+
this.input.onWheel.subscribe((_, ev) => this.cameraRig.dolly(ev.deltaY));
|
|
1812
2288
|
}
|
|
1813
2289
|
async enableOrbitControls() {
|
|
1814
2290
|
const { OrbitControls } = await import("three/examples/jsm/Addons.js");
|
|
@@ -2357,16 +2833,16 @@ var ParticleSystem3d = class extends Group3 {
|
|
|
2357
2833
|
this.add(pointsMesh);
|
|
2358
2834
|
for (let i = 0; i < this.particleCount; i++) {
|
|
2359
2835
|
this._particles.push({
|
|
2360
|
-
x: rng.
|
|
2361
|
-
y: rng.
|
|
2362
|
-
z: rng.
|
|
2836
|
+
x: rng.nextFloat(),
|
|
2837
|
+
y: rng.nextFloat(),
|
|
2838
|
+
z: rng.nextFloat(),
|
|
2363
2839
|
vx: 0,
|
|
2364
2840
|
vy: 0,
|
|
2365
2841
|
vz: 0,
|
|
2366
2842
|
color: rng.range(Colors2.length)
|
|
2367
2843
|
});
|
|
2368
2844
|
}
|
|
2369
|
-
this._attractionMatrix =
|
|
2845
|
+
this._attractionMatrix = randomMatrix(Colors2.length);
|
|
2370
2846
|
this._spatialPartition = new SpatialPartition3d(this._range, this._particles);
|
|
2371
2847
|
}
|
|
2372
2848
|
_calcForce(r, a, beta = 0.3) {
|
|
@@ -2496,8 +2972,8 @@ var AsteroidMesh = class extends Mesh3 {
|
|
|
2496
2972
|
const geometry = new IcosahedronGeometry(radius, detail);
|
|
2497
2973
|
const material = new MeshStandardMaterial2({ color });
|
|
2498
2974
|
super(geometry, material);
|
|
2499
|
-
const noise3d = createNoise3D2(
|
|
2500
|
-
const noise3d2 = secondaryNoise ? createNoise3D2(
|
|
2975
|
+
const noise3d = createNoise3D2(rng.rng.float);
|
|
2976
|
+
const noise3d2 = secondaryNoise ? createNoise3D2(rng.rng.float) : null;
|
|
2501
2977
|
const position = this.geometry.attributes.position;
|
|
2502
2978
|
const vertices = position.array;
|
|
2503
2979
|
for (let i = 0; i < vertices.length; i += 3) {
|
|
@@ -2523,8 +2999,8 @@ function CreateStarfield(radius = 1e3, count = 5e3, color = 16777215) {
|
|
|
2523
2999
|
const geometry = new BufferGeometry3();
|
|
2524
3000
|
const positions = new Float32Array(count * 3);
|
|
2525
3001
|
for (let i = 0; i < count; i++) {
|
|
2526
|
-
const theta = rng.
|
|
2527
|
-
const phi = Math.acos(rng.
|
|
3002
|
+
const theta = rng.nextFloat() * Math.PI * 2;
|
|
3003
|
+
const phi = Math.acos(rng.nextFloat() * 2 - 1);
|
|
2528
3004
|
const x = radius * Math.sin(phi) * Math.cos(theta);
|
|
2529
3005
|
const y = radius * Math.sin(phi) * Math.sin(theta);
|
|
2530
3006
|
const z = radius * Math.cos(phi);
|
|
@@ -2802,6 +3278,30 @@ var WebGlRenderer = class {
|
|
|
2802
3278
|
}
|
|
2803
3279
|
};
|
|
2804
3280
|
|
|
3281
|
+
// src/signal.ts
|
|
3282
|
+
var Signal = class {
|
|
3283
|
+
value;
|
|
3284
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
3285
|
+
constructor(initialValue) {
|
|
3286
|
+
this.value = initialValue;
|
|
3287
|
+
}
|
|
3288
|
+
get() {
|
|
3289
|
+
return this.value;
|
|
3290
|
+
}
|
|
3291
|
+
set(value) {
|
|
3292
|
+
if (Object.is(this.value, value)) return;
|
|
3293
|
+
this.value = value;
|
|
3294
|
+
for (const subscriber of [...this.subscribers]) {
|
|
3295
|
+
subscriber(value);
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
subscribe(subscriber) {
|
|
3299
|
+
this.subscribers.add(subscriber);
|
|
3300
|
+
subscriber(this.value);
|
|
3301
|
+
return () => this.subscribers.delete(subscriber);
|
|
3302
|
+
}
|
|
3303
|
+
};
|
|
3304
|
+
|
|
2805
3305
|
// src/simplex-noise.ts
|
|
2806
3306
|
var SimplexNoise = class {
|
|
2807
3307
|
grad3;
|
|
@@ -2824,7 +3324,7 @@ var SimplexNoise = class {
|
|
|
2824
3324
|
];
|
|
2825
3325
|
this.p = [];
|
|
2826
3326
|
for (let i = 0; i < 256; i++) {
|
|
2827
|
-
this.p.push(Math.floor(rng.
|
|
3327
|
+
this.p.push(Math.floor(rng.nextFloat() * 256));
|
|
2828
3328
|
}
|
|
2829
3329
|
this.perm = [];
|
|
2830
3330
|
for (let i = 0; i < 512; i++) {
|
|
@@ -3015,13 +3515,14 @@ var Tilemap = class {
|
|
|
3015
3515
|
};
|
|
3016
3516
|
|
|
3017
3517
|
// src/worker-interface.ts
|
|
3018
|
-
var WorkerInterface = class
|
|
3518
|
+
var WorkerInterface = class {
|
|
3019
3519
|
_worker;
|
|
3520
|
+
onError = new Observable();
|
|
3521
|
+
onMessage = new Observable();
|
|
3020
3522
|
constructor(url) {
|
|
3021
|
-
super();
|
|
3022
3523
|
this._worker = new Worker(url, { type: "module" });
|
|
3023
|
-
this._worker.onerror = (error) => this.
|
|
3024
|
-
this._worker.onmessage = (message) => this.
|
|
3524
|
+
this._worker.onerror = (error) => this.onError.notify(this, error);
|
|
3525
|
+
this._worker.onmessage = (message) => this.onMessage.notify(this, message);
|
|
3025
3526
|
}
|
|
3026
3527
|
postMessage(message, options) {
|
|
3027
3528
|
this._worker.postMessage(message, options);
|
|
@@ -3050,9 +3551,18 @@ export {
|
|
|
3050
3551
|
CreateThreeEntity,
|
|
3051
3552
|
CreateWebGlContext,
|
|
3052
3553
|
CubeSphereGeometry,
|
|
3053
|
-
|
|
3554
|
+
DEFAULT_COLOR,
|
|
3555
|
+
DEFAULT_FONT,
|
|
3556
|
+
DEFAULT_PIXEL_SIZE,
|
|
3557
|
+
DEFAULT_TEXTALIGN,
|
|
3558
|
+
DEFAULT_TEXTBASELINE,
|
|
3559
|
+
DEG2RAD,
|
|
3560
|
+
DOWN,
|
|
3561
|
+
Disposable,
|
|
3562
|
+
E,
|
|
3054
3563
|
ECS,
|
|
3055
|
-
|
|
3564
|
+
EPSILON,
|
|
3565
|
+
EventQueue,
|
|
3056
3566
|
GenerateDoors,
|
|
3057
3567
|
GenerateEntityId,
|
|
3058
3568
|
GenerateRooms,
|
|
@@ -3063,24 +3573,35 @@ export {
|
|
|
3063
3573
|
HALF_PI,
|
|
3064
3574
|
Input,
|
|
3065
3575
|
IsThreeEntity,
|
|
3576
|
+
LN10,
|
|
3577
|
+
LN2,
|
|
3578
|
+
LOG10E,
|
|
3579
|
+
LOG2E,
|
|
3066
3580
|
LoadTexture,
|
|
3067
3581
|
Map2D,
|
|
3068
3582
|
Map3D,
|
|
3069
3583
|
Noise,
|
|
3584
|
+
Observable,
|
|
3070
3585
|
PI,
|
|
3071
3586
|
ParticleRenderer,
|
|
3072
3587
|
ParticleSystem2d,
|
|
3073
3588
|
ParticleSystem3d,
|
|
3074
3589
|
PoissonDiskSampler,
|
|
3075
|
-
|
|
3076
|
-
|
|
3590
|
+
QUARTER_PI,
|
|
3591
|
+
RAD2DEG,
|
|
3592
|
+
Random,
|
|
3593
|
+
RandomTools,
|
|
3077
3594
|
Rectangle,
|
|
3078
3595
|
RemoveThreeComponent,
|
|
3079
3596
|
ResizeWebGlContext,
|
|
3597
|
+
SQRT1_2,
|
|
3598
|
+
SQRT2,
|
|
3080
3599
|
ShaderType,
|
|
3600
|
+
Signal,
|
|
3081
3601
|
SimplexNoise,
|
|
3082
3602
|
SpatialPartition2d,
|
|
3083
3603
|
SpatialPartition3d,
|
|
3604
|
+
TAU,
|
|
3084
3605
|
TILE_EMPTY,
|
|
3085
3606
|
TILE_FLOOR,
|
|
3086
3607
|
TILE_PATH,
|
|
@@ -3089,39 +3610,71 @@ export {
|
|
|
3089
3610
|
ThreeJsCameraRig,
|
|
3090
3611
|
ThreeJsPlayerController,
|
|
3091
3612
|
Tilemap,
|
|
3613
|
+
UP,
|
|
3092
3614
|
Vector,
|
|
3093
3615
|
VoxelFaces,
|
|
3094
3616
|
VoxelMesh,
|
|
3095
3617
|
WebGlRenderer,
|
|
3096
3618
|
WorkerInterface,
|
|
3097
3619
|
abs,
|
|
3620
|
+
acos,
|
|
3621
|
+
asin,
|
|
3622
|
+
atan,
|
|
3623
|
+
atan2,
|
|
3624
|
+
cbrt,
|
|
3098
3625
|
ceil,
|
|
3099
3626
|
clamp,
|
|
3100
3627
|
cos,
|
|
3101
|
-
|
|
3628
|
+
cosh,
|
|
3629
|
+
degrees,
|
|
3102
3630
|
distance2d,
|
|
3103
3631
|
distance3d,
|
|
3632
|
+
exp,
|
|
3633
|
+
expm1,
|
|
3104
3634
|
floor,
|
|
3635
|
+
fract,
|
|
3105
3636
|
getRedYellowGreenGradientHex,
|
|
3637
|
+
hypot,
|
|
3106
3638
|
hypot2,
|
|
3107
3639
|
hypot3,
|
|
3108
3640
|
imul,
|
|
3641
|
+
inverseLerp,
|
|
3642
|
+
isFinite,
|
|
3643
|
+
isInteger,
|
|
3644
|
+
isNaN,
|
|
3109
3645
|
isNullOrUndefined,
|
|
3110
3646
|
isPositiveString,
|
|
3111
3647
|
k2xy,
|
|
3112
3648
|
k2xyz,
|
|
3113
3649
|
lerp,
|
|
3114
3650
|
log,
|
|
3651
|
+
log10,
|
|
3652
|
+
log1p,
|
|
3653
|
+
log2,
|
|
3115
3654
|
manhattanDistance,
|
|
3655
|
+
map,
|
|
3116
3656
|
max,
|
|
3117
3657
|
min,
|
|
3658
|
+
mod,
|
|
3659
|
+
nearlyEqual,
|
|
3660
|
+
normalizeRadians,
|
|
3118
3661
|
pow,
|
|
3662
|
+
radians,
|
|
3663
|
+
randomMatrix,
|
|
3119
3664
|
rng,
|
|
3120
3665
|
round,
|
|
3121
3666
|
roundTo,
|
|
3667
|
+
saturate,
|
|
3668
|
+
sign,
|
|
3122
3669
|
sin,
|
|
3670
|
+
sinh,
|
|
3671
|
+
smoothstep,
|
|
3123
3672
|
sqrt,
|
|
3124
3673
|
squaredDistance,
|
|
3674
|
+
tan,
|
|
3675
|
+
tanh,
|
|
3676
|
+
trunc,
|
|
3677
|
+
wrap,
|
|
3125
3678
|
xy2k,
|
|
3126
3679
|
xyz2k
|
|
3127
3680
|
};
|