Ralith / hecs

A handy ECS
Apache License 2.0
924 stars 81 forks source link

Closure component #292

Closed wrnrlr closed 1 year ago

wrnrlr commented 1 year ago

I was wondering if it is possible and/or sensible to be able to create a component out of a closure or function. Something like this:

for (_id, (f)) in world.query::<(Box<dyn Fn()->Point>,)>() {
        //...
}

This could be a nice way to program some dynamic behaviour without needing a hierarchy of systems and entities.

Ralith commented 1 year ago

Any Rust type that satisfies Send + Sync may be used as a component. This includes boxed closures that include that constraint.