mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-26 21:58:20 -06:00
Move ClientIdMap
to shared, switch to with_capacity_and_hasher
where possible
This commit is contained in:
parent
cb18be7e2a
commit
c0ce1c71d9
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -996,6 +996,8 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bracket-noise",
|
"bracket-noise",
|
||||||
"glam",
|
"glam",
|
||||||
|
"hashbrown 0.13.2",
|
||||||
|
"nohash-hasher",
|
||||||
"postcard",
|
"postcard",
|
||||||
"rand",
|
"rand",
|
||||||
"rand_xoshiro",
|
"rand_xoshiro",
|
||||||
|
|
|
@ -14,10 +14,11 @@ use kubi_shared::{
|
||||||
transform::Transform, entity::{Entity, Health}
|
transform::Transform, entity::{Entity, Health}
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
server::{ServerEvents, UdpServer, IsMessageOfType},
|
|
||||||
config::ConfigTable,
|
config::ConfigTable,
|
||||||
client::{ClientAddress, ClientIdMap, ClientAddressMap}
|
server::{ServerEvents, UdpServer, IsMessageOfType},
|
||||||
|
client::{ClientAddress, ClientAddressMap}
|
||||||
};
|
};
|
||||||
|
pub use kubi_shared::networking::client::ClientIdMap;
|
||||||
|
|
||||||
pub fn authenticate_players(
|
pub fn authenticate_players(
|
||||||
storages: AllStoragesView,
|
storages: AllStoragesView,
|
||||||
|
|
|
@ -1,25 +1,11 @@
|
||||||
use shipyard::{Component, EntityId, Unique, AllStoragesView};
|
use shipyard::{Component, EntityId, Unique, AllStoragesView};
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use nohash_hasher::BuildNoHashHasher;
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use kubi_shared::networking::client::ClientId;
|
pub use kubi_shared::networking::client::ClientIdMap;
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy)]
|
#[derive(Component, Clone, Copy)]
|
||||||
pub struct ClientAddress(pub SocketAddr);
|
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)]
|
#[derive(Unique, Default)]
|
||||||
pub struct ClientAddressMap(pub HashMap<SocketAddr, EntityId>);
|
pub struct ClientAddressMap(pub HashMap<SocketAddr, EntityId>);
|
||||||
impl ClientAddressMap {
|
impl ClientAddressMap {
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl Chunk {
|
||||||
position,
|
position,
|
||||||
state: ChunkState::Nothing,
|
state: ChunkState::Nothing,
|
||||||
blocks: None,
|
blocks: None,
|
||||||
subscriptions: HashSet::with_hasher(BuildNoHashHasher::default()),
|
subscriptions: HashSet::with_capacity_and_hasher(4, BuildNoHashHasher::default()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@ version = "0.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
glam = { version = "0.23", features = ["debug-glam-assert", "fast-math", "serde"] }
|
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"] }
|
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"
|
bracket-noise = "0.8"
|
||||||
rand = { version = "0.8", default_features = false, features = ["std", "min_const_gen"] }
|
rand = { version = "0.8", default_features = false, features = ["std", "min_const_gen"] }
|
||||||
rand_xoshiro = "0.6"
|
rand_xoshiro = "0.6"
|
||||||
|
hashbrown = "0.13"
|
||||||
|
nohash-hasher = "0.2.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
nightly = ["rand/nightly", "rand/simd_support", "glam/core-simd"]
|
nightly = ["hashbrown/nightly", "rand/nightly", "rand/simd_support", "glam/core-simd"]
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
use shipyard::Component;
|
use shipyard::{Component, Unique, EntityId};
|
||||||
|
use hashbrown::HashMap;
|
||||||
|
use nohash_hasher::BuildNoHashHasher;
|
||||||
|
|
||||||
pub type ClientId = u16;
|
pub type ClientId = u16;
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy, Debug)]
|
#[derive(Component, Clone, Copy, Debug)]
|
||||||
pub struct Client(pub ClientId);
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ glam = { version = "0.23", features = ["debug-glam-assert", "fast-math"] }
|
||||||
image = { version = "0.24", default_features = false, features = ["png"] }
|
image = { version = "0.24", default_features = false, features = ["png"] }
|
||||||
strum = { version = "0.24", features = ["derive"] }
|
strum = { version = "0.24", features = ["derive"] }
|
||||||
hashbrown = "0.13"
|
hashbrown = "0.13"
|
||||||
|
nohash-hasher = "0.2.0"
|
||||||
rayon = "1.6"
|
rayon = "1.6"
|
||||||
shipyard = { git = "https://github.com/leudz/shipyard", rev = "a4f4d27edcf", default-features = false, features = ["std", "proc", "thread_local"] }
|
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"
|
anyhow = "1.0"
|
||||||
flume = "0.10"
|
flume = "0.10"
|
||||||
gilrs = { version = "0.10", default_features = false, features = ["xinput"] }
|
gilrs = { version = "0.10", default_features = false, features = ["xinput"] }
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
use glam::Vec3;
|
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 uflow::{SendMode, client::Event as ClientEvent};
|
||||||
use kubi_shared::networking::{
|
use kubi_shared::networking::{
|
||||||
messages::{ClientToServerMessage, ServerToClientMessage, S_PLAYER_POSITION_CHANGED},
|
messages::{ClientToServerMessage, ServerToClientMessage, S_PLAYER_POSITION_CHANGED},
|
||||||
channels::CHANNEL_MOVE,
|
channels::CHANNEL_MOVE,
|
||||||
|
client::{ClientId, ClientIdMap},
|
||||||
};
|
};
|
||||||
use crate::events::player_actions::PlayerActionEvent;
|
use crate::events::player_actions::PlayerActionEvent;
|
||||||
use super::{UdpClient, NetworkEvent};
|
use super::{UdpClient, NetworkEvent};
|
||||||
|
|
||||||
pub fn init_net_player_map() {
|
pub fn init_client_map(
|
||||||
//TODO
|
storages: AllStoragesView,
|
||||||
|
) {
|
||||||
|
storages.add_unique(ClientIdMap::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_net_player() {
|
pub fn add_net_player() {
|
||||||
|
|
Loading…
Reference in a new issue