@wonderyard/vivarium 0.1.4 → 0.1.5
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/blueprint/ref-blueprint.js +2 -2
- package/dist/blueprint/rule-blueprint.d.ts +1 -2
- package/dist/blueprint/rule-blueprint.js +2 -2
- package/dist/blueprint/utils.js +1 -1
- package/dist/blueprint/vivarium-blueprint.js +2 -2
- package/dist/common/constants.js +4 -4
- package/dist/common/utils.js +3 -9
- package/dist/{constants-Ry69vZz5.js → constants-CBz0gZS0.js} +41 -41
- package/dist/{rule-blueprint-Df5BKApy.js → rule-blueprint-Dhi6aLUs.js} +19 -18
- package/dist/webgpu/compiler.d.ts +11 -24
- package/dist/webgpu/compiler.js +127 -4
- package/dist/webgpu/setup.js +2088 -1705
- package/package.json +1 -1
- package/dist/compiler-CEYR17Vv.js +0 -527
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseBlueprint as r } from "./base-blueprint.js";
|
|
2
|
-
import { R as n } from "../rule-blueprint-
|
|
2
|
+
import { R as n } from "../rule-blueprint-Dhi6aLUs.js";
|
|
3
3
|
import { toRefIdOrPoint as p } from "./utils.js";
|
|
4
|
-
import { A as u } from "../constants-
|
|
4
|
+
import { A as u } from "../constants-CBz0gZS0.js";
|
|
5
5
|
class o extends r {
|
|
6
6
|
constructor(e, t) {
|
|
7
7
|
super(), this.automaton = e, this.id = t.id, this.name = t.name, this.type = t.type;
|
|
@@ -8,8 +8,7 @@ export declare class RuleBlueprint extends BaseBlueprint {
|
|
|
8
8
|
protected rule: Rule;
|
|
9
9
|
constructor(context: BlueprintContext, automaton: Automaton, rule: Rule);
|
|
10
10
|
private condition;
|
|
11
|
-
count(refBlueprintOrNeighbor: RefBlueprint | AnyNeighbor, count: number[]): RuleBlueprintWithAccept;
|
|
12
|
-
count(refBlueprintOrNeighbor: RefBlueprint | AnyNeighbor, ...count: number[]): RuleBlueprintWithAccept;
|
|
11
|
+
count(refBlueprintOrNeighbor: RefBlueprint | AnyNeighbor, ...count: (number | number[])[]): RuleBlueprintWithAccept;
|
|
13
12
|
is(neighbor: AnyNeighbor, refBlueprintOrNeighbor: RefBlueprint | AnyNeighbor): RuleBlueprintWithAccept;
|
|
14
13
|
chance(part: number, whole?: number): RuleBlueprintWithAccept;
|
|
15
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { R as m } from "../rule-blueprint-
|
|
1
|
+
import { R as m } from "../rule-blueprint-Dhi6aLUs.js";
|
|
2
2
|
import "./base-blueprint.js";
|
|
3
3
|
import "./utils.js";
|
|
4
|
-
import "../constants-
|
|
4
|
+
import "../constants-CBz0gZS0.js";
|
|
5
5
|
export {
|
|
6
6
|
m as RuleBlueprint
|
|
7
7
|
};
|
package/dist/blueprint/utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as o } from "../rule-blueprint-
|
|
1
|
+
import { n as o } from "../rule-blueprint-Dhi6aLUs.js";
|
|
2
2
|
import { BaseBlueprint as n } from "./base-blueprint.js";
|
|
3
3
|
import { Helpers as a } from "./helpers.js";
|
|
4
4
|
import { ElementBlueprint as h, KindBlueprint as m } from "./ref-blueprint.js";
|
|
5
|
-
import { C as u, S as p } from "../constants-
|
|
5
|
+
import { C as u, S as p } from "../constants-CBz0gZS0.js";
|
|
6
6
|
class C extends n {
|
|
7
7
|
constructor(t) {
|
|
8
8
|
super(), this.neighborhoodName = t, this.helpers = new a(this.neighborhoodName), this.neighbor = this.neighborhoodName === "cross" ? u : p, this.automaton = {
|
package/dist/common/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as o, C as e,
|
|
1
|
+
import { A as o, C as e, b as p, G as c, a as n, O as t, S as r, T as u, cf as G, c as i, n as O } from "../constants-CBz0gZS0.js";
|
|
2
2
|
export {
|
|
3
3
|
o as Accept,
|
|
4
4
|
e as Cross,
|
|
@@ -8,7 +8,7 @@ export {
|
|
|
8
8
|
t as Opcode,
|
|
9
9
|
r as Square,
|
|
10
10
|
u as To,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
G as WORKGROUP_SIZE,
|
|
12
|
+
i as acceptMap,
|
|
13
|
+
O as neighborhoodPoints
|
|
14
14
|
};
|
package/dist/common/utils.js
CHANGED
|
@@ -48,11 +48,10 @@ const f = (e) => {
|
|
|
48
48
|
case "darkgoldenrod":
|
|
49
49
|
return "#b8860b";
|
|
50
50
|
case "darkgray":
|
|
51
|
+
case "darkgrey":
|
|
51
52
|
return "#a9a9a9";
|
|
52
53
|
case "darkgreen":
|
|
53
54
|
return "#006400";
|
|
54
|
-
case "darkgrey":
|
|
55
|
-
return "#a9a9a9";
|
|
56
55
|
case "darkkhaki":
|
|
57
56
|
return "#bdb76b";
|
|
58
57
|
case "darkmagenta":
|
|
@@ -72,7 +71,6 @@ const f = (e) => {
|
|
|
72
71
|
case "darkslateblue":
|
|
73
72
|
return "#483d8b";
|
|
74
73
|
case "darkslategray":
|
|
75
|
-
return "#2f4f4f";
|
|
76
74
|
case "darkslategrey":
|
|
77
75
|
return "#2f4f4f";
|
|
78
76
|
case "darkturquoise":
|
|
@@ -84,7 +82,6 @@ const f = (e) => {
|
|
|
84
82
|
case "deepskyblue":
|
|
85
83
|
return "#00bfff";
|
|
86
84
|
case "dimgray":
|
|
87
|
-
return "#696969";
|
|
88
85
|
case "dimgrey":
|
|
89
86
|
return "#696969";
|
|
90
87
|
case "dodgerblue":
|
|
@@ -142,11 +139,10 @@ const f = (e) => {
|
|
|
142
139
|
case "lightgoldenrodyellow":
|
|
143
140
|
return "#fafad2";
|
|
144
141
|
case "lightgray":
|
|
142
|
+
case "lightgrey":
|
|
145
143
|
return "#d3d3d3";
|
|
146
144
|
case "lightgreen":
|
|
147
145
|
return "#90ee90";
|
|
148
|
-
case "lightgrey":
|
|
149
|
-
return "#d3d3d3";
|
|
150
146
|
case "lightpink":
|
|
151
147
|
return "#ffb6c1";
|
|
152
148
|
case "lightsalmon":
|
|
@@ -156,7 +152,6 @@ const f = (e) => {
|
|
|
156
152
|
case "lightskyblue":
|
|
157
153
|
return "#87cefa";
|
|
158
154
|
case "lightslategray":
|
|
159
|
-
return "#778899";
|
|
160
155
|
case "lightslategrey":
|
|
161
156
|
return "#778899";
|
|
162
157
|
case "lightsteelblue":
|
|
@@ -262,7 +257,6 @@ const f = (e) => {
|
|
|
262
257
|
case "slateblue":
|
|
263
258
|
return "#6a5acd";
|
|
264
259
|
case "slategray":
|
|
265
|
-
return "#708090";
|
|
266
260
|
case "slategrey":
|
|
267
261
|
return "#708090";
|
|
268
262
|
case "snow":
|
|
@@ -301,7 +295,7 @@ const f = (e) => {
|
|
|
301
295
|
const t = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
302
296
|
e = e.replace(
|
|
303
297
|
t,
|
|
304
|
-
(l, a,
|
|
298
|
+
(l, a, c, n) => a + a + c + c + n + n
|
|
305
299
|
);
|
|
306
300
|
const r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);
|
|
307
301
|
if (!r)
|
|
@@ -2366,42 +2366,42 @@ const Hn = {
|
|
|
2366
2366
|
export {
|
|
2367
2367
|
O as $,
|
|
2368
2368
|
Qi as A,
|
|
2369
|
-
|
|
2369
|
+
jn as B,
|
|
2370
2370
|
qi as C,
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2371
|
+
Nn as D,
|
|
2372
|
+
J as E,
|
|
2373
|
+
dh as F,
|
|
2374
|
+
Dn as G,
|
|
2375
|
+
wh as H,
|
|
2376
|
+
Ie as I,
|
|
2377
2377
|
Ks as J,
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2378
|
+
Y as K,
|
|
2379
|
+
jt as L,
|
|
2380
|
+
w as M,
|
|
2381
|
+
En as N,
|
|
2382
|
+
Ji as O,
|
|
2383
|
+
bh as P,
|
|
2384
|
+
Bi as Q,
|
|
2385
|
+
In as R,
|
|
2386
2386
|
Zi as S,
|
|
2387
|
-
|
|
2388
|
-
|
|
2387
|
+
Xi as T,
|
|
2388
|
+
Is as U,
|
|
2389
2389
|
z as V,
|
|
2390
2390
|
Tn as W,
|
|
2391
|
-
|
|
2391
|
+
Qs as X,
|
|
2392
2392
|
On as Y,
|
|
2393
|
-
|
|
2393
|
+
es as Z,
|
|
2394
2394
|
Te as _,
|
|
2395
|
-
|
|
2395
|
+
Wn as a,
|
|
2396
2396
|
en as a$,
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2397
|
+
sh as a0,
|
|
2398
|
+
kn as a1,
|
|
2399
|
+
si as a2,
|
|
2400
|
+
Gt as a3,
|
|
2401
|
+
b as a4,
|
|
2402
|
+
$ as a5,
|
|
2403
|
+
re as a6,
|
|
2404
|
+
Ve as a7,
|
|
2405
2405
|
xh as a8,
|
|
2406
2406
|
F as a9,
|
|
2407
2407
|
fn as aA,
|
|
@@ -2457,7 +2457,7 @@ export {
|
|
|
2457
2457
|
Xh as ax,
|
|
2458
2458
|
Jh as ay,
|
|
2459
2459
|
Qh as az,
|
|
2460
|
-
|
|
2460
|
+
Kn as b,
|
|
2461
2461
|
Oh as b$,
|
|
2462
2462
|
sn as b0,
|
|
2463
2463
|
Rh as b1,
|
|
@@ -2522,7 +2522,7 @@ export {
|
|
|
2522
2522
|
jh as bx,
|
|
2523
2523
|
uh as by,
|
|
2524
2524
|
Ui as bz,
|
|
2525
|
-
|
|
2525
|
+
Hn as c,
|
|
2526
2526
|
d as c0,
|
|
2527
2527
|
Mn as c1,
|
|
2528
2528
|
Pt as c2,
|
|
@@ -2539,27 +2539,27 @@ export {
|
|
|
2539
2539
|
Cn as cd,
|
|
2540
2540
|
Fn as ce,
|
|
2541
2541
|
Zn as cf,
|
|
2542
|
-
|
|
2543
|
-
|
|
2542
|
+
mh as d,
|
|
2543
|
+
ki as e,
|
|
2544
2544
|
qs as f,
|
|
2545
|
-
|
|
2545
|
+
_h as g,
|
|
2546
2546
|
Ue as h,
|
|
2547
2547
|
n as i,
|
|
2548
|
-
|
|
2549
|
-
|
|
2548
|
+
$i as j,
|
|
2549
|
+
Ys as k,
|
|
2550
2550
|
Rs as l,
|
|
2551
2551
|
zh as m,
|
|
2552
2552
|
Bn as n,
|
|
2553
|
-
|
|
2553
|
+
Xe as o,
|
|
2554
2554
|
Hs as p,
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2555
|
+
Ce as q,
|
|
2556
|
+
$n as r,
|
|
2557
|
+
a as s,
|
|
2558
2558
|
pt as t,
|
|
2559
2559
|
Ls as u,
|
|
2560
|
-
|
|
2560
|
+
Sn as v,
|
|
2561
2561
|
Zs as w,
|
|
2562
|
-
|
|
2562
|
+
Pn as x,
|
|
2563
2563
|
Us as y,
|
|
2564
2564
|
ph as z
|
|
2565
2565
|
};
|
|
@@ -1,50 +1,51 @@
|
|
|
1
1
|
import { BaseBlueprint as s } from "./blueprint/base-blueprint.js";
|
|
2
|
-
import { toRefIdOrPoint as
|
|
3
|
-
import { n as
|
|
2
|
+
import { toRefIdOrPoint as r } from "./blueprint/utils.js";
|
|
3
|
+
import { n as c, c as a } from "./constants-CBz0gZS0.js";
|
|
4
4
|
const h = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
5
|
-
let
|
|
5
|
+
let o = (i = 21) => {
|
|
6
6
|
let t = "", e = crypto.getRandomValues(new Uint8Array(i |= 0));
|
|
7
7
|
for (; i--; )
|
|
8
8
|
t += h[e[i] & 63];
|
|
9
9
|
return t;
|
|
10
10
|
};
|
|
11
11
|
class u extends s {
|
|
12
|
-
constructor(t, e,
|
|
13
|
-
super(), this.context = t, this.automaton = e, this.rule =
|
|
12
|
+
constructor(t, e, n) {
|
|
13
|
+
super(), this.context = t, this.automaton = e, this.rule = n;
|
|
14
14
|
}
|
|
15
15
|
condition(t) {
|
|
16
|
-
return this.assertNotCreated(), this.rule.when = [...this.rule.when, t], new
|
|
16
|
+
return this.assertNotCreated(), this.rule.when = [...this.rule.when, t], new l(this.context, this.automaton, this.rule);
|
|
17
17
|
}
|
|
18
|
-
count(t, e
|
|
19
|
-
|
|
18
|
+
count(t, ...e) {
|
|
19
|
+
let n = this.automaton.neighborhood === "cross" ? [1, 2, 3, 4] : [1, 2, 3, 4, 5, 6, 7, 8];
|
|
20
|
+
return e.length !== 0 && (n = e.flat()), this.condition({
|
|
20
21
|
type: "count",
|
|
21
|
-
id:
|
|
22
|
-
check:
|
|
23
|
-
count:
|
|
22
|
+
id: o(),
|
|
23
|
+
check: r(t),
|
|
24
|
+
count: n
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
is(t, e) {
|
|
27
28
|
return this.condition({
|
|
28
29
|
type: "is",
|
|
29
|
-
id:
|
|
30
|
-
compare:
|
|
31
|
-
with:
|
|
30
|
+
id: o(),
|
|
31
|
+
compare: c[t],
|
|
32
|
+
with: r(e)
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
chance(t, e = 100) {
|
|
35
36
|
return t < 0 && (t = 0), e <= 0 && (e = 1), t > e && (t = e), t = Math.floor(t), e = Math.floor(e), this.condition({
|
|
36
37
|
type: "chance",
|
|
37
|
-
id:
|
|
38
|
+
id: o(),
|
|
38
39
|
ratio: { part: t, whole: e }
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
class
|
|
43
|
+
class l extends u {
|
|
43
44
|
accept(t) {
|
|
44
|
-
this.assertNotCreated(), this.rule.accept =
|
|
45
|
+
this.assertNotCreated(), this.rule.accept = a[t];
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
export {
|
|
48
49
|
u as R,
|
|
49
|
-
n
|
|
50
|
+
o as n
|
|
50
51
|
};
|
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
import { TgpuRoot } from 'typegpu';
|
|
2
1
|
import { Automaton } from '../automaton/types';
|
|
2
|
+
import { GpuCondition, GpuElement, GpuRule } from '../common/constants';
|
|
3
3
|
import * as d from "typegpu/data";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
toType: d.U32;
|
|
13
|
-
toId: d.U32;
|
|
14
|
-
toNeighbor: d.Vec2u;
|
|
15
|
-
accept: d.U32;
|
|
16
|
-
conditionsStart: d.U32;
|
|
17
|
-
conditionsEnd: d.U32;
|
|
18
|
-
}>>> & import('typegpu').StorageFlag;
|
|
19
|
-
conditions: import('typegpu').TgpuBuffer<d.WgslArray<d.WgslStruct<{
|
|
20
|
-
opcode: d.U32;
|
|
21
|
-
checkId: d.U32;
|
|
22
|
-
countOrWithId: d.U32;
|
|
23
|
-
checkPointOrComparePoint: d.Vec2u;
|
|
24
|
-
withPoint: d.Vec2u;
|
|
25
|
-
chance: d.F32;
|
|
26
|
-
}>>> & import('typegpu').StorageFlag;
|
|
4
|
+
type GpuRuleType = d.Infer<typeof GpuRule>;
|
|
5
|
+
type GpuElementType = d.Infer<typeof GpuElement>;
|
|
6
|
+
type GpuConditionType = d.Infer<typeof GpuCondition>;
|
|
7
|
+
export type GpuAutomaton = {
|
|
8
|
+
gpuNeighborhood: number;
|
|
9
|
+
gpuElements: GpuElementType[];
|
|
10
|
+
gpuRules: GpuRuleType[];
|
|
11
|
+
gpuConditions: GpuConditionType[];
|
|
27
12
|
};
|
|
13
|
+
export declare const compileGpuAutomaton: (automaton: Automaton) => GpuAutomaton;
|
|
14
|
+
export {};
|
package/dist/webgpu/compiler.js
CHANGED
|
@@ -1,6 +1,129 @@
|
|
|
1
|
-
import "../constants-
|
|
2
|
-
import "../common/utils.js";
|
|
3
|
-
|
|
1
|
+
import { G as N, a as O, K as I, T as u, b as k, O as m } from "../constants-CBz0gZS0.js";
|
|
2
|
+
import { colorToABGR as g } from "../common/utils.js";
|
|
3
|
+
const T = (n) => {
|
|
4
|
+
if (n.some((t) => t > 31))
|
|
5
|
+
throw console.warn(
|
|
6
|
+
`Elements with an index greater than 31 and extending one or more kinds are not allowed when they are involved in conditions referencing kinds.
|
|
7
|
+
To assign a lower index, move the elements with extensions higher in the definition list or reduce the overall number of elements and kinds.`
|
|
8
|
+
), new Error(
|
|
9
|
+
"Element in condition involving kinds has an index greater than 31"
|
|
10
|
+
);
|
|
11
|
+
}, P = (n, t, f) => {
|
|
12
|
+
const { elements: h } = f, p = h.findIndex((r) => r.id === n);
|
|
13
|
+
if (p !== -1)
|
|
14
|
+
t.opcode = m.COUNT_ELEMENT, t.checkId = p;
|
|
15
|
+
else {
|
|
16
|
+
const r = h.map((s, d) => ({ ...s, index: d })).filter(
|
|
17
|
+
(s) => s.extensions.some((d) => d === n)
|
|
18
|
+
).map((s) => s.index);
|
|
19
|
+
T(r);
|
|
20
|
+
const c = r.reduce((s, d) => (s |= 1 << d, s), 0);
|
|
21
|
+
t.checkId = c, t.opcode = m.COUNT_KIND;
|
|
22
|
+
}
|
|
23
|
+
}, _ = (n, t) => {
|
|
24
|
+
t.opcode = m.COUNT_POINT, t.checkPointOrComparePoint = I(n.x, n.y);
|
|
25
|
+
}, S = (n, t, f) => {
|
|
26
|
+
const { check: h, count: p } = n;
|
|
27
|
+
if (typeof h > "u")
|
|
28
|
+
throw new Error("condition.check is undefined");
|
|
29
|
+
typeof h == "string" ? P(h, t, f) : _(h, t), t.countOrWithId = p.reduce(
|
|
30
|
+
// Packing numbers as positional bits.
|
|
31
|
+
// Example: [2, 3] -> 0b000001100
|
|
32
|
+
(r, c) => (r |= 1 << c, r),
|
|
33
|
+
0
|
|
34
|
+
);
|
|
35
|
+
}, M = (n, t, f) => {
|
|
36
|
+
const h = n.compare;
|
|
37
|
+
if (typeof h > "u")
|
|
38
|
+
throw new Error("condition.compare is undefined");
|
|
39
|
+
if (typeof n.with > "u")
|
|
40
|
+
throw new Error("condition.with is undefined");
|
|
41
|
+
if (t.checkPointOrComparePoint = I(
|
|
42
|
+
h.x,
|
|
43
|
+
h.y
|
|
44
|
+
), typeof n.with == "string") {
|
|
45
|
+
const p = n.with;
|
|
46
|
+
if (f.elements.some((r) => r.id === p)) {
|
|
47
|
+
t.opcode = m.IS_ELEMENT;
|
|
48
|
+
const r = f.elements.findIndex(
|
|
49
|
+
(c) => c.id === p
|
|
50
|
+
);
|
|
51
|
+
t.countOrWithId = r;
|
|
52
|
+
} else {
|
|
53
|
+
const r = f.elements.map((s, d) => ({ ...s, index: d })).filter(
|
|
54
|
+
(s) => s.extensions.some((d) => d === p)
|
|
55
|
+
).map((s) => s.index);
|
|
56
|
+
T(r);
|
|
57
|
+
const c = r.reduce((s, d) => (s |= 1 << d, s), 0);
|
|
58
|
+
t.countOrWithId = c, t.opcode = m.IS_KIND;
|
|
59
|
+
}
|
|
60
|
+
} else
|
|
61
|
+
t.opcode = m.IS_POINT, t.withPoint = I(n.with.x, n.with.y);
|
|
62
|
+
}, G = (n) => {
|
|
63
|
+
const { elements: t, rules: f } = n, h = f.filter((e) => e.fromType === "element").reduce(
|
|
64
|
+
(e, o) => {
|
|
65
|
+
const l = t.findIndex(
|
|
66
|
+
(i) => i.id === o.fromId
|
|
67
|
+
);
|
|
68
|
+
return e[l].push(o), e;
|
|
69
|
+
},
|
|
70
|
+
t.map(() => [])
|
|
71
|
+
), p = f.filter((e) => e.fromType === "kind").reduce((e, o) => (t.forEach((l, i) => {
|
|
72
|
+
l.extensions.includes(o.fromId) && e[i].push(o);
|
|
73
|
+
}), e), h), r = [];
|
|
74
|
+
let c = [];
|
|
75
|
+
const s = /* @__PURE__ */ new Map();
|
|
76
|
+
p.forEach((e) => {
|
|
77
|
+
e.forEach((o, l) => {
|
|
78
|
+
let i, a;
|
|
79
|
+
const w = `${o.fromId}:${l.toString()}`;
|
|
80
|
+
o.fromType === "kind" && s.has(w) ? [i, a] = s.get(w) : (i = c.length, Array.isArray(o.when) ? c = c.concat(o.when) : c = c.concat([o.when]), a = c.length, s.set(w, [i, a])), r.push({
|
|
81
|
+
...o,
|
|
82
|
+
conditionsStart: i,
|
|
83
|
+
conditionsEnd: a
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
const d = [], y = [], x = [];
|
|
88
|
+
let E = 0;
|
|
89
|
+
return t.forEach((e, o) => {
|
|
90
|
+
const l = E, i = E + p[o].length;
|
|
91
|
+
E = i;
|
|
92
|
+
const a = N({
|
|
93
|
+
color: g(e.color),
|
|
94
|
+
ruleStart: l,
|
|
95
|
+
ruleEnd: i
|
|
96
|
+
});
|
|
97
|
+
d.push(a);
|
|
98
|
+
}), r.forEach((e) => {
|
|
99
|
+
const { conditionsStart: o, conditionsEnd: l } = e, i = O({
|
|
100
|
+
toType: u.ELEMENT_ID,
|
|
101
|
+
toId: 0,
|
|
102
|
+
toNeighbor: I(),
|
|
103
|
+
conditionsStart: o,
|
|
104
|
+
conditionsEnd: l,
|
|
105
|
+
accept: e.accept
|
|
106
|
+
});
|
|
107
|
+
if (y.push(i), typeof e.to > "u")
|
|
108
|
+
throw new Error("rule.to is undefined");
|
|
109
|
+
typeof e.to == "string" ? (i.toType = u.ELEMENT_ID, i.toId = t.findIndex((a) => a.id === e.to)) : (i.toType = u.POINT, i.toNeighbor = I(e.to.x, e.to.y));
|
|
110
|
+
}), c.forEach((e) => {
|
|
111
|
+
const o = k({
|
|
112
|
+
opcode: m.NOOP,
|
|
113
|
+
checkId: 0,
|
|
114
|
+
countOrWithId: 0,
|
|
115
|
+
checkPointOrComparePoint: I(),
|
|
116
|
+
withPoint: I(),
|
|
117
|
+
chance: 0
|
|
118
|
+
});
|
|
119
|
+
x.push(o), e.type === "count" ? S(e, o, n) : e.type === "is" ? M(e, o, n) : (o.opcode = m.CHANCE, o.chance = e.ratio.part / e.ratio.whole);
|
|
120
|
+
}), {
|
|
121
|
+
gpuNeighborhood: n.neighborhood === "cross" ? 4 : 8,
|
|
122
|
+
gpuElements: d,
|
|
123
|
+
gpuRules: y,
|
|
124
|
+
gpuConditions: x
|
|
125
|
+
};
|
|
126
|
+
};
|
|
4
127
|
export {
|
|
5
|
-
|
|
128
|
+
G as compileGpuAutomaton
|
|
6
129
|
};
|