Files
benilla-octo/crates/benilla-formats/tests/m2_anim_events.rs
T
Sam SungandClaude Opus 5.5 8da634afa9 Comments in benilla-formats: one line of fact each, no history, no record numbers (#130)
Part of #41: the comments of `benilla-formats` (the library, its extract tools, examples and tests) are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 19,654 comment lines become 7,264.

Fixes #105: the WMO collision comments now name walking's box-query leaf `0x6bca50` and the camera and line-of-sight segment-query leaf `0x6bc700`, in `models/collision.rs`, `examples/wmo_bsp.rs` and `tests/chain.rs`.

- **The mechanical strip.** The citations that were only a private record number go first, and each edit is shown to be a pure removal.
- **Wrong facts corrected.** The rewrite corrects the comments that stated wrong facts. Among them:
  - A placed doodad's material alpha reads file slot 0 on its spawn clock, while the reference reads bone 0's armed sequence, re-rolled every play window. The old text said doodads are armed once at load.
  - The fog end is stored ×36 and scaled once at load (`0x6d6090`). It is not raw.
  - The MCSH bit picks a map doodad's sun scale, 1.0 lit or 0.5 shadowed. 2.5 belongs to an entity's light node.
  - `SpellRec` is the row as stored, column × 4, not a translated copy.
  - A global sequence's clock is anchored at the instance's attach time (`0x714352`).
  - Particle twinkle is a gated size multiplier (`0x7b2adc`).
  - The blob shadow sizes from the Stand box.
  - Data claims are checked against the install: the weapon-trail kits' parameters and alphas, the beam rows' noise, and the maps' `field_16`.
  - Dozens more turned up on the way: renamed or deleted items, docs sitting on the wrong item, stale counts and links.
- **Deviation labels.** "Deviation:" now marks only a choice with a reason. An unbuilt behaviour says so plainly.
- **Verification.** Every file strips to identical code, and `cargo fmt --check` is clean. Four second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the reference, the code and the shipped data.

String literals are untouched; they are #92.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 19:38:53 +07:00

106 lines
3.8 KiB
Rust

//! M2 events: the table at MD20 `0x114`, 44 bytes a record, its keys timed on the global sequence
//! timeline and rebased into each sequence; tags are stored forward, `$xxx`.
use benilla_formats::{open_chain, parse_m2_animations};
#[test]
fn creature_anim_events_parse_within_sequences() {
let data = benilla_formats::wow_data_or_skip!();
let chain = open_chain(&data).expect("open chain");
for model in [
"Creature\\DireWolf\\DireWolf.m2",
"Creature\\Kobold\\Kobold.m2",
"Creature\\Murloc\\Murloc.m2",
] {
let bytes = chain.read(model).expect("model bytes");
let anims = parse_m2_animations(&bytes);
assert!(!anims.is_empty(), "{model}: sequences parse");
let mut total_events = 0usize;
let mut footstep_tags = 0usize;
for a in &anims {
for e in &a.events {
total_events += 1;
assert!(
e.time >= 0.0 && e.time <= a.duration + 1e-3,
"{model}: event {:?} at {}s escapes its {}s sequence (anim {})",
std::str::from_utf8(&e.ident),
e.time,
a.duration,
a.anim_id
);
assert_eq!(e.ident[0], b'$', "{model}: forward-stored $ tag");
if matches!(&e.ident[..3], b"$FL" | b"$FR" | b"$RL" | b"$RR") {
footstep_tags += 1;
}
}
}
assert!(total_events > 0, "{model}: has event keys");
assert!(
footstep_tags > 0,
"{model}: walking creature has footstep tags"
);
}
}
/// A fired key carries its own record's bone and position, not the tag's first match: the event
/// kernel `0x719370` snapshots `placementMatrix · (boneMatrix[event.bone] · event.position)` into
/// the callback record. Every player model authors six `$CSD` records, one per emote clip.
#[test]
fn a_fired_key_carries_its_own_records_bone_and_point() {
let data = benilla_formats::wow_data_or_skip!();
let chain = open_chain(&data).expect("open chain");
let model = "Character\\Human\\Male\\HumanMale.m2";
let bytes = chain.read(model).expect("model bytes");
let markers = benilla_formats::parse_m2_event_markers(&bytes).expect("event markers");
let csd_records: Vec<_> = markers.iter().filter(|m| &m.ident == b"$CSD").collect();
assert_eq!(
csd_records.len(),
6,
"{model}: the six emote-voice records are what makes this test worth having"
);
let distinct: std::collections::BTreeSet<_> =
csd_records.iter().map(|m| (m.bone, m.data_key())).collect();
assert_eq!(
distinct.len(),
6,
"{model}: the six records are distinct — a first-match lookup cannot stand in for them"
);
let anims = parse_m2_animations(&bytes);
let mut fired: std::collections::BTreeSet<(u16, [u32; 3])> = Default::default();
for a in &anims {
for e in a.events.iter().filter(|e| &e.ident == b"$CSD") {
let key = (e.bone, bits(e.position));
assert!(
distinct.contains(&key),
"{model}: fired $CSD at bone {} is not one of the authored records",
e.bone
);
fired.insert(key);
}
}
assert!(
fired.len() > 1,
"{model}: only {} distinct $CSD point(s) ever fire — the record identity is being lost \
somewhere between the table and the key",
fired.len()
);
}
/// Exact bit patterns, so a float compare never decides record identity.
fn bits(p: [f32; 3]) -> [u32; 3] {
[p[0].to_bits(), p[1].to_bits(), p[2].to_bits()]
}
trait MarkerKey {
fn data_key(&self) -> [u32; 3];
}
impl MarkerKey for benilla_formats::EventMarker {
fn data_key(&self) -> [u32; 3] {
bits(self.position)
}
}