Created
April 21, 2021 10:01
-
-
Save oiotoxt/b5ab2f2320ee6360f350bd4963c3f003 to your computer and use it in GitHub Desktop.
C++ Lecture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // DpInputState.h | |
| //////////////////////////////////////////////////////////////////////////////// | |
| #ifndef DPINPUTSTATE_H | |
| #define DPINPUTSTATE_H | |
| #include "DpBase.h" | |
| _DP_BGN | |
| //****************************************************************************** | |
| // | |
| //------------------------------------------------------------------------------ | |
| struct eMoveKey | |
| { | |
| enum Enum : Mx::U8 | |
| { | |
| kL = 1 << 0, | |
| kR = 1 << 1, | |
| kT = 1 << 2, | |
| kB = 1 << 3, | |
| }; | |
| }; | |
| //****************************************************************************** | |
| // | |
| //------------------------------------------------------------------------------ | |
| class InputState | |
| { | |
| public: | |
| static const InputState NULL_STATE; | |
| Mx::U8 moveKey; | |
| InputState() { Reset(); } | |
| InputState(const InputState& rhs) | |
| { | |
| *this = rhs; | |
| } | |
| InputState(bool L, bool R, bool T, bool B) | |
| { | |
| Set(L, R, T, B); | |
| } | |
| void Reset() | |
| { | |
| moveKey = 0; | |
| } | |
| bool IsNull() | |
| { | |
| return (*this == NULL_STATE); | |
| } | |
| InputState& operator = (const InputState& rhs) | |
| { | |
| moveKey = rhs.moveKey; | |
| return *this; | |
| } | |
| bool operator == (const InputState& rhs) const | |
| { | |
| return (moveKey == rhs.moveKey); | |
| } | |
| bool operator != (const InputState& rhs) const | |
| { | |
| return (moveKey != rhs.moveKey); | |
| } | |
| void Flag(Mx::U8 bits) | |
| { | |
| moveKey |= bits; | |
| } | |
| void Unflag(Mx::U8 bits) | |
| { | |
| moveKey &= ~bits; | |
| } | |
| bool IsFlagged(Mx::U8 bits) | |
| { | |
| return ((moveKey & bits) == bits); | |
| } | |
| bool GetL() const { return moveKey & eMoveKey::Enum::kL; } | |
| bool GetR() const { return moveKey & eMoveKey::Enum::kR; } | |
| bool GetT() const { return moveKey & eMoveKey::Enum::kT; } | |
| bool GetB() const { return moveKey & eMoveKey::Enum::kB; } | |
| void SetL(bool yes) { yes ? Flag(eMoveKey::Enum::kL) : Unflag(eMoveKey::Enum::kL); } | |
| void SetR(bool yes) { yes ? Flag(eMoveKey::Enum::kR) : Unflag(eMoveKey::Enum::kR); } | |
| void SetT(bool yes) { yes ? Flag(eMoveKey::Enum::kT) : Unflag(eMoveKey::Enum::kT); } | |
| void SetB(bool yes) { yes ? Flag(eMoveKey::Enum::kB) : Unflag(eMoveKey::Enum::kB); } | |
| void Set(bool L, bool R, bool T, bool B) | |
| { | |
| moveKey = 0; | |
| if (L) moveKey |= eMoveKey::Enum::kL; | |
| if (R) moveKey |= eMoveKey::Enum::kR; | |
| if (T) moveKey |= eMoveKey::Enum::kT; | |
| if (B) moveKey |= eMoveKey::Enum::kB; | |
| } | |
| }; | |
| _DP_END | |
| #endif // DPINPUTSTATE_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment