Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle lots of objects in a C++ game
    primarykey
    data
    text
    <h2>The question</h2> <p>Sorry about the title, could not seem to find a shorter/better description..</p> <p>Here's the situation: I am making a simple game in which there is a big map (simple, but very big in size). There are also a lot of enemies on that map, but the action is exclusively around the main character (in a certain radius, which is a very small percentage of the map). </p> <p>At each 'tick' (or step, or whatever you call it), there is a certain function called on each of those objects to determine their next move. For performance reasons, since I do not care about what happens outside of my scope of view (or at least, the very far away stuff), I'd like not to call that function on very foreign objects.</p> <p><strong>How can I manage these objects to make sure I always have a list of the nearby objects that is updated when I move around the map?</strong></p> <p>(I know it is tagged in C++, but any language will do - I'm not looking for code that much - It's more about the idea)</p> <hr> <h2>What I've already tried</h2> <p>I've tried a few alternatives:</p> <ul> <li><strong>Alternative 1:</strong> Separate my map in "zones" and store a list of enemies in each zone. The problem with that is what happens when I'm on edges of those zones and (worse) when I'm on a corner (4 different zones around me). Also, it's harder to make the enemies switch zones if I run from one zone to another (but I had figured out something which could work...)</li> <li><strong>Alternative 2:</strong> Scan the whole map and refresh the active enemies list each time I move <code>x</code> distance. That's a bit better since I don't have to worry abound bounds like Alternative 1, but I do have to scan the whole map each time.</li> </ul> <p>I was now looking at <strong>Alternative 3</strong>, which is to mix those two solutions together. </p> <p>However, I wanted to make sure there is not a more obvious solution.</p>
    singulars
    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.
 

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