Merge pull request #19 from hymm/change-to-system-state

change use query to use system state
This commit is contained in:
JMS55 2024-01-20 23:17:58 -08:00 committed by GitHub
commit 273660d33d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 19 deletions

View File

@ -33,7 +33,7 @@ fn Editor(cx: Scope) -> Element {
#[component]
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 mut entities = entities.into_iter().collect::<Vec<_>>();
entities.sort_by_key(|(entity, _)| *entity);

View File

@ -3,9 +3,9 @@ use bevy::{
ecs::{
component::ComponentId,
event::{Event, EventIterator, Events, ManualEventReader},
query::{QueryState, ReadOnlyWorldQuery},
system::{Query, Resource},
world::{unsafe_world_cell::UnsafeWorldCell, World},
query::ReadOnlyWorldQuery,
system::{Query, Resource, SystemState},
world::World,
},
utils::{HashMap, HashSet},
};
@ -115,8 +115,8 @@ where
});
UseQuery {
query_state: QueryState::new(world),
world_cell: world.as_unsafe_world_cell(),
system_state: SystemState::new(world),
world_ref: world,
}
}
@ -128,9 +128,9 @@ pub fn use_event_reader<E: Event>(cx: &ScopeState) -> EventIterator<'_, E> {
event_reader.read(events)
}
pub struct UseQuery<'a, Q: ReadOnlyWorldQuery, F: ReadOnlyWorldQuery> {
query_state: QueryState<Q, F>,
world_cell: UnsafeWorldCell<'a>,
pub struct UseQuery<'a, Q: ReadOnlyWorldQuery + 'static, F: ReadOnlyWorldQuery + 'static> {
system_state: SystemState<Query<'static, 'static, Q, F>>,
world_ref: &'a World,
}
impl<'a, Q, F> UseQuery<'a, Q, F>
@ -138,15 +138,7 @@ where
Q: ReadOnlyWorldQuery,
F: ReadOnlyWorldQuery,
{
pub fn query(&self) -> Query<Q, F> {
unsafe {
Query::new(
self.world_cell,
&self.query_state,
self.world_cell.last_change_tick(),
self.world_cell.change_tick(),
true,
)
}
pub fn query(&mut self) -> Query<Q, F> {
self.system_state.get(self.world_ref)
}
}