summaryrefslogtreecommitdiffstats
path: root/src/Blocks/MetaRotater.h
blob: f1656f1bd36564690022ed4f6c19cae25407fb61 (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
73
74
75
76
77
78
79
80
81
82

#pragma once

template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
class cMetaRotater : public Base
{
public:

	cMetaRotater(BLOCKTYPE a_BlockType) :
		Base(a_BlockType)
	{}
	
	virtual ~cMetaRotater() {}

	virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta)  override;
	virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta)  override;
	virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta)  override;
	virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta)  override;
};


template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
NIBBLETYPE cMetaRotater<Base, BitFilter, North, East, South, West>::MetaRotateCW(NIBBLETYPE a_Meta)
{
NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
switch (a_Meta & BitFilter)
{
case South: return West  | OtherMeta; 
case West:  return North | OtherMeta; 
case North: return East  | OtherMeta;
case East:  return South | OtherMeta;
}
ASSERT(!"Invalid Meta value");
return a_Meta;
}


template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
NIBBLETYPE cMetaRotater<Base, BitFilter, North, East, South, West>::MetaRotateCCW(NIBBLETYPE a_Meta)
{
NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
switch (a_Meta & BitFilter)
{
case South: return East  | OtherMeta; 
case East:  return North | OtherMeta;
case North: return West  | OtherMeta;
case West:  return South | OtherMeta;
}
ASSERT(!"Invalid Meta value");
return a_Meta;
}



template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
NIBBLETYPE cMetaRotater<Base, BitFilter, North, East, South, West>::MetaMirrorXY(NIBBLETYPE a_Meta)
{
NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
switch (a_Meta & BitFilter)
{
case South: return North | OtherMeta;
case North: return South | OtherMeta;
}
// Not Facing North or South; No change.
return a_Meta;
}




template<class Base, NIBBLETYPE BitFilter, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West>
NIBBLETYPE cMetaRotater<Base, BitFilter, North, East, South, West>::MetaMirrorYZ(NIBBLETYPE a_Meta)
{
NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
switch (a_Meta & BitFilter)
{
case West: return East | OtherMeta;
case East: return West | OtherMeta;
}
// Not Facing East or West; No change.
return a_Meta;
}