From f0ef8adb42b3c314f9e9b1f6b552412cdbbd47e4 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Mon, 10 Jan 2022 20:25:39 -0500 Subject: [PATCH] core: Add a new frame phase to represent non-frame work such as input event handlers. --- core/src/frame_lifecycle.rs | 13 ++++++++++--- core/src/player.rs | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/src/frame_lifecycle.rs b/core/src/frame_lifecycle.rs index 23c9ea34e..1bb0f2873 100644 --- a/core/src/frame_lifecycle.rs +++ b/core/src/frame_lifecycle.rs @@ -17,7 +17,8 @@ use crate::display_object::TDisplayObject; /// Which phase of the frame we're currently in. /// /// AVM2 frames exist in one of five phases: `Enter`, `Construct`, `Update`, -/// `FrameScripts`, or `Exit`. +/// `FrameScripts`, or `Exit`. An additional `Idle` phase covers rendering and +/// event processing. #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum FramePhase { /// We're entering the next frame. @@ -60,6 +61,12 @@ pub enum FramePhase { /// When we exit a completed frame, we fire `exitFrame` on the broadcast /// list. Exit, + + /// We're not currently executing any frame code. + /// + /// At this point in time, event handlers are expected to run. No frame + /// catch-up work should execute. + Idle, } /// Run one frame according to AVM1 frame order. @@ -86,7 +93,7 @@ pub fn run_all_phases_avm1<'gc>(context: &mut UpdateContext<'_, 'gc, '_>) { .load_manager .movie_clip_on_load(context.action_queue); - *context.frame_phase = FramePhase::Enter; + *context.frame_phase = FramePhase::Idle; } /// Run one frame according to AVM2 frame order. @@ -109,5 +116,5 @@ pub fn run_all_phases_avm2<'gc>(context: &mut UpdateContext<'_, 'gc, '_>) { *context.frame_phase = FramePhase::Exit; stage.exit_frame(context); - *context.frame_phase = FramePhase::Enter; + *context.frame_phase = FramePhase::Idle; } diff --git a/core/src/player.rs b/core/src/player.rs index b77a9db8d..fdf14790a 100644 --- a/core/src/player.rs +++ b/core/src/player.rs @@ -1260,9 +1260,10 @@ impl Player { pub fn run_frame(&mut self) { self.update(|context| { - match context.swf.avm_type() { - AvmType::Avm1 => run_all_phases_avm1(context), - AvmType::Avm2 => run_all_phases_avm2(context), + if context.is_action_script_3() { + run_all_phases_avm2(context); + } else { + run_all_phases_avm1(context); } context.update_sounds(); });