-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Systems as entities #16618
Comments
Mutability is probably the biggest problem here to solve. i.e. How do you get mutable access to all the systems in the schedule in a safe way? You have to have exclusive access of the BoxedSystem and the cached system params to be able to run a system safely. While you can query for all the systems in a schedule, you have to drop the query before you can run the schedule, since that requires passing
I'm not sure this makes sense as we need queries as entities for relations. This needs observers on adding/removing components in the main world to update the query caches of the matching archetypes. So these need to live in the main world. I suppose it could work if the observers in the main world have exclusive access to the schedule world, but this would block the observers from running in parallel (if we ever enable that). I'd say other risks are that moving systems into the world might make some future scheduling algorithms harder to implement or block perf improvements. Scheduling is a very perf sensitive part of the ecs and not being able to use customized data structures for storing systems could lock us out of making certain improvements. But that's all rather nebulous, so it's not something that I would consider blocking. |
I've written a write-up about the principles I think we should follow when doing *-as-entities refactors like this: https://hackmd.io/@bevy/SypE1qZP1l |
Background
Today,
bevy_ecs
can roughly be split into two parts:World
, entities, components, resources, archetypes and querying.The data storage part is very flexible and powerful. It has facilities for storing arbitrary data on objects, composing data on objects, reacting to changes in data, and so on.
On the other hand, schedules are a hand crafted storage solution for systems which includes all manner of metadata: system name, before/after relations, system sets it belongs to, etc.
As a result, we have to build a lot of APIs. Schedules today can't have systems be removed (#279, wow that's an old issue). We'd have to come up with an ID scheme for systems, provide a function to remove systems, and also make sure the schedule graph reacts appropriately to the change.
Proposal: Systems-as-entities
(queue anything-as-entities meme)
Instead of building more stuff on top of the system storage, we can instead rewrite it to use the data storage and access part! Now we don't need an ID scheme for systems: it's just an
Entity
. Now we don't need a function to remove systems: that's just despawning an entity. As for having the schedule graphs react to changes, we have several tools to handle this. Change detection, hooks, and observers could be used.As part of this, we will likely want schedules and system sets to also be entities. Systems can then have a system set or schedule component that matches the particular type.
Issues that help this effort
Immutable Components (#16372)
Today, we likely need to use change detection to keep things in sync. With immutable components, we can just use hooks to sync any schedule data structures.
🌈 Relations (#3742)
Today, we either need to store before/after relationships as one component for all a system's constraints, or we need to spawn an entity to represent that constraint. Either way, these are both cumbersome to manage. With relations, we can use them to represent all the before/after constraints as relations. Finding all edges is very easy then.
Similarly, schedules and system sets could use relations to define which systems are in the schedule or system set.
Risks
Prior Art
flecs
implements systems as entities! Some of the cool features that just pop out for free was disabling systems the same way entities can be disabled!The text was updated successfully, but these errors were encountered: