Jump to content

  • Log In with Google      Sign In   
  • Create Account

Handling large entities on a grid


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1   Members   -  Reputation: 1486

Like
0Likes
Like

Posted 16 January 2014 - 08:36 PM

My world is made up of 'regions' laid out in a grid and I have some entities that could be overlapping several regions at once. I need some way of querying what entity (if any) is at a given world position.

I had thought I could do it with octrees but I can't really see them working. The first issue is that I can't just have 1 octree for the whole world, because I have to deal with multiplayer and having multiple players that could potentially be very very far away from each other. If I instead do 1 octree per region, that leads to more problems: if an entity is in region 1 and 2, and I query a position inside region 2 which the entity overlaps, region 2 won't have an entry for it.

I could possibly duplicate the entries so that both octrees have the same entry and it wouldn't matter which you queried, but then I run into another problem: I can't add entries to a region which isn't loaded yet.

Another solution might be to query all the neighbor regions' octrees if nothing is found within the octree of the original region. That means even more time taken to find an entity and either require that entities be no larger than a single region or I'd have to keep expanding the search outwards. Overall not a terrible solution, but not one I'm particularly happy with.

Anyone else have some better solutions? Whatever structure is used needs to be buildable in realtime, these entities are dynamically placed.

Edited by Telanor, 16 January 2014 - 08:38 PM.


#2   Moderators   -  Reputation: 21096

Like
0Likes
Like

Posted 16 January 2014 - 09:40 PM

You need to provide more context.

How many grid cells are there? How many of these entities? How many grid cells can a single entity possibly overlap?
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

#3   Crossbones+   -  Reputation: 24553

Like
0Likes
Like

Posted 16 January 2014 - 09:55 PM

What range do they (or the whole world) cover?

 

 

L. Spiro



#4   Members   -  Reputation: 1486

Like
0Likes
Like

Posted 16 January 2014 - 10:01 PM

Sure. By grid cells do you mean within a region? or grid cells of regions? In the first case, its 32x32x256, in the second case, unlimited (its an infinite world). Entity numbers are variable. Like I said, the user is placing them down. I'd probably guess there'd typically be less than 100 in a single region, though if they build a massive vertical structure, there could be a lot more. As for how many cells an entity can overlap, I'm not sure, we haven't made all of them yet. It wouldn't likely much of an issue to limit the max size to that of a region (32x32x256), as that's quite large. I'd say on average, probably won't be more than a few dozen for most entities.

Edited by Telanor, 16 January 2014 - 10:04 PM.


#5   Crossbones+   -  Reputation: 3951

Like
0Likes
Like

Posted 17 January 2014 - 04:28 AM


I could possibly duplicate the entries so that both octrees have the same entry and it wouldn't matter which you queried, but then I run into another problem: I can't add entries to a region which isn't loaded yet.
I don't think you want to query the octrees of regions that you haven't loaded.

When you load a region, not earlier, you can collect overlapping entities in nearby regions.and add references in the new region.


Omae Wa Mou Shindeiru


#6   Moderators   -  Reputation: 21096

Like
0Likes
Like

Posted 17 January 2014 - 02:15 PM

You seem to be thinking of the problem inside-out.


Don't build a spatial partitioning structure and then assume that every object will only belong neatly to one subspace. Instead, build a spatial partitioning structure and give each subspace an identifier (or just hold a pointer to it, more efficient). Then, each entity you have maintains a list of which partition subspaces it overlaps. If the entity moves, rebuild the membership list. If the world is mutated sufficiently, rebuild the spatial partitioning structure.

Octrees should be sufficient for this although you might have better results in non-uniform worlds with a kd-tree instead.
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

#7   Members   -  Reputation: 1486

Like
0Likes
Like

Posted 17 January 2014 - 08:43 PM

So it's looking like I need to set it up like this:

* When a region loads, load in any saved entities and add them to the octree.
* Query the 8 neighbor regions. For any that are loaded:
- Find any entities in the current region that overlap the neighbor region (loop all entities and do a check?) and add them to the neighbor's octree
- Find any entities in the neighbor region that overlap the current region and add them to current region's octree

That's going to be a lot of looping over all entities. Should I be concerned about this? Is there a better way? I know the answer is probably going to be "test and find out" but I figured I'd ask before I waste time implementing it.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS