Move ClientIdMap to shared, switch to with_capacity_and_hasher where possible

This commit is contained in:
griffi-gh 2023-05-19 04:35:16 +02:00
parent cb18be7e2a
commit c0ce1c71d9
8 changed files with 36 additions and 27 deletions

2
Cargo.lock generated
View file

@ -996,6 +996,8 @@ dependencies = [
"anyhow",
"bracket-noise",
"glam",
"hashbrown 0.13.2",
"nohash-hasher",
"postcard",
"rand",
"rand_xoshiro",

View file

@ -14,10 +14,11 @@ use kubi_shared::{
transform::Transform, entity::{Entity, Health}
};
use crate::{
server::{ServerEvents, UdpServer, IsMessageOfType},
config::ConfigTable,
client::{ClientAddress, ClientIdMap, ClientAddressMap}
server::{ServerEvents, UdpServer, IsMessageOfType},
client::{ClientAddress, ClientAddressMap}
};
pub use kubi_shared::networking::client::ClientIdMap;
pub fn authenticate_players(
storages: AllStoragesView,

View file

@ -1,25 +1,11 @@
use shipyard::{Component, EntityId, Unique, AllStoragesView};
use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher;
use std::net::SocketAddr;
use kubi_shared::networking::client::ClientId;
pub use kubi_shared::networking::client::ClientIdMap;
#[derive(Component, Clone, Copy)]
pub struct ClientAddress(pub SocketAddr);
#[derive(Unique)]
pub struct ClientIdMap(pub HashMap<ClientId, EntityId, BuildNoHashHasher<ClientId>>);
impl ClientIdMap {
pub fn new() -> Self {
Self(HashMap::with_hasher(BuildNoHashHasher::default()))
}
}
impl Default for ClientIdMap {
fn default() -> Self {
Self::new()
}
}
#[derive(Unique, Default)]
pub struct ClientAddressMap(pub HashMap<SocketAddr, EntityId>);
impl ClientAddressMap {

View file

@ -25,7 +25,7 @@ impl Chunk {
position,
state: ChunkState::Nothing,
blocks: None,
subscriptions: HashSet::with_hasher(BuildNoHashHasher::default()),
subscriptions: HashSet::with_capacity_and_hasher(4, BuildNoHashHasher::default()),
}
}
}

View file

@ -4,8 +4,6 @@ version = "0.0.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
glam = { version = "0.23", features = ["debug-glam-assert", "fast-math", "serde"] }
shipyard = { git = "https://github.com/leudz/shipyard", rev = "a4f4d27edcf", default-features = false, features = ["std"] }
@ -16,7 +14,9 @@ anyhow = "1.0"
bracket-noise = "0.8"
rand = { version = "0.8", default_features = false, features = ["std", "min_const_gen"] }
rand_xoshiro = "0.6"
hashbrown = "0.13"
nohash-hasher = "0.2.0"
[features]
default = []
nightly = ["rand/nightly", "rand/simd_support", "glam/core-simd"]
nightly = ["hashbrown/nightly", "rand/nightly", "rand/simd_support", "glam/core-simd"]

View file

@ -1,6 +1,21 @@
use shipyard::Component;
use shipyard::{Component, Unique, EntityId};
use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher;
pub type ClientId = u16;
#[derive(Component, Clone, Copy, Debug)]
pub struct Client(pub ClientId);
#[derive(Unique)]
pub struct ClientIdMap(pub HashMap<ClientId, EntityId, BuildNoHashHasher<ClientId>>);
impl ClientIdMap {
pub fn new() -> Self {
Self(HashMap::with_capacity_and_hasher(16, BuildNoHashHasher::default()))
}
}
impl Default for ClientIdMap {
fn default() -> Self {
Self::new()
}
}

View file

@ -13,9 +13,9 @@ glam = { version = "0.23", features = ["debug-glam-assert", "fast-math"] }
image = { version = "0.24", default_features = false, features = ["png"] }
strum = { version = "0.24", features = ["derive"] }
hashbrown = "0.13"
nohash-hasher = "0.2.0"
rayon = "1.6"
shipyard = { git = "https://github.com/leudz/shipyard", rev = "a4f4d27edcf", default-features = false, features = ["std", "proc", "thread_local"] }
nohash-hasher = "0.2.0"
anyhow = "1.0"
flume = "0.10"
gilrs = { version = "0.10", default_features = false, features = ["xinput"] }

View file

@ -1,15 +1,20 @@
use glam::Vec3;
use shipyard::{UniqueViewMut, View, IntoIter};
use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher;
use shipyard::{UniqueViewMut, View, IntoIter, Unique, EntityId, AllStoragesView};
use uflow::{SendMode, client::Event as ClientEvent};
use kubi_shared::networking::{
messages::{ClientToServerMessage, ServerToClientMessage, S_PLAYER_POSITION_CHANGED},
channels::CHANNEL_MOVE,
channels::CHANNEL_MOVE,
client::{ClientId, ClientIdMap},
};
use crate::events::player_actions::PlayerActionEvent;
use super::{UdpClient, NetworkEvent};
pub fn init_net_player_map() {
//TODO
pub fn init_client_map(
storages: AllStoragesView,
) {
storages.add_unique(ClientIdMap::new());
}
pub fn add_net_player() {