From 50f6ea83852a821ef86e8f9cc5d1ec586a8fe89f Mon Sep 17 00:00:00 2001 From: Dayo Lawal Date: Mon, 26 Jul 2021 16:22:34 -0500 Subject: [PATCH] Using GetBuildTargetName() and other fixes Signed-off-by: Dayo Lawal --- .../Application/AtomToolsApplication.h | 7 +-- .../Application/AtomToolsApplication.cpp | 33 ++++++------- .../Code/Source/MaterialEditorApplication.cpp | 47 ++++--------------- .../Code/Source/MaterialEditorApplication.h | 1 + .../ShaderManagementConsoleApplication.cpp | 23 +++------ .../ShaderManagementConsoleApplication.h | 1 + 6 files changed, 32 insertions(+), 80 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 1ee73ee9fb..daec30f7d7 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Application/AtomToolsApplication.h +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Application/AtomToolsApplication.h @@ -11,11 +11,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -81,7 +79,7 @@ namespace AtomToolsFramework void OnExceptionMessage(AZStd::string_view message) override; //////////////////////////////////////////////////////////////////////// - virtual AZStd::string_view GetBuildTargetName() {return targetName;}; + virtual AZStd::string_view GetBuildTargetName() {return m_targetName;}; virtual void LoadSettings(); virtual void UnloadSettings(); @@ -91,9 +89,8 @@ namespace AtomToolsFramework virtual void StartInternal(); static void PyIdleWaitFrames(uint32_t frames); - void setTargetName(AZStd::string newTargetName); - AZStd::string targetName = "AtomTools"; + AZStd::string m_targetName = "AtomTools"; AzToolsFramework::TraceLogger m_traceLogger; diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Application/AtomToolsApplication.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Application/AtomToolsApplication.cpp index 93ea6ca499..c8f1bebe3a 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Application/AtomToolsApplication.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Application/AtomToolsApplication.cpp @@ -119,7 +119,7 @@ namespace AtomToolsFramework void AtomToolsApplication::CreateStaticModules(AZStd::vector& outModules) { - Application::CreateStaticModules(outModules); + Base::CreateStaticModules(outModules); outModules.push_back(aznew AzToolsFramework::AzToolsFrameworkModule); } @@ -128,7 +128,7 @@ namespace AtomToolsFramework AzFramework::AssetSystemStatusBus::Handler::BusConnect(); AzToolsFramework::EditorPythonConsoleNotificationBus::Handler::BusConnect(); - AzFramework::Application::StartCommon(systemEntity); + Base::StartCommon(systemEntity); StartInternal(); @@ -141,12 +141,12 @@ namespace AtomToolsFramework AzToolsFramework::AssetDatabase::AssetDatabaseRequestsBus::Handler::BusDisconnect(); AzFramework::AssetSystemRequestBus::Broadcast(&AzFramework::AssetSystem::AssetSystemRequests::StartDisconnectingAssetProcessor); - Application::Destroy(); + Base::Destroy(); } void AtomToolsApplication::CompileCriticalAssets(const AZStd::vector &assetFiltersArray) { - AZ_TracePrintf(targetName.c_str(), "Compiling critical assets.\n"); + AZ_TracePrintf(m_targetName.c_str(), "Compiling critical assets.\n"); QStringList failedAssets; @@ -155,7 +155,7 @@ namespace AtomToolsFramework // So the asset id won't be found right after CompileAssetSync call. for (const AZStd::string& assetFilters : assetFiltersArray) { - AZ_TracePrintf("AtomTools", "Compiling critical asset matching: %s.\n", assetFilters.c_str()); + AZ_TracePrintf(m_targetName.c_str(), "Compiling critical asset matching: %s.\n", assetFilters.c_str()); // Wait for the asset be compiled AzFramework::AssetSystem::AssetStatus status = AzFramework::AssetSystem::AssetStatus_Unknown; @@ -187,7 +187,7 @@ namespace AtomToolsFramework AZ_Assert(context, "No serialize context"); char resolvedPath[AZ_MAX_PATH_LEN] = ""; - AZStd::string fileName = "@user@/" + targetName + "UserSettings.xml"; + AZStd::string fileName = "@user@/" + m_targetName + "UserSettings.xml"; AZ::IO::FileIOBase::GetInstance()->ResolvePath( fileName.c_str(), resolvedPath, AZ_ARRAY_SIZE(resolvedPath)); @@ -202,7 +202,7 @@ namespace AtomToolsFramework AZ_Assert(context, "No serialize context"); char resolvedPath[AZ_MAX_PATH_LEN] = ""; - AZStd::string fileName = "@user@/" + targetName + "UserSettings.xml"; + AZStd::string fileName = "@user@/" + m_targetName + "UserSettings.xml"; AZ::IO::FileIOBase::GetInstance()->ResolvePath(fileName.c_str(), resolvedPath, AZ_MAX_PATH_LEN); @@ -230,12 +230,12 @@ namespace AtomToolsFramework { const AZStd::string& timeoutValue = commandLine.GetSwitchValue(timeoputSwitchName, 0); const uint32_t timeoutInMs = atoi(timeoutValue.c_str()); - AZ_Printf(targetName.c_str(), "Timeout scheduled, shutting down in %u ms", timeoutInMs); + AZ_Printf(m_targetName.c_str(), "Timeout scheduled, shutting down in %u ms", timeoutInMs); QTimer::singleShot( timeoutInMs, [this] { - AZ_Printf(targetName.c_str(), "Timeout reached, shutting down"); + AZ_Printf(m_targetName.c_str(), "Timeout reached, shutting down"); ExitMainLoop(); }); } @@ -248,7 +248,7 @@ namespace AtomToolsFramework const AZStd::string runPythonScriptPath = commandLine.GetSwitchValue(runPythonScriptSwitchName, runPythonScriptIndex); AZStd::vector runPythonArgs; - AZ_Printf(targetName.c_str(), "Launching script: %s", runPythonScriptPath.c_str()); + AZ_Printf(m_targetName.c_str(), "Launching script: %s", runPythonScriptPath.c_str()); AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast( &AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, runPythonScriptPath, runPythonArgs); } @@ -323,7 +323,7 @@ namespace AtomToolsFramework return; } - AZStd::string fileName = targetName + ".log"; + AZStd::string fileName = m_targetName + ".log"; m_traceLogger.WriteStartupLog(fileName.c_str()); @@ -374,7 +374,7 @@ namespace AtomToolsFramework void AtomToolsApplication::Stop() { UnloadSettings(); - AzFramework::Application::Stop(); + Base::Stop(); } void AtomToolsApplication::QueryApplicationType(AZ::ApplicationTypeQuery& appType) const @@ -394,7 +394,7 @@ namespace AtomToolsFramework for (auto& line : lines) { - AZ_TracePrintf(targetName.c_str(), "Python: %s\n", line.c_str()); + AZ_TracePrintf(m_targetName.c_str(), "Python: %s\n", line.c_str()); } #endif } @@ -407,7 +407,7 @@ namespace AtomToolsFramework void AtomToolsApplication::OnExceptionMessage([[maybe_unused]] AZStd::string_view message) { - AZ_Error(targetName.c_str(), false, "Python: " AZ_STRING_FORMAT, AZ_STRING_ARG(message)); + AZ_Error(m_targetName.c_str(), false, "Python: " AZ_STRING_FORMAT, AZ_STRING_ARG(message)); } // Copied from PyIdleWaitFrames in CryEdit.cpp @@ -444,9 +444,4 @@ namespace AtomToolsFramework Ticker ticker(&loop, frames); loop.exec(); } - - void AtomToolsApplication::setTargetName(AZStd::string newTargetName) - { - targetName = newTargetName; - } } // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index 038005891d..0b4165cce0 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_view GetBuildTargetName() + AZStd::string_view MaterialEditorApplication::GetBuildTargetName() { #if !defined (LY_CMAKE_TARGET) #error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target" @@ -75,7 +75,7 @@ namespace MaterialEditor { QApplication::setApplicationName("O3DE Material Editor"); - setTargetName("MaterialEditor"); + m_targetName = GetBuildTargetName(); AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddBuildSystemTargetSpecialization( *AZ::SettingsRegistry::Get(), GetBuildTargetName()); @@ -139,7 +139,7 @@ namespace MaterialEditor AzFramework::AssetSystem::ConnectionSettings connectionSettings; AzFramework::AssetSystem::ReadConnectionSettingsFromSettingsRegistry(connectionSettings); connectionSettings.m_connectionDirection = AzFramework::AssetSystem::ConnectionSettings::ConnectionDirection::ConnectToAssetProcessor; - connectionSettings.m_connectionIdentifier = targetName.c_str(); + connectionSettings.m_connectionIdentifier = GetBuildTargetName(); connectionSettings.m_loggingCallback = []([[maybe_unused]] AZStd::string_view logData) { AZ_TracePrintf("Material Editor", "%.*s", aznumeric_cast(logData.size()), logData.data()); @@ -147,12 +147,12 @@ namespace MaterialEditor AzFramework::AssetSystemRequestBus::BroadcastResult(connectedToAssetProcessor, &AzFramework::AssetSystemRequestBus::Events::EstablishAssetProcessorConnection, connectionSettings); - // 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/" }; - 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); } @@ -168,33 +168,6 @@ namespace MaterialEditor &MaterialEditor::MaterialEditorWindowRequestBus::Handler::ActivateWindow); } - const AZStd::string timeoputSwitchName = "timeout"; - if (commandLine.HasSwitch(timeoputSwitchName)) - { - const AZStd::string& timeoutValue = commandLine.GetSwitchValue(timeoputSwitchName, 0); - const uint32_t timeoutInMs = atoi(timeoutValue.c_str()); - AZ_Printf("MaterialEditor", "Timeout scheduled, shutting down in %u ms", timeoutInMs); - QTimer::singleShot(timeoutInMs, [this] { - AZ_Printf("MaterialEditor", "Timeout reached, shutting down"); - ExitMainLoop(); - }); - } - - // Process command line options for running one or more python scripts on startup - const AZStd::string runPythonScriptSwitchName = "runpython"; - size_t runPythonScriptCount = commandLine.GetNumSwitchValues(runPythonScriptSwitchName); - for (size_t runPythonScriptIndex = 0; runPythonScriptIndex < runPythonScriptCount; ++runPythonScriptIndex) - { - const AZStd::string runPythonScriptPath = commandLine.GetSwitchValue(runPythonScriptSwitchName, runPythonScriptIndex); - AZStd::vector runPythonArgs; - - AZ_Printf("MaterialEditor", "Launching script: %s", runPythonScriptPath.c_str()); - AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast( - &AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, - runPythonScriptPath, - runPythonArgs); - } - // Process command line options for opening one or more material documents on startup size_t openDocumentCount = commandLine.GetNumMiscValues(); for (size_t openDocumentIndex = 0; openDocumentIndex < openDocumentCount; ++openDocumentIndex) @@ -205,11 +178,7 @@ namespace MaterialEditor MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::OpenDocument, openDocumentPath); } - const AZStd::string exitAfterCommandsSwitchName = "exitaftercommands"; - if (commandLine.HasSwitch(exitAfterCommandsSwitchName)) - { - ExitMainLoop(); - } + Base::ProcessCommandLine(commandLine); } void MaterialEditorApplication::StartInternal() diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h index 92f4223f99..0739fa6ae1 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h @@ -54,5 +54,6 @@ namespace MaterialEditor void ProcessCommandLine(const AZ::CommandLine& commandLine) override; void StartInternal() override; + AZStd::string_view GetBuildTargetName() override; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp index 48c246f938..5cb98a4345 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_view GetBuildTargetName() + AZStd::string_view ShaderManagementConsoleApplication::GetBuildTargetName() { #if !defined (LY_CMAKE_TARGET) #error "LY_CMAKE_TARGET must be defined in order to add this source file to a CMake executable target" @@ -70,7 +70,7 @@ namespace ShaderManagementConsole : AtomToolsApplication(argc, argv) { QApplication::setApplicationName("O3DE Shader Management Console"); - setTargetName("ShaderManagementConsole"); + m_targetName = GetBuildTargetName(); // The settings registry has been created at this point, so add the CMake target AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddBuildSystemTargetSpecialization( @@ -125,29 +125,18 @@ namespace ShaderManagementConsole }; AzFramework::AssetSystemRequestBus::Broadcast(ConnectToAssetProcessorWithIdentifier); - // 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/"}; - 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(); } -// bool ShaderManagementConsoleApplication::OnPrintf(const char* window, const char* /*message*/) -// { -// // Suppress spam from the Source Control system -// if (0 == strncmp(window, AzToolsFramework::SCC_WINDOW, AZ_ARRAY_SIZE(AzToolsFramework::SCC_WINDOW))) -// { -// return true; -// } -// -// return false; -// } - void ShaderManagementConsoleApplication::ProcessCommandLine() { // Process command line options for running one or more python scripts on startup diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h index 7c4f53f4e9..277d3ef1e3 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h @@ -55,5 +55,6 @@ namespace ShaderManagementConsole void ProcessCommandLine(); void StartInternal() override; + AZStd::string_view GetBuildTargetName() override; }; } // namespace ShaderManagementConsole