Skip to content

Commit c24aaf5

Browse files
kjaroshjarca0123
andcommitted
core: Add PLACED_BY_AVM1_SCRIPT DisplayObject flag
Add a flag PLACED_BY_AVM1_SCRIPT, which is used for rewind logic. This patch by itself does not change how rewinds work. This is pulled from ruffle-rs#21336 as a low-risk patch. Co-authored-by: jarca0123 <11705208+jarca0123@users.noreply.github.com>
1 parent 2484549 commit c24aaf5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

core/src/avm1/globals/movie_clip.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ fn attach_movie<'gc>(
798798
.library_for_movie(movie_clip.movie())
799799
.and_then(|l| l.instantiate_by_export_name(export_name, activation.gc()))
800800
{
801+
new_clip.set_placed_by_avm1_script(true);
801802
// Set name and attach to parent.
802803
new_clip.set_name(activation.gc(), new_instance_name);
803804
movie_clip.replace_at_depth(activation.context, new_clip, depth);
@@ -839,6 +840,7 @@ fn create_empty_movie_clip<'gc>(
839840
// Create empty movie clip.
840841
let swf_movie = movie_clip.movie();
841842
let new_clip = MovieClip::new(swf_movie, activation.gc());
843+
new_clip.set_placed_by_avm1_script(true);
842844

843845
// Set name and attach to parent.
844846
new_clip.set_name(activation.gc(), new_instance_name);
@@ -968,6 +970,7 @@ pub fn clone_sprite<'gc>(
968970
// Dynamically created clip; create a new empty movie clip.
969971
MovieClip::new(movie, context.gc())
970972
};
973+
new_clip.set_placed_by_avm1_script(true);
971974

972975
// Set name and attach to parent.
973976
new_clip.set_name(context.gc(), target);

core/src/display_object.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,14 @@ impl<'gc> DisplayObjectBase<'gc> {
767767
self.set_flag(DisplayObjectFlags::PLACED_BY_SCRIPT, value);
768768
}
769769

770+
fn placed_by_avm1_script(&self) -> bool {
771+
self.contains_flag(DisplayObjectFlags::PLACED_BY_AVM1_SCRIPT)
772+
}
773+
774+
fn set_placed_by_avm1_script(&self, value: bool) {
775+
self.set_flag(DisplayObjectFlags::PLACED_BY_AVM1_SCRIPT, value);
776+
}
777+
770778
fn is_bitmap_cached_preference(&self) -> bool {
771779
self.contains_flag(DisplayObjectFlags::CACHE_AS_BITMAP)
772780
}
@@ -2154,6 +2162,16 @@ pub trait TDisplayObject<'gc>:
21542162
self.base().set_placed_by_script(value)
21552163
}
21562164

2165+
#[no_dynamic]
2166+
fn placed_by_avm1_script(self) -> bool {
2167+
self.base().placed_by_avm1_script()
2168+
}
2169+
2170+
#[no_dynamic]
2171+
fn set_placed_by_avm1_script(self, value: bool) {
2172+
self.base().set_placed_by_avm1_script(value);
2173+
}
2174+
21572175
/// Whether this display object has been instantiated by the timeline.
21582176
/// When this flag is set, attempts to change the object's name from AVM2
21592177
/// throw an exception.
@@ -2849,6 +2867,7 @@ bitflags! {
28492867

28502868
/// Whether this object has been placed in a container by ActionScript 3.
28512869
/// When this flag is set, changes from SWF `RemoveObject` tags are ignored.
2870+
// TODO [KJ] Can we repurpose it to cover PLACED_BY_AVM1_SCRIPT too?
28522871
const PLACED_BY_SCRIPT = 1 << 4;
28532872

28542873
/// Whether this object has been instantiated by a SWF tag.
@@ -2887,6 +2906,11 @@ bitflags! {
28872906

28882907
/// Whether this object has matrix3D (used for stubbing).
28892908
const HAS_MATRIX3D_STUB = 1 << 14;
2909+
2910+
/// Whether this object has been placed by an AVM1 method,
2911+
/// i.e. attachMovie, createEmptyMovieClip, duplicateMovieClip.
2912+
// TODO [KJ] Can this be merged with PLACED_BY_SCRIPT?
2913+
const PLACED_BY_AVM1_SCRIPT = 1 << 15;
28902914
}
28912915
}
28922916

0 commit comments

Comments
 (0)