Jump to content
  • Advertisement
Sign in to follow this  
mike3

Map "areas"

This topic is 2145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi.

 

Suppose one has a 2D grid map for a game, and one wants to define special "areas" on the map, which could be bounded by a rectangle, ball, or polygon, and to which could be associated an effect or a name or something. I suppose one could store a list of these along with the level map, but what's the most efficient way then to find, given the player's position, which area(s) the player is in? How is this usually handled in games? Is the check performed every time the player moves?

Share this post


Link to post
Share on other sites
Advertisement

Usually I put a sparse container for such things.

 

Whatever it is, it's sorted into sectors which are quite a bit bigger than tiles (say 256x256 or 1000x1000 pixel for example). So everytime the player moves, I check the sectors the players bounding box is touching.

 

Simplest way for such a container is a std::map with sector pos as key and a list of trigger regions as values.

Share this post


Link to post
Share on other sites

Usually I put a sparse container for such things.

 

Whatever it is, it's sorted into sectors which are quite a bit bigger than tiles (say 256x256 or 1000x1000 pixel for example). So everytime the player moves, I check the sectors the players bounding box is touching.

 

Simplest way for such a container is a std::map with sector pos as key and a list of trigger regions as values.

 

But doesn't this constrain the regions significantly? E.g. they must be a union of macro-tiles/sectors, no? And what do you mean "sector pos as key"? The number of each sector?

Share this post


Link to post
Share on other sites

They don't have to be a union of tiles. It does make things easier though. It can be anything as long as its sector pos is calculated from the region somehow.

 

As for sector pos, I meant a simplified position as the sector key (for example the tile position divided by 32). Anything is possible.

 

For example a tile map of 40x20 tiles can make two sectors, both sized 20x20 tiles.

Or 3x2 sectors, when a sector is sized 15x15 tiles.

Share this post


Link to post
Share on other sites

In my system (which is 3D BTW), I just abuse the collision and scripting system.

All collision objects are allowed to have a scripted callback. Most objects have no callbacks at all but those having one are internally promoted to a different mangling. This extra mangling essentially collects their collision events and dispatches the scripted calls.

It is more complicated than doing what Endurion suggests but it bought me some piece of mind. The most prominent advantage is that the system is fully generic and flexible. The drawback is obviously the extra effort involved - even with no scripting in the picture.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!