AssetSystemDebugComponent.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  11. #include <AzCore/Asset/AssetCommon.h>
  12. #include <AzCore/Asset/AssetManager.h>
  13. namespace LmbrCentral
  14. {
  15. class AssetSystemDebugComponent
  16. : public AZ::Component
  17. , AzFramework::DebugDisplayEventBus::Handler
  18. , AZ::Data::IDebugAssetEvent
  19. {
  20. public:
  21. AZ_COMPONENT(AssetSystemDebugComponent, "{2DB77E66-67A5-4E56-B2FF-75C718B182A1}", AZ::Component);
  22. AssetSystemDebugComponent() = default;
  23. protected:
  24. //////////////////////////////////////////////////////////////////////////
  25. // Component base
  26. void Activate() override;
  27. void Deactivate() override;
  28. //////////////////////////////////////////////////////////////////////////
  29. //////////////////////////////////////////////////////////////////////////
  30. // DebugDisplayEventBus
  31. void DrawGlobalDebugInfo() override;
  32. //////////////////////////////////////////////////////////////////////////
  33. //////////////////////////////////////////////////////////////////////////
  34. // IDebugAssetEvent
  35. void AssetStatusUpdate(AZ::Data::AssetId id, AZ::Data::AssetData::AssetStatus status) override;
  36. void ReleaseAsset(AZ::Data::AssetId id) override;
  37. //////////////////////////////////////////////////////////////////////////
  38. /// \ref ComponentDescriptor::GetProvidedServices
  39. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  40. /// \ref ComponentDescriptor::GetIncompatibleServices
  41. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  42. /// \ref ComponentDescriptor::Reflect
  43. static void Reflect(AZ::ReflectContext* reflection);
  44. struct EventInfo
  45. {
  46. AZ::Data::AssetId m_id;
  47. AZ::Data::AssetData::AssetStatus m_status;
  48. AZStd::chrono::steady_clock::time_point m_loadStart;
  49. AZStd::chrono::steady_clock::time_point m_loadFinish;
  50. };
  51. struct EventSortOldest
  52. {
  53. bool operator()(const EventInfo* a, const EventInfo* b) const
  54. {
  55. return a->m_loadStart > b->m_loadStart;
  56. }
  57. };
  58. struct EventSortMostRecentCompleted
  59. {
  60. bool operator()(const EventInfo* a, const EventInfo* b)
  61. {
  62. return a->m_loadFinish > b->m_loadFinish;
  63. }
  64. };
  65. AZStd::recursive_mutex m_eventMutex;
  66. AZStd::unordered_map<AZ::Data::AssetId, EventInfo> m_events;
  67. AZStd::set<EventInfo*, EventSortOldest> m_oldestActive;
  68. AZStd::set<EventInfo*, EventSortMostRecentCompleted> m_recentlyCompleted;
  69. };
  70. }