0

In EntityX EntityManager has a method entities_with_components that returns all entities that have the required components. In the example of Emitting Events

I see double usage of that method:

for (Entity left_entity : es.entities_with_components(left_position)) {
  for (Entity right_entity : es.entities_with_components(right_position)) {

Is it performance effective or it queries to find the appropriate entities twice?

Narek
  • 38,779
  • 79
  • 233
  • 389

1 Answers1

2

I wrote Entityx.

Yes, that will iterate over the entities N^2 times. You do not want to do that in real code. The example included with EntityX has a much better collision system, which performs very well. But again, in real code it's likely that if you're using a physics system that it will do collisions for you, or you might use a dedicated collision library.

Alec

Alec Thomas
  • 19,639
  • 4
  • 30
  • 24
  • Thanks Alec. My question is not about iteration but about how it knows what are the entities that have appropriate components. I ask about querying. Does it have a static list of Entities for each System of each time I call `entities_with_components` the framework looks for such entities. – Narek Apr 03 '15 at 12:31
  • Ah. That was not clear.Each component is stored in a vector. Each entity is just an index into the component vectors, and a bitmask specifying which components the entity has assigned. – Alec Thomas Apr 03 '15 at 23:04
  • Alec, still it is not answering my question. How `entities_with_components` method selects entities? Does it find the vector of Position Components and for each component looks what entity it is mapped to. And in each call it does the same? For example, in Artemis each System has a member variable that stores its active entities and each time it does not do a lookup. It just calls `processEntites` and passes `active` entities to that method, which is very efficient than a lookup for each entity. – Narek Apr 04 '15 at 05:40
  • Well, it seems like you're asking about the specific implementation details of EntityX. There are two ways you can acquire that information: 1. Read all of the "Implementation details" sections in the README. 2. Read the source. EntityX stores components in vectors to increase cache coherence. The Artemis approach requires indirection through a pointer, which EntityX does not. There are tradeoffs to each approach. If you want a C++ version of Artemis try [this](https://github.com/vinova/Artemis-Cpp). – Alec Thomas Apr 05 '15 at 05:58