build_data_persistence.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. #include <Windows.h>
  3. #include <array>
  4. #include <vector>
  5. #include "../../../../core/filesystem/path.h"
  6. #include "../../../content/content_catalog.h"
  7. #include "../../abilities/definition.h"
  8. #include "../../cache/records/domains.h"
  9. #include "../../collectibles/collectible_catalog.h"
  10. #include "../../constants/definition.h"
  11. #include "../../definition.h"
  12. #include "../../hash_names/definition.h"
  13. #include "../../inventory/buckets/definition.h"
  14. #include "../../items/details/definition.h"
  15. #include "../../items/item_catalog.h"
  16. #include "../../items/socket_plugs/definition.h"
  17. #include "../../material_requirements/material_requirement_catalog.h"
  18. #include "../../progressions/definition.h"
  19. #include "../../scenarios/definition.h"
  20. #include "../../socket_entry_lists/definition.h"
  21. #include "../../spawn_sets/definition.h"
  22. #include "../../vendors/definition.h"
  23. namespace sunrise::state::build_data::runtime::persistence {
  24. /** Fixed cache paths, identity, and canonical snapshot storage guarded by one State lock. */
  25. struct Context {
  26. SRWLOCK lock{SRWLOCK_INIT};
  27. std::vector<content::Definition> namedScratch{};
  28. std::vector<items::Definition> itemScratch{};
  29. std::vector<collectibles::Definition> collectibleScratch{};
  30. std::vector<material_requirements::Definition> materialRequirementSetScratch{};
  31. std::vector<items::details::Definition> itemDetailScratch{};
  32. std::vector<items::socket_plugs::Rule> socketPlugRuleScratch{};
  33. std::vector<items::socket_plugs::Pool> socketPlugPoolScratch{};
  34. std::vector<items::socket_plugs::Member> socketPlugMemberScratch{};
  35. std::vector<inventory::buckets::Descriptor> inventoryBucketScratch{};
  36. std::vector<socket_entry_lists::Definition> socketEntryListScratch{};
  37. std::vector<socket_entry_lists::EntryTable> socketEntryTableScratch{};
  38. std::vector<abilities::Definition> abilityBucketScratch{};
  39. std::vector<progressions::Definition> progressionScratch{};
  40. std::vector<scenarios::Definition> scenarioScratch{};
  41. std::vector<scenarios::RosterGroup> rosterGroupScratch{};
  42. std::vector<spawn_sets::Stem> spawnStemScratch{};
  43. std::vector<spawn_sets::NameHash> spawnNameHashScratch{};
  44. std::vector<spawn_sets::Point> spawnPointScratch{};
  45. std::vector<hash_names::Name> hashNameScratch{};
  46. std::vector<vendors::IndexEntry> vendorIndexScratch{};
  47. std::vector<vendors::Definition> vendorDefinitionScratch{};
  48. std::vector<vendors::SaleRow> vendorSaleRowScratch{};
  49. std::vector<vendors::InstalledRow> vendorInstalledRowScratch{};
  50. std::vector<gameplay::entity_position_profiles::Row> positionProfileScratch{};
  51. std::vector<gameplay::entity_object_types::Row> objectTypeScratch{};
  52. gameplay::entity_position_profiles::Fingerprint positionFingerprint{};
  53. cache::records::InvestmentConstants constantsScratch{};
  54. core::path::Buffer cacheDirectory;
  55. core::path::Buffer cachePath;
  56. BuildIdentity buildIdentity{};
  57. bool enabled{};
  58. bool persisted{};
  59. bool replaceStaleCache{};
  60. };
  61. /** @return The process-wide persistence context, shared by lifecycle and writer code. */
  62. [[nodiscard]] Context& context() noexcept;
  63. /** @return True when every generated domain is complete in State. */
  64. [[nodiscard]] bool all_domains_ready() noexcept;
  65. /**
  66. * Clears fixed cache paths, identity, flags, and snapshot storage.
  67. * @param state Its lock must already be held exclusively.
  68. */
  69. void clear_locked(Context& state) noexcept;
  70. /** Releases transient cache snapshot banks while preserving paths, identity, and flags. */
  71. void release_scratch_locked(Context& state) noexcept;
  72. /**
  73. * Gives mutable views over every generated domain.
  74. * @param state Its lock must already be held exclusively.
  75. * @return Mutable spans covering each full-size domain buffer.
  76. */
  77. [[nodiscard]] cache::records::MutableDomains scratch_domains(Context& state) noexcept;
  78. /**
  79. * Gives read-only views over the used rows of one canonical snapshot.
  80. * @param state Its lock must already be held exclusively.
  81. * @param counts Used row count for each fixed domain buffer.
  82. * @return Read-only spans limited to the used rows.
  83. */
  84. [[nodiscard]] cache::records::Domains
  85. occupied_domains(Context& state, const cache::records::DomainCounts& counts) noexcept;
  86. /**
  87. * Saves one complete canonical snapshot when every domain is ready.
  88. * @param state Its lock must already be held exclusively.
  89. * @return True when no write is due, or the complete State is on disk.
  90. */
  91. [[nodiscard]] bool persist_if_complete_locked(Context& state) noexcept;
  92. } // namespace sunrise::state::build_data::runtime::persistence