legion: change query system ordering

This commit is contained in:
Carter Anderson 2020-06-27 10:18:27 -07:00
parent c5842fd92b
commit e75496772e
29 changed files with 72 additions and 85 deletions

View File

@ -112,11 +112,11 @@ pub fn impl_fn_systems(_input: TokenStream) -> TokenStream {
let command_buffer_var = &command_buffer_var[0..command_buffer_index];
let run_fn = if view_count == 0 {
quote! { self(#(#command_buffer_var,)*#(#resource_var),*) }
quote! { self(#(#resource_var,)* #(#command_buffer_var,)*) }
} else {
quote! {
for (#(#view_var),*) in _query.iter_mut(_world) {
self(#(#command_buffer_var,)*#(#resource_var.clone(),)* #(#view_var),*);
self(#(#resource_var.clone(),)* #(#command_buffer_var,)* #(#view_var),*);
}
}
};
@ -128,7 +128,7 @@ pub fn impl_fn_systems(_input: TokenStream) -> TokenStream {
#(#view: for<'b> View<'b> + DefaultFilter + ViewElement,)*
> IntoSystem<(#(#command_buffer)*), (#(#resource,)*), (#(#view,)*), ()> for Func
where
Func: FnMut(#(&mut #command_buffer,)* #(#resource,)* #(#view),*) + Send + Sync + 'static,
Func: FnMut(#(#resource,)* #(&mut #command_buffer,)* #(#view),*) + Send + Sync + 'static,
#(<#view as View<'a>>::Iter: Iterator<Item = #view>,
<#view as DefaultFilter>::Filter: Sync),*
{
@ -253,7 +253,7 @@ pub fn impl_fn_query_systems(_input: TokenStream) -> TokenStream {
#(#view: for<'b> View<'b> + DefaultFilter + ViewElement),*
> IntoSystem<(#(#command_buffer)*), (#(#resource,)*), (), #view_tuple_avoid_type_collision> for Func
where
Func: FnMut(#(&mut #command_buffer,)* &mut SubWorld, #(#resource,)* #(&mut SystemQuery<#view, <#view as DefaultFilter>::Filter>),*) + Send + Sync + 'static,
Func: FnMut(#(#resource,)*#(&mut #command_buffer,)* &mut SubWorld, #(&mut SystemQuery<#view, <#view as DefaultFilter>::Filter>),*) + Send + Sync + 'static,
#(<#view as DefaultFilter>::Filter: Sync),*
{
fn system_id(mut self, id: SystemId) -> Box<dyn Schedulable> {
@ -268,7 +268,7 @@ pub fn impl_fn_query_systems(_input: TokenStream) -> TokenStream {
| {
let #resource_var_tuple = _resources;
let #query_var_tuple = _queries;
self(#(#command_buffer_var,)*_world,#(#resource_var,)* #(#query_var),*)
self(#(#resource_var,)*#(#command_buffer_var,)*_world,#(#query_var),*)
},
PhantomData,
);

View File

@ -57,10 +57,10 @@ impl SystemNode for LightsNode {
let mut tmp_light_buffer = None;
let mut command_queue = self.command_queue.clone();
let max_lights = self.max_lights;
(move |world: &mut SubWorld,
render_resource_context: Res<Box<dyn RenderResourceContext>>,
(move |render_resource_context: Res<Box<dyn RenderResourceContext>>,
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same
mut render_resource_bindings: ResMut<RenderResourceBindings>,
world: &mut SubWorld,
query: &mut Query<(Read<Light>, Read<Transform>, Read<Translation>)>| {
if !lights_are_dirty {
return;

View File

@ -26,8 +26,8 @@ impl ActiveCameras {
}
pub fn active_cameras_system(
world: &mut SubWorld,
mut active_cameras: ResMut<ActiveCameras>,
world: &mut SubWorld,
query: &mut Query<Read<Camera>>,
) {
for (name, active_camera) in active_cameras.cameras.iter_mut() {

View File

@ -16,10 +16,10 @@ pub struct Camera {
pub fn camera_system<T: CameraProjection + Component>() -> Box<dyn Schedulable> {
let mut window_resized_event_reader = EventReader::<WindowResized>::default();
let mut window_created_event_reader = EventReader::<WindowCreated>::default();
(move |world: &mut SubWorld,
window_resized_events: Res<Events<WindowResized>>,
(move |window_resized_events: Res<Events<WindowResized>>,
window_created_events: Res<Events<WindowCreated>>,
windows: Res<Windows>,
world: &mut SubWorld,
query: &mut Query<(Write<Camera>, Write<T>)>| {
let mut changed_window_ids = Vec::new();
let mut changed_primary_window_id = None;

View File

@ -351,27 +351,11 @@ pub mod shape {
let extent = plane.size / 2.0;
let vertices = [
(
[extent, 0.0, -extent],
[0.0, 1.0, 0.0],
[1.0, 1.0],
),
(
[extent, 0.0, extent],
[0.0, 1.0, 0.0],
[1.0, 0.0],
),
(
[-extent, 0.0, extent],
[0.0, 1.0, 0.0],
[0.0, 0.0],
),
(
[-extent, 0.0, -extent],
[0.0, 1.0, 0.0],
[0.0, 1.0],
),
];
([extent, 0.0, -extent], [0.0, 1.0, 0.0], [1.0, 1.0]),
([extent, 0.0, extent], [0.0, 1.0, 0.0], [1.0, 0.0]),
([-extent, 0.0, extent], [0.0, 1.0, 0.0], [0.0, 0.0]),
([-extent, 0.0, -extent], [0.0, 1.0, 0.0], [0.0, 1.0]),
];
let indices = vec![0, 2, 1, 0, 3, 2];
@ -421,10 +405,10 @@ pub fn mesh_resource_provider_system(resources: &mut Resources) -> Box<dyn Sched
// TODO: allow pipelines to specialize on vertex_buffer_descriptor and index_format
let vertex_buffer_descriptor = Vertex::as_vertex_buffer_descriptor();
vertex_buffer_descriptors.set(vertex_buffer_descriptor.clone());
(move |world: &mut SubWorld,
render_resource_context: Res<Box<dyn RenderResourceContext>>,
(move |render_resource_context: Res<Box<dyn RenderResourceContext>>,
meshes: Res<Assets<Mesh>>,
mesh_events: Res<Events<AssetEvent<Mesh>>>,
world: &mut SubWorld,
query: &mut Query<(Read<Handle<Mesh>>, Write<RenderPipelines>)>| {
let mut changed_meshes = HashSet::new();
let render_resource_context = &**render_resource_context;

View File

@ -45,12 +45,13 @@ impl SystemNode for CameraNode {
let mut camera_buffer = None;
let mut command_queue = self.command_queue.clone();
let camera_name = self.camera_name.clone();
(move |world: &mut SubWorld,
(move |
active_cameras: Res<ActiveCameras>,
render_resource_context: Res<Box<dyn RenderResourceContext>>,
// PERF: this write on RenderResourceAssignments will prevent this system from running in parallel
// with other systems that do the same
mut render_resource_bindings: ResMut<RenderResourceBindings>,
world: &mut SubWorld,
_query: &mut Query<(Read<Camera>, Read<Transform>)>| {
let render_resource_context = &**render_resource_context;
if camera_buffer.is_none() {

View File

@ -371,8 +371,8 @@ where
let mut uniform_buffer_arrays = UniformBufferArrays::<T>::default();
let dynamic_uniforms = self.dynamic_uniforms;
// TODO: maybe run "update" here
(move |world: &mut SubWorld,
render_resource_context: Res<Box<dyn RenderResourceContext>>,
(move |render_resource_context: Res<Box<dyn RenderResourceContext>>,
world: &mut SubWorld,
query: &mut Query<(Read<T>, Read<Draw>, Write<RenderPipelines>)>| {
let render_resource_context = &**render_resource_context;
uniform_buffer_arrays.reset_changed_item_counts();
@ -498,11 +498,11 @@ where
let mut uniform_buffer_arrays = UniformBufferArrays::<T>::default();
// let mut asset_event_reader = EventReader::<AssetEvent<T>>::default();
let dynamic_uniforms = self.dynamic_uniforms;
(move |world: &mut SubWorld,
assets: Res<Assets<T>>,
(move |assets: Res<Assets<T>>,
// asset_events: Res<Events<AssetEvent<T>>>,
mut asset_render_resource_bindings: ResMut<AssetRenderResourceBindings>,
render_resource_context: Res<Box<dyn RenderResourceContext>>,
world: &mut SubWorld,
query: &mut Query<(Read<Handle<T>>, Read<Draw>, Write<RenderPipelines>)>| {
let render_resource_context = &**render_resource_context;
uniform_buffer_arrays.reset_changed_item_counts();

View File

@ -14,8 +14,8 @@ pub struct Rect {
}
pub fn ui_update_system(
world: &mut SubWorld,
windows: Res<Windows>,
world: &mut SubWorld,
node_query: &mut Query<(Write<Node>, Write<Translation>)>,
_parent_query: &mut Query<Read<Parent>>,
_children_query: &mut Query<Read<Children>>,
@ -51,7 +51,12 @@ pub fn ui_update_system(
}
}
fn update_node_entity(world: &mut SubWorld, entity: Entity, parent_rect: Option<&mut Rect>, previous_rect: Option<Rect>) -> Option<Rect> {
fn update_node_entity(
world: &mut SubWorld,
entity: Entity,
parent_rect: Option<&mut Rect>,
previous_rect: Option<Rect>,
) -> Option<Rect> {
// TODO: Somehow remove this unsafe
unsafe {
if let Some(mut node) = world.get_component_mut_unchecked::<Node>(entity) {
@ -64,18 +69,11 @@ fn update_node_entity(world: &mut SubWorld, entity: Entity, parent_rect: Option<
};
z -= UI_Z_STEP;
node.update(
&mut translation,
z - parent_rect.z,
parent_rect.size,
);
return Some(Rect {
size: node.size,
z,
});
node.update(&mut translation, z - parent_rect.z, parent_rect.size);
return Some(Rect { size: node.size, z });
}
}
}
None
}
}

View File

@ -8,9 +8,9 @@ fn main() {
}
fn setup(
command_buffer: &mut CommandBuffer,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
command_buffer: &mut CommandBuffer,
) {
let texture_handle = asset_server.load("assets/branding/icon.png").unwrap();
command_buffer

View File

@ -22,10 +22,10 @@ fn animate_sprite_system(
}
fn setup(
command_buffer: &mut CommandBuffer,
asset_server: Res<AssetServer>,
mut textures: ResMut<Assets<Texture>>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
command_buffer: &mut CommandBuffer,
) {
let texture_handle = asset_server
.load_sync(

View File

@ -18,9 +18,9 @@ pub struct RpgSpriteHandles {
}
fn setup(
command_buffer: &mut CommandBuffer,
mut rpg_sprite_handles: ResMut<RpgSpriteHandles>,
asset_server: Res<AssetServer>,
command_buffer: &mut CommandBuffer,
) {
rpg_sprite_handles.handles = asset_server
.load_asset_folder("assets/textures/rpg")
@ -36,13 +36,13 @@ struct State {
}
fn load_atlas(
command_buffer: &mut CommandBuffer,
mut state: ResMut<State>,
rpg_sprite_handles: Res<RpgSpriteHandles>,
asset_server: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
mut textures: ResMut<Assets<Texture>>,
mut materials: ResMut<Assets<ColorMaterial>>,
command_buffer: &mut CommandBuffer,
) {
if state.atlas_loaded {
return;

View File

@ -9,9 +9,9 @@ fn main() {
/// set up a simple scene
fn setup(
command_buffer: &mut CommandBuffer,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
command_buffer: &mut CommandBuffer,
) {
// create a cube and a plane mesh
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));

View File

@ -8,9 +8,9 @@ fn main() {
}
fn setup(
command_buffer: &mut CommandBuffer,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<StandardMaterial>>,
command_buffer: &mut CommandBuffer,
) {
// load the mesh
let mesh_handle = asset_server

View File

@ -17,9 +17,9 @@ fn rotator_system(time: Res<Time>, _rotator: ComMut<Rotator>, mut rotation: ComM
/// set up a simple scene with a "parent" cube and a "child" cube
fn setup(
command_buffer: &mut CommandBuffer,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
command_buffer: &mut CommandBuffer,
) {
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
let cube_material_handle = materials.add(StandardMaterial {

View File

@ -26,9 +26,9 @@ fn move_cubes(
}
fn setup(
command_buffer: &mut CommandBuffer,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
command_buffer: &mut CommandBuffer,
) {
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
let plane_handle = meshes.add(Mesh::from(shape::Plane { size: 10.0 }));

View File

@ -9,11 +9,11 @@ fn main() {
/// sets up a scene with textured entities
fn setup(
command_buffer: &mut CommandBuffer,
asset_server: Res<AssetServer>,
mut meshes: ResMut<Assets<Mesh>>,
mut textures: ResMut<Assets<Texture>>,
mut materials: ResMut<Assets<StandardMaterial>>,
command_buffer: &mut CommandBuffer,
) {
// load a texture
let texture_handle = asset_server

View File

@ -17,8 +17,8 @@ fn rotator_system(time: Res<Time>, _rotator: ComMut<Rotator>, mut rotation: ComM
}
fn camera_order_color_system(
world: &mut SubWorld,
mut materials: ResMut<Assets<StandardMaterial>>,
world: &mut SubWorld,
camera_query: &mut Query<(Read<Camera>, Read<VisibleEntities>)>,
_material_query: &mut Query<Read<Handle<StandardMaterial>>>,
) {
@ -37,9 +37,9 @@ fn camera_order_color_system(
/// set up a simple scene with a "parent" cube and a "child" cube
fn setup(
command_buffer: &mut CommandBuffer,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
command_buffer: &mut CommandBuffer,
) {
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
command_buffer

View File

@ -10,9 +10,9 @@ impl AppPlugin for ExamplePlugin {
}
fn setup(
command_buffer: &mut CommandBuffer,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
command_buffer: &mut CommandBuffer,
) {
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 }));
let cube_material_handle = materials.add(StandardMaterial {

View File

@ -8,10 +8,10 @@ fn main() {
}
fn setup(
command_buffer: &mut CommandBuffer,
asset_server: Res<AssetServer>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
command_buffer: &mut CommandBuffer,
) {
// You can load all assets in a folder like this. They will be loaded in parallel without blocking
asset_server

View File

@ -10,9 +10,9 @@ fn main() {
}
fn setup(
command_buffer: &mut CommandBuffer,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<StandardMaterial>>,
command_buffer: &mut CommandBuffer,
) {
// Load our mesh:
let mesh_handle = asset_server

View File

@ -193,9 +193,9 @@ fn startup_system(world: &mut World, resources: &mut Resources) {
// Command buffers give us the ability to queue up changes to our World without directly accessing it
// NOTE: Command buffers must always come before resources and components in system functions
fn new_player_system(
command_buffer: &mut CommandBuffer,
game_rules: Res<GameRules>,
mut game_state: ResMut<GameState>,
command_buffer: &mut CommandBuffer,
) {
// Randomly add a new player
let add_new_player = random::<bool>();

View File

@ -31,7 +31,11 @@ struct Scoreboard {
score: usize,
}
fn setup(command_buffer: &mut CommandBuffer, mut materials: ResMut<Assets<ColorMaterial>>, asset_server: Res<AssetServer>) {
fn setup(
mut materials: ResMut<Assets<ColorMaterial>>,
asset_server: Res<AssetServer>,
command_buffer: &mut CommandBuffer,
) {
// Add the game's entities to our world
let mut builder = command_buffer.build();
builder
@ -67,15 +71,11 @@ fn setup(command_buffer: &mut CommandBuffer, mut materials: ResMut<Assets<ColorM
style: TextStyle {
color: Color::rgb(0.2, 0.2, 0.8).into(),
font_size: 40.0,
}
},
},
node: Node::new(
Anchors::TOP_LEFT,
Margins::new(10.0, 50.0, 10.0, 50.0),
),
node: Node::new(Anchors::TOP_LEFT, Margins::new(10.0, 50.0, 10.0, 50.0)),
..Default::default()
})
;
});
// Add walls
let wall_material = materials.add(Color::rgb(0.5, 0.5, 0.5).into());
@ -155,9 +155,9 @@ fn setup(command_buffer: &mut CommandBuffer, mut materials: ResMut<Assets<ColorM
}
fn paddle_movement_system(
world: &mut SubWorld,
time: Res<Time>,
keyboard_input: Res<Input<KeyCode>>,
world: &mut SubWorld,
query: &mut Query<(Read<Paddle>, Write<Translation>)>,
) {
for (paddle, mut translation) in query.iter_mut(world) {
@ -175,8 +175,8 @@ fn paddle_movement_system(
}
fn ball_movement_system(
world: &mut SubWorld,
time: Res<Time>,
world: &mut SubWorld,
ball_query: &mut Query<(Read<Ball>, Write<Translation>)>,
) {
for (ball, mut translation) in ball_query.iter_mut(world) {
@ -184,16 +184,20 @@ fn ball_movement_system(
}
}
fn scoreboard_system(world: &mut SubWorld, scoreboard: Res<Scoreboard>, query: &mut Query<Write<Label>>) {
fn scoreboard_system(
scoreboard: Res<Scoreboard>,
world: &mut SubWorld,
query: &mut Query<Write<Label>>,
) {
for mut label in query.iter_mut(world) {
label.text = format!("Score: {}", scoreboard.score);
}
}
fn ball_collision_system(
mut scoreboard: ResMut<Scoreboard>,
command_buffer: &mut CommandBuffer,
world: &mut SubWorld,
mut scoreboard: ResMut<Scoreboard>,
ball_query: &mut Query<(Write<Ball>, Read<Translation>, Read<Sprite>)>,
paddle_query: &mut Query<(Read<Paddle>, Read<Translation>, Read<Sprite>)>,
brick_query: &mut Query<(Read<Brick>, Read<Translation>, Read<Sprite>)>,

View File

@ -40,12 +40,12 @@ void main() {
"#;
fn setup(
command_buffer: &mut CommandBuffer,
mut pipelines: ResMut<Assets<PipelineDescriptor>>,
mut shaders: ResMut<Assets<Shader>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<MyMaterial>>,
mut render_graph: ResMut<RenderGraph>,
command_buffer: &mut CommandBuffer,
) {
// Create a new shader pipeline
let pipeline_handle = pipelines.add(PipelineDescriptor::default_config(ShaderStages {

View File

@ -51,12 +51,12 @@ void main() {
"#;
fn setup(
command_buffer: &mut CommandBuffer,
mut pipelines: ResMut<Assets<PipelineDescriptor>>,
mut shaders: ResMut<Assets<Shader>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<MyMaterial>>,
mut render_graph: ResMut<RenderGraph>,
command_buffer: &mut CommandBuffer,
) {
// Create a new shader pipeline
let pipeline_handle = pipelines.add(PipelineDescriptor::default_config(ShaderStages {

View File

@ -27,11 +27,11 @@ impl Default for State {
}
fn atlas_render_system(
command_buffer: &mut CommandBuffer,
mut state: ResMut<State>,
mut materials: ResMut<Assets<ColorMaterial>>,
font_atlas_sets: Res<Assets<FontAtlasSet>>,
texture_atlases: Res<Assets<TextureAtlas>>,
command_buffer: &mut CommandBuffer,
) {
if state.added {
return;
@ -59,9 +59,9 @@ fn text_update_system(mut state: ResMut<State>, time: Res<Time>, mut label: ComM
}
fn setup(
command_buffer: &mut CommandBuffer,
asset_server: Res<AssetServer>,
mut state: ResMut<State>,
command_buffer: &mut CommandBuffer,
) {
let font_handle = asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap();
state.handle = font_handle;

View File

@ -20,7 +20,7 @@ fn text_update_system(diagnostics: Res<Diagnostics>, mut label: ComMut<Label>) {
}
}
fn setup(command_buffer: &mut CommandBuffer, asset_server: Res<AssetServer>) {
fn setup(asset_server: Res<AssetServer>, command_buffer: &mut CommandBuffer) {
let font_handle = asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap();
command_buffer
.build()

View File

@ -8,10 +8,10 @@ fn main() {
}
fn setup(
command_buffer: &mut CommandBuffer,
asset_server: Res<AssetServer>,
mut textures: ResMut<Assets<Texture>>,
mut materials: ResMut<Assets<ColorMaterial>>,
command_buffer: &mut CommandBuffer,
) {
// TODO: "background" 3D temporarily disabled until depth mismatch is fixed
// let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();

View File

@ -21,7 +21,7 @@ fn placement_system(
}
}
fn setup(command_buffer: &mut CommandBuffer, mut materials: ResMut<Assets<ColorMaterial>>) {
fn setup(mut materials: ResMut<Assets<ColorMaterial>>, command_buffer: &mut CommandBuffer) {
let mut builder = command_buffer.build();
builder.entity_with(OrthographicCameraComponents::ui());

View File

@ -19,12 +19,12 @@ fn main() {
}
fn setup(
command_buffer: &mut CommandBuffer,
mut create_window_events: ResMut<Events<CreateWindow>>,
mut active_cameras: ResMut<ActiveCameras>,
mut render_graph: ResMut<RenderGraph>,
mut materials: ResMut<Assets<StandardMaterial>>,
asset_server: Res<AssetServer>,
command_buffer: &mut CommandBuffer,
) {
let window_id = WindowId::new();