Switch to replicon (#80)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use bevy::prelude::*;
|
||||
use lightyear::prelude::{Connected, MessageSender};
|
||||
use bevy_replicon::prelude::{ClientId, ConnectedClient, SendMode, ToClients};
|
||||
use shared::{
|
||||
GameState, global_observer,
|
||||
protocol::{TbMapEntityId, channels::UnorderedReliableChannel, messages::DespawnTbMapEntity},
|
||||
protocol::{TbMapEntityId, messages::DespawnTbMapEntity},
|
||||
};
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
@@ -32,12 +32,14 @@ fn add_despawned_entities_to_cache(
|
||||
pub struct DespawnedTbEntityCache(pub Vec<u64>);
|
||||
|
||||
fn send_new_client_despawned_cache(
|
||||
trigger: On<Add, Connected>,
|
||||
on: On<Add, ConnectedClient>,
|
||||
cache: Res<DespawnedTbEntityCache>,
|
||||
mut send: Query<&mut MessageSender<DespawnTbMapEntity>>,
|
||||
mut send: MessageWriter<ToClients<DespawnTbMapEntity>>,
|
||||
) {
|
||||
let mut send = send.get_mut(trigger.event().entity).unwrap();
|
||||
for &id in cache.0.iter() {
|
||||
send.send::<UnorderedReliableChannel>(DespawnTbMapEntity(id));
|
||||
send.write(ToClients {
|
||||
mode: SendMode::Direct(ClientId::Client(on.entity)),
|
||||
message: DespawnTbMapEntity(id),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user