editor_network_profiler.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**************************************************************************/
  2. /* editor_network_profiler.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef EDITOR_NETWORK_PROFILER_H
  31. #define EDITOR_NETWORK_PROFILER_H
  32. #include "../multiplayer_debugger.h"
  33. #include "scene/debugger/scene_debugger.h"
  34. #include "scene/gui/box_container.h"
  35. #include "scene/gui/button.h"
  36. #include "scene/gui/label.h"
  37. #include "scene/gui/split_container.h"
  38. #include "scene/gui/tree.h"
  39. class EditorNetworkProfiler : public VBoxContainer {
  40. GDCLASS(EditorNetworkProfiler, VBoxContainer)
  41. public:
  42. struct NodeInfo {
  43. ObjectID id;
  44. String type;
  45. String path;
  46. NodeInfo() {}
  47. NodeInfo(const ObjectID &p_id) {
  48. id = p_id;
  49. path = String::num_int64(p_id);
  50. }
  51. };
  52. private:
  53. using RPCNodeInfo = MultiplayerDebugger::RPCNodeInfo;
  54. using SyncInfo = MultiplayerDebugger::SyncInfo;
  55. bool dirty = false;
  56. Timer *refresh_timer = nullptr;
  57. Button *activate = nullptr;
  58. Button *clear_button = nullptr;
  59. Tree *counters_display = nullptr;
  60. LineEdit *incoming_bandwidth_text = nullptr;
  61. LineEdit *outgoing_bandwidth_text = nullptr;
  62. Tree *replication_display = nullptr;
  63. HashMap<ObjectID, RPCNodeInfo> rpc_data;
  64. HashMap<ObjectID, SyncInfo> sync_data;
  65. HashMap<ObjectID, NodeInfo> node_data;
  66. HashSet<ObjectID> missing_node_data;
  67. struct ThemeCache {
  68. Ref<Texture2D> node_icon;
  69. Ref<Texture2D> stop_icon;
  70. Ref<Texture2D> play_icon;
  71. Ref<Texture2D> clear_icon;
  72. Ref<Texture2D> multiplayer_synchronizer_icon;
  73. Ref<Texture2D> instance_options_icon;
  74. Ref<Texture2D> incoming_bandwidth_icon;
  75. Ref<Texture2D> outgoing_bandwidth_icon;
  76. Color incoming_bandwidth_color;
  77. Color outgoing_bandwidth_color;
  78. } theme_cache;
  79. void _activate_pressed();
  80. void _clear_pressed();
  81. void _autostart_toggled(bool p_toggled_on);
  82. void _refresh();
  83. void _update_button_text();
  84. void _replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button);
  85. protected:
  86. virtual void _update_theme_item_cache() override;
  87. void _notification(int p_what);
  88. static void _bind_methods();
  89. public:
  90. void refresh_rpc_data();
  91. void refresh_replication_data();
  92. Array pop_missing_node_data();
  93. void add_node_data(const NodeInfo &p_info);
  94. void add_rpc_frame_data(const RPCNodeInfo &p_frame);
  95. void add_sync_frame_data(const SyncInfo &p_frame);
  96. void set_bandwidth(int p_incoming, int p_outgoing);
  97. bool is_profiling();
  98. void set_profiling(bool p_pressed);
  99. void started();
  100. void stopped();
  101. EditorNetworkProfiler();
  102. };
  103. #endif // EDITOR_NETWORK_PROFILER_H