@oliversalzburg/js-utils 0.0.28-dev.10 → 0.0.28-dev.11
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/graphics/canvas-sandbox-mp.d.ts +241 -0
- package/graphics/canvas-sandbox-mp.js +261 -0
- package/graphics/canvas-sandbox-mp.js.map +1 -0
- package/graphics/canvas-sandbox.d.ts +23 -1
- package/graphics/canvas-sandbox.js +1 -4
- package/graphics/canvas-sandbox.js.map +1 -1
- package/graphics/canvas3d.js +2 -0
- package/graphics/canvas3d.js.map +1 -1
- package/graphics/core.d.ts +0 -18
- package/graphics/core.js +0 -346
- package/graphics/core.js.map +1 -1
- package/graphics/index.d.ts +3 -0
- package/graphics/index.js +3 -0
- package/graphics/index.js.map +1 -1
- package/graphics/palette-sampler.d.ts +9 -0
- package/graphics/palette-sampler.js +24 -0
- package/graphics/palette-sampler.js.map +1 -0
- package/graphics/palette.d.ts +126 -0
- package/graphics/palette.js +475 -0
- package/graphics/palette.js.map +1 -0
- package/graphics/render-loop.js +9 -14
- package/graphics/render-loop.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/// <reference types="@types/web" />
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
+
import { ConstructorOf } from "../core.js";
|
|
5
|
+
import { Random } from "../random.js";
|
|
6
|
+
import { CanvasSandboxApplication, CanvasSandboxExpectedOptions } from "./canvas-sandbox.js";
|
|
7
|
+
import { Canvas } from "./canvas.js";
|
|
8
|
+
import { Canvas2DHeadless } from "./canvas2d-headless.js";
|
|
9
|
+
import { RenderLoop } from "./render-loop.js";
|
|
10
|
+
/**
|
|
11
|
+
* Sent from the host when a worker should reconfigure itself.
|
|
12
|
+
*/
|
|
13
|
+
export interface CanvasWorkerMessageReconfigure<TApplicationOptions extends CanvasSandboxExpectedOptions> {
|
|
14
|
+
/**
|
|
15
|
+
* Type identifier of this message.
|
|
16
|
+
*/
|
|
17
|
+
type: "reconfigure";
|
|
18
|
+
/**
|
|
19
|
+
* New ID for the worker.
|
|
20
|
+
*/
|
|
21
|
+
id: string;
|
|
22
|
+
/**
|
|
23
|
+
* New canvas for the worker to use.
|
|
24
|
+
*/
|
|
25
|
+
canvas: OffscreenCanvas;
|
|
26
|
+
/**
|
|
27
|
+
* New application options to use.
|
|
28
|
+
*/
|
|
29
|
+
options: TApplicationOptions;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sent from the host when a worker should start its rendering kernel.
|
|
33
|
+
*/
|
|
34
|
+
export interface CanvasWorkerMessageStart<TApplicationOptions extends CanvasSandboxExpectedOptions> {
|
|
35
|
+
/**
|
|
36
|
+
* Type identifier of this message.
|
|
37
|
+
*/
|
|
38
|
+
type: "start";
|
|
39
|
+
/**
|
|
40
|
+
* New application options to use before starting.
|
|
41
|
+
*/
|
|
42
|
+
options: TApplicationOptions;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sent from a worker when it finished rendering the current scene.
|
|
46
|
+
*/
|
|
47
|
+
export interface CanvasWorkerSceneFinishMessage {
|
|
48
|
+
/**
|
|
49
|
+
* Type identifier of this message.
|
|
50
|
+
*/
|
|
51
|
+
type: "sceneFinish";
|
|
52
|
+
/**
|
|
53
|
+
* Point in time when the scene finished rendering.
|
|
54
|
+
*/
|
|
55
|
+
timestamp: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The messages that are passed between the canvas sandbox host and its workers.
|
|
59
|
+
*/
|
|
60
|
+
export type CanvasWorkerMessage<TApplicationOptions extends CanvasSandboxExpectedOptions> = CanvasWorkerMessageReconfigure<TApplicationOptions> | CanvasWorkerMessageStart<TApplicationOptions> | CanvasWorkerSceneFinishMessage;
|
|
61
|
+
/**
|
|
62
|
+
* The canvas worker handles a web worker instance in the canvas sandbox host.
|
|
63
|
+
*
|
|
64
|
+
* It provides a thin abstraction over the web worker IPC messaging.
|
|
65
|
+
*/
|
|
66
|
+
export declare class CanvasWorker<TApplicationOptions extends CanvasSandboxExpectedOptions> extends EventTarget {
|
|
67
|
+
/**
|
|
68
|
+
* The ID of this worker.
|
|
69
|
+
*/
|
|
70
|
+
id: string;
|
|
71
|
+
/**
|
|
72
|
+
* The canvas element that this worker should handle.
|
|
73
|
+
*/
|
|
74
|
+
canvas: HTMLCanvasElement | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* The offscreen canvas that we created for this worker.
|
|
77
|
+
*/
|
|
78
|
+
canvasOffscreen: OffscreenCanvas | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* The application options for the worker.
|
|
81
|
+
*
|
|
82
|
+
* These are usually very similar, if not identical, to the host application options.
|
|
83
|
+
* Workers just usually get a different viewport assigned to them, correlating with the
|
|
84
|
+
* canvas element in the DOM that they draw to.
|
|
85
|
+
*/
|
|
86
|
+
readonly options: TApplicationOptions;
|
|
87
|
+
/**
|
|
88
|
+
* The web worker instance itself.
|
|
89
|
+
*/
|
|
90
|
+
readonly workerInstance: Worker;
|
|
91
|
+
/**
|
|
92
|
+
* Constructs a new canvas worker.
|
|
93
|
+
* @param id - The ID of the worker.
|
|
94
|
+
* @param source - The code that the worker should run. It's common to use a hybrid code module
|
|
95
|
+
* for as the sandbox application. This means the code of the host and the workers is identical,
|
|
96
|
+
* they just construct different code path on load/init. In such case, the source can simply be
|
|
97
|
+
* `new URL(import.meta.url)`.
|
|
98
|
+
* @param canvas - The canvas element to draw to.
|
|
99
|
+
* @param options - The application options.
|
|
100
|
+
*/
|
|
101
|
+
constructor(id: string, source: URL, canvas: HTMLCanvasElement, options: TApplicationOptions);
|
|
102
|
+
/**
|
|
103
|
+
* Posts a message to the worker.
|
|
104
|
+
*
|
|
105
|
+
* As messages to workers are _posted_ instead of _sent_, there is no delivery feedback.
|
|
106
|
+
* @param message - The message to post.
|
|
107
|
+
* @param transfer - The transferables to transfer to the worker with this message.
|
|
108
|
+
*/
|
|
109
|
+
postMessage(message: CanvasWorkerMessage<TApplicationOptions>, transfer?: Array<Transferable>): void;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The canvas worker instance handles a web worker instance in worker instance itself, and
|
|
113
|
+
* handles a feedback channel to the host application.
|
|
114
|
+
*
|
|
115
|
+
* It provides a thin abstraction over the web worker IPC messaging.
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* // Construct inside of worker from global scope and rendering kernel class.
|
|
119
|
+
* const worker = new CanvasWorkerInstance(self, RenderKernel);
|
|
120
|
+
* // Listen to custom events (messages) you send from the host.
|
|
121
|
+
* worker.addEventListener("fade", () => worker.renderKernel?.fadeOut());
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare class CanvasWorkerInstance<TCanvas extends Canvas2DHeadless, TApplicationOptions extends CanvasSandboxExpectedOptions, TKernel extends CanvasSandboxApplication<TCanvas, TApplicationOptions>> extends EventTarget {
|
|
125
|
+
#private;
|
|
126
|
+
/**
|
|
127
|
+
* The global scope of the worker.
|
|
128
|
+
*/
|
|
129
|
+
readonly self: typeof globalThis;
|
|
130
|
+
/**
|
|
131
|
+
* The ID of the worker.
|
|
132
|
+
*/
|
|
133
|
+
id: string;
|
|
134
|
+
/**
|
|
135
|
+
* The rendering kernel, which produces frames, and renders them to our
|
|
136
|
+
* offscreen canvas.
|
|
137
|
+
*/
|
|
138
|
+
renderKernel: TKernel | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* The canvas element we're presenting to.
|
|
141
|
+
*/
|
|
142
|
+
canvas: TCanvas | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* The offscreen canvas we're rendering to.
|
|
145
|
+
*/
|
|
146
|
+
offscreenCanvas: OffscreenCanvas | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Our rendering context to draw to.
|
|
149
|
+
*/
|
|
150
|
+
offscreenContext: OffscreenCanvasRenderingContext2D | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* Manages frame rendering timing.
|
|
153
|
+
*/
|
|
154
|
+
renderLoop: RenderLoop | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Constructs a new canvas worker instance.
|
|
157
|
+
*
|
|
158
|
+
* Note that many properties are only initialized after the host sent an
|
|
159
|
+
* initialization message.
|
|
160
|
+
* @param self - Our global worker scope.
|
|
161
|
+
* @param Kernel - The rendering kernel class to construct.
|
|
162
|
+
*/
|
|
163
|
+
constructor(self: typeof globalThis, Kernel: ConstructorOf<TKernel>);
|
|
164
|
+
/**
|
|
165
|
+
* Render a frame.
|
|
166
|
+
* @param delta - How many milliseconds have passed since the last invocation?
|
|
167
|
+
*/
|
|
168
|
+
render: (delta: number) => void;
|
|
169
|
+
/**
|
|
170
|
+
* Reconfigure the worker.
|
|
171
|
+
* @param id - New ID for this worker.
|
|
172
|
+
* @param canvas - New canvas to render to.
|
|
173
|
+
* @param options - New application options.
|
|
174
|
+
*/
|
|
175
|
+
reconfigure(id: string, canvas: OffscreenCanvas, options: TApplicationOptions): void;
|
|
176
|
+
/**
|
|
177
|
+
* Start rendering.
|
|
178
|
+
* @param options - New application options.
|
|
179
|
+
*/
|
|
180
|
+
start(options: TApplicationOptions): void;
|
|
181
|
+
/**
|
|
182
|
+
* Posts a message to the host.
|
|
183
|
+
* @param message - The message to post.
|
|
184
|
+
*/
|
|
185
|
+
postMessage(message: CanvasWorkerMessage<TApplicationOptions>): void;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Base class for multi-process canvas sandbox applications.
|
|
189
|
+
*
|
|
190
|
+
* Helps in orchestrating the workers.
|
|
191
|
+
*/
|
|
192
|
+
export declare abstract class CanvasSandboxHostApplication<TCanvas extends Canvas, TApplicationOptions extends CanvasSandboxExpectedOptions> implements CanvasSandboxApplication<TCanvas, TApplicationOptions> {
|
|
193
|
+
/**
|
|
194
|
+
* Usually a hidden canvas that serves as a proxy for canvas sandbox events.
|
|
195
|
+
*/
|
|
196
|
+
canvas: TCanvas;
|
|
197
|
+
/**
|
|
198
|
+
* Application options.
|
|
199
|
+
*/
|
|
200
|
+
options: TApplicationOptions;
|
|
201
|
+
/**
|
|
202
|
+
* PRNG instance for the application.
|
|
203
|
+
*/
|
|
204
|
+
random: Random;
|
|
205
|
+
/**
|
|
206
|
+
* Is the application running right now?
|
|
207
|
+
*/
|
|
208
|
+
paused: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Web worker instances.
|
|
211
|
+
*/
|
|
212
|
+
readonly workers: CanvasWorker<TApplicationOptions>[];
|
|
213
|
+
/**
|
|
214
|
+
* Construct a new host application.
|
|
215
|
+
* @param canvas - Usually a hidden canvas in the DOM to serve as an event proxy.
|
|
216
|
+
* @param options - Application options.
|
|
217
|
+
*/
|
|
218
|
+
constructor(canvas: TCanvas, options: TApplicationOptions);
|
|
219
|
+
/**
|
|
220
|
+
* Reconfigure the application with the given options and restart it.
|
|
221
|
+
* @param canvas - The canvas to use.
|
|
222
|
+
* @param options - The new options to use.
|
|
223
|
+
*/
|
|
224
|
+
abstract reconfigure(canvas: TCanvas, options?: Partial<TApplicationOptions>): void;
|
|
225
|
+
/**
|
|
226
|
+
* Request the application to draw a new frame.
|
|
227
|
+
* This call has no effect in a host application, as all rendering happens in the workers.
|
|
228
|
+
* @param _delta - How many milliseconds passed since the last frame draw.
|
|
229
|
+
* @param _timestamp - The current timestamp.
|
|
230
|
+
*/
|
|
231
|
+
onDraw(_delta: number, _timestamp: number): void;
|
|
232
|
+
/**
|
|
233
|
+
* Start the application.
|
|
234
|
+
*/
|
|
235
|
+
start(): void;
|
|
236
|
+
/**
|
|
237
|
+
* Posts a message to all workers.
|
|
238
|
+
* @param message - Message to post to all workers.
|
|
239
|
+
*/
|
|
240
|
+
postMessageAll(message: CanvasWorkerMessage<TApplicationOptions>): void;
|
|
241
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { isNil, mustExist } from "../nil.js";
|
|
2
|
+
import { Random } from "../random.js";
|
|
3
|
+
import { Canvas2DHeadless } from "./canvas2d-headless.js";
|
|
4
|
+
import { RenderLoop } from "./render-loop.js";
|
|
5
|
+
/**
|
|
6
|
+
* The canvas worker handles a web worker instance in the canvas sandbox host.
|
|
7
|
+
*
|
|
8
|
+
* It provides a thin abstraction over the web worker IPC messaging.
|
|
9
|
+
*/
|
|
10
|
+
export class CanvasWorker extends EventTarget {
|
|
11
|
+
/**
|
|
12
|
+
* The ID of this worker.
|
|
13
|
+
*/
|
|
14
|
+
id;
|
|
15
|
+
/**
|
|
16
|
+
* The canvas element that this worker should handle.
|
|
17
|
+
*/
|
|
18
|
+
canvas;
|
|
19
|
+
/**
|
|
20
|
+
* The offscreen canvas that we created for this worker.
|
|
21
|
+
*/
|
|
22
|
+
canvasOffscreen;
|
|
23
|
+
/**
|
|
24
|
+
* The application options for the worker.
|
|
25
|
+
*
|
|
26
|
+
* These are usually very similar, if not identical, to the host application options.
|
|
27
|
+
* Workers just usually get a different viewport assigned to them, correlating with the
|
|
28
|
+
* canvas element in the DOM that they draw to.
|
|
29
|
+
*/
|
|
30
|
+
options;
|
|
31
|
+
/**
|
|
32
|
+
* The web worker instance itself.
|
|
33
|
+
*/
|
|
34
|
+
workerInstance;
|
|
35
|
+
/**
|
|
36
|
+
* Constructs a new canvas worker.
|
|
37
|
+
* @param id - The ID of the worker.
|
|
38
|
+
* @param source - The code that the worker should run. It's common to use a hybrid code module
|
|
39
|
+
* for as the sandbox application. This means the code of the host and the workers is identical,
|
|
40
|
+
* they just construct different code path on load/init. In such case, the source can simply be
|
|
41
|
+
* `new URL(import.meta.url)`.
|
|
42
|
+
* @param canvas - The canvas element to draw to.
|
|
43
|
+
* @param options - The application options.
|
|
44
|
+
*/
|
|
45
|
+
constructor(id, source, canvas, options) {
|
|
46
|
+
super();
|
|
47
|
+
this.id = id;
|
|
48
|
+
this.canvas = canvas;
|
|
49
|
+
this.options = options;
|
|
50
|
+
this.workerInstance = new Worker(source, {
|
|
51
|
+
type: "module",
|
|
52
|
+
});
|
|
53
|
+
this.workerInstance.onmessage = (message) => {
|
|
54
|
+
this.dispatchEvent(new CustomEvent(message.data.type));
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Posts a message to the worker.
|
|
59
|
+
*
|
|
60
|
+
* As messages to workers are _posted_ instead of _sent_, there is no delivery feedback.
|
|
61
|
+
* @param message - The message to post.
|
|
62
|
+
* @param transfer - The transferables to transfer to the worker with this message.
|
|
63
|
+
*/
|
|
64
|
+
postMessage(message, transfer) {
|
|
65
|
+
this.workerInstance.postMessage(message, transfer ?? []);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The canvas worker instance handles a web worker instance in worker instance itself, and
|
|
70
|
+
* handles a feedback channel to the host application.
|
|
71
|
+
*
|
|
72
|
+
* It provides a thin abstraction over the web worker IPC messaging.
|
|
73
|
+
*
|
|
74
|
+
* ```ts
|
|
75
|
+
* // Construct inside of worker from global scope and rendering kernel class.
|
|
76
|
+
* const worker = new CanvasWorkerInstance(self, RenderKernel);
|
|
77
|
+
* // Listen to custom events (messages) you send from the host.
|
|
78
|
+
* worker.addEventListener("fade", () => worker.renderKernel?.fadeOut());
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export class CanvasWorkerInstance extends EventTarget {
|
|
82
|
+
/**
|
|
83
|
+
* The global scope of the worker.
|
|
84
|
+
*/
|
|
85
|
+
self;
|
|
86
|
+
/**
|
|
87
|
+
* The ID of the worker.
|
|
88
|
+
*/
|
|
89
|
+
id;
|
|
90
|
+
/**
|
|
91
|
+
* The rendering kernel, which produces frames, and renders them to our
|
|
92
|
+
* offscreen canvas.
|
|
93
|
+
*/
|
|
94
|
+
renderKernel;
|
|
95
|
+
/**
|
|
96
|
+
* The canvas element we're presenting to.
|
|
97
|
+
*/
|
|
98
|
+
canvas;
|
|
99
|
+
/**
|
|
100
|
+
* The offscreen canvas we're rendering to.
|
|
101
|
+
*/
|
|
102
|
+
offscreenCanvas;
|
|
103
|
+
/**
|
|
104
|
+
* Our rendering context to draw to.
|
|
105
|
+
*/
|
|
106
|
+
offscreenContext;
|
|
107
|
+
/**
|
|
108
|
+
* Manages frame rendering timing.
|
|
109
|
+
*/
|
|
110
|
+
renderLoop;
|
|
111
|
+
/**
|
|
112
|
+
* Constructor of our rendering kernel.
|
|
113
|
+
*/
|
|
114
|
+
#Kernel;
|
|
115
|
+
/**
|
|
116
|
+
* Constructs a new canvas worker instance.
|
|
117
|
+
*
|
|
118
|
+
* Note that many properties are only initialized after the host sent an
|
|
119
|
+
* initialization message.
|
|
120
|
+
* @param self - Our global worker scope.
|
|
121
|
+
* @param Kernel - The rendering kernel class to construct.
|
|
122
|
+
*/
|
|
123
|
+
constructor(self, Kernel) {
|
|
124
|
+
super();
|
|
125
|
+
this.self = self;
|
|
126
|
+
this.id = "<unassigned>";
|
|
127
|
+
this.#Kernel = Kernel;
|
|
128
|
+
self.onmessage = (message) => {
|
|
129
|
+
if (message.data.type === "start") {
|
|
130
|
+
const startMessage = message.data;
|
|
131
|
+
this.start(startMessage.options);
|
|
132
|
+
}
|
|
133
|
+
else if (message.data.type === "reconfigure") {
|
|
134
|
+
const reconfigureMessage = message.data;
|
|
135
|
+
this.reconfigure(reconfigureMessage.id, reconfigureMessage.canvas, reconfigureMessage.options);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
this.dispatchEvent(new CustomEvent(message.data.type));
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Render a frame.
|
|
144
|
+
* @param delta - How many milliseconds have passed since the last invocation?
|
|
145
|
+
*/
|
|
146
|
+
render = (delta) => {
|
|
147
|
+
this.renderKernel?.onDraw(delta, new Date().valueOf());
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Reconfigure the worker.
|
|
151
|
+
* @param id - New ID for this worker.
|
|
152
|
+
* @param canvas - New canvas to render to.
|
|
153
|
+
* @param options - New application options.
|
|
154
|
+
*/
|
|
155
|
+
reconfigure(id, canvas, options) {
|
|
156
|
+
this.renderLoop?.block();
|
|
157
|
+
this.id = id;
|
|
158
|
+
this.offscreenCanvas = canvas;
|
|
159
|
+
this.offscreenContext = mustExist(this.offscreenCanvas.getContext("2d"));
|
|
160
|
+
this.canvas = new Canvas2DHeadless(this.offscreenCanvas, this.offscreenContext);
|
|
161
|
+
this.renderLoop = new RenderLoop(this.render, this.canvas);
|
|
162
|
+
if (isNil(this.renderKernel)) {
|
|
163
|
+
this.renderKernel = new this.#Kernel(this, canvas, options);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
this.renderKernel.reconfigure(this.canvas, options);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Start rendering.
|
|
171
|
+
* @param options - New application options.
|
|
172
|
+
*/
|
|
173
|
+
start(options) {
|
|
174
|
+
if (!this.renderKernel) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.renderKernel.random = new Random(options.seed);
|
|
178
|
+
this.renderKernel.start(options);
|
|
179
|
+
this.renderLoop?.unblock();
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Posts a message to the host.
|
|
183
|
+
* @param message - The message to post.
|
|
184
|
+
*/
|
|
185
|
+
postMessage(message) {
|
|
186
|
+
this.self.postMessage(message);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Base class for multi-process canvas sandbox applications.
|
|
191
|
+
*
|
|
192
|
+
* Helps in orchestrating the workers.
|
|
193
|
+
*/
|
|
194
|
+
export class CanvasSandboxHostApplication {
|
|
195
|
+
/**
|
|
196
|
+
* Usually a hidden canvas that serves as a proxy for canvas sandbox events.
|
|
197
|
+
*/
|
|
198
|
+
canvas;
|
|
199
|
+
/**
|
|
200
|
+
* Application options.
|
|
201
|
+
*/
|
|
202
|
+
options;
|
|
203
|
+
/**
|
|
204
|
+
* PRNG instance for the application.
|
|
205
|
+
*/
|
|
206
|
+
random;
|
|
207
|
+
/**
|
|
208
|
+
* Is the application running right now?
|
|
209
|
+
*/
|
|
210
|
+
paused = false;
|
|
211
|
+
/**
|
|
212
|
+
* Web worker instances.
|
|
213
|
+
*/
|
|
214
|
+
workers = new Array();
|
|
215
|
+
/**
|
|
216
|
+
* Construct a new host application.
|
|
217
|
+
* @param canvas - Usually a hidden canvas in the DOM to serve as an event proxy.
|
|
218
|
+
* @param options - Application options.
|
|
219
|
+
*/
|
|
220
|
+
constructor(canvas, options) {
|
|
221
|
+
this.options = options;
|
|
222
|
+
this.canvas = canvas;
|
|
223
|
+
this.random = new Random(options.seed);
|
|
224
|
+
this.reconfigure(canvas, options);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Request the application to draw a new frame.
|
|
228
|
+
* This call has no effect in a host application, as all rendering happens in the workers.
|
|
229
|
+
* @param _delta - How many milliseconds passed since the last frame draw.
|
|
230
|
+
* @param _timestamp - The current timestamp.
|
|
231
|
+
*/
|
|
232
|
+
onDraw(_delta, _timestamp) {
|
|
233
|
+
// Draws happen in workers.
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Start the application.
|
|
237
|
+
*/
|
|
238
|
+
start() {
|
|
239
|
+
this.paused = false;
|
|
240
|
+
for (const worker of this.workers) {
|
|
241
|
+
worker.postMessage({
|
|
242
|
+
type: "start",
|
|
243
|
+
options: {
|
|
244
|
+
...this.options,
|
|
245
|
+
seed: this.random.seed,
|
|
246
|
+
viewport: worker.options.viewport,
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Posts a message to all workers.
|
|
253
|
+
* @param message - Message to post to all workers.
|
|
254
|
+
*/
|
|
255
|
+
postMessageAll(message) {
|
|
256
|
+
for (const worker of this.workers) {
|
|
257
|
+
worker.postMessage(message);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=canvas-sandbox-mp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-sandbox-mp.js","sourceRoot":"","sources":["../../source/graphics/canvas-sandbox-mp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAqE9C;;;;GAIG;AACH,MAAM,OAAO,YAEX,SAAQ,WAAW;IACnB;;OAEG;IACH,EAAE,CAAS;IAEX;;OAEG;IACH,MAAM,CAAgC;IAEtC;;OAEG;IACH,eAAe,CAA8B;IAE7C;;;;;;OAMG;IACM,OAAO,CAAsB;IAEtC;;OAEG;IACM,cAAc,CAAS;IAEhC;;;;;;;;;OASG;IACH,YAAY,EAAU,EAAE,MAAW,EAAE,MAAyB,EAAE,OAA4B;QAC1F,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,cAAc,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE;YACvC,IAAI,EAAE,QAAQ;SACf,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,CAAC,SAAS,GAAG,CAC9B,OAA+D,EAC/D,EAAE;YACF,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CACT,OAAiD,EACjD,QAA8B;QAE9B,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,IAAI,E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ClC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -38,6 +38,28 @@ export interface CanvasSandboxExpectedOptions {
|
|
|
38
38
|
* The seed for the PRNG.
|
|
39
39
|
*/
|
|
40
40
|
seed: number;
|
|
41
|
+
/**
|
|
42
|
+
* The part of the canvas that the targetted render kernel will handle.
|
|
43
|
+
* This is ignored, unless you use multi-process rendering.
|
|
44
|
+
*/
|
|
45
|
+
viewport: {
|
|
46
|
+
/**
|
|
47
|
+
* Start of the viewport in fractional world-space.
|
|
48
|
+
*/
|
|
49
|
+
x: number;
|
|
50
|
+
/**
|
|
51
|
+
* Start of the viewport in fractional world-space.
|
|
52
|
+
*/
|
|
53
|
+
y: number;
|
|
54
|
+
/**
|
|
55
|
+
* Width of the viewport in fractional world-space.
|
|
56
|
+
*/
|
|
57
|
+
w: number;
|
|
58
|
+
/**
|
|
59
|
+
* Height of the viewport in fractional world-space.
|
|
60
|
+
*/
|
|
61
|
+
h: number;
|
|
62
|
+
};
|
|
41
63
|
}
|
|
42
64
|
/**
|
|
43
65
|
* Describes an application running inside the {@linkcode CanvasSandbox}.
|
|
@@ -74,7 +96,7 @@ export interface CanvasSandboxApplication<TCanvas extends Canvas, TApplicationOp
|
|
|
74
96
|
/**
|
|
75
97
|
* Start the application.
|
|
76
98
|
*/
|
|
77
|
-
start(): void;
|
|
99
|
+
start(options?: Partial<TApplicationOptions>): void;
|
|
78
100
|
}
|
|
79
101
|
/**
|
|
80
102
|
* Options for a {@linkcode CanvasSandbox}.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { Shake } from "../device/shake.js";
|
|
3
3
|
import { getDocumentElementTypeById } from "../dom/core.js";
|
|
4
|
-
import { nextPalette } from "./core.js";
|
|
5
4
|
import { RenderLoop } from "./render-loop.js";
|
|
6
5
|
/**
|
|
7
6
|
* Provides the input as-is.
|
|
@@ -60,6 +59,7 @@ export const CANVAS_SANDBOX_DEFAULT_CSS = /* PURE */ css `
|
|
|
60
59
|
bottom: 0;
|
|
61
60
|
justify-content: center;
|
|
62
61
|
align-items: center;
|
|
62
|
+
z-index: 1;
|
|
63
63
|
|
|
64
64
|
filter: drop-shadow(10px 10px 4px rgba(0, 0, 0, 0.5));
|
|
65
65
|
transition: all 1s;
|
|
@@ -271,7 +271,6 @@ export class CanvasSandbox {
|
|
|
271
271
|
switch (event.keyCode) {
|
|
272
272
|
case 13:
|
|
273
273
|
// Enter
|
|
274
|
-
nextPalette();
|
|
275
274
|
this.#reconfigureApplication();
|
|
276
275
|
this.application.reconfigure(this.canvas);
|
|
277
276
|
this.application.start();
|
|
@@ -306,8 +305,6 @@ export class CanvasSandbox {
|
|
|
306
305
|
await document.exitFullscreen();
|
|
307
306
|
return;
|
|
308
307
|
}
|
|
309
|
-
// Run the next variation of the application.
|
|
310
|
-
nextPalette();
|
|
311
308
|
this.#reconfigureApplication();
|
|
312
309
|
event.preventDefault();
|
|
313
310
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-sandbox.js","sourceRoot":"","sources":["../../source/graphics/canvas-sandbox.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"canvas-sandbox.js","sourceRoot":"","sources":["../../source/graphics/canvas-sandbox.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,KAA2B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AAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACxC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,WAAW;QACT,IAAI,CAAC,uBAAuB,CAAC;YAC3B,QAAQ,EAAE,KAAK;SACgB,CAAC,CAAC;QACnC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
package/graphics/canvas3d.js
CHANGED
|
@@ -30,6 +30,7 @@ export class Canvas3D extends Canvas {
|
|
|
30
30
|
constructor(canvas, options = {}) {
|
|
31
31
|
super(canvas);
|
|
32
32
|
this.options = options;
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
33
34
|
this.#context = mustExist(this.canvasElement.getContext("webgl2", {
|
|
34
35
|
alpha: false,
|
|
35
36
|
}), "Unable to create rendering context for offscreen canvas.");
|
|
@@ -38,6 +39,7 @@ export class Canvas3D extends Canvas {
|
|
|
38
39
|
* Recreate internal buffers in reaction to a change in our target {@linkcode !HTMLCanvasElement}.
|
|
39
40
|
*/
|
|
40
41
|
refreshCanvasNode() {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
41
43
|
this.#context = mustExist(this.canvasElement.getContext("webgl2", {
|
|
42
44
|
alpha: false,
|
|
43
45
|
desynchronized: true,
|
package/graphics/canvas3d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas3d.js","sourceRoot":"","sources":["../../source/graphics/canvas3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;A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0D,CACjC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,4EAA4E;QAC5E,IAAI,CAAC,QAAQ,GAAG,SAAS,CACvB,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtC,KAAK,EAAE,KAAK;YACZ,cAAc,EAAE,IAAI;SACrB,CAAC,EACF,0DAA0D,CACjC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,+BAA+B;IACjC,CAAC;IACD;;OAEG;IACH,MAAM;QACJ,+BAA+B;IACjC,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,MAAc;QACtB,MAAM,IAAI,mBAAmB,EAAE,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACH,aAAa,CAAC,WAA0B,EAAE,UAAkB,EAAE,UAAkB;QAC9E,MAAM,IAAI,mBAAmB,EAAE,CAAC;IAClC,CAAC;CACF"}
|
package/graphics/core.d.ts
CHANGED
|
@@ -4,11 +4,6 @@
|
|
|
4
4
|
* @group Graphics
|
|
5
5
|
*/
|
|
6
6
|
export declare const GOLDEN_RATIO = 1.618033988749;
|
|
7
|
-
/**
|
|
8
|
-
* Color palettes that can be used to quickly colorize a drawing.
|
|
9
|
-
* @group Graphics
|
|
10
|
-
*/
|
|
11
|
-
export declare const PALETTES: number[][];
|
|
12
7
|
/**
|
|
13
8
|
* Constrains a color component value to single-byte range (`0`-`255`).
|
|
14
9
|
* @param c - A color component value.
|
|
@@ -97,19 +92,6 @@ export declare const blendAdditive: (src: number, dst: number, alpha: number) =>
|
|
|
97
92
|
* @group Graphics
|
|
98
93
|
*/
|
|
99
94
|
export declare const blendSubtractive: (src: number, dst: number, alpha: number) => number;
|
|
100
|
-
/**
|
|
101
|
-
* Retrieves a random color from the current global palette.
|
|
102
|
-
* Uses the global {@linkcode random} object.
|
|
103
|
-
* @returns A random color.
|
|
104
|
-
* @group Graphics
|
|
105
|
-
*/
|
|
106
|
-
export declare const someColor: () => number;
|
|
107
|
-
/**
|
|
108
|
-
* Switches the global palette to the next available preset.
|
|
109
|
-
* @returns The new new global palette.
|
|
110
|
-
* @group Graphics
|
|
111
|
-
*/
|
|
112
|
-
export declare const nextPalette: () => number[];
|
|
113
95
|
/**
|
|
114
96
|
* Converts a color value to grayscale.
|
|
115
97
|
* @param color - The color to convert.
|