diff options
| author | Léo Lam <leo@leolam.fr> | 2021-12-30 00:39:17 +0100 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2022-01-03 23:53:40 +0100 |
| commit | eb16cbaf55931853533d4e0ed2c71e643bc54c33 (patch) | |
| tree | 9efe14bece5cd25dd801c79328f41b93002c1966 /src/KingSystem/Utils | |
| parent | 75a270118adfc1e4838cd776a8b2adb11dad06f0 (diff) | |
ksys/phys: Add MaterialMask
Diffstat (limited to 'src/KingSystem/Utils')
| -rw-r--r-- | src/KingSystem/Utils/BitField.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/KingSystem/Utils/BitField.h b/src/KingSystem/Utils/BitField.h index 6b00b7df..4e28e675 100644 --- a/src/KingSystem/Utils/BitField.h +++ b/src/KingSystem/Utils/BitField.h @@ -116,6 +116,10 @@ struct BitField { // so that we can use this within unions constexpr BitField() = default; + // We declare a user-defined copy assignment operator, so the default copy constructor + // must be defaulted explicitly to avoid a deprecation warning. + constexpr BitField(const BitField&) = default; + // 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! @@ -132,6 +136,11 @@ struct BitField { storage = (storage & ~GetMask()) | (static_cast<StorageType>(val) << position); } + /// @warning Same as SetUnsafe, but assumes this bitfield's bits are zero. + /// This is intended to be called only once to efficiently initialise a bitfield, + /// and will break very badly if called more than once. Using Set() is preferred. + inline constexpr void Init(T val) { storage |= static_cast<StorageType>(val) << position; } + inline constexpr BitField& operator=(const BitField& other) { Set(other.Value()); return *this; |
