mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Removed NPCs that are outside the VD
This commit is contained in:
parent
b5d10bfb3e
commit
6ff75dcf0b
@ -19,8 +19,8 @@ use common::{
|
|||||||
net::PostOffice,
|
net::PostOffice,
|
||||||
state::{State, TimeOfDay, Uid},
|
state::{State, TimeOfDay, Uid},
|
||||||
terrain::{block::Block, TerrainChunk, TerrainChunkSize, TerrainMap},
|
terrain::{block::Block, TerrainChunk, TerrainChunkSize, TerrainMap},
|
||||||
vol::VolSize,
|
|
||||||
vol::Vox,
|
vol::Vox,
|
||||||
|
vol::{ReadVol, VolSize},
|
||||||
};
|
};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
@ -363,6 +363,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync changed blocks
|
// Sync changed blocks
|
||||||
let msg =
|
let msg =
|
||||||
ServerMsg::TerrainBlockUpdates(self.state.terrain_changes().modified_blocks.clone());
|
ServerMsg::TerrainBlockUpdates(self.state.terrain_changes().modified_blocks.clone());
|
||||||
@ -377,6 +378,23 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove NPCs that are outside the view distances of all players
|
||||||
|
let to_delete = {
|
||||||
|
let terrain = self.state.terrain();
|
||||||
|
(
|
||||||
|
&self.state.ecs().entities(),
|
||||||
|
&self.state.ecs().read_storage::<comp::Pos>(),
|
||||||
|
&self.state.ecs().read_storage::<comp::Agent>(),
|
||||||
|
)
|
||||||
|
.join()
|
||||||
|
.filter(|(_, pos, _)| terrain.get(pos.0.map(|e| e.floor() as i32)).is_err())
|
||||||
|
.map(|(entity, _, _)| entity)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
};
|
||||||
|
for entity in to_delete {
|
||||||
|
let _ = self.state.ecs_mut().delete_entity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
// 7) Finish the tick, pass control back to the frontend.
|
// 7) Finish the tick, pass control back to the frontend.
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
@ -132,7 +132,7 @@ impl World {
|
|||||||
|
|
||||||
const SPAWN_RATE: f32 = 0.1;
|
const SPAWN_RATE: f32 = 0.1;
|
||||||
let supplement = ChunkSupplement {
|
let supplement = ChunkSupplement {
|
||||||
npcs: if rand::thread_rng().gen::<f32>() < SPAWN_RATE {
|
npcs: if rand::thread_rng().gen::<f32>() < SPAWN_RATE && sim_chunk.chaos < 0.5 {
|
||||||
vec![NpcInfo {
|
vec![NpcInfo {
|
||||||
pos: gen_entity_pos(),
|
pos: gen_entity_pos(),
|
||||||
}]
|
}]
|
||||||
|
Loading…
Reference in New Issue
Block a user