mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Directly compare rtism resources to avoid unnecessary hooks
This commit is contained in:
parent
81b52298f0
commit
08afe26112
@ -233,7 +233,7 @@ pub enum NpcAction {
|
||||
|
||||
// Note: the `serde(name = "...")` is to minimise the length of field
|
||||
// identifiers for the sake of rtsim persistence
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, enum_map::Enum)]
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, enum_map::Enum)]
|
||||
pub enum ChunkResource {
|
||||
#[serde(rename = "0")]
|
||||
Grass,
|
||||
|
@ -700,9 +700,10 @@ impl Server {
|
||||
|
||||
fn on_block_update(ecs: &specs::World, changes: Vec<BlockDiff>) {
|
||||
// When a resource block updates, inform rtsim
|
||||
if changes.iter().any(|c| {
|
||||
c.old.get_rtsim_resource().is_some() || c.new.get_rtsim_resource().is_some()
|
||||
}) {
|
||||
if changes
|
||||
.iter()
|
||||
.any(|c| c.old.get_rtsim_resource() != c.new.get_rtsim_resource())
|
||||
{
|
||||
ecs.write_resource::<rtsim::RtSim>().hook_block_update(
|
||||
&ecs.read_resource::<Arc<world::World>>(),
|
||||
ecs.read_resource::<world::IndexOwned>().as_index_ref(),
|
||||
|
@ -159,6 +159,8 @@ impl RtSim {
|
||||
}
|
||||
}
|
||||
|
||||
// Note that this hook only needs to be invoked if the block change results in a
|
||||
// change to the rtsim resource produced by [`Block::get_rtsim_resource`].
|
||||
pub fn hook_block_update(&mut self, world: &World, index: IndexRef, changes: Vec<BlockDiff>) {
|
||||
self.state
|
||||
.emit(event::OnBlockChange { changes }, world, index);
|
||||
|
Loading…
Reference in New Issue
Block a user