API changes proposal #153
pietrovismara
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
This is very well conceived. Thank you for taking the time to put it together. Some initial thoughts and questions:
|
Beta Was this translation helpful? Give feedback.
4 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
This is a draft of a proposal with the goal of solving the following issues:
recursivelyInherit
, or all the complexity added by assuming SoA typed arrays)While I try to preserve compatibility with the current API as much as possible, there are some fundamental changes breaking it. What you don't see presented here (e.g. queries, etc) is implied to need no changes.
Entities
addEntity
takes any number of components after the world argument:addComponents
works similarly:Components and stores
A store factory is a function called whenever a component is registered with a world, creating a unique store for that world.
A store can be anything, indexable by entity ID or not.
defineComponent
can be optionally used to assign a generic type argument, used by theonAdd
lifecycle hook. (More on hooks later)Store factories add a level of indirection, but practically that will only cause a small amount of added verbosity.
A big portion of the most verbose interactions with store can happen in hooks, where the store is passed as argument, while for systems it will just require adding a line before we iterate over entities:
Prefabs
definePrefab
takes any number of components as arguments, and an optional type argument used by theonAdd
hook.The
withParams
function can be used to type-safely pass parameters to that component, allowing users to set default values.withParams
also allows prefab defaults to be overridden:Nested prefabs
Prefabs can have children through the
ChildOf
relation, now provided by bitECS:Relationships
Relationships optionally wrap a component, so that each time a relation is assigned to a target a new component of that type is created.
Relationship components are also unique per world.
Lifecycle hooks
Lifecycle hooks can be used to initialize and reset store values.
Hooks are independent from worlds, as they are registered to a world together with the component they refer to.
Hooks work on relationships too:
And on prefabs:
Performance
I expect these changes to have no negative impact on performance per-se.
I implemented as a PoC most of the features presented here and updated the benches, comparing it with the results from the
next
branch shows the PoC to actually improve performance by ~10%.I suspect that is caused by me removing Storage, Serialization, the concept of world size with related checks, and buffered queries, but I haven't tested this assumption.
Removed features
Changed
modifier, as it's basically only useful for serializationdefineSystem
The concept is that bitecs should make no assumptions over what a store is and should not be responsible for managing it, providing instead full access to the lifecycle of stores for users to manage it themselves.
Without all the logic stemming from Storage it also becomes much simpler to remove global state and have isolated worlds.
And stuff like prefab inheritance is simpler as well: as of now it works only with SoA and would require a dedicated code path for AoS, with my proposal this is solved at zero cost with lifecycle hooks and parameters.
Following this I also removed buffered queries as they seem to be needed for multi-threading and it wasn't a direct concern of mine. I figured it would still be possible for users to wrap queries results in a typed array if needed.
Beta Was this translation helpful? Give feedback.
All reactions