@fi4f/hg 0.0.11 → 0.0.12
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 +57 -0
- package/dist/asset.d.ts +46 -0
- package/dist/asset.d.ts.map +1 -0
- package/dist/{core/asset.js → asset.js} +5 -30
- package/dist/asset.js.map +1 -0
- package/dist/{core/cache.d.ts → cache.d.ts} +17 -7
- package/dist/cache.d.ts.map +1 -0
- package/dist/{core/cache.js → cache.js} +5 -6
- package/dist/cache.js.map +1 -0
- package/dist/canvas.d.ts +4 -0
- package/dist/canvas.d.ts.map +1 -0
- package/dist/canvas.js +12 -0
- package/dist/canvas.js.map +1 -0
- package/dist/el.d.ts.map +1 -0
- package/dist/el.js.map +1 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js.map +1 -0
- package/dist/hg.d.ts +13 -13
- package/dist/hg.d.ts.map +1 -1
- package/dist/hg.js +14 -14
- package/dist/hg.js.map +1 -1
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/matrix2.d.ts +152 -0
- package/dist/matrix2.d.ts.map +1 -0
- package/dist/matrix2.js +262 -0
- package/dist/matrix2.js.map +1 -0
- package/dist/matrix3.d.ts +196 -0
- package/dist/matrix3.d.ts.map +1 -0
- package/dist/matrix3.js +352 -0
- package/dist/matrix3.js.map +1 -0
- package/dist/matrix4.d.ts +253 -0
- package/dist/matrix4.d.ts.map +1 -0
- package/dist/matrix4.js +465 -0
- package/dist/matrix4.js.map +1 -0
- package/dist/{core/scene.d.ts → scene.d.ts} +2 -3
- package/dist/scene.d.ts.map +1 -0
- package/dist/scene.js.map +1 -0
- package/dist/sprite.d.ts.map +1 -0
- package/dist/sprite.js.map +1 -0
- package/dist/stage.d.ts +100 -0
- package/dist/stage.d.ts.map +1 -0
- package/dist/stage.js +303 -0
- package/dist/stage.js.map +1 -0
- package/dist/vector2.d.ts +114 -0
- package/dist/vector2.d.ts.map +1 -0
- package/dist/vector2.js +168 -0
- package/dist/vector2.js.map +1 -0
- package/dist/vector3.d.ts +126 -0
- package/dist/vector3.d.ts.map +1 -0
- package/dist/vector3.js +190 -0
- package/dist/vector3.js.map +1 -0
- package/dist/vector4.d.ts +135 -0
- package/dist/vector4.d.ts.map +1 -0
- package/dist/vector4.js +209 -0
- package/dist/vector4.js.map +1 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js.map +1 -0
- package/package.json +1 -1
- package/dist/core/asset.d.ts +0 -71
- package/dist/core/asset.d.ts.map +0 -1
- package/dist/core/asset.js.map +0 -1
- package/dist/core/atlas.d.ts +0 -2
- package/dist/core/atlas.d.ts.map +0 -1
- package/dist/core/atlas.js +0 -2
- package/dist/core/atlas.js.map +0 -1
- package/dist/core/cache.d.ts.map +0 -1
- package/dist/core/cache.js.map +0 -1
- package/dist/core/event.d.ts.map +0 -1
- package/dist/core/event.js.map +0 -1
- package/dist/core/index.d.ts +0 -14
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/scene.d.ts.map +0 -1
- package/dist/core/scene.js.map +0 -1
- package/dist/core/sprite.d.ts.map +0 -1
- package/dist/core/sprite.js.map +0 -1
- package/dist/core/stage.d.ts +0 -130
- package/dist/core/stage.d.ts.map +0 -1
- package/dist/core/stage.js +0 -308
- package/dist/core/stage.js.map +0 -1
- package/dist/math/el.d.ts.map +0 -1
- package/dist/math/el.js.map +0 -1
- package/dist/math/matrix2.d.ts +0 -70
- package/dist/math/matrix2.d.ts.map +0 -1
- package/dist/math/matrix2.js +0 -180
- package/dist/math/matrix2.js.map +0 -1
- package/dist/math/matrix3.d.ts +0 -108
- package/dist/math/matrix3.d.ts.map +0 -1
- package/dist/math/matrix3.js +0 -257
- package/dist/math/matrix3.js.map +0 -1
- package/dist/math/matrix4.d.ts +0 -158
- package/dist/math/matrix4.d.ts.map +0 -1
- package/dist/math/matrix4.js +0 -354
- package/dist/math/matrix4.js.map +0 -1
- package/dist/math/vector2.d.ts +0 -38
- package/dist/math/vector2.d.ts.map +0 -1
- package/dist/math/vector2.js +0 -67
- package/dist/math/vector2.js.map +0 -1
- package/dist/math/vector3.d.ts +0 -34
- package/dist/math/vector3.d.ts.map +0 -1
- package/dist/math/vector3.js +0 -74
- package/dist/math/vector3.js.map +0 -1
- package/dist/math/vector4.d.ts +0 -39
- package/dist/math/vector4.d.ts.map +0 -1
- package/dist/math/vector4.js +0 -81
- package/dist/math/vector4.js.map +0 -1
- package/dist/util/types.d.ts +0 -2
- package/dist/util/types.d.ts.map +0 -1
- package/dist/util/types.js +0 -2
- package/dist/util/types.js.map +0 -1
- package/dist/util/version.d.ts.map +0 -1
- package/dist/util/version.js.map +0 -1
- /package/dist/{math/el.d.ts → el.d.ts} +0 -0
- /package/dist/{math/el.js → el.js} +0 -0
- /package/dist/{core/event.d.ts → event.d.ts} +0 -0
- /package/dist/{core/event.js → event.js} +0 -0
- /package/dist/{core/index.js → index.js} +0 -0
- /package/dist/{core/scene.js → scene.js} +0 -0
- /package/dist/{core/sprite.d.ts → sprite.d.ts} +0 -0
- /package/dist/{core/sprite.js → sprite.js} +0 -0
- /package/dist/{util/version.d.ts → version.d.ts} +0 -0
- /package/dist/{util/version.js → version.js} +0 -0
package/dist/stage.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { Canvas } from "./canvas.js";
|
|
2
|
+
import { Event } from "./event.js";
|
|
3
|
+
import { Scene } from "./scene.js";
|
|
4
|
+
import { Vector2 } from "./vector2.js";
|
|
5
|
+
/**
|
|
6
|
+
* A collection of constants and functions for constructing and
|
|
7
|
+
* interacting with Stage objects.
|
|
8
|
+
*/
|
|
9
|
+
export const Stage = {
|
|
10
|
+
new(o) {
|
|
11
|
+
const configureDebug = o?.debug ?? false;
|
|
12
|
+
const configureW = o?.w ?? 0;
|
|
13
|
+
const configureH = o?.h ?? 0;
|
|
14
|
+
const configureLogicalBackground = o?.lbg ?? "#000";
|
|
15
|
+
const configureVirtualBackground = o?.vbg ?? "#fff";
|
|
16
|
+
const configureScaleIncrement = o?.si;
|
|
17
|
+
const configureImageSmoothing = o?.is;
|
|
18
|
+
const logicalCanvasElement = o?.canvas ?? Canvas.Default();
|
|
19
|
+
const virtualCanvasElement = new OffscreenCanvas(configureW || logicalCanvasElement.width, configureH || logicalCanvasElement.height);
|
|
20
|
+
const logicalCanvasContext = logicalCanvasElement.getContext("2d");
|
|
21
|
+
const virtualCanvasContext = virtualCanvasElement.getContext("2d");
|
|
22
|
+
// configure image smoothing
|
|
23
|
+
logicalCanvasContext.imageSmoothingEnabled = !!configureImageSmoothing;
|
|
24
|
+
virtualCanvasContext.imageSmoothingEnabled = !!configureImageSmoothing;
|
|
25
|
+
if (configureImageSmoothing) {
|
|
26
|
+
logicalCanvasContext.imageSmoothingQuality = configureImageSmoothing;
|
|
27
|
+
virtualCanvasContext.imageSmoothingQuality = configureImageSmoothing;
|
|
28
|
+
}
|
|
29
|
+
// configure virtual scale
|
|
30
|
+
let virtualScale = Math.min(logicalCanvasElement.width / virtualCanvasElement.width, logicalCanvasElement.height / virtualCanvasElement.height);
|
|
31
|
+
if (configureScaleIncrement)
|
|
32
|
+
virtualScale = Math.floor(virtualScale / configureScaleIncrement) * configureScaleIncrement;
|
|
33
|
+
const stage = {
|
|
34
|
+
// configuration
|
|
35
|
+
configureDebug,
|
|
36
|
+
configureW,
|
|
37
|
+
configureH,
|
|
38
|
+
configureLogicalBackground,
|
|
39
|
+
configureVirtualBackground,
|
|
40
|
+
configureScaleIncrement,
|
|
41
|
+
configureImageSmoothing,
|
|
42
|
+
// canvas
|
|
43
|
+
logicalCanvasElement,
|
|
44
|
+
virtualCanvasElement,
|
|
45
|
+
logicalCanvasContext,
|
|
46
|
+
virtualCanvasContext,
|
|
47
|
+
virtualScale,
|
|
48
|
+
// data
|
|
49
|
+
event: Event.Tree.new(),
|
|
50
|
+
debug: new Map(),
|
|
51
|
+
scene: undefined,
|
|
52
|
+
// metrics
|
|
53
|
+
measuredFramesPerSecond: 0,
|
|
54
|
+
measuredAverageFrame: 0,
|
|
55
|
+
measuredMinimumFrame: 0,
|
|
56
|
+
measuredMaximumFrame: 0,
|
|
57
|
+
measuredAverageUpdate: 0,
|
|
58
|
+
measuredMinimumUpdate: 0,
|
|
59
|
+
measuredMaximumUpdate: 0,
|
|
60
|
+
measuredAverageRender: 0,
|
|
61
|
+
measuredMinimumRender: 0,
|
|
62
|
+
measuredMaximumRender: 0,
|
|
63
|
+
};
|
|
64
|
+
Stage.setDebugInfo(stage, "stage:frameInfo", undefined);
|
|
65
|
+
Stage.setDebugInfo(stage, "stage:updateInfo", undefined);
|
|
66
|
+
Stage.setDebugInfo(stage, "stage:renderInfo", undefined);
|
|
67
|
+
Stage.setDebugInfo(stage, "stage:canvasInfo", undefined);
|
|
68
|
+
new ResizeObserver(() => resize(stage)).observe(logicalCanvasElement);
|
|
69
|
+
Stage.listen(stage, "stage:resize", resize => onResize(stage, resize));
|
|
70
|
+
Stage.listen(stage, "stage:change", change => onChange(stage, change));
|
|
71
|
+
requestAnimationFrame(firstFrame => requestAnimationFrame(lastFrame => requestAnimationFrame(thisFrame => animate(stage, firstFrame, lastFrame, thisFrame))));
|
|
72
|
+
return stage;
|
|
73
|
+
},
|
|
74
|
+
getLogicalSize(stage) {
|
|
75
|
+
return Vector2.new(stage.logicalCanvasElement.width, stage.logicalCanvasElement.height);
|
|
76
|
+
},
|
|
77
|
+
getVirtualSize(stage) {
|
|
78
|
+
return Vector2.new(stage.virtualCanvasElement.width, stage.virtualCanvasElement.height);
|
|
79
|
+
},
|
|
80
|
+
getVirtualScale(stage) {
|
|
81
|
+
return stage.virtualScale;
|
|
82
|
+
},
|
|
83
|
+
use(stage, scene) {
|
|
84
|
+
Stage.dispatch(stage, "stage:change", scene);
|
|
85
|
+
},
|
|
86
|
+
listen(stage, type, listener, o) {
|
|
87
|
+
Event.listen(stage.event, type, listener, o);
|
|
88
|
+
},
|
|
89
|
+
deafen(stage, type, listener, o) {
|
|
90
|
+
Event.deafen(stage.event, type, listener, o);
|
|
91
|
+
},
|
|
92
|
+
dispatch(stage, type, event, o) {
|
|
93
|
+
Event.dispatch(stage.event, type, event, o);
|
|
94
|
+
},
|
|
95
|
+
poll(stage) {
|
|
96
|
+
Event.poll(stage.event);
|
|
97
|
+
},
|
|
98
|
+
getDebugInfo(stage, id) {
|
|
99
|
+
return stage.debug.get(id);
|
|
100
|
+
},
|
|
101
|
+
setDebugInfo(stage, id, info) {
|
|
102
|
+
stage.debug.set(id, info);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
function resize(stage) {
|
|
106
|
+
const w = stage.logicalCanvasElement.getBoundingClientRect().width;
|
|
107
|
+
const h = stage.logicalCanvasElement.getBoundingClientRect().height;
|
|
108
|
+
Stage.dispatch(stage, "stage:resize", [w, h]);
|
|
109
|
+
}
|
|
110
|
+
function onResize(stage, [w, h]) {
|
|
111
|
+
// compute new canvas sizes
|
|
112
|
+
stage.logicalCanvasElement.width = w;
|
|
113
|
+
stage.logicalCanvasElement.height = h;
|
|
114
|
+
stage.virtualCanvasElement = new OffscreenCanvas(stage.configureW || stage.logicalCanvasElement.width, stage.configureH || stage.logicalCanvasElement.height);
|
|
115
|
+
// new canvas contexts
|
|
116
|
+
stage.logicalCanvasContext = stage.logicalCanvasElement.getContext("2d");
|
|
117
|
+
stage.virtualCanvasContext = stage.virtualCanvasElement.getContext("2d");
|
|
118
|
+
// configure image smoothing
|
|
119
|
+
stage.logicalCanvasContext.imageSmoothingEnabled = !!stage.configureImageSmoothing;
|
|
120
|
+
stage.virtualCanvasContext.imageSmoothingEnabled = !!stage.configureImageSmoothing;
|
|
121
|
+
if (stage.configureImageSmoothing) {
|
|
122
|
+
stage.logicalCanvasContext.imageSmoothingQuality = stage.configureImageSmoothing;
|
|
123
|
+
stage.virtualCanvasContext.imageSmoothingQuality = stage.configureImageSmoothing;
|
|
124
|
+
}
|
|
125
|
+
// configure virtual scale
|
|
126
|
+
stage.virtualScale = Math.min(stage.logicalCanvasElement.width / stage.virtualCanvasElement.width, stage.logicalCanvasElement.height / stage.virtualCanvasElement.height);
|
|
127
|
+
if (stage.configureScaleIncrement)
|
|
128
|
+
stage.virtualScale = Math.floor(stage.virtualScale / stage.configureScaleIncrement) * stage.configureScaleIncrement;
|
|
129
|
+
Stage.setDebugInfo(stage, "stage:canvasInfo", getCanvasInfo(stage));
|
|
130
|
+
}
|
|
131
|
+
function onChange(stage, scene) {
|
|
132
|
+
if (stage.scene && stage.scene.onDetach)
|
|
133
|
+
stage.scene.onDetach(stage);
|
|
134
|
+
stage.scene = scene;
|
|
135
|
+
if (stage.scene && stage.scene.onAttach)
|
|
136
|
+
stage.scene.onAttach(stage);
|
|
137
|
+
}
|
|
138
|
+
function update(stage, t, dt) {
|
|
139
|
+
Stage.poll(stage);
|
|
140
|
+
if (Scene.doesUpdate(stage.scene))
|
|
141
|
+
stage.scene.onUpdate({ stage, t, dt });
|
|
142
|
+
}
|
|
143
|
+
function render(stage, t, dt) {
|
|
144
|
+
const f = stage.logicalCanvasContext;
|
|
145
|
+
const g = stage.virtualCanvasContext;
|
|
146
|
+
f.resetTransform();
|
|
147
|
+
g.resetTransform();
|
|
148
|
+
f.fillStyle = stage.configureLogicalBackground;
|
|
149
|
+
const [lw, lh] = Stage.getLogicalSize(stage);
|
|
150
|
+
f.fillRect(0, 0, lw, lh);
|
|
151
|
+
g.fillStyle = stage.configureVirtualBackground;
|
|
152
|
+
const [vw, vh] = Stage.getVirtualSize(stage);
|
|
153
|
+
g.fillRect(0, 0, vw, vh);
|
|
154
|
+
const vs = Stage.getVirtualScale(stage);
|
|
155
|
+
f.translate(lw / 2 - vw * vs / 2, lh / 2 - vh * vs / 2);
|
|
156
|
+
f.scale(vs, vs);
|
|
157
|
+
if (Scene.doesRender(stage.scene))
|
|
158
|
+
stage.scene.onRender({ stage, t, dt, g });
|
|
159
|
+
f.drawImage(stage.virtualCanvasElement, 0, 0);
|
|
160
|
+
if (stage.configureDebug && stage.configureDebug !== "print")
|
|
161
|
+
paintDebugInfo(stage);
|
|
162
|
+
}
|
|
163
|
+
const Timing = {
|
|
164
|
+
new() {
|
|
165
|
+
return {
|
|
166
|
+
framesPerSecondAccumulator: 0,
|
|
167
|
+
averageFrameAccumulator: 0,
|
|
168
|
+
minimumFrameAccumulator: Infinity,
|
|
169
|
+
maximumFrameAccumulator: 0,
|
|
170
|
+
averageUpdateAccumulator: 0,
|
|
171
|
+
minimumUpdateAccumulator: Infinity,
|
|
172
|
+
maximumUpdateAccumulator: 0,
|
|
173
|
+
averageRenderAccumulator: 0,
|
|
174
|
+
minimumRenderAccumulator: Infinity,
|
|
175
|
+
maximumRenderAccumulator: 0,
|
|
176
|
+
oneSecondAccumulator: 0,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
function animate(stage, t0, t1, t2, m) {
|
|
181
|
+
m ??= Timing.new();
|
|
182
|
+
const t = (t2 - t0) / 1000;
|
|
183
|
+
const dt = (t2 - t1) / 1000;
|
|
184
|
+
const a = performance.now();
|
|
185
|
+
update(stage, t, dt);
|
|
186
|
+
const b = performance.now();
|
|
187
|
+
render(stage, t, dt);
|
|
188
|
+
const c = performance.now();
|
|
189
|
+
const deltaFrame = c - a;
|
|
190
|
+
const deltaUpdate = b - a;
|
|
191
|
+
const deltaRender = c - b;
|
|
192
|
+
m.framesPerSecondAccumulator += 1;
|
|
193
|
+
m.averageFrameAccumulator += deltaFrame;
|
|
194
|
+
m.minimumFrameAccumulator = Math.min(deltaFrame, m.minimumFrameAccumulator);
|
|
195
|
+
m.maximumFrameAccumulator = Math.max(deltaFrame, m.maximumFrameAccumulator);
|
|
196
|
+
m.averageUpdateAccumulator += deltaUpdate;
|
|
197
|
+
m.minimumUpdateAccumulator = Math.min(deltaUpdate, m.minimumUpdateAccumulator);
|
|
198
|
+
m.maximumUpdateAccumulator = Math.max(deltaUpdate, m.maximumUpdateAccumulator);
|
|
199
|
+
m.averageRenderAccumulator += deltaRender;
|
|
200
|
+
m.minimumRenderAccumulator = Math.min(deltaRender, m.minimumRenderAccumulator);
|
|
201
|
+
m.maximumRenderAccumulator = Math.max(deltaRender, m.maximumRenderAccumulator);
|
|
202
|
+
m.oneSecondAccumulator += dt;
|
|
203
|
+
if (m.oneSecondAccumulator >= 1) {
|
|
204
|
+
stage.measuredFramesPerSecond = m.framesPerSecondAccumulator;
|
|
205
|
+
stage.measuredAverageFrame = m.averageFrameAccumulator / m.framesPerSecondAccumulator;
|
|
206
|
+
stage.measuredMinimumFrame = m.minimumFrameAccumulator;
|
|
207
|
+
stage.measuredMaximumFrame = m.maximumFrameAccumulator;
|
|
208
|
+
stage.measuredAverageUpdate = m.averageUpdateAccumulator / m.framesPerSecondAccumulator;
|
|
209
|
+
stage.measuredMinimumUpdate = m.minimumUpdateAccumulator;
|
|
210
|
+
stage.measuredMaximumUpdate = m.maximumUpdateAccumulator;
|
|
211
|
+
stage.measuredAverageRender = m.averageRenderAccumulator / m.framesPerSecondAccumulator;
|
|
212
|
+
stage.measuredMinimumRender = m.minimumRenderAccumulator;
|
|
213
|
+
stage.measuredMaximumRender = m.maximumRenderAccumulator;
|
|
214
|
+
// reset accumulators
|
|
215
|
+
m.framesPerSecondAccumulator = 0;
|
|
216
|
+
m.averageFrameAccumulator = 0;
|
|
217
|
+
m.minimumFrameAccumulator = Infinity;
|
|
218
|
+
m.maximumFrameAccumulator = 0;
|
|
219
|
+
m.averageUpdateAccumulator = 0;
|
|
220
|
+
m.minimumUpdateAccumulator = Infinity;
|
|
221
|
+
m.maximumUpdateAccumulator = 0;
|
|
222
|
+
m.averageRenderAccumulator = 0;
|
|
223
|
+
m.minimumRenderAccumulator = Infinity;
|
|
224
|
+
m.maximumRenderAccumulator = 0;
|
|
225
|
+
m.oneSecondAccumulator = 0;
|
|
226
|
+
Stage.setDebugInfo(stage, "stage:frameInfo", getFrameInfo(stage));
|
|
227
|
+
Stage.setDebugInfo(stage, "stage:updateInfo", getUpdateInfo(stage));
|
|
228
|
+
Stage.setDebugInfo(stage, "stage:renderInfo", getRenderInfo(stage));
|
|
229
|
+
if (stage.configureDebug && stage.configureDebug !== "print")
|
|
230
|
+
printDebugInfo(stage);
|
|
231
|
+
}
|
|
232
|
+
requestAnimationFrame(t3 => animate(stage, t0, t2, t3));
|
|
233
|
+
}
|
|
234
|
+
function getFrameInfo(stage) {
|
|
235
|
+
return `FRAME ${stage.measuredFramesPerSecond.toFixed(0)} hz @ ${stage.measuredAverageFrame.toFixed(2)} [${stage.measuredMinimumFrame.toFixed(2)} - ${stage.measuredMaximumFrame.toFixed(2)}] ms`;
|
|
236
|
+
}
|
|
237
|
+
function getUpdateInfo(stage) {
|
|
238
|
+
return `UPDATE ${stage.measuredAverageFrame.toFixed(2)} [${stage.measuredMinimumFrame.toFixed(2)} - ${stage.measuredMaximumFrame.toFixed(2)}] ms`;
|
|
239
|
+
}
|
|
240
|
+
function getRenderInfo(stage) {
|
|
241
|
+
return `RENDER ${stage.measuredAverageFrame.toFixed(2)} [${stage.measuredMinimumFrame.toFixed(2)} - ${stage.measuredMaximumFrame.toFixed(2)}] ms`;
|
|
242
|
+
}
|
|
243
|
+
function getCanvasInfo(stage) {
|
|
244
|
+
const [lw, lh] = Stage.getLogicalSize(stage);
|
|
245
|
+
const [vw, vh] = Stage.getVirtualSize(stage);
|
|
246
|
+
const vs = Stage.getVirtualScale(stage);
|
|
247
|
+
return `CANVAS ${lw}x${lh} ${vw}x${vh} ${(100 * vs).toFixed(2)}%`;
|
|
248
|
+
}
|
|
249
|
+
function printDebugInfo(stage) {
|
|
250
|
+
let infos = "*** DEBUG ***\n";
|
|
251
|
+
for (const [id, info] of stage.debug) {
|
|
252
|
+
if (!info)
|
|
253
|
+
continue;
|
|
254
|
+
infos += `${info}\n`;
|
|
255
|
+
}
|
|
256
|
+
console.log(infos);
|
|
257
|
+
}
|
|
258
|
+
const configureDebugInfoBackground = "#000a";
|
|
259
|
+
const configureDebugInfoForeground = "#ffff";
|
|
260
|
+
const configureDebugInfoPaddingL = 10;
|
|
261
|
+
const configureDebugInfoPaddingR = 10;
|
|
262
|
+
const configureDebugInfoPaddingT = 10;
|
|
263
|
+
const configureDebugInfoPaddingB = 10;
|
|
264
|
+
const configureDebugInfoSpacing = 0;
|
|
265
|
+
const configureDebugInfoFont = "16px monospace";
|
|
266
|
+
function paintDebugInfo(stage) {
|
|
267
|
+
const g = stage.logicalCanvasContext;
|
|
268
|
+
g.resetTransform();
|
|
269
|
+
g.font = configureDebugInfoFont;
|
|
270
|
+
let w = 0;
|
|
271
|
+
let h = 0;
|
|
272
|
+
for (const [id, info] of stage.debug) {
|
|
273
|
+
if (!info)
|
|
274
|
+
continue;
|
|
275
|
+
const tm = g.measureText(info);
|
|
276
|
+
w = Math.max(w, tm.width);
|
|
277
|
+
h += (tm.fontBoundingBoxAscent +
|
|
278
|
+
tm.fontBoundingBoxDescent +
|
|
279
|
+
configureDebugInfoSpacing);
|
|
280
|
+
}
|
|
281
|
+
if (h > 0) {
|
|
282
|
+
w += configureDebugInfoPaddingL + configureDebugInfoPaddingR;
|
|
283
|
+
h += configureDebugInfoPaddingT + configureDebugInfoPaddingB;
|
|
284
|
+
h -= configureDebugInfoSpacing;
|
|
285
|
+
}
|
|
286
|
+
// draw background
|
|
287
|
+
g.fillStyle = configureDebugInfoBackground;
|
|
288
|
+
g.fillRect(0, 0, w, h);
|
|
289
|
+
// draw foreground
|
|
290
|
+
g.fillStyle = configureDebugInfoForeground;
|
|
291
|
+
let x = configureDebugInfoPaddingL;
|
|
292
|
+
let y = configureDebugInfoPaddingT;
|
|
293
|
+
for (const [id, info] of stage.debug) {
|
|
294
|
+
if (!info)
|
|
295
|
+
continue;
|
|
296
|
+
const tm = g.measureText(info);
|
|
297
|
+
g.fillText(info, x, y + tm.fontBoundingBoxAscent);
|
|
298
|
+
y += (tm.fontBoundingBoxAscent +
|
|
299
|
+
tm.fontBoundingBoxDescent +
|
|
300
|
+
configureDebugInfoSpacing);
|
|
301
|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AC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAEtB,kBAAkB;IAClB,CAAC,CAAC,SAAS,GAAG,4BAA4B,CAAA;IAC1C,IAAI,CAAC,GAAG,0BAA0B,CAAA;IAClC,IAAI,CAAC,GAAG,0BAA0B,CAAA;IAClC,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI;YAAE,SAAQ;QAEnB,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,CAAA;QACjD,CAAC,IAAI,CACH,EAAE,CAAC,qBAAqB;YACxB,EAAE,CAAC,sBAAsB;YACzB,yBAAyB,CAC1B,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export type Vector2 = [number, number];
|
|
2
|
+
/**
|
|
3
|
+
* A collection of constants and functions for constructing and
|
|
4
|
+
* interacting with Vector2 objects.
|
|
5
|
+
*/
|
|
6
|
+
export declare const Vector2: {
|
|
7
|
+
/** Constant index for the x-component of a Vector2 */
|
|
8
|
+
X: 0;
|
|
9
|
+
/** Constant index for the y-component of a Vector2 */
|
|
10
|
+
Y: 1;
|
|
11
|
+
/** A collection of getters for Vector2 objects */
|
|
12
|
+
Get: {
|
|
13
|
+
/** Get the x-component of a Vector2 */
|
|
14
|
+
x(a: Vector2): number;
|
|
15
|
+
/** Get the y-component of a Vector2 */
|
|
16
|
+
y(a: Vector2): number;
|
|
17
|
+
};
|
|
18
|
+
/** A collection of setters for Vector2 objects */
|
|
19
|
+
Set: {
|
|
20
|
+
/** Set the x-component of a Vector2 */
|
|
21
|
+
x(a: Vector2, x: number): number;
|
|
22
|
+
/** Set the y-component of a Vector2 */
|
|
23
|
+
y(a: Vector2, y: number): number;
|
|
24
|
+
};
|
|
25
|
+
/** Get or set (when `x` is defined) the x-component of a Vector2 */
|
|
26
|
+
x(a: Vector2, x?: number): number;
|
|
27
|
+
/** Get or set (when `y` is defined) the y-component of a Vector2 */
|
|
28
|
+
y(a: Vector2, y?: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Construct a Vector2 from a variadic array of numbers.
|
|
31
|
+
*
|
|
32
|
+
* Constructs a uniform Vector2 when `a.length === 1`
|
|
33
|
+
* ```js
|
|
34
|
+
* Vector2.new(1) // [1, 1]
|
|
35
|
+
* ```
|
|
36
|
+
* Otherwise constructs a standard zero-padded Vector2
|
|
37
|
+
* ```js
|
|
38
|
+
* Vector2.new( ) // [0, 0]
|
|
39
|
+
* Vector2.new(1, 2) // [1, 2]
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
"new"(...a: Array<number>): [number, number];
|
|
43
|
+
/**
|
|
44
|
+
* Constructs a Vector2 from a number or an array of numbers.
|
|
45
|
+
*
|
|
46
|
+
* Constructs a uniform Vector2 when `a` is a number
|
|
47
|
+
* ```js
|
|
48
|
+
* Vector2.from(1) // [1, 1]
|
|
49
|
+
* ```
|
|
50
|
+
* Otherwise constructs a standard zero-padded Vector2
|
|
51
|
+
* ```js
|
|
52
|
+
* Vector2.from([ ]) // [0, 0]
|
|
53
|
+
* Vector2.from([1 ]) // [1, 0]
|
|
54
|
+
* Vector2.from([1, 2]) // [1, 2]
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
from(a: number | Array<number>): [number, number];
|
|
58
|
+
/**
|
|
59
|
+
* Perform an element-wise operation on two Vector2 objects.
|
|
60
|
+
* Number-like arguments are promoted to uniform Vector2 objects
|
|
61
|
+
* before performing the operation. Constructs a new Vector2 when an
|
|
62
|
+
* output argument is not provided.
|
|
63
|
+
*/
|
|
64
|
+
el(op: (a: number, b: number) => number, a: number | Vector2, b: number | Vector2, out?: Vector2): Vector2;
|
|
65
|
+
/**
|
|
66
|
+
* Compute the sum of two Vector2 objects. Number-like arguments are
|
|
67
|
+
* promoted to uniform Vector2 objects before performing the operation.
|
|
68
|
+
* Constructs a new Vector2 when an output argument is not provided.
|
|
69
|
+
*/
|
|
70
|
+
add(a: number | Vector2, b: number | Vector2, out?: Vector2): Vector2;
|
|
71
|
+
/**
|
|
72
|
+
* Compute the difference of two Vector2 objects. Number-like arguments
|
|
73
|
+
* are promoted to uniform Vector2 objects before performing the
|
|
74
|
+
* operation. Constructs a new Vector2 when an output argument is not
|
|
75
|
+
* provided.
|
|
76
|
+
*/
|
|
77
|
+
sub(a: number | Vector2, b: number | Vector2, out?: Vector2): Vector2;
|
|
78
|
+
/**
|
|
79
|
+
* Compute the hadamard (element-wise) product of two Vector2 objects.
|
|
80
|
+
* Number-like arguments are promoted to uniform Vector2 objects before
|
|
81
|
+
* performing the operation. Constructs a new Vector2 when an output
|
|
82
|
+
* argument is not provided.
|
|
83
|
+
*/
|
|
84
|
+
hmul(a: number | Vector2, b: number | Vector2, out?: Vector2): Vector2;
|
|
85
|
+
/**
|
|
86
|
+
* Compute the hadamard (element-wise) quotient of two Vector2 objects.
|
|
87
|
+
* Number-like arguments are promoted to uniform Vector2 objects before
|
|
88
|
+
* performing the operation. Constructs a new Vector2 when an output
|
|
89
|
+
* argument is not provided.
|
|
90
|
+
*/
|
|
91
|
+
hdiv(a: number | Vector2, b: number | Vector2, out?: Vector2): Vector2;
|
|
92
|
+
/**
|
|
93
|
+
* Compute the hadamard (element-wise) remainder of two Vector2 objects.
|
|
94
|
+
* Number-like arguments are promoted to uniform Vector2 objects before
|
|
95
|
+
* performing the operation. Constructs a new Vector2 when an output
|
|
96
|
+
* argument is not provided.
|
|
97
|
+
*/
|
|
98
|
+
hmod(a: number | Vector2, b: number | Vector2, out?: Vector2): Vector2;
|
|
99
|
+
/**
|
|
100
|
+
* Compute the dot product of two Vector2 objects, or simply the
|
|
101
|
+
* dot product of `a` with itself when `b` is not defined. Number-like
|
|
102
|
+
* arguments are promoted to uniform Vector2 objects before performing
|
|
103
|
+
* the operation.
|
|
104
|
+
*/
|
|
105
|
+
dot(a: number | Vector2, b?: number | Vector2): number;
|
|
106
|
+
/**
|
|
107
|
+
* Convert a Vector2 into its string representation
|
|
108
|
+
* ```js
|
|
109
|
+
* Vector2.toString([1, 2]) // "vec2<1, 2>"
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
toString([x, y]: Vector2): `vec2<${number}, ${number}>`;
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=vector2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector2.d.ts","sourceRoot":"","sources":["../src/vector2.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEtC;;;GAGG;AACH,eAAO,MAAM,OAAO;IAClB,sDAAsD;;IAEtD,sDAAsD;;IAGtD,kDAAkD;;QAEhD,uCAAuC;aAClC,OAAO;QACZ,uCAAuC;aAClC,OAAO;;IAGd,kDAAkD;;QAEhD,uCAAuC;aAClC,OAAO,KAAK,MAAM;QACvB,uCAAuC;aAClC,OAAO,KAAK,MAAM;;IAGzB,oEAAoE;SAC/D,OAAO,MAAO,MAAM;IAKzB,oEAAoE;SAC/D,OAAO,MAAO,MAAM;IAKzB;;;;;;;;;;;;OAYG;gBACO,KAAK,CAAC,MAAM,CAAC;IAWvB;;;;;;;;;;;;;OAaG;YACK,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAW9B;;;;;OAKG;WACI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,KAAK,MAAM,GAAG,OAAO,KAAK,MAAM,GAAG,OAAO,QAAO,OAAO;IAQ/F;;;;OAIG;WACI,MAAM,GAAG,OAAO,KAAK,MAAM,GAAG,OAAO,QAAO,OAAO;IAI1D;;;;;OAKG;WACI,MAAM,GAAG,OAAO,KAAK,MAAM,GAAG,OAAO,QAAO,OAAO;IAI1D;;;;;OAKG;YACK,MAAM,GAAG,OAAO,KAAK,MAAM,GAAG,OAAO,QAAO,OAAO;IAI3D;;;;;OAKG;YACK,MAAM,GAAG,OAAO,KAAK,MAAM,GAAG,OAAO,QAAO,OAAO;IAI3D;;;;;OAKG;YACK,MAAM,GAAG,OAAO,KAAK,MAAM,GAAG,OAAO,QAAO,OAAO;IAI3D;;;;;OAKG;WACI,MAAM,GAAG,OAAO,MAAK,MAAM,GAAG,OAAO;IAM5C;;;;;OAKG;qBACe,OAAO;CAG1B,CAAA"}
|
package/dist/vector2.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { add, sub, mul, div, mod } from "./el.js";
|
|
2
|
+
/**
|
|
3
|
+
* A collection of constants and functions for constructing and
|
|
4
|
+
* interacting with Vector2 objects.
|
|
5
|
+
*/
|
|
6
|
+
export const Vector2 = {
|
|
7
|
+
/** Constant index for the x-component of a Vector2 */
|
|
8
|
+
X: 0,
|
|
9
|
+
/** Constant index for the y-component of a Vector2 */
|
|
10
|
+
Y: 1,
|
|
11
|
+
/** A collection of getters for Vector2 objects */
|
|
12
|
+
Get: {
|
|
13
|
+
/** Get the x-component of a Vector2 */
|
|
14
|
+
x(a) { return a[Vector2.X]; },
|
|
15
|
+
/** Get the y-component of a Vector2 */
|
|
16
|
+
y(a) { return a[Vector2.Y]; },
|
|
17
|
+
},
|
|
18
|
+
/** A collection of setters for Vector2 objects */
|
|
19
|
+
Set: {
|
|
20
|
+
/** Set the x-component of a Vector2 */
|
|
21
|
+
x(a, x) { return a[Vector2.X] = x; },
|
|
22
|
+
/** Set the y-component of a Vector2 */
|
|
23
|
+
y(a, y) { return a[Vector2.Y] = y; },
|
|
24
|
+
},
|
|
25
|
+
/** Get or set (when `x` is defined) the x-component of a Vector2 */
|
|
26
|
+
x(a, x) {
|
|
27
|
+
if (x === undefined)
|
|
28
|
+
return Vector2.Get.x(a);
|
|
29
|
+
else
|
|
30
|
+
return Vector2.Set.x(a, x);
|
|
31
|
+
},
|
|
32
|
+
/** Get or set (when `y` is defined) the y-component of a Vector2 */
|
|
33
|
+
y(a, y) {
|
|
34
|
+
if (y === undefined)
|
|
35
|
+
return Vector2.Get.y(a);
|
|
36
|
+
else
|
|
37
|
+
return Vector2.Set.y(a, y);
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Construct a Vector2 from a variadic array of numbers.
|
|
41
|
+
*
|
|
42
|
+
* Constructs a uniform Vector2 when `a.length === 1`
|
|
43
|
+
* ```js
|
|
44
|
+
* Vector2.new(1) // [1, 1]
|
|
45
|
+
* ```
|
|
46
|
+
* Otherwise constructs a standard zero-padded Vector2
|
|
47
|
+
* ```js
|
|
48
|
+
* Vector2.new( ) // [0, 0]
|
|
49
|
+
* Vector2.new(1, 2) // [1, 2]
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
new(...a) {
|
|
53
|
+
if (a.length === 1)
|
|
54
|
+
return [
|
|
55
|
+
a[Vector2.X],
|
|
56
|
+
a[Vector2.X]
|
|
57
|
+
];
|
|
58
|
+
else
|
|
59
|
+
return [
|
|
60
|
+
a[Vector2.X] ?? 0,
|
|
61
|
+
a[Vector2.Y] ?? 0
|
|
62
|
+
];
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Constructs a Vector2 from a number or an array of numbers.
|
|
66
|
+
*
|
|
67
|
+
* Constructs a uniform Vector2 when `a` is a number
|
|
68
|
+
* ```js
|
|
69
|
+
* Vector2.from(1) // [1, 1]
|
|
70
|
+
* ```
|
|
71
|
+
* Otherwise constructs a standard zero-padded Vector2
|
|
72
|
+
* ```js
|
|
73
|
+
* Vector2.from([ ]) // [0, 0]
|
|
74
|
+
* Vector2.from([1 ]) // [1, 0]
|
|
75
|
+
* Vector2.from([1, 2]) // [1, 2]
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
from(a) {
|
|
79
|
+
if (typeof a === "number")
|
|
80
|
+
return [
|
|
81
|
+
a,
|
|
82
|
+
a
|
|
83
|
+
];
|
|
84
|
+
else
|
|
85
|
+
return [
|
|
86
|
+
a[Vector2.X] ?? 0,
|
|
87
|
+
a[Vector2.Y] ?? 0
|
|
88
|
+
];
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Perform an element-wise operation on two Vector2 objects.
|
|
92
|
+
* Number-like arguments are promoted to uniform Vector2 objects
|
|
93
|
+
* before performing the operation. Constructs a new Vector2 when an
|
|
94
|
+
* output argument is not provided.
|
|
95
|
+
*/
|
|
96
|
+
el(op, a, b, out = Vector2.new()) {
|
|
97
|
+
const [xa, ya] = Vector2.from(a);
|
|
98
|
+
const [xb, yb] = Vector2.from(b);
|
|
99
|
+
Vector2.Set.x(out, op(xa, xb));
|
|
100
|
+
Vector2.Set.y(out, op(ya, yb));
|
|
101
|
+
return out;
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Compute the sum of two Vector2 objects. Number-like arguments are
|
|
105
|
+
* promoted to uniform Vector2 objects before performing the operation.
|
|
106
|
+
* Constructs a new Vector2 when an output argument is not provided.
|
|
107
|
+
*/
|
|
108
|
+
add(a, b, out = Vector2.new()) {
|
|
109
|
+
return Vector2.el(add, a, b, out);
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* Compute the difference of two Vector2 objects. Number-like arguments
|
|
113
|
+
* are promoted to uniform Vector2 objects before performing the
|
|
114
|
+
* operation. Constructs a new Vector2 when an output argument is not
|
|
115
|
+
* provided.
|
|
116
|
+
*/
|
|
117
|
+
sub(a, b, out = Vector2.new()) {
|
|
118
|
+
return Vector2.el(sub, a, b, out);
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Compute the hadamard (element-wise) product of two Vector2 objects.
|
|
122
|
+
* Number-like arguments are promoted to uniform Vector2 objects before
|
|
123
|
+
* performing the operation. Constructs a new Vector2 when an output
|
|
124
|
+
* argument is not provided.
|
|
125
|
+
*/
|
|
126
|
+
hmul(a, b, out = Vector2.new()) {
|
|
127
|
+
return Vector2.el(mul, a, b, out);
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Compute the hadamard (element-wise) quotient of two Vector2 objects.
|
|
131
|
+
* Number-like arguments are promoted to uniform Vector2 objects before
|
|
132
|
+
* performing the operation. Constructs a new Vector2 when an output
|
|
133
|
+
* argument is not provided.
|
|
134
|
+
*/
|
|
135
|
+
hdiv(a, b, out = Vector2.new()) {
|
|
136
|
+
return Vector2.el(div, a, b, out);
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Compute the hadamard (element-wise) remainder of two Vector2 objects.
|
|
140
|
+
* Number-like arguments are promoted to uniform Vector2 objects before
|
|
141
|
+
* performing the operation. Constructs a new Vector2 when an output
|
|
142
|
+
* argument is not provided.
|
|
143
|
+
*/
|
|
144
|
+
hmod(a, b, out = Vector2.new()) {
|
|
145
|
+
return Vector2.el(mod, a, b, out);
|
|
146
|
+
},
|
|
147
|
+
/**
|
|
148
|
+
* Compute the dot product of two Vector2 objects, or simply the
|
|
149
|
+
* dot product of `a` with itself when `b` is not defined. Number-like
|
|
150
|
+
* arguments are promoted to uniform Vector2 objects before performing
|
|
151
|
+
* the operation.
|
|
152
|
+
*/
|
|
153
|
+
dot(a, b = a) {
|
|
154
|
+
const [xa, ya] = Vector2.from(a);
|
|
155
|
+
const [xb, yb] = Vector2.from(b);
|
|
156
|
+
return xa * xb + ya * yb;
|
|
157
|
+
},
|
|
158
|
+
/**
|
|
159
|
+
* Convert a Vector2 into its string representation
|
|
160
|
+
* ```js
|
|
161
|
+
* Vector2.toString([1, 2]) // "vec2<1, 2>"
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
toString([x, y]) {
|
|
165
|
+
return `vec2<${x}, ${y}>`;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=vector2.js.map
|
|
@@ -0,0 +1 @@
|
|
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