Note that there are some explanatory texts on larger screens.

plurals
  1. POstd::map Access Speed Is Too Slow?
    primarykey
    data
    text
    <p>I have recently been implementing an Entity-component system for my game engine. Every entity keeps a map of components like that :</p> <p>Component.h</p> <pre><code>enum COMPONENT_INFO { COMPONENT_POSITION = 0, COMPONENT_PHYSICS, COMPONENT_RENDERABLE }; </code></pre> <p>Entity.h</p> <pre><code>class Entity { public: std::bitset&lt;NUM_COMPONENTS&gt; componentBits; std::map&lt;COMPONENT_INFO, Component*&gt; components; .. .. Component *getComponent(COMPONENT_INFO inf) { return components[inf]; } }; </code></pre> <p>And my System class updates every entity per frame like that :</p> <pre><code>void update(Entity *e, float delta) { PositionComponent *cmp=(PositionComponent*)e-&gt;getComponent(COMPONENT_INFO::COMPONENT_PHYSICS); //x += 1.0f; cmp-&gt;x += 1.0f; } </code></pre> <p>Everything works as intended, but I have a huge performance problem in accessing the map. When I create 10000 entities and iterate through them (the system iterates through actually), I get 80 FPS with a blue blank system(no visual effects, just plain screen). But when I comment out the access parts and only use <code>x += 1.0f;</code>, FPS increadibly increases to 1000. Like that :</p> <pre><code>void update(Entity *e, float delta) { x += 1.0f; //btw the system has a local x value. } </code></pre> <p>So the problem is simply at accessing the components through the map. What else can I use on a system like that ? Or maybe I am doing something wrong in accessing the map ? </p> <p>Important Edit : This is just a test drive, I mean there might be lots of components per entity, not just 3. I wrote these for just testing purposes. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload