scriptable_catalog_builder.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include <cstdint>
  3. #include <memory>
  4. #include <string_view>
  5. #include <vector>
  6. #include "../../../middleware/content/packages/reader/reader.h"
  7. #include "../../../state/build_data/hash_names/definition.h"
  8. #include "../../../state/build_data/scriptables/definition.h"
  9. #include "../../../state/content/content_catalog.h"
  10. #include "scriptable_catalog_container_index.h"
  11. namespace sunrise::client::content::scenarios {
  12. class LayoutSet;
  13. } // namespace sunrise::client::content::scenarios
  14. namespace sunrise::client::content::activity::scriptables::internal {
  15. using BuilderCancelCheck = bool (*)() noexcept;
  16. /** Package-wide tables one scenario build reads. A null member reads the table State publishes. */
  17. struct BuildTables final {
  18. const ::sunrise::client::content::scenarios::LayoutSet* layouts{};
  19. const std::vector<state::content::Definition>* definitions{};
  20. /** Identifier names, sorted by hash. */
  21. const std::vector<state::build_data::hash_names::Name>* hashNames{};
  22. };
  23. /**
  24. * Immutable source analyses shared by scenario builds from one installed package estate.
  25. * Use one instance for one sequential pass. Destroy it before changing the source estate.
  26. */
  27. class ScenarioAnalysisCache final {
  28. public:
  29. ScenarioAnalysisCache() noexcept;
  30. ~ScenarioAnalysisCache();
  31. ScenarioAnalysisCache(const ScenarioAnalysisCache&) = delete;
  32. ScenarioAnalysisCache& operator=(const ScenarioAnalysisCache&) = delete;
  33. ScenarioAnalysisCache(ScenarioAnalysisCache&&) = delete;
  34. ScenarioAnalysisCache& operator=(ScenarioAnalysisCache&&) = delete;
  35. private:
  36. struct Impl;
  37. std::unique_ptr<Impl> impl_{};
  38. friend std::shared_ptr<state::build_data::scriptables::Snapshot>
  39. build_scenario_catalog(const middleware::content::packages::reader::Source& source,
  40. const ContainerIndex& containers,
  41. middleware::content::packages::reader::Scratch& scratch,
  42. ScenarioAnalysisCache& analyses,
  43. const BuildTables& tables,
  44. std::uint32_t scenarioTag,
  45. std::string_view scenarioName,
  46. BuilderCancelCheck cancel);
  47. };
  48. /**
  49. * Builds one immutable package-derived scenario catalog without publishing it.
  50. * The caller owns package-key lifetime for the complete call and may attach its own request or
  51. * revision identity after the returned snapshot is complete.
  52. */
  53. [[nodiscard]] std::shared_ptr<state::build_data::scriptables::Snapshot>
  54. build_scenario_catalog(const middleware::content::packages::reader::Source& source,
  55. const ContainerIndex& containers,
  56. middleware::content::packages::reader::Scratch& scratch,
  57. std::uint32_t scenarioTag,
  58. std::string_view scenarioName,
  59. BuilderCancelCheck cancel);
  60. /**
  61. * Builds one scenario while reusing source-only object analysis from earlier pass rows.
  62. * @param tables Layouts and names the build reads in place of the tables State publishes.
  63. */
  64. [[nodiscard]] std::shared_ptr<state::build_data::scriptables::Snapshot>
  65. build_scenario_catalog(const middleware::content::packages::reader::Source& source,
  66. const ContainerIndex& containers,
  67. middleware::content::packages::reader::Scratch& scratch,
  68. ScenarioAnalysisCache& analyses,
  69. const BuildTables& tables,
  70. std::uint32_t scenarioTag,
  71. std::string_view scenarioName,
  72. BuilderCancelCheck cancel);
  73. } // namespace sunrise::client::content::activity::scriptables::internal