Block Compiler

Home --> Programming Projects --> Block Engine --> Block Compiler
Anyone who makes a Block Based game will at some point have a need for compressing thousands of blocks into a smaller amount of information. The program BlockCompiler does just this. This program demonstates the same sort of algorithm as the Quad Algorithm, but it is much simpler.

How To Use It

The program bc.exe reads block information from standard input and outputs information to standard output. The program can be run as follows:
bc.exe < input.txt > output.txt
Both input.txt and output.txt are text files. Suppose the content of input.txt is as follows:
0 0 0 5
0 1 0 5
1 0 0 42
1 1 0 7
The file format is as follows: each line consists of 4 integers: "x y z t". The numbers x, y, and z refer to the position (x,y,z) of a block in the world. The integer t refers to the texture of that block. Hence, the file input.txt is claiming that there is a block at position (0,0,0) in the world with texture 5, a block at (0,1,0) with texture 5, a block at (1,0,0) with texture 42, and a block at (1,1,0) with texture 7.

Adjacent blocks of the same texture can be "merger together", but blocks of different textures cannot. After running the program, the contents of the file output.txt should be as follows:
0 0 0 0 1 0 5
1 0 0 1 0 0 42
1 1 0 1 1 0 7
Each line of the file output.txt is of the form "x_min y_min z_min x_max y_max z_max t". Each line is expressing the fact that there is a three-dimensional array of blocks in the world with a particular texture. The bounds are inclusive. For instance, the first line of output.txt is saying that there is a block with texture 5 at both position (0,0,0) and (0,1,0).

For a less trivial example, use the file input.txt within in the TestData directory of the source code.

How It Works

The algorithm works very similarly to the Quad Algorithm but with "Block Rectangles" in 3D-space instead of "Quads" in 2D-space. That is, blocks are added one at a time, and block rectangles are merged together greedily. The program can be trivially changed so that blocks store additional information instead of just their texture. It would then be that only blocks with identical "additional information" can be merged together. The program is the way it is now for simplicity.

How To Build It

Here is the source code to the program. The executable is not included. To compile the program, simply extract the zip file, cd into that directory, and run the command "make". The Makefile will then call g++ to compile the c++ program bc.exe.