From 4b97a416a39b9dfe87b9c05b2fa9486b23534406 Mon Sep 17 00:00:00 2001 From: Dayo Lawal Date: Tue, 27 Jul 2021 02:06:33 -0500 Subject: [PATCH] GetCriticalAssetFilters() Signed-off-by: Dayo Lawal --- .../Application/AtomToolsApplication.h | 8 +++- .../Application/AtomToolsApplication.cpp | 45 ++++++++++++++++--- .../Code/Source/MaterialEditorApplication.cpp | 37 +++------------ .../Code/Source/MaterialEditorApplication.h | 8 +--- .../ShaderManagementConsoleApplication.cpp | 39 +++------------- .../ShaderManagementConsoleApplication.h | 8 +--- 6 files changed, 62 insertions(+), 83 deletions(-) diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Application/AtomToolsApplication.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Application/AtomToolsApplication.h index 9d412ec477..08eac727a3 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Application/AtomToolsApplication.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Application/AtomToolsApplication.h @@ -62,6 +62,11 @@ namespace AtomToolsFramework void Destroy() override; ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // AzFramework::AssetSystemStatusBus::Handler overrides... + void AssetSystemAvailable() override; + ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// // AZ::ComponentApplication overrides... void QueryApplicationType(AZ::ApplicationTypeQuery& appType) const override; @@ -79,7 +84,8 @@ namespace AtomToolsFramework void OnExceptionMessage(AZStd::string_view message) override; //////////////////////////////////////////////////////////////////////// - virtual AZStd::string GetBuildTargetName(); + virtual AZStd::string GetBuildTargetName() const; + virtual AZStd::vector GetCriticalAssetFilters() const; virtual void LoadSettings(); virtual void UnloadSettings(); diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Application/AtomToolsApplication.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Application/AtomToolsApplication.cpp index 0ee06d3fc2..2aeb53db90 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Application/AtomToolsApplication.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Application/AtomToolsApplication.cpp @@ -39,7 +39,7 @@ AZ_POP_DISABLE_WARNING namespace AtomToolsFramework { - AZStd::string AtomToolsApplication::GetBuildTargetName() + AZStd::string AtomToolsApplication::GetBuildTargetName() const { return AZStd::string("AtomTools"); } @@ -69,7 +69,7 @@ namespace AtomToolsFramework void AtomToolsApplication::Reflect(AZ::ReflectContext* context) { - Application::Reflect(context); + Base::Reflect(context); AzToolsFramework::AssetBrowser::AssetBrowserEntry::Reflect(context); AzToolsFramework::AssetBrowser::RootAssetBrowserEntry::Reflect(context); @@ -82,13 +82,12 @@ namespace AtomToolsFramework if (auto behaviorContext = azrtti_cast(context)) { - AZStd::string fileName = GetBuildTargetName() + ".general"; // this will put these methods into the 'azlmbr.AtomTools.general' module - auto addGeneral = [fileName](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder) + auto addGeneral = [](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder) { methodBuilder->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation) ->Attribute(AZ::Script::Attributes::Category, "Editor") - ->Attribute(AZ::Script::Attributes::Module, fileName); + ->Attribute(AZ::Script::Attributes::Module, "AtomTools"); }; // The reflection here is based on patterns in CryEditPythonHandler::Reflect addGeneral(behaviorContext->Method( @@ -150,6 +149,42 @@ namespace AtomToolsFramework Base::Destroy(); } + AZStd::vector AtomToolsApplication::GetCriticalAssetFilters() const + { + // List of common asset filters for things that need to be compiled to run the material editor + // Some of these things will not be necessary once we have proper support for queued asset loading and reloading + return AZStd::vector({ "passes/", "config/" }); + } + + void AtomToolsApplication::AssetSystemAvailable() + { + bool connectedToAssetProcessor = false; + + // When the AssetProcessor is already launched it should take less than a second to perform a connection + // but when the AssetProcessor needs to be launch it could take up to 15 seconds to have the AssetProcessor initialize + // and able to negotiate a connection when running a debug build + // and to negotiate a connection + + AzFramework::AssetSystem::ConnectionSettings connectionSettings; + AzFramework::AssetSystem::ReadConnectionSettingsFromSettingsRegistry(connectionSettings); + connectionSettings.m_connectionDirection = + AzFramework::AssetSystem::ConnectionSettings::ConnectionDirection::ConnectToAssetProcessor; + connectionSettings.m_connectionIdentifier = GetBuildTargetName(); + connectionSettings.m_loggingCallback = []([[maybe_unused]] AZStd::string_view logData) + { + AZ_TracePrintf("Atom Tools", "%.*s", aznumeric_cast(logData.size()), logData.data()); + }; + AzFramework::AssetSystemRequestBus::BroadcastResult( + connectedToAssetProcessor, &AzFramework::AssetSystemRequestBus::Events::EstablishAssetProcessorConnection, connectionSettings); + + if (connectedToAssetProcessor) + { + CompileCriticalAssets(GetCriticalAssetFilters()); + } + + AzFramework::AssetSystemStatusBus::Handler::BusDisconnect(); + } + void AtomToolsApplication::CompileCriticalAssets(const AZStd::vector &assetFiltersArray) { AZ_TracePrintf(GetBuildTargetName().c_str(), "Compiling critical assets.\n"); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index 6832ca683c..57313c6694 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -51,7 +51,7 @@ AZ_POP_DISABLE_WARNING namespace MaterialEditor { //! This function returns the build system target name of "MaterialEditor - AZStd::string MaterialEditorApplication::GetBuildTargetName() + AZStd::string MaterialEditorApplication::GetBuildTargetName() const { #if !defined (LY_CMAKE_TARGET) #error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target" @@ -117,36 +117,11 @@ namespace MaterialEditor Base::Destroy(); } - void MaterialEditorApplication::AssetSystemAvailable() + AZStd::vector MaterialEditorApplication::GetCriticalAssetFilters() const { - bool connectedToAssetProcessor = false; - - // When the AssetProcessor is already launched it should take less than a second to perform a connection - // but when the AssetProcessor needs to be launch it could take up to 15 seconds to have the AssetProcessor initialize - // and able to negotiate a connection when running a debug build - // and to negotiate a connection - - AzFramework::AssetSystem::ConnectionSettings connectionSettings; - AzFramework::AssetSystem::ReadConnectionSettingsFromSettingsRegistry(connectionSettings); - connectionSettings.m_connectionDirection = AzFramework::AssetSystem::ConnectionSettings::ConnectionDirection::ConnectToAssetProcessor; - connectionSettings.m_connectionIdentifier = GetBuildTargetName(); - connectionSettings.m_loggingCallback = []([[maybe_unused]] AZStd::string_view logData) - { - AZ_TracePrintf("Material Editor", "%.*s", aznumeric_cast(logData.size()), logData.data()); - }; - AzFramework::AssetSystemRequestBus::BroadcastResult(connectedToAssetProcessor, - &AzFramework::AssetSystemRequestBus::Events::EstablishAssetProcessorConnection, connectionSettings); - - if (connectedToAssetProcessor) - { - // List of common asset filters for things that need to be compiled to run the material editor - // Some of these things will not be necessary once we have proper support for queued asset loading and reloading - const AZStd::vector assetFiltersArray = { "passes/", "config/", "MaterialEditor/" }; - - CompileCriticalAssets(assetFiltersArray); - } - - AzFramework::AssetSystemStatusBus::Handler::BusDisconnect(); + // List of common asset filters for things that need to be compiled to run the material editor + // Some of these things will not be necessary once we have proper support for queued asset loading and reloading + return AZStd::vector({ "passes/", "config/", "MaterialEditor" }); } void MaterialEditorApplication::ProcessCommandLine(const AZ::CommandLine& commandLine) @@ -164,7 +139,7 @@ namespace MaterialEditor { const AZStd::string openDocumentPath = commandLine.GetMiscValue(openDocumentIndex); - AZ_Printf("MaterialEditor", "Opening document: %s", openDocumentPath.c_str()); + AZ_Printf(GetBuildTargetName().c_str(), "Opening document: %s", openDocumentPath.c_str()); MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::OpenDocument, openDocumentPath); } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h index 1139a73827..0177013a3d 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h @@ -46,13 +46,9 @@ namespace MaterialEditor void Destroy() override; ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // AzFramework::AssetSystemStatusBus::Handler overrides... - void AssetSystemAvailable() override; - ////////////////////////////////////////////////////////////////////////// - void ProcessCommandLine(const AZ::CommandLine& commandLine) override; void StartInternal() override; - AZStd::string GetBuildTargetName() override; + AZStd::string GetBuildTargetName() const override; + AZStd::vector GetCriticalAssetFilters() const override; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp index 6d5e331c75..6f6ee697d5 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp @@ -47,7 +47,7 @@ AZ_POP_DISABLE_WARNING namespace ShaderManagementConsole { - AZStd::string ShaderManagementConsoleApplication::GetBuildTargetName() + AZStd::string ShaderManagementConsoleApplication::GetBuildTargetName() const { #if !defined (LY_CMAKE_TARGET) #error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target" @@ -100,40 +100,11 @@ namespace ShaderManagementConsole Base::Destroy(); } - void ShaderManagementConsoleApplication::AssetSystemAvailable() + AZStd::vector ShaderManagementConsoleApplication::GetCriticalAssetFilters() const { - // Try connect to AP first before try to launch it manually. - bool connected = false; - auto ConnectToAssetProcessorWithIdentifier = [&connected](AzFramework::AssetSystem::AssetSystemRequests* assetSystemRequests) - { - // When the AssetProcessor is already launched it should take less than a second to perform a connection - // but when the AssetProcessor needs to be launch it could take up to 15 seconds to have the AssetProcessor initialize - // and able to negotiate a connection when running a debug build - // and to negotiate a connection - - AzFramework::AssetSystem::ConnectionSettings connectionSettings; - AzFramework::AssetSystem::ReadConnectionSettingsFromSettingsRegistry(connectionSettings); - connectionSettings.m_connectionDirection = AzFramework::AssetSystem::ConnectionSettings::ConnectionDirection::ConnectToAssetProcessor; - connectionSettings.m_connectionIdentifier = "Shader Management Console"; - connectionSettings.m_loggingCallback = []([[maybe_unused]] AZStd::string_view logData) - { - AZ_TracePrintf("Shader Management Console", "%.*s", aznumeric_cast(logData.size()), logData.data()); - }; - - connected = assetSystemRequests->EstablishAssetProcessorConnection(connectionSettings); - }; - AzFramework::AssetSystemRequestBus::Broadcast(ConnectToAssetProcessorWithIdentifier); - - if (connected) - { - // List of common asset filters for things that need to be compiled to run the material editor - // Some of these things will not be necessary once we have proper support for queued asset loading and reloading - const AZStd::vector assetFiltersArray = { "passes/", "config/" }; - - CompileCriticalAssets(assetFiltersArray); - } - - AzFramework::AssetSystemStatusBus::Handler::BusDisconnect(); + // List of common asset filters for things that need to be compiled to run the material editor + // Some of these things will not be necessary once we have proper support for queued asset loading and reloading + return AZStd::vector({ "passes/", "config/" }); } void ShaderManagementConsoleApplication::ProcessCommandLine() diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h index 42817040ce..6229f5d77d 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h @@ -43,13 +43,9 @@ namespace ShaderManagementConsole void Destroy() override; ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // AzFramework::AssetSystemStatusBus::Handler overrides... - void AssetSystemAvailable() override; - ////////////////////////////////////////////////////////////////////////// - void ProcessCommandLine(); void StartInternal() override; - AZStd::string GetBuildTargetName() override; + AZStd::string GetBuildTargetName() const override; + AZStd::vector GetCriticalAssetFilters() const override; }; } // namespace ShaderManagementConsole