Efficient Tile Map

Blitz3D Forums/Blitz3D Programming/Efficient Tile Map

LuckyPhil(Posted 2004) [#1]
I'm re-writting a 2D game into 3D. The game has a tile map (30x30).. so I've created a single tile mesh (simply a flat square 16x16 units). I've placed this tile mesh 30x30 times (900) into the game world, and as expected, it is quite slow.

I created a pvit object and made it the parent for each tile. So when I move the pivot, all the tiles move (quite nice actually)

My question is: Am I going about this the right way? There are world builders out there, but they all seem to be geared to outside, wilderness type terrain. I want objects and certain tile textures in certain places (the orig game is grid based, and I'd like to keep it that way if possible).

Is this making any sense?

Cheers,
Phil.


Shambler(Posted 2004) [#2]
You need to make a single mesh that contains all of your flat squares rather than have 30*30 individual ones.

All the flat squares that share the same texture can be on the same surface in that mesh.

The combination of the above will speed it up no end.


Afrohorse(Posted 2004) [#3]
Yes, having 900(30x30) separate objects would be slow, but also having one big object would mean it would try and draw all the tiles, all the time.

As these are tiles and the textures aren't repeated inside each tile you can put all the individual textures into one big super texture and use the UV coordinates in the vertices that make up the tiles to map into 'parts' this big texture. This way you only have to use one texture (this reduces texture swaps and will speed things up) and you can setup the surfaces however you like. You have to be a little careful doing this though, when the textures are mip-mapped they can bleed into each on the super texture, so its best to either move the UV coordinates inwards slightly, or put a border around the 'sub-textures'. (Ok - it's not the best explaination in the world, it's quite a common technique - but I can't find a link that explains it! )

Then, split up the tiles into patches - for instance make objects that have 10x10 tiles in it, so you'd have 9(3x3) objects. This way, blitz can clip out the patches that aren't seen.


EOF(Posted 2004) [#4]
you can put all the individual textures into one big super texture and use the UV coordinates in the vertices that make up the tiles to map into 'parts' this big texture
*Cough* .. ImagePacker will do this for you.

Just throw all of your images into ImagePacker and save the 'pack'. The saved pack will have an associated definitions file containing the details of each image stored in the pack such as name, x, y, width, height, and animation setting.

You can also generate Blitz code to display all of the images using a single-surface quad system (SpriteMaster) or regular 2d images (ImageMaster).

See this thread for more info: Image Packer


LuckyPhil(Posted 2004) [#5]
Ok, so this is what I need to do:

- Create 1 big model divitied with 30x30 squares in it instead of 30x30 individial squares.

- Create a surface for each texture that I want to use. 1 surface for all the road tiles, 1 surface for the grass tiles, 1 surface for the road corners, etc..

- UV map each square so that it uses the same point in the texture file

If my world is 30x30 big, and my camera range is say only 20, does that mean that blitz won't draw the last 10 squares of the model, and as you move towards the end, it will draw them.?

Sorry for the newbieish questions, but I just can't get my head around this bit.

Cheers,
Phil.


Matty(Posted 2004) [#6]
Here is an example of creating a grid.
http://www.blitzbasic.com/codearcs/codearcs.php?code=950

Regarding the camera, you can change the camera's range if you have to.

This code also textures the grid in a fairly intuitive manner using a single texture and a single surface (although it is capable of supporing multiple surfaces if you wish).


mearrin69(Posted 2004) [#7]
If my world is 30x30 big, and my camera range is say only 20, does that mean that blitz won't draw the last 10 squares of the model, and as you move towards the end, it will draw them.?



AFAIK, Blitz will draw the whole thing because it's one model. Part of it is in view all of the time, so the whole thing gets included in the mix.

If you're really talking about a lot of polygons and it's killing your machine you might think about breaking the model into a few more parts...say, 10x10 cells per mesh. Then you've got nine models. If you're in the middle facing a corner then only a few of those meshes will get drawn.

At least that's the way I understand it. Anybody correct me on that?
M