Debian Codegraph @

modules/multiplayer/multiplayer_debugger.h

raw symbols SCIP
1 /**************************************************************************/
2 /* multiplayer_debugger.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 #pragma once
32
33 #include "core/debugger/engine_profiler.h"
34
35 class MultiplayerSynchronizer;
36
37 class MultiplayerDebugger {
38 public:
39 struct RPCNodeInfo {
40 ObjectID node;
41 String node_path;
42 int incoming_rpc = 0;
43 int incoming_size = 0;
44 int outgoing_rpc = 0;
45 int outgoing_size = 0;
46 };
47
48 struct RPCFrame {
49 Vector<RPCNodeInfo> infos;
50
51 Array serialize();
52 bool deserialize(const Array &p_arr);
53 };
54
55 struct SyncInfo {
56 ObjectID synchronizer;
57 ObjectID config;
58 ObjectID root_node;
59 int incoming_syncs = 0;
60 int incoming_size = 0;
61 int outgoing_syncs = 0;
62 int outgoing_size = 0;
63
64 void write_to_array(Array &r_arr) const;
65 bool read_from_array(const Array &p_arr, int p_offset);
66
67 SyncInfo() {}
68 SyncInfo(MultiplayerSynchronizer *p_sync);
69 };
70
71 struct ReplicationFrame {
72 HashMap<ObjectID, SyncInfo> infos;
73
74 Array serialize();
75 bool deserialize(const Array &p_arr);
76 };
77
78 private:
79 class BandwidthProfiler : public EngineProfiler {
80 GDSOFTCLASS(BandwidthProfiler, EngineProfiler);
81
82 protected:
83 struct BandwidthFrame {
84 uint32_t timestamp;
85 int packet_size;
86 };
87
88 int bandwidth_in_ptr = 0;
89 Vector<BandwidthFrame> bandwidth_in;
90 int bandwidth_out_ptr = 0;
91 Vector<BandwidthFrame> bandwidth_out;
92 uint64_t last_bandwidth_time = 0;
93
94 int bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer);
95
96 public:
97 void toggle(bool p_enable, const Array &p_opts) override;
98 void add(const Array &p_data) override;
99 void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time) override;
100 };
101
102 class RPCProfiler : public EngineProfiler {
103 GDSOFTCLASS(RPCProfiler, EngineProfiler);
104
105 private:
106 HashMap<ObjectID, RPCNodeInfo> rpc_node_data;
107 uint64_t last_profile_time = 0;
108
109 void init_node(const ObjectID p_node);
110
111 public:
112 void toggle(bool p_enable, const Array &p_opts) override;
113 void add(const Array &p_data) override;
114 void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time) override;
115 };
116
117 class ReplicationProfiler : public EngineProfiler {
118 GDSOFTCLASS(ReplicationProfiler, EngineProfiler);
119
120 private:
121 HashMap<ObjectID, SyncInfo> sync_data;
122 uint64_t last_profile_time = 0;
123
124 public:
125 void toggle(bool p_enable, const Array &p_opts) override;
126 void add(const Array &p_data) override;
127 void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time) override;
128 };
129
130 static Error _capture(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured);
131
132 public:
133 static void initialize();
134 static void deinitialize();
135 };