investment_refresh.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <Windows.h>
  2. #include <mutex>
  3. #include "../../../core/ui/busy/busy.h"
  4. #include "../../../middleware/content/packages/reader/reader.h"
  5. #include "../../../state/build_data/runtime.h"
  6. #include "../../../state/runtime/runtime.h"
  7. #include "../items/packages/build.h"
  8. #include "core/threading/srw_lock.h"
  9. #include "internal.h"
  10. #include "runtime.h"
  11. namespace sunrise::client::content::investment {
  12. namespace {
  13. core::threading::SrwLock g_refreshLock{};
  14. [[nodiscard]] bool ready() noexcept {
  15. return state::build_data::named_catalog_ready() && items::packages::ready();
  16. }
  17. /**
  18. * Runs the emote-collection canonicalization early; the snapshot path runs it again behind its
  19. * own preflight.
  20. * @return False only when the account itself could not be updated.
  21. */
  22. [[nodiscard]] bool emote_collection_settled() noexcept {
  23. return state::ensure_character_emote_collection() != state::EmoteCollectionOutcome::failed;
  24. }
  25. } // namespace
  26. /** @return True when the next refresh slice needs a visible overlay for a package sweep. */
  27. bool requires_package_sweep() noexcept {
  28. return !state::build_data::item_definitions_ready() && items::packages::readable();
  29. }
  30. /** Publishes every installed equipment mapping domain. */
  31. bool refresh() noexcept {
  32. if (ready()) {
  33. const std::lock_guard lock(g_refreshLock);
  34. const bool persisted = state::ensure_profile_item_identities()
  35. && state::ensure_character_subclasses() && emote_collection_settled()
  36. && state::build_data::persist();
  37. // Nothing reads a package again until the next boot, so release the files and tables here.
  38. middleware::content::packages::reader::release_caches();
  39. core::ui::busy::end(core::ui::busy::Task::contentExtraction);
  40. return persisted;
  41. }
  42. const std::lock_guard lock(g_refreshLock);
  43. // The package pass creates parallel readers. Suspending the client while those threads start
  44. // can block their DLL thread-attach work behind a suspended owner, so the visible preflight
  45. // runs one frame early and extraction proceeds with the process live.
  46. core::ui::busy::raise(core::ui::busy::Task::contentExtraction);
  47. // The package pass owns the item table and must not wait on runtime content lookups.
  48. (void)items::packages::build();
  49. const bool domainsReady = ready();
  50. const bool complete = domainsReady && state::ensure_profile_item_identities()
  51. && state::ensure_character_subclasses() && emote_collection_settled()
  52. && state::build_data::persist();
  53. // The overlay ends with the work, not with the slice, so it spans every retry the pass needs.
  54. if (complete) {
  55. core::ui::busy::end(core::ui::busy::Task::contentExtraction);
  56. }
  57. return complete;
  58. }
  59. } // namespace sunrise::client::content::investment