Files
Sylpheed/crates/sylpheed-formats/tests/ui_prm_primitives_disc.rs
Sylpheed RE agent 0ebbe9951b formats: settle what .prm elements are — untextured quads marked by kind bit 0x10
369 .prm elements exist in the disc's screen builds and every composite is
missing them. Swept statically:

  * none of the 369 has a RATC child of its own name — no payload, nothing to
    draw, so .prm is a primitive and not a sprite;
  * kind & 0x10 and a .prm name agree with ZERO exceptions in either direction
    over all 965 builds, so the format marks primitives as a decoded field and a
    port need not parse filenames;
  * 361 of 369 are exactly 1280x720 at scale 100% in the corner, and their
    keyframe 'fade' ARGB is overwhelmingly black at some alpha — these are the
    fade-to-black, dim-behind-menu and flash layers, i.e. the PRMD dim-quad the
    compositor's backdrop has been standing in for.

Refuted before believing: drawing them at Element::rest() is wrong. The title's
pteff00.prm is opaque -> transparent -> transparent -> opaque, a transition whose
resting pose is the transparent plateau; rest() picks by longest dwell and lands
on the opaque endpoint, which is painted LAST on that screen and would black out
the title. A test asserts that wrong answer deliberately so that fixing the
resting rule fails it and leads to the note.

No compositing change: the resting rule is not .prm-specific and has to be A/B'd
against the title framebuffer capture first.
2026-08-19 06:30:05 +00:00

161 lines
6.5 KiB
Rust

