MultiplayerDebugPerEntityReporter.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "MultiplayerDebugByteReporter.h"
  10. #include <AzCore/Component/EntityId.h>
  11. #include <AzCore/EBus/ScheduledEvent.h>
  12. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  13. #include <Multiplayer/MultiplayerStats.h>
  14. #include <Multiplayer/MultiplayerTypes.h>
  15. namespace Multiplayer
  16. {
  17. /**
  18. * \brief Multiplayer traffic live analysis tool via ImGui.
  19. */
  20. class MultiplayerDebugPerEntityReporter
  21. {
  22. public:
  23. MultiplayerDebugPerEntityReporter();
  24. //! main update loop
  25. void OnImGuiUpdate();
  26. //! Event handlers
  27. // @{
  28. void RecordEntitySerializeStart(AzNetworking::SerializerMode mode, AZ::EntityId entityId, const char* entityName);
  29. void RecordComponentSerializeEnd(AzNetworking::SerializerMode mode, NetComponentId netComponentId);
  30. void RecordEntitySerializeStop(AzNetworking::SerializerMode mode, AZ::EntityId entityId, const char* entityName);
  31. void RecordPropertySent(NetComponentId netComponentId, PropertyIndex propertyId, uint32_t totalBytes);
  32. void RecordPropertyReceived(NetComponentId netComponentId, PropertyIndex propertyId, uint32_t totalBytes);
  33. void RecordRpcSent(AZ::EntityId entityId, const char* entityName, NetComponentId netComponentId, RpcIndex rpcId, uint32_t totalBytes);
  34. void RecordRpcReceived(AZ::EntityId entityId, const char* entityName, NetComponentId netComponentId, RpcIndex rpcId, uint32_t totalBytes);
  35. // }@
  36. //! Draws bandwidth text over entities
  37. void UpdateDebugOverlay();
  38. private:
  39. AZ::ScheduledEvent m_updateDebugOverlay;
  40. MultiplayerStats::EventHandlers m_eventHandlers;
  41. AZStd::map<AZ::EntityId, MultiplayerDebugEntityReporter> m_sendingEntityReports{};
  42. MultiplayerDebugEntityReporter m_currentSendingEntityReport;
  43. AZStd::map<AZ::EntityId, MultiplayerDebugEntityReporter> m_receivingEntityReports{};
  44. MultiplayerDebugEntityReporter m_currentReceivingEntityReport;
  45. [[maybe_unused]] float m_replicatedStateKbpsWarn = 10.f;
  46. [[maybe_unused]] float m_replicatedStateMaxSizeWarn = 30.f;
  47. char m_statusBuffer[100] = {};
  48. struct NetworkEntityTraffic
  49. {
  50. const char* m_name = nullptr;
  51. float m_up = 0.f;
  52. float m_down = 0.f;
  53. };
  54. AZStd::unordered_map<AZ::EntityId, NetworkEntityTraffic> m_networkEntitiesTraffic;
  55. AzFramework::DebugDisplayRequests* m_debugDisplay = nullptr;
  56. };
  57. }