mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-09 17:18:41 -06:00
ecs server
This commit is contained in:
parent
28a82cf69e
commit
055e6c3600
|
@ -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();
|
||||
loop {
|
||||
if let Err(or) = server.update() {
|
||||
println!("Server error: {or:?}")
|
||||
}
|
||||
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 {
|
||||
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