summaryrefslogtreecommitdiffstats
path: root/Tools/QtBiomeVisualiser/Region.cpp
blob: d8a0a2f76da42ad80199d267552d6d063ec928b0 (plain) (blame)
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
66
67
68
69
70
71
72

#include "Globals.h"
#include "Region.h"





Region::Region()
{
}





Chunk & Region::getRelChunk(int a_RelChunkX, int a_RelChunkZ)
{
		ASSERT(a_RelChunkX >= 0);
		ASSERT(a_RelChunkZ >= 0);
		ASSERT(a_RelChunkX < 32);
		ASSERT(a_RelChunkZ < 32);

		return m_Chunks[a_RelChunkX + a_RelChunkZ * 32];
}





int Region::getRelBiome(int a_RelBlockX, int a_RelBlockZ)
{
	ASSERT(a_RelBlockX >= 0);
	ASSERT(a_RelBlockZ >= 0);
	ASSERT(a_RelBlockX < 512);
	ASSERT(a_RelBlockZ < 512);

	int chunkX = a_RelBlockX / 16;
	int chunkZ = a_RelBlockZ / 16;
	Chunk & chunk = m_Chunks[chunkX + 32 * chunkZ];
	if (chunk.isValid())
	{
		return chunk.getBiome(a_RelBlockX - 16 * chunkX, a_RelBlockZ - 16 * chunkZ);
	}
	else
	{
		return biInvalidBiome;
	}
}




void Region::blockToRegion(int a_BlockX, int a_BlockZ, int & a_RegionX, int & a_RegionZ)
{
	a_RegionX = static_cast<int>(std::floor(static_cast<float>(a_BlockX) / 512));
	a_RegionZ = static_cast<int>(std::floor(static_cast<float>(a_BlockZ) / 512));
}





void Region::chunkToRegion(int a_ChunkX, int a_ChunkZ, int & a_RegionX, int & a_RegionZ)
{
	a_RegionX = static_cast<int>(std::floor(static_cast<float>(a_ChunkX) / 32));
	a_RegionZ = static_cast<int>(std::floor(static_cast<float>(a_ChunkZ) / 32));
}