Skip to content

Commit 67b689e

Browse files
committed
core: make Character: Copy
This allows returning them without having to keep a `&MovieLibrary` reference alive.
1 parent cddf354 commit 67b689e

File tree

11 files changed

+16
-21
lines changed

11 files changed

+16
-21
lines changed

core/src/avm1/globals/sound.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ fn attach_sound<'gc>(
197197
.library_for_movie_mut(movie)
198198
.character_by_export_name(name)
199199
{
200-
sound.set_sound(Some(*sound_handle));
200+
sound.set_sound(Some(sound_handle));
201201
sound.set_is_streaming(false);
202202
sound.set_duration(
203203
activation
204204
.context
205205
.audio
206-
.get_sound_duration(*sound_handle)
206+
.get_sound_duration(sound_handle)
207207
.map(|d| d.round() as u32),
208208
);
209209
sound.set_position(0);
@@ -554,7 +554,6 @@ fn stop<'gc>(
554554
.character_by_export_name(name)
555555
{
556556
// Stop all sounds with the given name.
557-
let sound = *sound;
558557
activation.context.stop_sounds_with_handle(sound);
559558
} else {
560559
avm_warn!(activation, "Sound.stop: Sound '{}' not found", name);

core/src/avm2/globals/flash/display/bitmap.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub fn bitmap_allocator<'gc>(
4949
.library
5050
.library_for_movie_mut(movie)
5151
.character_by_id(symbol)
52-
.cloned()
5352
{
5453
let new_bitmap_data = fill_bitmap_data_from_symbol(activation, bitmap.compressed());
5554
let bitmap_data_obj = BitmapDataObject::from_bitmap_data_internal(

core/src/avm2/globals/flash/display/bitmap_data.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ pub fn init<'gc>(
111111
.library
112112
.library_for_movie_mut(movie)
113113
.character_by_id(chara_id)
114-
.cloned()
115114
});
116115

117116
let new_bitmap_data = if let Some(Character::Bitmap(bitmap)) = character {

core/src/avm2/globals/flash/media/sound.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub fn init<'gc>(
4040
.library_for_movie_mut(movie)
4141
.character_by_id(symbol)
4242
{
43-
let sound = *sound;
4443
sound_object.set_sound(activation.context, sound)?;
4544
} else {
4645
tracing::warn!("Attempted to construct subclass of Sound, {}, which is associated with non-Sound character {}", class_def.name().local_name(), symbol);

core/src/avm2/globals/flash/text/font.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn register_font<'gc>(
157157
{
158158
if let Some(lib) = activation.context.library.library_for_movie(movie) {
159159
if let Some(Character::Font(font)) = lib.character_by_id(id) {
160-
activation.context.library.register_global_font(*font);
160+
activation.context.library.register_global_font(font);
161161
return Ok(Value::Undefined);
162162
}
163163
}

core/src/avm2/object/bytearray_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn byte_array_allocator<'gc>(
2626
if let Some(lib) = activation.context.library.library_for_movie(movie) {
2727
if let Some(Character::BinaryData(binary_data)) = lib.character_by_id(id) {
2828
Some(ByteArrayStorage::from_vec(
29-
SwfSlice::as_ref(binary_data).to_vec(),
29+
SwfSlice::as_ref(&binary_data).to_vec(),
3030
))
3131
} else {
3232
None

core/src/avm2/object/font_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn font_allocator<'gc>(
2222
{
2323
if let Some(lib) = activation.context.library.library_for_movie(movie) {
2424
if let Some(Character::Font(font)) = lib.character_by_id(id) {
25-
Some(*font)
25+
Some(font)
2626
} else {
2727
None
2828
}

core/src/character.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ruffle_render::bitmap::{Bitmap as RenderBitmap, BitmapHandle, BitmapSize};
1414
use ruffle_render::error::Error as RenderError;
1515
use swf::DefineBitsLossless;
1616

17-
#[derive(Clone, Collect, Debug)]
17+
#[derive(Copy, Clone, Collect, Debug)]
1818
#[collect(no_drop)]
1919
pub enum Character<'gc> {
2020
EditText(EditText<'gc>),

core/src/debug_ui/movie.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl MovieWindow {
125125
sorted_keys.sort();
126126

127127
for id in sorted_keys {
128-
let character = characters
128+
let character = *characters
129129
.get(&id)
130130
.expect("Value must exist as we're iterating known keys");
131131

@@ -256,7 +256,7 @@ pub fn open_movie_button(ui: &mut Ui, movie: &Arc<SwfMovie>, messages: &mut Vec<
256256
}
257257
}
258258

259-
pub fn open_character_button(ui: &mut Ui, character: &Character) {
259+
pub fn open_character_button(ui: &mut Ui, character: Character) {
260260
let name = match character {
261261
Character::EditText(_) => "EditText",
262262
Character::Graphic(_) => "Graphic",

core/src/display_object/movie_clip.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,7 +3687,7 @@ impl<'gc, 'a> MovieClipShared<'gc> {
36873687
.iter()
36883688
.map(|(name, id)| {
36893689
let character = importer_library.character_by_id(*id).unwrap();
3690-
(name, (*id, character.clone()))
3690+
(name, (*id, character))
36913691
})
36923692
.collect::<HashMap<AvmString<'gc>, (CharacterId, Character<'gc>)>>();
36933693

@@ -3819,7 +3819,6 @@ impl<'gc, 'a> MovieClipShared<'gc> {
38193819
if let Some(character) = self
38203820
.library(context)
38213821
.and_then(|l| l.character_by_id(export.id))
3822-
.cloned()
38233822
{
38243823
Self::register_export(context, export.id, &name, self.movie());
38253824
tracing::debug!("register_export asset: {} (ID: {})", name, export.id);
@@ -4131,7 +4130,7 @@ impl<'gc, 'a> MovieClip<'gc> {
41314130
.library
41324131
.library_for_movie_mut(movie.clone());
41334132

4134-
let Some(&Character::Bitmap(bitmap)) =
4133+
let Some(Character::Bitmap(bitmap)) =
41354134
library.character_by_id(id)
41364135
else {
41374136
unreachable!();

0 commit comments

Comments
 (0)