cargo fmt

This commit is contained in:
Carter Anderson 2020-04-04 12:43:16 -07:00
parent 5cbf606ef7
commit ef8c85f0c7
34 changed files with 123 additions and 88 deletions

View file

@ -1,7 +1,10 @@
use bevy::prelude::*;
fn main() {
App::build().add_default_plugins().add_setup_system(setup_system()).run();
App::build()
.add_default_plugins()
.add_setup_system(setup_system())
.run();
}
pub fn setup_system() -> Box<dyn Schedulable> {

View file

@ -40,7 +40,7 @@ fn setup(world: &mut World, resources: &mut Resources) {
mesh: quad_handle,
material: material_handle,
translation: Translation::new(0.0, 0.0, 0.0),
rotation: Rotation::from_euler_angles(0.0, std::f32::consts::PI / 3.0 , 0.0),
rotation: Rotation::from_euler_angles(0.0, std::f32::consts::PI / 3.0, 0.0),
..Default::default()
})
// textured quad modulated

View file

@ -5,9 +5,9 @@ use crate::{
},
core::{CorePlugin, Events},
legion::prelude::{Resources, Runnable, Schedulable, Schedule, Universe, World},
window::WindowPlugin,
render::RenderPlugin,
ui::UiPlugin,
window::WindowPlugin,
};
use std::collections::HashMap;

View file

@ -1,8 +1,8 @@
mod app;
mod app_builder;
pub mod system_stage;
pub mod plugin;
pub mod schedule_runner;
pub mod system_stage;
pub use app::App;
pub use app_builder::AppBuilder;

View file

