8#ifndef SEN_CORE_OBJ_DETAIL_PROPERTY_FLAGS_H
9#define SEN_CORE_OBJ_DETAIL_PROPERTY_FLAGS_H
23constexpr uint8_t currMask = 0b10000000U;
24constexpr uint8_t nextMask = 0b01000000U;
25constexpr uint8_t dirtMask = 0b00100000U;
26constexpr uint8_t syncMask = 0b00010000U;
29using PropBuffer = std::array<T, 2U>;
31class PropertyFlags final
34 SEN_COPY_MOVE(PropertyFlags)
37 PropertyFlags() =
default;
38 ~PropertyFlags() =
default;
41 [[nodiscard]] SEN_ALWAYS_INLINE uint8_t currentIndex() const noexcept {
return (state_ & currMask) != 0U ? 1U : 0U; }
42 [[nodiscard]] SEN_ALWAYS_INLINE uint8_t nextIndex() const noexcept {
return (state_ & nextMask) != 0U ? 1U : 0U; }
43 [[nodiscard]] SEN_ALWAYS_INLINE
bool changedInLastCycle() const noexcept {
return (state_ & dirtMask) != 0U; }
44 [[nodiscard]] uint8_t advanceNext() noexcept;
45 void advanceCurrent() noexcept;
47 void setValue(std::array<T, 2>& buffer, const T& value) noexcept(std::is_nothrow_copy_constructible_v<T> &&
48 std::is_nothrow_copy_assignable_v<T> &&
49 noexcept(std::declval<T>() != std::declval<T>()));
50 [[nodiscard]]
bool getTypesInSync() const noexcept {
return (state_ & syncMask) != 0U; }
51 void setTypesInSync(
bool value)
noexcept
53 value ? state_ |= syncMask : state_ &= ~syncMask;
60static_assert(
sizeof(PropertyFlags) == 1);
67void PropertyFlags::setValue(std::array<T, 2>& buffer,
68 const T& value)
noexcept(std::is_nothrow_copy_constructible_v<T> &&
69 std::is_nothrow_copy_assignable_v<T> &&
70 noexcept(std::declval<T>() != std::declval<T>()))
72 const uint8_t cur = currentIndex();
73 const uint8_t nex = nextIndex();
74 assert(cur < 2 && nex < 2);
82 if (buffer[cur] != value)
84 buffer[advanceNext()] = value;
89inline void PropertyFlags::advanceCurrent() noexcept
91 if ((state_ & nextMask) != 0U)
93 if ((state_ & currMask) != 0U)
100 state_ = (state_ & syncMask) | currMask | nextMask | dirtMask;
105 if ((state_ & currMask) != 0U)
108 state_ = (state_ & syncMask) | dirtMask;
118inline uint8_t PropertyFlags::advanceNext() noexcept
120 if ((state_ & nextMask) != 0U)
122 if ((state_ & currMask) != 0U)
133 if ((state_ & currMask) != 0U)