scene/holder_index.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | /// @file holder_index.h | ||
| 3 | /// @brief The reverse index of relationships: which prims target each path. | ||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "ernie/scene/storage.h" | ||
| 7 | |||
| 8 | #include <cstdint> | ||
| 9 | #include <unordered_map> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | namespace ernie { | ||
| 13 | |||
| 14 | /// @brief Which prims' relationships target each path, kept up to date from the store's changes, | ||
| 15 | /// so an edit to a target reaches its holders: a prototype its instancers, a material the prims | ||
| 16 | /// bound to it (through their resolved bindings), a body its terrains. | ||
| 17 | 261 | class HolderIndex { | |
| 18 | public: | ||
| 19 | /// Re-indexes the relationship cells that changed since the last update. | ||
| 20 | void Update(const PrimStore& store); | ||
| 21 | /// @return The live prims with a relationship targeting `target`, each once. | ||
| 22 | std::vector<PrimId> Find(const PrimStore& store, PathId target) const; | ||
| 23 | |||
| 24 | private: | ||
| 25 | /// A relationship cell: the prim's slot and the attribute, packed. | ||
| 26 | using Cell = std::uint64_t; | ||
| 27 | 8703 | static Cell Key(PrimId prim, AttributeId attribute) { | |
| 28 | 8703 | return (std::uint64_t{prim.slot} << 32) | attribute; | |
| 29 | } | ||
| 30 | |||
| 31 | void Index(PrimId prim, AttributeId attribute, std::vector<PathId> targets); | ||
| 32 | |||
| 33 | /// Each target's holding cells, with the generation of the prim that wrote them. | ||
| 34 | std::unordered_map<PathId, std::unordered_map<Cell, std::uint32_t>> holders_; | ||
| 35 | /// Each cell's targets, to unindex them when it changes. | ||
| 36 | std::unordered_map<Cell, std::vector<PathId>> targets_; | ||
| 37 | std::uint64_t cursor_ = 0; | ||
| 38 | }; | ||
| 39 | |||
| 40 | } // namespace ernie | ||
| 41 |