Modify organization of subsystems.
This commit is contained in:
parent
7785d22ef0
commit
b275dc9a98
@ -1,10 +1,14 @@
|
|||||||
pub struct Config {
|
use crate::system::*;
|
||||||
|
|
||||||
|
pub struct Config {
|
||||||
|
window:Option<WindowConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn new() -> Self
|
pub fn new() -> Self
|
||||||
{
|
{
|
||||||
Self { }
|
Self {
|
||||||
|
window:None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub struct APISystem {
|
pub struct APIManager {
|
||||||
channel:Sender<Query>,
|
channel:Sender<Query>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl APISystem {
|
impl APIManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subsystem for APISystem {
|
impl Subsystem for APIManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub struct AudioSystem {
|
pub struct AudioManager {
|
||||||
channel:Sender<Query>,
|
channel:Sender<Query>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioSystem {
|
impl AudioManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subsystem for AudioSystem {
|
impl Subsystem for AudioManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub struct ControlSystem {
|
pub struct ControlManager {
|
||||||
channel:Sender<Query>,
|
channel:Sender<Query>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ControlSystem {
|
impl ControlManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subsystem for ControlSystem {
|
impl Subsystem for ControlManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,14 @@ use super::*;
|
|||||||
mod usage; use usage::Usage;
|
mod usage; use usage::Usage;
|
||||||
mod device; use device::Device;
|
mod device; use device::Device;
|
||||||
|
|
||||||
pub struct InputSystem {
|
pub struct InputManager {
|
||||||
channel:Sender<Query>,
|
channel:Sender<Query>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputSystem {
|
impl InputManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subsystem for InputSystem {
|
impl Subsystem for InputManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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 supervisor; pub(crate) use supervisor::*;
|
||||||
pub(crate) mod window; pub(crate) use window::*;
|
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 audio; pub(crate) use audio::*;
|
||||||
pub(crate) mod input; pub(crate) use input::*;
|
pub(crate) mod input; pub(crate) use input::*;
|
||||||
pub(crate) mod control; pub(crate) use control::*;
|
pub(crate) mod control; pub(crate) use control::*;
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub struct NetworkSystem {
|
pub struct NetworkManager {
|
||||||
channel:Sender<Query>,
|
channel:Sender<Query>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetworkSystem {
|
impl NetworkManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subsystem for NetworkSystem {
|
impl Subsystem for NetworkManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,13 @@ impl Query {
|
|||||||
|
|
||||||
pub enum QueryData {
|
pub enum QueryData {
|
||||||
Supervisor(SupervisorQuery),
|
Supervisor(SupervisorQuery),
|
||||||
|
API,
|
||||||
|
Audio,
|
||||||
|
Control,
|
||||||
|
Input,
|
||||||
|
Network,
|
||||||
|
Scene,
|
||||||
|
Storage,
|
||||||
|
Video,
|
||||||
Window(WindowQuery),
|
Window(WindowQuery),
|
||||||
}
|
}
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
use super::*;
|
|
||||||
|
|
||||||
pub struct RenderSystem {
|
|
||||||
channel:Sender<Query>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RenderSystem {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Subsystem for RenderSystem {
|
|
||||||
|
|
||||||
}
|
|
@ -1,13 +1,13 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub struct SceneSystem {
|
pub struct SceneManager {
|
||||||
channel:Sender<Query>,
|
channel:Sender<Query>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SceneSystem {
|
impl SceneManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subsystem for SceneSystem {
|
impl Subsystem for SceneManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub struct StorageSystem {
|
pub struct StorageManager {
|
||||||
channel:Sender<Query>,
|
channel:Sender<Query>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StorageSystem {
|
impl StorageManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subsystem for StorageSystem {
|
impl Subsystem for StorageManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ impl Internal {
|
|||||||
} => if sv.subsystems[system as usize].is_none() {
|
} => if sv.subsystems[system as usize].is_none() {
|
||||||
if let Ok(channel) = match system {
|
if let Ok(channel) = match system {
|
||||||
|
|
||||||
System::Window => WindowSystem::start(),
|
System::Window => WindowManager::start(),
|
||||||
|
|
||||||
_ => { Err(Error::new()) }
|
_ => { Err(Error::new()) }
|
||||||
} {
|
} {
|
||||||
@ -49,6 +49,9 @@ impl Internal {
|
|||||||
system,
|
system,
|
||||||
}
|
}
|
||||||
))).ok();
|
))).ok();
|
||||||
|
|
||||||
|
// Drop channel.
|
||||||
|
sv.subsystems[system as usize] = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
SupervisorQuery::Status {
|
SupervisorQuery::Status {
|
||||||
|
13
src/system/video/mod.rs
Normal file
13
src/system/video/mod.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub struct VideoManager {
|
||||||
|
channel:Sender<Query>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VideoManager {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Subsystem for VideoManager {
|
||||||
|
|
||||||
|
}
|
3
src/system/window/config.rs
Normal file
3
src/system/window/config.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pub struct WindowConfig {
|
||||||
|
|
||||||
|
}
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => { }
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
35
src/system/window/internal/handler.rs
Normal file
35
src/system/window/internal/handler.rs
Normal 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,
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
61
src/system/window/internal/mod.rs
Normal file
61
src/system/window/internal/mod.rs
Normal 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 {
|
||||||
|
|
||||||
|
} => {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => { }
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,47 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
mod query; pub use query::WindowQuery;
|
mod query; pub use query::WindowQuery;
|
||||||
|
mod config; pub use config::WindowConfig;
|
||||||
mod internal; use internal::Internal;
|
mod internal; use internal::Internal;
|
||||||
|
|
||||||
pub struct WindowSystem {
|
pub struct WindowManager {
|
||||||
channel:Sender<Query>,
|
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>
|
fn start() -> Result<Sender<Query>, crate::Error>
|
||||||
{
|
{
|
||||||
let (tx, rx) = channel::bounded::<Query>(24);
|
let (tx, rx) = channel::bounded::<Query>(24);
|
||||||
|
|
||||||
|
let sys_tx = tx.clone();
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
Internal::thread(rx);
|
Internal::thread(sys_tx, rx);
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Sender<Query>> for WindowManager {
|
||||||
|
fn from(channel :Sender<Query>) -> Self {
|
||||||
|
Self {
|
||||||
|
channel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
pub enum WindowQuery {
|
pub enum WindowQuery {
|
||||||
None,
|
None,
|
||||||
|
|
||||||
|
Create {
|
||||||
|
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user