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;
}
}
}
}
Loading Maps ... with a pointer ?
Hi all,
Im trying to make a DrawMap function that can take in all my maps and Draw which ones i want, like ...
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 ;)
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.
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 ;)
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 ;)
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement