Skip to content

Commit 3dccbc9

Browse files
committed
Implement Dynamic Systems
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.
1 parent 976b476 commit 3dccbc9

File tree

12 files changed

+773
-204
lines changed

12 files changed

+773
-204
lines changed

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ serde = { version = "1", features = ["derive"] }
8989
log = "0.4"
9090
ron = "0.6"
9191
anyhow = "1.0"
92+
bytemuck = "1.4.1"
9293

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

210+
[[example]]
211+
name = "dynamic_systems"
212+
path = "examples/ecs/dynamic_systems.rs"
213+
209214
[[example]]
210215
name = "breakout"
211216
path = "examples/game/breakout.rs"

crates/bevy_ecs/hecs/src/archetype.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ impl Archetype {
241241
size: usize,
242242
index: usize,
243243
) -> Option<NonNull<u8>> {
244-
debug_assert!(index < self.len);
244+
// TODO(zicklag): I'm pretty sure that it is valid for the index to be zero
245+
debug_assert!(index < self.len || index == 0);
245246
Some(NonNull::new_unchecked(
246247
(*self.data.get())
247248
.as_ptr()
@@ -438,8 +439,11 @@ impl Archetype {
438439
}
439440

440441
/// How, if at all, `Q` will access entities in this archetype
441-
pub fn access<Q: Query>(&self) -> Option<Access> {
442-
Q::Fetch::access(self)
442+
pub fn access<S: Default, Q: Query>(&self, state: &S) -> Option<Access>
443+
where
444+
Q::Fetch: for<'a> Fetch<'a, State = S>,
445+
{
446+
Q::Fetch::access(self, state)
443447
}
444448
}
445449

crates/bevy_ecs/hecs/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ pub use bundle::{Bundle, DynamicBundle, MissingComponent};
8181
pub use entities::{Entity, EntityReserver, Location, NoSuchEntity};
8282
pub use entity_builder::{BuiltEntity, EntityBuilder};
8383
pub use query::{
84-
Access, Added, BatchedIter, Changed, Mut, Mutated, Or, Query, QueryBorrow, QueryIter,
85-
ReadOnlyFetch, With, Without,
84+
Access, Added, BatchedIter, Changed, DynamicComponentAccess, DynamicComponentInfo,
85+
DynamicComponentQuery, Mut, Mutated, Or, Query, QueryBorrow, QueryIter, ReadOnlyFetch, With,
86+
Without,
8687
};
8788
pub use query_one::QueryOne;
8889
pub use world::{

0 commit comments

Comments
 (0)