Jump to content

  • Log In with Google      Sign In   
  • Create Account

Map "areas"


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 mike3   Members   -  Reputation: 149

Like
0Likes
Like

Posted 31 August 2013 - 06:32 PM

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?



Sponsor:

#2 Endurion   Crossbones+   -  Reputation: 3682

Like
0Likes
Like

Posted 31 August 2013 - 11:30 PM

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.


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#3 mike3   Members   -  Reputation: 149

Like
0Likes
Like

Posted 01 September 2013 - 05:52 AM

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?



#4 Endurion   Crossbones+   -  Reputation: 3682

Like
0Likes
Like

Posted 01 September 2013 - 08:36 AM

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.


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#5 mike3   Members   -  Reputation: 149

Like
0Likes
Like

Posted 01 September 2013 - 03:30 PM

However, what happens when a sector overlaps multiple areas?



#6 Endurion   Crossbones+   -  Reputation: 3682

Like
0Likes
Like

Posted 01 September 2013 - 10:30 PM

In that case I'd put the trigger in all areas. There may be some duplicated checks then but in the total that shouldn't make much of a difference.


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#7 Krohm   Crossbones+   -  Reputation: 3245

Like
0Likes
Like

Posted 02 September 2013 - 12:53 AM

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.






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