Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible ECS System Params #798

Merged
merged 12 commits into from
Nov 8, 2020
Next Next commit
ecs: system params can be in any order, faster compiles, remove foreach
  • Loading branch information
cart committed Nov 8, 2020
commit af305cbadd2d79510800f1c15ac651807a7d9202
2 changes: 1 addition & 1 deletion crates/bevy_app/src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
plugin::Plugin,
stage, startup_stage, PluginGroup, PluginGroupBuilder,
};
use bevy_ecs::{FromResources, IntoQuerySystem, Resources, System, World};
use bevy_ecs::{FromResources, IntoSystem, Resources, System, World};

/// Configure [App]s using the builder pattern
pub struct AppBuilder {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
update_asset_storage_system, Asset, AssetLoader, AssetServer, Handle, HandleId, RefChange,
};
use bevy_app::{prelude::Events, AppBuilder};
use bevy_ecs::{FromResources, IntoQuerySystem, ResMut};
use bevy_ecs::{FromResources, IntoSystem, ResMut};
use bevy_type_registry::RegisterType;
use bevy_utils::HashMap;
use crossbeam_channel::Sender;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod prelude {
}

use bevy_app::{prelude::Plugin, AppBuilder};
use bevy_ecs::IntoQuerySystem;
use bevy_ecs::IntoSystem;
use bevy_type_registry::RegisterType;

/// Adds support for Assets to an App. Assets are typed collections with change tracking, which are added as App Resources.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_app::prelude::*;
use bevy_core::Time;
use bevy_ecs::{IntoQuerySystem, Res, ResMut};
use bevy_ecs::{IntoSystem, Res, ResMut};

/// Adds "frame time" diagnostic to an App, specifically "frame time", "fps" and "frame count"
#[derive(Default)]
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_diagnostic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Plugin for DiagnosticsPlugin {
app.init_resource::<Diagnostics>();
#[cfg(feature = "profiler")]
{
use bevy_ecs::IntoQuerySystem;
use bevy_ecs::IntoSystem;
app.add_resource::<Box<dyn bevy_ecs::Profiler>>(Box::new(
system_profiler::SystemProfiler::default(),
))
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_diagnostic/src/print_diagnostics_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_app::prelude::*;
use bevy_core::{Time, Timer};
use bevy_ecs::{IntoQuerySystem, Res, ResMut};
use bevy_ecs::{IntoSystem, Res, ResMut};
use std::time::Duration;

/// An App Plugin that prints diagnostics to the console
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ pub use world::*;
pub mod prelude {
pub use crate::{
resource::{ChangedRes, FromResources, Local, OrRes, Res, ResMut, Resource, Resources},
system::{
Commands, IntoForEachSystem, IntoQuerySystem, IntoThreadLocalSystem, Query, System,
},
system::{Commands, IntoSystem, IntoThreadLocalSystem, Query, System},
world::WorldBuilderSource,
Added, Bundle, Changed, Component, Entity, Mut, Mutated, Or, QuerySet, Ref, RefMut, With,
Without, World,
Expand Down
12 changes: 12 additions & 0 deletions crates/bevy_ecs/src/resource/resource_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ pub trait FetchResource<'a>: Sized {
}
}

pub trait ResourceFetchSelf {
#[allow(clippy::missing_safety_doc)]
unsafe fn get(resources: &Resources, system_id: Option<SystemId>) -> Self;
}

impl<'a, Q: ResourceQuery<Fetch=F>, F: FetchResource<'a, Item=Q>> ResourceFetchSelf for Q {
unsafe fn get(resources: &Resources, system_id: Option<SystemId>) -> Q {
let resources: &'a Resources = std::mem::transmute(resources);
<Q::Fetch as FetchResource<'a>>::get(resources, system_id)
}
}

impl<'a, T: Resource> ResourceQuery for Res<'a, T> {
type Fetch = FetchResourceRead<T>;
}
Expand Down
Loading