cargo fmt

This commit is contained in:
Carter Anderson 2020-04-30 22:30:51 -07:00
parent b11a7f177b
commit 3e3ab92ff5
13 changed files with 55 additions and 43 deletions

View File

@ -1,4 +1,4 @@
use legion::prelude::{Resources, ResourceMut}; use legion::prelude::{ResourceMut, Resources};
use std::marker::PhantomData; use std::marker::PhantomData;
struct EventInstance<T> { struct EventInstance<T> {
@ -225,7 +225,6 @@ where
} }
} }
pub trait GetEventReader { pub trait GetEventReader {
/// returns an [EventReader] of the given type /// returns an [EventReader] of the given type
fn get_event_reader<T>(&self) -> EventReader<T> fn get_event_reader<T>(&self) -> EventReader<T>

View File

@ -4,16 +4,16 @@ mod app_builder;
mod entity_archetype; mod entity_archetype;
mod event; mod event;
mod plugin; mod plugin;
mod resources;
pub mod schedule_plan; pub mod schedule_plan;
pub mod schedule_runner; pub mod schedule_runner;
pub mod stage; pub mod stage;
mod system; mod system;
mod resources;
pub use app::*; pub use app::*;
pub use app_builder::*; pub use app_builder::*;
pub use entity_archetype::*; pub use entity_archetype::*;
pub use event::*; pub use event::*;
pub use plugin::*; pub use plugin::*;
pub use system::*;
pub use resources::*; pub use resources::*;
pub use system::*;

View File

@ -14,7 +14,10 @@ where
} }
} }
impl<T> FromResources for EventReader<T> where T: Send + Sync + 'static { impl<T> FromResources for EventReader<T>
where
T: Send + Sync + 'static,
{
fn from_resources(resources: &mut Resources) -> Self { fn from_resources(resources: &mut Resources) -> Self {
resources.get_event_reader::<T>() resources.get_event_reader::<T>()
} }

View File

@ -1,9 +1,4 @@
use legion::{ use legion::prelude::{Resources, Runnable, Schedulable, World};
prelude::{
Resources,
Runnable, Schedulable, World,
},
};
pub enum System { pub enum System {
Schedulable(Box<dyn Schedulable>), Schedulable(Box<dyn Schedulable>),
ThreadLocal(Box<dyn Runnable>), ThreadLocal(Box<dyn Runnable>),

View File

@ -36,4 +36,4 @@ pub fn start_timer_system(mut time: ResourceMut<Time>) {
pub fn stop_timer_system(mut time: ResourceMut<Time>) { pub fn stop_timer_system(mut time: ResourceMut<Time>) {
time.stop(); time.stop();
} }

View File

@ -132,13 +132,9 @@ pub fn derive_resource(input: TokenStream) -> TokenStream {
let modules = get_modules(&ast); let modules = get_modules(&ast);
let bevy_app_path = get_path(&modules.bevy_app); let bevy_app_path = get_path(&modules.bevy_app);
let field_types = fields let field_types = fields.iter().map(|field| &field.ty);
.iter()
.map(|field| &field.ty);
let fields = fields let fields = fields.iter().map(|field| field.ident.as_ref().unwrap());
.iter()
.map(|field| field.ident.as_ref().unwrap());
let generics = ast.generics; let generics = ast.generics;
let (impl_generics, ty_generics, _where_clause) = generics.split_for_impl(); let (impl_generics, ty_generics, _where_clause) = generics.split_for_impl();

View File

@ -8,19 +8,18 @@ mod system_fn_types;
pub use bit_set; pub use bit_set;
pub use system::*; pub use system::*;
pub use system_fn::*; pub use system_fn::*;
pub use system_fn_types::{ResourceMut, Resource}; pub use system_fn_types::{Resource, ResourceMut};
pub mod prelude { pub mod prelude {
pub use crate::{ pub use crate::{
bit_set::BitSet, bit_set::BitSet,
// aliased preparedread and preparedwrite used by system_fn // aliased preparedread and preparedwrite used by system_fn
resource::{ resource::{ResourceSet, Resources},
ResourceSet, Resources,
},
schedule::{Executor, Runnable, Schedulable, Schedule}, schedule::{Executor, Runnable, Schedulable, Schedule},
IntoSystem, IntoSystem,
Resource,
ResourceMut,
System, System,
SystemBuilder, SystemBuilder,
Resource, ResourceMut,
}; };
} }

View File

@ -1,10 +1,21 @@
use crate::{schedule::{ArchetypeAccess, Runnable}, resource::{ use crate::{
PreparedRead, PreparedWrite, ResourceSet, ResourceTypeId, Resources, self resource::{self, PreparedRead, PreparedWrite, ResourceSet, ResourceTypeId, Resources},
}, QuerySet, SystemId, SubWorld, SystemAccess}; schedule::{ArchetypeAccess, Runnable},
use std::{marker::PhantomData, ops::{Deref, DerefMut}, hash::{Hasher, Hash}}; QuerySet, SubWorld, SystemAccess, SystemId,
use legion_core::{world::{World, WorldId}, storage::ComponentTypeId, borrow::{AtomicRefCell, RefMut}, command::CommandBuffer}; };
use tracing::{debug, span, info, Level};
use fxhash::FxHashMap; use fxhash::FxHashMap;
use legion_core::{
borrow::{AtomicRefCell, RefMut},
command::CommandBuffer,
storage::ComponentTypeId,
world::{World, WorldId},
};
use std::{
hash::{Hash, Hasher},
marker::PhantomData,
ops::{Deref, DerefMut},
};
use tracing::{debug, info, span, Level};
#[derive(Debug)] #[derive(Debug)]
pub struct Resource<'a, T: 'a> { pub struct Resource<'a, T: 'a> {
#[allow(dead_code)] #[allow(dead_code)]
@ -22,7 +33,12 @@ impl<'a, T: 'a> Clone for Resource<'a, T> {
impl<'a, T: 'a> Resource<'a, T> { impl<'a, T: 'a> Resource<'a, T> {
#[inline(always)] #[inline(always)]
fn new(resource: *const T) -> Self { Self { value: resource, _marker: PhantomData::default()} } fn new(resource: *const T) -> Self {
Self {
value: resource,
_marker: PhantomData::default(),
}
}
#[inline(always)] #[inline(always)]
pub fn map<K: 'a, F: FnMut(&T) -> &K>(&self, mut f: F) -> Resource<'a, K> { pub fn map<K: 'a, F: FnMut(&T) -> &K>(&self, mut f: F) -> Resource<'a, K> {
@ -106,7 +122,12 @@ impl<'a, T: 'a> Clone for ResourceMut<'a, T> {
impl<'a, T: 'a> ResourceMut<'a, T> { impl<'a, T: 'a> ResourceMut<'a, T> {
#[inline(always)] #[inline(always)]
fn new(resource: *mut T) -> Self { Self { value: resource, _marker: PhantomData::default()} } fn new(resource: *mut T) -> Self {
Self {
value: resource,
_marker: PhantomData::default(),
}
}
#[inline(always)] #[inline(always)]
pub fn map_into<K: 'a, F: FnMut(&mut T) -> K>(mut self, mut f: F) -> ResourceMut<'a, K> { pub fn map_into<K: 'a, F: FnMut(&mut T) -> K>(mut self, mut f: F) -> ResourceMut<'a, K> {
@ -179,7 +200,6 @@ impl<'a, T: resource::Resource> ResourceSet for ResourceMut<'a, T> {
fn write_types() -> Vec<ResourceTypeId> { Vec::new() } fn write_types() -> Vec<ResourceTypeId> { Vec::new() }
} }
impl<T: resource::Resource> ResourceSet for PreparedRead<T> { impl<T: resource::Resource> ResourceSet for PreparedRead<T> {
type PreparedResources = PreparedRead<T>; type PreparedResources = PreparedRead<T>;
@ -206,7 +226,6 @@ impl<T: resource::Resource> ResourceSet for PreparedWrite<T> {
fn write_types() -> Vec<ResourceTypeId> { vec![ResourceTypeId::of::<T>()] } fn write_types() -> Vec<ResourceTypeId> { vec![ResourceTypeId::of::<T>()] }
} }
/// The concrete type which contains the system closure provided by the user. This struct should /// The concrete type which contains the system closure provided by the user. This struct should
/// not be instantiated directly, and instead should be created using `SystemBuilder`. /// not be instantiated directly, and instead should be created using `SystemBuilder`.
/// ///
@ -336,4 +355,4 @@ where
) { ) {
(self.0)(commands, world, resources, queries); (self.0)(commands, world, resources, queries);
} }
} }

View File

@ -9,4 +9,4 @@ fn main() {
fn hello_world_system() { fn hello_world_system() {
println!("hello world"); println!("hello world");
} }

View File

@ -1,10 +1,11 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_input::system::exit_on_esc_system;
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_default_plugins()
.add_startup_system(setup) .add_startup_system(setup)
.add_system_init(bevy::input::system::exit_on_esc_system) .add_system_init(exit_on_esc_system)
.run(); .run();
} }

View File

@ -44,4 +44,4 @@ fn startup_system(
)), )),
..Default::default() ..Default::default()
}); });
} }

