Note that there are some explanatory texts on larger screens.

plurals
  1. POIterating and storing thousands/millions of objects efficiently
    primarykey
    data
    text
    <p>I am working on a simulation where I need to be able to handle thousands potentialy millions of objects updating every loop. All of the objects need to have their logic function called (AI). But depending on the location of the object determines how detailed the logic will be. For example:</p> <p>[working with 100 objects to keep it simple]</p> <ul> <li>All objects have a location (x,y)</li> <li><code>20</code> objects are 500 points away from a 'point of interest' location.</li> <li><code>50</code> objects are 500 points from the <code>20</code> objects (1000 points away).</li> <li><code>30</code> objects are within 100 points from the point of interest.</li> </ul> <p>Now say this was a detailed city simulation with the objects being virtual citizens. At 6pm it's time for everyone to go home from their jobs and sleep.</p> <p>So we iterate through all citizens, but I'm wanting them to do different things.</p> <ul> <li>The furtherest away objects (50) Go home from their job and sleep until morning. </li> <li>The closer objects (20) Go home from their job, have a bite to eat then sleep until morning. </li> <li>The closest objects (30) Go home from their job, have a bite to eat, brush teeth then sleep until morning.</li> </ul> <p>As you can see the closer they are to the point of interest the more detailed the logic becomes.</p> <p>I am trying to work out what the best and most performance efficient way to iterate through all objects would be. This would be relativly easy with a hand full of objects but as this needs to handle at lest 500,000 objects efficiently, I need some advice.</p> <p>Also I'm not sure if I should iterate through all objects every loop or maybe it would be better to iterate through the closest objects every loop but only itereate through further away objects every 10 loops?</p> <p>With the additional requirement of needing the objects to interact between other objects close to them, I have been thinking the best way to do this might be to organise them in a quadtree but I'm not sure. It seems as though quad trees are more for static content, but the objects i'm dealing with, as mentioned have a location and are required to move to other locations. Am I going down the right track of thinking? or is there a 'better' way?</p> <p>I am also working in c++ if anyone thinks its relevant. </p> <p>Any advise would be greatly appreciated. </p> <p><strong>NOTE:</strong></p> <ol> <li>The point of interest changes regularly, think of it as a camera view.</li> <li>Objects are created and destroyed dynamically</li> </ol>
    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.
    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