port a few more systems to functions and add some name clarity

This commit is contained in:
Carter Anderson 2020-05-01 01:37:20 -07:00
parent 913d016344
commit 5458c6daf4
6 changed files with 33 additions and 45 deletions

View file

@ -12,6 +12,7 @@ use bevy_app::{stage, AppBuilder, AppPlugin};
use bevy_asset::AssetStorage;
use bevy_render::{render_graph::RenderGraph, shader};
use material::StandardMaterial;
use legion::prelude::IntoSystem;
#[derive(Default)]
pub struct PbrPlugin;
@ -23,7 +24,7 @@ impl AppPlugin for PbrPlugin {
app.add_resource(AssetStorage::<StandardMaterial>::new())
.add_system_to_stage(
stage::POST_UPDATE,
shader::asset_handle_shader_def_system::<StandardMaterial>(),
shader::asset_handle_shader_def_system::<StandardMaterial>.system(),
)
.add_system_to_stage(
stage::POST_UPDATE,

View file

@ -36,7 +36,7 @@ impl SystemNode for Camera2dNode {
let mut tmp_buffer = None;
let mut window_resized_event_reader = resources.get_event_reader::<WindowResized>();
let mut command_queue = self.command_queue.clone();
SystemBuilder::new("camera_resource_provider")
SystemBuilder::new("camera_2d_resource_provider")
.read_resource::<GlobalRenderResourceContext>()
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same
.write_resource::<RenderResourceAssignments>()

View file

@ -432,7 +432,7 @@ where
let mut staging_buffer_resource = None;
initialize_vertex_buffer_descriptor::<T>(&mut vertex_buffer_descriptors);
// TODO: maybe run "update" here
SystemBuilder::new("uniform_resource_provider")
SystemBuilder::new(format!("uniform_resource_provider::<{}>", std::any::type_name::<T>()))
.read_resource::<AssetStorage<Texture>>()
.read_resource::<GlobalRenderResourceContext>()
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same

View file

@ -20,53 +20,40 @@ pub trait AsUniforms: Send + Sync + 'static {
fn get_vertex_buffer_descriptor() -> Option<&'static VertexBufferDescriptor>;
}
pub fn shader_def_system<T>() -> Box<dyn Schedulable>
pub fn shader_def_system<T>(uniforms: Ref<T>, mut renderable: RefMut<Renderable>)
where
T: AsUniforms + Send + Sync + 'static,
{
SystemBuilder::new(format!("shader_def::{}", std::any::type_name::<T>()))
.with_query(<(Read<T>, Write<Renderable>)>::query())
.build(|_, world, _, query| {
for (uniforms, mut renderable) in query.iter_mut(world) {
if let Some(shader_defs) = uniforms.get_shader_defs() {
renderable
.render_resource_assignments
.pipeline_specialization
.shader_specialization
.shader_defs
.extend(shader_defs)
}
}
})
if let Some(shader_defs) = uniforms.get_shader_defs() {
renderable
.render_resource_assignments
.pipeline_specialization
.shader_specialization
.shader_defs
.extend(shader_defs)
}
}
pub fn asset_handle_shader_def_system<T>() -> Box<dyn Schedulable>
where
pub fn asset_handle_shader_def_system<T>(
asset_storage: Resource<AssetStorage<T>>,
asset_handle: Ref<Handle<T>>,
mut renderable: RefMut<Renderable>,
) where
T: AsUniforms + Send + Sync + 'static,
{
SystemBuilder::new(format!(
"asset_handle_shader_def::{}",
std::any::type_name::<T>()
))
.read_resource::<AssetStorage<T>>()
.with_query(<(Read<Handle<T>>, Write<Renderable>)>::query())
.build(|_, world, asset_storage, query| {
for (uniform_handle, mut renderable) in query.iter_mut(world) {
if !renderable.is_visible || renderable.is_instanced {
continue;
}
if !renderable.is_visible || renderable.is_instanced {
return;
}
let uniforms = asset_storage.get(&uniform_handle).unwrap();
if let Some(shader_defs) = uniforms.get_shader_defs() {
renderable
.render_resource_assignments
.pipeline_specialization
.shader_specialization
.shader_defs
.extend(shader_defs)
}
}
})
let uniforms = asset_storage.get(&asset_handle).unwrap();
if let Some(shader_defs) = uniforms.get_shader_defs() {
renderable
.render_resource_assignments
.pipeline_specialization
.shader_specialization
.shader_defs
.extend(shader_defs)
}
}
pub fn asset_handle_batcher_system<T>() -> Box<dyn Schedulable>

View file

@ -6,7 +6,7 @@ fn main() {
.add_startup_system(setup)
.add_system_to_stage(
stage::POST_UPDATE,
shader::asset_handle_shader_def_system::<MyMaterial>(),
shader::asset_handle_shader_def_system::<MyMaterial>.system(),
)
.run();
}

View file

@ -5,7 +5,7 @@ fn main() {
App::build()
.add_default_plugins()
.add_event::<MyEvent>()
.add_startup_system(setup)
.add_startup_system(setup_system)
.add_system_init(built_system)
.add_system(simple_system.system())
.add_system(closure_system())
@ -22,7 +22,7 @@ struct X(usize);
struct Y(usize);
// add our resources and entities
fn setup(world: &mut World, resources: &mut Resources) {
fn setup_system(world: &mut World, resources: &mut Resources) {
resources.insert(A(0));
world.insert((), vec![(X(0), Y(1)), (X(2), Y(3))]);
}