Skip to content

Commit 2484549

Browse files
kjaroshHerscheljarca0123
committed
core: Track PlaceObject's ratio on DisplayObject
This patch sets PlaceObject's ratio on DisplayObject as it's also used for rewind logic. By itself this patch does not change how rewinds work. This is pulled from #21336 as a low-risk patch. Co-authored-by: Mike Welsh <mwelsh@gmail.com> Co-authored-by: jarca0123 <11705208+jarca0123@users.noreply.github.com>
1 parent a388d0e commit 2484549

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

core/src/display_object.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ pub struct DisplayObjectBase<'gc> {
238238
parent: Lock<Option<DisplayObject<'gc>>>,
239239
place_frame: Cell<u16>,
240240
depth: Cell<Depth>,
241+
ratio: Cell<u16>,
241242
name: Lock<Option<AvmString<'gc>>>,
242243
clip_depth: Cell<Depth>,
243244

@@ -316,6 +317,7 @@ impl Default for DisplayObjectBase<'_> {
316317
parent: Default::default(),
317318
place_frame: Default::default(),
318319
depth: Default::default(),
320+
ratio: Default::default(),
319321
name: Lock::new(None),
320322
clip_depth: Default::default(),
321323
matrix: Default::default(),
@@ -1686,6 +1688,20 @@ pub trait TDisplayObject<'gc>:
16861688
self.set_scale_y(Percent::from_unit(new_scale_y));
16871689
}
16881690

1691+
#[no_dynamic]
1692+
fn ratio(self) -> u16 {
1693+
self.base().ratio.get()
1694+
}
1695+
1696+
#[no_dynamic]
1697+
fn set_ratio(self, context: &mut UpdateContext<'gc>, ratio: u16) {
1698+
self.base().ratio.set(ratio);
1699+
self.invalidate_cached_bitmap();
1700+
self.on_ratio_changed(context, ratio);
1701+
}
1702+
1703+
fn on_ratio_changed(self, _context: &mut UpdateContext<'gc>, _new_ratio: u16) {}
1704+
16891705
/// The opacity of this display object.
16901706
/// 1 is fully opaque.
16911707
/// Returned by the `_alpha`/`alpha` ActionScript properties.
@@ -2427,11 +2443,7 @@ pub trait TDisplayObject<'gc>:
24272443
}
24282444
}
24292445
if let Some(ratio) = place_object.ratio {
2430-
if let Some(morph_shape) = self.as_morph_shape() {
2431-
morph_shape.set_ratio(ratio);
2432-
} else if let Some(video) = self.as_video() {
2433-
video.seek(context, ratio.into());
2434-
}
2446+
self.set_ratio(context, ratio);
24352447
}
24362448
if let Some(is_bitmap_cached) = place_object.is_bitmap_cached {
24372449
self.set_bitmap_cached_preference(is_bitmap_cached);

core/src/display_object/morph_shape.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use gc_arena::lock::Lock;
1111
use gc_arena::{Collect, Gc, Mutation};
1212
use ruffle_render::backend::ShapeHandle;
1313
use ruffle_render::commands::CommandHandler;
14-
use std::cell::{Cell, RefCell, RefMut};
14+
use std::cell::{RefCell, RefMut};
1515
use std::sync::Arc;
1616
use swf::{Fixed16, Fixed8};
1717

@@ -35,7 +35,6 @@ pub struct MorphShapeData<'gc> {
3535
shared: Lock<Gc<'gc, MorphShapeShared>>,
3636
/// The AVM2 representation of this MorphShape.
3737
object: Lock<Option<Avm2StageObject<'gc>>>,
38-
ratio: Cell<u16>,
3938
}
4039

4140
impl<'gc> MorphShape<'gc> {
@@ -50,20 +49,10 @@ impl<'gc> MorphShape<'gc> {
5049
MorphShapeData {
5150
base: Default::default(),
5251
shared: Lock::new(Gc::new(gc_context, shared)),
53-
ratio: Cell::new(0),
5452
object: Lock::new(None),
5553
},
5654
))
5755
}
58-
59-
pub fn ratio(self) -> u16 {
60-
self.0.ratio.get()
61-
}
62-
63-
pub fn set_ratio(self, ratio: u16) {
64-
self.0.ratio.set(ratio);
65-
self.invalidate_cached_bitmap();
66-
}
6756
}
6857

6958
impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
@@ -117,7 +106,7 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
117106
}
118107

119108
fn render_self(self, context: &mut RenderContext) {
120-
let ratio = self.0.ratio.get();
109+
let ratio = self.ratio();
121110
let shared = self.0.shared.get();
122111
let shape_handle = shared.get_shape(context, context.library, ratio);
123112
context
@@ -126,7 +115,7 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
126115
}
127116

128117
fn self_bounds(self) -> Rectangle<Twips> {
129-
let ratio = self.0.ratio.get();
118+
let ratio = self.ratio();
130119
let shared = self.0.shared.get();
131120
let frame = shared.get_frame(ratio);
132121
frame.bounds

core/src/display_object/video.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ impl<'gc> TDisplayObject<'gc> for Video<'gc> {
454454
}
455455
}
456456

457+
fn on_ratio_changed(self, context: &mut UpdateContext<'gc>, new_ratio: u16) {
458+
self.seek(context, new_ratio.into());
459+
}
460+
457461
fn id(self) -> CharacterId {
458462
match self.0.source.get() {
459463
VideoSource::Swf(swf_source) => swf_source.streamdef.id,

0 commit comments

Comments
 (0)