10#include <unordered_set>
39 if (readers_.empty()) {
44 do { ++next_reader_; }
while (!next_reader_ || readers_.contains(next_reader_));
45 readers_.insert(next_reader_);
49 readers_.erase(reader);
50 if (readers_.empty()) std::vector<EntityChangeRow>().swap(rows_);
52 double sequence()
const {
return static_cast<double>(sequence_); }
53 double resetEpoch()
const {
return reset_epoch_ == MAX_SEQUENCE ? -1 :
static_cast<double>(reset_epoch_); }
56 : component < revisions_.size() ? revisions_[component][topology ? 1 : 0] : 0;
57 return value == MAX_SEQUENCE ? -1 :
static_cast<double>(value);
63 if (revision_ < MAX_SEQUENCE) ++revision_;
66 revisions[0] = revision_;
69 if (readers_.empty())
return;
71 if (sequence_ == MAX_SEQUENCE) { exhausted_ =
true;
return; }
76 i32 read(
double after, std::span<EntityChangeRow> output)
const {
77 if (rows_.empty() || exhausted_ || !std::isfinite(after) || after < 0
78 || after >
sequence() || std::floor(after) != after)
return -1;
79 const auto cursor =
static_cast<u64>(after);
80 const auto count = sequence_ - cursor;
83 return static_cast<i32>(count);
87 static constexpr u64 MAX_SEQUENCE = (
u64{1} << 53) - 1;
88 std::vector<EntityChangeRow> rows_;
89 std::unordered_set<u32> readers_;
93 std::vector<std::array<u64, 2>> revisions_;
94 std::array<u64, 2> entity_revisions_{};
96 bool exhausted_ =
false;
Reflection and metadata system for automatic binding generation.
#define ES_CONST(...)
Mark a constant that CROSSES the boundary, so EHT emits its TS twin.
Core type definitions and utilities for ESEngine.
double resetEpoch() const
usize retainedRows() const
i32 read(double after, std::span< EntityChangeRow > output) const
usize readerCount() const
double componentRevision(u32 component, bool topology) const
void record(u32 entity, u32 flags=0, u32 component=ENTITY_CHANGE_NO_COMPONENT)
static constexpr u32 ENTITY_CHANGE_SUBTREE
static constexpr u32 ENTITY_CHANGE_REPLACED
static constexpr u32 ENTITY_CHANGE_WORDS
static constexpr u32 ENTITY_CHANGE_CAPACITY
static constexpr u32 ENTITY_CHANGE_RESET
static constexpr u32 ENTITY_CHANGE_NO_COMPONENT
std::int32_t i32
Signed 32-bit integer.
std::uint64_t u64
Unsigned 64-bit integer.
std::size_t usize
Size type for indexing and sizes.
std::uint32_t u32
Unsigned 32-bit integer.