Ralith / hecs

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

Implement updating components in command buffers #307

Closed cjhowedev closed 1 year ago

cjhowedev commented 1 year ago

Adds the ability to command buffers to update entities' components. This can be used to implement operations on components such as incrementing a counter or appending to an array.

cjhowedev commented 1 year ago

I think that maybe we can do better than this API. It's very simple, and it turns out I need an upsert to implement the kinds of commands I want to support.

cjhowedev commented 1 year ago

Okay, I ended up with a greatly simplified API which supports all prior use cases. Let me know what you think!

Ralith commented 1 year ago

Thanks for the PR!

I'm unsure if this is a direction we should go in. In a game (for example) hecs is not intended to be the entirety of your world representation; in practice applications might be better served by maintaining their own Vec of closures which accept a more all-encompassing state struct that includes non-ECS data. By providing a narrower version, we risk promoting a pattern that may prove awkwardly limiting. Meanwhile, implementing this pattern downstream is simple and no less efficient.

adamreichold commented 1 year ago

in practice applications might be better served by maintaining their own Vec of closures

I would also suggest to refrain from this. In my personal experience, one can also be both more readable and more efficient by not storing closures, but rather the data (entity ID, new or updated values, etc.) a uniform set of closures would operate on because the code itself is usually fixed at least on a per-system basis.