From 34a50c62b0bad1b98dac24a93c19c8e77d96da6a Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Wed, 8 Mar 2023 17:27:53 +0100 Subject: [PATCH] change server stuff --- Cargo.lock | 3 +++ kubi-server/Cargo.toml | 7 +++++-- kubi-server/src/client.rs | 3 ++- kubi-server/src/server.rs | 1 + kubi-server/src/world/chunk.rs | 7 +++++-- kubi-shared/Cargo.toml | 2 +- kubi-shared/src/networking.rs | 1 + kubi-shared/src/networking/client.rs | 3 +++ 8 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 kubi-shared/src/networking/client.rs diff --git a/Cargo.lock b/Cargo.lock index ad34951..8a4cca4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -961,10 +961,13 @@ dependencies = [ "kubi-shared", "log", "nohash-hasher", + "postcard", + "rand", "rayon", "serde", "shipyard", "toml", + "uflow", ] [[package]] diff --git a/kubi-server/Cargo.toml b/kubi-server/Cargo.toml index 3784589..6c6b67d 100644 --- a/kubi-server/Cargo.toml +++ b/kubi-server/Cargo.toml @@ -9,7 +9,7 @@ kubi-shared = { path = "../kubi-shared" } kubi-logging = { path = "../kubi-logging" } log = "*" shipyard = { git = "https://github.com/leudz/shipyard", rev = "eb189f66" } -serde = "1.0" +serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } toml = "0.7" glam = { version = "0.23", features = ["debug-glam-assert", "fast-math"] } hashbrown = "0.13" @@ -17,7 +17,10 @@ nohash-hasher = "0.2.0" anyhow = "1.0" rayon = "1.6" flume = "0.10" +rand = "0.8" +uflow = "0.7" +postcard = { version = "1.0", features = ["alloc"] } [features] default = [] -unstable = ["glam/core-simd"] +nightly = ["rand/nightly", "rand/simd_support", "serde/unstable", "glam/core-simd", "kubi-shared/nightly"] diff --git a/kubi-server/src/client.rs b/kubi-server/src/client.rs index 41423ba..086e398 100644 --- a/kubi-server/src/client.rs +++ b/kubi-server/src/client.rs @@ -1,11 +1,12 @@ use shipyard::{Component, EntityId}; use hashbrown::HashMap; use nohash_hasher::BuildNoHashHasher; +use kubi_shared::networking::client::ClientId; #[derive(Component)] pub struct Client(ClientId); -pub struct ClientMap(HashMap>); +pub struct ClientMap(HashMap>); impl ClientMap { pub fn new() -> Self { Self(HashMap::with_hasher(BuildNoHashHasher::default())) diff --git a/kubi-server/src/server.rs b/kubi-server/src/server.rs index f576b3e..b862a31 100644 --- a/kubi-server/src/server.rs +++ b/kubi-server/src/server.rs @@ -1,5 +1,6 @@ use shipyard::{AllStoragesView, Unique, UniqueView, UniqueViewMut}; use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage}; +use uflow::server::Server; use std::time::Duration; use crate::config::ConfigTable; diff --git a/kubi-server/src/world/chunk.rs b/kubi-server/src/world/chunk.rs index 8a26922..bfecbcd 100644 --- a/kubi-server/src/world/chunk.rs +++ b/kubi-server/src/world/chunk.rs @@ -1,7 +1,10 @@ use glam::IVec3; use hashbrown::HashSet; use nohash_hasher::BuildNoHashHasher; -use kubi_shared::chunk::BlockData; +use kubi_shared::{ + chunk::BlockData, + networking::client::ClientId +}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ChunkState { @@ -14,7 +17,7 @@ pub struct Chunk { pub position: IVec3, pub state: ChunkState, pub blocks: Option, - pub subscriptions: HashSet>, + pub subscriptions: HashSet>, } impl Chunk { pub fn new(position: IVec3) -> Self { diff --git a/kubi-shared/Cargo.toml b/kubi-shared/Cargo.toml index be2079d..90617c0 100644 --- a/kubi-shared/Cargo.toml +++ b/kubi-shared/Cargo.toml @@ -19,4 +19,4 @@ rand_xoshiro = "0.6" [features] default = [] -nightly = ["rand/nightly", "rand/simd_support", "serde/unstable"] +nightly = ["rand/nightly", "rand/simd_support", "serde/unstable", "glam/core-simd"] diff --git a/kubi-shared/src/networking.rs b/kubi-shared/src/networking.rs index 4945d0c..05bff68 100644 --- a/kubi-shared/src/networking.rs +++ b/kubi-shared/src/networking.rs @@ -1,2 +1,3 @@ pub mod messages; pub mod state; +pub mod client; diff --git a/kubi-shared/src/networking/client.rs b/kubi-shared/src/networking/client.rs new file mode 100644 index 0000000..35f3744 --- /dev/null +++ b/kubi-shared/src/networking/client.rs @@ -0,0 +1,3 @@ +pub type ClientId = u16; +pub type ClientKey = u16; +