mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-25 13:18:21 -06:00
ecs server
This commit is contained in:
parent
6922c7635e
commit
1c35573bba
|
@ -6,3 +6,4 @@ edition = "2021"
|
|||
[dependencies]
|
||||
kubi-shared = { path = "../kubi-shared" }
|
||||
kubi-udp = { path = "../kubi-udp" }
|
||||
shipyard = "0.6"
|
||||
|
|
|
@ -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<ServerToClientMessage, ClientToServerMessage> = Server::bind(
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
pub struct UdpServer(Server<ServerToClientMessage, ClientToServerMessage>);
|
||||
|
||||
fn bind_server(
|
||||
storages: AllStoragesView,
|
||||
) {
|
||||
let server: Server<ServerToClientMessage, ClientToServerMessage> = Server::bind(
|
||||
"0.0.0.0:1234".parse().unwrap(),
|
||||
ServerConfig::default()
|
||||
).unwrap();
|
||||
storages.add_unique(UdpServer(server));
|
||||
}
|
||||
|
||||
fn update_server(
|
||||
mut server: UniqueViewMut<UdpServer>
|
||||
) {
|
||||
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 {
|
||||
if let Err(or) = server.update() {
|
||||
println!("Server error: {or:?}")
|
||||
}
|
||||
world.run_workload(update).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pub struct Server<S, R> where S: Encode + Decode, R: Encode + Decode {
|
|||
clients: HashMap<ClientId, ConnectedClient, BuildNoHashHasher<u8>>,
|
||||
config: ServerConfig,
|
||||
event_queue: VecDeque<ServerEvent<R>>,
|
||||
_s: PhantomData<*const S>,
|
||||
_s: PhantomData<S>,
|
||||
}
|
||||
impl<S, R> Server<S, R> where S: Encode + Decode, R: Encode + Decode {
|
||||
fn send_to_addr(&self, addr: SocketAddr, packet: IdServerPacket<S>) -> Result<()> {
|
||||
|
|
Loading…
Reference in a new issue