Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/multiplayer/multiplayer_debugger.h
10277 views
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
protected:
81
struct BandwidthFrame {
82
uint32_t timestamp;
83
int packet_size;
84
};
85
86
int bandwidth_in_ptr = 0;
87
Vector<BandwidthFrame> bandwidth_in;
88
int bandwidth_out_ptr = 0;
89
Vector<BandwidthFrame> bandwidth_out;
90
uint64_t last_bandwidth_time = 0;
91
92
int bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer);
93
94
public:
95
void toggle(bool p_enable, const Array &p_opts);
96
void add(const Array &p_data);
97
void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time);
98
};
99
100
class RPCProfiler : public EngineProfiler {
101
private:
102
HashMap<ObjectID, RPCNodeInfo> rpc_node_data;
103
uint64_t last_profile_time = 0;
104
105
void init_node(const ObjectID p_node);
106
107
public:
108
void toggle(bool p_enable, const Array &p_opts);
109
void add(const Array &p_data);
110
void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time);
111
};
112
113
class ReplicationProfiler : public EngineProfiler {
114
private:
115
HashMap<ObjectID, SyncInfo> sync_data;
116
uint64_t last_profile_time = 0;
117
118
public:
119
void toggle(bool p_enable, const Array &p_opts);
120
void add(const Array &p_data);
121
void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time);
122
};
123
124
static Error _capture(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured);
125
126
public:
127
static void initialize();
128
static void deinitialize();
129
};
130
131