So working on an little project but thinking about making maps efficient. I have a grid of numbers say
100110
011011
010110
If you’ve ever played dungeon keeper, the idea is a 0 is a flat dug out square, and 1 is a still standing square.
I want to take advantage of the grid layout and be able to minimise the number of vertexes used. So instead of using individuals cubes for an area like:
1111
1111
1111
I want to just use 8.
Any idea on the best approach to this? or even just knows the name of the type of algorithm i should use. Something that can do it quickly on the fly would be preferable so not to bottle neck rendering.
I agree that this is probably not gonna be a performance issue, but you could represent your map in a compressed map by using a (slightly modified) unbalanced Quad-tree.
Start by your map consisting only of 1’s. You can store this as a box of size n*n in the root node of your tree.
IF you want to dig out one of the boxes you recursively walk down the tree, splitting the n*n box (or whatever you find there) using the default quad tree rules (= split an n*n box into four n/2*n/2 boxes, etc.). At some point you’ll arrive in a leaf of the tree that only contains the single box (the one you want to dig out) and you may change it from 1 to 0.
Additionally, after the leaf has changed and your recursive calls return (= you walk back up the tree towards the root node), you can check neighboring boxes for whether they may be merged. (If you have two neighboring boxes that are both dug out, you can merge them).
Another technique that is sometimes used when indexing low-dimensional data like this is a space filling curve. One that has good average locality and is reversible is the Hilbert curve. Basically, you may enumerate your boxes (dug out ones and filled ones) along the space filling curve and then use simple run-length compression.
The tree-idea allows you to reduce the number of rendered geometry (you can rescale texture, etc. to emulate n*n boxes by a single larger box). The space filling curve probably will only save you some memory.