@ -6,17 +6,13 @@ use std::{thread, time::Duration};
#[derive(Copy, Clone, Debug)]
pub enum RunMode {
Loop {
wait: Option<Duration>,
},
Loop { wait: Option<Duration> },
Once,
}
impl Default for RunMode {
fn default() -> Self {
RunMode::Loop {
wait: None,
}
RunMode::Loop { wait: None }
}
}
@ -32,7 +28,7 @@ impl AppPlugin for ScheduleRunner {
RunMode::Once => {
app.schedule.execute(&mut app.world, &mut app.resources);
}
RunMode::Loop { wait }=> loop {
RunMode::Loop { wait } => loop {
app.schedule.execute(&mut app.world, &mut app.resources);
if let Some(wait) = wait {
thread::sleep(wait);

View file

@ -23,7 +23,10 @@ impl<T> Handle<T> {
}
}
pub fn from_untyped(untyped_handle: HandleUntyped) -> Option<Handle<T>> where T: 'static {
pub fn from_untyped(untyped_handle: HandleUntyped) -> Option<Handle<T>>
where
T: 'static,
{
if TypeId::of::<T>() == untyped_handle.type_id {
Some(Handle::new(untyped_handle.id))
} else {
@ -96,7 +99,8 @@ where
T: 'static,
{
fn from(handle: HandleUntyped) -> Self {
Handle::from_untyped(handle).expect("attempted to convert untyped handle to incorrect typed handle")
Handle::from_untyped(handle)
.expect("attempted to convert untyped handle to incorrect typed handle")
}
}

View file

@ -1,6 +1,6 @@
use super::Time;
use crate::app::{plugin::AppPlugin, AppBuilder};
use bevy_transform::transform_system_bundle;
use super::Time;
#[derive(Default)]
pub struct CorePlugin;
@ -11,8 +11,7 @@ impl AppPlugin for CorePlugin {
app = app.add_system(transform_system);
}
app
.add_resource(Time::new())
app.add_resource(Time::new())
}
fn name(&self) -> &'static str {

View file

@ -20,7 +20,7 @@ enum State {
/// # Example
/// ```
/// use bevy::core::event::Events;
///
///
/// struct MyEvent {
/// value: usize
/// }

View file

@ -1,9 +1,9 @@
pub mod bytes;
mod time;
mod core_plugin;
pub mod event;
mod time;
pub use bytes::*;
pub use time::*;
pub use core_plugin::*;
pub use event::*;
pub use event::*;
pub use time::*;

View file

@ -2,7 +2,7 @@ use super::{
diagnostics::{frame_time_diagnostic_system, print_diagnostics_system},
Diagnostics,
};
use crate::{app::AppBuilder, app::plugin::AppPlugin};
use crate::app::{plugin::AppPlugin, AppBuilder};
use std::time::Duration;
pub struct DiagnosticsPlugin {

View file

@ -93,4 +93,4 @@ pub fn print_diagnostics_debug_system(wait: Duration) -> Box<dyn Schedulable> {
}
}
})
}
}

View file

@ -1,5 +1,5 @@
pub mod diagnostics;
mod diagnostic_plugin;
pub mod diagnostics;
pub use diagnostic_plugin::*;
use std::{
@ -36,10 +36,8 @@ impl Diagnostic {
}
self.sum += value;
self.history.push_front(DiagnosticMeasurement {
time,
value,
});
self.history
.push_front(DiagnosticMeasurement { time, value });
}
pub fn new(id: DiagnosticId, name: &str, max_history_length: usize) -> Diagnostic {
@ -74,22 +72,21 @@ impl Diagnostic {
pub fn duration(&self) -> Option<Duration> {
if self.history.len() < 2 {
return None
return None;
}
if let Some(oldest) = self.history.back() {
if let Some(newest) = self.history.front() {
return newest.time.duration_since(oldest.time).ok()
return newest.time.duration_since(oldest.time).ok();
}
}
return None
return None;
}
pub fn get_max_history_length(&self) -> usize {
self.max_history_length
}
}
#[derive(Default)]
@ -111,7 +108,9 @@ impl Diagnostics {
}
pub fn get_measurement(&self, id: DiagnosticId) -> Option<&DiagnosticMeasurement> {
self.diagnostics.get(&id).and_then(|diagnostic| diagnostic.history.front())
self.diagnostics
.get(&id)
.and_then(|diagnostic| diagnostic.history.front())
}
pub fn add_measurement(&mut self, id: DiagnosticId, value: f64) {
@ -120,7 +119,7 @@ impl Diagnostics {
}
}
pub fn iter(&self) -> impl Iterator<Item=&Diagnostic> {
pub fn iter(&self) -> impl Iterator<Item = &Diagnostic> {
self.diagnostics.values()
}
}
}

View file

@ -1,8 +1,7 @@
pub use crate::{
app::{plugin::AppPlugin, App, AppBuilder},
asset::{Asset, AssetStorage, Handle},
window::{Window, Windows, WindowDescriptor, WindowPlugin},
core::{Events, EventReader, GetEventReader, Time},
core::{EventReader, Events, GetEventReader, Time},
diagnostic::DiagnosticsPlugin,
ecs,
ecs::{
@ -21,6 +20,7 @@ pub use crate::{
ActiveCamera, ActiveCamera2d, Camera, CameraType, Color, ColorSource, Light, Renderable,
},
ui::{Anchors, Margins, Node},
window::{Window, WindowDescriptor, WindowPlugin, Windows},
};
pub use bevy_derive::*;
pub use bevy_transform::prelude::*;

View file

@ -76,24 +76,33 @@ impl DrawTarget for AssignedBatchesDrawTarget {
let mut global_render_resource_assignments =
resources.get_mut::<RenderResourceAssignments>().unwrap();
log::debug!("setting up batch bind groups for pipeline: {:?}", pipeline_handle);
log::debug!(
"setting up batch bind groups for pipeline: {:?}",
pipeline_handle
);
log::trace!("setting up global bind groups");
renderer.setup_bind_groups(&mut global_render_resource_assignments, pipeline_descriptor);
for batch in asset_batches.get_batches_mut() {
log::debug!("setting up batch bind groups: {:?}", batch.render_resource_assignments.id);
log::trace!("{:#?}", batch);
renderer.setup_bind_groups(
&mut batch.render_resource_assignments,
pipeline_descriptor,
log::debug!(
"setting up batch bind groups: {:?}",
batch.render_resource_assignments.id
);
log::trace!("{:#?}", batch);
renderer.setup_bind_groups(&mut batch.render_resource_assignments, pipeline_descriptor);
for batched_entity in batch.entities.iter() {
let mut renderable = world.get_component_mut::<Renderable>(*batched_entity).unwrap();
let mut renderable = world
.get_component_mut::<Renderable>(*batched_entity)
.unwrap();
if !renderable.is_visible || renderable.is_instanced {
continue;
}
log::trace!("setting up entity bind group {:?} for batch {:?}", batched_entity, batch.render_resource_assignments.id);
log::trace!(
"setting up entity bind group {:?} for batch {:?}",
batched_entity,
batch.render_resource_assignments.id
);
renderer.setup_bind_groups(
&mut renderable.render_resource_assignments,
pipeline_descriptor,

View file

@ -2,12 +2,8 @@ use crate::{asset::Asset, math::*, render::Vertex};
pub enum MeshType {
Cube,
Plane {
size: f32,
},
Quad {
size: Vec2,
},
Plane { size: f32 },
Quad { size: Vec2 },
}
pub struct Mesh {
@ -20,9 +16,7 @@ impl Asset<MeshType> for Mesh {
let (vertices, indices) = match descriptor {
MeshType::Cube => create_cube(),
MeshType::Plane { size } => create_plane(size),
MeshType::Quad {
size
} => create_quad(size),
MeshType::Quad { size } => create_quad(size),
};
Mesh { vertices, indices }

View file

@ -1,8 +1,8 @@
mod camera;
pub mod mesh;
pub mod render_graph;
pub mod shader;
mod render_plugin;
pub mod shader;
mod color;
mod light;
@ -11,8 +11,8 @@ mod vertex;
pub use camera::*;
pub use color::*;
pub use light::*;
pub use renderable::*;
pub use render_plugin::*;
pub use renderable::*;
pub use vertex::Vertex;

View file

@ -1,5 +1,5 @@
use super::UniformProperty;
use crate::render::texture::{TextureComponentType, TextureViewDimension, TextureFormat};
use crate::render::texture::{TextureComponentType, TextureFormat, TextureViewDimension};
#[derive(Hash, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct BindingDescriptor {

View file

@ -57,7 +57,7 @@ impl PipelineCompiler {
// set binding uniforms to dynamic if render resource assignments use dynamic
// TODO: this breaks down if different assignments have different "dynamic" status or if the dynamic status changes.
// the fix would be to add "dynamic bindings" to the existing shader_def sets. this would ensure new pipelines are generated
// for all permutations of dynamic/non-dynamic
// for all permutations of dynamic/non-dynamic
for bind_group in layout.bind_groups.iter_mut() {
for binding in bind_group.bindings.iter_mut() {
if let Some(render_resource) = render_resource_assignments.get(&binding.name) {
@ -236,7 +236,11 @@ impl ShaderPipelineAssignments {
}
// TODO: make this a system
pub fn update_shader_assignments(world: &mut World, resources: &mut Resources, renderer: &dyn Renderer) {
pub fn update_shader_assignments(
world: &mut World,
resources: &mut Resources,
renderer: &dyn Renderer,
) {
// PERF: this seems like a lot of work for things that don't change that often.
// lots of string + hashset allocations. sees uniform_resource_provider for more context
{

View file

@ -251,10 +251,9 @@ mod tests {
];
expected_batches.sort_by(|a, b| a.0.cmp(&b.0));
// copy ignored fields
batches
.iter()
.zip(expected_batches.iter_mut())
.for_each(|((_, ref actual), (_, ref mut expected))| copy_ignored_fields(actual, expected));
batches.iter().zip(expected_batches.iter_mut()).for_each(
|((_, ref actual), (_, ref mut expected))| copy_ignored_fields(actual, expected),
);
assert_eq!(
batches,
expected_batches

View file

@ -27,7 +27,10 @@ impl Batch {
}
}
pub fn get_handle<T>(&self) -> Option<Handle<T>> where T: 'static {
pub fn get_handle<T>(&self) -> Option<Handle<T>>
where
T: 'static,
{
self.handles
.iter()
.map(|h| Handle::from_untyped(*h))

View file

@ -1,5 +1,4 @@
use crate::{
window::WindowResized,
prelude::*,
render::{
render_resource::{
@ -7,6 +6,7 @@ use crate::{
},
renderer::Renderer,
},
window::WindowResized,
};
use zerocopy::AsBytes;

View file

@ -1,5 +1,4 @@
use crate::{
window::WindowResized,
prelude::*,
render::{
render_resource::{
@ -9,6 +8,7 @@ use crate::{
renderer::Renderer,
ActiveCamera, Camera,
},
window::WindowResized,
};
use zerocopy::AsBytes;

View file

@ -1,11 +1,11 @@
use crate::{
window::Windows,
prelude::World,
render::{
render_resource::{RenderResourceAssignments, ResourceProvider},
renderer::Renderer,
texture::TextureDescriptor,
},
window::Windows,
};
use legion::prelude::Resources;

View file

@ -42,12 +42,22 @@ impl MeshResourceProvider {
}
}
fn setup_mesh_resources(renderer: &mut dyn Renderer, mesh_storage: &mut AssetStorage<Mesh>, handle: Handle<Mesh>, render_resource_assignments: &mut RenderResourceAssignments) {
fn setup_mesh_resources(
renderer: &mut dyn Renderer,
mesh_storage: &mut AssetStorage<Mesh>,
handle: Handle<Mesh>,
render_resource_assignments: &mut RenderResourceAssignments,
) {
let (vertex_buffer, index_buffer) = if let Some(vertex_buffer) = renderer
.get_render_resources()
.get_mesh_vertices_resource(handle)
{
(vertex_buffer, renderer.get_render_resources().get_mesh_indices_resource(handle))
(
vertex_buffer,
renderer
.get_render_resources()
.get_mesh_indices_resource(handle),
)
} else {
let mesh_asset = mesh_storage.get(&handle).unwrap();
let vertex_buffer = renderer.create_buffer_with_data(
@ -109,7 +119,12 @@ impl ResourceProvider for MeshResourceProvider {
for batch in batches {
let handle = batch.get_handle::<Mesh>().unwrap();
log::trace!("setup mesh for {:?}", batch.render_resource_assignments.id);
Self::setup_mesh_resources(renderer, &mut mesh_storage, handle, &mut batch.render_resource_assignments);
Self::setup_mesh_resources(
renderer,
&mut mesh_storage,
handle,
&mut batch.render_resource_assignments,
);
}
}
};

View file

@ -18,7 +18,7 @@ use zerocopy::{AsBytes, FromBytes};
#[repr(C)]
#[derive(Clone, Copy, Debug, AsBytes, FromBytes, Uniforms)]
#[uniform(bevy_path="crate")]
#[uniform(bevy_path = "crate")]
pub struct Rect {
#[uniform(instance)]
pub position: [f32; 2],

View file

@ -538,7 +538,7 @@ where
new_capacity,
item_size
);
buffer_array_status.buffer = Some(buffer);
}
}

View file

@ -10,7 +10,8 @@ pub use wgpu_resources::*;
use crate::{
app::{plugin::AppPlugin, system_stage, AppBuilder},
core::Events,
render::renderer::Renderer, window::{WindowCreated, WindowResized},
render::renderer::Renderer,
window::{WindowCreated, WindowResized},
};
use legion::prelude::*;

View file

@ -6,7 +6,7 @@ use crate::{
use bevy_derive::Uniforms;
#[derive(Uniforms)]
#[uniform(bevy_path="crate")]
#[uniform(bevy_path = "crate")]
pub struct StandardMaterial {
#[uniform(instance)]
pub albedo: Color,

View file

@ -5,7 +5,7 @@ use bevy_derive::Uniforms;
#[repr(C)]
#[derive(Clone, Copy, AsBytes, FromBytes, Uniforms)]
#[uniform(bevy_path="crate")]
#[uniform(bevy_path = "crate")]
pub struct Vertex {
#[uniform(vertex)]
pub position: [f32; 4],

View file

@ -15,8 +15,7 @@ pub struct UiPlugin;
impl AppPlugin for UiPlugin {
fn build(&self, app: AppBuilder) -> AppBuilder {
app
.add_system(ui_update_system())
app.add_system(ui_update_system())
}
fn name(&self) -> &'static str {
"UI"

View file

@ -1,12 +1,12 @@
mod events;
mod window_plugin;
mod windows;
#[cfg(feature = "winit")]
pub mod winit;
mod events;
mod windows;
mod window_plugin;
pub use events::*;
pub use windows::*;
pub use window_plugin::*;
pub use windows::*;
use uuid::Uuid;
@ -56,4 +56,4 @@ impl Default for WindowDescriptor {
vsync: true,
}
}
}
}

View file

@ -1,5 +1,8 @@
use super::{CreateWindow, WindowCreated, WindowResized, Windows, WindowDescriptor};
use crate::{core::Events, app::{plugin::AppPlugin, AppBuilder}};
use super::{CreateWindow, WindowCreated, WindowDescriptor, WindowResized, Windows};
use crate::{
app::{plugin::AppPlugin, AppBuilder},
core::Events,
};
pub struct WindowPlugin {
pub primary_window: Option<WindowDescriptor>,
@ -15,7 +18,8 @@ impl Default for WindowPlugin {
impl AppPlugin for WindowPlugin {
fn build(&self, mut app: AppBuilder) -> AppBuilder {
app = app.add_event::<WindowResized>()
app = app
.add_event::<WindowResized>()
.add_event::<CreateWindow>()
.add_event::<WindowCreated>()
.add_resource(Windows::default());
@ -23,7 +27,7 @@ impl AppPlugin for WindowPlugin {
if let Some(ref primary_window_descriptor) = self.primary_window {
let mut create_window_event = app.resources.get_mut::<Events<CreateWindow>>().unwrap();
create_window_event.send(CreateWindow {
descriptor: primary_window_descriptor.clone(),
descriptor: primary_window_descriptor.clone(),
});
}

View file

@ -109,7 +109,13 @@ fn handle_create_window_events(
winit_windows.create_window(event_loop, &window);
let window_id = window.id;
windows.add(window);
let is_primary = windows.get_primary().map(|primary| primary.id == window_id).unwrap_or(false);
window_created_events.send(WindowCreated { id: window_id, is_primary });
let is_primary = windows
.get_primary()
.map(|primary| primary.id == window_id)
.unwrap_or(false);
window_created_events.send(WindowCreated {
id: window_id,
is_primary,
});
}
}

View file

@ -1,4 +1,4 @@
use crate::{window::WindowId, prelude::*};
use crate::{prelude::*, window::WindowId};
use std::collections::HashMap;
#[derive(Default)]