Ok, let me explain this with an example (oh and by the way the "zone" partitionning is a good idea!)
What I want to do is a terrain like my subdivided with tiles. Let's define what a tile is:
A tile is a square subdivided into small triangle making little square. So, a tile has about 10x10 small pane into it. So, that's about 200 polys (triangle). I can modify the poly coords to make terrain effects in it. A tile is also as large as a character in the screen, so it is not big like a terrain.
Now, let's define map:
A map is made of tiles aligned to each other (with the height of each tiles) Making the map like a Warcraft 3 map. A map can have 64x64, 128x128, 100x50, etc. tiles. Though, I'm just showing what the camera is seeing, let's say the camera is pointing the character like warcraft. So, I just want to show maybe 16x16 tiles.
Well, now that's where the problem lies. The basic way to do this is surely a 2D array, containing the tiles informations.
and then getting the character position in the map, x and y, and limiting the vue to x + 8, x - 8, y + 8, y - 8.
now you can loop with 2 for loops like this:
for ( int y = charY - 8; y < charY + 8; y++ )
for ( int x = charX - 8; x < charX + 8; x++ )
if (we're not outside the array && the tile isn't null )
- [y] );
ok, it can be a bit long, I thought of another way that is making an array with one dimension like this:
tile[x * y]
// getting the top left 16x16 square depending on the character position
topleftSquare = ( mapSizeX * charY ) + charX;
// getting the bottom left 16x16 square depending on the character position
bottomleftSquare = ( mapSizeX * charY ) + charX;
for ( int i = topleftSquare; i < bottomleftSquare; i++ )
enable( tile )
I don't know if it's really faster, but anyway.
Another way could be making different BranchGroup, called zone. And when I'm approching of one zone, I enable it. While this solution can be the fastest (perhaps) It can be a problem if I'm in a 40x40 tiles zone and I load up a 40x40 zone.
Or, I could load the map, and divid it into small 16x16 tile not caring of what the map is made of (a "room" could be cut in a half) but the user will not see this, since 16x16 is as large as the screen view.
Any thought is welcome, I'm a bit lost in all this