Merge pull request #19 from hymm/change-to-system-state
change use query to use system state
This commit is contained in:
commit
273660d33d
|
@ -33,7 +33,7 @@ fn Editor(cx: Scope) -> Element {
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseStateSendable<Option<Entity>>) -> Element {
|
fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseStateSendable<Option<Entity>>) -> Element {
|
||||||
let entities = use_query_filtered::<(Entity, DebugName), Without<Node>>(cx);
|
let mut entities = use_query_filtered::<(Entity, DebugName), Without<Node>>(cx);
|
||||||
let entities = entities.query();
|
let entities = entities.query();
|
||||||
let mut entities = entities.into_iter().collect::<Vec<_>>();
|
let mut entities = entities.into_iter().collect::<Vec<_>>();
|
||||||
entities.sort_by_key(|(entity, _)| *entity);
|
entities.sort_by_key(|(entity, _)| *entity);
|
||||||
|
|
|
@ -3,9 +3,9 @@ use bevy::{
|
||||||
ecs::{
|
ecs::{
|
||||||
component::ComponentId,
|
component::ComponentId,
|
||||||
event::{Event, EventIterator, Events, ManualEventReader},
|
event::{Event, EventIterator, Events, ManualEventReader},
|
||||||
query::{QueryState, ReadOnlyWorldQuery},
|
query::ReadOnlyWorldQuery,
|
||||||
system::{Query, Resource},
|
system::{Query, Resource, SystemState},
|
||||||
world::{unsafe_world_cell::UnsafeWorldCell, World},
|
world::World,
|
||||||
},
|
},
|
||||||
utils::{HashMap, HashSet},
|
utils::{HashMap, HashSet},
|
||||||
};
|
};
|
||||||
|
@ -115,8 +115,8 @@ where
|
||||||
});
|
});
|
||||||
|
|
||||||
UseQuery {
|
UseQuery {
|
||||||
query_state: QueryState::new(world),
|
system_state: SystemState::new(world),
|
||||||
world_cell: world.as_unsafe_world_cell(),
|
world_ref: world,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,9 +128,9 @@ pub fn use_event_reader<E: Event>(cx: &ScopeState) -> EventIterator<'_, E> {
|
||||||
event_reader.read(events)
|
event_reader.read(events)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UseQuery<'a, Q: ReadOnlyWorldQuery, F: ReadOnlyWorldQuery> {
|
pub struct UseQuery<'a, Q: ReadOnlyWorldQuery + 'static, F: ReadOnlyWorldQuery + 'static> {
|
||||||
query_state: QueryState<Q, F>,
|
system_state: SystemState<Query<'static, 'static, Q, F>>,
|
||||||
world_cell: UnsafeWorldCell<'a>,
|
world_ref: &'a World,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Q, F> UseQuery<'a, Q, F>
|
impl<'a, Q, F> UseQuery<'a, Q, F>
|
||||||
|
@ -138,15 +138,7 @@ where
|
||||||
Q: ReadOnlyWorldQuery,
|
Q: ReadOnlyWorldQuery,
|
||||||
F: ReadOnlyWorldQuery,
|
F: ReadOnlyWorldQuery,
|
||||||
{
|
{
|
||||||
pub fn query(&self) -> Query<Q, F> {
|
pub fn query(&mut self) -> Query<Q, F> {
|
||||||
unsafe {
|
self.system_state.get(self.world_ref)
|
||||||
Query::new(
|
|
||||||
self.world_cell,
|
|
||||||
&self.query_state,
|
|
||||||
self.world_cell.last_change_tick(),
|
|
||||||
self.world_cell.change_tick(),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue