From 53010544db58ffa63cbf4b5e051f5efcb2b1d5b7 Mon Sep 17 00:00:00 2001 From: Moulins Date: Wed, 23 Nov 2022 02:28:52 +0100 Subject: [PATCH] core: Simplify core::do::container::Lists bitflags into boolean enum Callsites only ever used two values, as children in the display list are always in the render list. --- core/src/avm1/globals.rs | 2 +- .../flash/display/displayobjectcontainer.rs | 4 +- core/src/display_object.rs | 2 +- core/src/display_object/avm1_button.rs | 2 +- core/src/display_object/avm2_button.rs | 2 +- core/src/display_object/container.rs | 41 ++++++++++--------- core/src/display_object/movie_clip.rs | 12 +++--- 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/core/src/avm1/globals.rs b/core/src/avm1/globals.rs index 2dc7f260d..2105d237c 100644 --- a/core/src/avm1/globals.rs +++ b/core/src/avm1/globals.rs @@ -1204,7 +1204,7 @@ pub fn remove_display_object<'gc>( if depth >= AVM_DEPTH_BIAS && depth < AVM_MAX_REMOVE_DEPTH && !this.removed() { // Need a parent to remove from. if let Some(mut parent) = this.avm1_parent().and_then(|o| o.as_movie_clip()) { - parent.remove_child(&mut activation.context, this, Lists::all()); + parent.remove_child(&mut activation.context, this, Lists::Render); } } } diff --git a/core/src/avm2/globals/flash/display/displayobjectcontainer.rs b/core/src/avm2/globals/flash/display/displayobjectcontainer.rs index 27ace5e1d..cff9d84f8 100644 --- a/core/src/avm2/globals/flash/display/displayobjectcontainer.rs +++ b/core/src/avm2/globals/flash/display/displayobjectcontainer.rs @@ -109,7 +109,7 @@ fn remove_child_from_displaylist<'gc>( ) { if let Some(parent) = child.parent() { if let Some(mut ctr) = parent.as_container() { - ctr.remove_child(context, child, Lists::all()); + ctr.remove_child(context, child, Lists::Render); } } } @@ -360,7 +360,7 @@ pub fn remove_child_at<'gc>( let child = ctr.child_by_index(target_child as usize).unwrap(); - ctr.remove_child(&mut activation.context, child, Lists::all()); + ctr.remove_child(&mut activation.context, child, Lists::Render); return Ok(child.object2()); } diff --git a/core/src/display_object.rs b/core/src/display_object.rs index eccd15ca4..8bc1a3750 100644 --- a/core/src/display_object.rs +++ b/core/src/display_object.rs @@ -1621,7 +1621,7 @@ bitflags! { const PLACED_BY_SCRIPT = 1 << 4; /// Whether this object has been instantiated by a SWF tag. - /// When this flag is set, changes from SWF `RemoveObject` tags are ignored. + /// When this flag is set, attempts to change the object's name from AVM2 throw an exception. const INSTANTIATED_BY_TIMELINE = 1 << 5; /// Whether this object is a "root", the top-most display object of a loaded SWF or Bitmap. diff --git a/core/src/display_object/avm1_button.rs b/core/src/display_object/avm1_button.rs index 21ebe8071..bcb15b8c4 100644 --- a/core/src/display_object/avm1_button.rs +++ b/core/src/display_object/avm1_button.rs @@ -180,7 +180,7 @@ impl<'gc> Avm1Button<'gc> { // Kill children that no longer exist in this state. for depth in removed_depths { if let Some(child) = self.child_by_depth(depth) { - self.remove_child(context, child, Lists::all()); + self.remove_child(context, child, Lists::Render); } } diff --git a/core/src/display_object/avm2_button.rs b/core/src/display_object/avm2_button.rs index 88db1da7d..cc1483f6b 100644 --- a/core/src/display_object/avm2_button.rs +++ b/core/src/display_object/avm2_button.rs @@ -309,7 +309,7 @@ impl<'gc> Avm2Button<'gc> { if let Some(child) = child { if let Some(mut parent) = child.parent().and_then(|parent| parent.as_container()) { - parent.remove_child(context, child, Lists::all()); + parent.remove_child(context, child, Lists::Render); } if is_cur_state { diff --git a/core/src/display_object/container.rs b/core/src/display_object/container.rs index b9694c910..558672587 100644 --- a/core/src/display_object/container.rs +++ b/core/src/display_object/container.rs @@ -8,7 +8,6 @@ use crate::display_object::movie_clip::MovieClip; use crate::display_object::stage::Stage; use crate::display_object::{Depth, DisplayObject, TDisplayObject}; use crate::string::WStr; -use bitflags::bitflags; use gc_arena::{Collect, MutationContext}; use ruffle_macros::enum_trait_object; use ruffle_render::commands::CommandHandler; @@ -121,21 +120,22 @@ pub fn dispatch_added_event<'gc>( } } -bitflags! { - /// The three lists that a display object container is supposed to maintain. - pub struct Lists: u8 { - /// The list that determines the order in which children are rendered. - /// - /// This is directly manipulated by AVM2 code. - const RENDER = 1 << 0; +#[derive(Copy, Clone)] +pub enum Lists { + /// The list that determines the identity of children according to the + /// timeline and AVM1 code. + /// + /// Manipulations of the depth list are generally propagated to the render + /// list, except in cases where children have been reordered by AVM2. + Depth, - /// The list that determines the identity of children according to the - /// timeline and AVM1 code. - /// - /// Manipulations of the depth list are generally propagated to the render - /// list, except in cases where children have been reordered by AVM2. - const DEPTH = 1 << 1; - } + /// The render list determines the order in which children are rendered. + /// + /// Removing a child from the render list automatically removes it from the depth + /// list. + /// + /// It is directly manipulated by AVM2 code. + Render, } #[enum_trait_object( @@ -278,7 +278,7 @@ pub trait TDisplayObjectContainer<'gc>: let parent_changed = if let Some(old_parent) = child.parent() { if !DisplayObject::ptr_eq(old_parent, this) { if let Some(mut old_parent) = old_parent.as_container() { - old_parent.remove_child(context, child, Lists::all()); + old_parent.remove_child(context, child, Lists::Render); } true @@ -340,10 +340,11 @@ pub trait TDisplayObjectContainer<'gc>: let mut write = self.raw_container_mut(context.gc_context); - let removed_from_depth_list = - from_lists.contains(Lists::DEPTH) && write.remove_child_from_depth_list(child); - let removed_from_render_list = - from_lists.contains(Lists::RENDER) && write.remove_child_from_render_list(child); + let removed_from_depth_list = write.remove_child_from_depth_list(child); + let removed_from_render_list = match from_lists { + Lists::Render => write.remove_child_from_render_list(child), + Lists::Depth => false, + }; drop(write); diff --git a/core/src/display_object/movie_clip.rs b/core/src/display_object/movie_clip.rs index e43a2b5b7..7215a8120 100644 --- a/core/src/display_object/movie_clip.rs +++ b/core/src/display_object/movie_clip.rs @@ -1742,9 +1742,9 @@ impl<'gc> MovieClip<'gc> { .collect(); for child in children { if !child.placed_by_script() { - self.remove_child(context, child, Lists::all()); + self.remove_child(context, child, Lists::Render); } else { - self.remove_child(context, child, Lists::DEPTH); + self.remove_child(context, child, Lists::Depth); } } } @@ -2107,9 +2107,9 @@ impl<'gc> MovieClip<'gc> { let child = self.child_by_depth(depth); if let Some(child) = child { if !child.placed_by_script() { - self.remove_child(context, child, Lists::all()); + self.remove_child(context, child, Lists::Render); } else { - self.remove_child(context, child, Lists::DEPTH); + self.remove_child(context, child, Lists::Depth); } removed_frame_scripts.push(child); @@ -3700,9 +3700,9 @@ impl<'gc, 'a> MovieClip<'gc> { if let Some(child) = self.child_by_depth(remove_object.depth.into()) { if !child.placed_by_script() { - self.remove_child(context, child, Lists::all()); + self.remove_child(context, child, Lists::Render); } else { - self.remove_child(context, child, Lists::DEPTH); + self.remove_child(context, child, Lists::Depth); } }