@wildshard/shard-format 0.15.0 → 0.17.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/package.json +36 -3
- package/src/format/assetAdmission.ts +5 -2
- package/src/format/baked-terrain.golden.json +2760 -0
- package/src/format/colliders.golden.json +1619 -0
- package/src/format/colliders.ts +568 -0
- package/src/format/contentBounds.ts +6 -0
- package/src/format/creature-perch-admission.ts +86 -0
- package/src/format/creature-perch.ts +269 -0
- package/src/format/creatures.ts +11 -8
- package/src/format/forest-placement.golden.json +4588 -0
- package/src/format/forest-placement.ts +385 -0
- package/src/format/geometry-layout.golden.json +180 -0
- package/src/format/grass-field.ts +287 -0
- package/src/format/headless-sections.ts +49 -0
- package/src/format/interact-table.golden.json +340 -0
- package/src/format/interact-table.ts +541 -0
- package/src/format/item-catalogue.golden.json +2310 -0
- package/src/format/item-catalogue.ts +148 -0
- package/src/format/mover-pose.ts +46 -0
- package/src/format/native-geometry-channels.ts +64 -0
- package/src/format/noise.ts +106 -0
- package/src/format/road-light.ts +47 -0
- package/src/format/seeded-rng.golden.json +857 -0
- package/src/format/seeded-rng.ts +111 -0
- package/src/format/shardSchema.ts +3 -0
- package/src/format/small-laws.golden.json +57 -0
- package/src/format/terrain-field.golden.json +3998 -0
- package/src/format/terrain-field.ts +405 -0
- package/src/format/whole-partition.ts +170 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* oxlint-disable capitalized-comments, curly, id-length, import/exports-last, import/group-exports, no-bitwise, no-inline-comments, no-magic-numbers, no-plusplus, no-use-before-define, typescript/explicit-member-accessibility, typescript/no-unsafe-type-assertion, typescript/prefer-readonly-parameter-types, unicorn/number-literal-case, unicorn/numeric-separators-style, unicorn/prefer-at -- verbatim port of the engine's law (SDK-SPLIT SP4); bit-exact output is pinned by golden vectors, so it keeps the engine's form */
|
|
2
|
+
/** SDK-SPLIT SP4a (Q35): the seeded RNG both the bake and the engine draw from, so their draws agree bit for bit.
|
|
3
|
+
* Moved from engine `shared/engine/core/rng.ts` (its named-stream service and page salt stay in the engine, which
|
|
4
|
+
* builds them on this). `seeded-rng.golden.json` holds the engine's own draws as float64 bits. */
|
|
5
|
+
|
|
6
|
+
/** Mulberry32 continuation, including fork seed and the legacy scrambled-fork mode. */
|
|
7
|
+
export interface RngState {
|
|
8
|
+
version: number
|
|
9
|
+
state: number
|
|
10
|
+
initial: number
|
|
11
|
+
scrambledFork: boolean
|
|
12
|
+
}
|
|
13
|
+
/** Public seeded draws and continuation; independent of a generator's private storage. */
|
|
14
|
+
export interface RngPort {
|
|
15
|
+
readonly next: () => number
|
|
16
|
+
readonly range: (a: number, b: number) => number
|
|
17
|
+
readonly int: (a: number, b: number) => number
|
|
18
|
+
readonly pick: <T>(arr: readonly T[]) => T
|
|
19
|
+
readonly chance: (p: number) => boolean
|
|
20
|
+
readonly weighted: <T>(pairs: readonly (readonly [T, number])[]) => T
|
|
21
|
+
readonly fork: (salt: number | string) => RngPort
|
|
22
|
+
readonly snapshot: () => RngState
|
|
23
|
+
readonly restore: (state: RngState) => void
|
|
24
|
+
}
|
|
25
|
+
const uint32 = (value: number): boolean =>
|
|
26
|
+
Number.isInteger(value) && value >= 0 && value <= 0xffffffff
|
|
27
|
+
/** Throws a RangeError unless `state` is a version-1 continuation of uint32 words. */
|
|
28
|
+
export function validateRngState(state: RngState): void {
|
|
29
|
+
if (
|
|
30
|
+
state.version !== 1 ||
|
|
31
|
+
!uint32(state.state) ||
|
|
32
|
+
!uint32(state.initial) ||
|
|
33
|
+
typeof state.scrambledFork !== 'boolean'
|
|
34
|
+
)
|
|
35
|
+
throw new RangeError('Invalid RNG snapshot')
|
|
36
|
+
}
|
|
37
|
+
/** Deterministic PRNG (mulberry32) so every playtest sees the same chunk. */
|
|
38
|
+
export class Rng implements RngPort {
|
|
39
|
+
private s: number
|
|
40
|
+
private initial: number
|
|
41
|
+
private scrambledFork = false
|
|
42
|
+
constructor(seed: number) {
|
|
43
|
+
this.s = seed >>> 0
|
|
44
|
+
this.initial = this.s
|
|
45
|
+
}
|
|
46
|
+
snapshot(): RngState {
|
|
47
|
+
return {
|
|
48
|
+
version: 1,
|
|
49
|
+
state: this.s,
|
|
50
|
+
initial: this.initial,
|
|
51
|
+
scrambledFork: this.scrambledFork,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
restore(state: RngState): void {
|
|
55
|
+
validateRngState(state)
|
|
56
|
+
this.s = state.state
|
|
57
|
+
this.initial = state.initial
|
|
58
|
+
this.scrambledFork = state.scrambledFork
|
|
59
|
+
}
|
|
60
|
+
/** Preserve the facade grammar's multiplicative constructor and numeric forks. */
|
|
61
|
+
static scrambled(seed: number): Rng {
|
|
62
|
+
const rng = new Rng((seed * 2654435761) >>> 0)
|
|
63
|
+
rng.scrambledFork = true
|
|
64
|
+
return rng
|
|
65
|
+
}
|
|
66
|
+
next(): number {
|
|
67
|
+
this.s = (this.s + 0x6d2b79f5) >>> 0
|
|
68
|
+
let t = this.s
|
|
69
|
+
t = Math.imul(t ^ (t >>> 15), t | 1)
|
|
70
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
|
|
71
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
|
|
72
|
+
}
|
|
73
|
+
range(a: number, b: number): number {
|
|
74
|
+
return a + (b - a) * this.next()
|
|
75
|
+
}
|
|
76
|
+
int(a: number, b: number): number {
|
|
77
|
+
return Math.floor(this.range(a, b + 1))
|
|
78
|
+
}
|
|
79
|
+
pick<T>(arr: readonly T[]): T {
|
|
80
|
+
return arr[Math.floor(this.next() * arr.length)] as T
|
|
81
|
+
} // an empty list yields undefined, as it always did
|
|
82
|
+
chance(p: number): boolean {
|
|
83
|
+
return this.next() < p
|
|
84
|
+
}
|
|
85
|
+
weighted<T>(pairs: readonly (readonly [T, number])[]): T {
|
|
86
|
+
let sum = 0
|
|
87
|
+
for (const [, weight] of pairs) sum += weight
|
|
88
|
+
let r = this.next() * sum
|
|
89
|
+
for (const [item, weight] of pairs) {
|
|
90
|
+
r -= weight
|
|
91
|
+
if (r <= 0) return item
|
|
92
|
+
}
|
|
93
|
+
const last = pairs[pairs.length - 1]
|
|
94
|
+
if (last === undefined) throw new Error('Rng.weighted on an empty list')
|
|
95
|
+
return last[0]
|
|
96
|
+
}
|
|
97
|
+
fork(salt: number | string): Rng {
|
|
98
|
+
if (typeof salt === 'string')
|
|
99
|
+
return new Rng(fnv1a32(`${String(this.initial)}:${salt}`))
|
|
100
|
+
const seed = (this.s ^ Math.imul(salt + 1, 0x9e3779b1)) >>> 0
|
|
101
|
+
return this.scrambledFork ? Rng.scrambled(seed) : new Rng(seed)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 32-bit FNV-1a over a string's code points (the string-fork and named-stream seed hash). */
|
|
106
|
+
export function fnv1a32(text: string): number {
|
|
107
|
+
let hash = 0x811c9dc5
|
|
108
|
+
for (let i = 0; i < text.length; i++)
|
|
109
|
+
hash = Math.imul(hash ^ (text.codePointAt(i) ?? 0), 0x01000193)
|
|
110
|
+
return hash >>> 0
|
|
111
|
+
}
|
|
@@ -346,6 +346,9 @@ export function shardfileRules(s: Shardfile, sections?: ReadonlyMap<string, unkn
|
|
|
346
346
|
if (s.terrain?.sampling !== undefined && s.meshCollision !== null) errors.push('terrain sampling and mesh ground are mutually exclusive');
|
|
347
347
|
if (s.look.families.some((family) => !materialExists({}, family)) || (s.terrain !== null && s.terrain.form !== 'query' && !materialExists(s.look.materials, s.terrain.family)) || s.rows.looks.some((row) => row.material !== null && !materialExists(s.look.materials, row.material))) errors.push('declared platform material family');
|
|
348
348
|
const species = new Map(s.rows.species.map((row) => [row.id, row])), strikes = new Map(s.rows.strikes.map((row) => [row.id, row]));
|
|
349
|
+
for (const row of s.creatures.perchBodies ?? []) {
|
|
350
|
+
if (!strikes.has(row.policy.strike) || !strikes.has(row.projectile.strike)) { errors.push('declared perch body strikes'); }
|
|
351
|
+
}
|
|
349
352
|
for (const brain of s.creatures.brains) if (brain.kind === 'script' && (!s.sim.scripts.includes(brain.module) || brain.strikes.some((request) => !strikes.has(request.strike)))) errors.push('declared custom brain module and strikes');
|
|
350
353
|
for (const declared of s.creatures.brains) {
|
|
351
354
|
const brain = declared.kind === 'grazer' ? grazerPreset(declared) : declared.kind === 'diver' ? diverPreset(declared) : declared;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"about": "SDK-SPLIT SP4f1: engine host/headlessSections.ts, grid/frameModel.ts ROAD_SKY, grid/farView.ts FAR_CLIFF_FLOOR and plugin/clientChannelView.ts moverChannelValues over small-laws.golden-specs.ts",
|
|
3
|
+
"sectionNames": [
|
|
4
|
+
"actors/species-programs",
|
|
5
|
+
"view/modules",
|
|
6
|
+
"sim/scripts",
|
|
7
|
+
"actors/spawn-scripts",
|
|
8
|
+
"actors/return-scripts",
|
|
9
|
+
"actors/moves",
|
|
10
|
+
"actors/strikes",
|
|
11
|
+
"world/targets",
|
|
12
|
+
"sim/runtime-plan",
|
|
13
|
+
"sim/bodies"
|
|
14
|
+
],
|
|
15
|
+
"sections": [
|
|
16
|
+
[{ "ok": [] }, { "ok": [] }],
|
|
17
|
+
[
|
|
18
|
+
{ "ok": [["world/targets", { "targets": [], "spots": [] }]] },
|
|
19
|
+
{ "ok": [["world/targets", { "targets": [], "spots": [] }]] }
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
{ "error": "Invalid type: Expected Object but received \"nope\"" },
|
|
23
|
+
{ "error": "Invalid type: Expected Object but received \"nope\"" }
|
|
24
|
+
]
|
|
25
|
+
],
|
|
26
|
+
"roadSky": {
|
|
27
|
+
"air": [0.95, 0.56, 0.44],
|
|
28
|
+
"mid": [0.58, 0.46, 0.8],
|
|
29
|
+
"zenith": [0.1, 0.24, 0.72],
|
|
30
|
+
"line": [0.25, 1.1, 1.4],
|
|
31
|
+
"grid": [0.3, 0.85, 1.1],
|
|
32
|
+
"gridStrength": 0.3,
|
|
33
|
+
"void": [0.17, 0.17, 0.27],
|
|
34
|
+
"sun": {
|
|
35
|
+
"azimuth": 70,
|
|
36
|
+
"elevation": 13,
|
|
37
|
+
"colour": [1, 0.8, 0.66],
|
|
38
|
+
"intensity": 2.4,
|
|
39
|
+
"glow": [1, 0.62, 0.42]
|
|
40
|
+
},
|
|
41
|
+
"hemi": {
|
|
42
|
+
"sky": [0.6, 0.62, 0.86],
|
|
43
|
+
"ground": [0.42, 0.36, 0.34],
|
|
44
|
+
"intensity": 1.1
|
|
45
|
+
},
|
|
46
|
+
"env": 0.7,
|
|
47
|
+
"fogSun": [1, 0.72, 0.56]
|
|
48
|
+
},
|
|
49
|
+
"farCliffFloor": 0.8,
|
|
50
|
+
"mover": [
|
|
51
|
+
{ "ok": [1, 1.5, -2, 3.25, 0.1, -0.2, 0.3] },
|
|
52
|
+
{ "ok": [0.5, -7, 0] },
|
|
53
|
+
{ "error": "Missing copied mover field" },
|
|
54
|
+
{ "error": "Missing copied mover field" },
|
|
55
|
+
{ "error": "Missing copied mover field" }
|
|
56
|
+
]
|
|
57
|
+
}
|