New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EntityIndex #154
Comments
A code generator is planned for a future version. See #75 public const string PositionKey = "Position":
public static void AddEntityIndices(Pool pool) {
// Position index, key type is IntVector2
var entityIndex = new EntityIndex<IntVector2>(
pool.GetGroup(Matcher.Position),
(entity, component) => { // How to create a key based on entity and component
var positionComponent = component as PositionComponent;
return positionComponent != null
? positionComponent.value
: entity.position.value;
});
pool.AddEntityIndex(
PositionKey, // Any unique name
entityIndex
);
} public static HashSet<Entity> GetEntitiesWithPosition(this Pool pool, IntVector2 position) {
var index = (EntityIndex<IntVector2>)pool.GetEntityIndex(PositionKey);
return index.GetEntities(position);
} var entities = pool.GetEntitiesWithPosition(pos); // fast index access |
I try:
And I get error on
|
I updated my previous comment. Try that |
Thanks all works fine! |
What you think about double indices?
Or indices from different components Example
|
You can achieve sth like this already manually, but yeah, generating these things will be very handy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An EntityIndex can speed up retrieving entities dramatically. Entities can be indexed similar to a index in a database.
Instead of iterating over all entities with a e.g. a position and checking if pos == (1, 2), an EntityIndex can observe group(Position) and index entities already. Getting all entities with pos == (1, 2) is constant speed of Dictionary access (=> very fast).
EntityIndex allows multiple entities with same key (key can be e.g. position or name)
PrimaryIndex ensures there is only one entity for a given key.
The text was updated successfully, but these errors were encountered: