ksys/phys: Add MaterialMask

This commit is contained in:
Léo Lam
2021-12-30 00:39:17 +01:00
parent 75a270118a
commit eb16cbaf55
9 changed files with 223 additions and 45 deletions
+9
View File
@@ -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;