S
S
siRius322021-01-15 12:34:03
Game development
siRius32, 2021-01-15 12:34:03

Entity Component System + OOP approach?

It is not entirely clear how to write in this style, whether it is possible to interfere with OOP. For example, there is an entity player with a set of components inherited from Entity, it has methods that change data in components, these methods are called in systems. Or there is no type of "types" of entities and it is necessary to take components from entity only in systems and only do something there. About states, add empty components to remove in entity as flags that the entity is in any state, and separate systems for processing each state is this a normal approach ?! *

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Shatunov, 2021-01-15
@siRius32

ECS is not only a decomposition approach for logic and data, but also an approach to reject aggregation and inheritance in favor of indirect composition. Explicit composition in ECS is also not provided, and indirect composition does not hint at the connectivity or structure of the data. Indirect composition means only the presence of any data on some indirect features.
Moreover, within the framework of ECS, third-party code is not able to work normally with data. For third-party code, ECS provides an abstraction layer for reading and writing data.
All this should indicate that OOP can only be used next to ECS and separately from ECS, but not together with and not inside the ECS data model.

For example, there is an entity player with a set of components inherited from Entity,

No, it will not immediately be ECS. The player entity is the entity, which is the ephemeral entity in the ECS world.
And entity cannot have methods. All the logic of entities is distributed across systems and is highly dependent on the components that the entity has.
Furthermore. If you are talking about the fact that in your world there can be an entity with the characteristic of a player, such entities in your world can be up to 100% of the entire ECS of the world. If your player should be represented by a single entity, then this is no longer an entity, but an external object, mistakenly introduced into the ECS world.
In ECS, the basic rule is that any entity can gain or lose any component at any given time.
About states, add empty components to remove in entity as flags that the entity is in any state, and separate systems for processing each state is this a normal approach ?!

Bitwise components are a simple optimization for storing empty components. Yes, they do and ensure that the systems work correctly so that component filters treat both full-size components and bitwise ones equally.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question