AssetStatusTracker.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <AzFramework/Asset/AssetSystemBus.h>
  10. namespace AtomSampleViewer
  11. {
  12. //! Utility for tracking status of assets being built by the asset processor so scripts can insert delays
  13. class AssetStatusTracker final
  14. : public AzFramework::AssetSystemInfoBus::Handler
  15. {
  16. public:
  17. ~AssetStatusTracker();
  18. //! Starts tracking asset status updates from the Asset Processor.
  19. //! Clears any asset status information already collected.
  20. //! Clears any asset expectations that were added by ExpectAsset().
  21. void StartTracking();
  22. //! Sets the AssetStatusTracker to expect a particular asset with specific expected results.
  23. //! Note this can be called multiple times with the same assetPath, in which case the expected counts will be added.
  24. //! @param sourceAssetPath the source asset path, relative to the watch folder. Will be normalized and matched case-insensitive.
  25. //! @param expectedCount number of completed jobs expected for this asset.
  26. void ExpectAsset(AZStd::string sourceAssetPath, uint32_t expectedCount = 1);
  27. //! Returns whether all of the expected assets have finished.
  28. bool DidExpectedAssetsFinish() const;
  29. //! Stops tracking asset status updates from the Asset Processor. Clears any asset status information already collected.
  30. void StopTracking();
  31. private:
  32. // Tracks the number of times various events occur
  33. struct AssetStatusEvents
  34. {
  35. uint32_t m_started = 0;
  36. uint32_t m_succeeded = 0;
  37. uint32_t m_failed = 0;
  38. uint32_t m_expecteCount = 0;
  39. };
  40. // AssetSystemInfoBus overrides...
  41. void AssetCompilationStarted(const AZStd::string& assetPath) override;
  42. void AssetCompilationSuccess(const AZStd::string& assetPath) override;
  43. void AssetCompilationFailed(const AZStd::string& assetPath) override;
  44. bool m_isTracking = false;
  45. AZStd::unordered_map<AZStd::string /*asset path*/, AssetStatusEvents> m_allAssetStatusData;
  46. mutable AZStd::mutex m_mutex;
  47. };
  48. } // namespace AtomSampleViewer