Optimizing entity rendering?

Started by
11 comments, last by larspensjo 11 years ago

Little bit off-topic, sorry about that, but where did you get your "Component" system ideas from? Is that from a specific framework?

I got the basic idea and some of the implementation details from the "EntityX"- framework.

Advertisement

It looks like you are using lazy loading in your Search/Get functions, but for your entities, try to use a quicker algorithm for find() if you can, it's usually linear time in complexity. I used a binary search algorithm for named entities, at the expense of taking a slightly longer insertion time when ordering them alphabetically. Also, make sure to handle name clashes elegantly if you happen to try to create a new entity with the name of an existing one.

Hm, interesting thought, but are you sure we are talking about the same topic here? I wouldn't want to search my entities based on name. In this case e.g. I want every entity that has a position and a model component - no matter what the entity itself is. Wouldn't it be contraproductive if I had to search for entities based on names here? All my render system cares about is that it actually can render an entity (thus it has at least a position and a renderable)- I might add some more factors too once I get to implement more complex things... The actual implementation of "EntitiesWithComponents" doesn't even use find at all, it uses this:


template<typename C, typename... Components>
EntityManager::entityVector* EntityManager::EntitiesWithComponents(void)
{

    ComponentMask mask = componentMask<C, Components...>();
    entityVector* vMatchingEntities = new entityVector;
    for(entityVector::const_iterator ii = m_vEntities.cbegin(); ii != m_vEntities.cend(); ++ii)
    {
        if( (mask & (*ii)->GetMask()) == mask)
            vMatchingEntities->push_back(*ii);
    }
    return vMatchingEntities;
}

I store all my entities in a vector<>. Now I know this implementation is lacking, but because I might need to access an entity by any combination of components at any time - there is not much of a choice for optimisation, at least on that level. Like I suggested I might use a custom iterator to simply skip over all entities that doesn't match the wanted components, but other than that - I don't really know what else to optimize.

I guess we are talking about different things since I meant using a binary search by entity name if I want to manipulate a particular entity's transformation, material, texture, etc. because numerical indices are not intuitive. It does work well if you're not looking to modify a bunch of them at once. In the worst case if all entities need to update in one frame that will be n (log n) time, which by then you might as well just iterate through them in one go. You are correct that the renderer should just be accessing them from a vector.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

Little bit off-topic, sorry about that, but where did you get your "Component" system ideas from? Is that from a specific framework?

I got the basic idea and some of the implementation details from the "EntityX"- framework.

For some more details, the ideas can be found at Entity-Component-System.

The library used above is modified from EntityX.

[size=2]Current project: Ephenation.
[size=2]Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

This topic is closed to new replies.

Advertisement