AssetValidationSystemComponent.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 <AssetValidation/AssetValidationBus.h>
  11. #include <AzCore/std/containers/set.h>
  12. #include <AzCore/std/containers/unordered_map.h>
  13. #include <AzCore/std/containers/vector.h>
  14. #include <AzCore/std/string/string.h>
  15. #include <AzFramework/Asset/AssetSeedList.h>
  16. #include <AzCore/Outcome/Outcome.h>
  17. #include <AssetSystemTestCommands.h>
  18. #include <CrySystemBus.h>
  19. #include <AzFramework/Archive/ArchiveBus.h>
  20. struct IConsoleCmdArgs;
  21. namespace AssetValidation
  22. {
  23. class AssetValidationSystemComponent
  24. : public AZ::Component
  25. , protected AssetValidationRequestBus::Handler
  26. , public CrySystemEventBus::Handler
  27. , public AZ::IO::ArchiveNotificationBus::Handler
  28. {
  29. public:
  30. AZ_COMPONENT(AssetValidationSystemComponent, "{BF122D5A-17B3-46B9-880B-39026989CD7E}");
  31. static void Reflect(AZ::ReflectContext* context);
  32. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  33. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  34. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  35. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  36. protected:
  37. ////////////////////////////////////////////////////////////////////////
  38. // AssetValidationRequestBus interface implementation
  39. // Given an asset fileName does it exist in our dependency graph beneath any of our declared seed assetIds
  40. bool IsKnownAsset(const char* fileName) override;
  41. bool CheckKnownAsset(const char* fileName) override;
  42. bool AddSeedAssetId(AZ::Data::AssetId assetId, AZ::u32 sourceId) override;
  43. bool RemoveSeedAssetId(AZ::Data::AssetId assetId, AZ::u32 sourceId) override;
  44. bool RemoveSeedAssetIdList(AssetSourceList assetList) override;
  45. void SeedMode() override;
  46. bool AddSeedPath(const char* fileName) override;
  47. bool RemoveSeedPath(const char* fileName) override;
  48. void ListKnownAssets() override;
  49. void TogglePrintExcluded() override;
  50. virtual AZ::Outcome<AzFramework::AssetSeedList, AZStd::string> LoadSeedList(const char* fileName, AZStd::string& seedFilepath);
  51. bool RemoveSeedListHelper(const char* seedPath);
  52. ////////////////////////////////////////////////////////////////////////
  53. void BuildAssetList();
  54. void AddKnownAssets(AZ::Data::AssetId assetId);
  55. //! Return the number of occurrences of that assetID remaining, -1 for failure
  56. int RemoveSeedAssetIdBySource(const AZ::Data::AssetId& assetId, AZ::u32 sourceId);
  57. static void ConsoleCommandSeedMode(IConsoleCmdArgs* pCmdArgs);
  58. static void ConsoleCommandAddSeedPath(IConsoleCmdArgs* pCmdArgs);
  59. static void ConsoleCommandRemoveSeedPath(IConsoleCmdArgs* pCmdArgs);
  60. static void ConsoleCommandKnownAssets(IConsoleCmdArgs* pCmdArgs);
  61. static void ConsoleCommandTogglePrintExcluded(IConsoleCmdArgs* pCmdArgs);
  62. void OnCrySystemInitialized(ISystem& system, const SSystemInitParams& systemInitParams) override;
  63. ////////////////////////////////////////////////////////////////////////
  64. // AZ::Component interface implementation
  65. void Init() override;
  66. void Activate() override;
  67. void Deactivate() override;
  68. ////////////////////////////////////////////////////////////////////////
  69. ////////////////////////////////////////////////////////////////////////
  70. // ArchiveNotificationBus interface implementation
  71. void FileAccess(const char* filePath) override /*override*/;
  72. ////////////////////////////////////////////////////////////////////////
  73. bool AddSeedList(const char* seedPath) override;
  74. bool RemoveSeedList(const char* seedPath) override;
  75. ////////////////////////////////////////////////////////////////////////
  76. static void ConsoleCommandAddSeedList(IConsoleCmdArgs* pCmdArgs);
  77. static void ConsoleCommandRemoveSeedList(IConsoleCmdArgs* pCmdArgs);
  78. bool AddSeedsFor(const AzFramework::AssetSeedList& seedList, AZ::u32 sourceId);
  79. bool RemoveSeedsFor(const AzFramework::AssetSeedList& seedList, AZ::u32 sourceId);
  80. bool AddSeedListHelper(const char* seedPath);
  81. private:
  82. bool m_seedMode{ false };
  83. bool m_printExcluded{ false };
  84. AZStd::unordered_map<AZ::Data::AssetId, AZStd::set<AZ::u32>> m_seedAssetIds;
  85. AZStd::set<AZ::Data::AssetId> m_knownAssetIds;
  86. AZStd::set<AZStd::string> m_knownAssetPaths;
  87. AZStd::vector<AZStd::string> m_excludedFileTags;
  88. AZStd::set<AZStd::string> m_seedLists;
  89. AZStd::set<AZStd::string> m_assetSet;
  90. // Auto registration of Asset System Test Commands
  91. AssetValidation m_testCommands;
  92. };
  93. }