End the show when its world closes and verify the MP4 lifecycle (#89)
A frame hook ends an active film or export when the world is gone. The game stops ticking at the title screen but keeps rendering, so an export used to keep recording the title with its playback clock frozen (a sec=10 request produced 3898 frames) and went on after re-entering the world. Session cleanup runs once with WorldChange and cancels the capture. Real short exports on a scratch home and world (pin 57f8b2853, API 29, Metal): h264+AAC both 2.07 s with non-silent audio, reported frames equal ffprobe nb_frames; cancel, SDK refusal, encoder failure and restart all leave no capture running; 1920x1080 works. The engine still leaves *.audio.raw and *.ffmpeg.log behind on an encoder error (game/film.rs). Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
@@ -286,6 +286,16 @@ impl<P, E> Session<P, E> {
|
||||
Some(Cleanup { actions })
|
||||
}
|
||||
|
||||
/// The world is gone (the title screen): the game stops ticking there, so an active export
|
||||
/// would otherwise go on recording the title with its playback clock frozen. Nothing to do
|
||||
/// in Live, and a world still open is not a leave.
|
||||
pub fn world_left(&mut self, world: Option<&str>) -> Option<Cleanup> {
|
||||
if self.is_live() || world.is_some() {
|
||||
return None;
|
||||
}
|
||||
self.end(ExitCause::WorldChange)
|
||||
}
|
||||
|
||||
/// A world change invalidates live work too. Active playback uses the normal cleanup path,
|
||||
/// which advances generation exactly once; Live advances generation without host cleanup.
|
||||
pub fn world_changed(&mut self) -> Option<Cleanup> {
|
||||
@@ -466,6 +476,30 @@ mod tests {
|
||||
assert_ne!(session.generation(), first);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_gone_world_ends_an_active_export_once() {
|
||||
let mut session = Session::<(), ()>::default();
|
||||
assert!(session.world_left(None).is_none(), "Live has nothing to clean up");
|
||||
session.replay(());
|
||||
assert!(session.world_left(Some("world:w")).is_none(), "the world is still open");
|
||||
let State::Replay(playback) = session.take() else {
|
||||
panic!("replay state lost")
|
||||
};
|
||||
session.export(playback, ());
|
||||
let cleanup = session.world_left(None).expect("the title screen ends the export");
|
||||
assert!(cleanup.actions.contains(&CleanupAction::CancelCapture));
|
||||
|
||||
let mut host = HostFixture::default();
|
||||
host.apply(&cleanup);
|
||||
let count = host.actions.len();
|
||||
assert!(session.world_left(None).is_none(), "a second frame sees Live");
|
||||
assert_eq!(host.actions.len(), count, "cleanup is not repeated");
|
||||
assert_eq!(
|
||||
host.actions.iter().filter(|a| **a == CleanupAction::CancelCapture).count(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn end_and_restart_emit_cleanup_once_for_stop_unload_failure_and_success() {
|
||||
for cause in [
|
||||
|
||||
Reference in New Issue
Block a user