Sign in to follow this  
McGrane

Loading Maps ... with a pointer ?

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this