cleanup: Define distinct key types for different kinds of slotmaps

This commit is contained in:
TÖRÖK Attila 2024-03-03 00:56:05 +01:00 committed by Adrian Wielgosik
parent 5bfd8af257
commit 8764c08b01
10 changed files with 36 additions and 23 deletions

View File

@ -7,7 +7,7 @@ use crate::{
};
use downcast_rs::Downcast;
use gc_arena::Collect;
use slotmap::{DefaultKey, Key, SlotMap};
use slotmap::{new_key_type, Key, SlotMap};
#[cfg(feature = "audio")]
pub mod decoders;
@ -35,8 +35,11 @@ mod decoders {
use thiserror::Error;
use web_time::Duration;
pub type SoundHandle = DefaultKey;
pub type SoundInstanceHandle = DefaultKey;
new_key_type! {
pub struct SoundHandle;
pub struct SoundInstanceHandle;
}
pub type DecodeError = decoders::Error;
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
@ -212,7 +215,7 @@ pub struct NullAudioBackend {
impl NullAudioBackend {
pub fn new() -> NullAudioBackend {
NullAudioBackend {
sounds: SlotMap::new(),
sounds: SlotMap::with_key(),
volume: 1.0,
}
}

View File

@ -239,8 +239,8 @@ impl AudioMixer {
/// Creates a new `AudioMixer` with the given number of channels and sample rate.
pub fn new(num_output_channels: u8, output_sample_rate: u32) -> Self {
Self {
sounds: SlotMap::new(),
sound_instances: Arc::new(Mutex::new(SlotMap::new())),
sounds: SlotMap::with_key(),
sound_instances: Arc::new(Mutex::new(SlotMap::with_key())),
volume: Arc::new(RwLock::new(1.0)),
num_output_channels,
output_sample_rate,

View File

@ -33,7 +33,7 @@ use crate::{avm2_stub_method, avm2_stub_method_context};
use encoding_rs::UTF_8;
use gc_arena::{Collect, GcCell};
use ruffle_render::utils::{determine_jpeg_tag_format, JpegTagFormat};
use slotmap::{DefaultKey, SlotMap};
use slotmap::{new_key_type, SlotMap};
use std::borrow::Borrow;
use std::fmt;
use std::sync::{Arc, Mutex, Weak};
@ -42,7 +42,9 @@ use swf::read::{extract_swz, read_compression_type};
use thiserror::Error;
use url::{form_urlencoded, ParseError, Url};
pub type LoaderHandle = DefaultKey;
new_key_type! {
pub struct LoaderHandle;
}
/// The depth of AVM1 movies that AVM2 loads.
const LOADER_INSERTED_AVM1_DEPTH: i32 = -0xF000;
@ -237,7 +239,7 @@ unsafe impl<'gc> Collect for LoadManager<'gc> {
impl<'gc> LoadManager<'gc> {
/// Construct a new `LoadManager`.
pub fn new() -> Self {
Self(SlotMap::new())
Self(SlotMap::with_key())
}
/// Add a new loader to the `LoadManager`.

View File

@ -2,9 +2,11 @@ use crate::avm1::Object as Avm1Object;
use crate::avm2::object::LocalConnectionObject;
use crate::string::AvmString;
use gc_arena::Collect;
use slotmap::{DefaultKey, SlotMap};
use slotmap::{new_key_type, SlotMap};
pub type LocalConnectionHandle = DefaultKey;
new_key_type! {
pub struct LocalConnectionHandle;
}
#[derive(Collect)]
#[collect(no_drop)]
@ -55,7 +57,7 @@ unsafe impl<'gc> Collect for LocalConnections<'gc> {
impl<'gc> LocalConnections<'gc> {
pub fn empty() -> Self {
Self {
connections: SlotMap::new(),
connections: SlotMap::with_key(),
}
}

View File

@ -10,12 +10,14 @@ use crate::Player;
use flash_lso::packet::{Header, Message, Packet};
use flash_lso::types::{AMFVersion, Value as AmfValue};
use gc_arena::{Collect, DynamicRoot, Rootable};
use slotmap::{DefaultKey, SlotMap};
use slotmap::{new_key_type, SlotMap};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use std::sync::{Mutex, Weak};
pub type NetConnectionHandle = DefaultKey;
new_key_type! {
pub struct NetConnectionHandle;
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum ResponderCallback {
@ -90,7 +92,7 @@ unsafe impl<'gc> Collect for NetConnections<'gc> {
impl<'gc> Default for NetConnections<'gc> {
fn default() -> Self {
Self {
connections: SlotMap::new(),
connections: SlotMap::with_key(),
}
}
}

View File

@ -13,13 +13,15 @@ use crate::{
};
use async_channel::{unbounded, Receiver, Sender as AsyncSender, Sender};
use gc_arena::Collect;
use slotmap::{DefaultKey, SlotMap};
use slotmap::{new_key_type, SlotMap};
use std::{
cell::{Cell, RefCell},
time::Duration,
};
pub type SocketHandle = DefaultKey;
new_key_type! {
pub struct SocketHandle;
}
#[derive(Copy, Clone, Collect)]
#[collect(no_drop)]
@ -81,7 +83,7 @@ impl<'gc> Sockets<'gc> {
let (sender, receiver) = unbounded();
Self {
sockets: SlotMap::new(),
sockets: SlotMap::with_key(),
receiver,
sender,
}

View File

@ -434,7 +434,7 @@ impl<'gc> NetStream<'gc> {
}
if let Some(sound) = write.sound_instance {
context.stop_sounds_with_handle(sound);
context.stop_sound(sound);
context.audio.stop_sound(sound);
write.sound_instance = None;

View File

@ -23,7 +23,7 @@ impl Default for SoftwareVideoBackend {
impl SoftwareVideoBackend {
pub fn new() -> Self {
Self {
streams: SlotMap::new(),
streams: SlotMap::with_key(),
}
}
}

View File

@ -1,10 +1,12 @@
#![deny(clippy::unwrap_used)]
use slotmap::DefaultKey;
use slotmap::new_key_type;
pub mod backend;
pub mod error;
pub mod frame;
pub mod null;
pub type VideoStreamHandle = DefaultKey;
new_key_type! {
pub struct VideoStreamHandle;
}

View File

@ -22,7 +22,7 @@ pub struct NullVideoBackend {
impl NullVideoBackend {
pub fn new() -> Self {
Self {
streams: SlotMap::new(),
streams: SlotMap::with_key(),
}
}
}