fix: bugs in new server ecs systems fixed

This commit is contained in:
Imbris 2019-10-25 22:00:30 -04:00
parent 572196ed10
commit fd06a0a7bf
4 changed files with 18 additions and 9 deletions

View File

@ -809,7 +809,7 @@ impl Server {
.collect::<Vec<_>>() .collect::<Vec<_>>()
}; };
for entity in to_delete { for entity in to_delete {
let _ = self.state.ecs_mut().delete_entity(entity); let _ = self.state.ecs_mut().delete_entity_synced(entity);
} }
let before_tick_7 = Instant::now(); let before_tick_7 = Instant::now();

View File

@ -105,11 +105,13 @@ impl<'a> System<'a> for Sys {
}) })
}) })
{ {
for (client, regions, _, _) in &mut subscribers { for (client, regions, client_entity, _) in &mut subscribers {
if maybe_key if maybe_key
.as_ref() .as_ref()
.map(|key| !regions.contains(key)) .map(|key| !regions.contains(key))
.unwrap_or(true) .unwrap_or(true)
&& *client_entity != entity
// Client doesn't need to know about itself
{ {
send_initial_unsynced_components( send_initial_unsynced_components(
client, client,

View File

@ -58,10 +58,15 @@ impl<'a> System<'a> for Sys {
// 7. Determine list of regions that are in range and iterate through it // 7. Determine list of regions that are in range and iterate through it
// - check if in hashset (hash calc) if not add it // - check if in hashset (hash calc) if not add it
let mut regions_to_remove = Vec::new(); let mut regions_to_remove = Vec::new();
for (client, subscription, pos, vd) in for (client, subscription, pos, vd, client_entity) in (
(&mut clients, &mut subscriptions, &positions, &players) &mut clients,
&mut subscriptions,
&positions,
&players,
&entities,
)
.join() .join()
.filter_map(|(c, s, pos, player)| player.view_distance.map(|v| (c, s, pos, v))) .filter_map(|(c, s, pos, player, e)| player.view_distance.map(|v| (c, s, pos, v, e)))
{ {
let chunk = (Vec2::<f32>::from(pos.0)) let chunk = (Vec2::<f32>::from(pos.0))
.map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32); .map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32);
@ -137,15 +142,17 @@ impl<'a> System<'a> for Sys {
// Send client intial info about the entities in this region // Send client intial info about the entities in this region
if subscription.regions.insert(key) { if subscription.regions.insert(key) {
if let Some(region) = region_map.get(key) { if let Some(region) = region_map.get(key) {
for (uid, pos, vel, ori, character_state, _) in ( for (uid, pos, vel, ori, character_state, _, _) in (
&uids, &uids,
&positions, &positions,
velocities.maybe(), velocities.maybe(),
orientations.maybe(), orientations.maybe(),
character_states.maybe(), character_states.maybe(),
region.entities(), region.entities(),
&entities,
) )
.join() .join()
.filter(|(_, _, _, _, _, _, e)| *e != client_entity)
{ {
super::entity_sync::send_initial_unsynced_components( super::entity_sync::send_initial_unsynced_components(
client, client,

View File

@ -145,8 +145,8 @@ impl<'a> System<'a> for Sys {
terrain terrain
.iter() .iter()
.map(|(k, _)| k) .map(|(k, _)| k)
// Don't every chunk every tick (spread over 16 ticks) // Don't check every chunk every tick (spread over 16 ticks)
.filter(|k| k.x.abs() as u64 % 4 + k.y.abs() as u64 % 8 * 4 == tick.0 % 16) .filter(|k| k.x.abs() as u64 % 4 + (k.y.abs() as u64 % 4) * 4 == tick.0 % 16)
// There shouldn't be to many pending chunks so we will just check them all // There shouldn't be to many pending chunks so we will just check them all
.chain(chunk_generator.pending_chunks()) .chain(chunk_generator.pending_chunks())
.for_each(|chunk_key| { .for_each(|chunk_key| {