/* * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #pragma once #include #include #include #include #include #include #include #include #include #include #include namespace AzToolsFramework { namespace AssetDatabase { class AssetDatabaseConnection; } namespace AssetBrowser { class AssetBrowserModel; class SourceAssetBrowserEntry; class FolderAssetBrowserEntry; class RootAssetBrowserEntry; class AssetEntryChangeset; //! AssetBrowserComponent caches database entries /*! Database entries are cached so that they can be quickly accessed by asset browser views. Additionally this class watches for any changes to the database and updates the views if such changes happen */ class AssetBrowserComponent : public AZ::Component , public AssetBrowserComponentRequestBus::Handler , public AssetDatabaseLocationNotificationBus::Handler , public AzFramework::AssetCatalogEventBus::Handler , public AZ::TickBus::Handler , public AssetSystemBus::Handler , public AssetBrowserInteractionNotificationBus::Handler { public: AZ_COMPONENT(AssetBrowserComponent, "{4BC5F93F-2F9E-412E-B00A-396C68CFB5FB}") AssetBrowserComponent(); virtual ~AssetBrowserComponent(); ////////////////////////////////////////////////////////////////////////// // AZ::Component ////////////////////////////////////////////////////////////////////////// void Activate() override; void Deactivate() override; static void Reflect(AZ::ReflectContext* context); static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services); static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); ////////////////////////////////////////////////////////////////////////// // AssetDatabaseLocationNotificationBus ////////////////////////////////////////////////////////////////////////// void OnDatabaseInitialized() override; ////////////////////////////////////////////////////////////////////////// // AssetBrowserComponentRequestBus ////////////////////////////////////////////////////////////////////////// AssetBrowserModel* GetAssetBrowserModel() override; bool AreEntriesReady() override; void PickAssets(AssetSelectionModel& selection, QWidget* parent) override; AzQtComponents::StyledBusyLabel* GetStyledBusyLabel() override; ////////////////////////////////////////////////////////////////////////// // AssetCatalogEventBus ////////////////////////////////////////////////////////////////////////// void OnCatalogAssetAdded(const AZ::Data::AssetId& assetId) override; void OnCatalogAssetChanged(const AZ::Data::AssetId& assetId) override; void OnCatalogAssetRemoved(const AZ::Data::AssetId& assetId, const AZ::Data::AssetInfo& assetInfo) override; ////////////////////////////////////////////////////////////////////////// // TickBus ////////////////////////////////////////////////////////////////////////// void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; ////////////////////////////////////////////////////////////////////////// // AssetSystemBus ////////////////////////////////////////////////////////////////////////// void SourceFileChanged(AZStd::string relativePath, AZStd::string scanFolder, AZ::Uuid sourceUuid) override; ////////////////////////////////////////////////////////////////////////// // AssetBrowserInteractionNotificationBus SourceFileDetails GetSourceFileDetails(const char* fullSourceFileName) override; ////////////////////////////////////////////////////////////////////////// void AddFile(const AZ::s64& fileId); void RemoveFile(const AZ::s64& fileId); void PopulateAssets(); void UpdateAssets(); private: AZStd::shared_ptr m_databaseConnection; AZStd::shared_ptr m_rootEntry; AZStd::binary_semaphore m_updateWait; AZStd::thread m_thread; //! wait until database is ready bool m_dbReady; //! have entries been populated yet bool m_entriesReady = false; //! is query waiting for more update requests AZStd::atomic_bool m_waitingForMore; //! should the query thread stop AZStd::atomic_bool m_disposed; AZStd::unique_ptr m_assetBrowserModel; AZStd::shared_ptr m_changeset; AzFramework::SocketConnection::TMessageCallbackHandle m_cbHandle = 0; //! Notify to start the query thread void NotifyUpdateThread(); void HandleFileInfoNotification(const void* buffer, unsigned int bufferSize); AzQtComponents::StyledBusyLabel* m_styledBusyLabel; }; } } // namespace AssetBrowser