aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-12-03 01:22:34 -0600
committermat <github@matdoes.dev>2022-12-03 01:22:34 -0600
commit661c3622bebc111a1523bc80792dc90d9d571b24 (patch)
treed605a758f6fcfc5001223f96a380b5acbc551b3e
parent8fd88aeae85932b8d9e9c67df0be3d01d499ce72 (diff)
downloadazalea-drasl-661c3622bebc111a1523bc80792dc90d9d571b24.tar.xz
make the packets in events be Arc
so they're cheap to clone
-rwxr-xr-xazalea-client/src/chat.rs9
-rw-r--r--azalea-client/src/client.rs16
2 files changed, 15 insertions, 10 deletions
diff --git a/azalea-client/src/chat.rs b/azalea-client/src/chat.rs
index 5f566fe7..26f37d58 100755
--- a/azalea-client/src/chat.rs
+++ b/azalea-client/src/chat.rs
@@ -9,13 +9,16 @@ use azalea_protocol::packets::game::{
serverbound_chat_command_packet::ServerboundChatCommandPacket,
serverbound_chat_packet::ServerboundChatPacket,
};
-use std::time::{SystemTime, UNIX_EPOCH};
+use std::{
+ sync::Arc,
+ time::{SystemTime, UNIX_EPOCH},
+};
/// A chat packet, either a system message or a chat message.
#[derive(Debug, Clone, PartialEq)]
pub enum ChatPacket {
- System(ClientboundSystemChatPacket),
- Player(Box<ClientboundPlayerChatPacket>),
+ System(Arc<ClientboundSystemChatPacket>),
+ Player(Arc<ClientboundPlayerChatPacket>),
}
macro_rules! regex {
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index ce4ca4cf..1cd26aa8 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -65,11 +65,11 @@ pub enum Event {
Chat(ChatPacket),
/// Happens 20 times per second, but only when the world is loaded.
Tick,
- Packet(Box<ClientboundGamePacket>),
+ Packet(Arc<ClientboundGamePacket>),
/// Happens when a player is added, removed, or updated in the tab list.
UpdatePlayers(UpdatePlayersEvent),
/// Emits when the player dies.
- Death(Option<Box<ClientboundPlayerCombatKillPacket>>),
+ Death(Option<Arc<ClientboundPlayerCombatKillPacket>>),
}
/// Happens when a player is added, removed, or updated in the tab list.
@@ -421,8 +421,9 @@ impl Client {
client: &Client,
tx: &Sender<Event>,
) -> Result<(), HandleError> {
- tx.send(Event::Packet(Box::new(packet.clone()))).await?;
- match packet {
+ let packet = Arc::new(packet.clone());
+ tx.send(Event::Packet(packet.clone())).await?;
+ match &*packet {
ClientboundGamePacket::Login(p) => {
debug!("Got login packet");
@@ -896,12 +897,13 @@ impl Client {
}
ClientboundGamePacket::PlayerChat(p) => {
debug!("Got player chat packet {:?}", p);
- tx.send(Event::Chat(ChatPacket::Player(Box::new(p.clone()))))
+ tx.send(Event::Chat(ChatPacket::Player(Arc::new(p.clone()))))
.await?;
}
ClientboundGamePacket::SystemChat(p) => {
debug!("Got system chat packet {:?}", p);
- tx.send(Event::Chat(ChatPacket::System(p.clone()))).await?;
+ tx.send(Event::Chat(ChatPacket::System(Arc::new(p.clone()))))
+ .await?;
}
ClientboundGamePacket::Sound(_p) => {
// debug!("Got sound packet {:?}", p);
@@ -975,7 +977,7 @@ impl Client {
// because of https://github.com/rust-lang/rust/issues/57478
if !*client.dead.lock() {
*client.dead.lock() = true;
- tx.send(Event::Death(Some(Box::new(p.clone())))).await?;
+ tx.send(Event::Death(Some(Arc::new(p.clone())))).await?;
}
}
}