mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
don't insert event busses on client
This commit is contained in:
parent
e651b9b2ac
commit
d75889ed75
@ -1982,13 +1982,6 @@ impl Client {
|
||||
&self.connected_server_constants,
|
||||
|_, _| {},
|
||||
);
|
||||
// TODO: TODO
|
||||
// TODO: avoid emitting these in the first place
|
||||
// let _ = self
|
||||
// .state
|
||||
// .ecs()
|
||||
// .fetch::<EventBus<common::event::ServerFrontendEvent>>()
|
||||
// .recv_all();
|
||||
|
||||
// TODO: avoid emitting these in the first place OR actually use outcomes
|
||||
// generated locally on the client (if they can be deduplicated from
|
||||
|
@ -556,35 +556,35 @@ macro_rules! event_emitters {
|
||||
$(
|
||||
#[derive(specs::SystemData)]
|
||||
pub struct $read_data<'a> {
|
||||
$($ev_ident: specs::Read<'a, $crate::event::EventBus<$ty>>),+
|
||||
$($ev_ident: Option<specs::Read<'a, $crate::event::EventBus<$ty>>>),+
|
||||
}
|
||||
|
||||
impl<'a> $read_data<'a> {
|
||||
#[allow(unused)]
|
||||
pub fn get_emitters(&self) -> $emitters {
|
||||
$emitters {
|
||||
$($ev_ident: self.$ev_ident.emitter()),+
|
||||
$($ev_ident: self.$ev_ident.as_ref().map(|e| e.emitter())),+
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct $emitters<'a> {
|
||||
$($ev_ident: $crate::event::Emitter<'a, $ty>),+
|
||||
$($ev_ident: Option<$crate::event::Emitter<'a, $ty>>),+
|
||||
}
|
||||
|
||||
impl<'a> $emitters<'a> {
|
||||
#[allow(unused)]
|
||||
pub fn append(&mut self, mut other: Self) {
|
||||
$(
|
||||
self.$ev_ident.append(&mut other.$ev_ident.events);
|
||||
self.$ev_ident.as_mut().zip(other.$ev_ident).map(|(a, mut b)| a.append(&mut b.events));
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
$(
|
||||
impl<'a> $crate::event::EmitExt<$ty> for $emitters<'a> {
|
||||
fn emit(&mut self, event: $ty) { self.$ev_ident.emit(event) }
|
||||
fn emit_many(&mut self, events: impl IntoIterator<Item = $ty>) { self.$ev_ident.emit_many(events) }
|
||||
fn emit(&mut self, event: $ty) { self.$ev_ident.as_mut().map(|e| e.emit(event)); }
|
||||
fn emit_many(&mut self, events: impl IntoIterator<Item = $ty>) { self.$ev_ident.as_mut().map(|e| e.emit_many(events)); }
|
||||
}
|
||||
)+
|
||||
)+
|
||||
|
@ -8,7 +8,7 @@ use common::uid::IdMaps;
|
||||
use common::{
|
||||
calendar::Calendar,
|
||||
comp,
|
||||
event::{register_event_busses, EventBus, LocalEvent},
|
||||
event::{EventBus, LocalEvent},
|
||||
link::Is,
|
||||
mounting::{Mount, Rider, VolumeRider, VolumeRiders},
|
||||
outcome::Outcome,
|
||||
@ -331,7 +331,6 @@ impl State {
|
||||
ecs.insert(SlowJobPool::new(slow_limit, 10_000, thread_pool));
|
||||
|
||||
// TODO: only register on the server
|
||||
register_event_busses(&mut ecs);
|
||||
ecs.insert(comp::group::GroupManager::default());
|
||||
ecs.insert(SysMetrics::default());
|
||||
ecs.insert(PhysicsMetrics::default());
|
||||
|
@ -7,7 +7,8 @@ use common::{
|
||||
PosVelOriDefer, PreviousPhysCache, Projectile, Scale, Stats, Sticky, Vel,
|
||||
},
|
||||
consts::{AIR_DENSITY, FRIC_GROUND, GRAVITY},
|
||||
event::{EventBus, LandOnGroundEvent},
|
||||
event::{EmitExt, EventBus, LandOnGroundEvent},
|
||||
event_emitters,
|
||||
link::Is,
|
||||
mounting::{Rider, VolumeRider},
|
||||
outcome::Outcome,
|
||||
@ -123,6 +124,12 @@ fn calc_z_limit(char_state_maybe: Option<&CharacterState>, collider: &Collider)
|
||||
collider.get_z_limits(modifier)
|
||||
}
|
||||
|
||||
event_emitters! {
|
||||
struct Events[Emitters] {
|
||||
land_on_ground: LandOnGroundEvent,
|
||||
}
|
||||
}
|
||||
|
||||
/// This system applies forces and calculates new positions and velocities.
|
||||
#[derive(Default)]
|
||||
pub struct Sys;
|
||||
@ -130,10 +137,10 @@ pub struct Sys;
|
||||
#[derive(SystemData)]
|
||||
pub struct PhysicsRead<'a> {
|
||||
entities: Entities<'a>,
|
||||
events: Events<'a>,
|
||||
uids: ReadStorage<'a, Uid>,
|
||||
terrain: ReadExpect<'a, TerrainGrid>,
|
||||
dt: Read<'a, DeltaTime>,
|
||||
land_on_ground_event: Read<'a, EventBus<LandOnGroundEvent>>,
|
||||
game_mode: ReadExpect<'a, GameMode>,
|
||||
scales: ReadStorage<'a, Scale>,
|
||||
stickies: ReadStorage<'a, Sticky>,
|
||||
@ -1364,16 +1371,16 @@ impl<'a> PhysicsData<'a> {
|
||||
}
|
||||
drop(guard);
|
||||
|
||||
let mut event_emitter = read.land_on_ground_event.emitter();
|
||||
land_on_grounds
|
||||
.into_iter()
|
||||
.for_each(|(entity, vel, surface_normal)| {
|
||||
event_emitter.emit(LandOnGroundEvent {
|
||||
let mut emitters = read.events.get_emitters();
|
||||
emitters.emit_many(
|
||||
land_on_grounds
|
||||
.into_iter()
|
||||
.map(|(entity, vel, surface_normal)| LandOnGroundEvent {
|
||||
entity,
|
||||
vel: vel.0,
|
||||
surface_normal,
|
||||
});
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
fn update_cached_spatial_grid(&mut self) {
|
||||
|
@ -52,8 +52,8 @@ use common_state::{AreasContainer, BlockChange, NoDurabilityArea};
|
||||
use hashbrown::HashSet;
|
||||
use rand::Rng;
|
||||
use specs::{
|
||||
shred, DispatcherBuilder, Entities, Entity as EcsEntity, Entity, Join, LendJoin, ReadExpect,
|
||||
ReadStorage, SystemData, Write, WriteExpect, WriteStorage,
|
||||
shred, DispatcherBuilder, Entities, Entity as EcsEntity, Entity, Join, LendJoin, Read,
|
||||
ReadExpect, ReadStorage, SystemData, Write, WriteExpect, WriteStorage,
|
||||
};
|
||||
use std::{collections::HashMap, iter, sync::Arc, time::Duration};
|
||||
use tracing::{debug, warn};
|
||||
@ -124,16 +124,16 @@ impl ServerEvent for PoiseChangeEvent {
|
||||
impl ServerEvent for HealthChangeEvent {
|
||||
type SystemData<'a> = (
|
||||
Entities<'a>,
|
||||
Read<'a, EventBus<Outcome>>,
|
||||
ReadStorage<'a, Pos>,
|
||||
ReadStorage<'a, Uid>,
|
||||
WriteStorage<'a, Agent>,
|
||||
WriteStorage<'a, Health>,
|
||||
WriteExpect<'a, EventBus<Outcome>>,
|
||||
);
|
||||
|
||||
fn handle(
|
||||
events: impl ExactSizeIterator<Item = Self>,
|
||||
(entities, positions, uids, mut agents, mut healths, outcomes): Self::SystemData<'_>,
|
||||
(entities, outcomes, positions, uids, mut agents, mut healths): Self::SystemData<'_>,
|
||||
) {
|
||||
let mut outcomes_emitter = outcomes.emitter();
|
||||
for ev in events {
|
||||
@ -272,17 +272,17 @@ fn handle_exp_gain(
|
||||
pub struct DestroyEventData<'a> {
|
||||
entities: Entities<'a>,
|
||||
rtsim: WriteExpect<'a, RtSim>,
|
||||
id_maps: ReadExpect<'a, IdMaps>,
|
||||
id_maps: Read<'a, IdMaps>,
|
||||
msm: ReadExpect<'a, MaterialStatManifest>,
|
||||
ability_map: ReadExpect<'a, AbilityMap>,
|
||||
time: ReadExpect<'a, Time>,
|
||||
time: Read<'a, Time>,
|
||||
world: ReadExpect<'a, Arc<World>>,
|
||||
index: ReadExpect<'a, world::IndexOwned>,
|
||||
areas_container: ReadExpect<'a, AreasContainer<NoDurabilityArea>>,
|
||||
outcomes: ReadExpect<'a, EventBus<Outcome>>,
|
||||
create_item_drop: ReadExpect<'a, EventBus<CreateItemDropEvent>>,
|
||||
delete_event: ReadExpect<'a, EventBus<DeleteEvent>>,
|
||||
chat_events: ReadExpect<'a, EventBus<ChatEvent>>,
|
||||
areas_container: Read<'a, AreasContainer<NoDurabilityArea>>,
|
||||
outcomes: Read<'a, EventBus<Outcome>>,
|
||||
create_item_drop: Read<'a, EventBus<CreateItemDropEvent>>,
|
||||
delete_event: Read<'a, EventBus<DeleteEvent>>,
|
||||
chat_events: Read<'a, EventBus<ChatEvent>>,
|
||||
melees: WriteStorage<'a, comp::Melee>,
|
||||
beams: WriteStorage<'a, comp::Beam>,
|
||||
skill_sets: WriteStorage<'a, SkillSet>,
|
||||
@ -745,7 +745,7 @@ impl ServerEvent for DeleteEvent {
|
||||
Entities<'a>,
|
||||
Write<'a, comp::group::GroupManager>,
|
||||
Write<'a, Trades>,
|
||||
ReadExpect<'a, IdMaps>,
|
||||
Read<'a, IdMaps>,
|
||||
WriteStorage<'a, Group>,
|
||||
WriteStorage<'a, Agent>,
|
||||
ReadStorage<'a, Uid>,
|
||||
@ -819,10 +819,10 @@ impl ServerEvent for DeleteEvent {
|
||||
|
||||
impl ServerEvent for LandOnGroundEvent {
|
||||
type SystemData<'a> = (
|
||||
ReadExpect<'a, Time>,
|
||||
Read<'a, Time>,
|
||||
ReadExpect<'a, MaterialStatManifest>,
|
||||
ReadExpect<'a, EventBus<HealthChangeEvent>>,
|
||||
ReadExpect<'a, EventBus<PoiseChangeEvent>>,
|
||||
Read<'a, EventBus<HealthChangeEvent>>,
|
||||
Read<'a, EventBus<PoiseChangeEvent>>,
|
||||
ReadStorage<'a, PhysicsState>,
|
||||
ReadStorage<'a, CharacterState>,
|
||||
ReadStorage<'a, comp::Mass>,
|
||||
@ -933,7 +933,7 @@ impl ServerEvent for LandOnGroundEvent {
|
||||
|
||||
impl ServerEvent for RespawnEvent {
|
||||
type SystemData<'a> = (
|
||||
ReadExpect<'a, SpawnPoint>,
|
||||
Read<'a, SpawnPoint>,
|
||||
WriteStorage<'a, Health>,
|
||||
WriteStorage<'a, comp::Combo>,
|
||||
WriteStorage<'a, Pos>,
|
||||
@ -995,15 +995,15 @@ event_emitters! {
|
||||
impl ServerEvent for ExplosionEvent {
|
||||
type SystemData<'a> = (
|
||||
Entities<'a>,
|
||||
WriteExpect<'a, BlockChange>,
|
||||
ReadExpect<'a, Settings>,
|
||||
ReadExpect<'a, Time>,
|
||||
ReadExpect<'a, IdMaps>,
|
||||
ReadExpect<'a, CachedSpatialGrid>,
|
||||
Write<'a, BlockChange>,
|
||||
Read<'a, Settings>,
|
||||
Read<'a, Time>,
|
||||
Read<'a, IdMaps>,
|
||||
Read<'a, CachedSpatialGrid>,
|
||||
ReadExpect<'a, TerrainGrid>,
|
||||
ReadExpect<'a, MaterialStatManifest>,
|
||||
ReadExplosionEvents<'a>,
|
||||
ReadExpect<'a, EventBus<Outcome>>,
|
||||
Read<'a, EventBus<Outcome>>,
|
||||
ReadStorage<'a, Group>,
|
||||
ReadStorage<'a, Auras>,
|
||||
ReadStorage<'a, Pos>,
|
||||
@ -1502,7 +1502,7 @@ impl ServerEvent for BonkEvent {
|
||||
type SystemData<'a> = (
|
||||
Write<'a, BlockChange>,
|
||||
ReadExpect<'a, TerrainGrid>,
|
||||
ReadExpect<'a, EventBus<CreateObjectEvent>>,
|
||||
Read<'a, EventBus<CreateObjectEvent>>,
|
||||
);
|
||||
|
||||
fn handle(
|
||||
@ -1592,7 +1592,7 @@ impl ServerEvent for AuraEvent {
|
||||
|
||||
impl ServerEvent for BuffEvent {
|
||||
type SystemData<'a> = (
|
||||
ReadExpect<'a, Time>,
|
||||
Read<'a, Time>,
|
||||
WriteStorage<'a, comp::Buffs>,
|
||||
ReadStorage<'a, Body>,
|
||||
ReadStorage<'a, Health>,
|
||||
@ -1696,8 +1696,8 @@ impl ServerEvent for EnergyChangeEvent {
|
||||
|
||||
impl ServerEvent for ComboChangeEvent {
|
||||
type SystemData<'a> = (
|
||||
ReadExpect<'a, Time>,
|
||||
ReadExpect<'a, EventBus<Outcome>>,
|
||||
Read<'a, Time>,
|
||||
Read<'a, EventBus<Outcome>>,
|
||||
WriteStorage<'a, comp::Combo>,
|
||||
ReadStorage<'a, Uid>,
|
||||
);
|
||||
@ -1723,9 +1723,9 @@ impl ServerEvent for ComboChangeEvent {
|
||||
|
||||
impl ServerEvent for ParryHookEvent {
|
||||
type SystemData<'a> = (
|
||||
ReadExpect<'a, Time>,
|
||||
ReadExpect<'a, EventBus<EnergyChangeEvent>>,
|
||||
ReadExpect<'a, EventBus<BuffEvent>>,
|
||||
Read<'a, Time>,
|
||||
Read<'a, EventBus<EnergyChangeEvent>>,
|
||||
Read<'a, EventBus<BuffEvent>>,
|
||||
WriteStorage<'a, CharacterState>,
|
||||
ReadStorage<'a, Uid>,
|
||||
ReadStorage<'a, Stats>,
|
||||
@ -1792,7 +1792,7 @@ impl ServerEvent for ParryHookEvent {
|
||||
|
||||
impl ServerEvent for TeleportToEvent {
|
||||
type SystemData<'a> = (
|
||||
ReadExpect<'a, IdMaps>,
|
||||
Read<'a, IdMaps>,
|
||||
WriteStorage<'a, Pos>,
|
||||
WriteStorage<'a, comp::ForceUpdate>,
|
||||
);
|
||||
@ -1826,12 +1826,12 @@ impl ServerEvent for EntityAttackedHookEvent {
|
||||
type SystemData<'a> = (
|
||||
Entities<'a>,
|
||||
Write<'a, Trades>,
|
||||
ReadExpect<'a, IdMaps>,
|
||||
ReadExpect<'a, Time>,
|
||||
ReadExpect<'a, EventBus<BuffEvent>>,
|
||||
ReadExpect<'a, EventBus<ComboChangeEvent>>,
|
||||
ReadExpect<'a, EventBus<KnockbackEvent>>,
|
||||
ReadExpect<'a, EventBus<Outcome>>,
|
||||
Read<'a, IdMaps>,
|
||||
Read<'a, Time>,
|
||||
Read<'a, EventBus<BuffEvent>>,
|
||||
Read<'a, EventBus<ComboChangeEvent>>,
|
||||
Read<'a, EventBus<KnockbackEvent>>,
|
||||
Read<'a, EventBus<Outcome>>,
|
||||
WriteStorage<'a, CharacterState>,
|
||||
WriteStorage<'a, Poise>,
|
||||
WriteStorage<'a, Agent>,
|
||||
@ -2089,7 +2089,7 @@ impl ServerEvent for RemoveLightEmitterEvent {
|
||||
|
||||
impl ServerEvent for TeleportToPositionEvent {
|
||||
type SystemData<'a> = (
|
||||
ReadExpect<'a, IdMaps>,
|
||||
Read<'a, IdMaps>,
|
||||
WriteStorage<'a, Is<VolumeRider>>,
|
||||
WriteStorage<'a, Pos>,
|
||||
WriteStorage<'a, comp::ForceUpdate>,
|
||||
@ -2131,7 +2131,7 @@ impl ServerEvent for TeleportToPositionEvent {
|
||||
|
||||
impl ServerEvent for StartTeleportingEvent {
|
||||
type SystemData<'a> = (
|
||||
ReadExpect<'a, Time>,
|
||||
Read<'a, Time>,
|
||||
WriteStorage<'a, comp::Teleporting>,
|
||||
ReadStorage<'a, Pos>,
|
||||
ReadStorage<'a, comp::Object>,
|
||||
|
@ -10,7 +10,7 @@ use common::{
|
||||
uid::{IdMaps, Uid},
|
||||
};
|
||||
use common_net::msg::ServerGeneral;
|
||||
use specs::{world::Entity, Entities, ReadExpect, ReadStorage, WriteExpect, WriteStorage};
|
||||
use specs::{world::Entity, Entities, Read, ReadStorage, Write, WriteStorage};
|
||||
|
||||
use super::ServerEvent;
|
||||
|
||||
@ -111,8 +111,8 @@ pub fn update_map_markers<'a>(
|
||||
impl ServerEvent for GroupManipEvent {
|
||||
type SystemData<'a> = (
|
||||
Entities<'a>,
|
||||
WriteExpect<'a, GroupManager>,
|
||||
ReadExpect<'a, IdMaps>,
|
||||
Write<'a, GroupManager>,
|
||||
Read<'a, IdMaps>,
|
||||
WriteStorage<'a, Group>,
|
||||
ReadStorage<'a, Client>,
|
||||
ReadStorage<'a, Uid>,
|
||||
|
@ -1,8 +1,8 @@
|
||||
use hashbrown::HashSet;
|
||||
use rand::{seq::IteratorRandom, Rng};
|
||||
use specs::{
|
||||
join::Join, shred, DispatcherBuilder, Entities, Entity as EcsEntity, ReadExpect, ReadStorage,
|
||||
SystemData, WriteExpect, WriteStorage,
|
||||
join::Join, shred, DispatcherBuilder, Entities, Entity as EcsEntity, Read, ReadExpect,
|
||||
ReadStorage, SystemData, Write, WriteStorage,
|
||||
};
|
||||
use tracing::{debug, error, warn};
|
||||
use vek::{Rgb, Vec3};
|
||||
@ -77,11 +77,11 @@ event_emitters! {
|
||||
pub struct InventoryManipData<'a> {
|
||||
entities: Entities<'a>,
|
||||
events: Events<'a>,
|
||||
block_change: WriteExpect<'a, common_state::BlockChange>,
|
||||
trades: WriteExpect<'a, Trades>,
|
||||
block_change: Write<'a, common_state::BlockChange>,
|
||||
trades: Write<'a, Trades>,
|
||||
terrain: ReadExpect<'a, common::terrain::TerrainGrid>,
|
||||
id_maps: ReadExpect<'a, IdMaps>,
|
||||
time: ReadExpect<'a, Time>,
|
||||
id_maps: Read<'a, IdMaps>,
|
||||
time: Read<'a, Time>,
|
||||
ability_map: ReadExpect<'a, AbilityMap>,
|
||||
msm: ReadExpect<'a, MaterialStatManifest>,
|
||||
inventories: WriteStorage<'a, comp::Inventory>,
|
||||
|
@ -19,7 +19,7 @@ use common::{
|
||||
};
|
||||
use common_net::msg::{InviteAnswer, ServerGeneral};
|
||||
use specs::{
|
||||
shred, DispatcherBuilder, Entities, Entity, ReadExpect, ReadStorage, SystemData, WriteExpect,
|
||||
shred, DispatcherBuilder, Entities, Entity, Read, ReadExpect, ReadStorage, SystemData, Write,
|
||||
WriteStorage,
|
||||
};
|
||||
use std::time::{Duration, Instant};
|
||||
@ -37,10 +37,10 @@ pub(super) fn register_event_systems(builder: &mut DispatcherBuilder) {
|
||||
|
||||
impl ServerEvent for InitiateInviteEvent {
|
||||
type SystemData<'a> = (
|
||||
WriteExpect<'a, Trades>,
|
||||
ReadExpect<'a, Settings>,
|
||||
ReadExpect<'a, IdMaps>,
|
||||
ReadExpect<'a, GroupManager>,
|
||||
Write<'a, Trades>,
|
||||
Read<'a, Settings>,
|
||||
Read<'a, IdMaps>,
|
||||
Read<'a, GroupManager>,
|
||||
WriteStorage<'a, PendingInvites>,
|
||||
WriteStorage<'a, Agent>,
|
||||
WriteStorage<'a, Invite>,
|
||||
@ -215,10 +215,10 @@ impl ServerEvent for InitiateInviteEvent {
|
||||
#[derive(SystemData)]
|
||||
pub struct InviteResponseData<'a> {
|
||||
entities: Entities<'a>,
|
||||
group_manager: WriteExpect<'a, GroupManager>,
|
||||
trades: WriteExpect<'a, Trades>,
|
||||
group_manager: Write<'a, GroupManager>,
|
||||
trades: Write<'a, Trades>,
|
||||
index: ReadExpect<'a, world::IndexOwned>,
|
||||
id_maps: ReadExpect<'a, IdMaps>,
|
||||
id_maps: Read<'a, IdMaps>,
|
||||
invites: WriteStorage<'a, Invite>,
|
||||
pending_invites: WriteStorage<'a, PendingInvites>,
|
||||
groups: WriteStorage<'a, Group>,
|
||||
|
@ -328,6 +328,7 @@ impl Server {
|
||||
}
|
||||
},
|
||||
);
|
||||
register_event_busses(state.ecs_mut());
|
||||
state.ecs_mut().insert(battlemode_buffer);
|
||||
state.ecs_mut().insert(settings.clone());
|
||||
state.ecs_mut().insert(editable_settings);
|
||||
|
@ -22,7 +22,7 @@ impl<'a> System<'a> for Sys {
|
||||
type SystemData = (
|
||||
Entities<'a>,
|
||||
Read<'a, EventBus<ClientDisconnectEvent>>,
|
||||
ReadExpect<'a, EventBus<ChunkSendEntry>>,
|
||||
Read<'a, EventBus<ChunkSendEntry>>,
|
||||
ReadExpect<'a, TerrainGrid>,
|
||||
ReadExpect<'a, Lod>,
|
||||
ReadExpect<'a, NetworkRequestMetrics>,
|
||||
|
@ -56,7 +56,7 @@ impl<'a> System<'a> for Sys {
|
||||
Write<'a, Option<WeatherJob>>,
|
||||
WriteExpect<'a, WeatherGrid>,
|
||||
WriteExpect<'a, SlowJobPool>,
|
||||
ReadExpect<'a, EventBus<Outcome>>,
|
||||
Read<'a, EventBus<Outcome>>,
|
||||
ReadExpect<'a, Arc<World>>,
|
||||
ReadStorage<'a, Client>,
|
||||
ReadStorage<'a, comp::Pos>,
|
||||
|
Loading…
Reference in New Issue
Block a user