@wonderyard/vivarium 1.4.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Helpers } from './blueprint/helpers';
2
- export { ElementBlueprint, KindBlueprint, RefBlueprint, } from './blueprint/ref-blueprint';
3
- export { RuleBlueprint, RuleBlueprintWithAccept, } from './blueprint/rule-blueprint';
2
+ export { ElementBlueprint, KindBlueprint, RefBlueprint } from './blueprint/ref-blueprint';
3
+ export { RuleBlueprint, RuleBlueprintWithAccept } from './blueprint/rule-blueprint';
4
4
  export { VivariumBlueprint } from './blueprint/vivarium-blueprint';
5
5
  export { vivarium } from './vivarium/vivarium';
6
6
  export { setup } from './webgpu/setup';
package/dist/main.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Helpers as t } from "./blueprint/helpers.js";
2
2
  import { ElementBlueprint as i, KindBlueprint as o, RefBlueprint as u } from "./blueprint/ref-blueprint.js";
3
- import { R as m, a as n } from "./rule-blueprint-DGODv9IV.js";
3
+ import { R as m, a as n } from "./rule-blueprint-C9qa6iP-.js";
4
4
  import { VivariumBlueprint as x } from "./blueprint/vivarium-blueprint.js";
5
5
  import { vivarium as a } from "./vivarium/vivarium.js";
6
6
  import { setup as R } from "./webgpu/setup.js";
@@ -1,6 +1,6 @@
1
1
  import { BaseBlueprint as r } from "./blueprint/base-blueprint.js";
2
2
  import { toRefIdOrPoint as s } from "./blueprint/utils.js";
3
- import { n as c, c as a } from "./constants-D4GX9YB2.js";
3
+ import { n as c, c as a } from "./constants-BT-9-x_4.js";
4
4
  const h = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
