definition.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. namespace sunrise::state::build_data::vendors {
  6. /** Rows of the installed vendor index. The live table has 511. */
  7. inline constexpr std::size_t kIndexCapacity = 512;
  8. /** Vendor definitions this catalog holds rows for. A definition is read only when asked for. */
  9. inline constexpr std::size_t kDefinitionCapacity = 48;
  10. /** Sale rows across every held definition. One installed definition declares 277. */
  11. inline constexpr std::size_t kSaleRowCapacity = 8192;
  12. /** Installed rows across every held definition. One installed definition declares 43. */
  13. inline constexpr std::size_t kInstalledRowCapacity = 2048;
  14. /** One vendor index row is 24 bytes: hash at +0, definition tag at +16. */
  15. inline constexpr std::size_t kIndexRowStride = 24;
  16. /** One sale row is 184 bytes. */
  17. inline constexpr std::size_t kSaleRowStride = 184;
  18. /** One installed row is 24 bytes. */
  19. inline constexpr std::size_t kInstalledRowStride = 24;
  20. /** One row of the unnamed third array is 80 bytes. */
  21. inline constexpr std::size_t kThirdRowStride = 80;
  22. /** Wrapper class of the vendor index blob. */
  23. inline constexpr std::uint32_t kIndexWrapperClass = 0x8080784AU;
  24. /** Element class of the vendor index array. */
  25. inline constexpr std::uint32_t kIndexRowClass = 0x8080784EU;
  26. /** Class of a vendor definition blob. */
  27. inline constexpr std::uint32_t kDefinitionClass = 0x80807850U;
  28. /** Element class of a definition's installed array. */
  29. inline constexpr std::uint32_t kInstalledRowClass = 0x80807860U;
  30. /** Element class of a definition's sale array. */
  31. inline constexpr std::uint32_t kSaleRowClass = 0x80807861U;
  32. /** Sale row +176 carries this when the row names no secondary item. */
  33. inline constexpr std::uint16_t kAbsentSecondaryItem = 0xFFFFU;
  34. /** Sale row +100 carries this when the row belongs to no category. The client tests for it. */
  35. inline constexpr std::int32_t kAbsentCategoryIndex = -1;
  36. /** One row of the installed vendor index, which maps a vendor hash to its definition tag. */
  37. struct IndexEntry {
  38. std::uint32_t definitionHash{};
  39. std::uint32_t definitionTag{};
  40. /** Row position, which is the index the opcode-901 request carries. */
  41. std::uint16_t index{};
  42. };
  43. /** One extracted vendor definition and the flat-bank ranges its rows occupy. */
  44. struct Definition {
  45. std::uint32_t definitionHash{};
  46. std::uint32_t definitionTag{};
  47. /** Class the package entry records, which must be `kDefinitionClass`. */
  48. std::uint32_t definitionClass{};
  49. /** Definition blob size. Every array must end inside it. */
  50. std::uint32_t definitionSize{};
  51. /** First installed row, as an offset into the definition blob. */
  52. std::uint32_t installedRowBase{};
  53. std::uint32_t installedRowClass{};
  54. /** First sale row, as an offset into the definition blob. */
  55. std::uint32_t saleRowBase{};
  56. std::uint32_t saleRowClass{};
  57. /** First row of the unnamed third array, as an offset into the definition blob. */
  58. std::uint32_t thirdRowBase{};
  59. std::uint32_t thirdRowClass{};
  60. /** First row of this definition's range in the flat sale bank. */
  61. std::uint32_t saleRowOffset{};
  62. /** First row of this definition's range in the flat installed bank. */
  63. std::uint32_t installedRowOffset{};
  64. /** Raw definition +20. Its unit, epoch and scope are open, so it is not converted. */
  65. std::uint32_t resetIntervalRaw{};
  66. /** Raw definition +24, paired with the interval and equally open. */
  67. std::uint32_t resetPhaseRaw{};
  68. /** Row of the vendor index this definition is named by. */
  69. std::uint16_t index{};
  70. std::uint16_t installedCount{};
  71. std::uint16_t saleCount{};
  72. std::uint16_t thirdCount{};
  73. };
  74. /**
  75. * One sale row of one vendor definition.
  76. * Do not name a raw field a cost, award, stock or quantity without its mutation reader.
  77. */
  78. struct SaleRow {
  79. /** Vendor index row of the definition owning this sale row. */
  80. std::uint16_t vendorIndex{};
  81. /** Sale row ordinal inside that definition. */
  82. std::uint16_t rowIndex{};
  83. /** Row +70. Main sale item-definition index. */
  84. std::uint16_t itemIndex{};
  85. /** Row +176. `kAbsentSecondaryItem` when the row names none. */
  86. std::uint16_t secondaryItemIndex{};
  87. /**
  88. * Row +100. The row's vendor category, established by correlating 3,304 rows against the
  89. * manifest. The catalog bounds it by the installed count, as it always has.
  90. */
  91. std::int32_t categoryIndex{};
  92. /** Row +104, raw f32 bits. Role open. */
  93. std::uint32_t raw104{};
  94. /** Row +108. Role open. */
  95. std::uint32_t raw108{};
  96. /** Row +172. Role open, and it is not the field the runtime selector reads. */
  97. std::int32_t raw172{};
  98. /** Row +8 expression count. */
  99. std::uint32_t expressionCount8{};
  100. /** Row +32 nested-record count. */
  101. std::uint32_t nestedRecordCount{};
  102. /** Row +120 expression count. */
  103. std::uint32_t expressionCount120{};
  104. /** Row +136 array count. Role open. */
  105. std::uint32_t count136{};
  106. /** Row +160 inline expression count. */
  107. std::uint32_t expressionCount160{};
  108. /** Row +154 feature branch byte. */
  109. std::uint8_t featureBranch{};
  110. };
  111. /** One installed row, kept whole because no field of it has a closed consumer. */
  112. struct InstalledRow {
  113. /** Vendor index row of the definition owning this installed row. */
  114. std::uint16_t vendorIndex{};
  115. /** Installed row ordinal inside that definition. */
  116. std::uint16_t rowIndex{};
  117. std::array<std::uint8_t, kInstalledRowStride> raw{};
  118. };
  119. } // namespace sunrise::state::build_data::vendors