@swf2es/render 0.1.34 → 0.1.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands.d.ts +11 -2
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +36 -6
- package/dist/commands.js.map +1 -1
- package/dist/geometry.d.ts +62 -5
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +100 -17
- package/dist/geometry.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/measure.d.ts.map +1 -1
- package/dist/measure.js +118 -61
- package/dist/measure.js.map +1 -1
- package/dist/plan.js +4 -4
- package/dist/plan.js.map +1 -1
- package/dist/rows.d.ts +4 -0
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +59 -10
- package/dist/rows.js.map +1 -1
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +37 -5
- package/dist/scene.js.map +1 -1
- package/dist/webgl/atlas.d.ts +89 -16
- package/dist/webgl/atlas.d.ts.map +1 -1
- package/dist/webgl/atlas.js +285 -109
- package/dist/webgl/atlas.js.map +1 -1
- package/dist/webgl/backend.d.ts +5 -3
- package/dist/webgl/backend.d.ts.map +1 -1
- package/dist/webgl/backend.js +9 -9
- package/dist/webgl/backend.js.map +1 -1
- package/dist/webgl/draws.js +1 -1
- package/dist/webgl/draws.js.map +1 -1
- package/package.json +2 -2
- package/src/commands.ts +48 -6
- package/src/geometry.ts +109 -19
- package/src/index.ts +1 -0
- package/src/measure.ts +132 -68
- package/src/plan.ts +4 -4
- package/src/rows.ts +62 -19
- package/src/scene.ts +41 -5
- package/src/webgl/atlas.ts +334 -118
- package/src/webgl/backend.ts +9 -9
- package/src/webgl/draws.ts +1 -1
package/src/geometry.ts
CHANGED
|
@@ -6,6 +6,16 @@ import { type Handle, Registry } from "./registry.js";
|
|
|
6
6
|
*/
|
|
7
7
|
export const IDLE_FRAMES = 300;
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Frames of the registry (Geometries.frame) a geometry stands copied to the GPU before its
|
|
11
|
+
* arrays are let go of (release): one drawn anew each frame, as a script's drawing redrawn every
|
|
12
|
+
* frame is, goes whole before then, and costs the backend no copy of its indices; copying a
|
|
13
|
+
* thousand such geometries' indices a frame took about a millisecond. An owner that reads a
|
|
14
|
+
* geometry's arrays after adding it does so within these frames, or asks for them again
|
|
15
|
+
* (rebuild).
|
|
16
|
+
*/
|
|
17
|
+
export const RELEASE_FRAMES = 3;
|
|
18
|
+
|
|
9
19
|
/** Floats a vertex of advanced text's glyph quads (GeometryData.glyphs). */
|
|
10
20
|
export const GLYPH_FLOATS = 18;
|
|
11
21
|
|
|
@@ -83,12 +93,23 @@ export interface GeometryData {
|
|
|
83
93
|
* Every geometry a scene list may name, by id. What goes undrawn for
|
|
84
94
|
* IDLE_FRAMES is let go of; its owner finds it gone by its handle and adds
|
|
85
95
|
* it again. The backend takes what was added and removed since it last
|
|
86
|
-
* looked (taken), and keeps its own copies
|
|
96
|
+
* looked (taken), and keeps its own copies: once it has copied a geometry's
|
|
97
|
+
* arrays into a context not known to be lost, the registry lets go of them (release),
|
|
98
|
+
* unless their owner changes them in place (add's `keep`). Nothing else
|
|
99
|
+
* releases them, so a view with no GPU backend, as in node, keeps every
|
|
100
|
+
* geometry's arrays. A reader that needs arrays let go of, a lost context
|
|
101
|
+
* or a CPU rasterizer alike, asks for them again through one entry point,
|
|
102
|
+
* rebuild: the geometry is removed, and its owner adds it again with its
|
|
103
|
+
* arrays as it next draws it, as it does an expired one.
|
|
87
104
|
*/
|
|
88
105
|
export class Geometries extends Registry {
|
|
89
106
|
/** Changes only when a handle can have become stale, including expiry and context loss. */
|
|
90
107
|
removalVersion = 0;
|
|
91
108
|
private readonly data: (GeometryData | null)[] = [];
|
|
109
|
+
/** Whether each geometry's arrays stay held once copied, as their owner changes them in place (update). */
|
|
110
|
+
private readonly kept: boolean[] = [];
|
|
111
|
+
/** Whether each geometry is flat (GeometryData.flat), its arrays held or not. */
|
|
112
|
+
private readonly flats: boolean[] = [];
|
|
92
113
|
/** Each geometry's box: its positions' least x and y, then their greatest. */
|
|
93
114
|
private boxes = new Float32Array(1024);
|
|
94
115
|
/** Added since the backend last took them. */
|
|
@@ -98,10 +119,17 @@ export class Geometries extends Registry {
|
|
|
98
119
|
/** Found flat since the backend last took them (markFlat). */
|
|
99
120
|
flattened: number[] = [];
|
|
100
121
|
|
|
101
|
-
|
|
122
|
+
/**
|
|
123
|
+
* `data` added, for the backend to copy. Its arrays are let go of once
|
|
124
|
+
* copied (release) unless `keep`, for an owner that changes them in place
|
|
125
|
+
* (update).
|
|
126
|
+
*/
|
|
127
|
+
add(data: GeometryData, keep = false): GeometryHandle {
|
|
102
128
|
const handle = this.hold(IDLE_FRAMES);
|
|
103
129
|
const id = handle.id;
|
|
104
130
|
this.data[id] = data;
|
|
131
|
+
this.kept[id] = keep;
|
|
132
|
+
this.flats[id] = data.flat === true;
|
|
105
133
|
this.added.push(id);
|
|
106
134
|
this.measure(id);
|
|
107
135
|
return handle;
|
|
@@ -109,27 +137,98 @@ export class Geometries extends Registry {
|
|
|
109
137
|
|
|
110
138
|
/**
|
|
111
139
|
* Geometry `id`'s arrays changed in place, their lengths as they were: its
|
|
112
|
-
* box measured again, and its vertices copied again where they lie.
|
|
140
|
+
* box measured again, and its vertices copied again where they lie. Only
|
|
141
|
+
* for a geometry added to be kept, and only its vertices: the backend
|
|
142
|
+
* keeps the indices it was added with (the atlas's Place.local).
|
|
113
143
|
*/
|
|
114
144
|
update(id: number): void {
|
|
115
|
-
if (this.data[id]) {
|
|
145
|
+
if (this.data[id] && this.kept[id]) {
|
|
116
146
|
this.measure(id);
|
|
117
147
|
this.updated.push(id);
|
|
118
148
|
}
|
|
119
149
|
}
|
|
120
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Geometry `id`'s arrays copied by the backend into a context not known to be lost,
|
|
153
|
+
* which keeps what it needs of them: let go of, unless they were added to
|
|
154
|
+
* be kept. Its box and flatness stay. Only the GPU backend calls it, once
|
|
155
|
+
* the copy is made (webgl/atlas.ts).
|
|
156
|
+
*/
|
|
157
|
+
release(id: number): void {
|
|
158
|
+
if (!this.kept[id]) {
|
|
159
|
+
this.data[id] = null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Whether geometry `id` is held but its arrays were let go of (release). */
|
|
164
|
+
released(id: number): boolean {
|
|
165
|
+
return this.holds(id) && !this.data[id];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Geometry `id`'s arrays wanted again, by any reader of them: where they
|
|
170
|
+
* were let go of (release), the geometry is removed, for its owner to add
|
|
171
|
+
* it again with its arrays as it next draws it (tessellated and stroked
|
|
172
|
+
* again, or from a slow layer's kept triangles), as an expired one is;
|
|
173
|
+
* its handle then reads dead. True where it was removed so; false where
|
|
174
|
+
* its arrays are held (get), or it is not held at all. Called outside a
|
|
175
|
+
* frame's walk, or with the view's spans dropped after: a frame walked
|
|
176
|
+
* or kept as spans (scene/spans.ts) before the call names the removed id
|
|
177
|
+
* in its scene list, which then draws nothing for it. An owner remaking
|
|
178
|
+
* its own geometry as it is next asked for it, before it is drawn, may
|
|
179
|
+
* call it mid-walk (Parts.partsOf).
|
|
180
|
+
*/
|
|
181
|
+
rebuild(id: number): boolean {
|
|
182
|
+
if (!this.released(id)) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
this.remove(id);
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
|
|
121
190
|
/**
|
|
122
191
|
* Geometry `id` found flat (GeometryData.flat) after it was added, for
|
|
123
192
|
* the backend to draw it so: its flag alone taken again, not its vertices.
|
|
124
193
|
*/
|
|
125
194
|
markFlat(id: number): void {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
data
|
|
195
|
+
if (this.holds(id) && !this.flats[id]) {
|
|
196
|
+
this.flats[id] = true;
|
|
197
|
+
const data = this.data[id];
|
|
198
|
+
if (data) {
|
|
199
|
+
data.flat = true;
|
|
200
|
+
}
|
|
201
|
+
|
|
129
202
|
this.flattened.push(id);
|
|
130
203
|
}
|
|
131
204
|
}
|
|
132
205
|
|
|
206
|
+
/** Whether geometry `id` is flat (GeometryData.flat, markFlat). */
|
|
207
|
+
flat(id: number): boolean {
|
|
208
|
+
return this.flats[id] === true;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The context was lost, and the backend's copies with it: the geometries
|
|
213
|
+
* whose arrays were let go of rebuilt (rebuild), and those whose arrays
|
|
214
|
+
* are held added again as they are.
|
|
215
|
+
*/
|
|
216
|
+
override lost(): void {
|
|
217
|
+
for (let id = 0; id < this.size; id++) {
|
|
218
|
+
this.rebuild(id);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this.added.length = 0;
|
|
222
|
+
this.removed.length = 0;
|
|
223
|
+
this.updated.length = 0;
|
|
224
|
+
this.flattened.length = 0;
|
|
225
|
+
for (let id = 0; id < this.size; id++) {
|
|
226
|
+
if (this.holds(id)) {
|
|
227
|
+
this.added.push(id);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
133
232
|
private measure(id: number): void {
|
|
134
233
|
const data = this.data[id] as GeometryData;
|
|
135
234
|
if (id * 4 >= this.boxes.length) {
|
|
@@ -166,24 +265,15 @@ export class Geometries extends Registry {
|
|
|
166
265
|
return this.boxes;
|
|
167
266
|
}
|
|
168
267
|
|
|
268
|
+
/** Geometry `id`'s arrays, null once let go of (release) or for one not held. */
|
|
169
269
|
get(id: number): GeometryData | null {
|
|
170
270
|
return this.data[id] ?? null;
|
|
171
271
|
}
|
|
172
272
|
|
|
173
|
-
/** The ids of every geometry held, in order. */
|
|
174
|
-
live(): number[] {
|
|
175
|
-
const ids: number[] = [];
|
|
176
|
-
for (let id = 0; id < this.data.length; id++) {
|
|
177
|
-
if (this.data[id]) {
|
|
178
|
-
ids.push(id);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return ids;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
273
|
protected override dropped(id: number): void {
|
|
186
274
|
this.removalVersion++;
|
|
187
275
|
this.data[id] = null;
|
|
276
|
+
this.kept[id] = false;
|
|
277
|
+
this.flats[id] = false;
|
|
188
278
|
}
|
|
189
279
|
}
|
package/src/index.ts
CHANGED
package/src/measure.ts
CHANGED
|
@@ -29,12 +29,71 @@ export interface MeasureTarget {
|
|
|
29
29
|
/** A hair, which keeps a padded edge on the pixel it lies on at any resolution. */
|
|
30
30
|
const TEXEL_SNAP = 1e-6;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
/**
|
|
33
|
+
* A scratch stack of areas, four numbers each: least x and y, greatest x
|
|
34
|
+
* and y, in target pixels. Typed and grown by doubling, never shortened,
|
|
35
|
+
* so that a frame neither boxes its numbers nor makes its store again.
|
|
36
|
+
*/
|
|
37
|
+
class Areas {
|
|
38
|
+
data = new Float64Array(64);
|
|
39
|
+
/** Numbers in use, four an area. */
|
|
40
|
+
top = 0;
|
|
41
|
+
|
|
42
|
+
/** Room for one more area. */
|
|
43
|
+
room(): Float64Array {
|
|
44
|
+
if (this.top + 4 > this.data.length) {
|
|
45
|
+
const grown = new Float64Array(this.data.length * 2);
|
|
46
|
+
grown.set(this.data);
|
|
47
|
+
this.data = grown;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return this.data;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** An area of nothing, its least past its greatest. */
|
|
54
|
+
pushEmpty(): void {
|
|
55
|
+
this.push(
|
|
56
|
+
Number.POSITIVE_INFINITY,
|
|
57
|
+
Number.POSITIVE_INFINITY,
|
|
58
|
+
Number.NEGATIVE_INFINITY,
|
|
59
|
+
Number.NEGATIVE_INFINITY,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
push(left: number, top: number, right: number, bottom: number): void {
|
|
64
|
+
const data = this.room();
|
|
65
|
+
const n = this.top;
|
|
66
|
+
data[n] = left;
|
|
67
|
+
data[n + 1] = top;
|
|
68
|
+
data[n + 2] = right;
|
|
69
|
+
data[n + 3] = bottom;
|
|
70
|
+
this.top = n + 4;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The top area moved onto `to`. */
|
|
74
|
+
moveTop(to: Areas): void {
|
|
75
|
+
const data = to.room();
|
|
76
|
+
const from = this.data;
|
|
77
|
+
const n = this.top - 4;
|
|
78
|
+
const t = to.top;
|
|
79
|
+
data[t] = from[n];
|
|
80
|
+
data[t + 1] = from[n + 1];
|
|
81
|
+
data[t + 2] = from[n + 2];
|
|
82
|
+
data[t + 3] = from[n + 3];
|
|
83
|
+
to.top = t + 4;
|
|
84
|
+
this.top = n;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const areas = new Areas();
|
|
89
|
+
const clips = new Areas();
|
|
90
|
+
// Each open layer's cut, as an area: an alpha mask's rectangle in it (ALPHA_MASK).
|
|
91
|
+
const cuts = new Areas();
|
|
92
|
+
// The open layers by number, innermost last, `openTop` of them.
|
|
93
|
+
let open = new Int32Array(16);
|
|
94
|
+
let openTop = 0;
|
|
95
|
+
// drawnArea's area as it is measured.
|
|
96
|
+
const drawn = new Float64Array(4);
|
|
38
97
|
|
|
39
98
|
/**
|
|
40
99
|
* Each layer's rectangle of the target (SceneList.layerRect), from what is
|
|
@@ -60,11 +119,11 @@ export function measureLayers(
|
|
|
60
119
|
return;
|
|
61
120
|
}
|
|
62
121
|
|
|
63
|
-
areas.
|
|
64
|
-
clips.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
pushEmpty(
|
|
122
|
+
areas.top = 0;
|
|
123
|
+
clips.top = 0;
|
|
124
|
+
cuts.top = 0;
|
|
125
|
+
openTop = 0;
|
|
126
|
+
areas.pushEmpty();
|
|
68
127
|
const k = target.scale;
|
|
69
128
|
const box = geometries.box;
|
|
70
129
|
const m = rows.data;
|
|
@@ -72,16 +131,22 @@ export function measureLayers(
|
|
|
72
131
|
for (let i = 0; i < scene.length; i++) {
|
|
73
132
|
switch (scene.kind[i]) {
|
|
74
133
|
case DRAW:
|
|
75
|
-
placeDraw(scene, i, box, m, k, areas);
|
|
134
|
+
placeDraw(scene, i, box, m, k, areas.data, areas.top);
|
|
76
135
|
break;
|
|
77
136
|
|
|
78
137
|
case MASK_BEGIN:
|
|
79
138
|
// The mask's own draws, measured apart.
|
|
80
|
-
pushEmpty(
|
|
139
|
+
areas.pushEmpty();
|
|
81
140
|
break;
|
|
82
141
|
case LAYER_BEGIN:
|
|
83
|
-
open.
|
|
84
|
-
|
|
142
|
+
if (openTop === open.length) {
|
|
143
|
+
const grown = new Int32Array(open.length * 2);
|
|
144
|
+
grown.set(open);
|
|
145
|
+
open = grown;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
open[openTop++] = scene.geometry[i];
|
|
149
|
+
areas.pushEmpty();
|
|
85
150
|
cuts.push(
|
|
86
151
|
Number.NEGATIVE_INFINITY,
|
|
87
152
|
Number.NEGATIVE_INFINITY,
|
|
@@ -91,18 +156,20 @@ export function measureLayers(
|
|
|
91
156
|
break;
|
|
92
157
|
case MASK_USE:
|
|
93
158
|
// The mask's draws clip what follows, measured apart till it pops.
|
|
94
|
-
moveTop(
|
|
95
|
-
pushEmpty(
|
|
159
|
+
areas.moveTop(clips);
|
|
160
|
+
areas.pushEmpty();
|
|
96
161
|
break;
|
|
97
162
|
case MASK_POP: {
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
163
|
+
const a = areas.data;
|
|
164
|
+
const n = areas.top;
|
|
165
|
+
const cl = clips.data;
|
|
166
|
+
const c = clips.top;
|
|
167
|
+
const left = Math.max(a[n - 4], cl[c - 4]);
|
|
168
|
+
const top = Math.max(a[n - 3], cl[c - 3]);
|
|
169
|
+
const right = Math.min(a[n - 2], cl[c - 2]);
|
|
170
|
+
const bottom = Math.min(a[n - 1], cl[c - 1]);
|
|
171
|
+
areas.top = n - 4;
|
|
172
|
+
clips.top = c - 4;
|
|
106
173
|
if (right > left && bottom > top) {
|
|
107
174
|
unionTop(left, top, right, bottom);
|
|
108
175
|
}
|
|
@@ -111,17 +178,19 @@ export function measureLayers(
|
|
|
111
178
|
}
|
|
112
179
|
|
|
113
180
|
case LAYER_END: {
|
|
114
|
-
const
|
|
115
|
-
const
|
|
181
|
+
const a = areas.data;
|
|
182
|
+
const n = areas.top;
|
|
183
|
+
const layer = open[--openTop];
|
|
116
184
|
const pad = scene.pads[layer];
|
|
117
|
-
const
|
|
185
|
+
const cut = cuts.data;
|
|
186
|
+
const c = cuts.top - 4;
|
|
118
187
|
if (pad < 0) {
|
|
119
|
-
const left = Math.max(0, Math.floor(
|
|
120
|
-
const top = Math.max(0, Math.floor(
|
|
121
|
-
const right = Math.min(target.width, Math.ceil(
|
|
122
|
-
const bottom = Math.min(target.height, Math.ceil(
|
|
123
|
-
areas.
|
|
124
|
-
cuts.
|
|
188
|
+
const left = Math.max(0, Math.floor(a[n - 4]) - 1, cut[c]);
|
|
189
|
+
const top = Math.max(0, Math.floor(a[n - 3]) - 1, cut[c + 1]);
|
|
190
|
+
const right = Math.min(target.width, Math.ceil(a[n - 2]) + 1, cut[c + 2]);
|
|
191
|
+
const bottom = Math.min(target.height, Math.ceil(a[n - 1]) + 1, cut[c + 3]);
|
|
192
|
+
areas.top = n - 4;
|
|
193
|
+
cuts.top = c;
|
|
125
194
|
if (scene.geometry[i] === ALPHA_MASK) {
|
|
126
195
|
// Not taken into the layer it ends, which it cuts to its rectangle: to nothing, where it
|
|
127
196
|
// has none.
|
|
@@ -131,10 +200,10 @@ export function measureLayers(
|
|
|
131
200
|
|
|
132
201
|
const p = c - 4;
|
|
133
202
|
if (p >= 0) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
203
|
+
cut[p] = Math.max(cut[p], left);
|
|
204
|
+
cut[p + 1] = Math.max(cut[p + 1], top);
|
|
205
|
+
cut[p + 2] = Math.min(cut[p + 2], right);
|
|
206
|
+
cut[p + 3] = Math.min(cut[p + 3], bottom);
|
|
138
207
|
}
|
|
139
208
|
|
|
140
209
|
break;
|
|
@@ -150,10 +219,10 @@ export function measureLayers(
|
|
|
150
219
|
|
|
151
220
|
// The view puts no alpha mask straight in a filtered layer, which would run its filters on
|
|
152
221
|
// what the mask left (cuts).
|
|
153
|
-
cuts.
|
|
222
|
+
cuts.top = c;
|
|
154
223
|
const kept = scene.areas;
|
|
155
224
|
for (let k = 0; k < 4; k++) {
|
|
156
|
-
kept[layer * 4 + k] =
|
|
225
|
+
kept[layer * 4 + k] = a[n - 4 + k];
|
|
157
226
|
}
|
|
158
227
|
|
|
159
228
|
filteredRect(
|
|
@@ -166,7 +235,7 @@ export function measureLayers(
|
|
|
166
235
|
scene.wholes[layer],
|
|
167
236
|
scene.objects,
|
|
168
237
|
);
|
|
169
|
-
areas.
|
|
238
|
+
areas.top = n - 4;
|
|
170
239
|
const r = scene.layers;
|
|
171
240
|
const at = layer * 4;
|
|
172
241
|
if (r[at + 2] > 0) {
|
|
@@ -320,14 +389,16 @@ export function drawnArea(
|
|
|
320
389
|
scale: number,
|
|
321
390
|
out: number[],
|
|
322
391
|
): void {
|
|
323
|
-
|
|
324
|
-
|
|
392
|
+
drawn[0] = Number.POSITIVE_INFINITY;
|
|
393
|
+
drawn[1] = Number.POSITIVE_INFINITY;
|
|
394
|
+
drawn[2] = Number.NEGATIVE_INFINITY;
|
|
395
|
+
drawn[3] = Number.NEGATIVE_INFINITY;
|
|
325
396
|
let defining = 0;
|
|
326
397
|
for (let i = from; i < scene.length; i++) {
|
|
327
398
|
switch (scene.kind[i]) {
|
|
328
399
|
case DRAW:
|
|
329
400
|
if (defining === 0) {
|
|
330
|
-
placeDraw(scene, i, geometries.box, rows.data, scale,
|
|
401
|
+
placeDraw(scene, i, geometries.box, rows.data, scale, drawn, 4);
|
|
331
402
|
}
|
|
332
403
|
|
|
333
404
|
break;
|
|
@@ -339,16 +410,25 @@ export function drawnArea(
|
|
|
339
410
|
break;
|
|
340
411
|
}
|
|
341
412
|
}
|
|
413
|
+
|
|
414
|
+
out[0] = drawn[0];
|
|
415
|
+
out[1] = drawn[1];
|
|
416
|
+
out[2] = drawn[2];
|
|
417
|
+
out[3] = drawn[3];
|
|
342
418
|
}
|
|
343
419
|
|
|
344
|
-
/**
|
|
420
|
+
/**
|
|
421
|
+
* Entry `i`'s geometry box placed by its row at `k` target pixels a stage
|
|
422
|
+
* pixel, taken into the area that ends before `stack[n]`.
|
|
423
|
+
*/
|
|
345
424
|
function placeDraw(
|
|
346
425
|
scene: SceneList,
|
|
347
426
|
i: number,
|
|
348
427
|
box: Float32Array,
|
|
349
428
|
m: Float32Array,
|
|
350
429
|
k: number,
|
|
351
|
-
stack:
|
|
430
|
+
stack: Float64Array,
|
|
431
|
+
n: number,
|
|
352
432
|
): void {
|
|
353
433
|
const g = scene.geometry[i] * 4;
|
|
354
434
|
const x0 = box[g];
|
|
@@ -367,34 +447,18 @@ function placeDraw(
|
|
|
367
447
|
const tx = m[r + 4] * k;
|
|
368
448
|
const ty = m[r + 5] * k;
|
|
369
449
|
// The box's corners placed: each of the least and greatest a coordinate takes, by sign.
|
|
370
|
-
const n = stack.length;
|
|
371
450
|
stack[n - 4] = Math.min(stack[n - 4], tx + Math.min(a * x0, a * x1) + Math.min(c * y0, c * y1));
|
|
372
451
|
stack[n - 3] = Math.min(stack[n - 3], ty + Math.min(b * x0, b * x1) + Math.min(d * y0, d * y1));
|
|
373
452
|
stack[n - 2] = Math.max(stack[n - 2], tx + Math.max(a * x0, a * x1) + Math.max(c * y0, c * y1));
|
|
374
453
|
stack[n - 1] = Math.max(stack[n - 1], ty + Math.max(b * x0, b * x1) + Math.max(d * y0, d * y1));
|
|
375
454
|
}
|
|
376
455
|
|
|
377
|
-
function pushEmpty(stack: number[]): void {
|
|
378
|
-
stack.push(
|
|
379
|
-
Number.POSITIVE_INFINITY,
|
|
380
|
-
Number.POSITIVE_INFINITY,
|
|
381
|
-
Number.NEGATIVE_INFINITY,
|
|
382
|
-
Number.NEGATIVE_INFINITY,
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/** The top area of `from` moved onto `to`. */
|
|
387
|
-
function moveTop(from: number[], to: number[]): void {
|
|
388
|
-
const n = from.length;
|
|
389
|
-
to.push(from[n - 4], from[n - 3], from[n - 2], from[n - 1]);
|
|
390
|
-
from.length = n - 4;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
456
|
/** The open area on top grown to take in the rectangle. */
|
|
394
457
|
function unionTop(left: number, top: number, right: number, bottom: number): void {
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
458
|
+
const a = areas.data;
|
|
459
|
+
const n = areas.top;
|
|
460
|
+
a[n - 4] = Math.min(a[n - 4], left);
|
|
461
|
+
a[n - 3] = Math.min(a[n - 3], top);
|
|
462
|
+
a[n - 2] = Math.max(a[n - 2], right);
|
|
463
|
+
a[n - 1] = Math.max(a[n - 1], bottom);
|
|
400
464
|
}
|
package/src/plan.ts
CHANGED
|
@@ -78,7 +78,7 @@ export function plan(scene: SceneList, background: number, out: Commands): void
|
|
|
78
78
|
const alpha = (background >>> 24) / 255;
|
|
79
79
|
out.push(
|
|
80
80
|
CLEAR,
|
|
81
|
-
out.
|
|
81
|
+
out.param4(
|
|
82
82
|
(((background >> 16) & 0xff) / 255) * alpha,
|
|
83
83
|
(((background >> 8) & 0xff) / 255) * alpha,
|
|
84
84
|
((background & 0xff) / 255) * alpha,
|
|
@@ -176,7 +176,7 @@ function emit(scene: SceneList, from: number, to: number, out: Commands, stage:
|
|
|
176
176
|
if (r[at + 2] > 0 && r[at + 3] > 0) {
|
|
177
177
|
out.push(
|
|
178
178
|
COMPOSITE,
|
|
179
|
-
out.
|
|
179
|
+
out.param5(r[at], r[at + 1], r[at + 2], r[at + 3], scene.texture[i]),
|
|
180
180
|
scene.blend[i],
|
|
181
181
|
scene.row[i],
|
|
182
182
|
);
|
|
@@ -280,8 +280,8 @@ function layerParams(out: Commands, scene: SceneList, layer: number): number {
|
|
|
280
280
|
const o = scene.objects;
|
|
281
281
|
const at = layer * 4;
|
|
282
282
|
return scene.wholes[layer] === NO_WHOLE
|
|
283
|
-
? out.
|
|
284
|
-
: out.
|
|
283
|
+
? out.param8(r[at], r[at + 1], r[at + 2], r[at + 3], 0, 0, -1, -1)
|
|
284
|
+
: out.param8(
|
|
285
285
|
r[at],
|
|
286
286
|
r[at + 1],
|
|
287
287
|
r[at + 2],
|
package/src/rows.ts
CHANGED
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
export const ROW_FLOATS = 16;
|
|
7
7
|
/** Rows a line of the rows' texture. */
|
|
8
8
|
export const ROWS_A_LINE = 256;
|
|
9
|
+
/**
|
|
10
|
+
* Floats of a span from which Rows.append copies through a view: below
|
|
11
|
+
* it, copying by index costs less than making the view.
|
|
12
|
+
*/
|
|
13
|
+
const SPAN_VIEW_FLOATS = 4 * ROW_FLOATS;
|
|
9
14
|
|
|
10
15
|
/** The rows of a frame's draws, written in order and uploaded together. */
|
|
11
16
|
export class Rows {
|
|
@@ -37,7 +42,20 @@ export class Rows {
|
|
|
37
42
|
this.data = grown;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
// A short span by index, as a view to copy from would be an allocation each span; a long one
|
|
46
|
+
// through the view, which copies it much faster.
|
|
47
|
+
const source = from.data;
|
|
48
|
+
const data = this.data;
|
|
49
|
+
const start = first * ROW_FLOATS;
|
|
50
|
+
const last = end * ROW_FLOATS;
|
|
51
|
+
if (last - start < SPAN_VIEW_FLOATS) {
|
|
52
|
+
for (let i = start, to = row * ROW_FLOATS; i < last; i++, to++) {
|
|
53
|
+
data[to] = source[i];
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
data.set(source.subarray(start, last), row * ROW_FLOATS);
|
|
57
|
+
}
|
|
58
|
+
|
|
41
59
|
return row;
|
|
42
60
|
}
|
|
43
61
|
|
|
@@ -46,20 +64,33 @@ export class Rows {
|
|
|
46
64
|
* caller keeps in a typed array, so that none are boxed passing them.
|
|
47
65
|
*/
|
|
48
66
|
addPlaced(places: Float64Array, at: number, ct: ColorRow | null): number {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
// Written here, not passed to add, which would box them where it is not inlined.
|
|
68
|
+
const row = this.next();
|
|
69
|
+
const out = this.data;
|
|
70
|
+
const to = row * ROW_FLOATS;
|
|
71
|
+
out[to] = places[at];
|
|
72
|
+
out[to + 1] = places[at + 1];
|
|
73
|
+
out[to + 2] = places[at + 2];
|
|
74
|
+
out[to + 3] = places[at + 3];
|
|
75
|
+
out[to + 4] = places[at + 4];
|
|
76
|
+
out[to + 5] = places[at + 5];
|
|
77
|
+
this.color(to, ct);
|
|
78
|
+
return row;
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
/** A row for the translation of the transform at `places[at]` alone. */
|
|
61
82
|
addTranslated(places: Float64Array, at: number, ct: ColorRow | null): number {
|
|
62
|
-
|
|
83
|
+
const row = this.next();
|
|
84
|
+
const out = this.data;
|
|
85
|
+
const to = row * ROW_FLOATS;
|
|
86
|
+
out[to] = 1;
|
|
87
|
+
out[to + 1] = 0;
|
|
88
|
+
out[to + 2] = 0;
|
|
89
|
+
out[to + 3] = 1;
|
|
90
|
+
out[to + 4] = places[at + 4];
|
|
91
|
+
out[to + 5] = places[at + 5];
|
|
92
|
+
this.color(to, ct);
|
|
93
|
+
return row;
|
|
63
94
|
}
|
|
64
95
|
|
|
65
96
|
/**
|
|
@@ -75,13 +106,7 @@ export class Rows {
|
|
|
75
106
|
ty: number,
|
|
76
107
|
ct: ColorRow | null,
|
|
77
108
|
): number {
|
|
78
|
-
const row = this.
|
|
79
|
-
if (this.count * ROW_FLOATS > this.data.length) {
|
|
80
|
-
const grown = new Float32Array(this.data.length * 2);
|
|
81
|
-
grown.set(this.data);
|
|
82
|
-
this.data = grown;
|
|
83
|
-
}
|
|
84
|
-
|
|
109
|
+
const row = this.next();
|
|
85
110
|
const out = this.data;
|
|
86
111
|
const at = row * ROW_FLOATS;
|
|
87
112
|
out[at] = a;
|
|
@@ -90,6 +115,25 @@ export class Rows {
|
|
|
90
115
|
out[at + 3] = d;
|
|
91
116
|
out[at + 4] = tx;
|
|
92
117
|
out[at + 5] = ty;
|
|
118
|
+
this.color(at, ct);
|
|
119
|
+
return row;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A row taken, the store grown for it: its index. */
|
|
123
|
+
private next(): number {
|
|
124
|
+
const row = this.count++;
|
|
125
|
+
if (this.count * ROW_FLOATS > this.data.length) {
|
|
126
|
+
const grown = new Float32Array(this.data.length * 2);
|
|
127
|
+
grown.set(this.data);
|
|
128
|
+
this.data = grown;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return row;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The row at `data[at]` coloured by `ct`, or by nothing where it is null. */
|
|
135
|
+
private color(at: number, ct: ColorRow | null): void {
|
|
136
|
+
const out = this.data;
|
|
93
137
|
out[at + 6] = 0;
|
|
94
138
|
out[at + 7] = 0;
|
|
95
139
|
out[at + 8] = ct ? ct.rMul : 1;
|
|
@@ -100,7 +144,6 @@ export class Rows {
|
|
|
100
144
|
out[at + 13] = ct ? ct.gAdd / 255 : 0;
|
|
101
145
|
out[at + 14] = ct ? ct.bAdd / 255 : 0;
|
|
102
146
|
out[at + 15] = ct ? ct.aAdd / 255 : 0;
|
|
103
|
-
return row;
|
|
104
147
|
}
|
|
105
148
|
}
|
|
106
149
|
|