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

System data problem #30

Closed
kvark opened this issue Apr 14, 2016 · 0 comments
Closed

System data problem #30

kvark opened this issue Apr 14, 2016 · 0 comments

Comments

@kvark
Copy link
Member

kvark commented Apr 14, 2016

Anything more than a simple demo will probably have some soft of a System trait, with objects implementing it being boxed and stored in a list to be executed automatically. It may look like this:

trait System {
    fn process(&mut self, &mut secs::Planner, TimeDelta);
}

Unfortunately, using secs under such abstraction is not elegant:

  1. The system execution is now split into 3 different chunks, executed at different moments:
    • process() entry, executed upon queuing the system
    • fetch phase, executed at the start of the system on another thread
    • iter phase, executed after all the storage locks are acquired
  2. Any data that system has (and wants to access in the execution closure) needs to be Clone + Sync. Imaging a mutable vector there - now you'd need to wrap it into Arc<Mutex<X>> , even though it should not be needed. This is inconvenient and bloats the code.

Optimally, I'd like to base ECS onto the system interface like this (edit: moved to #40):

trait System<C: Clone>: Send { //`C` stands for "Context"
    type Data<'a>; // some sort of HKT, which is not supported in current Rust
    fn fetch<'a>(&self, &'a secs::World) -> Self::Data<'a>;
    fn run(&mut self, Data<'a>, C);
}

Why this would be nice:

  • this system is required to implement Send: each time it needs to be executed, it's moved onto the thread, run, and then moved back (or not, if we can track this).
  • it allows any sort of data to be kept within the system without harsh restrictions or bloated wrappers
  • it clearly separates executable parts and their contexts. This enforces a fetch at compile time.
  • it allows the users to start using it right away (without higher abstractions) in complex systems, one just need to decide what C is (in the original example, C = TimeDelta)
@ghost ghost closed this as completed in #41 Apr 20, 2016
xMAC94x pushed a commit to xMAC94x/specs that referenced this issue Mar 10, 2021
30: Give better control over system dispatching (by Object905) r=torkleyy
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant