S
S
siRius322021-01-22 12:57:58
Game development
siRius32, 2021-01-22 12:57:58

How to bind a game cell field in Entity Component System?

Can you tell me the right direction how is the cellular playing field implemented in ECS? The game itself: a playing field of n by m cells, with types of terrain, with units, turn-by-turn. If it is more or less clear with units, an entity with a set of components, then what is the playing field and how is it connected in systems with the positions of units?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Shatunov, 2021-01-24
@MarkusD

In general, the space of the playing field is not very well expressed in terms of ECS. The playing field is usually a monolithic piece of logic for which the CBSE(COP) approach would be better suited . Usually the playing field is represented by a composition of several spaces in which the mechanics of the game work. It is more convenient to express such spaces with components from CBSE rather than components from ECS.
However, despite all this, there is a good way to implement the playing field in terms of ECS. Especially if the playing field is discrete.
To start thinking in this direction, you first need to study cellular automata: [ 1 ], [ 2 ].
When it becomes clearer with the principles of operation of cellular automata, you should turn your attention to the templateinversions of control . With direct control, your entire world is ruled by a quantum of time that descends from the main cycle to each entity. This approach is unacceptable on the playing field in terms of ECS.
The cellular automaton operates with excited and passive cells. Due to the inversion of the control of the system, not all cells of the automaton are processed, but only excited ones. During its time quantum, a cell can go into a calm state, remain excited, or transfer the excitement to a neighboring cell.
In terms of ECS, this is all decided by the components. An excited cell of the playing field has a component of excitation, a calm cell does not have it. Each cell has a component with neighboring cells. If there is no component, the cell is an island.
And now the most interesting. Game entities are now also components of the playing field. And due to the same inversion of control, game entities can now only be updated for excited field cells. If the cell is calm, the character standing on it does not receive a refresh quantum. This is an important rule that must be observed in order not to violate the integrity of the implementation of the playing field through the ECS.
Any control of the character can only excite the cell of the playing field where the character is standing. When a character moves to another cell, it is not the character itself that moves between cells, but its components. Literally, first, the data components of the character are moved to the entity of the target cell, and then the components of the character in the current cell are deleted.
Regarding entities. For a discrete field, the cell is the entity. At the same time, according to ECS terminology, an entity is an ephemeral object that only identifies its components. In other words, a cell of a discrete field can be expressed by an identifier of its coordinates. When requesting a particular component, launching a system quantum, or referring to an entity through the identifier of its coordinates, we will always know exactly the geolocation of our actions in the playing field. However, to implement such a mechanism, it is required to develop your own implementation of ECS.
The essence of the ECS can be not only one cell of the playing field, but, say, one chunk of 16x16 cells, in which all the rules of the cellular automaton are stored.
Through this approach, it is quite possible to implement something like Factorio.

F
freeExec, 2021-01-22
@freeExec

By N and M coordinates

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question