More refractoring

Signed-off-by: Dayo Lawal <lawalfua@amazon.com>
This commit is contained in:
Dayo Lawal
2021-07-26 17:41:10 -05:00
parent 50f6ea8385
commit 7122f1b761
6 changed files with 40 additions and 89 deletions
@@ -79,7 +79,7 @@ namespace AtomToolsFramework
void OnExceptionMessage(AZStd::string_view message) override;
////////////////////////////////////////////////////////////////////////
virtual AZStd::string_view GetBuildTargetName() {return m_targetName;};
virtual AZStd::string GetBuildTargetName();
virtual void LoadSettings();
virtual void UnloadSettings();
@@ -90,8 +90,6 @@ namespace AtomToolsFramework
static void PyIdleWaitFrames(uint32_t frames);
AZStd::string m_targetName = "AtomTools";
AzToolsFramework::TraceLogger m_traceLogger;
//! Local user settings are used to store material browser tree expansion state
@@ -39,6 +39,11 @@ AZ_POP_DISABLE_WARNING
namespace AtomToolsFramework
{
AZStd::string AtomToolsApplication::GetBuildTargetName()
{
return AZStd::string("AtomTools");
}
const char* AtomToolsApplication::GetCurrentConfigurationName() const
{
#if defined(_RELEASE)
@@ -146,7 +151,7 @@ namespace AtomToolsFramework
void AtomToolsApplication::CompileCriticalAssets(const AZStd::vector<AZStd::string> &assetFiltersArray)
{
AZ_TracePrintf(m_targetName.c_str(), "Compiling critical assets.\n");
AZ_TracePrintf(GetBuildTargetName().c_str(), "Compiling critical assets.\n");
QStringList failedAssets;
@@ -155,7 +160,7 @@ namespace AtomToolsFramework
// So the asset id won't be found right after CompileAssetSync call.
for (const AZStd::string& assetFilters : assetFiltersArray)
{
AZ_TracePrintf(m_targetName.c_str(), "Compiling critical asset matching: %s.\n", assetFilters.c_str());
AZ_TracePrintf(GetBuildTargetName().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 +192,7 @@ namespace AtomToolsFramework
AZ_Assert(context, "No serialize context");
char resolvedPath[AZ_MAX_PATH_LEN] = "";
AZStd::string fileName = "@user@/" + m_targetName + "UserSettings.xml";
AZStd::string fileName = "@user@/" + GetBuildTargetName() + "UserSettings.xml";
AZ::IO::FileIOBase::GetInstance()->ResolvePath(
fileName.c_str(), resolvedPath, AZ_ARRAY_SIZE(resolvedPath));
@@ -202,7 +207,7 @@ namespace AtomToolsFramework
AZ_Assert(context, "No serialize context");
char resolvedPath[AZ_MAX_PATH_LEN] = "";
AZStd::string fileName = "@user@/" + m_targetName + "UserSettings.xml";
AZStd::string fileName = "@user@/" + GetBuildTargetName() + "UserSettings.xml";
AZ::IO::FileIOBase::GetInstance()->ResolvePath(fileName.c_str(), resolvedPath, AZ_MAX_PATH_LEN);
@@ -230,12 +235,12 @@ namespace AtomToolsFramework
{
const AZStd::string& timeoutValue = commandLine.GetSwitchValue(timeoputSwitchName, 0);
const uint32_t timeoutInMs = atoi(timeoutValue.c_str());
AZ_Printf(m_targetName.c_str(), "Timeout scheduled, shutting down in %u ms", timeoutInMs);
AZ_Printf(GetBuildTargetName().c_str(), "Timeout scheduled, shutting down in %u ms", timeoutInMs);
QTimer::singleShot(
timeoutInMs,
[this]
{
AZ_Printf(m_targetName.c_str(), "Timeout reached, shutting down");
AZ_Printf(GetBuildTargetName().c_str(), "Timeout reached, shutting down");
ExitMainLoop();
});
}
@@ -248,7 +253,7 @@ namespace AtomToolsFramework
const AZStd::string runPythonScriptPath = commandLine.GetSwitchValue(runPythonScriptSwitchName, runPythonScriptIndex);
AZStd::vector<AZStd::string_view> runPythonArgs;
AZ_Printf(m_targetName.c_str(), "Launching script: %s", runPythonScriptPath.c_str());
AZ_Printf(GetBuildTargetName().c_str(), "Launching script: %s", runPythonScriptPath.c_str());
AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast(
&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, runPythonScriptPath, runPythonArgs);
}
@@ -323,7 +328,7 @@ namespace AtomToolsFramework
return;
}
AZStd::string fileName = m_targetName + ".log";
AZStd::string fileName = GetBuildTargetName() + ".log";
m_traceLogger.WriteStartupLog(fileName.c_str());
@@ -342,6 +347,23 @@ namespace AtomToolsFramework
AZ::RPI::RPISystemInterface::Get()->InitializeSystemAssets();
LoadSettings();
auto editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
if (editorPythonEventsInterface)
{
// The PythonSystemComponent does not call StartPython to allow for lazy python initialization, so start it here
// The PythonSystemComponent will call StopPython when it deactivates, so we do not need our own corresponding call to
// StopPython
editorPythonEventsInterface->StartPython();
}
// Delay execution of commands and scripts post initialization
QTimer::singleShot(
0,
[this]()
{
ProcessCommandLine(m_commandLine);
});
}
bool AtomToolsApplication::GetAssetDatabaseLocation(AZStd::string& result)
@@ -394,7 +416,7 @@ namespace AtomToolsFramework
for (auto& line : lines)
{
AZ_TracePrintf(m_targetName.c_str(), "Python: %s\n", line.c_str());
AZ_TracePrintf(GetBuildTargetName().c_str(), "Python: %s\n", line.c_str());
}
#endif
}
@@ -407,7 +429,7 @@ namespace AtomToolsFramework
void AtomToolsApplication::OnExceptionMessage([[maybe_unused]] AZStd::string_view message)
{
AZ_Error(m_targetName.c_str(), false, "Python: " AZ_STRING_FORMAT, AZ_STRING_ARG(message));
AZ_Error(GetBuildTargetName().c_str(), false, "Python: " AZ_STRING_FORMAT, AZ_STRING_ARG(message));
}
// Copied from PyIdleWaitFrames in CryEdit.cpp
@@ -51,12 +51,12 @@ AZ_POP_DISABLE_WARNING
namespace MaterialEditor
{
//! This function returns the build system target name of "MaterialEditor
AZStd::string_view MaterialEditorApplication::GetBuildTargetName()
AZStd::string 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"
#endif
return AZStd::string_view{ LY_CMAKE_TARGET };
return AZStd::string{ LY_CMAKE_TARGET };
}
const char* MaterialEditorApplication::GetCurrentConfigurationName() const
@@ -75,7 +75,6 @@ namespace MaterialEditor
{
QApplication::setApplicationName("O3DE Material Editor");
m_targetName = GetBuildTargetName();
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddBuildSystemTargetSpecialization(
*AZ::SettingsRegistry::Get(), GetBuildTargetName());
@@ -102,15 +101,6 @@ namespace MaterialEditor
outModules.push_back(aznew MaterialEditorWindowModule);
}
void MaterialEditorApplication::StartCommon(AZ::Entity* systemEntity)
{
{
//[GFX TODO][ATOM-408] This needs to be updated in some way to support the MaterialViewport render widget
}
Base::StartCommon(systemEntity);
}
void MaterialEditorApplication::OnMaterialEditorWindowClosing()
{
ExitMainLoop();
@@ -189,17 +179,6 @@ namespace MaterialEditor
MaterialEditor::MaterialEditorWindowFactoryRequestBus::Broadcast(
&MaterialEditor::MaterialEditorWindowFactoryRequestBus::Handler::CreateMaterialEditorWindow);
auto editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
if (editorPythonEventsInterface)
{
// The PythonSystemComponent does not call StartPython to allow for lazy python initialization, so start it here
// The PythonSystemComponent will call StopPython when it deactivates, so we do not need our own corresponding call to StopPython
editorPythonEventsInterface->StartPython();
}
// Delay execution of commands and scripts post initialization
QTimer::singleShot(0, [this]() { ProcessCommandLine(m_commandLine); });
}
void MaterialEditorApplication::Stop()
@@ -33,7 +33,6 @@ namespace MaterialEditor
// AzFramework::Application
void CreateStaticModules(AZStd::vector<AZ::Module*>& outModules) override;
const char* GetCurrentConfigurationName() const override;
void StartCommon(AZ::Entity* systemEntity) override;
void Stop() override;
private:
@@ -54,6 +53,6 @@ namespace MaterialEditor
void ProcessCommandLine(const AZ::CommandLine& commandLine) override;
void StartInternal() override;
AZStd::string_view GetBuildTargetName() override;
AZStd::string GetBuildTargetName() override;
};
} // namespace MaterialEditor
@@ -47,7 +47,7 @@ AZ_POP_DISABLE_WARNING
namespace ShaderManagementConsole
{
AZStd::string_view ShaderManagementConsoleApplication::GetBuildTargetName()
AZStd::string 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,6 @@ namespace ShaderManagementConsole
: AtomToolsApplication(argc, argv)
{
QApplication::setApplicationName("O3DE Shader Management Console");
m_targetName = GetBuildTargetName();
// The settings registry has been created at this point, so add the CMake target
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddBuildSystemTargetSpecialization(
@@ -163,51 +162,10 @@ namespace ShaderManagementConsole
void ShaderManagementConsoleApplication::StartInternal()
{
if (WasExitMainLoopRequested())
{
return;
}
m_traceLogger.WriteStartupLog("ShaderManagementConsole.log");
//[GFX TODO][ATOM-415] Try to factor out some of this stuff with AtomSampleViewerApplication
AzToolsFramework::AssetDatabase::AssetDatabaseRequestsBus::Handler::BusConnect();
AzToolsFramework::AssetBrowser::AssetDatabaseLocationNotificationBus::Broadcast(&AzToolsFramework::AssetBrowser::AssetDatabaseLocationNotifications::OnDatabaseInitialized);
AZ::Data::AssetCatalogRequestBus::Broadcast(&AZ::Data::AssetCatalogRequestBus::Events::LoadCatalog, "@assets@/assetcatalog.xml");
AZ::RPI::RPISystemInterface::Get()->InitializeSystemAssets();
LoadSettings();
LaunchDiscoveryService();
Base::StartInternal();
ShaderManagementConsoleWindowNotificationBus::Handler::BusConnect();
ShaderManagementConsole::ShaderManagementConsoleWindowRequestBus::Broadcast(&ShaderManagementConsole::ShaderManagementConsoleWindowRequestBus::Handler::CreateShaderManagementConsoleWindow);
auto editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
if (editorPythonEventsInterface)
{
// The PythonSystemComponent does not call StartPython to allow for lazy python initialization, so start it here
// The PythonSystemComponent will call StopPython when it deactivates, so we do not need our own corresponding call to StopPython
editorPythonEventsInterface->StartPython();
}
ProcessCommandLine();
}
bool ShaderManagementConsoleApplication::GetAssetDatabaseLocation(AZStd::string& result)
{
AZ::SettingsRegistryInterface* settingsRegistry = AZ::SettingsRegistry::Get();
AZ::IO::FixedMaxPath assetDatabaseSqlitePath;
if (settingsRegistry && settingsRegistry->Get(assetDatabaseSqlitePath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_CacheProjectRootFolder))
{
assetDatabaseSqlitePath /= "assetdb.sqlite";
result = AZStd::string_view(assetDatabaseSqlitePath.Native());
return true;
}
return false;
}
} // namespace ShaderManagementConsole
@@ -22,7 +22,7 @@ namespace ShaderManagementConsole
public:
AZ_TYPE_INFO(ShaderManagementConsole::ShaderManagementConsoleApplication, "{A31B1AEB-4DA3-49CD-884A-CC998FF7546F}");
using Base = AzFramework::Application;
using Base = AtomToolsFramework::AtomToolsApplication;
ShaderManagementConsoleApplication(int* argc, char*** argv);
virtual ~ShaderManagementConsoleApplication() = default;
@@ -33,11 +33,6 @@ namespace ShaderManagementConsole
const char* GetCurrentConfigurationName() const override;
private:
//////////////////////////////////////////////////////////////////////////
// AssetDatabaseRequestsBus::Handler overrides...
bool GetAssetDatabaseLocation(AZStd::string& result) override;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// ShaderManagementConsoleWindowNotificationBus::Handler overrides...
void OnShaderManagementConsoleWindowClosing() override;
@@ -55,6 +50,6 @@ namespace ShaderManagementConsole
void ProcessCommandLine();
void StartInternal() override;
AZStd::string_view GetBuildTargetName() override;
AZStd::string GetBuildTargetName() override;
};
} // namespace ShaderManagementConsole