diff options
author | MerryMage <MerryMage@users.noreply.github.com> | 2016-02-11 18:41:15 +0100 |
---|---|---|
committer | MerryMage <MerryMage@users.noreply.github.com> | 2016-02-12 20:51:16 +0100 |
commit | 6c71858c5c698a718045ba44eda495080417a84b (patch) | |
tree | 0dc7778532b0e2d1c5acd0224266b8a67d961155 /src/common | |
parent | Merge pull request #1264 from bunnei/fragment-lighting-hw (diff) | |
download | yuzu-6c71858c5c698a718045ba44eda495080417a84b.tar yuzu-6c71858c5c698a718045ba44eda495080417a84b.tar.gz yuzu-6c71858c5c698a718045ba44eda495080417a84b.tar.bz2 yuzu-6c71858c5c698a718045ba44eda495080417a84b.tar.lz yuzu-6c71858c5c698a718045ba44eda495080417a84b.tar.xz yuzu-6c71858c5c698a718045ba44eda495080417a84b.tar.zst yuzu-6c71858c5c698a718045ba44eda495080417a84b.zip |
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/bit_field.h | 44 | ||||
-rw-r--r-- | src/common/emu_window.cpp | 4 |
2 files changed, 22 insertions, 26 deletions
diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 66689f398..600e0c70c 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h @@ -115,29 +115,24 @@ template<std::size_t position, std::size_t bits, typename T> struct BitField { private: - // This constructor might be considered ambiguous: - // Would it initialize the storage or just the bitfield? - // Hence, delete it. Use the assignment operator to set bitfield values! - BitField(T val) = delete; + // We hide the copy assigment operator here, because the default copy + // assignment would copy the full storage value, rather than just the bits + // relevant to this particular bit field. + // We don't delete it because we want BitField to be trivially copyable. + BitField& operator=(const BitField&) = default; public: + // This constructor and assignment operator might be considered ambiguous: + // Would they initialize the storage or just the bitfield? + // Hence, delete them. Use the Assign method to set bitfield values! + BitField(T val) = delete; + BitField& operator=(T val) = delete; + // Force default constructor to be created // so that we can use this within unions BitField() = default; - // We explicitly delete the copy assigment operator here, because the - // default copy assignment would copy the full storage value, rather than - // just the bits relevant to this particular bit field. - BitField& operator=(const BitField&) = delete; - - FORCE_INLINE BitField& operator=(T val) - { - Assign(val); - return *this; - } - - FORCE_INLINE operator T() const - { + FORCE_INLINE operator T() const { return Value(); } @@ -145,8 +140,7 @@ public: storage = (storage & ~GetMask()) | (((StorageType)value << position) & GetMask()); } - FORCE_INLINE T Value() const - { + FORCE_INLINE T Value() const { if (std::numeric_limits<T>::is_signed) { std::size_t shift = 8 * sizeof(T)-bits; @@ -159,8 +153,7 @@ public: } // TODO: we may want to change this to explicit operator bool() if it's bug-free in VS2015 - FORCE_INLINE bool ToBool() const - { + FORCE_INLINE bool ToBool() const { return Value() != 0; } @@ -176,8 +169,7 @@ private: // Unsigned version of StorageType typedef typename std::make_unsigned<StorageType>::type StorageTypeU; - FORCE_INLINE StorageType GetMask() const - { + FORCE_INLINE StorageType GetMask() const { return (((StorageTypeU)~0) >> (8 * sizeof(T)-bits)) << position; } @@ -189,6 +181,10 @@ private: static_assert(position < 8 * sizeof(T), "Invalid position"); static_assert(bits <= 8 * sizeof(T), "Invalid number of bits"); static_assert(bits > 0, "Invalid number of bits"); - static_assert(std::is_standard_layout<T>::value, "Invalid base type"); + static_assert(std::is_pod<T>::value, "Invalid base type"); }; #pragma pack() + +#if (__GNUC__ >= 5) || defined __clang__ || defined _MSC_VER +static_assert(std::is_trivially_copyable<BitField<0, 1, u32>>::value, "BitField must be trivially copyable"); +#endif diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp index b69b05cb9..b2807354a 100644 --- a/src/common/emu_window.cpp +++ b/src/common/emu_window.cpp @@ -55,14 +55,14 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) { (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top); touch_pressed = true; - pad_state.touch = 1; + pad_state.touch.Assign(1); } void EmuWindow::TouchReleased() { touch_pressed = false; touch_x = 0; touch_y = 0; - pad_state.touch = 0; + pad_state.touch.Assign(0); } void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { |