`cargo fmt --all -- --check` has failed on every run in this repository's history, identically on `main` and on every branch. This is #12. Mechanical: `cargo fmt --all`, nothing else. 154 files, all `.rs`, no other extension touched. `cargo check --workspace` exits 0 afterwards, so nothing changed semantically. ON THE ORDERING, WHICH WAS THE REAL QUESTION. HANDOFF-2026-09-06 section 7 warns this is the expensive fix: a whole-tree reformat before #7 and #8 return "would put a conflict in every file of 861 commits and make the reviews those items exist to enable unreadable". That is measurably too pessimistic, and it had been reasoned rather than tested. Measured here by three-way merging a rustfmt'd `main` against both unmerged branches, file by file: file/branch pairs tested 32 merges CLEAN 28 merges CONFLICTING 4 (8 conflict hunks total) sylpheed-cli/src/main.rs 1 hunk sylpheed-export/src/check.rs 1 sylpheed-export/src/screen.rs 4 sylpheed-export/src/video.rs 2 All four are against `auto/frame-blend-draw-path` only; `auto/port-p6-audio` does not conflict anywhere. The earlier framing -- 154 dirty files, 133 that cannot collide, 21 that can, the collision set carrying 147 of 774 hunks (19%) -- reproduces exactly. What it did not say is that most of the 21 still merge cleanly, because rustfmt's edits and the branches' edits rarely land on the same lines. So the cost of sweeping now is 4 files and 8 hunks for one branch, against a check that is otherwise red forever. Deliberately NOT folded into the WASM PR: 154 reformatted files would make that one unreviewable. Closes #12
119 lines
4.6 KiB
Rust
119 lines
4.6 KiB
Rust
//! Which container did each captured draw come from, and where in it?
|
||
//!
|
||
//! Extends the single-container `--map` check in `shared_vbase_check` to a whole
|
||
//! `resource3d` directory. For each container it indexes every 4-byte-aligned
|
||
//! position triple, looks up each draw's first dumped position, confirms the run
|
||
//! at a fixed stride, and reports the modal `vbase − offset`. A container the
|
||
//! engine loaded shows one dominant constant; an unrelated one shows noise.
|
||
//!
|
||
//! The output is capture-named ground truth for anchors far beyond the one ship
|
||
//! `Stage_S01` gave us.
|
||
//!
|
||
//! Usage: capture_truth_scan <resource3d_dir> <capture.log>...
|
||
use std::collections::HashMap;
|
||
use sylpheed_formats::ship_capture::{parse_capture, parse_drawlog, CapturedDraw};
|
||
|
||
fn q(v: f32) -> i64 {
|
||
(v as f64 * 1e4).round() as i64
|
||
}
|
||
|
||
fn main() {
|
||
let a: Vec<String> = std::env::args().collect();
|
||
let dir = &a[1];
|
||
let mut draws: Vec<CapturedDraw> = Vec::new();
|
||
let mut seen = std::collections::HashSet::new();
|
||
for log in &a[2..] {
|
||
let text = std::fs::read_to_string(log).expect("log");
|
||
let mut d = parse_capture(&text);
|
||
if d.is_empty() {
|
||
d = parse_drawlog(&text);
|
||
}
|
||
for x in d {
|
||
// One entry per buffer; the logs are already deduped per transform.
|
||
if x.pos.len() >= 8 && x.vcount >= 20 && seen.insert((log.clone(), x.vbase)) {
|
||
draws.push(x);
|
||
}
|
||
}
|
||
}
|
||
eprintln!("{} distinct (log, vbase) draws to place", draws.len());
|
||
|
||
let mut files: Vec<_> = std::fs::read_dir(dir)
|
||
.unwrap()
|
||
.flatten()
|
||
.map(|e| e.path())
|
||
.filter(|p| p.extension().and_then(|s| s.to_str()) == Some("xpr"))
|
||
.collect();
|
||
files.sort();
|
||
|
||
let mut placed = 0usize;
|
||
for f in &files {
|
||
let Ok(bytes) = std::fs::read(f) else {
|
||
continue;
|
||
};
|
||
// Index quantised position triples. Junk floats (NaN/huge) are skipped,
|
||
// which prunes most of a texture-heavy container.
|
||
let be = |at: usize| f32::from_be_bytes(bytes[at..at + 4].try_into().unwrap());
|
||
let mut index: HashMap<(i64, i64, i64), Vec<u32>> = HashMap::new();
|
||
let mut o = 0usize;
|
||
while o + 12 <= bytes.len() {
|
||
let (x, y, z) = (be(o), be(o + 4), be(o + 8));
|
||
if x.is_finite()
|
||
&& y.is_finite()
|
||
&& z.is_finite()
|
||
&& x.abs() < 1e6
|
||
&& y.abs() < 1e6
|
||
&& z.abs() < 1e6
|
||
{
|
||
index.entry((q(x), q(y), q(z))).or_default().push(o as u32);
|
||
}
|
||
o += 4;
|
||
}
|
||
let mut deltas: HashMap<i64, Vec<(u32, u32)>> = HashMap::new();
|
||
for d in &draws {
|
||
let k = (q(d.pos[0][0]), q(d.pos[0][1]), q(d.pos[0][2]));
|
||
// ±1 in each axis: the log rounds, our file value may round the
|
||
// other way at a tie.
|
||
for dx in -1..=1i64 {
|
||
for dy in -1..=1i64 {
|
||
for dz in -1..=1i64 {
|
||
let Some(cands) = index.get(&(k.0 + dx, k.1 + dy, k.2 + dz)) else {
|
||
continue;
|
||
};
|
||
for &off in cands {
|
||
for stride in (12..=64).step_by(4) {
|
||
let ok = (1..4).all(|j| {
|
||
let at = off as usize + j * stride;
|
||
at + 12 <= bytes.len()
|
||
&& (0..3)
|
||
.all(|c| (be(at + c * 4) - d.pos[j][c]).abs() <= 1e-4)
|
||
});
|
||
if ok {
|
||
deltas
|
||
.entry(d.vbase as i64 - off as i64)
|
||
.or_default()
|
||
.push((d.vbase, d.vcount));
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
let mut top: Vec<_> = deltas.into_iter().collect();
|
||
top.sort_by_key(|(_, v)| std::cmp::Reverse(v.len()));
|
||
if let Some((delta, hits)) = top.first() {
|
||
if hits.len() >= 3 {
|
||
placed += hits.len();
|
||
println!(
|
||
"{:<22} base=0x{:<10X} buffers={}",
|
||
f.file_name().unwrap().to_string_lossy(),
|
||
delta,
|
||
hits.len()
|
||
);
|
||
}
|
||
}
|
||
}
|
||
eprintln!("{placed} draws placed in a container");
|
||
}
|