5
5
  let o = (i = 21) => {
6
6
  let t = "", e = crypto.getRandomValues(new Uint8Array(i |= 0));
@@ -4,6 +4,9 @@ import { VivariumBlueprint } from '../blueprint/vivarium-blueprint';
4
4
  * Creates a new vivarium builder used to define elements, kinds, and rules.
5
5
  *
6
6
  * @param neighborhoodName - The neighborhood type to use. Defaults to `"square"` (Moore neighborhood, 8 neighbors). Use `"cross"` for a von Neumann neighborhood (4 neighbors).
7
+ * @param options - Optional configuration object. Use `{ wrapping: true }` to enable toroidal grid wrapping. Defaults to non-wrapping.
7
8
  * @returns A {@link VivariumBlueprint} instance.
8
9
  */
9
- export declare function vivarium<N extends Neighborhood = "square">(neighborhoodName?: N): VivariumBlueprint<N>;
10
+ export declare function vivarium<N extends Neighborhood = "square">(neighborhoodName?: N, options?: {
11
+ wrapping?: boolean;
12
+ }): VivariumBlueprint<N>;
@@ -1,7 +1,7 @@
1
- import { VivariumBlueprint as i } from "../blueprint/vivarium-blueprint.js";
2
- function t(r) {
3
- return new i(r);
1
+ import { VivariumBlueprint as n } from "../blueprint/vivarium-blueprint.js";
2
+ function u(r, i) {
3
+ return new n(r, i);
4
4
  }
5
5
  export {
6
- t as vivarium
6
+ u as vivarium
7
7
  };
@@ -4,8 +4,9 @@ import * as d from "typegpu/data";
4
4
  type GpuRuleType = d.Infer<typeof GpuRule>;
5
5
  type GpuElementType = d.Infer<typeof GpuElement>;
6
6
  type GpuConditionType = d.Infer<typeof GpuCondition>;
7
+ type GpuNeighborhoodType = 0 | 1;
7
8
  export type GpuAutomaton = {
8
- gpuNeighborhood: number;
9
+ gpuNeighborhood: GpuNeighborhoodType;
9
10
  gpuElements: GpuElementType[];
10
11
  gpuRules: GpuRuleType[];
11
12
  gpuConditions: GpuConditionType[];
@@ -1,29 +1,25 @@
1
- import { G as N, a as O, T as u, l as I, b as k, O as m } from "../constants-D4GX9YB2.js";
1
+ import { G as N, a as O, T as u, v as I, b as k, O as m } from "../constants-BT-9-x_4.js";
2
2
  import { colorToABGR as g } from "../common/utils.js";
3
- const T = (n) => {
4
- if (n.some((t) => t > 31))
3
+ const T = (o) => {
4
+ if (o.some((t) => t > 31))
5
5
  throw console.warn(
6
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
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);
8
+ ), new Error("Element in condition involving kinds has an index greater than 31");
9
+ }, P = (o, t, f) => {
10
+ const { elements: h } = f, p = h.findIndex((r) => r.id === o);
13
11
  if (p !== -1)
14
12
  t.opcode = m.COUNT_ELEMENT, t.checkId = p;
15
13
  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);
14
+ const r = h.map((s, d) => ({ ...s, index: d })).filter((s) => s.extensions.some((d) => d === o)).map((s) => s.index);
19
15
  T(r);
20
16
  const c = r.reduce((s, d) => (s |= 1 << d, s), 0);
21
17
  t.checkId = c, t.opcode = m.COUNT_KIND;
22
18
  }
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;
19
+ }, _ = (o, t) => {
20
+ t.opcode = m.COUNT_POINT, t.checkPointOrComparePoint = I(o.x, o.y);
21
+ }, v = (o, t, f) => {
22
+ const { check: h, count: p } = o;
27
23
  if (typeof h > "u")
28
24
  throw new Error("condition.check is undefined");
29
25
  typeof h == "string" ? P(h, t, f) : _(h, t), t.countOrWithId = p.reduce(
@@ -32,53 +28,44 @@ To assign a lower index, move the elements with extensions higher in the definit
32
28
  (r, c) => (r |= 1 << c, r),
33
29
  0
34
30
  );
35
- }, M = (n, t, f) => {
36
- const h = n.compare;
31
+ }, S = (o, t, f) => {
32
+ const h = o.compare;
37
33
  if (typeof h > "u")
38
34
  throw new Error("condition.compare is undefined");
39
- if (typeof n.with > "u")
35
+ if (typeof o.with > "u")
40
36
  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;
37
+ if (t.checkPointOrComparePoint = I(h.x, h.y), typeof o.with == "string") {
38
+ const p = o.with;
46
39
  if (f.elements.some((r) => r.id === p)) {
47
40
  t.opcode = m.IS_ELEMENT;
48
- const r = f.elements.findIndex(
49
- (c) => c.id === p
50
- );
41
+ const r = f.elements.findIndex((c) => c.id === p);
51
42
  t.countOrWithId = r;
52
43
  } 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);
44
+ const r = f.elements.map((s, d) => ({ ...s, index: d })).filter((s) => s.extensions.some((d) => d === p)).map((s) => s.index);
56
45
  T(r);
57
46
  const c = r.reduce((s, d) => (s |= 1 << d, s), 0);
58
47
  t.countOrWithId = c, t.opcode = m.IS_KIND;
59
48
  }
60
49
  } 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;
50
+ t.opcode = m.IS_POINT, t.withPoint = I(o.with.x, o.with.y);
51
+ }, G = (o) => {
52
+ const { elements: t, rules: f } = o, h = f.filter((e) => e.fromType === "element").reduce(
53
+ (e, n) => {
54
+ const l = t.findIndex((i) => i.id === n.fromId);
55
+ return e[l].push(n), e;
69
56
  },
70
57
  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);
58
+ ), p = f.filter((e) => e.fromType === "kind").reduce((e, n) => (t.forEach((l, i) => {
59
+ l.extensions.includes(n.fromId) && e[i].push(n);
73
60
  }), e), h), r = [];
74
61
  let c = [];
75
62
  const s = /* @__PURE__ */ new Map();
