Crates.io | bevy_stokes |
lib.rs | bevy_stokes |
version | 0.1.0-alpha.2 |
source | src |
created_at | 2022-02-15 05:12:08.565396 |
updated_at | 2022-02-18 12:12:28.521464 |
description | A bevy plugin providing a thin and ergonomic wrapper around laminar. |
homepage | https://github.com/hlb8122/bevy_stokes |
repository | https://github.com/hlb8122/bevy_stokes |
max_upload_size | |
id | 532569 |
size | 97,927 |
A bevy plugin providing a thin and ergonomic wrapper around laminar.
fn setup(mut commands: Commands) {
let addr: SocketAddr = PING_ADDR.parse().unwrap();
let socket_bundle = bind(addr, Duration::from_millis(10)).unwrap();
commands.spawn_bundle(socket_bundle);
}
fn ping(mut socket_query: Query<&mut SendQueue, With<SocketMarker>>) {
let mut packet_queue = socket_query.single_mut();
let ping = Packet::reliable_unordered(PONG_ADDR.parse().unwrap(), b"DEADBEEF".to_vec());
packet_queue.send(ping);
info!("sent ping");
}
fn pong(mut connection_query: Query<&mut ReceiveQueue, With<ConnectionMarker>>) {
if let Ok(mut queue) = connection_query.get_single_mut() {
for _ in queue.drain() {
info!("received pong");
}
}
}
fn setup(mut commands: Commands) {
let addr: SocketAddr = PONG_ADDR.parse().unwrap();
let socket_bundle = bind(addr, Duration::from_millis(10)).unwrap();
commands.spawn_bundle(socket_bundle);
}
fn pong(
mut socket_query: Query<&mut SendQueue, With<SocketMarker>>,
mut connection_query: Query<
(&SocketId, &ConnectionAddress, &mut ReceiveQueue),
With<ConnectionMarker>,
>,
) {
if let Ok((socket_id, conn_addr, mut queue)) = connection_query.get_single_mut() {
for ping in queue.drain() {
info!("received ping");
let mut packet_queue = socket_query.get_mut(socket_id.0).unwrap();
let pong = Packet::reliable_unordered(conn_addr.0, ping.payload().to_vec());
packet_queue.send(pong);
info!("returned pong");
}
}
}