At a glance

Battle statefrom the library Retail: PCSX-Redux probe inject the cast at action state 0x0A, grab frames + per-vsync metadata Engine: corpus image child the state's fight, cast seeded, play-window recorder per tick Pair + score on the action clock and the module phase report segments, strip, cues
The driver scripts/ci/cast-sequence.py runs the three stages and caches each one until something it depends on changes. The scorer is legaia-engine cast-sequence-score (crates/parity); a disc-free test pins the pairing rule on synthetic recordings.

Running it

# first run: retail capture (an emulator run, a few minutes), engine seed, engine run, score
scripts/ci/cast-sequence.py --spell 0x86 --state party_basic_attack_vs_gobu_gobu

# after an engine change: re-run only the engine side and the score (seconds)
scripts/ci/cast-sequence.py --spell 0x86 --state party_basic_attack_vs_gobu_gobu --engine-only

# re-score cached recordings with another display-lag rule
scripts/ci/cast-sequence.py --spell 0x86 --state party_basic_attack_vs_gobu_gobu --score-only --retail-lag 4

Several casts go through cast-sequence-batch.py: the retail recordings side by side, then the engine runs one at a time. A retail recording is a headless emulator at normal speed, and two recordings of one cast are not byte-identical, so a residual smaller than two retail runs differ from each other is noise. The driver builds legaia-engine with the oracles feature, which the scorer and the recorder's frame shots need. Output lands under captures/cast-sequence/<state>_<spell>/, which is gitignored.

