Now as I study more ECS I see that Cocos Creator follows approach after Unity GameObject model (or Component model) but not ECS.
At first I also did confuse these two, but now I have got more or less understanding of ECS, although I am not sure that I fully understand Cocos creator approach.
Some comparison of component model vs ECS can be found in this video:
Although devs say that Creator is ECS: Any tutorials for entity component system using Cocos Creator? :)
As far as I know even Unity does not provide true ECS and currently trying to actively develop into that directions. They have some steps on the way which is job system and etc, but it is not yet ECS as far as I know.
As well as they agree of performance degrations due to non-ECS approach (huge number of unnecessary update() methods): https://blogs.unity3d.com/2015/12/23/1k-update-calls/
That is why I want to clarify a little bit about cocos.
For ECS we need:
- Entity - empty object that role is only as a container for list of Components
- Component - data holding object (or sometimes empty if we use only class type for behavior change).
- Systems - place for update method that can change Entity structure and interact with corresponding components
Now cocos developers say that Components and Systems are united into “cocos component” and entity into node. But, is it valid to call it ECS now?
There shouldn’t be one-to-one correspondence between Systems and Components, for example, let’s say I have meteorites which has positions, moving randomly in 2d box and some of which are destroyed on contact. In total 100 meteorites, 5 normal, 5 destructible.
Then I will have Components: PositionComponent
, DestructibleComponent
.
Then 5 Entities with PositionComponentand
5 with PositionComponent
and DestructibleComponent
components.
And 3 systems:
-
RandomWalkSystem
which updates onlyPositionComponents
-
CollisionSystem
which iterates only Entities which hasDestructibleComponent
and compute collisions, remove Entity from list and/or split Entity into pieces of smaller size etc… -
RenderSystem
which draws objects based onPositionComponents
.
our update(dt) will have form:
update(dt) {
RandomWalkSystem.update(dt);
CollisionSystem.update(dt);
RenderSystem.update(dt);
}
The efficiency comes from the fact that we can notify each needed system about Entity which adds corresponding component. Systems iterate only through entities that contain related components and avoid iteration over remaining.
Now returning back to cocos creator, I do not see how it is possible case for current implementation. I had 3 systems and 2 components, in creator on other hand components and systems are the same thing. Moreover, Node is and entity that not only has components but also positions, angles, etc – a pieces that should be moved to some system components.
Am I missing something? How to implement ECS with cocos creator if I am wrong with above. Thanks.