scene/extent_cache.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | /// @file extent_cache.h | ||
| 3 | /// @brief Prims' extents kept per bucket and refreshed for the rows that changed. | ||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "ernie/geometry/bounds.h" | ||
| 7 | #include "ernie/scene/schema.h" | ||
| 8 | #include "ernie/scene/storage.h" | ||
| 9 | #include "ernie/util/bytes.h" | ||
| 10 | |||
| 11 | #include <cstdint> | ||
| 12 | #include <optional> | ||
| 13 | #include <vector> | ||
| 14 | |||
| 15 | namespace ernie { | ||
| 16 | |||
| 17 | /// @brief The extents of every bucket with an extent function, a box per row. `Update` replays | ||
| 18 | /// the buckets' row changes and recomputes only the rows whose values or places changed. | ||
| 19 | 233 | class ExtentCache { | |
| 20 | public: | ||
| 21 | /// Tracks a bucket, computing its extents with `compute`; null for a bucket without them. | ||
| 22 | void Track(BucketId bucket, ExtentFunction compute); | ||
| 23 | /// Brings every tracked bucket up to the store's version. | ||
| 24 | void Update(const PrimStore& store); | ||
| 25 | /// @return A row's extent, or none when its bucket changed since `Update` or has none. | ||
| 26 | std::optional<Box> Find(const PrimStore& store, BucketId bucket, std::uint32_t row) const; | ||
| 27 | |||
| 28 | private: | ||
| 29 | 2093 | struct Entry { | |
| 30 | ExtentFunction compute = nullptr; | ||
| 31 | std::vector<Box> boxes; | ||
| 32 | BitSet stale; | ||
| 33 | }; | ||
| 34 | |||
| 35 | bool Tracked(BucketId bucket) const; | ||
| 36 | static void Replay(Entry& entry, const StructuralChange& change); | ||
| 37 | static void Resize(Entry& entry, std::uint32_t rows); | ||
| 38 | static void Refresh(Entry& entry, const PrimStore& store, BucketId bucket); | ||
| 39 | |||
| 40 | std::vector<Entry> buckets_; | ||
| 41 | std::uint64_t cursor_ = 0; | ||
| 42 | }; | ||
| 43 | |||
| 44 | } // namespace ernie | ||
| 45 |