Modify organization of subsystems.

This commit is contained in:
yukirij 2024-11-11 01:07:36 -08:00
parent 7785d22ef0
commit b275dc9a98
20 changed files with 181 additions and 74 deletions

View File

@ -1,10 +1,14 @@
pub struct Config {
use crate::system::*;
pub struct Config {
window:Option<WindowConfig>,
}
impl Config {
pub fn new() -> Self
{
Self { }
Self {
window:None,
}
}
}

View File

@ -1,13 +1,13 @@
use super::*;
pub struct APISystem {
pub struct APIManager {
channel:Sender<Query>,
}
impl APISystem {
impl APIManager {
}
impl Subsystem for APISystem {
impl Subsystem for APIManager {
}

View File

@ -1,13 +1,13 @@
use super::*;
pub struct AudioSystem {
pub struct AudioManager {
channel:Sender<Query>,
}
impl AudioSystem {
impl AudioManager {
}
impl Subsystem for AudioSystem {
impl Subsystem for AudioManager {
}

View File

@ -1,13 +1,13 @@
use super::*;
pub struct ControlSystem {
pub struct ControlManager {
channel:Sender<Query>,
}
impl ControlSystem {
impl ControlManager {
}
impl Subsystem for ControlSystem {
impl Subsystem for ControlManager {
}

View File

@ -3,14 +3,14 @@ use super::*;
mod usage; use usage::Usage;
mod device; use device::Device;
pub struct InputSystem {
pub struct InputManager {
channel:Sender<Query>,
}
impl InputSystem {
impl InputManager {
}
impl Subsystem for InputSystem {
impl Subsystem for InputManager {
}

View File

@ -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::*;

View File

@ -1,13 +1,13 @@
use super::*;
pub struct NetworkSystem {
pub struct NetworkManager {
channel:Sender<Query>,
}
impl NetworkSystem {
impl NetworkManager {
}
impl Subsystem for NetworkSystem {
impl Subsystem for NetworkManager {
}

View File

@ -16,5 +16,13 @@ impl Query {
pub enum QueryData {
Supervisor(SupervisorQuery),
API,
Audio,
Control,
Input,
Network,
Scene,
Storage,
Video,
Window(WindowQuery),
}

View File

@ -1,13 +0,0 @@
use super::*;
pub struct RenderSystem {
channel:Sender<Query>,
}
impl RenderSystem {
}
impl Subsystem for RenderSystem {
}

View File

@ -1,13 +1,13 @@
use super::*;
pub struct SceneSystem {
pub struct SceneManager {
channel:Sender<Query>,
}
impl SceneSystem {
impl SceneManager {
}
impl Subsystem for SceneSystem {
impl Subsystem for SceneManager {
}

View File

@ -1,13 +1,13 @@
use super::*;
pub struct StorageSystem {
pub struct StorageManager {
channel:Sender<Query>,
}
impl StorageSystem {
impl StorageManager {
}
impl Subsystem for StorageSystem {
impl Subsystem for StorageManager {
}

View File

@ -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 {

13
src/system/video/mod.rs Normal file
View File

@ -0,0 +1,13 @@
use super::*;
pub struct VideoManager {
channel:Sender<Query>,
}
impl VideoManager {
}
impl Subsystem for VideoManager {
}

View File

@ -0,0 +1,3 @@
pub struct WindowConfig {
}

View File

@ -1,31 +0,0 @@
use crate::system::*;
pub struct Internal {
}
impl Internal {
pub fn thread(rx:Receiver<Query>)
{
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;
}
_ => { }
}
_ => { }
}
}
}
}

View File

@ -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<Query>,
}
impl Handler {
pub fn new(channel:Sender<Query>) -> 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,
) {
}
}

View File

@ -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<Query>, rx:Receiver<Query>)
{
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 {
} => {
}
_ => { }
}
_ => { }
}
}
}
}

View File

@ -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<Query>,
}
impl WindowSystem {
impl WindowManager {
pub fn create(&mut self) -> Result<(),()>
{
self.channel.send(Query::new(
Some(self.channel.clone()),
QueryData::Window(WindowQuery::Create {
}
))).ok();
impl Subsystem for WindowSystem {
Err(())
}
}
impl Subsystem for WindowManager {
fn start() -> Result<Sender<Query>, crate::Error>
{
let (tx, rx) = channel::bounded::<Query>(24);
let sys_tx = tx.clone();
std::thread::spawn(move || {
Internal::thread(rx);
Internal::thread(sys_tx, rx);
});
Ok(tx)
}
}
impl From<Sender<Query>> for WindowManager {
fn from(channel :Sender<Query>) -> Self {
Self {
channel
}
}
}

View File

@ -1,3 +1,7 @@
pub enum WindowQuery {
None,
Create {
},
}