multiplayer_debugger.h 4.6 KB

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