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

[Slightly less WIP] Design SystemParams to hold state #1364

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions crates/bevy_ecs/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use stage::*;
pub use stage_executor::*;
pub use state::*;

use crate::{BoxedSystem, IntoSystem, Resources, System, World};
use crate::{AsSystem, BoxedSystem, IntoSystem, Resources, System, World};
use bevy_utils::HashMap;

#[derive(Default)]
Expand Down Expand Up @@ -47,11 +47,12 @@ impl Schedule {
self
}

pub fn set_run_criteria<S: System<In = (), Out = ShouldRun>>(
&mut self,
system: S,
) -> &mut Self {
self.run_criteria = Some(Box::new(system.system()));
pub fn set_run_criteria<S: AsSystem>(&mut self, system: S) -> &mut Self
where
S::System: System<In = (), Out = ShouldRun>,
{
// TODO(before-merge): Get resources here somehow
self.run_criteria = Some(Box::new(system.as_system(&mut Resources::default())));
self.run_criteria_initialized = false;
self
}
Expand Down Expand Up @@ -99,11 +100,14 @@ impl Schedule {
self
}

pub fn add_system_to_stage<S: System<In = (), Out = ()>>(
pub fn add_system_to_stage<S: AsSystem>(
&mut self,
stage_name: &'static str,
system: S,
) -> &mut Self {
) -> &mut Self
where
S::System: System<In = (), Out = ()>,
{
let stage = self
.get_stage_mut::<SystemStage>(stage_name)
.unwrap_or_else(|| {
Expand All @@ -112,7 +116,7 @@ impl Schedule {
stage_name
)
});
stage.add_system(system.system());
stage.add_system(system.as_system(&mut Resources::default()));
self
}

Expand Down
12 changes: 8 additions & 4 deletions crates/bevy_ecs/src/schedule/stage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{any::TypeId, borrow::Cow};

use crate::{
ArchetypeComponent, BoxedSystem, Resources, System, SystemId, ThreadLocalExecution, TypeAccess,
World,
ArchetypeComponent, AsSystem, BoxedSystem, Resources, System, SystemId, ThreadLocalExecution,
TypeAccess, World,
};
use bevy_utils::HashSet;
use downcast_rs::{impl_downcast, Downcast};
Expand Down Expand Up @@ -78,8 +78,12 @@ impl SystemStage {
self
}

pub fn add_system<S: System<In = (), Out = ()>>(&mut self, system: S) -> &mut Self {
self.add_system_boxed(Box::new(system));
pub fn add_system<S: AsSystem>(&mut self, system: S) -> &mut Self
where
S::System: System<In = (), Out = ()>,
{
// TODO(before-merge): get the resources to here
self.add_system_boxed(Box::new(system.as_system(&mut Resources::default())));
self
}

Expand Down
Loading