Skip to content

Commit 2042829

Browse files
core: Move exit_frame and frame_constructed to frame_lifecycle.rs
Also make them standalone functions instead of associated methods. Previously, they were associated methods on `TDisplayObject`, but they didn't actually access the `DisplayObject` they were called on
1 parent f3080ad commit 2042829

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

core/src/display_object.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ use crate::avm1::{
22
ActivationIdentifier as Avm1ActivationIdentifier, Object as Avm1Object, Value as Avm1Value,
33
};
44
use crate::avm2::{
5-
Activation as Avm2Activation, Avm2, Error as Avm2Error, EventObject as Avm2EventObject,
6-
LoaderInfoObject, Multiname as Avm2Multiname, Object as Avm2Object,
7-
StageObject as Avm2StageObject, TObject as _, Value as Avm2Value,
5+
Activation as Avm2Activation, Error as Avm2Error, LoaderInfoObject, Multiname as Avm2Multiname,
6+
Object as Avm2Object, StageObject as Avm2StageObject, TObject as _, Value as Avm2Value,
87
};
98
use crate::context::{RenderContext, UpdateContext};
109
use crate::drawing::Drawing;
11-
use crate::loader::LoadManager;
1210
use crate::prelude::*;
1311
use crate::string::{AvmString, WString};
1412
use crate::tag_utils::SwfMovie;
@@ -2344,16 +2342,6 @@ pub trait TDisplayObject<'gc>:
23442342
}
23452343
}
23462344

2347-
/// Emit a `frameConstructed` event on this DisplayObject and any children it
2348-
/// may have.
2349-
#[no_dynamic]
2350-
fn frame_constructed(self, context: &mut UpdateContext<'gc>) {
2351-
let frame_constructed_evt =
2352-
Avm2EventObject::bare_default_event(context, "frameConstructed");
2353-
let dobject_constr = context.avm2.classes().display_object;
2354-
Avm2::broadcast_event(context, frame_constructed_evt, dobject_constr);
2355-
}
2356-
23572345
/// Run any frame scripts (if they exist and this object needs to run them).
23582346
fn run_frame_scripts(self, context: &mut UpdateContext<'gc>) {
23592347
if let Some(container) = self.as_container() {
@@ -2363,16 +2351,6 @@ pub trait TDisplayObject<'gc>:
23632351
}
23642352
}
23652353

2366-
/// Emit an `exitFrame` broadcast event.
2367-
#[no_dynamic]
2368-
fn exit_frame(self, context: &mut UpdateContext<'gc>) {
2369-
let exit_frame_evt = Avm2EventObject::bare_default_event(context, "exitFrame");
2370-
let dobject_constr = context.avm2.classes().display_object;
2371-
Avm2::broadcast_event(context, exit_frame_evt, dobject_constr);
2372-
2373-
LoadManager::run_exit_frame(context);
2374-
}
2375-
23762354
/// Called before the child is about to be rendered.
23772355
/// Note that this happens even if the child is invisible
23782356
/// (as long as the child is still on a render list)

core/src/display_object/avm2_button.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use crate::display_object::container::{dispatch_added_event, dispatch_removed_ev
1414
use crate::display_object::interactive::{InteractiveObjectBase, TInteractiveObject};
1515
use crate::display_object::{DisplayObjectBase, MovieClip};
1616
use crate::events::{ClipEvent, ClipEventResult};
17-
use crate::frame_lifecycle::catchup_display_object_to_frame;
17+
use crate::frame_lifecycle::{
18+
broadcast_frame_constructed, broadcast_frame_exited, catchup_display_object_to_frame,
19+
};
1820
use crate::prelude::*;
1921
use crate::tag_utils::{SwfMovie, SwfSlice};
2022
use crate::vminterface::Instantiator;
@@ -363,15 +365,17 @@ impl<'gc> Avm2Button<'gc> {
363365
dispatch_removed_event(old_state_child, context);
364366
}
365367

366-
if let Some(child) = child {
367-
child.frame_constructed(context);
368+
// FIXME is this correct?
369+
if child.is_some() {
370+
broadcast_frame_constructed(context);
368371
}
369372
}
370373

371374
if is_cur_state {
372375
if let Some(child) = child {
373376
child.run_frame_scripts(context);
374-
child.exit_frame(context);
377+
// FIXME is this correct?
378+
broadcast_frame_exited(context);
375379
}
376380
}
377381
}
@@ -527,10 +531,10 @@ impl<'gc> TDisplayObject<'gc> for Avm2Button<'gc> {
527531

