node_catalog.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <cstddef>
  3. #include <span>
  4. #include "definition.h"
  5. namespace sunrise::state::build_data::nodes {
  6. /** Clears every generated node definition. */
  7. void clear() noexcept;
  8. /**
  9. * Checks that the definitions are dense and in native index order.
  10. * @param definitions Candidate rows.
  11. * @return True when the rows fit storage, index n sits at position n, and no child count overflows.
  12. */
  13. [[nodiscard]] bool valid(std::span<const Definition> definitions) noexcept;
  14. /**
  15. * Replaces the generated node definitions in one step.
  16. * @param definitions Complete dense rows in native node order.
  17. * @return True when the rows pass the checks and fit fixed State storage.
  18. */
  19. [[nodiscard]] bool replace(std::span<const Definition> definitions) noexcept;
  20. /**
  21. * Runs one callable over every node that drives a value slot.
  22. * Held under the shared lock, so the callable must not re-enter this domain.
  23. * @param visit Receives each node owning at least one record and an addressable value slot.
  24. */
  25. void for_each_driving(void* context,
  26. void (*visit)(void* context, const Definition& definition)) noexcept;
  27. /**
  28. * Copies every row in native node order.
  29. * @param output Caller-owned fixed row storage.
  30. * @param count Receives the copied row count, or zero when output is too small.
  31. * @return True when output can hold every row.
  32. */
  33. [[nodiscard]] bool snapshot(std::span<Definition> output, std::size_t& count) noexcept;
  34. /** @return Number of generated node definitions, read under the lock. */
  35. [[nodiscard]] std::size_t count() noexcept;
  36. /**
  37. * Sets the visibility gate of every lore book category over one account flag bank.
  38. * @param accountFlags Bank already filled from the authored policy.
  39. * @return Number of gates set.
  40. */
  41. std::size_t apply_visibility(std::span<std::uint8_t> accountFlags) noexcept;
  42. /**
  43. * Calls back for every node, under the shared lock.
  44. *
  45. * Copying the table out costs a hundred and fifty kilobytes a call, and both callers wanted only a
  46. * few fields of a few rows. The callback must not take the catalog lock again.
  47. * @param context Passed through untouched.
  48. * @param visit Called once per node in native order.
  49. */
  50. void for_each(void* context, void (*visit)(void*, const Definition&) noexcept) noexcept;
  51. /**
  52. * Sets the character scoped visibility gates of the lore book categories.
  53. * @param characterFlags Character bank already filled from the authored policy.
  54. * @return Number of gates set.
  55. */
  56. std::size_t apply_character_visibility(std::span<std::byte> characterFlags) noexcept;
  57. } // namespace sunrise::state::build_data::nodes