core: Add a new frame phase to represent non-frame work such as input event handlers.

This commit is contained in:
David Wendt 2022-01-10 20:25:39 -05:00 committed by kmeisthax
parent ae530b5d6b
commit f0ef8adb42
2 changed files with 14 additions and 6 deletions

View File

@ -17,7 +17,8 @@ use crate::display_object::TDisplayObject;
/// Which phase of the frame we're currently in. /// Which phase of the frame we're currently in.
/// ///
/// AVM2 frames exist in one of five phases: `Enter`, `Construct`, `Update`, /// 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)] #[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum FramePhase { pub enum FramePhase {
/// We're entering the next frame. /// 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 /// When we exit a completed frame, we fire `exitFrame` on the broadcast
/// list. /// list.
Exit, 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. /// 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 .load_manager
.movie_clip_on_load(context.action_queue); .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. /// 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; *context.frame_phase = FramePhase::Exit;
stage.exit_frame(context); stage.exit_frame(context);
*context.frame_phase = FramePhase::Enter; *context.frame_phase = FramePhase::Idle;
} }

View File

@ -1260,9 +1260,10 @@ impl Player {
pub fn run_frame(&mut self) { pub fn run_frame(&mut self) {
self.update(|context| { self.update(|context| {
match context.swf.avm_type() { if context.is_action_script_3() {
AvmType::Avm1 => run_all_phases_avm1(context), run_all_phases_avm2(context);
AvmType::Avm2 => run_all_phases_avm2(context), } else {
run_all_phases_avm1(context);
} }
context.update_sounds(); context.update_sounds();
}); });