Identify the tie record as RAC1's TiePacketHeader, and retract a formula
The 16-byte tie record is R&C1's TiePacketHeader offset for offset: a data pointer at +0, then R&C1's byte fields at +4 through +0x10. The identification is not a resemblance but R&C1's own rule -- bfc_distance == 5 * shader_count -- holding on all 15,219 records of all 2,177 blocks on all 27 levels. Measured over the same set, and reported rather than asserted where it is not universal: bfc_distance == 5 * shader_count 15219 / 15219 vert_ofs <= vert_size all scissor_size <= scissor_ofs all control_size <= control_count all color_ofs == vert_size 12640 / 15219 color_ofs == vert_ofs + vert_size 0 / 15219 color_count, strip_count, strip_vertex_count zero 15089 / 15077 / 15078 R&C1's rule for the colour offset holding on none of them is the interesting line: the two games use that field differently, so it is named color_ofs for what this game's majority reads as and the 2,579 exceptions are counted rather than averaged away. TieRecord parses all twelve fields, invariants_hold asserts only the universal four, and the disc test counts the rest. A packet-length formula is withdrawn rather than softened. (vert_ofs + vert_size + scissor_ofs + scissor_size) * 16 was measured at 61 of 61 pairs and is not reproduced on the correct blocks -- 0 of 13,042. The block set was the error, not the arithmetic: the script that produced the 61 read packets[2] where packets[1] was meant, so it measured 461 blocks instead of the 2,177 the class tables define, and the formula agreed perfectly with a population that was not the tie blocks. TieRecord::packet_bytes goes with it, and the retraction is recorded in the format doc and in the struct. That misread also explains why the earlier RAM verification saw different numbers for the two inputs -- same lesson as rule 3, arriving through a wrong subscript instead of a wrong span.
This commit is contained in:
@@ -2447,6 +2447,130 @@ fn chunk_record_leading_word_is_fixed_per_type() {
|
||||
);
|
||||
}
|
||||
|
||||
/// The tie record is R&C1's `TiePacketHeader`, and its rule holds.
|
||||
///
|
||||
/// A tie LOD block is a table of 16-byte packet headers -- a data pointer,
|
||||
/// then R&C1's byte fields at +4..+0x10. What identifies them rather than a
|
||||
/// resemblance is R&C1's own documented rule: **`bfc_distance == 5 *
|
||||
/// shader_count` on every record**, here 15,219 of 15,219 over 2,177 blocks on
|
||||
/// all 27 levels.
|
||||
///
|
||||
/// Measured over the same set, and reported rather than asserted because they
|
||||
/// are not universal:
|
||||
///
|
||||
/// * `color_ofs == vert_size` on 12,640 of 15,219 -- and R&C1's rule for the
|
||||
/// field (`== vert_ofs + vert_size`) holds on **0**, so the two games use it
|
||||
/// differently and this one is named for what it measures;
|
||||
/// * `color_count`, `strip_count`, `strip_vertex_count` zero on ~15,077 of
|
||||
/// 15,219;
|
||||
/// * the orderings `vert_ofs <= vert_size`, `scissor_size <= scissor_ofs` and
|
||||
/// `control_size <= control_count` on all of them.
|
||||
///
|
||||
/// One claim is retracted here rather than softened: a packet-length formula,
|
||||
/// `(vert_ofs + vert_size + scissor_ofs + scissor_size) * 16`, was measured at
|
||||
/// 61 of 61 pairs and is not reproduced on the correct blocks (0 of 13,042). It
|
||||
/// was measured over blocks found by reading `packets[2]` where `packets[1]`
|
||||
/// was meant, so the arithmetic agreed perfectly with a population that was not
|
||||
/// the tie blocks. The block set was the error; see `AGENTS.md` rule 3.
|
||||
#[test]
|
||||
fn tie_records_are_packet_headers() {
|
||||
require_disc!();
|
||||
let data = std::env::var_os("GC_EXTRACTED")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| {
|
||||
let home = std::env::var("HOME").unwrap_or_else(|_| ".".into());
|
||||
PathBuf::from(home).join("Documents/gc-extracted")
|
||||
});
|
||||
if !data.exists() {
|
||||
eprintln!("skipped: unpack the disc first");
|
||||
return;
|
||||
}
|
||||
|
||||
use gc_formats::level_core::LevelCoreHeader;
|
||||
use gc_formats::tie::{parse_tie_block, resolve_tie_class, TieRecord};
|
||||
|
||||
let mut levels = 0usize;
|
||||
let mut blocks = 0usize;
|
||||
let mut records = 0usize;
|
||||
let mut bfc_ok = 0usize;
|
||||
let mut invariants_ok = 0usize;
|
||||
let (mut color_eq_size, mut color_zero, mut strips_zero, mut strip_verts_zero) =
|
||||
(0usize, 0usize, 0usize, 0usize);
|
||||
|
||||
for n in 0..27 {
|
||||
let (Ok(core), Ok(index)) = (
|
||||
std::fs::read(data.join(format!("level{n}/core_data.bin"))),
|
||||
std::fs::read(data.join(format!("level{n}/core_index.bin"))),
|
||||
) else {
|
||||
continue;
|
||||
};
|
||||
let h = LevelCoreHeader::parse(&index).expect("core header");
|
||||
for c in 0..h.tie_classes.count.max(0) as usize {
|
||||
let Ok(class) = resolve_tie_class(&index, &core, h.tie_classes, c) else {
|
||||
continue;
|
||||
};
|
||||
for lod in 1..=2usize {
|
||||
let off = class.header.packets[lod];
|
||||
if off <= 0 {
|
||||
continue;
|
||||
}
|
||||
let start = class.entry.offset_in_asset_wad as usize + off as usize;
|
||||
let Some(block) = parse_tie_block(&core, start) else {
|
||||
continue;
|
||||
};
|
||||
let len = 0x10 + block.payload.len() + block.padding.len();
|
||||
let Some(slice) = core.get(start..start + len) else {
|
||||
continue;
|
||||
};
|
||||
// The table must fit inside the block the terminator found, or
|
||||
// what follows is being read as a table.
|
||||
if block.header.data_offset as usize > 0x10 + block.payload.len() {
|
||||
continue;
|
||||
}
|
||||
blocks += 1;
|
||||
for r in block
|
||||
.header
|
||||
.records(slice)
|
||||
.map(|r| TieRecord::parse(r).expect("record parses"))
|
||||
{
|
||||
records += 1;
|
||||
bfc_ok += usize::from(r.bfc_distance == 5 * r.shader_count);
|
||||
invariants_ok += usize::from(r.invariants_hold());
|
||||
color_eq_size += usize::from(r.color_ofs == r.vert_size);
|
||||
color_zero += usize::from(r.color_count == 0);
|
||||
strips_zero += usize::from(r.strip_count == 0);
|
||||
strip_verts_zero += usize::from(r.strip_vertex_count == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
levels += 1;
|
||||
}
|
||||
|
||||
assert!(levels >= 25, "only {levels} levels were read");
|
||||
assert_eq!(blocks, 2_177, "expected 2,177 tie blocks, got {blocks}");
|
||||
assert!(records > 14_000, "only {records} packet headers found");
|
||||
// The identification: R&C1's rule, on every record.
|
||||
assert_eq!(
|
||||
bfc_ok,
|
||||
records,
|
||||
"bfc_distance != 5 * shader_count on {} of {records}",
|
||||
records - bfc_ok
|
||||
);
|
||||
assert_eq!(
|
||||
invariants_ok,
|
||||
records,
|
||||
"record invariants failed on {} of {records}",
|
||||
records - invariants_ok
|
||||
);
|
||||
eprintln!(
|
||||
"tie packet headers: {records} over {levels} levels, {blocks} blocks; \
|
||||
bfc_distance == 5*shader_count on all; orderings on all; \
|
||||
color_ofs == vert_size on {color_eq_size}/{records}; \
|
||||
color_count/strip_count/strip_vertex_count zero on \
|
||||
{color_zero}/{strips_zero}/{strip_verts_zero}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Byte positions that hold the same value in every supplied record.
|
||||
fn constant_positions(records: &[&[u8]]) -> usize {
|
||||
let Some(first) = records.first() else {
|
||||
|
||||
Reference in New Issue
Block a user