mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Stop syncing Projectile component to the client
This commit is contained in:
parent
e49cafafbf
commit
c3ac251fa8
@ -3,19 +3,25 @@ use serde_derive::{Deserialize, Serialize};
|
||||
use std::marker::PhantomData;
|
||||
use sum_type::sum_type;
|
||||
|
||||
// TODO: remove me
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum MustHaveMoreThanOneVariant {}
|
||||
|
||||
// Automatically derive From<T> for EcsResPacket
|
||||
// for each variant EcsResPacket::T(T).
|
||||
sum_type! {
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum EcsResPacket {
|
||||
Time(state::Time),
|
||||
//Time(state::Time),
|
||||
MustHaveMoreThanOneVariant(MustHaveMoreThanOneVariant),
|
||||
TimeOfDay(state::TimeOfDay),
|
||||
}
|
||||
}
|
||||
impl sync::ResPacket for EcsResPacket {
|
||||
fn apply(self, world: &specs::World) {
|
||||
match self {
|
||||
EcsResPacket::Time(time) => sync::handle_res_update(time, world),
|
||||
//EcsResPacket::Time(time) => sync::handle_res_update(time, world),
|
||||
EcsResPacket::MustHaveMoreThanOneVariant(_) => unimplemented!(),
|
||||
EcsResPacket::TimeOfDay(time_of_day) => sync::handle_res_update(time_of_day, world),
|
||||
}
|
||||
}
|
||||
@ -35,7 +41,7 @@ sum_type! {
|
||||
MountState(comp::MountState),
|
||||
Mounting(comp::Mounting),
|
||||
Mass(comp::Mass),
|
||||
Projectile(comp::Projectile),
|
||||
//Projectile(comp::Projectile),
|
||||
Gravity(comp::Gravity),
|
||||
Sticky(comp::Sticky),
|
||||
}
|
||||
@ -55,7 +61,7 @@ sum_type! {
|
||||
MountState(PhantomData<comp::MountState>),
|
||||
Mounting(PhantomData<comp::Mounting>),
|
||||
Mass(PhantomData<comp::Mass>),
|
||||
Projectile(PhantomData<comp::Projectile>),
|
||||
//Projectile(PhantomData<comp::Projectile>),
|
||||
Gravity(PhantomData<comp::Gravity>),
|
||||
Sticky(PhantomData<comp::Sticky>),
|
||||
}
|
||||
@ -74,7 +80,7 @@ impl sync::CompPacket for EcsCompPacket {
|
||||
EcsCompPacket::MountState(comp) => sync::handle_insert(comp, entity, world),
|
||||
EcsCompPacket::Mounting(comp) => sync::handle_insert(comp, entity, world),
|
||||
EcsCompPacket::Mass(comp) => sync::handle_insert(comp, entity, world),
|
||||
EcsCompPacket::Projectile(comp) => sync::handle_insert(comp, entity, world),
|
||||
//EcsCompPacket::Projectile(comp) => sync::handle_insert(comp, entity, world),
|
||||
EcsCompPacket::Gravity(comp) => sync::handle_insert(comp, entity, world),
|
||||
EcsCompPacket::Sticky(comp) => sync::handle_insert(comp, entity, world),
|
||||
}
|
||||
@ -91,7 +97,7 @@ impl sync::CompPacket for EcsCompPacket {
|
||||
EcsCompPacket::MountState(comp) => sync::handle_modify(comp, entity, world),
|
||||
EcsCompPacket::Mounting(comp) => sync::handle_modify(comp, entity, world),
|
||||
EcsCompPacket::Mass(comp) => sync::handle_modify(comp, entity, world),
|
||||
EcsCompPacket::Projectile(comp) => sync::handle_modify(comp, entity, world),
|
||||
//EcsCompPacket::Projectile(comp) => sync::handle_modify(comp, entity, world),
|
||||
EcsCompPacket::Gravity(comp) => sync::handle_modify(comp, entity, world),
|
||||
EcsCompPacket::Sticky(comp) => sync::handle_modify(comp, entity, world),
|
||||
}
|
||||
@ -110,7 +116,7 @@ impl sync::CompPacket for EcsCompPacket {
|
||||
EcsCompPhantom::MountState(_) => sync::handle_remove::<comp::MountState>(entity, world),
|
||||
EcsCompPhantom::Mounting(_) => sync::handle_remove::<comp::Mounting>(entity, world),
|
||||
EcsCompPhantom::Mass(_) => sync::handle_remove::<comp::Mass>(entity, world),
|
||||
EcsCompPhantom::Projectile(_) => sync::handle_remove::<comp::Projectile>(entity, world),
|
||||
//EcsCompPhantom::Projectile(_) => sync::handle_remove::<comp::Projectile>(entity, world),
|
||||
EcsCompPhantom::Gravity(_) => sync::handle_remove::<comp::Gravity>(entity, world),
|
||||
EcsCompPhantom::Sticky(_) => sync::handle_remove::<comp::Sticky>(entity, world),
|
||||
}
|
||||
|
@ -119,7 +119,6 @@ impl State {
|
||||
ecs.register::<comp::Mass>();
|
||||
ecs.register::<comp::Sticky>();
|
||||
ecs.register::<comp::Gravity>();
|
||||
ecs.register::<comp::Projectile>();
|
||||
|
||||
// Register components send from clients -> server
|
||||
ecs.register::<comp::Controller>();
|
||||
@ -143,9 +142,9 @@ impl State {
|
||||
ecs.register::<comp::Agent>();
|
||||
ecs.register::<comp::ForceUpdate>();
|
||||
ecs.register::<comp::InventoryUpdate>();
|
||||
ecs.register::<comp::Inventory>();
|
||||
ecs.register::<comp::Admin>();
|
||||
ecs.register::<comp::Waypoint>();
|
||||
ecs.register::<comp::Projectile>();
|
||||
|
||||
// Register synced resources used by the ECS.
|
||||
ecs.add_resource(TimeOfDay(0.0));
|
||||
@ -156,6 +155,7 @@ impl State {
|
||||
ecs.add_resource(TerrainGrid::new().unwrap());
|
||||
ecs.add_resource(BlockChange::default());
|
||||
ecs.add_resource(TerrainChanges::default());
|
||||
// TODO: only register on the server
|
||||
ecs.add_resource(EventBus::<ServerEvent>::default());
|
||||
ecs.add_resource(EventBus::<LocalEvent>::default());
|
||||
ecs.add_resource(EventBus::<SfxEventItem>::default());
|
||||
|
@ -112,17 +112,6 @@ impl<P: CompPacket> SyncPackage<P> {
|
||||
.join()
|
||||
.map(|(uid, _, _)| (*uid).into())
|
||||
.collect();
|
||||
// TODO: handle modified uid?
|
||||
//created_entities.append(&mut (uids, filter, uid_tracker.inserted()).join().map(|(uid, _, _)| uid).collect());
|
||||
// let deleted_entities = (uids.maybe(), filter, uid_tracker.removed())
|
||||
// .join()
|
||||
// Why doesn't this panic??
|
||||
// .map(|(uid, _, _)| Into::<u64>::into(*uid.unwrap()))
|
||||
// .collect::<Vec<_>>();
|
||||
//let len = deleted_entities.len();
|
||||
//if len > 0 {
|
||||
// println!("deleted {} in sync message", len);
|
||||
// }
|
||||
|
||||
Self {
|
||||
comp_updates: Vec::new(),
|
||||
|
@ -342,13 +342,14 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
|
||||
// Apply pushback
|
||||
for (pos, scale, mass, vel, _, _, physics) in (
|
||||
for (pos, scale, mass, vel, _, _, _, physics) in (
|
||||
&positions,
|
||||
scales.maybe(),
|
||||
masses.maybe(),
|
||||
&mut velocities,
|
||||
&bodies,
|
||||
!&mountings,
|
||||
!&stickies, // Can't push stickies around
|
||||
&mut physics_states,
|
||||
)
|
||||
.join()
|
||||
|
@ -1,8 +1,8 @@
|
||||
use super::SysTimer;
|
||||
use common::{
|
||||
comp::{
|
||||
Body, CanBuild, Gravity, Item, LightEmitter, Mass, MountState, Mounting, Player,
|
||||
Projectile, Scale, Stats, Sticky,
|
||||
Body, CanBuild, Gravity, Item, LightEmitter, Mass, MountState, Mounting, Player, Scale,
|
||||
Stats, Sticky,
|
||||
},
|
||||
msg::{EcsCompPacket, EcsResPacket},
|
||||
state::TimeOfDay,
|
||||
@ -16,7 +16,6 @@ use shred_derive::SystemData;
|
||||
use specs::{
|
||||
Entity as EcsEntity, Join, ReadExpect, ReadStorage, System, World, Write, WriteExpect,
|
||||
};
|
||||
use std::ops::Deref;
|
||||
use vek::*;
|
||||
|
||||
/// Always watching
|
||||
@ -54,7 +53,7 @@ pub struct TrackedComps<'a> {
|
||||
pub mass: ReadStorage<'a, Mass>,
|
||||
pub sticky: ReadStorage<'a, Sticky>,
|
||||
pub gravity: ReadStorage<'a, Gravity>,
|
||||
pub projectile: ReadStorage<'a, Projectile>,
|
||||
//pub projectile: ReadStorage<'a, Projectile>,
|
||||
}
|
||||
impl<'a> TrackedComps<'a> {
|
||||
pub fn create_entity_package(&self, entity: EcsEntity) -> EntityPackage<EcsCompPacket> {
|
||||
@ -113,10 +112,10 @@ impl<'a> TrackedComps<'a> {
|
||||
.get(entity)
|
||||
.copied()
|
||||
.map(|c| packets.push(c.into()));
|
||||
self.projectile
|
||||
.get(entity)
|
||||
.cloned()
|
||||
.map(|c| packets.push(c.into()));
|
||||
//self.projectile
|
||||
// .get(entity)
|
||||
// .cloned()
|
||||
// .map(|c| packets.push(c.into()));
|
||||
|
||||
EntityPackage(uid, packets)
|
||||
}
|
||||
@ -136,7 +135,7 @@ pub struct ReadTrackers<'a> {
|
||||
pub mass: ReadExpect<'a, UpdateTracker<Mass>>,
|
||||
pub sticky: ReadExpect<'a, UpdateTracker<Sticky>>,
|
||||
pub gravity: ReadExpect<'a, UpdateTracker<Gravity>>,
|
||||
pub projectile: ReadExpect<'a, UpdateTracker<Projectile>>,
|
||||
//pub projectile: ReadExpect<'a, UpdateTracker<Projectile>>,
|
||||
}
|
||||
impl<'a> ReadTrackers<'a> {
|
||||
pub fn create_sync_package(
|
||||
@ -146,34 +145,29 @@ impl<'a> ReadTrackers<'a> {
|
||||
deleted_entities: Vec<u64>,
|
||||
) -> SyncPackage<EcsCompPacket> {
|
||||
SyncPackage::new(&comps.uid, &self.uid, filter, deleted_entities)
|
||||
.with_component(&comps.uid, self.body.deref(), &comps.body, filter)
|
||||
.with_component(&comps.uid, self.player.deref(), &comps.player, filter)
|
||||
.with_component(&comps.uid, self.stats.deref(), &comps.stats, filter)
|
||||
.with_component(&comps.uid, self.can_build.deref(), &comps.can_build, filter)
|
||||
.with_component(&comps.uid, &*self.body, &comps.body, filter)
|
||||
.with_component(&comps.uid, &*self.player, &comps.player, filter)
|
||||
.with_component(&comps.uid, &*self.stats, &comps.stats, filter)
|
||||
.with_component(&comps.uid, &*self.can_build, &comps.can_build, filter)
|
||||
.with_component(
|
||||
&comps.uid,
|
||||
self.light_emitter.deref(),
|
||||
&*self.light_emitter,
|
||||
&comps.light_emitter,
|
||||
filter,
|
||||
)
|
||||
.with_component(&comps.uid, self.item.deref(), &comps.item, filter)
|
||||
.with_component(&comps.uid, self.scale.deref(), &comps.scale, filter)
|
||||
.with_component(&comps.uid, self.mounting.deref(), &comps.mounting, filter)
|
||||
.with_component(
|
||||
&comps.uid,
|
||||
self.mount_state.deref(),
|
||||
&comps.mount_state,
|
||||
filter,
|
||||
)
|
||||
.with_component(&comps.uid, self.mass.deref(), &comps.mass, filter)
|
||||
.with_component(&comps.uid, self.sticky.deref(), &comps.sticky, filter)
|
||||
.with_component(&comps.uid, self.gravity.deref(), &comps.gravity, filter)
|
||||
.with_component(
|
||||
&comps.uid,
|
||||
self.projectile.deref(),
|
||||
&comps.projectile,
|
||||
filter,
|
||||
)
|
||||
.with_component(&comps.uid, &*self.item, &comps.item, filter)
|
||||
.with_component(&comps.uid, &*self.scale, &comps.scale, filter)
|
||||
.with_component(&comps.uid, &*self.mounting, &comps.mounting, filter)
|
||||
.with_component(&comps.uid, &*self.mount_state, &comps.mount_state, filter)
|
||||
.with_component(&comps.uid, &*self.mass, &comps.mass, filter)
|
||||
.with_component(&comps.uid, &*self.sticky, &comps.sticky, filter)
|
||||
.with_component(&comps.uid, &*self.gravity, &comps.gravity, filter)
|
||||
//.with_component(
|
||||
// &comps.uid,
|
||||
// self.projectile.deref(),
|
||||
// &comps.projectile,
|
||||
// filter,
|
||||
//)
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +186,7 @@ pub struct WriteTrackers<'a> {
|
||||
mass: WriteExpect<'a, UpdateTracker<Mass>>,
|
||||
sticky: WriteExpect<'a, UpdateTracker<Sticky>>,
|
||||
gravity: WriteExpect<'a, UpdateTracker<Gravity>>,
|
||||
projectile: WriteExpect<'a, UpdateTracker<Projectile>>,
|
||||
//projectile: WriteExpect<'a, UpdateTracker<Projectile>>,
|
||||
}
|
||||
|
||||
fn record_changes(comps: &TrackedComps, trackers: &mut WriteTrackers) {
|
||||
@ -210,7 +204,7 @@ fn record_changes(comps: &TrackedComps, trackers: &mut WriteTrackers) {
|
||||
trackers.mass.record_changes(&comps.mass);
|
||||
trackers.sticky.record_changes(&comps.sticky);
|
||||
trackers.gravity.record_changes(&comps.gravity);
|
||||
trackers.projectile.record_changes(&comps.projectile);
|
||||
//trackers.projectile.record_changes(&comps.projectile);
|
||||
}
|
||||
|
||||
pub fn register_trackers(world: &mut World) {
|
||||
@ -227,7 +221,7 @@ pub fn register_trackers(world: &mut World) {
|
||||
world.register_tracker::<Mass>();
|
||||
world.register_tracker::<Sticky>();
|
||||
world.register_tracker::<Gravity>();
|
||||
world.register_tracker::<Projectile>();
|
||||
//world.register_tracker::<Projectile>();
|
||||
}
|
||||
|
||||
#[derive(SystemData)]
|
||||
@ -236,11 +230,11 @@ pub struct TrackedResources<'a> {
|
||||
}
|
||||
impl<'a> TrackedResources<'a> {
|
||||
pub fn create_res_sync_package(&self) -> ResSyncPackage<EcsResPacket> {
|
||||
ResSyncPackage::new().with_res(self.time_of_day.deref())
|
||||
ResSyncPackage::new().with_res(&*self.time_of_day)
|
||||
}
|
||||
/// Create state package with resources included
|
||||
pub fn state_package<C: CompPacket>(&self) -> StatePackage<C, EcsResPacket> {
|
||||
StatePackage::new().with_res(self.time_of_day.deref())
|
||||
StatePackage::new().with_res(&*self.time_of_day)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ impl<'a> System<'a> for Sys {
|
||||
.reduce_or()
|
||||
{
|
||||
// Update current chunk
|
||||
subscription.fuzzy_chunk = dbg!(Vec2::<f32>::from(pos.0))
|
||||
subscription.fuzzy_chunk = Vec2::<f32>::from(pos.0)
|
||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32);
|
||||
// Use the largest side length as our chunk size
|
||||
let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32;
|
||||
@ -173,7 +173,6 @@ impl<'a> System<'a> for Sys {
|
||||
// Send client intial info about the entities in this region if it was not
|
||||
// already within the set of subscribed regions
|
||||
if subscription.regions.insert(key.clone()) {
|
||||
let mut counter = 0;
|
||||
if let Some(region) = region_map.get(key) {
|
||||
for (uid, pos, vel, ori, character_state, _, entity) in (
|
||||
&uids,
|
||||
@ -187,7 +186,6 @@ impl<'a> System<'a> for Sys {
|
||||
.join()
|
||||
.filter(|(_, _, _, _, _, _, e)| *e != client_entity)
|
||||
{
|
||||
counter += 1;
|
||||
// Send message to create entity and tracked components
|
||||
client.notify(ServerMsg::CreateEntity(
|
||||
tracked_comps.create_entity_package(entity),
|
||||
|
Loading…
Reference in New Issue
Block a user