| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
}; |