diff --git a/kubi-server/Cargo.toml b/kubi-server/Cargo.toml index 5dc3fc5..87c64dd 100644 --- a/kubi-server/Cargo.toml +++ b/kubi-server/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" [dependencies] kubi-shared = { path = "../kubi-shared" } kubi-udp = { path = "../kubi-udp" } +shipyard = "0.6" diff --git a/kubi-server/src/main.rs b/kubi-server/src/main.rs index 9460db3..b82c528 100644 --- a/kubi-server/src/main.rs +++ b/kubi-server/src/main.rs @@ -1,14 +1,47 @@ +use shipyard::{World, AllStoragesView, Unique, Workload, IntoWorkload, UniqueView, UniqueViewMut}; use kubi_udp::server::{Server, ServerConfig}; use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage}; -fn main() { - let mut server: Server = Server::bind( +#[derive(Unique)] +#[repr(transparent)] +pub struct UdpServer(Server); + +fn bind_server( + storages: AllStoragesView, +) { + let server: Server = Server::bind( "0.0.0.0:1234".parse().unwrap(), ServerConfig::default() ).unwrap(); - loop { - if let Err(or) = server.update() { - println!("Server error: {or:?}") - } + storages.add_unique(UdpServer(server)); +} + +fn update_server( + mut server: UniqueViewMut +) { + if let Err(error) = server.0.update() { + println!("Server error: {error:?}") + } +} + +fn initialize() -> Workload { + ( + bind_server, + ).into_workload() +} + +fn update() -> Workload { + ( + update_server, + ).into_workload() +} + +fn main() { + let world = World::new(); + world.add_workload(initialize); + world.add_workload(update); + world.run_workload(initialize).unwrap(); + loop { + world.run_workload(update).unwrap(); } } diff --git a/kubi-udp/src/server.rs b/kubi-udp/src/server.rs index 1a0b537..905aefc 100644 --- a/kubi-udp/src/server.rs +++ b/kubi-udp/src/server.rs @@ -48,7 +48,7 @@ pub struct Server where S: Encode + Decode, R: Encode + Decode { clients: HashMap>, config: ServerConfig, event_queue: VecDeque>, - _s: PhantomData<*const S>, + _s: PhantomData, } impl Server where S: Encode + Decode, R: Encode + Decode { fn send_to_addr(&self, addr: SocketAddr, packet: IdServerPacket) -> Result<()> {