Merge remote-tracking branch 'origin/worktree-agent-a2bb16cfb9ff4be19' into t3code/rewrite-minecraft-rust
# Conflicts: # tools/prepare_native_client.py
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare Rust structure starts (chunkgen_bench --starts) with the vanilla oracle.
|
||||
|
||||
usage: compare_structure_starts.py VANILLA RUST [--all]
|
||||
Pieces are compared by type, bounding box and (for jigsaw pieces) position,
|
||||
rotation, ground level delta and junction count. Without --all, vanilla
|
||||
starts of structure types Rust does not generate yet are only counted.
|
||||
"""
|
||||
import collections
|
||||
import sys
|
||||
|
||||
|
||||
def load(path):
|
||||
starts = {}
|
||||
current = None
|
||||
for line in open(path):
|
||||
t = line.split()
|
||||
if not t:
|
||||
continue
|
||||
if t[0] == 'start':
|
||||
current = (int(t[1]), int(t[2]), t[3])
|
||||
starts[current] = [' '.join(t[4:])]
|
||||
elif t[0] == 'piece' and current:
|
||||
starts[current].append(' '.join(t[1:14]))
|
||||
return starts
|
||||
|
||||
|
||||
def main():
|
||||
vanilla, rust = load(sys.argv[1]), load(sys.argv[2])
|
||||
generated = {k[2] for k in rust}
|
||||
matched = 0
|
||||
missing = collections.Counter()
|
||||
for key in sorted(vanilla):
|
||||
if key not in rust:
|
||||
missing[key[2]] += 1
|
||||
if key[2] in generated or '--all' in sys.argv:
|
||||
print('missing', key)
|
||||
continue
|
||||
if vanilla[key] == rust[key]:
|
||||
matched += 1
|
||||
continue
|
||||
v, r = vanilla[key], rust[key]
|
||||
print('DIFF', key, 'pieces', len(v) - 1, len(r) - 1)
|
||||
for i, (a, b) in enumerate(zip(v, r)):
|
||||
if a != b:
|
||||
print(' first difference at line', i, '\n vanilla', a, '\n rust ', b)
|
||||
break
|
||||
for key in sorted(set(rust) - set(vanilla)):
|
||||
print('extra', key)
|
||||
print(f'{matched} of {len(vanilla)} vanilla starts match exactly; not generated by Rust:', dict(missing))
|
||||
return 0 if matched == len(rust) == sum(1 for k in vanilla if k[2] in generated) else 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
@@ -21,13 +21,44 @@ WORLDGEN_BUNDLES = {
|
||||
'biomes': 'worldgen/biome', 'world_presets': 'worldgen/world_preset', 'features': 'worldgen/feature',
|
||||
'placed_features': 'worldgen/placed_feature', 'state_providers': 'worldgen/block_state_provider',
|
||||
'biome_tags': 'tags/worldgen/biome', 'feature_tags': 'tags/worldgen/feature', 'block_tags': 'tags/block',
|
||||
'fluid_tags': 'tags/fluid'}
|
||||
'fluid_tags': 'tags/fluid', 'processor_lists': 'worldgen/processor_list',
|
||||
'template_pools': 'worldgen/template_pool', 'structures': 'worldgen/structure',
|
||||
'structure_sets': 'worldgen/structure_set'}
|
||||
|
||||
|
||||
def prepare_worldgen(root, jars, local):
|
||||
def export_structure_blocks(target, jars, libraries):
|
||||
"""Run the vanilla exporter of per-state rotate/mirror results and template flags."""
|
||||
lock = json.loads((lab.ROOT/'research-lock.json').read_text())
|
||||
source = lab.ROOT/'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaStructureBlockExporter.java'
|
||||
export = lab.LOCAL/'horizon-client-structures'
|
||||
classes = export/'classes'
|
||||
classes.mkdir(parents=True, exist_ok=True)
|
||||
dependencies = os.pathsep.join(map(str, [jars['server'], *libraries]))
|
||||
with (export/'export.log').open('w') as log:
|
||||
subprocess.run(['javac', '--release', str(lock['minecraft']['java_major']), '-proc:none', '-cp', dependencies,
|
||||
'-d', str(classes), str(source)], check=True, stdout=log, stderr=subprocess.STDOUT, timeout=3600)
|
||||
subprocess.run(['java', '-Xmx1G', '-cp', str(classes)+os.pathsep+dependencies,
|
||||
'dev.horizonlab.parity.VanillaStructureBlockExporter', str(target)],
|
||||
check=True, stdout=log, stderr=subprocess.STDOUT, timeout=3600)
|
||||
|
||||
|
||||
def prepare_worldgen(root, jars, local, libraries=None):
|
||||
"""Write the chunk generator's resource bundle to root/worldgen (see GeneratorData::load)."""
|
||||
out = root / 'worldgen'
|
||||
out.mkdir(exist_ok=True)
|
||||
# Structure templates: gzip NBT files under structure/<namespace>/<path>.nbt.
|
||||
with zipfile.ZipFile(jars['server']) as server:
|
||||
prefix = 'data/minecraft/structure/'
|
||||
for name in server.namelist():
|
||||
if name.startswith(prefix) and name.endswith('.nbt'):
|
||||
relative = Path(name[len(prefix):])
|
||||
if relative.is_absolute() or '..' in relative.parts:
|
||||
raise ValueError('Invalid structure path')
|
||||
target = out/'structure'/'minecraft'/relative
|
||||
data = server.read(name)
|
||||
if not target.exists() or target.read_bytes() != data:
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
with zipfile.ZipFile(jars['server']) as server, zipfile.ZipFile(jars['client']) as client:
|
||||
for name, path in WORLDGEN_BUNDLES.items():
|
||||
prefix = f'data/minecraft/{path}/'
|
||||
@@ -60,6 +91,9 @@ def prepare_worldgen(root, jars, local):
|
||||
blocks.mkdir(exist_ok=True)
|
||||
for name in names:
|
||||
(blocks/name).write_bytes((behavior/name).read_bytes())
|
||||
if libraries is not None:
|
||||
blocks.mkdir(exist_ok=True)
|
||||
export_structure_blocks(blocks/'structure-blocks.json', jars, libraries)
|
||||
else:
|
||||
print('Feature block behavior exports missing; run tools/test_simple_block_parity.py for full decoration')
|
||||
if presets is None:
|
||||
@@ -294,7 +328,7 @@ def main():
|
||||
for f in (reports / 'biome_parameters' / 'minecraft').glob('*.json'):
|
||||
(root / 'biome-parameters' / f.name).write_bytes(f.read_bytes())
|
||||
# Biome parameter tables come from the data generator reports above.
|
||||
prepare_worldgen(root, jars, lab.LOCAL)
|
||||
prepare_worldgen(root, jars, lab.LOCAL, libraries)
|
||||
entity_models = root / 'entity-models.json'
|
||||
entity_oracle = oracle.with_name('VanillaEntityModelExporter.java')
|
||||
entity_sources = base.source_hashes([entity_oracle])
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run the vanilla structure-start oracle for a seed and chunk rectangle.
|
||||
|
||||
usage: structure_start_oracle.py OUT SEED X0 Z0 X1 Z1
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
try:
|
||||
from . import lab, test_rust_parity as base
|
||||
except ImportError:
|
||||
import lab
|
||||
import test_rust_parity as base
|
||||
|
||||
|
||||
def main():
|
||||
out, seed, x0, z0, x1, z1 = sys.argv[1:7]
|
||||
lock, jars, libraries = base.verify_artifacts()
|
||||
source = lab.ROOT/'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaStructureStartOracle.java'
|
||||
build = lab.LOCAL/'structure-start-oracle'
|
||||
classes = build/'classes'
|
||||
classes.mkdir(parents=True, exist_ok=True)
|
||||
dependencies = os.pathsep.join(map(str, [jars['server'], *libraries]))
|
||||
compiled = subprocess.run(['javac', '--release', str(lock['minecraft']['java_major']), '-proc:none', '-cp', dependencies,
|
||||
'-d', str(classes), str(source)], capture_output=True, text=True)
|
||||
if compiled.returncode:
|
||||
raise SystemExit('javac failed:\n' + compiled.stderr[-3000:])
|
||||
result = subprocess.run(['java', '-Xmx2G', '-cp', str(classes)+os.pathsep+dependencies,
|
||||
'dev.horizonlab.parity.VanillaStructureStartOracle', out, seed, x0, z0, x1, z1],
|
||||
capture_output=True, text=True)
|
||||
if result.returncode:
|
||||
lines = [line for line in (result.stdout + result.stderr).splitlines() if 'Exception' in line or 'Caused' in line]
|
||||
raise SystemExit('oracle failed: ' + ' | '.join(lines[:5]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user