FlagEffect
--caster / --targetThe seat whose queue is rewritten and the seat it aims at. A caster seat of 3 or more is a monster.
--monster-pickWrite a monster's cast where its AI pick returns, so any battle state that reaches the monster's turn records any spell it owns a clip for.
--physicalFilm the strike a harvested state already holds instead of injecting a cast; --strike-deal stands the engine on retail's hand.
--hit-traceLog the rand() seed word every melee hit draws from on the retail side (breakpoint core), at the head of the strike kernel's hit body; --strike-deal then deals those words, blocked swings included. A cast whose hits are the melee kernel's (Astral Slash's four-beat clip) takes the words alone.
--retail-stepsRun the engine on the recording's own frame steps, a disclosed harness seat that takes the frame's cost out of what is left.
--rand-at <state>:<phase>Hold the engine's rand() stream on retail's seed word under one cast key.
--popup-traceRetail: every damage numeral’s projected square, its depth and the GTE view.
--ribbon-traceRetail: every streak-ribbon call with its seed word, anchor, projected corners and GTE view.
--rand-trackSeat every module-band pass on the rand() word retail's frame before it ended on, for an arm that draws on every pass.
--retail-partsLog every live move-VM part per vsync on the retail side, to read beside the engine's parts.csv.
--recapture / --reseed / --rerecordRedo one cached stage.

What each side records

Pairing frames on the game's clock

Frames pair on the action state machine's clock, never on wall time.

Retail 0x28 0x29 0x32 phase 1 phase 2 phase 3 0x51 Engine 0x28 0x29 phase 1 phase 2 phase 3 0x51 0x32 has no engine segment: a CD read the engine answers at once a segment is a run of one key; keys align by longest common subsequence
A retail frame k vsyncs into its segment, measured on the game clock, pairs with the engine frame k ticks into the aligned segment, clamped to that segment's last tick: an engine arm that ends early is compared at its last frame for the rest of retail's arm, which is what a viewer would see.

The rand() stream

Retail draws every rand() from one seed word. The engine's world stream is the same generator, but it reaches a cast's arms after another number of draws, so an arm whose look is its draws plays another pattern: Gigaton Press picks each of its sixteen falling rocks by rand() % 4. --rand-at sets the engine's stream to the word retail held on the last vsync under one key, so the pass that leaves the key draws as retail's did; on a Gigaton Press capture the rocks' arm scores .770 with it and .649 without.

One held word deals one pass. Earthquake bursts a rock pair every frame off rand(), and retail's other passes draw tens of times where the engine draws a few, so --rand-track holds every band pass on the word retail's frame before it ended on. Van Saryu's Earthquake film goes from .808 to .943 and Scale Lizard's from .748 to .910; Death Game's cues from .800 to .970. It is a harness seat: a pass that draws in another order than retail's still parts (Fatal Decision drops .841 to .830).

Some draws depend on the camera. A streak ribbon draws a fixed number of words per segment, and it chains as many segments as it takes to climb from its projected anchor to the top of the screen, so the camera’s pose decides how many words the pass uses. A --ribbon-trace recording puts each call’s inputs beside the engine’s; that is how Thunder Storm's ring, scatter and hit order were matched until its damage dealt as retail’s.

The roll can decide the cast's sound as well as its look. Kiss of Death cues only on its hit leg: a film whose retail side missed recorded no cue, while the engine's own stream rolled a hit and played three. Held on retail's word with --rand-at, the engine misses too and plays none. That difference was the replay's stream, not the cast.

A monster's physical attack

--physical films the strike a harvested battle_*_strike state already holds. Neither side is steered: retail plays on from the state, and the engine child keeps the state's own pad drive and starts recording on its gate. Past the capture's instant nothing holds the two rounds together - the block roll, the next queue byte and later picks draw on each side's own stream - so --strike-deal stands the engine on retail's hand at the gate: a monster striker's queue, the approach terms, the striker's working ATK, the party members retail held in the Spirit stance and the seed going into each hit, for a monster's strike or a party member's. The stance matters as much as the seed: the block roll scales a guarding defender's side by half again, and Warhalf's second swing on Vahn blocks in retail only because he stood on Spirit. Dealt that way, most strike recordings match retail cue for cue: block verdict, damage rolls, the flinch's impact pick and the times. With --hit-trace words the engine's block verdicts are retail's on every traced hit: Nova's five swings on Gala, Gaza's four Astral Slash beats and Vahn's Slash Kick. Since the state sits mid-glide wherever it was saved, a physical film seats retail’s first recorded camera row on its gate tick rather than letting the engine’s own round take the seat. On the same tick it stands the party in the recording’s stance exactly and the rand() stream on the state’s own seed word: the drive commits Spirit for the whole party while a monster casts, and Gilium’s Thunder Storm had landed about a quarter of retail’s damage on a party retail never guarded. Seated, it lands retail’s numbers to the unit.

From the gate on, a strike film runs on the capture’s own frame-cost ring: a replay that reached the capture on the default step otherwise played the whole film at step two where retail’s full party runs three, and its camera yaw drifted two units a pass. A replayed cast keeps its pinned step, since its module arms run on their own step tables.

At the same gate every seat stands on the capture’s ground, its position and heading together: a striking monster re-faces each pass onto its target’s body, which the target’s heading turns, so a heading seated on a replay’s position swung the camera off retail’s.

The sound channel

Both sides also write one row per sound cue played: retail's from the cue ring sampled every vsync (an edge into "countdown zero, id not negative" is one cue), the engine's from the audio director's command record each tick. A retail cue is placed into engine time the way a frame is - its segment, its offset on the game clock - and matches the nearest unmatched engine cue of the same id within a tolerance; a second pass lists near misses as timing, the rest as missing or extra. CD-XA voice clips are not ring cues and are scored apart. The channel found, among others, the defeat cue the clip commit writes into the ring itself, a reacting seat the engine read as idle so Theeder's sweep struck it every pass, and Zenoir's opening hit landing on the wrong arm, and a Paralyzing Wave whose paralysed victim played a reaction (and its three cues) that retail's marking branch never stages.

The sampler has one blind spot: a cue pushed into the slot that held the same id a frame earlier reads as one cue, because the slot is cleared and refilled between two samples. Three homing landings of Kemaro's Lava Breath ring the impact cue three times, and the sampler counts two. A lone engine extra of that shape is checked against the --sfx-callers call log before it is read as an engine defect.

The level of the voice itself, rather than its timing, is measured against mednafen's audio output by the real-PCM cast channel; how a summon's voice waits for the CD drive is on the cast module page.

The cue ratchet

A film's image score moves a little with every engine change, so the films stay report-only. Their cue channel is held to a committed baseline instead: film-cues.py --check reads each film's report from a run of the committed film sets (the Seru casts, the enemy casts, the dealt monster strikes) and fails when a baselined film plays fewer of retail's cues on retail's clock. A baseline that falls needs a ledger entry, which the baseline-loosening gate enforces on the file alone.

Each strike and enemy film is pinned to the battle random stream it was baselined on. The seed tries that stream first, so a change to the draws before the cast no longer hands the film whichever stream now happens to reach the phase first - a re-deal that read as a regression without any defect behind it. A pin that stops reaching falls back to the search, and the film run says which stream it got.

Two cue drops show why. A summon kill's fade stand-in once faded the body before its knockdown committed, so the defeat cue never rang on five Seru films. Chaos Flare's victim lost the rate its knockdown plays at when reactions began to commit in the struck seat's own node tick, and both of the knockdown's cues rang early. Most of those films' images moved by a thousandth or so; only the cue channel said anything was wrong.

Waits the engine does not run

Some waits in a summon band are CD reads, which the engine's resident streams answer at once, so their segments part on length without any engine error. The pairing keys each segment on its own, so they do not shift the rest of the cast's pairs.

WaitWhat it pollsRetailEngine
State 0x32the read the cast trigger started in 0x29about 16 vsyncsone pass
The side-band armthe applier stage that streams the cast's slots of summon.dat28 to 30 vsyncs a slotheld for the same CD time
A stream-poll armthe creature's own reada few vsyncsone pass
Capture states 0x6E / 0x6Fthe queued read, then the module's own14..17 and 4..6 vsyncsheld 14 and 4 ticks

The capture band's two polls are held because neither idles: each pass walks a framing or pulls the shot depth in, so a tween opened two ticks early stands on another pose for its whole length.

CD-seek waits

A summon module seeks the CD drive to its voice clip on one arm and polls the seek on a later one. The seek arm blocks the whole game loop while the drive finishes the seek before it; the poll arm waits with the rest of the frame running. How long either takes is the drive's seek time, which varies across drives and across emulators. The engine keeps one model, fitted to mednafen, that holds the seek arm 23 to 36 frames and the poll arm up to 29 ticks; the PCSX-Redux films seek in 1 to 4 vsyncs. Paired strictly, that difference reads as engine error: Gimard's held frames put the rest of its arm 2 twenty-three ticks out of step.

The oracle accepts any wait inside a window instead: from no extra vsync up to the engine's own wait plus max(8, wait / 2) vsyncs. Inside it, the seek arm pairs on the engine's live ticks, retail frames of a wait arm the engine's drive answered sooner are counted apart, and each arm after the wait pairs on whichever of two clocks scores higher: its own arm clock, or the clock that ran on through the poll (a fade spawned before the wait stands that many ticks ahead in the engine). A retail wait outside the window, and every other segment, stays strict; --strict-drive turns the window off. The report states the wait, the window and the strict mean, so the tolerance is never silent. On the Seru films with drive arms the mean goes from .792 to .808; films with no drive arms are unchanged.

A monster cast from any battle state

A monster's AI pick and the use of its result run in the same pass, so no vsync hook can get between them. With --monster-pick the probe breaks just after the pick returns, where the queue it wrote is final and unread, and writes the cast there with the same two stores the AI's own cast arms make. Any battle state that reaches the monster's turn therefore records any spell the monster owns a clip for. The engine half hands the monster the round's first turn from the first prompt and stands each slot on the ground retail's earlier actions left. A monster target is re-keyed to the engine's slot numbering as the caster is: left on retail's number, Koru's self-cast Ultra Charge named no engine actor in a one-member party, and Vahn drew solid in front of Koru where retail ghosts him. A cast that wipes the party (Koru's Dead End Crisis on a lone Vahn) goes to the game-over flow with no Done band, so it has nothing to pair; filming it needs a state whose party outlives the cast.

Each seat’s HP comes from the recording’s cast begin, not the state’s HUD bars: a --monster-pick recording plays the party’s turns to the pick, so the caster and its victims stand at other HP when the cast begins, and the damage rolls read the attacker’s HP. A monster those turns killed is seated dead. --wrapper-trace reads each capture-class damage roll straight off retail - the power, the slots, the seed word, the stat words and the two roll words around the finisher - so a cast’s damage is checked on its inputs rather than off the HP columns.

Reading the report, and its limits

report.md opens with the mean, the minimum and the excluded counts, then the segment table (each key's retail length in wall vsyncs and on the game clock, the engine's in ticks, its pairs and mean), the worst pairs, the strip rows (retail | engine | |diff|) and the sound score. Lengths that part are a pacing defect; a one-tick engine segment against a long retail one is an arm the engine runs through without its countdown.

See also

Reference Measuring against retail A cast, end to end Retail comparison corpus Retail oracle method PCSX-Redux automation Cast modules Full doc