Skip to content

Commit

Permalink
Implement Dynamic Systems
Browse files Browse the repository at this point in the history
This adds support for creating `DynamicSystem`s and for constructing
`GenericQuery`s that can be used to implement systems that are loaded at
runtime instead of compile time.
  • Loading branch information
zicklag committed Oct 16, 2020
1 parent a69cb1e commit 1f901da
Show file tree
Hide file tree
Showing 12 changed files with 773 additions and 204 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ serde = { version = "1", features = ["derive"] }
log = "0.4"
ron = "0.6"
anyhow = "1.0"
bytemuck = "1.4.1"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
console_error_panic_hook = "0.1.6"
Expand Down Expand Up @@ -206,6 +207,10 @@ path = "examples/ecs/parallel_query.rs"
name = "hierarchy"
path = "examples/ecs/hierarchy.rs"

[[example]]
name = "dynamic_systems"
path = "examples/ecs/dynamic_systems.rs"

[[example]]
name = "breakout"
path = "examples/game/breakout.rs"
Expand Down
10 changes: 7 additions & 3 deletions crates/bevy_ecs/hecs/src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ impl Archetype {
size: usize,
index: usize,
) -> Option<NonNull<u8>> {
debug_assert!(index < self.len);
// TODO(zicklag): I'm pretty sure that it is valid for the index to be zero
debug_assert!(index < self.len || index == 0);
Some(NonNull::new_unchecked(
(*self.data.get())
.as_ptr()
Expand Down Expand Up @@ -438,8 +439,11 @@ impl Archetype {
}

/// How, if at all, `Q` will access entities in this archetype
pub fn access<Q: Query>(&self) -> Option<Access> {
Q::Fetch::access(self)
pub fn access<S: Default, Q: Query>(&self, state: &S) -> Option<Access>
where
Q::Fetch: for<'a> Fetch<'a, State = S>,
{
Q::Fetch::access(self, state)
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_ecs/hecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ pub use bundle::{Bundle, DynamicBundle, MissingComponent};
pub use entities::{Entity, EntityReserver, Location, NoSuchEntity};
pub use entity_builder::{BuiltEntity, EntityBuilder};
pub use query::{
Access, Added, BatchedIter, Changed, Mut, Mutated, Or, Query, QueryBorrow, QueryIter,
ReadOnlyFetch, With, Without,
Access, Added, BatchedIter, Changed, DynamicComponentAccess, DynamicComponentInfo,
DynamicComponentQuery, Mut, Mutated, Or, Query, QueryBorrow, QueryIter, ReadOnlyFetch, With,
Without,
};
pub use query_one::QueryOne;
pub use world::{
Expand Down
Loading

0 comments on commit 1f901da

Please sign in to comment.