2014-03-25 17:26:13 -04:00
|
|
|
// MetaRotator.h
|
2014-03-02 15:29:20 -05:00
|
|
|
|
|
|
|
// Provides a mixin for rotations and reflections
|
|
|
|
|
2014-02-27 14:33:35 -05:00
|
|
|
#pragma once
|
|
|
|
|
2014-03-09 12:58:01 -04:00
|
|
|
// MSVC generates warnings for the templated AssertIfNotMatched parameter conditions, so disable it:
|
|
|
|
#ifdef _MSC_VER
|
2014-07-17 16:15:34 -04:00
|
|
|
#pragma warning(disable: 4127) // Conditional expression is constant
|
2014-03-09 12:58:01 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-02 15:29:20 -05:00
|
|
|
/*
|
|
|
|
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>
|
2014-03-25 17:26:13 -04:00
|
|
|
class cMetaRotator : public Base
|
2014-02-27 14:33:35 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-03-25 17:26:13 -04:00
|
|
|
cMetaRotator(BLOCKTYPE a_BlockType) :
|
2014-02-27 14:33:35 -05:00
|
|
|
Base(a_BlockType)
|
|
|
|
{}
|
|
|
|
|
2014-03-25 17:26:13 -04:00
|
|
|
virtual ~cMetaRotator() {}
|
2014-02-27 14:33:35 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-09 12:58:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-02 15:29:20 -05:00
|
|
|
template<class Base, NIBBLETYPE BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched>
|
2014-03-25 17:26:13 -04:00
|
|
|
NIBBLETYPE cMetaRotator<Base, BitMask, North, East, South, West, AssertIfNotMatched>::MetaRotateCW(NIBBLETYPE a_Meta)
|
2014-02-27 14:33:35 -05:00
|
|
|
{
|
2014-03-02 15:29:20 -05:00
|
|
|
NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
|
|
|
|
switch (a_Meta & BitMask)
|
2014-03-01 12:47:27 -05:00
|
|
|
{
|
2014-07-17 16:50:58 -04:00
|
|
|
case South: return West | OtherMeta;
|
|
|
|
case West: return North | OtherMeta;
|
2014-03-01 12:47:27 -05:00
|
|
|
case North: return East | OtherMeta;
|
|
|
|
case East: return South | OtherMeta;
|
|
|
|
}
|
2014-03-02 15:29:20 -05:00
|
|
|
if (AssertIfNotMatched)
|
2014-03-01 12:47:27 -05:00
|
|
|
{
|
|
|
|
ASSERT(!"Invalid Meta value");
|
|
|
|
}
|
2014-03-08 09:23:00 -05:00
|
|
|
return a_Meta;
|
2014-02-27 14:33:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-08 09:23:00 -05:00
|
|
|
|
2014-03-09 12:58:01 -04:00
|
|
|
|
|
|
|
|
2014-03-02 15:29:20 -05:00
|
|
|
template<class Base, NIBBLETYPE BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched>
|
2014-03-25 17:26:13 -04:00
|
|
|
NIBBLETYPE cMetaRotator<Base, BitMask, North, East, South, West, AssertIfNotMatched>::MetaRotateCCW(NIBBLETYPE a_Meta)
|
2014-02-27 14:33:35 -05:00
|
|
|
{
|
2014-03-02 15:29:20 -05:00
|
|
|
NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
|
|
|
|
switch (a_Meta & BitMask)
|
2014-03-01 12:47:27 -05:00
|
|
|
{
|
2014-07-17 16:50:58 -04:00
|
|
|
case South: return East | OtherMeta;
|
2014-03-01 12:47:27 -05:00
|
|
|
case East: return North | OtherMeta;
|
|
|
|
case North: return West | OtherMeta;
|
|
|
|
case West: return South | OtherMeta;
|
|
|
|
}
|
2014-03-02 15:29:20 -05:00
|
|
|
if (AssertIfNotMatched)
|
2014-03-01 12:47:27 -05:00
|
|
|
{
|
|
|
|
ASSERT(!"Invalid Meta value");
|
|
|
|
}
|
2014-03-08 09:23:00 -05:00
|
|
|
return a_Meta;
|
2014-02-27 14:33:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-09 12:58:01 -04:00
|
|
|
|
|
|
|
|
2014-03-02 15:29:20 -05:00
|
|
|
template<class Base, NIBBLETYPE BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched>
|
2014-03-25 17:26:13 -04:00
|
|
|
NIBBLETYPE cMetaRotator<Base, BitMask, North, East, South, West, AssertIfNotMatched>::MetaMirrorXY(NIBBLETYPE a_Meta)
|
2014-02-27 14:33:35 -05:00
|
|
|
{
|
2014-03-02 15:29:20 -05:00
|
|
|
NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
|
|
|
|
switch (a_Meta & BitMask)
|
2014-03-01 12:47:27 -05:00
|
|
|
{
|
|
|
|
case South: return North | OtherMeta;
|
|
|
|
case North: return South | OtherMeta;
|
|
|
|
}
|
|
|
|
// Not Facing North or South; No change.
|
|
|
|
return a_Meta;
|
2014-02-27 14:33:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-09 12:58:01 -04:00
|
|
|
|
2014-03-02 15:29:20 -05:00
|
|
|
template<class Base, NIBBLETYPE BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched>
|
2014-03-25 17:26:13 -04:00
|
|
|
NIBBLETYPE cMetaRotator<Base, BitMask, North, East, South, West, AssertIfNotMatched>::MetaMirrorYZ(NIBBLETYPE a_Meta)
|
2014-02-27 14:33:35 -05:00
|
|
|
{
|
2014-03-02 15:29:20 -05:00
|
|
|
NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
|
|
|
|
switch (a_Meta & BitMask)
|
2014-03-01 12:47:27 -05:00
|
|
|
{
|
|
|
|
case West: return East | OtherMeta;
|
|
|
|
case East: return West | OtherMeta;
|
|
|
|
}
|
|
|
|
// Not Facing East or West; No change.
|
|
|
|
return a_Meta;
|
2014-02-27 14:33:35 -05:00
|
|
|
}
|
2014-03-09 12:58:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|