Efficient way of matching entities to systems in an entity component system

后端 未结 6 531
再見小時候
再見小時候 2021-01-31 04:53

I\'m working on a data-oriented entity component system where component types and system signatures are known at compile-time.


An entity

6条回答
  •  后悔当初
    2021-01-31 05:14

    Regarding the pseudo code:

    for(auto& e : entities)
        for(const auto& s : signatures)
             if((e.bitset & s.bitset) == s.bitset)
                 callUserFunction(e);
    

    I am unsure why you need the inner loop.

    If you have the requested signature in the function then you can get the bitset of that signature and there is no need to iterate over all of the signatures.

    template 
    void forEntitiesMatching(const std::function& fun)
    {
        for(auto& e : entities)
            if((e.bitset & T::get_bitset()) == T::get_bitset())
                 fun(e);
    }
    

提交回复
热议问题