Jump to content
  • Advertisement
Sign in to follow this  
McGrane

Loading Maps ... with a pointer ?

This topic is 5128 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 all, Im trying to make a DrawMap function that can take in all my maps and Draw which ones i want, like ...
void DrawMap(int* Map)
{
	
	for( int y = 0; y < MAPHEIGHT; y++)
	{
	for( int x = 0; x < MAPWIDTH;  x++)
	{

	switch(&Map[y][x])
	{
	case 0:
	DrawQuad(/*Whatever Pos's And Textures*/);
	break;
	}

	}
	}

}

Im not sure on how to get it to work, or evan if this is the best way to do it? (c++, opengl, dev-cpp, windows) Thanks for anyhelp ;)

Share this post


Link to post
Share on other sites
Advertisement
This wouldn't be very optimal if you had a very large map. I would suggest inserting the quads into a quad-tree structure, or sectorizing the map in some way. That way you can have very fast visibility and collision culling without having to check against every quad in your map.

Share this post


Link to post
Share on other sites
But the map shouldnt get too big, frogot to mention,
Im making it that once you go off the first map the 2nd one is displayed ... thats why i wanted a map loader. It goes screen by screen.
Im not too sure on what a quadtree is so im googling it now,
Thanks for the reply ;)

Share this post


Link to post
Share on other sites
For a simple tile-based system you don't need a quadtree (it's for worlds with quads laid out in an arbitrary way).

This is an OK way to do things, though I'd recommend two changes:

Firstly, you're only every going to be using one map at a time, right? In which case you're probably better off having a global pointer called something like g_pCurrentMap, which the DrawMap function always uses, instead of asking people to pass in a pointer to the map each time. It's simpler if you can just change the map pointer in one place and have everything else just use the new map automatically without having to throw the pointer around.

Secondly, I'm not convinced that indexing works, because Map is an int* instead of an int*[]. If you're going to be throwing pointers around like this, I'd recommend sticking to a 1D array using index math - so Map[y][x] becomes Map[ (y * MAPWIDTH) + x ]. That way there's never any question about how it works and is laid out in memory.

Share this post


Link to post
Share on other sites
Thanks for the help ;)
I see what you mean and will try that out when i get home.
This post was ment to help me find a good way of doing this,
so i wont be throughing around pointers anymore ;)
Thanks again :P

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!