alecthomas / entityx

EntityX - A fast, type-safe C++ Entity-Component system
MIT License
2.23k stars 295 forks source link

[Compile-Time branch] Performance concerns, iteration #181

Closed H1X4Dev closed 7 years ago

H1X4Dev commented 7 years ago

Hey there,

I noticed that a new entity is being created each time it is being iterated and I was wondering, wouldn't that affect the overall performance? Or this was a design pattern ? Also, would it be possible to iterate in parallel, for faster updates or update each system simultaneously on different threads?

Regards.

alecthomas commented 7 years ago

An entity is very small a handle; a std::uint64_t containing bit fields with the index and version of the entity, plus a pointer to the manager.

Regard parallel iteration, I created a proof-of-concept, but it needs a lot more work and testing before it's usable, and I don't have the time.

H1X4Dev commented 7 years ago

Would it be a good idea to use std::shared_lock and std::unique_lock along-side boost io stream when implementing network components? I think this would help thread-safety while creating / removing entities using unique_lock and shared_lock for using mainly on iteration.

alecthomas commented 7 years ago

I don't want to add locking to core EntityX (if that's what you're asking) but locking around EntityX would work (of course).

H1X4Dev commented 7 years ago

About parallel iteration, I meant to be able to parallelize for loop with OpenMP or Intel TBB, I think it could give a good performance boost overall, though it's very fast already.

Also, would it be a good idea allowing systems to communicate directly with oop references from application class? I did not see observer / events possibility in compile-time branch though.

alecthomas commented 7 years ago

There are hooks (which can be enabled at compile time) for on_entity_created, on_entity_destroyed, on_component_added and on_component_removed, but there is no generic event system at the moment.