From b275dc9a98a90da1ed8beecf8173c08ece1a6a3d Mon Sep 17 00:00:00 2001 From: yukirij Date: Mon, 11 Nov 2024 01:07:36 -0800 Subject: [PATCH] Modify organization of subsystems. --- src/config/mod.rs | 8 ++- src/system/api/mod.rs | 6 +-- src/system/audio/mod.rs | 6 +-- src/system/control/mod.rs | 6 +-- src/system/input/mod.rs | 6 +-- src/system/mod.rs | 2 +- src/system/network/mod.rs | 6 +-- src/system/query.rs | 8 +++ src/system/render/mod.rs | 13 ----- src/system/scene/mod.rs | 6 +-- src/system/storage/mod.rs | 6 +-- src/system/supervisor/internal.rs | 5 +- src/system/video/mod.rs | 13 +++++ src/system/{render => video}/vulkan/mod.rs | 0 src/system/window/config.rs | 3 ++ src/system/window/internal.rs | 31 ----------- src/system/window/internal/handler.rs | 35 +++++++++++++ src/system/window/internal/mod.rs | 61 ++++++++++++++++++++++ src/system/window/mod.rs | 30 +++++++++-- src/system/window/query.rs | 4 ++ 20 files changed, 181 insertions(+), 74 deletions(-) delete mode 100644 src/system/render/mod.rs create mode 100644 src/system/video/mod.rs rename src/system/{render => video}/vulkan/mod.rs (100%) create mode 100644 src/system/window/config.rs delete mode 100644 src/system/window/internal.rs create mode 100644 src/system/window/internal/handler.rs create mode 100644 src/system/window/internal/mod.rs diff --git a/src/config/mod.rs b/src/config/mod.rs index 1d42736..3ac0e7f 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,10 +1,14 @@ +use crate::system::*; + pub struct Config { - + window:Option, } impl Config { pub fn new() -> Self { - Self { } + Self { + window:None, + } } } diff --git a/src/system/api/mod.rs b/src/system/api/mod.rs index 97a8680..d047b48 100644 --- a/src/system/api/mod.rs +++ b/src/system/api/mod.rs @@ -1,13 +1,13 @@ use super::*; -pub struct APISystem { +pub struct APIManager { channel:Sender, } -impl APISystem { +impl APIManager { } -impl Subsystem for APISystem { +impl Subsystem for APIManager { } diff --git a/src/system/audio/mod.rs b/src/system/audio/mod.rs index 221dae1..9d5ec83 100644 --- a/src/system/audio/mod.rs +++ b/src/system/audio/mod.rs @@ -1,13 +1,13 @@ use super::*; -pub struct AudioSystem { +pub struct AudioManager { channel:Sender, } -impl AudioSystem { +impl AudioManager { } -impl Subsystem for AudioSystem { +impl Subsystem for AudioManager { } diff --git a/src/system/control/mod.rs b/src/system/control/mod.rs index 059850d..f2e004d 100644 --- a/src/system/control/mod.rs +++ b/src/system/control/mod.rs @@ -1,13 +1,13 @@ use super::*; -pub struct ControlSystem { +pub struct ControlManager { channel:Sender, } -impl ControlSystem { +impl ControlManager { } -impl Subsystem for ControlSystem { +impl Subsystem for ControlManager { } diff --git a/src/system/input/mod.rs b/src/system/input/mod.rs index 08cb7cf..147ff83 100644 --- a/src/system/input/mod.rs +++ b/src/system/input/mod.rs @@ -3,14 +3,14 @@ use super::*; mod usage; use usage::Usage; mod device; use device::Device; -pub struct InputSystem { +pub struct InputManager { channel:Sender, } -impl InputSystem { +impl InputManager { } -impl Subsystem for InputSystem { +impl Subsystem for InputManager { } diff --git a/src/system/mod.rs b/src/system/mod.rs index 179867b..83e48cb 100644 --- a/src/system/mod.rs +++ b/src/system/mod.rs @@ -5,7 +5,7 @@ pub(crate) mod query; pub(crate) use query::{Query, QueryData}; pub(crate) mod supervisor; pub(crate) use supervisor::*; pub(crate) mod window; pub(crate) use window::*; -pub(crate) mod render; pub(crate) use render::*; +pub(crate) mod video; pub(crate) use video::*; pub(crate) mod audio; pub(crate) use audio::*; pub(crate) mod input; pub(crate) use input::*; pub(crate) mod control; pub(crate) use control::*; diff --git a/src/system/network/mod.rs b/src/system/network/mod.rs index 5d6fb1c..a2c1a55 100644 --- a/src/system/network/mod.rs +++ b/src/system/network/mod.rs @@ -1,13 +1,13 @@ use super::*; -pub struct NetworkSystem { +pub struct NetworkManager { channel:Sender, } -impl NetworkSystem { +impl NetworkManager { } -impl Subsystem for NetworkSystem { +impl Subsystem for NetworkManager { } diff --git a/src/system/query.rs b/src/system/query.rs index 88e4ae7..23db4d5 100644 --- a/src/system/query.rs +++ b/src/system/query.rs @@ -16,5 +16,13 @@ impl Query { pub enum QueryData { Supervisor(SupervisorQuery), + API, + Audio, + Control, + Input, + Network, + Scene, + Storage, + Video, Window(WindowQuery), } diff --git a/src/system/render/mod.rs b/src/system/render/mod.rs deleted file mode 100644 index afeadc2..0000000 --- a/src/system/render/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -use super::*; - -pub struct RenderSystem { - channel:Sender, -} - -impl RenderSystem { - -} - -impl Subsystem for RenderSystem { - -} diff --git a/src/system/scene/mod.rs b/src/system/scene/mod.rs index a3745dd..9d3ea3b 100644 --- a/src/system/scene/mod.rs +++ b/src/system/scene/mod.rs @@ -1,13 +1,13 @@ use super::*; -pub struct SceneSystem { +pub struct SceneManager { channel:Sender, } -impl SceneSystem { +impl SceneManager { } -impl Subsystem for SceneSystem { +impl Subsystem for SceneManager { } diff --git a/src/system/storage/mod.rs b/src/system/storage/mod.rs index f20365c..53b5661 100644 --- a/src/system/storage/mod.rs +++ b/src/system/storage/mod.rs @@ -1,13 +1,13 @@ use super::*; -pub struct StorageSystem { +pub struct StorageManager { channel:Sender, } -impl StorageSystem { +impl StorageManager { } -impl Subsystem for StorageSystem { +impl Subsystem for StorageManager { } diff --git a/src/system/supervisor/internal.rs b/src/system/supervisor/internal.rs index 422aa9e..2e51fbc 100644 --- a/src/system/supervisor/internal.rs +++ b/src/system/supervisor/internal.rs @@ -20,7 +20,7 @@ impl Internal { } => if sv.subsystems[system as usize].is_none() { if let Ok(channel) = match system { - System::Window => WindowSystem::start(), + System::Window => WindowManager::start(), _ => { Err(Error::new()) } } { @@ -49,6 +49,9 @@ impl Internal { system, } ))).ok(); + + // Drop channel. + sv.subsystems[system as usize] = None; } SupervisorQuery::Status { diff --git a/src/system/video/mod.rs b/src/system/video/mod.rs new file mode 100644 index 0000000..cbf14a7 --- /dev/null +++ b/src/system/video/mod.rs @@ -0,0 +1,13 @@ +use super::*; + +pub struct VideoManager { + channel:Sender, +} + +impl VideoManager { + +} + +impl Subsystem for VideoManager { + +} diff --git a/src/system/render/vulkan/mod.rs b/src/system/video/vulkan/mod.rs similarity index 100% rename from src/system/render/vulkan/mod.rs rename to src/system/video/vulkan/mod.rs diff --git a/src/system/window/config.rs b/src/system/window/config.rs new file mode 100644 index 0000000..7fd1fc8 --- /dev/null +++ b/src/system/window/config.rs @@ -0,0 +1,3 @@ +pub struct WindowConfig { + +} diff --git a/src/system/window/internal.rs b/src/system/window/internal.rs deleted file mode 100644 index 98c5e7a..0000000 --- a/src/system/window/internal.rs +++ /dev/null @@ -1,31 +0,0 @@ -use crate::system::*; - -pub struct Internal { - -} -impl Internal { - pub fn thread(rx:Receiver) - { - let _sv = Internal { - - }; - - while let Ok(msg) = rx.recv() { - match msg.data { - QueryData::Supervisor(request) => match request { - SupervisorQuery::Stop { - system: _, - } => { - - // Perform shutdown operations and terminate thread. - return; - } - - _ => { } - } - - _ => { } - } - } - } -} diff --git a/src/system/window/internal/handler.rs b/src/system/window/internal/handler.rs new file mode 100644 index 0000000..57ce54c --- /dev/null +++ b/src/system/window/internal/handler.rs @@ -0,0 +1,35 @@ +use crossbeam::channel::Sender; +use winit::{ + event::{Event, WindowEvent}, + event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, + window::{Window, WindowId}, + application::ApplicationHandler, +}; +use crate::system::Query; + +pub struct Handler { + pub channel:Sender, +} + +impl Handler { + pub fn new(channel:Sender) -> Self + { + Self { channel } + } +} + +impl ApplicationHandler for Handler { + fn resumed(&mut self, _event_loop: &winit::event_loop::ActiveEventLoop) + { + + } + + fn window_event( + &mut self, + _event_loop:&ActiveEventLoop, + _window_id:WindowId, + _event: WindowEvent, + ) { + + } +} diff --git a/src/system/window/internal/mod.rs b/src/system/window/internal/mod.rs new file mode 100644 index 0000000..fd9a90d --- /dev/null +++ b/src/system/window/internal/mod.rs @@ -0,0 +1,61 @@ +use crate::system::*; + +use winit::{ + event::{Event, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + window::Window, + application::ApplicationHandler, +}; + +mod handler; use handler::Handler; + +pub struct Internal { + +} +impl Internal { + pub fn thread(tx:Sender, rx:Receiver) + { + let _sv = Internal { + + }; + + // Initialize event loop. + let channel = tx.clone(); + std::thread::spawn(move || { + if let Ok(event_loop) = EventLoop::new() { + let mut handler = Handler::new(channel); + event_loop.set_control_flow(ControlFlow::Wait); + event_loop.run_app(&mut handler).ok(); + } + }); + + // Handle messages. + while let Ok(msg) = rx.recv() { + match msg.data { + QueryData::Supervisor(request) => match request { + SupervisorQuery::Stop { + system: _, + } => { + + // Perform shutdown operations and terminate thread. + return; + } + + _ => { } + } + + QueryData::Window(request) => match request { + WindowQuery::Create { + + } => { + + } + + _ => { } + } + + _ => { } + } + } + } +} diff --git a/src/system/window/mod.rs b/src/system/window/mod.rs index 3ffc182..712894a 100644 --- a/src/system/window/mod.rs +++ b/src/system/window/mod.rs @@ -1,27 +1,47 @@ use super::*; mod query; pub use query::WindowQuery; +mod config; pub use config::WindowConfig; mod internal; use internal::Internal; -pub struct WindowSystem { +pub struct WindowManager { channel:Sender, } -impl WindowSystem { - +impl WindowManager { + pub fn create(&mut self) -> Result<(),()> + { + self.channel.send(Query::new( + Some(self.channel.clone()), + QueryData::Window(WindowQuery::Create { + + } + ))).ok(); + + Err(()) + } } -impl Subsystem for WindowSystem { +impl Subsystem for WindowManager { fn start() -> Result, crate::Error> { let (tx, rx) = channel::bounded::(24); + let sys_tx = tx.clone(); std::thread::spawn(move || { - Internal::thread(rx); + Internal::thread(sys_tx, rx); }); Ok(tx) } } + +impl From> for WindowManager { + fn from(channel :Sender) -> Self { + Self { + channel + } + } +} diff --git a/src/system/window/query.rs b/src/system/window/query.rs index d1b89d9..25da49a 100644 --- a/src/system/window/query.rs +++ b/src/system/window/query.rs @@ -1,3 +1,7 @@ pub enum WindowQuery { None, + + Create { + + }, }