amethyst / amethyst/legion

Components are marked as changed when accessed mutable but when not changed.

未关闭
#86 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
1.7k
派生
140
PR 合并指标
30 天内没有已合并 PR

描述

When I do:

```rust
// Define our entity data types
#[derive(Clone, Copy, Debug, PartialEq)]
struct Position {
x: f32,
y: f32,
}

#[derive(Clone, Copy, Debug, PartialEq)]
struct Velocity {
dx: f32,
dy: f32,
}

pub fn main() {
// Create a world to store our entities
let universe = Universe::new();
let mut real_world = universe.create_world();

// Create entities with `Position` and `Velocity` data
real_world.insert(
(),
(0..999).map(|_| (Position { x: 0.0, y: 0.0 }, Velocity { dx: 0.1, dy: 0.1 }))
);

// Create a query which finds all `Position` and `Velocity` components
let query = <(Write, Read)>::query();
//Iterate through all entities that match the query in the world
for (mut pos, vel) in query.iter(&mut real_world) {
// because we loop mutable all position components are marked changed. While I haven't changed anything.
}

let query = <(Read)>::query().filter(changed::());
for pos in query.iter(&mut real_world) {
println!("changed: {} {}", pos.x, pos.y);
}
}
```

Components are marked as changed even if I don't change them. This has to do with the fact that the mutable query increases the version of a component. If the version has changed then it is considered changed. This seems to me to be undesirable behavior or should at least be mentioned in the documentation as a warning. Is this intended, is this problem known, and would it be possible to somehow fix this? It is a difficult issue, specs does basicly the same.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。