diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-02-27 20:33:35 +0100 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-02-27 20:33:35 +0100 |
commit | 84913299f45a28d3bd6146b3decbf14764449030 (patch) | |
tree | 02707f55323bb35f4d0de65a376ba10e3a1fb5e4 /src/Blocks/MetaRotater.h | |
parent | Fixed crash and some warnings in map handling. (diff) | |
download | cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.gz cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.bz2 cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.lz cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.xz cuberite-84913299f45a28d3bd6146b3decbf14764449030.tar.zst cuberite-84913299f45a28d3bd6146b3decbf14764449030.zip |
Diffstat (limited to 'src/Blocks/MetaRotater.h')
-rw-r--r-- | src/Blocks/MetaRotater.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h new file mode 100644 index 000000000..f1656f1bd --- /dev/null +++ b/src/Blocks/MetaRotater.h @@ -0,0 +1,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; +} |