Added a CriticalAssetsCompiled Lifecycle event (#6469)
The CriticalAssetsCompiled event can be handled to detect when the
AssetProcessor has finished processing Critical Assets
Also with the new event, an audit has been performed over all the
locations where the AssetCatalogEventBus OnCatalogLoaded event was being
handle to make sure it was the proper event to use.
If the handler was actually examing the enumerating over the full
catalog or querying all assets within the catalog, then it was a proper
use.
For handlers that were interested in a particular asset it was not
Moreover added implementations of `OnCatalogAssetChanged` and
`OnCatalogAssetAdded` to the FileTagComponent and the MaterialViewportComponent.
Any applications which uses the AtomToolsApplication
class(MaterialEditor, AtomSampleViewerStandalone,
ShaderMangementConsole) now signals a "CriticalAssetsCompiled" lifecycle
event as well as loads the "assetcatalog.xml" if it exists.
The Launcher application signals the "CrticalAssetsCompiled" event and
reloads the "assetcatalog.xml" for the ${project}.GameLauncher and
${project}.ServerLauncher in Launcher.cpp
Finally the Editor signals the "CriticalAssetsCompiled" and reloads the
"assetcatalog.xml" in CryEdit.cpp
resolves #6093
Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
df7a2fbd9d
commit
18ea4ba6a8
@@ -97,19 +97,38 @@ namespace AzFramework
|
||||
AZStd::vector<AZStd::string> registeredAssetPaths;
|
||||
AZ::Data::AssetCatalogRequestBus::BroadcastResult(registeredAssetPaths, &AZ::Data::AssetCatalogRequests::GetRegisteredAssetPaths);
|
||||
|
||||
const char* dependencyXmlPattern = "*_dependencies.xml";
|
||||
constexpr const char* dependencyXmlPattern = "_dependencies.xml";
|
||||
for (const AZStd::string& assetPath : registeredAssetPaths)
|
||||
{
|
||||
if (!AZStd::wildcard_match(dependencyXmlPattern, assetPath.c_str()))
|
||||
if (assetPath.ends_with(dependencyXmlPattern))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!m_excludeFileQueryManager.get()->LoadEngineDependencies(assetPath))
|
||||
{
|
||||
AZ_Error("ExcludeFileComponent", false, "Failed to add assets referenced from %s to the blocked list", assetPath.c_str());
|
||||
AZ_VerifyError("ExcludeFileComponent", m_excludeFileQueryManager.get()->LoadEngineDependencies(assetPath),
|
||||
"Failed to add assets referenced from %s to the blocked list", assetPath.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExcludeFileComponent::OnCatalogAssetChanged(const AZ::Data::AssetId& assetId)
|
||||
{
|
||||
// Reload any modified "<name>_dependencies.xml" files
|
||||
AZ::IO::Path assetPath;
|
||||
auto GetAssetPath = [&assetId, &assetPath](AZ::Data::AssetCatalogRequests* assetCatalogRequests)
|
||||
{
|
||||
assetPath = assetCatalogRequests->GetAssetPathById(assetId);
|
||||
};
|
||||
|
||||
AZ::Data::AssetCatalogRequestBus::Broadcast(AZStd::move(GetAssetPath));
|
||||
constexpr const char* dependencyXmlPattern = "_dependencies.xml";
|
||||
if (assetPath.Native().ends_with(dependencyXmlPattern))
|
||||
{
|
||||
AZ_VerifyError("ExcludeFileComponent", m_excludeFileQueryManager.get()->LoadEngineDependencies(assetPath.Native()),
|
||||
"Failed to add assets referenced from %s to the blocked list", assetPath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void ExcludeFileComponent::OnCatalogAssetAdded(const AZ::Data::AssetId& assetId)
|
||||
{
|
||||
OnCatalogAssetChanged(assetId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace AzFramework
|
||||
void Deactivate() override;
|
||||
|
||||
void OnCatalogLoaded(const char* catalogFile) override;
|
||||
void OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) override;
|
||||
void OnCatalogAssetAdded(const AZ::Data::AssetId& assetId) override;
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <AzCore/Asset/AssetManager.h>
|
||||
#include <AzCore/Asset/AssetSerializer.h>
|
||||
#include <AzCore/Component/ComponentApplicationLifecycle.h>
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzFramework/Spawnable/SpawnableMetaData.h>
|
||||
@@ -61,15 +62,6 @@ namespace AzFramework
|
||||
m_entitiesManager.ProcessQueue(SpawnableEntitiesManager::CommandQueuePriority::High);
|
||||
}
|
||||
|
||||
void SpawnableSystemComponent::OnCatalogLoaded([[maybe_unused]] const char* catalogFile)
|
||||
{
|
||||
if (!m_catalogAvailable)
|
||||
{
|
||||
m_catalogAvailable = true;
|
||||
LoadRootSpawnableFromSettingsRegistry();
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t SpawnableSystemComponent::AssignRootSpawnable(AZ::Data::Asset<Spawnable> rootSpawnable)
|
||||
{
|
||||
uint32_t generation = 0;
|
||||
@@ -157,20 +149,29 @@ namespace AzFramework
|
||||
// Register with AssetDatabase
|
||||
AZ_Assert(AZ::Data::AssetManager::IsReady(), "Spawnables can't be registered because the Asset Manager is not ready yet.");
|
||||
AZ::Data::AssetManager::Instance().RegisterHandler(&m_assetHandler, AZ::AzTypeInfo<Spawnable>::Uuid());
|
||||
|
||||
|
||||
// Register with AssetCatalog
|
||||
AZ::Data::AssetCatalogRequestBus::Broadcast(
|
||||
&AZ::Data::AssetCatalogRequestBus::Events::EnableCatalogForAsset, AZ::AzTypeInfo<Spawnable>::Uuid());
|
||||
AZ::Data::AssetCatalogRequestBus::Broadcast(
|
||||
&AZ::Data::AssetCatalogRequestBus::Events::AddExtension, Spawnable::FileExtension);
|
||||
|
||||
AssetCatalogEventBus::Handler::BusConnect();
|
||||
// Register for the CriticalAssetsCompiled lifecycle event to trigger the loading of the root spawnable
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
AZ_Assert(settingsRegistry, "Unable to change root spawnable callback because Settings Registry is not available.");
|
||||
|
||||
auto LifecycleCallback = [this](AZStd::string_view, AZ::SettingsRegistryInterface::Type)
|
||||
{
|
||||
LoadRootSpawnableFromSettingsRegistry();
|
||||
};
|
||||
AZ::ComponentApplicationLifecycle::RegisterHandler(*settingsRegistry, m_criticalAssetsHandler,
|
||||
AZStd::move(LifecycleCallback), "CriticalAssetsCompiled");
|
||||
|
||||
|
||||
RootSpawnableNotificationBus::Handler::BusConnect();
|
||||
AZ::TickBus::Handler::BusConnect();
|
||||
|
||||
auto registry = AZ::SettingsRegistry::Get();
|
||||
AZ_Assert(registry, "Unable to change root spawnable callback because Settings Registry is not available.");
|
||||
m_registryChangeHandler = registry->RegisterNotifier([this](AZStd::string_view path, AZ::SettingsRegistryInterface::Type /*type*/)
|
||||
m_registryChangeHandler = settingsRegistry->RegisterNotifier([this](AZStd::string_view path, AZ::SettingsRegistryInterface::Type /*type*/)
|
||||
{
|
||||
if (path.starts_with(RootSpawnableRegistryKey))
|
||||
{
|
||||
@@ -187,13 +188,14 @@ namespace AzFramework
|
||||
|
||||
AZ::TickBus::Handler::BusDisconnect();
|
||||
RootSpawnableNotificationBus::Handler::BusDisconnect();
|
||||
AssetCatalogEventBus::Handler::BusDisconnect();
|
||||
// Unregister Lifecycle event handler
|
||||
m_criticalAssetsHandler = {};
|
||||
|
||||
if (m_catalogAvailable)
|
||||
if (m_rootSpawnableId.IsValid())
|
||||
{
|
||||
ReleaseRootSpawnable();
|
||||
|
||||
// The SpawnalbleSystemComponent needs to guarantee there's no more processing left to do by the
|
||||
// The SpawnableSystemComponent needs to guarantee there's no more processing left to do by the
|
||||
// entity manager before it can safely destroy it on shutdown, but also to make sure that are no
|
||||
// more calls to the callback registered to the root spawnable as that accesses this component.
|
||||
m_rootSpawnableContainer.Clear();
|
||||
@@ -210,8 +212,6 @@ namespace AzFramework
|
||||
|
||||
void SpawnableSystemComponent::LoadRootSpawnableFromSettingsRegistry()
|
||||
{
|
||||
AZ_Assert(m_catalogAvailable, "Attempting to load root spawnable while the catalog is not available yet.");
|
||||
|
||||
auto registry = AZ::SettingsRegistry::Get();
|
||||
AZ_Assert(registry, "Unable to check for root spawnable because the Settings Registry is not available.");
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <AzCore/Component/TickBus.h>
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
#include <AzCore/std/parallel/atomic.h>
|
||||
#include <AzFramework/Asset/AssetCatalogBus.h>
|
||||
#include <AzFramework/Spawnable/RootSpawnableInterface.h>
|
||||
#include <AzFramework/Spawnable/Spawnable.h>
|
||||
#include <AzFramework/Spawnable/SpawnableAssetHandler.h>
|
||||
@@ -25,7 +24,6 @@ namespace AzFramework
|
||||
: public AZ::Component
|
||||
, public AZ::TickBus::Handler
|
||||
, public AZ::SystemTickBus::Handler
|
||||
, public AssetCatalogEventBus::Handler
|
||||
, public RootSpawnableInterface::Registrar
|
||||
, public RootSpawnableNotificationBus::Handler
|
||||
{
|
||||
@@ -63,12 +61,6 @@ namespace AzFramework
|
||||
|
||||
void OnSystemTick() override;
|
||||
|
||||
//
|
||||
// AssetCatalogEventBus
|
||||
//
|
||||
|
||||
void OnCatalogLoaded(const char* catalogFile) override;
|
||||
|
||||
//
|
||||
// RootSpawnableInterface
|
||||
//
|
||||
@@ -97,6 +89,6 @@ namespace AzFramework
|
||||
AZ::SettingsRegistryInterface::NotifyEventHandler m_registryChangeHandler;
|
||||
|
||||
AZ::Data::AssetId m_rootSpawnableId;
|
||||
bool m_catalogAvailable{ false };
|
||||
AZ::SettingsRegistryInterface::NotifyEventHandler m_criticalAssetsHandler;
|
||||
};
|
||||
} // namespace AzFramework
|
||||
|
||||
Reference in New Issue
Block a user