some changes to server and shared crates

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

View file

@ -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 = []

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)]
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 server;
pub(crate) mod client;
pub(crate) mod transform;
use config::read_config;
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]
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"

View file

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

View file

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

View file

@ -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::LittleEndian, bincode::config::Varint, bincode::config::SkipFixedArrayLength> = bincode::config::standard()

View file

@ -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<T> where T: Encode + Decode {
pub struct Server<S, R> where S: Encode + Decode, R: Encode + Decode {
socket: UdpSocket,
clients: HashMap<ClientId, ConnectedClient, BuildNoHashHasher<u8>>,
clients: HashMap<ClientId, ConnectedClient, BuildNoHashHasher<ClientIdRepr>>,
config: ServerConfig,
event_queue: VecDeque<ServerEvent<R>>,
_s: PhantomData<S>,

View file

@ -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;