View File

@ -34,7 +34,10 @@
//! If you prefer it, you can also consume the individual bevy crates directly. //! If you prefer it, you can also consume the individual bevy crates directly.
#![feature(min_specialization)] #![feature(min_specialization)]
#![doc(html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png")] #![doc(
html_logo_url = "https://bevyengine.org/assets/icon.png",
html_favicon_url = "https://bevyengine.org/assets/icon.png"
)]
mod add_default_plugins; mod add_default_plugins;
pub mod prelude; pub mod prelude;

View File

@ -53,12 +53,9 @@ pub use legion::{
query::{IntoQuery, Query, Read, Tagged, TryRead, TryWrite, Write}, query::{IntoQuery, Query, Read, Tagged, TryRead, TryWrite, Write},
systems::{ systems::{
bit_set::BitSet, bit_set::BitSet,
resource::{ resource::{ResourceSet, Resources},
ResourceSet, Resources,
},
schedule::{Executor, Runnable, Schedulable, Schedule}, schedule::{Executor, Runnable, Schedulable, Schedule},
IntoSystem, SubWorld, SystemBuilder, IntoSystem, Resource, ResourceMut, SubWorld, SystemBuilder,
Resource, ResourceMut,
}, },
world::{Universe, World}, world::{Universe, World},
}; };