zakarumych / edict

Other
82 stars 6 forks source link

How to avoid adding same system to schedule again. #24

Closed navneetankur closed 3 weeks ago

navneetankur commented 4 weeks ago

Assuming systems are normal functions. Is there a way to check if schedule already contains a system and add, if it does not?

Or in general, is it possible to create a schedule which does not contain duplicate system? Even if we have to use some other data structure like Vec or Set to create a list of systems first before adding them to schedule.

navneetankur commented 4 weeks ago
let m = HashMap::default();
m.insert(some_system as usize, Box::new(some_system.into_system()));
...
let mut s = Scheduler::new();
for (_,system) in m {
    s.add_boxed_system(system);
}

Seems one possible hackish way.

navneetankur commented 4 weeks ago

Also it would be nice to have impl Clone for Scheduler. It would make it possible to create a schedule which is combination of two schedules.

Edit: That's difficult due to presence of ActionBuffer I guess. Just getting a Clone of scheduler::systems's clone out of it will make it possible to create a scheduler with same systems and then add more system to it.

zakarumych commented 4 weeks ago

First, take note that this scheduler is optional and users can roll their own.

Second, this Scheduler is sensitive to order in which systems are added.

There's no need to combine schedulers, instead make system bundles and add them at once to the Scheduler that you intend to run.