amethyst / shred

Shared resource dispatcher

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow runtime `SystemData`

torkleyy opened this issue · comments

SystemData currently has associated functions for read and write. This prohibits creating more dynamic systems that don't specify what they fetch at compile-time.

Proposal

  • add SystemData::Specifier
  • move SystemData::read and SystemData::write to Specifier and let them take &self
  • add a specifier method to System with a default implementation that works for all current cases

Example

This is what a custom implementation could look like (very primitive).

struct CustomData {
    // ..
}

impl<'a> SystemData<'a> for CustomData {
    type Specifier = CustomSpec;

    fn fetch(spec: &Self::Specifier, res: &'a Resources) -> Self {
        unimplemented!()
    }
}

struct CustomSpec {
    reads: Vec<ResourceId>,
    writes: Vec<ResourceId>,
}

impl Specifier for CustomSpec {
    fn reads(&self) -> Vec<ResourceId> {
        self.reads.clone()
    }

    fn writes(&self) -> Vec<ResourceId> {
        self.writes.clone()
    }
}

Possible complications

The default implementation for System::specifier won't be able to use the usual Specifier::default function as you'd expect, because we can't specialize the default for that method for Specifier: Default.

Unresolved questions

  • Find a better name for Specifier

Name suggestions for Specifier welcome!

Just a little heads up, this issue is now being worked on by @tversteeg. Thank you and welcome!

commented

Only thing that comes mind is AccessConstraints which seems awfully generic.

How about ResourceIdAccessor?

Ah, I think Accessor is good! No need to prepend ResourceId.