anax
anax copied to clipboard
Test plain entity id vs entity handle class performance
I was just wondering what the performance impact of using the entity handles would be.
In particular, in the SpriteRenderingSystem.cpp file, you iterate over entities like so:
void SpriteRenderingSystem::render()
{
auto entities = getEntities();
for(auto& entity : entities)
{
auto& sprite = entity.getComponent<SpriteComponent>().sprite;
auto& transform = entity.getComponent<TransformComponent>().transform;
getRenderTarget().draw(sprite, transform.getTransform());
}
}
But isn't one of the key benefits of using the ECS system that you minimize cache-misses by, for example, iterating over arrays/vectors of components using an entity id? I'm basing a lot of my thinking here on this article: http://www.gamedev.net/page/resources/_/technical/game-programming/implementing-component-entity-systems-r3382
for example, iterating over arrays/vectors of components using an entity id
That code you provided is iterating over arrays of components using an entity ID; the entity class is just a wrapper to an entity ID, and the implementation uses the IDs. Unless you specifically mean to iterate over the components individually, but then it would be impossible to render the sprites, as you require both the transform and sprite components for rendering to occur.
Also, as of current, the components are not allocated next to each other (e.g. VelocityComponent velocities[1000];
). Rather they are allocated via the free store (i.e. by new
), thus even if you did iterate through the individual components you would still get cache misses. Unfortunately this is an issue I have yet to figure out how to solve.
Ahh ok. I'm still learning how all the ECS stuff work :) Looking to decide what to use for my own game (not sure I really want to write my own).