script_debugger_remote.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*************************************************************************/
  2. /* script_debugger_remote.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef SCRIPT_DEBUGGER_REMOTE_H
  30. #define SCRIPT_DEBUGGER_REMOTE_H
  31. #include "script_language.h"
  32. #include "io/stream_peer_tcp.h"
  33. #include "io/packet_peer.h"
  34. #include "list.h"
  35. class ScriptDebuggerRemote : public ScriptDebugger {
  36. struct Message {
  37. String message;
  38. Array data;
  39. };
  40. struct ProfileInfoSort {
  41. bool operator()(ScriptLanguage::ProfilingInfo*A,ScriptLanguage::ProfilingInfo*B) const {
  42. return A->total_time < B->total_time;
  43. }
  44. };
  45. Vector<ScriptLanguage::ProfilingInfo> profile_info;
  46. Vector<ScriptLanguage::ProfilingInfo*> profile_info_ptrs;
  47. Map<StringName,int> profiler_function_signature_map;
  48. float frame_time,idle_time,fixed_time,fixed_frame_time;
  49. bool profiling;
  50. int max_frame_functions;
  51. bool skip_profile_frame;
  52. bool reload_all_scripts;
  53. Ref<StreamPeerTCP> tcp_client;
  54. Ref<PacketPeerStream> packet_peer_stream;
  55. uint64_t last_perf_time;
  56. Object *performance;
  57. bool requested_quit;
  58. Mutex *mutex;
  59. struct OutputError {
  60. int hr;
  61. int min;
  62. int sec;
  63. int msec;
  64. String source_file;
  65. String source_func;
  66. int source_line;
  67. String error;
  68. String error_descr;
  69. bool warning;
  70. Array callstack;
  71. };
  72. List<String> output_strings;
  73. List<Message> messages;
  74. List<OutputError> errors;
  75. int max_cps;
  76. int char_count;
  77. uint64_t last_msec;
  78. uint64_t msec_count;
  79. bool locking; //hack to avoid a deadloop
  80. static void _print_handler(void *p_this,const String& p_string);
  81. PrintHandlerList phl;
  82. void _get_output();
  83. void _poll_events();
  84. uint32_t poll_every;
  85. bool _parse_live_edit(const Array &p_command);
  86. RequestSceneTreeMessageFunc request_scene_tree;
  87. void *request_scene_tree_ud;
  88. void _set_object_property(ObjectID p_id, const String& p_property, const Variant& p_value);
  89. void _send_object_id(ObjectID p_id);
  90. void _send_video_memory();
  91. LiveEditFuncs *live_edit_funcs;
  92. ErrorHandlerList eh;
  93. static void _err_handler(void*,const char*,const char*,int p_line,const char *, const char *,ErrorHandlerType p_type);
  94. void _send_profiling_data(bool p_for_frame);
  95. struct FrameData {
  96. StringName name;
  97. Array data;
  98. };
  99. Vector<FrameData> profile_frame_data;
  100. public:
  101. struct ResourceUsage {
  102. String path;
  103. String format;
  104. String type;
  105. RID id;
  106. int vram;
  107. bool operator<(const ResourceUsage& p_img) const { return vram==p_img.vram ? id<p_img.id : vram > p_img.vram; }
  108. };
  109. typedef void (*ResourceUsageFunc)(List<ResourceUsage>*);
  110. static ResourceUsageFunc resource_usage_func;
  111. Error connect_to_host(const String& p_host,uint16_t p_port);
  112. virtual void debug(ScriptLanguage *p_script,bool p_can_continue=true);
  113. virtual void idle_poll();
  114. virtual void line_poll();
  115. virtual bool is_remote() const { return true; }
  116. virtual void request_quit();
  117. virtual void send_message(const String& p_message, const Array& p_args);
  118. virtual void set_request_scene_tree_message_func(RequestSceneTreeMessageFunc p_func, void *p_udata);
  119. virtual void set_live_edit_funcs(LiveEditFuncs *p_funcs);
  120. virtual bool is_profiling() const;
  121. virtual void add_profiling_frame_data(const StringName& p_name,const Array& p_data);
  122. virtual void profiling_start();
  123. virtual void profiling_end();
  124. virtual void profiling_set_frame_times(float p_frame_time,float p_idle_time,float p_fixed_time,float p_fixed_frame_time);
  125. ScriptDebuggerRemote();
  126. ~ScriptDebuggerRemote();
  127. };
  128. #endif // SCRIPT_DEBUGGER_REMOTE_H