Comments (3)
Hi,
@IgnatusZuk
For information purposes, the Artemis implementation uses a bit of reflection and polymorphic bitmasking to fire off 'add', 'remove' and other useful events (which can be expanded as necessary) which allows you to take various actions when new entities and components have been added/removed from particular systems etc. Quite handy for many scenarios. I'd recommend taking a quick browse through the code:
https://github.com/vinova/Artemis-Cpp
eg:
void EntitySystem::change(Entity& e) {
bool contains = (systemBit & e.getSystemBits()) == systemBit;
bool interest = (typeFlags & e.getTypeBits()) == typeFlags;
if(interest && !contains && typeFlags.any()) {
actives.add(&e);
e.addSystemBit(systemBit);
added(e);
} else if(!interest && contains && typeFlags.any()) {
this->remove(e);
}
}
from entityx.
@DanoThom EntityX supports all of the operations required to implement that approach.
One thing that is bothering me is the fact that each system has to iterate through ALL entities in order to find entities with the appropriate components, and it's doing that on every update() call. Is that really necessary? That's a hell lot of bitmask checks and temporary tuples constructed and destroyed.
Yes, it is possible that this approach is not appropriate for some entity creation/destruction/usage patterns. For example, in a game where each component is used by just one system, the sparsity of the component vectors might result in unsuitable performance. But in my experience that is rare. Most systems share components.
One alternative is to somehow associate compact component vectors with all systems interested in those components. This brings its own set of problems. Insertion and deletion of components from the middle of vectors is expensive. This also means that component vector lookups by entity are not constant time, as they are of variable length.
Another alternative is (as described by @DanoThom 's example) to track entities with the components you're interested in. But again, what data structure are you going to use? A hash map? A list? Is the secondary data structure bookkeeping overhead going to be a win? It depends.
There are other data structures that are more suitable for different patterns, but the simplicity and cache characteristics of simple vectors of components is appealing.
In the end, it will depend on your usage patterns.
Finally, the bitmask checks are very cheap and there is minimal overhead in acquiring a Component handle. The handle is just a pointer to the EntityManager, and a 64-bit Entity::Id. There is no destructor.
Now imagine 1,000,000 entities (particles and stuff) and 50 fairly small systems. On each game update we have to do 50 million bitmask comparisons just to find out what entities we're interested in.
So really... is this practical?
How's the performance when the list of entities grows?
Benchmarks are included, so you can check this yourself. On my system I get around 18M entity iterations per second with component extraction.
But if you have 1M entities being simulated each frame, any general purpose system will struggle. In particular, particle systems probably aren't a great fit for EntityX (at least, mixed with other entity types). For larger levels, it's unlikely you'd completely simulate all objects in every frame in a traditional system anyway. You would typically partition the simulation by visible or near-visible regions, partially simulate non-visible entities, etc.
Is it possible to have more than one pool of entities? e.g. Separate gameplay entities from GUI entities.
This is definitely possible. You can just instantiate a separate EntityManager. You could use this for a particle system, or other client-only entities, etc.
Could we register systems to events which will be notified when a particular component is added to some entity?
This is already possible.
Could we have non-dynamic systems that store all entities they're interested in?
You can achieve this with the event system, though I'm not sure what you mean by "non-dynamic"?
from entityx.
@alecthomas excellent reply! this answers all my questions and concerns. I guess what's left now is to make a game with it and really find out how it stands vs traditional OOP. I'm especially excited about this; great things can be made with it. :)
from entityx.
Related Issues (20)
- Cross compile with target_complie_feature error HOT 2
- Assertion failed when trying to add system HOT 3
- Assertion failure when removing a component while an entity is being destroyed
- family_counter_ issues when using EntityX as a shared library HOT 6
- UUIDCollisionResolver HOT 2
- Assigning Component in Update Loop Crashes HOT 3
- [Question] Select components based on a specific variable value HOT 1
- Can't use entityx in Qt : conflicts with simplesignal HOT 2
- Some little requests~
- Future of entityx HOT 5
- more efficient way of looping trough a bunch of classes? HOT 1
- Passing an entity as a pointer (Question) HOT 11
- Catch::AssertionInfo& Issues Preventing Build HOT 1
- Inherited Component Polymorphism? HOT 2
- Grabbing access to the entity that owns a component? HOT 1
- Inheriting from Entity? HOT 1
- Issue with install from vcpkg
- Shared library not working in Windows HOT 1
- Entity creation / destruction slows down over time? HOT 15
- Does this project have DOP optimization? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entityx.