528532
let stage = context.stage;
529533
stage.construct_frame(context);
530-
stage.frame_constructed(context);
534+
broadcast_frame_constructed(context);
531535
self.set_state(context, ButtonState::Up);
532536
stage.run_frame_scripts(context);
533-
stage.exit_frame(context);
537+
broadcast_frame_exited(context);
534538
}
535539

536540
if let Some(avm2_object) = self.0.object.get() {

core/src/frame_lifecycle.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
//! runs in one phase, with timeline operations executing with all phases
1212
//! inline in the order that clips were originally created.
1313
14+
use crate::avm2::{Avm2, EventObject};
1415
use crate::avm2_stub_method_context;
1516
use crate::context::UpdateContext;
1617
use crate::display_object::{DisplayObject, MovieClip, TDisplayObject};
18+
use crate::loader::LoadManager;
1719
use crate::orphan_manager::OrphanManager;
1820
use tracing::instrument;
1921

@@ -87,7 +89,7 @@ pub fn run_all_phases_avm2(context: &mut UpdateContext<'_>) {
8789
orphan.construct_frame(context);
8890
});
8991
stage.construct_frame(context);
90-
stage.frame_constructed(context);
92+
broadcast_frame_constructed(context);
9193

9294
*context.frame_phase = FramePhase::FrameScripts;
9395
OrphanManager::each_orphan_obj(context, |orphan, context| {
@@ -97,7 +99,7 @@ pub fn run_all_phases_avm2(context: &mut UpdateContext<'_>) {
9799
MovieClip::run_frame_script_cleanup(context);
98100

99101
*context.frame_phase = FramePhase::Exit;
100-
stage.exit_frame(context);
102+
broadcast_frame_exited(context);
101103

102104
// We cannot easily remove dead `GcWeak` instances from the orphan list
103105
// inside `each_orphan_movie`, since the callback may modify the orphan list.
@@ -151,7 +153,7 @@ pub fn run_inner_goto_frame<'gc>(
151153
orphan.construct_frame(context);
152154
});
153155
stage.construct_frame(context);
154-
stage.frame_constructed(context);
156+
broadcast_frame_constructed(context);
155157

156158
*context.frame_phase = FramePhase::FrameScripts;
157159
stage.run_frame_scripts(context);
@@ -164,7 +166,7 @@ pub fn run_inner_goto_frame<'gc>(
164166
}
165167

166168
*context.frame_phase = FramePhase::Exit;
167-
stage.exit_frame(context);
169+
broadcast_frame_exited(context);
168170

169171
// We cannot easily remove dead `GcWeak` instances from the orphan list
170172
// inside `each_orphan_movie`, since the callback may modify the orphan list.
@@ -176,6 +178,22 @@ pub fn run_inner_goto_frame<'gc>(
176178
*context.frame_phase = old_phase;
177179
}
178180

181+
/// Broadcast a `frameConstructed` event to all `DisplayObject`s.
182+
pub fn broadcast_frame_constructed<'gc>(context: &mut UpdateContext<'gc>) {
183+
let frame_constructed_evt = EventObject::bare_default_event(context, "frameConstructed");
184+
let dobject_constr = context.avm2.classes().display_object;
185+
Avm2::broadcast_event(context, frame_constructed_evt, dobject_constr);
186+
}
187+
188+
/// Broadcast a `exitFrame` event to all `DisplayObject`s.
189+
pub fn broadcast_frame_exited<'gc>(context: &mut UpdateContext<'gc>) {
190+
let exit_frame_evt = EventObject::bare_default_event(context, "exitFrame");
191+
let dobject_constr = context.avm2.classes().display_object;
192+
Avm2::broadcast_event(context, exit_frame_evt, dobject_constr);
193+
194+
LoadManager::run_exit_frame(context);
195+
}
196+
179197
/// Run all previously-executed frame phases on a newly-constructed display
180198
/// object.
181199
///

0 commit comments

Comments
 (0)