multiplayer_debugger.h 4.6 KB

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