//! `.prm` elements are untextured quads, and the declaration table says so.
//!
//! Every composite the port draws is missing them: they carry no sprite, so
//! `compose` skips them. What they are was settled statically on 2026-08-19 —
//! see `docs/re/structures/ui-prm-primitives.md`. This pins the three facts the
//! decoding rests on, and is disc-gated like the rest of the corpus.
use std::path::{Path, PathBuf};
use sylpheed_formats::{pak::PakArchive, ratc, ui_layout};
fn disc_root() -> Option<PathBuf> {
if let Ok(p) = std::env::var("SYLPHEED_DISC") {
let p = PathBuf::from(p);
if p.join("dat").is_dir() {
return Some(p);
}
}
let default = Path::new(
"/home/fabi/RE - Project Sylpheed/Project Sylpheed - Arc of Deception (USA, Europe) (En,Ja)",
);
if default.join("dat").is_dir() {
return Some(default.to_path_buf());
}
None
}
fn for_each_build(root: &Path, mut f: impl FnMut(&str, &[u8])) {
let mut paks: Vec<PathBuf> = std::fs::read_dir(root.join("dat"))
.expect("dat/")
.flatten()
.map(|e| e.path())
.filter(|p| p.extension().and_then(|s| s.to_str()) == Some("pak"))
.collect();
paks.sort();
for p in &paks {
let name = p.file_name().unwrap().to_string_lossy().to_string();
let Ok(arc) = PakArchive::open(p) else { continue };
for e in arc.entries() {
let Ok(bytes) = arc.read(e) else { continue };
if ratc::is_ratc(&bytes) {
f(&name, &bytes);
}
}
}
}
/// **Bit `0x10` of `kind` means "untextured primitive", and it is exact.**
///
/// This is the point of the whole item: the primitive-ness is a *decoded field*,
/// not a guess from the `.prm` file extension. Over every screen build on the
/// disc, `kind & 0x10` and a `.prm` name agree with **zero** exceptions in
/// either direction — so a port can classify without parsing names.
///
/// Also pinned here because it is the same sweep: no `.prm` element has a RATC
/// child of its own name. All 369 of them are payload-less, which is what
/// "untextured" means concretely — there is nothing in the bundle to draw.
#[test]
fn kind_bit_0x10_means_prm_exactly_and_prm_carries_no_payload() {
let Some(root) = disc_root() else {
eprintln!("SKIP: extracted disc not found (set SYLPHEED_DISC to enable)");
return;
};
let (mut prm, mut prm_without_bit, mut bit_without_prm, mut with_child) = (0, 0, 0, 0);
let (mut full_screen, mut sized) = (0, 0);
for_each_build(&root, |pak, bytes| {
let Some(build) = ui_layout::parse_build(bytes) else {
return;
};
if build.from_fallback {
return;
}
let kids = ratc::parse(bytes).unwrap_or_default();
for el in &build.elements {
let is_prm = el.name.to_ascii_lowercase().ends_with(".prm");
let has_bit = el.kind & 0x10 != 0;
if is_prm && !has_bit {
prm_without_bit += 1;
eprintln!("{pak}: {} is .prm without bit 0x10", el.name);
}
if has_bit && !is_prm {
bit_without_prm += 1;
eprintln!("{pak}: {} has bit 0x10 but is not .prm", el.name);
}
if !is_prm {
continue;
}
prm += 1;
if kids.iter().any(|c| c.name == el.name) {
with_child += 1;
eprintln!("{pak}: {} has a payload child", el.name);
}
sized += 1;
if (el.pivot_x * 2, el.pivot_y * 2) == (1280, 720) {
full_screen += 1;
}
}
});
assert!(prm > 300, "only {prm} `.prm` elements — the sweep did not run");
assert_eq!(prm_without_bit, 0, "a `.prm` element without kind bit 0x10");
assert_eq!(bit_without_prm, 0, "kind bit 0x10 on something that is not `.prm`");
assert_eq!(with_child, 0, "a `.prm` element with a payload child");
// 361 of 369 are exactly the design space; the handful that are not are
// small coloured quads (844x600, and two degenerate 0x720).
assert!(
full_screen * 10 > sized * 9,
"only {full_screen}/{sized} `.prm` elements are full-screen"
);
eprintln!("{prm} `.prm` elements: all kind&0x10, none with a payload, {full_screen} full-screen");
}
/// **A `.prm` fade quad cannot be drawn at `Element::rest()`** — the pose that
/// rule picks would black out the screen.
///
/// The title's `pteff00.prm` is a screen transition: opaque black at t=12,
/// transparent by t=64, held transparent to t=74, opaque black again on the way
/// out. What the title screen sits at is the transparent plateau. `rest()` picks
/// by longest dwell to the next keyframe's time, which lands on an *endpoint* of
/// the fade — an opaque black full-screen quad, painted last in the measured
/// order, i.e. the whole screen.
///
/// This test states the defect rather than hiding it: it asserts the shape of
/// the group (so the reasoning stays checkable) and that `rest()` returns the
/// opaque frame (so that when the resting rule is fixed, this test fails and
/// someone reads the note above instead of rediscovering it).
#[test]
fn the_title_fade_quad_is_a_transition_and_rest_picks_the_wrong_end() {
let Some(root) = disc_root() else {
eprintln!("SKIP: extracted disc not found (set SYLPHEED_DISC to enable)");
return;
};
let arc = PakArchive::open(root.join("dat").join("GP_TITLE.pak")).expect("GP_TITLE.pak");
let mut checked = 0usize;
for e in arc.entries() {
let Ok(bytes) = arc.read(e) else { continue };
let Some(build) = ui_layout::parse_build(&bytes) else {
continue;
};
for el in &build.elements {
if el.name != "pteff00.prm" || el.keyframes.len() != 4 {
continue;
}
checked += 1;
let a: Vec<u32> = el.keyframes.iter().map(|k| k.fade >> 24).collect();
assert_eq!(
a,
vec![0xff, 0x00, 0x00, 0xff],
"the fade group is opaque → transparent → transparent → opaque"
);
assert_eq!(
el.rest().map(|k| k.fade),
Some(0xff00_0000),
"rest() still picks an endpoint of the fade — if this now returns \
the transparent plateau the resting rule has been fixed and the \
note on this test is stale"
);
}
}
assert!(checked >= 3, "found {checked} title fade quads, expected several");
}