BundlingSystemComponent.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/std/containers/vector.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <AzCore/std/containers/unordered_map.h>
  13. #include <AzCore/std/parallel/mutex.h>
  14. #include <AzCore/std/smart_ptr/shared_ptr.h>
  15. #include <AzFramework/Asset/AssetRegistry.h>
  16. #include <LmbrCentral/Bundling/BundlingSystemComponentBus.h>
  17. #include <AzFramework/Archive/ArchiveBus.h>
  18. namespace AzFramework
  19. {
  20. class AssetBundleManifest;
  21. }
  22. namespace LmbrCentral
  23. {
  24. struct OpenBundleInfo
  25. {
  26. OpenBundleInfo() = default;
  27. AZStd::shared_ptr<AzFramework::AssetBundleManifest> m_manifest;
  28. AZStd::shared_ptr<AzFramework::AssetRegistry> m_catalog;
  29. };
  30. /**
  31. * System component for managing bundles
  32. */
  33. class BundlingSystemComponent
  34. : public AZ::Component
  35. , public BundlingSystemRequestBus::Handler
  36. , public AZ::IO::ArchiveNotificationBus::Handler
  37. {
  38. public:
  39. AZ_COMPONENT(BundlingSystemComponent, "{0FB7153D-EE80-4B1C-9584-134270401AAF}");
  40. static void Reflect(AZ::ReflectContext* context);
  41. BundlingSystemComponent() = default;
  42. protected:
  43. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  44. {
  45. provided.push_back(AZ_CRC_CE("BundlingService"));
  46. }
  47. // AZ::Component
  48. void Activate() override;
  49. void Deactivate() override;
  50. // BundlingSystemRequestBus
  51. void LoadBundles(const char* baseFolder, const char* fileExtension) override;
  52. void UnloadBundles() override;
  53. void BundleOpened(const char* bundleName, AZStd::shared_ptr<AzFramework::AssetBundleManifest> bundleManifest, const char* nextBundle, AZStd::shared_ptr<AzFramework::AssetRegistry> bundleCatalog) override;
  54. void BundleClosed(const char* bundleName) override;
  55. AZStd::vector<AZStd::string> GetBundleList(const char* bundlePath, const char* bundleExtension) const;
  56. //! Bundles which are split across archives (Usually due to size constraints) have the dependent bundles listed in the manifest
  57. //! of the main bundle. This method manages opening the dependent bundles.
  58. void OpenDependentBundles(const char* bundleName, AZStd::shared_ptr<AzFramework::AssetBundleManifest> bundleManifest);
  59. //! Bundles which are split across archives (Usually due to size constraints) have the dependent bundles listed in the manifest
  60. //! of the main bundle. This method manages closing the dependent bundles.
  61. void CloseDependentBundles(const char* bundleName, AZStd::shared_ptr<AzFramework::AssetBundleManifest> bundleManifest);
  62. size_t GetOpenedBundleCount() const override;
  63. private:
  64. // Maintain a list of all opened bundles as reported through the BundleOpened ebus
  65. AZStd::unordered_map<AZStd::string, AZStd::unique_ptr<OpenBundleInfo>> m_openedBundles;
  66. // Used to maintain the order of the opened bundles to properly apply catalog info
  67. AZStd::vector<AZStd::string> m_openedBundleList;
  68. // Maintain a list of bundles opened through our "LoadBundles" command.
  69. // We'll unmount only this list rather than all opened bundles when calling UnloadBundles
  70. AZStd::vector<AZStd::string> m_bundleModeBundles;
  71. mutable AZStd::mutex m_openedBundleMutex;
  72. AZStd::mutex m_bundleModeMutex;
  73. };
  74. }