Skip to content

Commit a546909

Browse files
committed
core: Rename display objects' static_data field to shared
...and the corresponding `FooStatic` structs to `FooShared`. This better represents the semantics, and avoids conflation with the `'static` lifetime (in fact, these structs sometimes contain GC'd data).
1 parent 0f1b72e commit a546909

File tree

7 files changed

+213
-244
lines changed

7 files changed

+213
-244
lines changed

core/src/display_object/avm1_button.rs

+28-29
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl fmt::Debug for Avm1Button<'_> {
4040
#[collect(no_drop)]
4141
pub struct Avm1ButtonData<'gc> {
4242
cell: RefLock<Avm1ButtonDataMut<'gc>>,
43-
static_data: Gc<'gc, ButtonStatic>,
43+
shared: Gc<'gc, ButtonShared>,
4444
state: Cell<ButtonState>,
4545
tracking: Cell<ButtonTracking>,
4646
object: Lock<Option<Object<'gc>>>,
@@ -77,13 +77,13 @@ impl<'gc> Avm1Button<'gc> {
7777
hit_area: BTreeMap::new(),
7878
hit_bounds: Default::default(),
7979
}),
80-
static_data: Gc::new(
80+
shared: Gc::new(
8181
mc,
82-
ButtonStatic {
82+
ButtonShared {
8383
swf: source_movie.movie.clone(),
8484
id: button.id,
8585
actions,
86-
cell: RefCell::new(ButtonStaticMut {
86+
cell: RefCell::new(ButtonSharedMut {
8787
records: button.records.clone(),
8888
up_to_over_sound: None,
8989
over_to_down_sound: None,
@@ -105,22 +105,21 @@ impl<'gc> Avm1Button<'gc> {
105105
}
106106

107107
pub fn set_sounds(self, sounds: swf::ButtonSounds) {
108-
let mut static_data = self.0.static_data.cell.borrow_mut();
109-
static_data.up_to_over_sound = sounds.up_to_over_sound;
110-
static_data.over_to_down_sound = sounds.over_to_down_sound;
111-
static_data.down_to_over_sound = sounds.down_to_over_sound;
112-
static_data.over_to_up_sound = sounds.over_to_up_sound;
108+
let mut shared = self.0.shared.cell.borrow_mut();
109+
shared.up_to_over_sound = sounds.up_to_over_sound;
110+
shared.over_to_down_sound = sounds.over_to_down_sound;
111+
shared.down_to_over_sound = sounds.down_to_over_sound;
112+
shared.over_to_up_sound = sounds.over_to_up_sound;
113113
}
114114

115115
/// Handles the ancient DefineButtonCxform SWF tag.
116116
/// Set the color transform for all children of each state.
117117
pub fn set_colors(self, color_transforms: &[swf::ColorTransform]) {
118-
let mut static_data = self.0.static_data.cell.borrow_mut();
118+
let mut shared = self.0.shared.cell.borrow_mut();
119119

120120
// This tag isn't documented well in SWF19. It is only used in very old SWF<=2 content.
121121
// It applies color transforms to every character in a button, in sequence(?).
122-
for (record, color_transform) in static_data.records.iter_mut().zip(color_transforms.iter())
123-
{
122+
for (record, color_transform) in shared.records.iter_mut().zip(color_transforms.iter()) {
124123
record.color_transform = *color_transform;
125124
}
126125
}
@@ -142,7 +141,7 @@ impl<'gc> Avm1Button<'gc> {
142141
// TODO: This behavior probably differs in AVM2 (I suspect they always get recreated).
143142
let mut children = Vec::new();
144143

145-
for record in &self.0.static_data.cell.borrow().records {
144+
for record in &self.0.shared.cell.borrow().records {
146145
if record.states.contains(state.into()) {
147146
// State contains this depth, so we don't have to remove it.
148147
removed_depths.remove(&record.depth.into());
@@ -260,7 +259,7 @@ impl<'gc> TDisplayObject<'gc> for Avm1Button<'gc> {
260259
}
261260

262261
fn id(&self) -> CharacterId {
263-
self.0.static_data.id
262+
self.0.shared.id
264263
}
265264

266265
fn movie(&self) -> Arc<SwfMovie> {
@@ -306,7 +305,7 @@ impl<'gc> TDisplayObject<'gc> for Avm1Button<'gc> {
306305
self.set_state(context, ButtonState::Up);
307306
self.0.initialized.set(true);
308307

309-
for record in &self.0.static_data.cell.borrow().records {
308+
for record in &self.0.shared.cell.borrow().records {
310309
if record.states.contains(swf::ButtonState::HIT_TEST) {
311310
match context
312311
.library
@@ -322,7 +321,7 @@ impl<'gc> TDisplayObject<'gc> for Avm1Button<'gc> {
322321
Err(error) => {
323322
tracing::error!(
324323
"Button ID {}: could not instantiate child ID {}: {}",
325-
self.0.static_data.id,
324+
self.0.shared.id,
326325
record.id,
327326
error
328327
);
@@ -463,8 +462,8 @@ impl<'gc> TInteractiveObject<'gc> for Avm1Button<'gc> {
463462
let is_enabled = self.enabled(context);
464463

465464
// Translate the clip event to a button event, based on how the button state changes.
466-
let static_data = self.0.static_data;
467-
let static_data = static_data.cell.borrow();
465+
let shared = self.0.shared;
466+
let shared = shared.cell.borrow();
468467
let (new_state, condition, sound) = match event {
469468
ClipEvent::DragOut { .. } => (
470469
ButtonState::Over,
@@ -479,27 +478,27 @@ impl<'gc> TInteractiveObject<'gc> for Avm1Button<'gc> {
479478
ClipEvent::Press { .. } => (
480479
ButtonState::Down,
481480
Some(ButtonActionCondition::OVER_UP_TO_OVER_DOWN),
482-
static_data.over_to_down_sound.as_ref(),
481+
shared.over_to_down_sound.as_ref(),
483482
),
484483
ClipEvent::Release { .. } => (
485484
ButtonState::Over,
486485
Some(ButtonActionCondition::OVER_DOWN_TO_OVER_UP),
487-
static_data.down_to_over_sound.as_ref(),
486+
shared.down_to_over_sound.as_ref(),
488487
),
489488
ClipEvent::ReleaseOutside => (
490489
ButtonState::Up,
491490
Some(ButtonActionCondition::OUT_DOWN_TO_IDLE),
492-
static_data.over_to_up_sound.as_ref(),
491+
shared.over_to_up_sound.as_ref(),
493492
),
494493
ClipEvent::RollOut { .. } => (
495494
ButtonState::Up,
496495
Some(ButtonActionCondition::OVER_UP_TO_IDLE),
497-
static_data.over_to_up_sound.as_ref(),
496+
shared.over_to_up_sound.as_ref(),
498497
),
499498
ClipEvent::RollOver { .. } => (
500499
ButtonState::Over,
501500
Some(ButtonActionCondition::IDLE_TO_OVER_UP),
502-
static_data.up_to_over_sound.as_ref(),
501+
shared.up_to_over_sound.as_ref(),
503502
),
504503
ClipEvent::KeyPress { key_code } => {
505504
return self.0.run_actions(
@@ -623,7 +622,7 @@ impl<'gc> Avm1ButtonData<'gc> {
623622
) -> ClipEventResult {
624623
let mut handled = ClipEventResult::NotHandled;
625624
if let Some(parent) = self.cell.borrow().base.base.parent {
626-
for action in &self.static_data.actions {
625+
for action in &self.shared.actions {
627626
if action.conditions.matches(condition) {
628627
// Note that AVM1 buttons run actions relative to their parent, not themselves.
629628
handled = ClipEventResult::Handled;
@@ -641,7 +640,7 @@ impl<'gc> Avm1ButtonData<'gc> {
641640
}
642641

643642
fn movie(&self) -> Arc<SwfMovie> {
644-
self.static_data.swf.clone()
643+
self.shared.swf.clone()
645644
}
646645
}
647646

@@ -676,18 +675,18 @@ pub enum ButtonTracking {
676675
Menu,
677676
}
678677

679-
/// Static data shared between all instances of a button.
678+
/// Data shared between all instances of a button.
680679
#[derive(Collect, Debug)]
681680
#[collect(require_static)]
682-
struct ButtonStatic {
681+
struct ButtonShared {
683682
swf: Arc<SwfMovie>,
684683
id: CharacterId,
685684
actions: Vec<ButtonAction>,
686-
cell: RefCell<ButtonStaticMut>,
685+
cell: RefCell<ButtonSharedMut>,
687686
}
688687

689688
#[derive(Debug)]
690-
struct ButtonStaticMut {
689+
struct ButtonSharedMut {
691690
records: Vec<swf::ButtonRecord>,
692691

693692
/// The sounds to play on state changes for this button.

core/src/display_object/avm2_button.rs

+27-32
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl fmt::Debug for Avm2Button<'_> {
4545
pub struct Avm2ButtonData<'gc> {
4646
base: RefLock<InteractiveObjectBase<'gc>>,
4747

48-
static_data: Gc<'gc, ButtonStatic>,
48+
shared: Gc<'gc, ButtonShared>,
4949

5050
/// The current button state to render.
5151
state: Cell<ButtonState>,
@@ -107,12 +107,12 @@ impl<'gc> Avm2Button<'gc> {
107107
context.gc(),
108108
Avm2ButtonData {
109109
base: Default::default(),
110-
static_data: Gc::new(
110+
shared: Gc::new(
111111
context.gc(),
112-
ButtonStatic {
112+
ButtonShared {
113113
swf: source_movie.movie.clone(),
114114
id: button.id,
115-
cell: RefCell::new(ButtonStaticMut {
115+
cell: RefCell::new(ButtonSharedMut {
116116
records: button.records.clone(),
117117
up_to_over_sound: None,
118118
over_to_down_sound: None,
@@ -155,22 +155,21 @@ impl<'gc> Avm2Button<'gc> {
155155
}
156156

157157
pub fn set_sounds(self, sounds: swf::ButtonSounds) {
158-
let mut static_data = self.0.static_data.cell.borrow_mut();
159-
static_data.up_to_over_sound = sounds.up_to_over_sound;
160-
static_data.over_to_down_sound = sounds.over_to_down_sound;
161-
static_data.down_to_over_sound = sounds.down_to_over_sound;
162-
static_data.over_to_up_sound = sounds.over_to_up_sound;
158+
let mut shared = self.0.shared.cell.borrow_mut();
159+
shared.up_to_over_sound = sounds.up_to_over_sound;
160+
shared.over_to_down_sound = sounds.over_to_down_sound;
161+
shared.down_to_over_sound = sounds.down_to_over_sound;
162+
shared.over_to_up_sound = sounds.over_to_up_sound;
163163
}
164164

165165
/// Handles the ancient DefineButtonCxform SWF tag.
166166
/// Set the color transform for all children of each state.
167167
pub fn set_colors(self, color_transforms: &[swf::ColorTransform]) {
168-
let mut static_data = self.0.static_data.cell.borrow_mut();
168+
let mut shared = self.0.shared.cell.borrow_mut();
169169

170170
// This tag isn't documented well in SWF19. It is only used in very old SWF<=2 content.
171171
// It applies color transforms to every character in a button, in sequence(?).
172-
for (record, color_transform) in static_data.records.iter_mut().zip(color_transforms.iter())
173-
{
172+
for (record, color_transform) in shared.records.iter_mut().zip(color_transforms.iter()) {
174173
record.color_transform = *color_transform;
175174
}
176175
}
@@ -196,9 +195,9 @@ impl<'gc> Avm2Button<'gc> {
196195
let sprite_class = context.avm2.classes().sprite;
197196

198197
let mut children = Vec::new();
199-
let static_data = self.0.static_data;
198+
let shared = self.0.shared;
200199

201-
for record in static_data.cell.borrow().records.iter() {
200+
for record in shared.cell.borrow().records.iter() {
202201
if record.states.contains(swf_state) {
203202
match context
204203
.library
@@ -223,7 +222,7 @@ impl<'gc> Avm2Button<'gc> {
223222
Err(error) => {
224223
tracing::error!(
225224
"Button ID {}: could not instantiate child ID {}: {}",
226-
static_data.id,
225+
shared.id,
227226
record.id,
228227
error
229228
);
@@ -431,11 +430,11 @@ impl<'gc> TDisplayObject<'gc> for Avm2Button<'gc> {
431430
}
432431

433432
fn id(&self) -> CharacterId {
434-
self.0.static_data.id
433+
self.0.shared.id
435434
}
436435

437436
fn movie(&self) -> Arc<SwfMovie> {
438-
self.0.static_data.swf.clone()
437+
self.0.shared.swf.clone()
439438
}
440439

441440
fn post_instantiation(
@@ -747,20 +746,16 @@ impl<'gc> TInteractiveObject<'gc> for Avm2Button<'gc> {
747746
event: ClipEvent<'gc>,
748747
) -> ClipEventResult {
749748
// Translate the clip event to a button event, based on how the button state changes.
750-
let static_data = self.0.static_data.cell.borrow();
749+
let shared = self.0.shared.cell.borrow();
751750
let (new_state, sound) = match event {
752751
ClipEvent::DragOut { .. } => (ButtonState::Over, None),
753752
ClipEvent::DragOver { .. } => (ButtonState::Down, None),
754-
ClipEvent::Press { .. } => (ButtonState::Down, static_data.over_to_down_sound.as_ref()),
755-
ClipEvent::Release { .. } => {
756-
(ButtonState::Over, static_data.down_to_over_sound.as_ref())
757-
}
758-
ClipEvent::ReleaseOutside => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),
759-
ClipEvent::MouseUpInside => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),
760-
ClipEvent::RollOut { .. } => (ButtonState::Up, static_data.over_to_up_sound.as_ref()),
761-
ClipEvent::RollOver { .. } => {
762-
(ButtonState::Over, static_data.up_to_over_sound.as_ref())
763-
}
753+
ClipEvent::Press { .. } => (ButtonState::Down, shared.over_to_down_sound.as_ref()),
754+
ClipEvent::Release { .. } => (ButtonState::Over, shared.down_to_over_sound.as_ref()),
755+
ClipEvent::ReleaseOutside => (ButtonState::Up, shared.over_to_up_sound.as_ref()),
756+
ClipEvent::MouseUpInside => (ButtonState::Up, shared.over_to_up_sound.as_ref()),
757+
ClipEvent::RollOut { .. } => (ButtonState::Up, shared.over_to_up_sound.as_ref()),
758+
ClipEvent::RollOver { .. } => (ButtonState::Over, shared.up_to_over_sound.as_ref()),
764759
_ => return ClipEventResult::NotHandled,
765760
};
766761

@@ -837,17 +832,17 @@ impl<'gc> TInteractiveObject<'gc> for Avm2Button<'gc> {
837832
}
838833
}
839834

840-
/// Static data shared between all instances of a button.
835+
/// Data shared between all instances of a button.
841836
#[derive(Collect, Debug)]
842837
#[collect(require_static)]
843-
struct ButtonStatic {
838+
struct ButtonShared {
844839
swf: Arc<SwfMovie>,
845840
id: CharacterId,
846-
cell: RefCell<ButtonStaticMut>,
841+
cell: RefCell<ButtonSharedMut>,
847842
}
848843

849844
#[derive(Debug)]
850-
struct ButtonStaticMut {
845+
struct ButtonSharedMut {
851846
records: Vec<swf::ButtonRecord>,
852847

853848
/// The sounds to play on state changes for this button.

core/src/display_object/edit_text.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ pub struct EditTextData<'gc> {
8484
/// DisplayObject and InteractiveObject common properties.
8585
base: InteractiveObjectBase<'gc>,
8686

87-
/// Static data shared among all instances of this `EditText`.
88-
static_data: Gc<'gc, EditTextStatic>,
87+
/// Data shared among all instances of this `EditText`.
88+
shared: Gc<'gc, EditTextShared>,
8989

9090
/// The underlying text format spans of the `EditText`.
9191
///
@@ -234,7 +234,7 @@ impl EditTextData<'_> {
234234
self.style_sheet.style_sheet(),
235235
self.flags.contains(EditTextFlag::MULTILINE),
236236
self.flags.contains(EditTextFlag::CONDENSE_WHITE),
237-
self.static_data.swf.version(),
237+
self.shared.swf.version(),
238238
);
239239
self.original_html_text = if self.style_sheet.is_some() {
240240
Some(text.to_owned())
@@ -338,9 +338,9 @@ impl<'gc> EditText<'gc> {
338338
EditTextData {
339339
base: InteractiveObjectBase::default(),
340340
text_spans,
341-
static_data: Gc::new(
341+
shared: Gc::new(
342342
context.gc(),
343-
EditTextStatic {
343+
EditTextShared {
344344
swf: swf_movie,
345345
id: swf_tag.id(),
346346
initial_text: swf_tag
@@ -878,7 +878,7 @@ impl<'gc> EditText<'gc> {
878878
let text = self
879879
.0
880880
.read()
881-
.static_data
881+
.shared
882882
.initial_text
883883
.clone()
884884
.unwrap_or_default();
@@ -898,7 +898,7 @@ impl<'gc> EditText<'gc> {
898898
let mut edit_text = self.0.write(context.gc());
899899
let autosize = edit_text.autosize;
900900
let is_word_wrap = edit_text.flags.contains(EditTextFlag::WORD_WRAP);
901-
let movie = edit_text.static_data.swf.clone();
901+
let movie = edit_text.shared.swf.clone();
902902
let padding = Self::GUTTER * 2;
903903

904904
if edit_text.flags.contains(EditTextFlag::PASSWORD) {
@@ -2481,11 +2481,11 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
24812481
}
24822482

24832483
fn id(&self) -> CharacterId {
2484-
self.0.read().static_data.id
2484+
self.0.read().shared.id
24852485
}
24862486

24872487
fn movie(&self) -> Arc<SwfMovie> {
2488-
self.0.read().static_data.swf.clone()
2488+
self.0.read().shared.swf.clone()
24892489
}
24902490

24912491
/// Construct objects placed on this frame.
@@ -3117,10 +3117,10 @@ bitflags::bitflags! {
31173117
}
31183118
}
31193119

3120-
/// Static data shared between all instances of a text object.
3120+
/// Data shared between all instances of a text object.
31213121
#[derive(Debug, Clone, Collect)]
31223122
#[collect(require_static)]
3123-
struct EditTextStatic {
3123+
struct EditTextShared {
31243124
swf: Arc<SwfMovie>,
31253125
id: CharacterId,
31263126
initial_text: Option<WString>,

0 commit comments

Comments
 (0)