AssetStatusTracker.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #pragma once
  13. #include <AzFramework/Asset/AssetSystemBus.h>
  14. namespace AtomSampleViewer
  15. {
  16. //! Utility for tracking status of assets being built by the asset processor so scripts can insert delays
  17. class AssetStatusTracker final
  18. : public AzFramework::AssetSystemInfoBus::Handler
  19. {
  20. public:
  21. ~AssetStatusTracker();
  22. //! Starts tracking asset status updates from the Asset Processor.
  23. //! Clears any asset status information already collected.
  24. //! Clears any asset expectations that were added by ExpectAsset().
  25. void StartTracking();
  26. //! Sets the AssetStatusTracker to expect a particular asset with specific expected results.
  27. //! Note this can be called multiple times with the same assetPath, in which case the expected counts will be added.
  28. //! @param sourceAssetPath the source asset path, relative to the watch folder. Will be normalized and matched case-insensitive.
  29. //! @param expectedCount number of completed jobs expected for this asset.
  30. void ExpectAsset(AZStd::string sourceAssetPath, uint32_t expectedCount = 1);
  31. //! Returns whether all of the expected assets have finished.
  32. bool DidExpectedAssetsFinish() const;
  33. //! Stops tracking asset status updates from the Asset Processor. Clears any asset status information already collected.
  34. void StopTracking();
  35. private:
  36. // Tracks the number of times various events occur
  37. struct AssetStatusEvents
  38. {
  39. uint32_t m_started = 0;
  40. uint32_t m_succeeded = 0;
  41. uint32_t m_failed = 0;
  42. uint32_t m_expecteCount = 0;
  43. };
  44. // AssetSystemInfoBus overrides...
  45. void AssetCompilationStarted(const AZStd::string& assetPath) override;
  46. void AssetCompilationSuccess(const AZStd::string& assetPath) override;
  47. void AssetCompilationFailed(const AZStd::string& assetPath) override;
  48. bool m_isTracking = false;
  49. AZStd::unordered_map<AZStd::string /*asset path*/, AssetStatusEvents> m_allAssetStatusData;
  50. mutable AZStd::mutex m_mutex;
  51. };
  52. } // namespace AtomSampleViewer