Skip to content

Commit

Permalink
Implement dynamic scheduling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders429 committed Aug 18, 2023
1 parent 9f3654d commit ef76b0c
Show file tree
Hide file tree
Showing 36 changed files with 751 additions and 3,637 deletions.
2 changes: 1 addition & 1 deletion src/hlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ macro_rules! define_null_uninstantiable {
};
}

define_null_uninstantiable!();
define_null!();

pub(crate) use define_null;
pub(crate) use define_null_uninstantiable;
Expand Down
1 change: 1 addition & 0 deletions src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(crate) use sealed::CanonicalParViews;
pub(crate) use sealed::{
Canonical,
CanonicalViews,
Claims,
Length,
};

Expand Down
10 changes: 10 additions & 0 deletions src/registry/sealed/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ use core::{

pub trait Claims {
type Claims: view::Claims + Clone + Debug + Eq + Hash + Send;

fn empty_claims() -> Self::Claims;
}

impl Claims for Null {
type Claims = claim::Null;

fn empty_claims() -> Self::Claims {
claim::Null
}
}

impl<C, R> Claims for (C, R)
Expand All @@ -28,4 +34,8 @@ where
R: Claims,
{
type Claims = (Claim, R::Claims);

fn empty_claims() -> Self::Claims {
(Claim::None, R::empty_claims())
}
}
10 changes: 10 additions & 0 deletions src/resource/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@ use core::{

pub trait Claims {
type Claims: view::Claims + Clone + Debug + Eq + Hash + Send + Default;

fn empty_claims() -> Self::Claims;
}

impl Claims for Null {
type Claims = claim::Null;

fn empty_claims() -> Self::Claims {
claim::Null
}
}

impl<Resource, Resources> Claims for (Resource, Resources)
where
Resources: Claims,
{
type Claims = (Claim, Resources::Claims);

fn empty_claims() -> Self::Claims {
(Claim::None, Resources::empty_claims())
}
}
3 changes: 2 additions & 1 deletion src/resource/contains/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub(crate) mod views;

mod resource;
mod views;

pub use resource::ContainsResource;
pub use views::ContainsViews;
Expand Down
60 changes: 52 additions & 8 deletions src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
//! Defining `System`s allows for reuse of querying logic in multiple places, as well as combining
//! `System`s together within a `Schedule` to allow them to be run in parallel.
//!
//! [`Schedule`]: trait@crate::system::schedule::Schedule
//! [`Schedule`]: crate::system::schedule::Schedule
//! [`System`]: crate::system::System
//! [`World`]: crate::world::World

Expand All @@ -64,15 +64,14 @@ mod par;
pub use par::ParSystem;
#[cfg(feature = "rayon")]
#[doc(inline)]
pub use schedule::{
inner::Schedule,
schedule,
};
pub use schedule::Schedule;

use crate::{
query::{
view::Views,
filter,
view,
Result,
Views,
},
registry::ContainsViews,
};
Expand Down Expand Up @@ -136,7 +135,7 @@ pub trait System {
/// The filter to apply to queries run by this system.
type Filter;
/// The views on components this system should operate on.
type Views<'a>: Views<'a>;
type Views<'a>: view::Views<'a>;
/// Views on resources.
///
/// The system will have access to the resources requested here when run.
Expand All @@ -148,7 +147,7 @@ pub trait System {
/// The views here must be [`Disjoint`] with `Self::Views`
///
/// [`Disjoint`]: crate::query::view::Disjoint
type EntryViews<'a>: Views<'a>;
type EntryViews<'a>: view::Views<'a>;

/// Logic to be run over the query result.
///
Expand Down Expand Up @@ -207,3 +206,48 @@ pub trait System {
R: ContainsViews<'a, Self::EntryViews<'a>, E>,
I: Iterator<Item = Self::Views<'a>>;
}

#[cfg(feature = "rayon")]
mod private {
use super::*;
use rayon::iter::ParallelIterator;

pub struct Null;

impl System for Null {
type Filter = filter::None;
type Views<'a> = Views!();
type EntryViews<'a> = Views!();
type ResourceViews<'a> = Views!();

fn run<'a, R, S, I, E>(
&mut self,
_query_result: Result<'a, R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
) where
R: ContainsViews<'a, Self::EntryViews<'a>, E>,
I: Iterator<Item = Self::Views<'a>>,
{
unreachable!()
}
}

impl ParSystem for Null {
type Filter = filter::None;
type Views<'a> = Views!();
type EntryViews<'a> = Views!();
type ResourceViews<'a> = Views!();

fn run<'a, R, S, I, E>(
&mut self,
_query_result: Result<'a, R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
) where
R: ContainsViews<'a, Self::EntryViews<'a>, E>,
I: ParallelIterator<Item = Self::Views<'a>>,
{
unreachable!()
}
}
}

#[cfg(feature = "rayon")]
pub(crate) use private::Null;
2 changes: 0 additions & 2 deletions src/system/schedule/claim/decision.rs

This file was deleted.

59 changes: 0 additions & 59 deletions src/system/schedule/claim/inverse.rs

This file was deleted.

25 changes: 0 additions & 25 deletions src/system/schedule/claim/merger.rs

This file was deleted.

62 changes: 0 additions & 62 deletions src/system/schedule/claim/mod.rs

This file was deleted.

Loading

0 comments on commit ef76b0c

Please sign in to comment.