summaryrefslogtreecommitdiffstats
path: root/src/Blocks/MetaRotater.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-03-08 18:27:24 +0100
committerMattes D <github@xoft.cz>2014-03-08 18:27:24 +0100
commit3a6499b192b4d0cf28d960a5f9ac09ee44265d5c (patch)
tree3fabece6b0dbac4c229453c81f1a57bb248ef9b8 /src/Blocks/MetaRotater.h
parentMerge pull request #770 from xdot/master (diff)
parentMoved returns (diff)
downloadcuberite-3a6499b192b4d0cf28d960a5f9ac09ee44265d5c.tar
cuberite-3a6499b192b4d0cf28d960a5f9ac09ee44265d5c.tar.gz
cuberite-3a6499b192b4d0cf28d960a5f9ac09ee44265d5c.tar.bz2
cuberite-3a6499b192b4d0cf28d960a5f9ac09ee44265d5c.tar.lz
cuberite-3a6499b192b4d0cf28d960a5f9ac09ee44265d5c.tar.xz
cuberite-3a6499b192b4d0cf28d960a5f9ac09ee44265d5c.tar.zst
cuberite-3a6499b192b4d0cf28d960a5f9ac09ee44265d5c.zip
Diffstat (limited to '')
-rw-r--r--src/Blocks/MetaRotater.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h
new file mode 100644
index 000000000..d3664b6f1
--- /dev/null
+++ b/src/Blocks/MetaRotater.h
@@ -0,0 +1,99 @@
+// MetaRotater.h
+
+// Provides a mixin for rotations and reflections
+
+#pragma once
+
+/*
+Provides a mixin for rotations and reflections following the standard pattern of apply mask then use case.
+
+Usage:
+Inherit from this class providing your base class as Base, the BitMask for the direction bits in bitmask and the masked value for the directions in North, East, South, West. There is also an aptional parameter AssertIfNotMatched. Set this if it is invalid for a block to exist in any other state.
+*/
+
+template<class Base, NIBBLETYPE BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched = false>
+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 BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched>
+NIBBLETYPE cMetaRotater<Base, BitMask, North, East, South, West, AssertIfNotMatched>::MetaRotateCW(NIBBLETYPE a_Meta)
+{
+ NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
+ switch (a_Meta & BitMask)
+ {
+ case South: return West | OtherMeta;
+ case West: return North | OtherMeta;
+ case North: return East | OtherMeta;
+ case East: return South | OtherMeta;
+ }
+ if (AssertIfNotMatched)
+ {
+ ASSERT(!"Invalid Meta value");
+ }
+ return a_Meta;
+}
+
+
+
+template<class Base, NIBBLETYPE BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched>
+NIBBLETYPE cMetaRotater<Base, BitMask, North, East, South, West, AssertIfNotMatched>::MetaRotateCCW(NIBBLETYPE a_Meta)
+{
+ NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
+ switch (a_Meta & BitMask)
+ {
+ case South: return East | OtherMeta;
+ case East: return North | OtherMeta;
+ case North: return West | OtherMeta;
+ case West: return South | OtherMeta;
+ }
+ if (AssertIfNotMatched)
+ {
+ ASSERT(!"Invalid Meta value");
+ }
+ return a_Meta;
+}
+
+
+
+template<class Base, NIBBLETYPE BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched>
+NIBBLETYPE cMetaRotater<Base, BitMask, North, East, South, West, AssertIfNotMatched>::MetaMirrorXY(NIBBLETYPE a_Meta)
+{
+ NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
+ switch (a_Meta & BitMask)
+ {
+ case South: return North | OtherMeta;
+ case North: return South | OtherMeta;
+ }
+ // Not Facing North or South; No change.
+ return a_Meta;
+}
+
+
+
+
+template<class Base, NIBBLETYPE BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched>
+NIBBLETYPE cMetaRotater<Base, BitMask, North, East, South, West, AssertIfNotMatched>::MetaMirrorYZ(NIBBLETYPE a_Meta)
+{
+ NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
+ switch (a_Meta & BitMask)
+ {
+ case West: return East | OtherMeta;
+ case East: return West | OtherMeta;
+ }
+ // Not Facing East or West; No change.
+ return a_Meta;
+}