Don't immediately send heartbeat
All checks were successful
CI / Formatting (push) Successful in 1m11s
All checks were successful
CI / Formatting (push) Successful in 1m11s
This commit is contained in:
parent
591cfee715
commit
e58629c2f1
5 changed files with 50 additions and 46 deletions
|
@ -3,40 +3,35 @@ use std::{collections::HashMap, net::SocketAddr, time::Duration};
|
|||
use bevy::prelude::*;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct Timing {
|
||||
timestamp: Option<Duration>,
|
||||
}
|
||||
use super::packet::{OutboundPacket, Packet};
|
||||
|
||||
#[derive(Component, Debug, Default)]
|
||||
pub struct PeerSendTiming(Timing);
|
||||
pub struct PeerSendTiming(Duration);
|
||||
|
||||
impl PeerSendTiming {
|
||||
pub fn update(&mut self, time: &Res<Time>) {
|
||||
self.0.timestamp = Some(time.elapsed())
|
||||
self.0 = time.elapsed()
|
||||
}
|
||||
|
||||
pub fn timestamp(&self) -> Option<Duration> {
|
||||
self.0.timestamp
|
||||
pub fn time(&self) -> Duration {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Debug, Default)]
|
||||
pub struct PeerReceiveTiming(Timing);
|
||||
pub struct PeerReceiveTiming(Option<Duration>);
|
||||
|
||||
impl PeerReceiveTiming {
|
||||
pub fn new(time: &Res<Time>) -> Self {
|
||||
Self(Timing {
|
||||
timestamp: Some(time.elapsed()),
|
||||
})
|
||||
Self(Some(time.elapsed()))
|
||||
}
|
||||
|
||||
pub fn update(&mut self, time: &Res<Time>) {
|
||||
self.0.timestamp = Some(time.elapsed())
|
||||
self.0 = Some(time.elapsed())
|
||||
}
|
||||
|
||||
pub fn timestamp(&self) -> Option<Duration> {
|
||||
self.0.timestamp
|
||||
pub fn time(&self) -> Option<Duration> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,3 +125,12 @@ pub fn handle_peer_change(
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_new_peer(
|
||||
new_peers: Query<&Peer, Added<Peer>>,
|
||||
mut outbound: EventWriter<OutboundPacket>,
|
||||
) {
|
||||
for peer in new_peers {
|
||||
outbound.write(OutboundPacket(Packet::new(Vec::new(), peer.uuid)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue