From 0a9b479b047c0ab667e65947e3498b5ff85eceaa Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 23 May 2024 13:43:01 -0400 Subject: [PATCH] core: Store MovieClip avm2_class in MovieClipStatic This is preparation for allowing a class to be linked to the root movie clip and instantiated. --- core/src/display_object/movie_clip.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/src/display_object/movie_clip.rs b/core/src/display_object/movie_clip.rs index 51abca384728..8fc325aa0eac 100644 --- a/core/src/display_object/movie_clip.rs +++ b/core/src/display_object/movie_clip.rs @@ -159,7 +159,6 @@ pub struct MovieClipData<'gc> { frame_scripts: Vec>>, #[collect(require_static)] flags: MovieClipFlags, - avm2_class: Option>, #[collect(require_static)] drawing: Drawing, avm2_enabled: bool, @@ -209,7 +208,6 @@ impl<'gc> MovieClip<'gc> { clip_event_flags: ClipEventFlag::empty(), frame_scripts: Vec::new(), flags: MovieClipFlags::empty(), - avm2_class: None, drawing: Drawing::new(), avm2_enabled: true, avm2_use_hand_cursor: true, @@ -234,7 +232,7 @@ impl<'gc> MovieClip<'gc> { class: Avm2ClassObject<'gc>, gc_context: &Mutation<'gc>, ) -> Self { - MovieClip(GcCell::new( + let clip = MovieClip(GcCell::new( gc_context, MovieClipData { base: Default::default(), @@ -251,7 +249,6 @@ impl<'gc> MovieClip<'gc> { clip_event_flags: ClipEventFlag::empty(), frame_scripts: Vec::new(), flags: MovieClipFlags::empty(), - avm2_class: Some(class), drawing: Drawing::new(), avm2_enabled: true, avm2_use_hand_cursor: true, @@ -267,7 +264,9 @@ impl<'gc> MovieClip<'gc> { queued_tags: HashMap::new(), attached_audio: None, }, - )) + )); + clip.set_avm2_class(gc_context, Some(class)); + clip } /// Constructs a non-root movie @@ -294,7 +293,6 @@ impl<'gc> MovieClip<'gc> { clip_event_flags: ClipEventFlag::empty(), frame_scripts: Vec::new(), flags: MovieClipFlags::PLAYING, - avm2_class: None, drawing: Drawing::new(), avm2_enabled: true, avm2_use_hand_cursor: true, @@ -362,7 +360,6 @@ impl<'gc> MovieClip<'gc> { clip_event_flags: ClipEventFlag::empty(), frame_scripts: Vec::new(), flags: MovieClipFlags::PLAYING, - avm2_class: None, drawing: Drawing::new(), avm2_enabled: true, avm2_use_hand_cursor: true, @@ -1370,8 +1367,7 @@ impl<'gc> MovieClip<'gc> { } pub fn set_avm2_class(self, gc_context: &Mutation<'gc>, constr: Option>) { - let mut write = self.0.write(gc_context); - write.avm2_class = constr; + *self.0.read().static_data.avm2_class.write(gc_context) = constr; } pub fn frame_label_to_number( @@ -2192,7 +2188,9 @@ impl<'gc> MovieClip<'gc> { let class_object = self .0 .read() + .static_data .avm2_class + .read() .unwrap_or_else(|| context.avm2.classes().movieclip); let mut constr_thing = || { @@ -2222,7 +2220,9 @@ impl<'gc> MovieClip<'gc> { let class_object = self .0 .read() + .static_data .avm2_class + .read() .unwrap_or_else(|| context.avm2.classes().movieclip); if let Avm2Value::Object(object) = self.object2() { @@ -4611,6 +4611,7 @@ struct MovieClipStatic<'gc> { /// The last known symbol name under which this movie clip was exported. /// Used for looking up constructors registered with `Object.registerClass`. exported_name: GcCell<'gc, Option>>, + avm2_class: GcCell<'gc, Option>>, /// Only set if this MovieClip is the root movie in an SWF /// (either the root SWF initially loaded by the player, /// or an SWF dynamically loaded by `Loader`) @@ -4657,6 +4658,7 @@ impl<'gc> MovieClipStatic<'gc> { audio_stream_info: None, audio_stream_handle: None, exported_name: GcCell::new(gc_context, None), + avm2_class: GcCell::new(gc_context, None), loader_info, preload_progress: GcCell::new(gc_context, Default::default()), processed_bytecode_tags_pos: GcCell::new(gc_context, -1),