cargo fmt

This commit is contained in:
Carter Anderson 2020-05-13 18:05:18 -07:00
parent 6381611e89
commit 2bcb8a2a41
27 changed files with 76 additions and 105 deletions

View file

@ -232,7 +232,10 @@ impl<T> Events<T> {
}
}
pub fn extend<I>(&mut self, events: I) where I: Iterator<Item = T> {
pub fn extend<I>(&mut self, events: I)
where
I: Iterator<Item = T>,
{
for event in events {
self.send(event);
}

View file

@ -80,7 +80,8 @@ pub fn run_on_hierarchy_subworld_mut<T>(
input: T,
run: &mut dyn FnMut(&mut SubWorld, Entity, T) -> Option<T>,
child_result_action: &mut dyn FnMut(T, T) -> T,
) -> Option<T> where
) -> Option<T>
where
T: Copy,
{
// TODO: not a huge fan of this pattern. are there ways to do recursive updates in legion without allocations?
@ -99,7 +100,8 @@ pub fn run_on_hierarchy_subworld_mut<T>(
if let Some(mut result) = result {
if let Some(children) = children {
for child in children {
let child_result = run_on_hierarchy_subworld_mut(world, child, result, run, child_result_action);
let child_result =
run_on_hierarchy_subworld_mut(world, child, result, run, child_result_action);
if let Some(child_result) = child_result {
result = child_result_action(result, child_result)
}

View file

@ -41,9 +41,7 @@ impl<'a, T: 'a> Res<'a, T> {
}
#[inline(always)]
pub fn map<K: 'a, F: FnMut(&T) -> &K>(&self, mut f: F) -> Res<'a, K> {
Res::new(f(&self))
}
pub fn map<K: 'a, F: FnMut(&T) -> &K>(&self, mut f: F) -> Res<'a, K> { Res::new(f(&self)) }
}
impl<'a, T: 'a> Deref for Res<'a, T> {

View file

@ -25,19 +25,14 @@ pub trait ForwardPbrRenderGraphBuilder {
impl ForwardPbrRenderGraphBuilder for RenderGraph {
fn add_pbr_graph(&mut self, resources: &Resources) -> &mut Self {
self.add_system_node(
node::LOCAL_TO_WORLD,
UniformNode::<LocalToWorld>::new(true)
);
self.add_system_node(node::LOCAL_TO_WORLD, UniformNode::<LocalToWorld>::new(true));
self.add_system_node(
node::STANDARD_MATERIAL,
AssetUniformNode::<StandardMaterial>::new(true)
AssetUniformNode::<StandardMaterial>::new(true),
);
self.add_system_node(node::LIGHTS, LightsNode::new(10));
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
let mut pipelines = resources
.get_mut::<Assets<PipelineDescriptor>>()
.unwrap();
let mut pipelines = resources.get_mut::<Assets<PipelineDescriptor>>().unwrap();
{
let main_pass: &mut PassNode = self
.get_node_mut(base_render_graph::node::MAIN_PASS)

View file

@ -10,7 +10,7 @@ pub enum TextureAttachment {
impl TextureAttachment {
pub fn get_resource(&self) -> Option<RenderResource> {
if let TextureAttachment::RenderResource(render_resource) = self {
if let TextureAttachment::RenderResource(render_resource) = self {
Some(*render_resource)
} else {
None

View file

@ -213,9 +213,8 @@ pub fn update_shader_assignments(world: &mut World, resources: &Resources) {
let mut pipeline_compiler = resources.get_mut::<PipelineCompiler>().unwrap();
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
let vertex_buffer_descriptors = resources.get::<VertexBufferDescriptors>().unwrap();
let mut pipeline_descriptor_storage = resources
.get_mut::<Assets<PipelineDescriptor>>()
.unwrap();
let mut pipeline_descriptor_storage =
resources.get_mut::<Assets<PipelineDescriptor>>().unwrap();
// reset assignments so they are updated every frame
shader_pipeline_assignments.assignments = HashMap::new();

View file

@ -41,11 +41,7 @@ impl RenderGraph {
self.add_node_nameless(node)
}
pub fn add_system_node<T>(
&mut self,
name: impl Into<Cow<'static, str>>,
node: T,
) -> NodeId
pub fn add_system_node<T>(&mut self, name: impl Into<Cow<'static, str>>, node: T) -> NodeId
where
T: SystemNode + 'static,
{
@ -313,7 +309,8 @@ mod tests {
use super::RenderGraph;
use crate::{
render_graph::{Edge, Node, NodeId, RenderGraphError, ResourceSlotInfo, ResourceSlots},
renderer::RenderContext, shader::FieldBindType,
renderer::RenderContext,
shader::FieldBindType,
};
use legion::prelude::{Resources, World};
use std::{collections::HashSet, iter::FromIterator};

View file

@ -1,6 +1,7 @@
use crate::{
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
renderer::RenderContext, shader::FieldBindType,
renderer::RenderContext,
shader::FieldBindType,
};
use bevy_app::{EventReader, Events};
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};

View file

@ -1,7 +1,8 @@
use crate::{
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
renderer::RenderContext,
texture::TextureDescriptor, shader::FieldBindType,
shader::FieldBindType,
texture::TextureDescriptor,
};
use bevy_app::{EventReader, Events};
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};

View file

@ -264,7 +264,8 @@ mod tests {
use super::{DependentNodeStager, OrderedJob, RenderGraphStager, Stage};
use crate::{
render_graph::{Node, NodeId, RenderGraph, ResourceSlotInfo, ResourceSlots},
renderer::RenderContext, shader::FieldBindType,
renderer::RenderContext,
shader::FieldBindType,
};
use legion::prelude::{Resources, World};

View file

@ -2,7 +2,8 @@ use super::RenderResource;
use crate::pipeline::{BindGroupDescriptor, BindGroupDescriptorId, PipelineSpecialization};
use std::{
collections::{hash_map::DefaultHasher, HashMap, HashSet},
hash::{Hash, Hasher}, ops::Range,
hash::{Hash, Hasher},
ops::Range,
};
use uuid::Uuid;
@ -39,8 +40,7 @@ pub struct RenderResourceAssignments {
pub id: RenderResourceAssignmentsId,
render_resources: HashMap<String, RenderResourceAssignment>,
vertex_buffers: HashMap<String, (RenderResource, Option<RenderResource>)>,
bind_group_resource_sets:
HashMap<BindGroupDescriptorId, RenderResourceSet>,
bind_group_resource_sets: HashMap<BindGroupDescriptorId, RenderResourceSet>,
dirty_bind_groups: HashSet<BindGroupDescriptorId>,
pub pipeline_specialization: PipelineSpecialization,
}
@ -52,8 +52,7 @@ impl RenderResourceAssignments {
pub fn set(&mut self, name: &str, assignment: RenderResourceAssignment) {
self.try_set_dirty(name, &assignment);
self.render_resources
.insert(name.to_string(), assignment);
self.render_resources.insert(name.to_string(), assignment);
}
fn try_set_dirty(&mut self, name: &str, assignment: &RenderResourceAssignment) {
@ -126,7 +125,11 @@ impl RenderResourceAssignments {
if let Some(assignment) = self.get(&binding_descriptor.name) {
let resource = assignment.get_resource();
resource.hash(&mut hasher);
if let RenderResourceAssignment::Buffer { dynamic_index: Some(index), .. } = assignment {
if let RenderResourceAssignment::Buffer {
dynamic_index: Some(index),
..
} = assignment
{
indices.push(*index);
}
} else {

View file

@ -1,4 +1,4 @@
use crate::{texture::TextureDescriptor, render_resource::BufferUsage};
use crate::{render_resource::BufferUsage, texture::TextureDescriptor};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct BufferInfo {

View file

@ -65,12 +65,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
self.add_resource_info(resource, ResourceInfo::Buffer(buffer_info));
resource
}
fn create_shader_module(
&self,
_shader_handle: Handle<Shader>,
_shaders: &Assets<Shader>,
) {
}
fn create_shader_module(&self, _shader_handle: Handle<Shader>, _shaders: &Assets<Shader>) {}
fn remove_buffer(&self, resource: RenderResource) {
self.resource_info.write().unwrap().remove(&resource);
}
@ -129,10 +124,5 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
None
}
}
fn create_shader_module_from_source(
&self,
_shader_handle: Handle<Shader>,
_shader: &Shader,
) {
}
fn create_shader_module_from_source(&self, _shader_handle: Handle<Shader>, _shader: &Shader) {}
}

View file

@ -40,16 +40,8 @@ pub trait RenderResourceContext: Downcast + Send + Sync + 'static {
setup_data: &mut dyn FnMut(&mut [u8], &dyn RenderResourceContext),
) -> RenderResource;
fn create_buffer_with_data(&self, buffer_info: BufferInfo, data: &[u8]) -> RenderResource;
fn create_shader_module(
&self,
shader_handle: Handle<Shader>,
shaders: &Assets<Shader>,
);
fn create_shader_module_from_source(
&self,
shader_handle: Handle<Shader>,
shader: &Shader,
);
fn create_shader_module(&self, shader_handle: Handle<Shader>, shaders: &Assets<Shader>);
fn create_shader_module_from_source(&self, shader_handle: Handle<Shader>, shader: &Shader);
fn remove_buffer(&self, resource: RenderResource);
fn remove_texture(&self, resource: RenderResource);
fn remove_sampler(&self, resource: RenderResource);

View file

@ -62,10 +62,7 @@ pub struct Shader {
impl Shader {
pub fn new(stage: ShaderStage, source: ShaderSource) -> Shader {
Shader {
stage,
source,
}
Shader { stage, source }
}
pub fn from_glsl(stage: ShaderStage, glsl: &str) -> Shader {
Shader {
@ -90,7 +87,10 @@ impl Shader {
pub fn reflect_layout(&self, enforce_bevy_conventions: bool) -> Option<ShaderLayout> {
if let ShaderSource::Spirv(ref spirv) = self.source {
Some(ShaderLayout::from_spirv(spirv.as_slice(), enforce_bevy_conventions))
Some(ShaderLayout::from_spirv(
spirv.as_slice(),
enforce_bevy_conventions,
))
} else {
panic!("Cannot reflect layout of non-SpirV shader. Try compiling this shader to SpirV first using self.get_spirv_shader()");
}

View file

@ -1,4 +1,4 @@
mod render;
mod font;
mod render;
pub use font::*;

View file

@ -76,9 +76,7 @@ impl UiRenderGraphBuilder for RenderGraph {
self.add_system_node("rect", UniformNode::<Rect>::new(false));
self.add_node_edge("rect", base_render_graph::node::MAIN_PASS)
.unwrap();
let mut pipelines = resources
.get_mut::<Assets<PipelineDescriptor>>()
.unwrap();
let mut pipelines = resources.get_mut::<Assets<PipelineDescriptor>>().unwrap();
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
pipelines.add_with_handle(UI_PIPELINE_HANDLE, build_ui_pipeline(&mut shaders));
let main_pass: &mut PassNode = self

View file

@ -67,7 +67,7 @@ fn update_node_entity(world: &mut SubWorld, entity: Entity, parent_rect: Rect) -
}
fn process_child_result(_parent_result: Rect, child_result: Rect) -> Rect {
// "earlier" children are sorted behind "later" children
// "earlier" children are sorted behind "later" children
let mut result = child_result.clone();
result.z_index -= UI_Z_STEP;
result

View file

@ -182,14 +182,17 @@ impl WgpuResourceDiagnosticsPlugin {
);
let mut bind_group_count = 0;
for bind_group in render_resource_context.resources.bind_groups.read().unwrap().values() {
for bind_group in render_resource_context
.resources
.bind_groups
.read()
.unwrap()
.values()
{
bind_group_count += bind_group.bind_groups.len();
}
diagnostics.add_measurement(
Self::BIND_GROUPS,
bind_group_count as f64,
);
diagnostics.add_measurement(Self::BIND_GROUPS, bind_group_count as f64);
diagnostics.add_measurement(
Self::BIND_GROUP_LAYOUTS,

View file

@ -6,7 +6,7 @@ use bevy_render::{
PassDescriptor, RenderPass, RenderPassColorAttachmentDescriptor,
RenderPassDepthStencilAttachmentDescriptor, TextureAttachment,
},
render_resource::{RenderResource, RenderResourceAssignments, RenderResourceAssignment},
render_resource::{RenderResource, RenderResourceAssignment, RenderResourceAssignments},
renderer::{RenderContext, RenderResourceContext},
texture::{Extent3d, TextureDescriptor},
};

View file

@ -294,11 +294,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
shader_modules.insert(shader_handle, shader_module);
}
fn create_shader_module(
&self,
shader_handle: Handle<Shader>,
shaders: &Assets<Shader>,
) {
fn create_shader_module(&self, shader_handle: Handle<Shader>, shaders: &Assets<Shader>) {
if self
.resources
.shader_modules

View file

@ -29,11 +29,12 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
}
fn set_viewport(&mut self, x: f32, y: f32, w: f32, h: f32, min_depth: f32, max_depth: f32) {
self.render_pass.set_viewport(x, y, w, h, min_depth, max_depth);
self.render_pass
.set_viewport(x, y, w, h, min_depth, max_depth);
}
fn set_stencil_reference(&mut self, reference: u32) {
self.render_pass.set_stencil_reference(reference);
self.render_pass.set_stencil_reference(reference);
}
fn set_index_buffer(&mut self, resource: RenderResource, offset: u64) {
@ -47,8 +48,7 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
}
fn draw(&mut self, vertices: Range<u32>, instances: Range<u32>) {
self.render_pass
.draw(vertices, instances);
self.render_pass.draw(vertices, instances);
}
fn set_render_resources(
@ -99,16 +99,16 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
{
if let Some(bind_group_info) = self.render_resources.bind_groups.get(&bind_group.id)
{
if let Some(wgpu_bind_group) =
bind_group_info.bind_groups.get(&resource_set.id)
if let Some(wgpu_bind_group) = bind_group_info.bind_groups.get(&resource_set.id)
{
const EMPTY: &'static [u32] = &[];
let dynamic_uniform_indices =
if let Some(ref dynamic_uniform_indices) = resource_set.dynamic_uniform_indices {
dynamic_uniform_indices.as_slice()
} else {
EMPTY
};
let dynamic_uniform_indices = if let Some(ref dynamic_uniform_indices) =
resource_set.dynamic_uniform_indices
{
dynamic_uniform_indices.as_slice()
} else {
EMPTY
};
// don't bind bind groups if they are already set
// TODO: these checks come at a performance cost. make sure it's worth it!

View file

@ -42,10 +42,7 @@ struct EventListenerState {
}
// prints events as they come in
fn event_listener_system(
mut state: ResMut<EventListenerState>,
my_events: Res<Events<MyEvent>>,
) {
fn event_listener_system(mut state: ResMut<EventListenerState>, my_events: Res<Events<MyEvent>>) {
for my_event in state.my_event_reader.iter(&my_events) {
println!("{}", my_event.message);
}

View file

@ -21,10 +21,7 @@ struct State {
}
/// adjusts move state based on keyboard input
fn collect_input(
mut state: ResMut<State>,
keyboard_input_events: Res<Events<KeyboardInput>>,
) {
fn collect_input(mut state: ResMut<State>, keyboard_input_events: Res<Events<KeyboardInput>>) {
for event in state.event_reader.iter(&keyboard_input_events) {
match event {
KeyboardInput {

View file

@ -55,8 +55,7 @@ fn setup(
))),
}));
render_graph
.add_system_node("my_material", AssetUniformNode::<MyMaterial>::new(true));
render_graph.add_system_node("my_material", AssetUniformNode::<MyMaterial>::new(true));
let main_pass: &mut PassNode = render_graph.get_node_mut("main_pass").unwrap();
main_pass.add_pipeline(
pipeline_handle,

View file

@ -64,8 +64,7 @@ fn setup(
"#,
))),
}));
render_graph
.add_system_node("my_material", AssetUniformNode::<MyMaterial>::new(true));
render_graph.add_system_node("my_material", AssetUniformNode::<MyMaterial>::new(true));
let main_pass: &mut PassNode = render_graph.get_node_mut("main_pass").unwrap();
main_pass.add_pipeline(
pipeline_handle,

View file

@ -63,17 +63,17 @@ pub use bevy_input as input;
pub use bevy_pbr as pbr;
#[cfg(feature = "render")]
pub use bevy_render as render;
#[cfg(feature = "text")]
pub use bevy_text as text;
#[cfg(feature = "serialization")]
pub use bevy_serialization as serialization;
#[cfg(feature = "text")]
pub use bevy_text as text;
#[cfg(feature = "transform")]
pub use bevy_transform as transform;
#[cfg(feature = "ui")]
pub use bevy_ui as ui;
#[cfg(feature = "wgpu")]
pub use bevy_wgpu as wgpu;
#[cfg(feature = "window")]
pub use bevy_window as window;
#[cfg(feature = "winit")]
pub use bevy_winit as winit;
#[cfg(feature = "wgpu")]
pub use bevy_wgpu as wgpu;