Concept of component manager? #17
Replies: 2 comments
-
I just saw |
Beta Was this translation helpful? Give feedback.
-
There's no component manager in the traditional sense as Polymorph shifts this work to compile-time with static system state changes. The design is orientated around systems holding their slice of the entity-component state and the management aspect is performed by the state changes themselves (such as Systems are essentially update driven "work lists" rather than queries to a manager. For example if there's a component that's only used by one system, adding this component to an entity generates a single static update just for that system. This means state updates are generally very efficient as only the relevant systems are being touched and there's no run-time cost for determining what needs updating. It also means systems have no run-time setup cost; they just go through their work list. This is handy for performance but also lets you design a really tiny ECS with one or two components for say, embedded work - ultimately the code boils down to simple arrays and loops. You can always view all the generated code by passing There's no mechanism for gathering entities from arbitrary sets of components. To do this you'd make a system which would then be updated upon state change.
In general the library is built assuming any operations with components is done with systems, so most of the time they're the most ergonomic solution even for single components or one-off operations. Systems also have the advantage of a set order of execution, as the order of component reads and writes can be really important with ECS. Notable exceptions to using systems is things like serialisation which operate "outside" of the ECS, doesn't perform logic, and may operate on the state as a whole. Systems also offer quite a bit of flexibility over manually iterating components, for example you can make them run at intervals whilst still maintaining a set system run order: makeSystemOpts("displayComp", [ComponentX], ECSSysOptions(timings: stRunEvery)):
all: echo item.componentX
sysDisplayComp.runEvery = 1.0 / 30.0 For one-off manual operations a pattern I sometimes use is with the system's makeSystem("runOnce", [ComponentX]):
init: sys.paused = true
all: echo "Some code to do the one off thing with ComponentX"
finish: sys.paused = true When you want the system to run, setting You can see an example of this in the Polymers particle demo here. The Having described the above, it's worth noting that systems do have some minor overhead in terms of (by default) an indirection and the storage for this indirection, which defineSystemOwner("forAllX", [ComponentX], [ComponentX], defaultSystemOptions)
makeSystemBody("forAllX"):
all:
echo item.componentX # `componentX` is the source type.
On my TODO list is to make systems with only one component automatically iterate over the storage of the component like
Cheers! I'm using it quite intensively for a few projects, including a game world with a need for running a few tens of thousands of active entities with a high dynamic requirement (procgen world, weapons, and creatures) so it's being "dogfooded". Let me know if you have any more queries or issues! :) |
Beta Was this translation helpful? Give feedback.
-
Is there any concept of something like a component manager in polymorph? If I want to iterate over all of the instances of component X - not the entities which have component X via a system - is there any way to do this?
Beta Was this translation helpful? Give feedback.
All reactions