mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-25 08:18:43 -06:00
ecs server
This commit is contained in:
parent
28a82cf69e
commit
055e6c3600
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
kubi-shared = { path = "../kubi-shared" }
|
kubi-shared = { path = "../kubi-shared" }
|
||||||
kubi-udp = { path = "../kubi-udp" }
|
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_udp::server::{Server, ServerConfig};
|
||||||
use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage};
|
use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage};
|
||||||
|
|
||||||
fn main() {
|
#[derive(Unique)]
|
||||||
let mut server: Server<ServerToClientMessage, ClientToServerMessage> = Server::bind(
|
#[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(),
|
"0.0.0.0:1234".parse().unwrap(),
|
||||||
ServerConfig::default()
|
ServerConfig::default()
|
||||||
).unwrap();
|
).unwrap();
|
||||||
loop {
|
storages.add_unique(UdpServer(server));
|
||||||
if let Err(or) = server.update() {
|
}
|
||||||
println!("Server error: {or:?}")
|
|
||||||
}
|
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>>,
|
clients: HashMap<ClientId, ConnectedClient, BuildNoHashHasher<u8>>,
|
||||||
config: ServerConfig,
|
config: ServerConfig,
|
||||||
event_queue: VecDeque<ServerEvent<R>>,
|
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 {
|
impl<S, R> Server<S, R> where S: Encode + Decode, R: Encode + Decode {
|
||||||
fn send_to_addr(&self, addr: SocketAddr, packet: IdServerPacket<S>) -> Result<()> {
|
fn send_to_addr(&self, addr: SocketAddr, packet: IdServerPacket<S>) -> Result<()> {
|
||||||
|
|
Loading…
Reference in a new issue