Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
Herschel committed Apr 13, 2023
1 parent 5289009 commit f256aac
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 101 deletions.
32 changes: 12 additions & 20 deletions core/src/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ use self::loader_display::LoaderDisplayWeak;
#[collect(no_drop)]
pub struct DisplayObjectBase<'gc> {
parent: Option<DisplayObject<'gc>>,
place_frame: u16,
depth: Depth,
ratio: u16,
#[collect(require_static)]
transform: Transform,
name: AvmString<'gc>,
Expand Down Expand Up @@ -126,8 +126,8 @@ impl<'gc> Default for DisplayObjectBase<'gc> {
fn default() -> Self {
Self {
parent: Default::default(),
place_frame: Default::default(),
depth: Default::default(),
ratio: 0,
transform: Default::default(),
name: Default::default(),
filters: Default::default(),
Expand Down Expand Up @@ -164,14 +164,6 @@ impl<'gc> DisplayObjectBase<'gc> {
self.depth = depth;
}

fn place_frame(&self) -> u16 {
self.place_frame
}

fn set_place_frame(&mut self, frame: u16) {
self.place_frame = frame;
}

fn transform(&self) -> &Transform {
&self.transform
}
Expand Down Expand Up @@ -681,6 +673,14 @@ pub trait TDisplayObject<'gc>:
self.base_mut(gc_context).set_depth(depth)
}

fn ratio(self) -> u16 {
self.base().ratio
}

fn set_ratio(self, gc_context: MutationContext<'gc, '_>, ratio: u16) {
self.base_mut(gc_context).ratio = ratio;
}

/// The untransformed inherent bounding box of this object.
/// These bounds do **not** include child DisplayObjects.
/// To get the bounds including children, use `bounds`, `local_bounds`, or `world_bounds`.
Expand Down Expand Up @@ -734,13 +734,6 @@ pub trait TDisplayObject<'gc>:
bounds
}

fn place_frame(&self) -> u16 {
self.base().place_frame()
}
fn set_place_frame(&self, gc_context: MutationContext<'gc, '_>, frame: u16) {
self.base_mut(gc_context).set_place_frame(frame)
}

fn set_matrix(&self, gc_context: MutationContext<'gc, '_>, matrix: Matrix) {
self.base_mut(gc_context).set_matrix(matrix);
}
Expand Down Expand Up @@ -1555,9 +1548,8 @@ pub trait TDisplayObject<'gc>:
self.set_color_transform(context.gc_context, *color_transform);
}
if let Some(ratio) = place_object.ratio {
if let Some(mut morph_shape) = self.as_morph_shape() {
morph_shape.set_ratio(context.gc_context, ratio);
} else if let Some(video) = self.as_video() {
self.set_ratio(context.gc_context, ratio);
if let Some(video) = self.as_video() {
video.seek(context, ratio.into());
}
}
Expand Down
17 changes: 15 additions & 2 deletions core/src/display_object/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ pub trait TDisplayObjectContainer<'gc>:
.replace_at_depth(child, depth);

child.set_parent(context, Some(self.into()));
child.set_place_frame(context.gc_context, 0);
child.set_depth(context.gc_context, depth);

if let Some(removed_child) = removed_child {
Expand Down Expand Up @@ -260,7 +259,6 @@ pub trait TDisplayObjectContainer<'gc>:

let child_was_on_stage = child.is_on_stage(context);

child.set_place_frame(context.gc_context, 0);
child.set_parent(context, Some(this));
if !context.is_action_script_3() {
child.set_avm1_removed(context.gc_context, false);
Expand Down Expand Up @@ -372,6 +370,21 @@ pub trait TDisplayObjectContainer<'gc>:
.remove_child_from_depth_list(child);
}

/// Removes (without unloading) a child display object from this container's depth list.
fn remove_child_from_render_list(
&mut self,
context: &mut UpdateContext<'_, 'gc>,
child: DisplayObject<'gc>,
) {
debug_assert!(DisplayObject::ptr_eq(
child.parent().unwrap(),
(*self).into()
));

self.raw_container_mut(context.gc_context)
.remove_child_from_render_list(child);
}

/// Remove a set of children identified by their render list indicies from
/// this container's render and depth lists.
fn remove_range<R>(&mut self, context: &mut UpdateContext<'_, 'gc>, range: R)
Expand Down
14 changes: 2 additions & 12 deletions core/src/display_object/morph_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl fmt::Debug for MorphShape<'_> {
pub struct MorphShapeData<'gc> {
base: DisplayObjectBase<'gc>,
static_data: Gc<'gc, MorphShapeStatic>,
ratio: u16,
}

impl<'gc> MorphShape<'gc> {
Expand All @@ -43,18 +42,9 @@ impl<'gc> MorphShape<'gc> {
MorphShapeData {
base: Default::default(),
static_data: Gc::allocate(gc_context, static_data),
ratio: 0,
},
))
}

pub fn ratio(self) -> u16 {
self.0.read().ratio
}

pub fn set_ratio(&mut self, gc_context: MutationContext<'gc, '_>, ratio: u16) {
self.0.write(gc_context).ratio = ratio;
}
}

impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
Expand Down Expand Up @@ -100,7 +90,7 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {

fn render_self(&self, context: &mut RenderContext) {
let this = self.0.read();
let ratio = this.ratio;
let ratio = this.base.ratio;
let static_data = this.static_data;
let shape_handle = static_data.get_shape(context, context.library, ratio);
context
Expand All @@ -110,7 +100,7 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {

fn self_bounds(&self) -> Rectangle<Twips> {
let this = self.0.read();
let ratio = this.ratio;
let ratio = this.base.ratio;
let static_data = this.static_data;
let frame = static_data.get_frame(ratio);
frame.bounds.clone()
Expand Down
Loading

0 comments on commit f256aac

Please sign in to comment.