Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/server/related_entities.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::any::{self, TypeId};
use core::any::TypeId;

use bevy::{
ecs::{component::Immutable, relationship::Relationship},
Expand Down Expand Up @@ -106,7 +106,7 @@ impl RelatedEntities {
let type_id = TypeId::of::<C>();
debug!(
"connecting `{source}` with `{target}` via `{}`",
any::type_name::<C>()
ShortName::of::<C>()
);

self.graph.add_edge(source_node, target_node, type_id);
Expand All @@ -124,7 +124,7 @@ impl RelatedEntities {
let type_id = TypeId::of::<C>();
debug!(
"disconnecting `{source}` from `{target}` via `{}`",
any::type_name::<C>()
ShortName::of::<C>()
);

// Remove all matching edges of this type.
Expand Down
4 changes: 2 additions & 2 deletions src/shared/message/client_event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::any::{self, TypeId};
use core::any::TypeId;

use bevy::{ecs::entity::MapEntities, prelude::*, ptr::PtrMut};
use log::debug;
Expand Down Expand Up @@ -123,7 +123,7 @@ impl ClientEvent {
for FromClient { client_id, message } in from_messages.drain() {
debug!(
"triggering `{}` from `{client_id}`",
any::type_name::<FromClient<E>>()
ShortName::of::<FromClient<E>>()
);
commands.trigger(FromClient {
client_id,
Expand Down
14 changes: 7 additions & 7 deletions src/shared/message/client_message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::any::{self, TypeId};
use core::any::TypeId;

use bevy::{
ecs::{component::ComponentId, entity::MapEntities, message::MessageCursor},
Expand Down Expand Up @@ -263,12 +263,12 @@ impl ClientMessage {
if let Err(e) = unsafe { self.serialize::<M, I>(ctx, message, &mut message_bytes) } {
error!(
"ignoring message `{}` that failed to serialize: {e}",
any::type_name::<M>()
ShortName::of::<M>()
);
continue;
}

debug!("sending message `{}`", any::type_name::<M>());
debug!("sending message `{}`", ShortName::of::<M>());
client_messages.send(self.channel_id, message_bytes);
}
}
Expand Down Expand Up @@ -306,7 +306,7 @@ impl ClientMessage {
Ok(message) => {
debug!(
"writing message `{}` from client `{client}`",
any::type_name::<M>()
ShortName::of::<M>()
);
from_messages.write(FromClient {
client_id: client.into(),
Expand All @@ -315,7 +315,7 @@ impl ClientMessage {
}
Err(e) => debug!(
"ignoring message `{}` from client `{client}` that failed to deserialize: {e}",
any::type_name::<M>()
ShortName::of::<M>()
),
}
}
Expand Down Expand Up @@ -343,7 +343,7 @@ impl ClientMessage {
debug!(
"writing {} message(s) `{}` locally",
messages.len(),
any::type_name::<M>()
ShortName::of::<M>()
);
from_messages.write_batch(messages.drain().map(|message| FromClient {
client_id: ClientId::Server,
Expand Down Expand Up @@ -373,7 +373,7 @@ impl ClientMessage {
if drained_count > 0 {
warn!(
"discarded {drained_count} messages of type `{}` that were buffered before the connection",
any::type_name::<M>()
ShortName::of::<M>()
);
}
}
Expand Down
29 changes: 13 additions & 16 deletions src/shared/message/message_fns.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use alloc::vec::Vec;
use core::{
any::{self, TypeId},
mem,
};
use core::{any::TypeId, mem};

use bevy::prelude::*;
use bytes::Bytes;
Expand All @@ -13,13 +10,13 @@ use bytes::Bytes;
#[derive(Clone, Copy)]
pub(super) struct UntypedMessageFns {
serialize_ctx_id: TypeId,
serialize_ctx_name: &'static str,
serialize_ctx_name: ShortName<'static>,
deserialize_ctx_id: TypeId,
deserialize_ctx_name: &'static str,
deserialize_ctx_name: ShortName<'static>,
message_id: TypeId,
message_name: &'static str,
message_name: ShortName<'static>,
inner_id: TypeId,
inner_name: &'static str,
inner_name: ShortName<'static>,

serialize_adapter: unsafe fn(),
deserialize_adapter: unsafe fn(),
Expand All @@ -41,28 +38,28 @@ impl UntypedMessageFns {
self.serialize_ctx_id,
typeid::of::<S>(),
"trying to call message functions with serialize context `{}`, but they were created with `{}`",
any::type_name::<S>(),
ShortName::of::<S>(),
self.serialize_ctx_name,
);
debug_assert_eq!(
self.deserialize_ctx_id,
typeid::of::<D>(),
"trying to call message functions with deserialize context `{}`, but they were created with `{}`",
any::type_name::<D>(),
ShortName::of::<D>(),
self.deserialize_ctx_name,
);
debug_assert_eq!(
self.message_id,
TypeId::of::<M>(),
"trying to call message functions with message `{}`, but they were created with `{}`",
any::type_name::<M>(),
ShortName::of::<M>(),
self.message_name,
);
debug_assert_eq!(
self.inner_id,
TypeId::of::<I>(),
"trying to call message functions with inner type `{}`, but they were created with `{}`",
any::type_name::<I>(),
ShortName::of::<I>(),
self.inner_name,
);

Expand All @@ -88,13 +85,13 @@ impl<S, D, M: 'static, I: 'static> From<MessageFns<S, D, M, I>> for UntypedMessa
// SAFETY: these functions won't be called until the type is restored.
Self {
serialize_ctx_id: typeid::of::<S>(),
serialize_ctx_name: any::type_name::<S>(),
serialize_ctx_name: ShortName::of::<S>(),
deserialize_ctx_id: typeid::of::<D>(),
deserialize_ctx_name: any::type_name::<D>(),
deserialize_ctx_name: ShortName::of::<D>(),
message_id: TypeId::of::<M>(),
message_name: any::type_name::<M>(),
message_name: ShortName::of::<M>(),
inner_id: TypeId::of::<I>(),
inner_name: any::type_name::<I>(),
inner_name: ShortName::of::<I>(),
serialize_adapter: unsafe {
mem::transmute::<AdapterSerializeFn<S, M, I>, unsafe fn()>(value.serialize_adapter)
},
Expand Down
8 changes: 4 additions & 4 deletions src/shared/message/server_event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::any::{self, TypeId};
use core::any::TypeId;

use bevy::{ecs::entity::MapEntities, prelude::*, ptr::PtrMut};
use log::debug;
Expand Down Expand Up @@ -96,7 +96,7 @@ impl ServerEventAppExt for App {
.unwrap_or_else(|| {
panic!(
"event `{}` should be previously registered",
any::type_name::<E>()
ShortName::of::<E>()
)
});

Expand All @@ -107,7 +107,7 @@ impl ServerEventAppExt for App {
.unwrap_or_else(|| {
panic!(
"message `{}` should be previously registered as a server message",
any::type_name::<E>()
ShortName::of::<E>()
)
});

Expand Down Expand Up @@ -158,7 +158,7 @@ impl ServerEvent {
) {
let messages: &mut Messages<ServerTriggerEvent<E>> = unsafe { messages.deref_mut() };
for message in messages.drain() {
debug!("triggering `{}`", any::type_name::<E>());
debug!("triggering `{}`", ShortName::of::<E>());
commands.trigger(message.event);
}
}
Expand Down
30 changes: 12 additions & 18 deletions src/shared/message/server_message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub(crate) mod message_buffer;
mod message_queue;

use core::any::{self, TypeId};
use core::any::TypeId;

use bevy::{
ecs::{component::ComponentId, entity::MapEntities},
Expand Down Expand Up @@ -184,7 +184,7 @@ impl ServerMessageAppExt for App {
.unwrap_or_else(|| {
panic!(
"message `{}` should be previously registered",
any::type_name::<M>()
ShortName::of::<M>()
)
});

Expand All @@ -195,7 +195,7 @@ impl ServerMessageAppExt for App {
.unwrap_or_else(|| {
panic!(
"message `{}` should be previously registered as a server message",
any::type_name::<M>()
ShortName::of::<M>()
)
});

Expand Down Expand Up @@ -336,10 +336,7 @@ impl ServerMessage {
// For server messages we don't track read message because
// all of them will always be drained in the local sending system.
for ToClients { message, mode } in to_messages.get_cursor().read(to_messages) {
debug!(
"sending message `{}` with `{mode:?}`",
any::type_name::<M>()
);
debug!("sending message `{}` with `{mode:?}`", ShortName::of::<M>());

if self.independent {
unsafe {
Expand Down Expand Up @@ -481,13 +478,13 @@ impl ServerMessage {
Ok(message) => {
debug!(
"writing message `{}` from queue with `{tick:?}`",
any::type_name::<M>()
ShortName::of::<M>()
);
messages.write(message);
}
Err(e) => error!(
"ignoring message `{}` from queue with `{tick:?}` that failed to deserialize: {e}",
any::type_name::<M>()
ShortName::of::<M>()
),
}
}
Expand All @@ -500,34 +497,31 @@ impl ServerMessage {
Err(e) => {
error!(
"ignoring message `{}` because it's tick failed to deserialize: {e}",
any::type_name::<M>()
ShortName::of::<M>()
);
continue;
}
};
if tick > update_tick {
debug!(
"queuing message `{}` with `{tick:?}`",
any::type_name::<M>()
);
debug!("queuing message `{}` with `{tick:?}`", ShortName::of::<M>());
queue.insert(tick, message);
continue;
} else {
debug!(
"receiving message `{}` with `{tick:?}`",
any::type_name::<M>()
ShortName::of::<M>()
);
}
}

match unsafe { self.deserialize::<M, I>(ctx, &mut message) } {
Ok(message) => {
debug!("writing message `{}`", any::type_name::<M>());
debug!("writing message `{}`", ShortName::of::<M>());
messages.write(message);
}
Err(e) => error!(
"ignoring message `{}` that failed to deserialize: {e}",
any::type_name::<M>()
ShortName::of::<M>()
),
}
}
Expand All @@ -552,7 +546,7 @@ impl ServerMessage {
let to_messages: &mut Messages<ToClients<M>> = unsafe { to_messages.deref_mut() };
let messages: &mut Messages<M> = unsafe { messages.deref_mut() };
for ToClients { message, mode } in to_messages.drain() {
debug!("writing message `{}` locally", any::type_name::<M>());
debug!("writing message `{}` locally", ShortName::of::<M>());
match mode {
SendMode::Broadcast => {
messages.write(message);
Expand Down
16 changes: 8 additions & 8 deletions src/shared/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ProtocolHasher {
pub(crate) fn replicate<R>(&mut self, priority: usize) {
debug!(
"adding replication rule `{}` with priority {priority}",
any::type_name::<R>()
ShortName::of::<R>()
);
self.hash::<R>(ProtocolPart::Replicate {
priority: priority as u64,
Expand All @@ -63,38 +63,38 @@ impl ProtocolHasher {
pub(crate) fn replicate_bundle<B>(&mut self) {
debug!(
"adding replication rule for bundle `{}`",
any::type_name::<B>()
ShortName::of::<B>()
);
self.hash::<B>(ProtocolPart::ReplicateBundle);
}

pub(crate) fn add_client_message<E>(&mut self) {
debug!("adding client message `{}`", any::type_name::<E>());
debug!("adding client message `{}`", ShortName::of::<E>());
self.hash::<E>(ProtocolPart::ClientMessage);
}

pub(crate) fn add_client_event<E>(&mut self) {
debug!("adding client event `{}`", any::type_name::<E>());
debug!("adding client event `{}`", ShortName::of::<E>());
self.hash::<E>(ProtocolPart::ClientEvent);
}

pub(crate) fn add_server_message<E>(&mut self) {
debug!("adding server message `{}`", any::type_name::<E>());
debug!("adding server message `{}`", ShortName::of::<E>());
self.hash::<E>(ProtocolPart::ServerMessage);
}

pub(crate) fn add_server_event<E>(&mut self) {
debug!("adding server event `{}`", any::type_name::<E>());
debug!("adding server event `{}`", ShortName::of::<E>());
self.hash::<E>(ProtocolPart::ServerEvent);
}

pub(crate) fn make_message_independent<E>(&mut self) {
debug!("making message `{}` independent", any::type_name::<E>());
debug!("making message `{}` independent", ShortName::of::<E>());
self.hash::<E>(ProtocolPart::IndependentMessage);
}

pub(crate) fn make_event_independent<E>(&mut self) {
debug!("making event `{}` independent", any::type_name::<E>());
debug!("making event `{}` independent", ShortName::of::<E>());
self.hash::<E>(ProtocolPart::IndependentEvent);
}

Expand Down
Loading