summaryrefslogtreecommitdiff
path: root/src/main/java/com/encrox/instancedregions/chunkmap/ChunkMapBuffer.java
blob: e138c9fb406f026c7a38849074e725dce5de666c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 * @author Aleksey Terzi
 *
 */

package com.encrox.instancedregions.chunkmap;

public class ChunkMapBuffer {
	private static final int BITS_PER_BLOCK_SIZE = 1;
	private static final int PALETTE_LENGTH_SIZE = 5;
	private static final int DATA_ARRAY_LENGTH_SIZE = 5;
	private static final int BLOCKS_PER_CHUNK_SECTION = 16 * 16 * 16;
	private static final int DATA_ARRAY_SIZE = BLOCKS_PER_CHUNK_SECTION * 13 / 8;
	private static final int BLOCK_LIGHT_SIZE = BLOCKS_PER_CHUNK_SECTION / 2;
	private static final int SKY_LIGHT_SIZE = BLOCKS_PER_CHUNK_SECTION / 2;
	private static final int COLUMNS_PER_CHUNK = 16;
	
	private static final int MAX_BYTES_PER_CHUNK =
			COLUMNS_PER_CHUNK *
			(
				BITS_PER_BLOCK_SIZE
				+ PALETTE_LENGTH_SIZE
				+ DATA_ARRAY_LENGTH_SIZE
				+ DATA_ARRAY_SIZE
				+ BLOCK_LIGHT_SIZE
				+ SKY_LIGHT_SIZE
			);
	
	public int[] palette;
	public byte[] output;
	public int[] outputPalette;
	public byte[] outputPaletteMap;
	public ChunkWriter writer;
	public ChunkLayer prevLayer;
	public ChunkLayer curLayer;
	public ChunkLayer nextLayer;
	
	public int bitsPerBlock;
	public int paletteLength;
	public int dataArrayLength;
	public int lightArrayLength;
	public int dataArrayStartIndex;
	public int outputPaletteLength;
	public int outputBitsPerBlock;
    
	public ChunkMapBuffer() {
    	this.palette = new int[256];
		this.output = new byte[MAX_BYTES_PER_CHUNK];
		this.outputPalette = new int[256];
		this.outputPaletteMap = new byte[65536];
		this.writer = new ChunkWriter(this.output);
		this.prevLayer = new ChunkLayer();
		this.prevLayer.map = new int[16 * 16];
		this.curLayer = new ChunkLayer();
		this.curLayer.map = new int[16 * 16];
		this.nextLayer = new ChunkLayer();
		this.nextLayer.map = new int[16 * 16];
	}
	
	public void clearLayers() {
		this.prevLayer.hasData = false;
		this.curLayer.hasData = false;
		this.nextLayer.hasData = false;
	}
}