From cc2eb4ef053da7a53663bdecac912a1c49490301 Mon Sep 17 00:00:00 2001 From: stale Date: Fri, 1 Jul 2022 22:14:52 -0300 Subject: fix the mess i made of type aliases --- src/types.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/types.rs') diff --git a/src/types.rs b/src/types.rs index 7cdd44c..0bd7881 100644 --- a/src/types.rs +++ b/src/types.rs @@ -24,7 +24,7 @@ pub struct RoomConf { pub struct Room { pub conf: RoomConf, - pub players: PlayerMap, + pub players: Arc>, pub game_driver: tokio::task::JoinHandle<()>, pub cmd_stream: CmdTx, pub livepos_driver: tokio::task::JoinHandle<()>, @@ -90,8 +90,8 @@ impl RoomId { } pub type CmdTx = tokio::sync::mpsc::UnboundedSender; -pub type RoomMap = Arc>>>>; -pub type PlayerMapData = Arc>>; +pub type RoomMap = HashMap>>; +pub type PlayerMapData = HashMap; #[derive(Debug)] pub struct PlayerMap { inner: PlayerMapData, @@ -99,7 +99,7 @@ pub struct PlayerMap { } impl Deref for PlayerMap { - type Target = Arc>>; + type Target = PlayerMapData; fn deref(&self) -> &Self::Target { &self.inner } @@ -111,15 +111,14 @@ impl DerefMut for PlayerMap { } impl Default for PlayerMap { fn default() -> Self { - Self { inner: Arc::new(RwLock::new(HashMap::new())), uid_counter: 0.into() } + Self { inner: HashMap::new(), uid_counter: 0.into() } } } impl PlayerMap { - pub async fn insert_conn(&mut self, conn: Conn, name: String, clr: String) -> usize { - let mut map = self.write().await; + pub fn insert_conn(&mut self, conn: Conn, name: String, clr: String) -> usize { let uid = self.uid_counter.fetch_add(1, Ordering::Relaxed); - map.insert( + self.insert( conn.addr, Player { conn, uid, name, clr }, ); -- cgit v1.2.3