You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
During our internal hackathon I noticed that most people were running into some confusion around the entity.addComponent() API.
The current signature is this:
classWorld{registerComponent<CextendsComponent>(component: ComponentConstructor<C>): this
}interfaceComponent{copy(source: Component): this // Optional}classEntity{addComponent(component: ComponentConstructor,parameters: Component|{}): this
}
Where the parameters are copied to the instance of the component acquired from the object pool. In the case that it is an instance of Component with a copy() method it uses that otherwise it just does a shallow copy of the object.
addComponent() does not implement pooling by default. I think most of us had issues with the default pooling behavior. The shallow copy doesn't work for non-value types like Matrix4, Vector3, etc. which produces undesirable results. I'll let others comment on their experiences with object pooling, but I think the Hubs team was generally in favor of making object pooling a higher level concept and not turned on by default.
addComponent() returns the component instance. In my experience this is more common than adding multiple components to an entity which is why we currently return the instance of the entity rather than the component.
registerComponent() takes an optional ComponentManager which allows you to implement pooling yourself on a per component basis. You can also store your components with different backing data structures such as Map or a BitSet or TypedArray. The default should probably just use a Map or Array I did some benchmarks in HECS that you can look at to determine the best default.
Add clone() to Component. I think it's good to allow people to add arguments to the component constructor. However, this makes it tough to clone components in editors like Spoke. Adding the clone() method lets you specify those constructor parameters or override how the component is instantiated when cloned.
Move Component from an interface to a class with default implementations of clone and copy. These implementations support ThreeJS classes such as Vector3, Matrix4, etc.
The text was updated successfully, but these errors were encountered:
During our internal hackathon I noticed that most people were running into some confusion around the
entity.addComponent()
API.The current signature is this:
Where the parameters are copied to the instance of the component acquired from the object pool. In the case that it is an instance of
Component
with acopy()
method it uses that otherwise it just does a shallow copy of the object.I'd like to propose moving to this:
The differences are the following:
addComponent()
does not implement pooling by default. I think most of us had issues with the default pooling behavior. The shallow copy doesn't work for non-value types likeMatrix4
,Vector3
, etc. which produces undesirable results. I'll let others comment on their experiences with object pooling, but I think the Hubs team was generally in favor of making object pooling a higher level concept and not turned on by default.addComponent()
returns the component instance. In my experience this is more common than adding multiple components to an entity which is why we currently return the instance of the entity rather than the component.registerComponent()
takes an optional ComponentManager which allows you to implement pooling yourself on a per component basis. You can also store your components with different backing data structures such asMap
or aBitSet
orTypedArray
. The default should probably just use aMap
orArray
I did some benchmarks in HECS that you can look at to determine the best default.clone()
toComponent
. I think it's good to allow people to add arguments to the component constructor. However, this makes it tough to clone components in editors like Spoke. Adding theclone()
method lets you specify those constructor parameters or override how the component is instantiated when cloned.Component
from an interface to a class with default implementations ofclone
andcopy
. These implementations support ThreeJS classes such asVector3
,Matrix4
, etc.The text was updated successfully, but these errors were encountered: