diff --git a/kubi-server/Cargo.toml b/kubi-server/Cargo.toml index 1b5c09a..d2856d9 100644 --- a/kubi-server/Cargo.toml +++ b/kubi-server/Cargo.toml @@ -12,6 +12,8 @@ shipyard = "0.6" serde = "1.0" toml = "0.7" glam = { version = "0.22", features = ["debug-glam-assert", "fast-math"] } +hashbrown = "0.13" +nohash-hasher = "0.2.0" [features] default = [] diff --git a/kubi-server/src/client.rs b/kubi-server/src/client.rs index a0c57ac..2508fa1 100644 --- a/kubi-server/src/client.rs +++ b/kubi-server/src/client.rs @@ -1,4 +1,31 @@ -use shipyard::Component; +use shipyard::{Component, EntityId}; +use hashbrown::HashMap; +use nohash_hasher::BuildNoHashHasher; +use kubi_udp::{ClientId, ClientIdRepr}; #[derive(Component)] -pub struct Client; +pub struct Client(ClientId); + + +// disconnected => connect => join => load => ingame +#[derive(Component)] +pub enum ClientJoinState { + /// Client has connected to the game, but haven't authenticated yet + Connected, + /// Client has joined the game, but haven't loaded the world yet + Joined, + /// Client is currently ingame + InGame, +} + +pub struct ClientMap(HashMap>); +impl ClientMap { + pub fn new() -> Self { + Self(HashMap::with_hasher(BuildNoHashHasher::default())) + } +} +impl Default for ClientMap { + fn default() -> Self { + Self::new() + } +} diff --git a/kubi-server/src/main.rs b/kubi-server/src/main.rs index 6c0158e..bb6f60e 100644 --- a/kubi-server/src/main.rs +++ b/kubi-server/src/main.rs @@ -4,7 +4,6 @@ use std::{thread, time::Duration}; pub(crate) mod config; pub(crate) mod server; pub(crate) mod client; -pub(crate) mod transform; use config::read_config; use server::{bind_server, update_server}; diff --git a/kubi-server/src/transform.rs b/kubi-server/src/transform.rs deleted file mode 100644 index 5087b6c..0000000 --- a/kubi-server/src/transform.rs +++ /dev/null @@ -1,6 +0,0 @@ -use shipyard::Component; -use glam::Mat4; - -#[derive(Component, Clone, Copy, Debug, Default)] -#[track(All)] -pub struct Transform(pub Mat4); diff --git a/kubi-shared/Cargo.toml b/kubi-shared/Cargo.toml index c42eb3b..7fb813f 100644 --- a/kubi-shared/Cargo.toml +++ b/kubi-shared/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] glam = { version = "0.22", features = ["debug-glam-assert", "fast-math", "serde"] } +shipyard = "0.6" strum = { version = "0.24", features = ["derive"] } bincode = "2.0.0-rc" anyhow = "1.0" diff --git a/kubi-shared/src/lib.rs b/kubi-shared/src/lib.rs index dd0e7a5..13cb165 100644 --- a/kubi-shared/src/lib.rs +++ b/kubi-shared/src/lib.rs @@ -2,3 +2,4 @@ pub mod blocks; pub mod networking; pub mod worldgen; pub mod chunk; +pub mod transform; diff --git a/kubi/src/transform.rs b/kubi-shared/src/transform.rs similarity index 100% rename from kubi/src/transform.rs rename to kubi-shared/src/transform.rs diff --git a/kubi-udp/src/common.rs b/kubi-udp/src/common.rs index 20e5a1e..76e92b2 100644 --- a/kubi-udp/src/common.rs +++ b/kubi-udp/src/common.rs @@ -1,4 +1,5 @@ use std::num::NonZeroU8; pub type ClientId = NonZeroU8; +pub type ClientIdRepr = u8; pub const MAX_CLIENTS: usize = u8::MAX as _; diff --git a/kubi-udp/src/lib.rs b/kubi-udp/src/lib.rs index ec14b35..ae5678c 100644 --- a/kubi-udp/src/lib.rs +++ b/kubi-udp/src/lib.rs @@ -3,6 +3,7 @@ pub mod server; pub(crate) mod packet; pub(crate) mod common; pub use common::ClientId; +pub use common::ClientIdRepr; //pub(crate) trait Serializable: bincode::Encode + bincode::Decode {} pub(crate) const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard() diff --git a/kubi-udp/src/server.rs b/kubi-udp/src/server.rs index 905aefc..f9a8322 100644 --- a/kubi-udp/src/server.rs +++ b/kubi-udp/src/server.rs @@ -10,7 +10,7 @@ use hashbrown::HashMap; use nohash_hasher::BuildNoHashHasher; use crate::{ BINCODE_CONFIG, - common::{ClientId, MAX_CLIENTS}, + common::{ClientId, ClientIdRepr, MAX_CLIENTS}, packet::{IdClientPacket, ClientPacket, ServerPacket, IdServerPacket} }; @@ -45,7 +45,7 @@ pub enum ServerEvent where T: Encode + Decode { pub struct Server where S: Encode + Decode, R: Encode + Decode { socket: UdpSocket, - clients: HashMap>, + clients: HashMap>, config: ServerConfig, event_queue: VecDeque>, _s: PhantomData, diff --git a/kubi/src/main.rs b/kubi/src/main.rs index d683794..924d481 100644 --- a/kubi/src/main.rs +++ b/kubi/src/main.rs @@ -18,11 +18,12 @@ use glium::{ use glam::vec3; use std::time::Instant; +pub use kubi_shared::transform; + pub(crate) mod rendering; pub(crate) mod world; pub(crate) mod player; pub(crate) mod prefabs; -pub(crate) mod transform; pub(crate) mod settings; pub(crate) mod camera; pub(crate) mod events;