mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 14:31:30 +11:00
Skip spawn of non visible player characters (#100)
* Skip spawn of non visible player characters * Don't spawn player if player list is `None` Co-authored-by: Ryan <ryanj00a@gmail.com>
This commit is contained in:
parent
153cde1a04
commit
e13d0ffe7a
|
@ -188,8 +188,8 @@ pub struct Client<C: Config> {
|
||||||
username: String,
|
username: String,
|
||||||
textures: Option<SignedPlayerTextures>,
|
textures: Option<SignedPlayerTextures>,
|
||||||
world: WorldId,
|
world: WorldId,
|
||||||
|
player_list: Option<PlayerListId>,
|
||||||
old_player_list: Option<PlayerListId>,
|
old_player_list: Option<PlayerListId>,
|
||||||
new_player_list: Option<PlayerListId>,
|
|
||||||
position: Vec3<f64>,
|
position: Vec3<f64>,
|
||||||
old_position: Vec3<f64>,
|
old_position: Vec3<f64>,
|
||||||
/// Measured in m/s.
|
/// Measured in m/s.
|
||||||
|
@ -271,7 +271,7 @@ impl<C: Config> Client<C> {
|
||||||
textures: ncd.textures,
|
textures: ncd.textures,
|
||||||
world: WorldId::default(),
|
world: WorldId::default(),
|
||||||
old_player_list: None,
|
old_player_list: None,
|
||||||
new_player_list: None,
|
player_list: None,
|
||||||
position: Vec3::default(),
|
position: Vec3::default(),
|
||||||
old_position: Vec3::default(),
|
old_position: Vec3::default(),
|
||||||
velocity: Vec3::default(),
|
velocity: Vec3::default(),
|
||||||
|
@ -334,14 +334,14 @@ impl<C: Config> Client<C> {
|
||||||
|
|
||||||
/// Gets the player list this client sees.
|
/// Gets the player list this client sees.
|
||||||
pub fn player_list(&self) -> Option<&PlayerListId> {
|
pub fn player_list(&self) -> Option<&PlayerListId> {
|
||||||
self.new_player_list.as_ref()
|
self.player_list.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the player list this client sees.
|
/// Sets the player list this client sees.
|
||||||
///
|
///
|
||||||
/// The previous player list ID is returned.
|
/// The previous player list ID is returned.
|
||||||
pub fn set_player_list(&mut self, id: impl Into<Option<PlayerListId>>) -> Option<PlayerListId> {
|
pub fn set_player_list(&mut self, id: impl Into<Option<PlayerListId>>) -> Option<PlayerListId> {
|
||||||
mem::replace(&mut self.new_player_list, id.into())
|
mem::replace(&mut self.player_list, id.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets if this client sees the world as superflat. Superflat worlds have
|
/// Sets if this client sees the world as superflat. Superflat worlds have
|
||||||
|
@ -1035,7 +1035,7 @@ impl<C: Config> Client<C> {
|
||||||
if self.created_this_tick() {
|
if self.created_this_tick() {
|
||||||
self.bits.set_spawn(false);
|
self.bits.set_spawn(false);
|
||||||
|
|
||||||
if let Some(id) = &self.new_player_list {
|
if let Some(id) = &self.player_list {
|
||||||
player_lists
|
player_lists
|
||||||
.get(id)
|
.get(id)
|
||||||
.initial_packets(|p| send_packet(&mut self.send, p));
|
.initial_packets(|p| send_packet(&mut self.send, p));
|
||||||
|
@ -1118,7 +1118,7 @@ impl<C: Config> Client<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the player list was changed...
|
// If the player list was changed...
|
||||||
if self.old_player_list != self.new_player_list {
|
if self.old_player_list != self.player_list {
|
||||||
// Delete existing entries from old player list.
|
// Delete existing entries from old player list.
|
||||||
if let Some(id) = &self.old_player_list {
|
if let Some(id) = &self.old_player_list {
|
||||||
player_lists
|
player_lists
|
||||||
|
@ -1127,14 +1127,14 @@ impl<C: Config> Client<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get initial packets for new player list.
|
// Get initial packets for new player list.
|
||||||
if let Some(id) = &self.new_player_list {
|
if let Some(id) = &self.player_list {
|
||||||
player_lists
|
player_lists
|
||||||
.get(id)
|
.get(id)
|
||||||
.initial_packets(|p| send_packet(&mut self.send, p));
|
.initial_packets(|p| send_packet(&mut self.send, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.old_player_list = self.new_player_list.clone();
|
self.old_player_list = self.player_list.clone();
|
||||||
} else if let Some(id) = &self.new_player_list {
|
} else if let Some(id) = &self.player_list {
|
||||||
// Update current player list.
|
// Update current player list.
|
||||||
player_lists
|
player_lists
|
||||||
.get(id)
|
.get(id)
|
||||||
|
@ -1452,6 +1452,17 @@ impl<C: Config> Client<C> {
|
||||||
let entity = entities
|
let entity = entities
|
||||||
.get(id)
|
.get(id)
|
||||||
.expect("entity IDs in spatial index should be valid at this point");
|
.expect("entity IDs in spatial index should be valid at this point");
|
||||||
|
|
||||||
|
// Skip spawning players not in the player list because they would be invisible
|
||||||
|
// otherwise.
|
||||||
|
if entity.kind() == EntityKind::Player {
|
||||||
|
if let Some(list_id) = &self.player_list {
|
||||||
|
player_lists.get(list_id).entry(entity.uuid())?;
|
||||||
|
} else {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if entity.kind() != EntityKind::Marker
|
if entity.kind() != EntityKind::Marker
|
||||||
&& entity.uuid() != self.uuid
|
&& entity.uuid() != self.uuid
|
||||||
&& self.loaded_entities.insert(id)
|
&& self.loaded_entities.insert(id)
|
||||||
|
|
|
@ -222,6 +222,20 @@ impl<C: Config> PlayerList<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a reference to the entry with the given UUID.
|
||||||
|
///
|
||||||
|
/// If the entry does not exist, `None` is returned.
|
||||||
|
pub fn entry(&self, uuid: Uuid) -> Option<&PlayerListEntry> {
|
||||||
|
self.entries.get(&uuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a mutable reference to the entry with the given UUID.
|
||||||
|
///
|
||||||
|
/// If the entry does not exist, `None` is returned.
|
||||||
|
pub fn entry_mut(&mut self, uuid: Uuid) -> Option<&mut PlayerListEntry> {
|
||||||
|
self.entries.get_mut(&uuid)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all entries in an unspecified order.
|
/// Returns an iterator over all entries in an unspecified order.
|
||||||
pub fn entries(&self) -> impl Iterator<Item = (Uuid, &PlayerListEntry)> + '_ {
|
pub fn entries(&self) -> impl Iterator<Item = (Uuid, &PlayerListEntry)> + '_ {
|
||||||
self.entries.iter().map(|(k, v)| (*k, v))
|
self.entries.iter().map(|(k, v)| (*k, v))
|
||||||
|
|
Loading…
Reference in a new issue