76
63
  p.forEach((e) => {
77
- e.forEach((o, l) => {
64
+ e.forEach((n, l) => {
78
65
  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,
66
+ const w = `${n.fromId}:${l.toString()}`;
67
+ n.fromType === "kind" && s.has(w) ? [i, a] = s.get(w) : (i = c.length, Array.isArray(n.when) ? c = c.concat(n.when) : c = c.concat([n.when]), a = c.length, s.set(w, [i, a])), r.push({
68
+ ...n,
82
69
  conditionsStart: i,
83
70
  conditionsEnd: a
84
71
  });
@@ -86,8 +73,8 @@ To assign a lower index, move the elements with extensions higher in the definit
86
73
  });
87
74
  const d = [], y = [], x = [];
88
75
  let E = 0;
89
- return t.forEach((e, o) => {
90
- const l = E, i = E + p[o].length;
76
+ return t.forEach((e, n) => {
77
+ const l = E, i = E + p[n].length;
91
78
  E = i;
92
79
  const a = N({
93
80
  color: g(e.color),
@@ -96,11 +83,11 @@ To assign a lower index, move the elements with extensions higher in the definit
96
83
  });
97
84
  d.push(a);
98
85
  }), r.forEach((e) => {
99
- const { conditionsStart: o, conditionsEnd: l } = e, i = O({
86
+ const { conditionsStart: n, conditionsEnd: l } = e, i = O({
100
87
  toType: u.ELEMENT_ID,
101
88
  toId: 0,
102
89
  toNeighbor: I(),
103
- conditionsStart: o,
90
+ conditionsStart: n,
104
91
  conditionsEnd: l,
105
92
  accept: e.accept
106
93
  });
@@ -108,7 +95,7 @@ To assign a lower index, move the elements with extensions higher in the definit
108
95
  throw new Error("rule.to is undefined");
109
96
  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
97
  }), c.forEach((e) => {
111
- const o = k({
98
+ const n = k({
112
99
  opcode: m.NOOP,
113
100
  checkId: 0,
114
101
  countOrWithId: 0,
@@ -116,9 +103,9 @@ To assign a lower index, move the elements with extensions higher in the definit
116
103
  withPoint: I(),
117
104
  chance: 0
118
105
  });
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);
106
+ x.push(n), e.type === "count" ? v(e, n, o) : e.type === "is" ? S(e, n, o) : (n.opcode = m.CHANCE, n.chance = e.ratio.part / e.ratio.whole);
120
107
  }), {
121
- gpuNeighborhood: n.neighborhood === "cross" ? 4 : 8,
108
+ gpuNeighborhood: o.neighborhood === "square" ? 1 : 0,
122
109
  gpuElements: d,
123
110
  gpuRules: y,
124
111
  gpuConditions: x
@@ -1,11 +1,14 @@
1
- import { TgpuUniform } from 'typegpu';
2
1
  import { Automaton } from '../automaton/types';
2
+ import { TgpuUniform } from 'typegpu';
3
3
  import * as d from "typegpu/data";
4
4
  export declare const setSeed: (s: TgpuUniform<d.F32>) => void;
5
5
  export declare const gridLayout: import('typegpu').TgpuBindGroupLayout<{
6
6
  dimensions: {
7
7
  uniform: d.Vec2u;
8
8
  };
9
+ wrapping: {
10
+ uniform: d.U32;
11
+ };
9
12
  colors: {
10
13
  storage: (elementCount: number) => d.WgslArray<d.U32>;
11
14
  access: "mutable";
@@ -58,7 +61,7 @@ export declare const automatonLayout: import('typegpu').TgpuBindGroupLayout<{
58
61
  access: "readonly";
59
62
  };
60
63
  }>;
61
- export declare const mainCompute: import('typegpu').TgpuComputeFn<{
64
+ export declare const compute: import('typegpu').TgpuComputeFn<{
62
65
  pos: d.BuiltinGlobalInvocationId;
63
66
  }>;
64
67
  /**