How is this library different from EntityX, what are the use cases where it is preferable? #42

Closed
sztomi opened this Issue Apr 1, 2014 · 6 comments

Comments

Projects
None yet
5 participants
@sztomi

sztomi commented Apr 1, 2014

I'm looking for a Component-Entity-System library, and I found these two. The faq lists EntityX as an inspiration. I find the two very similar in goals and implementation as well. Is there a killer advantage to choose either?

@miguelmartin75

This comment has been minimized.

Show comment
Hide comment
@miguelmartin75

miguelmartin75 Apr 1, 2014

Owner

The only similarities between EntityX is the similar syntax to add systems, components, and to create entities and new (custom) components. Some of the implementation is similar (see below on entity handles, this is the only similar implementation detail, I believe), but for the most part it's quite different.

e.g.

Adding a component to an entity in EntityX:

entity.assign<Position>(1.0f, 2.0f);

Adding a component to an entity in anax:

entity.addComponent<Position>(1.0f, 2.0f);

Creating a custom component in EntityX:

struct Direction : entityx::Component<Direction> {
  Direction(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}

  float x, y;
};

In anax:

struct Direction : anax::Component<Direction> {
  Direction(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}

  float x, y;
};

The other similarity is how entity handles are implemented. I originally thought the way that EntityX stores entity handles was quite useful, however, I made a subtle change to the (original) design.

EntityX's old implementation of entity handle's made it so when you invalidated/destroyed one entity handle, other handles "pointing" to the same entity would not be invalidated. e.g.

entity2 = entity1;
entity1.invalidate();
// entity2 is still valid
entity2.addComponent<Position>();

This is now changed, as EntityX basically does the same thing anax does; contain a count and index for entity IDs. The "count" of an entity's ID is basically incremented whenever an entity is destroyed/invalidated.


