1 /**
2 Copyright: Copyright (c) 2013-2016 Andrey Penechko.
3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
4 Authors: Andrey Penechko.
5 */
6 module voxelman.core.block;
7 
8 import voxelman.core.config;
9 
10 
11 struct Block
12 {
13 	BlockType id;
14 	string name;
15 	ubyte[3] color;
16 	bool isVisible;
17 
18 	ubyte[] mesh(ubyte bx, ubyte by, ubyte bz, ubyte sides, ubyte sidesnum) const
19 	{
20 		return getMesh(this, bx, by, bz, sides, sidesnum);
21 	}
22 
23 	bool function (Side side) isSideTransparent;
24 	ubyte[] function(const Block block,
25 		ubyte bx, ubyte by, ubyte bz, ubyte sides, ubyte sidesnum) getMesh;
26 }
27 
28 enum Side : ubyte
29 {
30 	north	= 0,
31 	south	= 1,
32 
33 	east	= 2,
34 	west	= 3,
35 
36 	top		= 4,
37 	bottom	= 5,
38 }
39 
40 immutable ubyte[6] oppSide = [1, 0, 3, 2, 5, 4];
41 
42 immutable byte[3][6] sideOffsets = [
43 	[ 0, 0,-1],
44 	[ 0, 0, 1],
45 	[ 1, 0, 0],
46 	[-1, 0, 0],
47 	[ 0, 1, 0],
48 	[ 0,-1, 0],
49 ];
50 
51 Side sideFromNormal(ivec3 normal)
52 {
53 	if (normal.x == 1)
54 		return Side.east;
55 	else if (normal.x == -1)
56 		return Side.west;
57 
58 	if (normal.y == 1)
59 		return Side.top;
60 	else if (normal.y == -1)
61 		return Side.bottom;
62 
63 	if (normal.z == 1)
64 		return Side.south;
65 	else if (normal.z == -1)
66 		return Side.north;
67 
68 	return Side.north;
69 }