some changes to server and shared crates

This commit is contained in:
griffi-gh 2023-02-12 01:32:59 +01:00
parent f76fa8c70e
commit af62a3749b
11 changed files with 39 additions and 12 deletions

View file

@ -12,6 +12,8 @@ shipyard = "0.6"
serde = "1.0" serde = "1.0"
toml = "0.7" toml = "0.7"
glam = { version = "0.22", features = ["debug-glam-assert", "fast-math"] } glam = { version = "0.22", features = ["debug-glam-assert", "fast-math"] }
hashbrown = "0.13"
nohash-hasher = "0.2.0"
[features] [features]
default = [] default = []

View file

@ -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)] #[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<ClientId, EntityId, BuildNoHashHasher<ClientIdRepr>>);
impl ClientMap {
pub fn new() -> Self {
Self(HashMap::with_hasher(BuildNoHashHasher::default()))
}
}
impl Default for ClientMap {
fn default() -> Self {
Self::new()
}
}

View file

@ -4,7 +4,6 @@ use std::{thread, time::Duration};
pub(crate) mod config; pub(crate) mod config;
pub(crate) mod server; pub(crate) mod server;
pub(crate) mod client; pub(crate) mod client;
pub(crate) mod transform;
use config::read_config; use config::read_config;
use server::{bind_server, update_server}; use server::{bind_server, update_server};

View file

@ -1,6 +0,0 @@
use shipyard::Component;
use glam::Mat4;
#[derive(Component, Clone, Copy, Debug, Default)]
#[track(All)]
pub struct Transform(pub Mat4);

View file

@ -7,6 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
glam = { version = "0.22", features = ["debug-glam-assert", "fast-math", "serde"] } glam = { version = "0.22", features = ["debug-glam-assert", "fast-math", "serde"] }
shipyard = "0.6"
strum = { version = "0.24", features = ["derive"] } strum = { version = "0.24", features = ["derive"] }
bincode = "2.0.0-rc" bincode = "2.0.0-rc"
anyhow = "1.0" anyhow = "1.0"

View file

@ -2,3 +2,4 @@ pub mod blocks;
pub mod networking; pub mod networking;
pub mod worldgen; pub mod worldgen;
pub mod chunk; pub mod chunk;
pub mod transform;

View file

@ -1,4 +1,5 @@
use std::num::NonZeroU8; use std::num::NonZeroU8;
pub type ClientId = NonZeroU8; pub type ClientId = NonZeroU8;
pub type ClientIdRepr = u8;
pub const MAX_CLIENTS: usize = u8::MAX as _; pub const MAX_CLIENTS: usize = u8::MAX as _;

View file

@ -3,6 +3,7 @@ pub mod server;
pub(crate) mod packet; pub(crate) mod packet;
pub(crate) mod common; pub(crate) mod common;
pub use common::ClientId; pub use common::ClientId;
pub use common::ClientIdRepr;
//pub(crate) trait Serializable: bincode::Encode + bincode::Decode {} //pub(crate) trait Serializable: bincode::Encode + bincode::Decode {}
pub(crate) const BINCODE_CONFIG: bincode::config::Configuration<bincode::config::LittleEndian, bincode::config::Varint, bincode::config::SkipFixedArrayLength> = bincode::config::standard() pub(crate) const BINCODE_CONFIG: bincode::config::Configuration<bincode::config::LittleEndian, bincode::config::Varint, bincode::config::SkipFixedArrayLength> = bincode::config::standard()

View file

@ -10,7 +10,7 @@ use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher; use nohash_hasher::BuildNoHashHasher;
use crate::{ use crate::{
BINCODE_CONFIG, BINCODE_CONFIG,
common::{ClientId, MAX_CLIENTS}, common::{ClientId, ClientIdRepr, MAX_CLIENTS},
packet::{IdClientPacket, ClientPacket, ServerPacket, IdServerPacket} packet::{IdClientPacket, ClientPacket, ServerPacket, IdServerPacket}
}; };
@ -45,7 +45,7 @@ pub enum ServerEvent<T> where T: Encode + Decode {
pub struct Server<S, R> where S: Encode + Decode, R: Encode + Decode { pub struct Server<S, R> where S: Encode + Decode, R: Encode + Decode {
socket: UdpSocket, socket: UdpSocket,
clients: HashMap<ClientId, ConnectedClient, BuildNoHashHasher<u8>>, clients: HashMap<ClientId, ConnectedClient, BuildNoHashHasher<ClientIdRepr>>,
config: ServerConfig, config: ServerConfig,
event_queue: VecDeque<ServerEvent<R>>, event_queue: VecDeque<ServerEvent<R>>,
_s: PhantomData<S>, _s: PhantomData<S>,

View file

@ -18,11 +18,12 @@ use glium::{
use glam::vec3; use glam::vec3;
use std::time::Instant; use std::time::Instant;
pub use kubi_shared::transform;
pub(crate) mod rendering; pub(crate) mod rendering;
pub(crate) mod world; pub(crate) mod world;
pub(crate) mod player; pub(crate) mod player;
pub(crate) mod prefabs; pub(crate) mod prefabs;
pub(crate) mod transform;
pub(crate) mod settings; pub(crate) mod settings;
pub(crate) mod camera; pub(crate) mod camera;
pub(crate) mod events; pub(crate) mod events;