activity_sdk_topology_inventory.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include <string>
  6. #include <unordered_map>
  7. #include <unordered_set>
  8. #include <vector>
  9. #include "../../../state/activity_sdk/format.h"
  10. #include "../../../state/build_data/scriptables/definition.h"
  11. #include "activity_sdk_activity_inventory.h"
  12. namespace sunrise::client::content::activity::sdk_generation::topology_inventory {
  13. /** A partial source walk leaves every object count pending. */
  14. inline constexpr std::uint32_t kObjectConfigCountPending = 0x01U;
  15. inline constexpr std::uint32_t kObjectPlacedSubblockCountPending = 0x02U;
  16. inline constexpr std::uint32_t kObjectPlacedLeafCountPending = 0x04U;
  17. inline constexpr std::uint32_t kObjectPlacedHopCountPending = 0x08U;
  18. inline constexpr std::uint32_t kObjectBareTargetCountPending = 0x10U;
  19. inline constexpr std::uint32_t kObjectCountPendingMask =
  20. kObjectConfigCountPending | kObjectPlacedSubblockCountPending | kObjectPlacedLeafCountPending
  21. | kObjectPlacedHopCountPending | kObjectBareTargetCountPending;
  22. /** Generated topology text stays owned until the final string table is linked. */
  23. struct Text final {
  24. std::array<char, middleware::content::packages::tables::kActivityDefinitionInternalNameCapacity>
  25. value{};
  26. std::uint16_t length{};
  27. };
  28. /** One all-activity row before string offsets and policy ranges are linked. */
  29. struct Activity final {
  30. std::uint32_t activityIndex{};
  31. std::uint32_t definitionHash{};
  32. std::uint32_t scenarioIndex{state::build_data::scriptables::kNoRow};
  33. /** Only exactness bits proved by this topology slice are set. */
  34. std::uint32_t exactFlags{};
  35. Text id{};
  36. Text internalName{};
  37. /** Reserved for later enrichment; this topology slice leaves it empty. */
  38. Text displayName{};
  39. };
  40. /** One scenario and its contiguous global topology ranges. */
  41. struct Scenario final {
  42. std::uint32_t tag{};
  43. Text id{};
  44. Text name{};
  45. std::uint32_t firstBubble{};
  46. std::uint32_t bubbleCount{};
  47. std::uint32_t firstState{};
  48. std::uint32_t stateCount{};
  49. std::uint32_t firstOccurrence{};
  50. std::uint32_t occurrenceCount{};
  51. };
  52. /** One scenario bubble and its contiguous global state range. */
  53. struct Bubble final {
  54. std::uint32_t scenarioIndex{};
  55. std::uint32_t bubbleOrdinal{};
  56. std::uint32_t nameHash{};
  57. Text id{};
  58. /** Raw candidates stay unresolved until the estate read universe is proved. */
  59. std::uint32_t observedNameRow{state::build_data::scriptables::kNoRow};
  60. std::uint32_t firstObservedAlias{};
  61. std::uint32_t observedAliasCount{};
  62. std::uint32_t firstState{};
  63. std::uint32_t stateCount{};
  64. };
  65. /** One exact state row retained before global string offsets are linked. */
  66. struct State final {
  67. std::uint32_t scenarioIndex{};
  68. std::uint32_t bubbleIndex{};
  69. std::uint32_t stateOrdinal{};
  70. std::uint32_t entryIndex{};
  71. std::uint32_t sliceSetIndex{};
  72. std::uint32_t mapBubbleIndex{};
  73. std::uint32_t stateHash{};
  74. std::uint32_t rawU32At12{};
  75. std::uint32_t entryTag{};
  76. std::uint32_t registryTag{};
  77. bool enabled{};
  78. Text id{};
  79. Text entryId{};
  80. Text registryId{};
  81. };
  82. /** One normalized descriptor shape retained to compare repeated object definitions. */
  83. struct DescriptorEvidence final {
  84. std::uint32_t componentClass{};
  85. std::uint32_t senseSchema{};
  86. std::uint32_t authSchema{};
  87. bool operator==(const DescriptorEvidence&) const = default;
  88. };
  89. /** One canonical definition slot before reflection and mission-policy joins. */
  90. struct Slot final {
  91. std::uint32_t objectIndex{state::build_data::scriptables::kNoRow};
  92. std::uint32_t nameHash{};
  93. std::uint32_t slotIndex{};
  94. std::uint32_t slotType{};
  95. std::uint32_t componentClass{state::activity_sdk::format::kAbsentIndex};
  96. std::uint32_t senseSchema{state::activity_sdk::format::kAbsentIndex};
  97. std::uint32_t authSchema{state::activity_sdk::format::kAbsentIndex};
  98. std::uint32_t flags{};
  99. /** Package descriptor candidates remain separate from the pending reflection join. */
  100. std::uint32_t descriptorComponentClass{state::activity_sdk::format::kAbsentIndex};
  101. std::uint32_t descriptorSenseSchema{state::activity_sdk::format::kAbsentIndex};
  102. std::uint32_t descriptorAuthSchema{state::activity_sdk::format::kAbsentIndex};
  103. std::uint32_t descriptorCount{state::activity_sdk::format::kAbsentIndex};
  104. Text id{};
  105. std::uint32_t idString{state::build_data::scriptables::kNoRow};
  106. std::uint32_t observedNameRow{state::build_data::scriptables::kNoRow};
  107. std::uint32_t firstObservedAlias{};
  108. std::uint32_t observedAliasCount{};
  109. std::vector<DescriptorEvidence> descriptorEvidence{};
  110. };
  111. /** One object definition deduplicated by tag from scenario-local placement rows. */
  112. struct Object final {
  113. std::uint32_t objectTag{};
  114. std::uint32_t objectKey{};
  115. std::uint32_t firstSlot{};
  116. std::uint32_t slotCount{};
  117. std::uint32_t configCount{};
  118. std::uint32_t placedSubblockCount{};
  119. std::uint32_t placedLeafCount{};
  120. std::uint32_t placedHopCount{};
  121. std::uint32_t bareTargetCount{};
  122. std::uint32_t replicatedPlacementCount{};
  123. std::uint32_t descriptorCount{state::activity_sdk::format::kAbsentIndex};
  124. bool descriptorEvidenceComplete{};
  125. bool countEvidenceComplete{};
  126. Text id{};
  127. std::uint32_t idString{state::build_data::scriptables::kNoRow};
  128. std::uint32_t pendingCountMask{kObjectCountPendingMask};
  129. std::vector<Slot> definitionSlots{};
  130. };
  131. /** One exact scenario occurrence before its object definition index is linked. */
  132. struct Occurrence final {
  133. std::uint32_t scenarioIndex{};
  134. std::uint32_t bubbleIndex{};
  135. std::uint32_t stateIndex{};
  136. std::uint32_t objectIndex{state::build_data::scriptables::kNoRow};
  137. std::uint32_t objectTag{};
  138. std::uint32_t registryTag{};
  139. std::uint32_t entryTag{};
  140. std::uint32_t registryField{};
  141. std::uint32_t objectOrdinal{};
  142. Text id{};
  143. Text contextRegistryKey{};
  144. Text registryId{};
  145. Text entryId{};
  146. std::uint32_t idString{state::build_data::scriptables::kNoRow};
  147. std::uint32_t contextRegistryKeyString{state::build_data::scriptables::kNoRow};
  148. std::uint32_t registryIdString{state::build_data::scriptables::kNoRow};
  149. std::uint32_t entryIdString{state::build_data::scriptables::kNoRow};
  150. };
  151. /** One exact value in the estate-wide package-inline byte bank. */
  152. struct InlineName final {
  153. std::uint32_t hash{};
  154. std::uint32_t firstByte{};
  155. std::uint32_t byteCount{};
  156. };
  157. /** Mutable indexes used only while scenario topology is being accumulated. */
  158. struct Accumulator final {
  159. std::unordered_map<std::uint32_t, std::size_t> objectRows{};
  160. std::unordered_set<std::string> inlineNames{};
  161. std::size_t inlineNameBytes{};
  162. };
  163. /** All activity rows and exact scenario topology for one installed content identity. */
  164. struct Snapshot final {
  165. std::vector<Activity> activities{};
  166. std::vector<Scenario> scenarios{};
  167. std::vector<Bubble> bubbles{};
  168. std::vector<State> states{};
  169. std::vector<Object> objects{};
  170. std::vector<Occurrence> occurrences{};
  171. std::vector<Slot> slots{};
  172. std::vector<InlineName> inlineNames{};
  173. std::vector<std::byte> inlineNameBytes{};
  174. std::vector<std::uint32_t> observedAliases{};
  175. /** Sorted proved strings only; later sections must rebuild final byte offsets. */
  176. std::vector<std::string> strings{};
  177. Accumulator accumulator{};
  178. std::size_t nextScenario{};
  179. /** Name and final-string closure stay false until the full read universe is proved. */
  180. bool nameInventoryComplete{};
  181. bool stringInventoryComplete{};
  182. bool ready{};
  183. };
  184. /** Starts one deterministic topology build from the complete activity inventory. */
  185. [[nodiscard]] bool begin(const activity_inventory::Snapshot& source, Snapshot& output) noexcept;
  186. /** Appends the next scenario shard and rejects gaps, repeats, and lossy state rows. */
  187. [[nodiscard]] bool append(const state::build_data::scriptables::Snapshot& source,
  188. Snapshot& output) noexcept;
  189. /** Closes all scenario ranges without claiming the later exact content join. */
  190. [[nodiscard]] bool finish(Snapshot& output) noexcept;
  191. } // namespace sunrise::client::content::activity::sdk_generation::topology_inventory