fix: bugs in new server ecs systems fixed

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

View File

@ -809,7 +809,7 @@ impl Server {
.collect::<Vec<_>>()
};
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();

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
.as_ref()
.map(|key| !regions.contains(key))
.unwrap_or(true)
&& *client_entity != entity
// Client doesn't need to know about itself
{
send_initial_unsynced_components(
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
// - check if in hashset (hash calc) if not add it
let mut regions_to_remove = Vec::new();
for (client, subscription, pos, vd) in
(&mut clients, &mut subscriptions, &positions, &players)
.join()
.filter_map(|(c, s, pos, player)| player.view_distance.map(|v| (c, s, pos, v)))
for (client, subscription, pos, vd, client_entity) in (
&mut clients,
&mut subscriptions,
&positions,
&players,
&entities,
)
.join()
.filter_map(|(c, s, pos, player, e)| player.view_distance.map(|v| (c, s, pos, v, e)))
{
let chunk = (Vec2::<f32>::from(pos.0))
.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
if subscription.regions.insert(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,
&positions,
velocities.maybe(),
orientations.maybe(),
character_states.maybe(),
region.entities(),
&entities,
)
.join()
.filter(|(_, _, _, _, _, _, e)| *e != client_entity)
{
super::entity_sync::send_initial_unsynced_components(
client,

View File

@ -145,8 +145,8 @@ impl<'a> System<'a> for Sys {
terrain
.iter()
.map(|(k, _)| k)
// Don't 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)
// Don't check every chunk every tick (spread over 16 ticks)
.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
.chain(chunk_generator.pending_chunks())
.for_each(|chunk_key| {