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
31#ifndef EDITOR_NETWORK_PROFILER_H
32#define EDITOR_NETWORK_PROFILER_H
33
34#include "../multiplayer_debugger.h"
35
36#include "scene/debugger/scene_debugger.h"
37#include "scene/gui/box_container.h"
38#include "scene/gui/button.h"
39#include "scene/gui/label.h"
40#include "scene/gui/split_container.h"
41#include "scene/gui/tree.h"
42
43class EditorNetworkProfiler : public VBoxContainer {
44 GDCLASS(EditorNetworkProfiler, VBoxContainer)
45
46public:
47 struct NodeInfo {
48 ObjectID id;
49 String type;
50 String path;
51
52 NodeInfo() {}
53 NodeInfo(const ObjectID &p_id) {
54 id = p_id;
55 path = String::num_int64(p_id);
56 }
57 };
58
59private:
60 using RPCNodeInfo = MultiplayerDebugger::RPCNodeInfo;
61 using SyncInfo = MultiplayerDebugger::SyncInfo;
62
63 bool dirty = false;
64 Timer *refresh_timer = nullptr;
65 Button *activate = nullptr;
66 Button *clear_button = nullptr;
67 Tree *counters_display = nullptr;
68 LineEdit *incoming_bandwidth_text = nullptr;
69 LineEdit *outgoing_bandwidth_text = nullptr;
70 Tree *replication_display = nullptr;
71
72 HashMap<ObjectID, RPCNodeInfo> rpc_data;
73 HashMap<ObjectID, SyncInfo> sync_data;
74 HashMap<ObjectID, NodeInfo> node_data;
75 HashSet<ObjectID> missing_node_data;
76
77 struct ThemeCache {
78 Ref<Texture2D> node_icon;
79 Ref<Texture2D> stop_icon;
80 Ref<Texture2D> play_icon;
81 Ref<Texture2D> clear_icon;
82
83 Ref<Texture2D> multiplayer_synchronizer_icon;
84 Ref<Texture2D> instance_options_icon;
85
86 Ref<Texture2D> incoming_bandwidth_icon;
87 Ref<Texture2D> outgoing_bandwidth_icon;
88
89 Color incoming_bandwidth_color;
90 Color outgoing_bandwidth_color;
91 } theme_cache;
92
93 void _activate_pressed();
94 void _clear_pressed();
95 void _refresh();
96 void _replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button);
97
98protected:
99 virtual void _update_theme_item_cache() override;
100
101 void _notification(int p_what);
102 static void _bind_methods();
103
104public:
105 void refresh_rpc_data();
106 void refresh_replication_data();
107
108 Array pop_missing_node_data();
109 void add_node_data(const NodeInfo &p_info);
110 void add_rpc_frame_data(const RPCNodeInfo &p_frame);
111 void add_sync_frame_data(const SyncInfo &p_frame);
112 void set_bandwidth(int p_incoming, int p_outgoing);
113 bool is_profiling();
114
115 EditorNetworkProfiler();
116};
117
118#endif // EDITOR_NETWORK_PROFILER_H
119