#pragma once #include #include #include #include "../../../../core/filesystem/path.h" #include "../../../content/content_catalog.h" #include "../../abilities/definition.h" #include "../../cache/records/domains.h" #include "../../collectibles/collectible_catalog.h" #include "../../constants/definition.h" #include "../../definition.h" #include "../../hash_names/definition.h" #include "../../inventory/buckets/definition.h" #include "../../items/details/definition.h" #include "../../items/item_catalog.h" #include "../../items/socket_plugs/definition.h" #include "../../material_requirements/material_requirement_catalog.h" #include "../../progressions/definition.h" #include "../../scenarios/definition.h" #include "../../socket_entry_lists/definition.h" #include "../../spawn_sets/definition.h" #include "../../vendors/definition.h" namespace sunrise::state::build_data::runtime::persistence { /** Fixed cache paths, identity, and canonical snapshot storage guarded by one State lock. */ struct Context { SRWLOCK lock{SRWLOCK_INIT}; std::vector namedScratch{}; std::vector itemScratch{}; std::vector collectibleScratch{}; std::vector materialRequirementSetScratch{}; std::vector itemDetailScratch{}; std::vector socketPlugRuleScratch{}; std::vector socketPlugPoolScratch{}; std::vector socketPlugMemberScratch{}; std::vector inventoryBucketScratch{}; std::vector socketEntryListScratch{}; std::vector socketEntryTableScratch{}; std::vector abilityBucketScratch{}; std::vector progressionScratch{}; std::vector scenarioScratch{}; std::vector rosterGroupScratch{}; std::vector spawnStemScratch{}; std::vector spawnNameHashScratch{}; std::vector spawnPointScratch{}; std::vector hashNameScratch{}; std::vector vendorIndexScratch{}; std::vector vendorDefinitionScratch{}; std::vector vendorSaleRowScratch{}; std::vector vendorInstalledRowScratch{}; std::vector positionProfileScratch{}; std::vector objectTypeScratch{}; gameplay::entity_position_profiles::Fingerprint positionFingerprint{}; cache::records::InvestmentConstants constantsScratch{}; core::path::Buffer cacheDirectory; core::path::Buffer cachePath; BuildIdentity buildIdentity{}; bool enabled{}; bool persisted{}; bool replaceStaleCache{}; }; /** @return The process-wide persistence context, shared by lifecycle and writer code. */ [[nodiscard]] Context& context() noexcept; /** @return True when every generated domain is complete in State. */ [[nodiscard]] bool all_domains_ready() noexcept; /** * Clears fixed cache paths, identity, flags, and snapshot storage. * @param state Its lock must already be held exclusively. */ void clear_locked(Context& state) noexcept; /** Releases transient cache snapshot banks while preserving paths, identity, and flags. */ void release_scratch_locked(Context& state) noexcept; /** * Gives mutable views over every generated domain. * @param state Its lock must already be held exclusively. * @return Mutable spans covering each full-size domain buffer. */ [[nodiscard]] cache::records::MutableDomains scratch_domains(Context& state) noexcept; /** * Gives read-only views over the used rows of one canonical snapshot. * @param state Its lock must already be held exclusively. * @param counts Used row count for each fixed domain buffer. * @return Read-only spans limited to the used rows. */ [[nodiscard]] cache::records::Domains occupied_domains(Context& state, const cache::records::DomainCounts& counts) noexcept; /** * Saves one complete canonical snapshot when every domain is ready. * @param state Its lock must already be held exclusively. * @return True when no write is due, or the complete State is on disk. */ [[nodiscard]] bool persist_if_complete_locked(Context& state) noexcept; } // namespace sunrise::state::build_data::runtime::persistence