From 9a117c080b8a18dc1c9f1291542d2cbd4c70d64f Mon Sep 17 00:00:00 2001 From: Ryan Butler Date: Sun, 31 Mar 2024 16:11:22 -0400 Subject: [PATCH] Removed old/outdated ChannelManager code. Not sure its still relevant. --- crates/replicate/server/src/instance/mod.rs | 65 +-------------------- 1 file changed, 1 insertion(+), 64 deletions(-) diff --git a/crates/replicate/server/src/instance/mod.rs b/crates/replicate/server/src/instance/mod.rs index 13f03b7..2a7a302 100644 --- a/crates/replicate/server/src/instance/mod.rs +++ b/crates/replicate/server/src/instance/mod.rs @@ -3,73 +3,10 @@ //! [article][gaffer_vr] on networked physics in VR by GafferOnGames. //! //! [gaffer_vr]: https://gafferongames.com/post/networked_physics_in_virtual_reality -// TODO: Remove this -#![allow(unused)] mod manager; pub use self::manager::InstanceManager; -use replicate_common::{ChannelFormat, ChannelId, ClientId}; -use std::collections::{BTreeSet, HashMap}; - -#[derive(Debug, Default)] -pub struct Instance { - channels: ChannelManager, - sessions: HashMap, -} - -/// State associated with a client session. -#[derive(Debug)] -struct SessionState { - /// All channels that this client has registered themselves on during this - /// session. - channels: HashMap, - /// The client associated with this session. - client: ClientId, -} - -/// Manages allocation and indices of channels. #[derive(Debug, Default)] -struct ChannelManager { - formats: HashMap, - /// Channels which have been deleted. - holes: BTreeSet, - /// Indexed by `ChannelId`. Deleted channels will be noted in `holes` - /// and must be re-initialized before use. They are not dropped when - /// deleted to avoid memory allocator pressure. - channels: Vec, -} - -impl ChannelManager { - /// Registers a [`ChannelFormat`] and returns the [`ChannelId`] that references it. - /// - /// If the channel already is registered, returns Err(ChannelId). - fn register_channel( - &mut self, - format: ChannelFormat, - ) -> Result { - if let Some(&id) = self.formats.get(&format) { - return Err(id); - } - // We use the first hole to prioiritize filling the values closer to the - // start of the vec. This will help reduce fragmentation in `self.channels`. - if let Some(hole) = self.holes.pop_first() { - self.channels[usize::try_from(hole.0).expect("cast err")].reinitialize(); - Ok(hole) - } else { - self.channels.push(Channel::default()); - Ok(ChannelId( - (self.channels.len() - 1).try_into().expect("cast err"), - )) - } - } -} - -#[derive(Debug, Default)] -struct Channel {} - -impl Channel { - /// resets channel to default state, while reusing underlying memory buffers. - fn reinitialize(&mut self) {} -} +pub struct Instance {}