Here are some major differences:

  • Dynamic amount of component types (I may add the option to have a static amount of component types, see #22)
  • No "built-in" event system - this leaves to more freedom on how you wish to do it
  • Creating/using systems is a new system is similar, but a bit different. Specifically because when you "update" your system, you have to ask the manager(?) for entities with specific components, whereas in anax this is all cached and you can access the entities with specific components you need via getEntities() - See this for EntityX and this for anax for specific details (note see #20 and #34 for possible (optional?) differences in future versions of anax)
  • Regarding the point above; EntityX may or may not be less efficient in the way it grabs entities with specific components. As anax caches the entities with specific components, within the system, much like Artemis. Although you can probably do this manually with entityx.
  • Components in EntityX are retrieved and "stored" in a entityx::ptr, which is an alias to a std::shared_ptr. This may make a noticeable difference in performance, of course I don't have evidence, as I haven't benchmarked this difference. anax returns a reference to the component; although this may change in future versions (due to #23)
  • In anax there are no "managers" - as I personally didn't think this was an entity system specific feature (which is also true for built-in events)

Also, I have examples (not full game examples), within the repository; I'm not sure if there are any concrete game examples for entityx.

I'm not going to tell you what library to use. Use whatever one you want to. If you don't like something about my library (anax), comment about it, as I am interested to know what I could improve.

Owner

miguelmartin75 commented Apr 1, 2014

The only similarities between EntityX is the similar syntax to add systems, components, and to create entities and new (custom) components. Some of the implementation is similar (see below on entity handles, this is the only similar implementation detail, I believe), but for the most part it's quite different.

e.g.

Adding a component to an entity in EntityX:

entity.assign<Position>(1.0f, 2.0f);

Adding a component to an entity in anax:

entity.addComponent<Position>(1.0f, 2.0f);

Creating a custom component in EntityX:

struct Direction : entityx::Component<Direction> {
  Direction(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}

  float x, y;
};

In anax:

struct Direction : anax::Component<Direction> {
  Direction(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}

  float x, y;
};

The other similarity is how entity handles are implemented. I originally thought the way that EntityX stores entity handles was quite useful, however, I made a subtle change to the (original) design.

EntityX's old implementation of entity handle's made it so when you invalidated/destroyed one entity handle, other handles "pointing" to the same entity would not be invalidated. e.g.

entity2 = entity1;
entity1.invalidate();
// entity2 is still valid
entity2.addComponent<Position>();

This is now changed, as EntityX basically does the same thing anax does; contain a count and index for entity IDs. The "count" of an entity's ID is basically incremented whenever an entity is destroyed/invalidated.


Here are some major differences:

  • Dynamic amount of component types (I may add the option to have a static amount of component types, see #22)
  • No "built-in" event system - this leaves to more freedom on how you wish to do it
  • Creating/using systems is a new system is similar, but a bit different. Specifically because when you "update" your system, you have to ask the manager(?) for entities with specific components, whereas in anax this is all cached and you can access the entities with specific components you need via getEntities() - See this for EntityX and this for anax for specific details (note see #20 and #34 for possible (optional?) differences in future versions of anax)
  • Regarding the point above; EntityX may or may not be less efficient in the way it grabs entities with specific components. As anax caches the entities with specific components, within the system, much like Artemis. Although you can probably do this manually with entityx.
  • Components in EntityX are retrieved and "stored" in a entityx::ptr, which is an alias to a std::shared_ptr. This may make a noticeable difference in performance, of course I don't have evidence, as I haven't benchmarked this difference. anax returns a reference to the component; although this may change in future versions (due to #23)
  • In anax there are no "managers" - as I personally didn't think this was an entity system specific feature (which is also true for built-in events)

Also, I have examples (not full game examples), within the repository; I'm not sure if there are any concrete game examples for entityx.

I'm not going to tell you what library to use. Use whatever one you want to. If you don't like something about my library (anax), comment about it, as I am interested to know what I could improve.

@sztomi

This comment has been minimized.

Show comment
Hide comment
@sztomi

sztomi Apr 1, 2014

Thanks for the detailed answer. Maybe this post could go the FAQ?

sztomi commented Apr 1, 2014

Thanks for the detailed answer. Maybe this post could go the FAQ?

@miguelmartin75

This comment has been minimized.

Show comment
Hide comment
@miguelmartin75

miguelmartin75 Apr 2, 2014

Owner

Added a link to this discussion in the FAQ, as it's easier (as I have to manually link to issues).

Owner

miguelmartin75 commented Apr 2, 2014

Added a link to this discussion in the FAQ, as it's easier (as I have to manually link to issues).

@LearnCocos2D

This comment has been minimized.

Show comment
Hide comment
@LearnCocos2D

LearnCocos2D Oct 19, 2015

"Here are some major differences:"

You may want to rephrase that as it's not clear whether this list is about features that are in entityX but not in anax or vice versa, especially since some items in the list are "pros" and others are "cons".

PS: I intend to benchmark anax, entityx and artemiscpp next week as I need an ECS in TilemapKit. I'll post an update with a link to the blog post when I'm done. I'm curious to see how the libraries compare.

"Here are some major differences:"

You may want to rephrase that as it's not clear whether this list is about features that are in entityX but not in anax or vice versa, especially since some items in the list are "pros" and others are "cons".

PS: I intend to benchmark anax, entityx and artemiscpp next week as I need an ECS in TilemapKit. I'll post an update with a link to the blog post when I'm done. I'm curious to see how the libraries compare.

@skyrpex

This comment has been minimized.

Show comment
Hide comment
@skyrpex

skyrpex Jun 2, 2016

did you finally created those benchmarks?

skyrpex commented Jun 2, 2016

did you finally created those benchmarks?

@dzanis

This comment has been minimized.

Show comment
Hide comment
@dzanis

dzanis Oct 30, 2016

I did a test. Created 100,000 entities (SFML) .FPS the same, but the difference in memory usage.Anax uses more memory.
anax_test_2016-10-30_11-43-00
entityx_test

dzanis commented Oct 30, 2016

I did a test. Created 100,000 entities (SFML) .FPS the same, but the difference in memory usage.Anax uses more memory.
anax_test_2016-10-30_11-43-00
entityx_test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment