libgdx/ashley — pull request #38 by siondream (2014-08-02 20:31:03+00:00)
Title: Performance

A few changes mostly to improve performance but also to make the API simpler. This has been done after some benchmarking and profiling.

I believe this makes the library a lot better but I wanted to check with other people before merging like crazy.

`ComponentType` wasn't being used outside of `core` so it is now package protected.

`Entity` carries a `Bag` of `Component` objects. `Components` are indexed using their `ComponentType` index for super fast retrieval. We no longer use a dictionary for this. Unfortunately, this breaks the API.

In order to retrieve a `Component` we use the `ComponentMapper` class. Similar to what Artemis does but with a lot less black magic. There are no annotations and it's easier to use.

public class StateSystem extends IteratingSystem {
private ComponentMapper sm = ComponentMapper.getFor(StateComponent.class);

public StateSystem() {
super(Family.getFamilyFor(StateComponent.class));
}

@Override
public void processEntity(Entity entity, float deltaTime) {
sm.get(entity).time += deltaTime;
}
}

Retrieving a component is now O(1) rather than O(logn)!