core_bind.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. /*************************************************************************/
  2. /* core_bind.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 CORE_BIND_H
  31. #define CORE_BIND_H
  32. #include "core/io/compression.h"
  33. #include "core/io/image.h"
  34. #include "core/io/resource_loader.h"
  35. #include "core/io/resource_saver.h"
  36. #include "core/os/dir_access.h"
  37. #include "core/os/file_access.h"
  38. #include "core/os/os.h"
  39. #include "core/os/semaphore.h"
  40. #include "core/os/thread.h"
  41. class _ResourceLoader : public Object {
  42. GDCLASS(_ResourceLoader, Object);
  43. protected:
  44. static void _bind_methods();
  45. static _ResourceLoader *singleton;
  46. public:
  47. enum ThreadLoadStatus {
  48. THREAD_LOAD_INVALID_RESOURCE,
  49. THREAD_LOAD_IN_PROGRESS,
  50. THREAD_LOAD_FAILED,
  51. THREAD_LOAD_LOADED
  52. };
  53. static _ResourceLoader *get_singleton() { return singleton; }
  54. Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false);
  55. ThreadLoadStatus load_threaded_get_status(const String &p_path, Array r_progress = Array());
  56. RES load_threaded_get(const String &p_path);
  57. RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false);
  58. Vector<String> get_recognized_extensions_for_type(const String &p_type);
  59. void set_abort_on_missing_resources(bool p_abort);
  60. PackedStringArray get_dependencies(const String &p_path);
  61. bool has_cached(const String &p_path);
  62. bool exists(const String &p_path, const String &p_type_hint = "");
  63. _ResourceLoader() { singleton = this; }
  64. };
  65. VARIANT_ENUM_CAST(_ResourceLoader::ThreadLoadStatus);
  66. class _ResourceSaver : public Object {
  67. GDCLASS(_ResourceSaver, Object);
  68. protected:
  69. static void _bind_methods();
  70. static _ResourceSaver *singleton;
  71. public:
  72. enum SaverFlags {
  73. FLAG_RELATIVE_PATHS = 1,
  74. FLAG_BUNDLE_RESOURCES = 2,
  75. FLAG_CHANGE_PATH = 4,
  76. FLAG_OMIT_EDITOR_PROPERTIES = 8,
  77. FLAG_SAVE_BIG_ENDIAN = 16,
  78. FLAG_COMPRESS = 32,
  79. FLAG_REPLACE_SUBRESOURCE_PATHS = 64,
  80. };
  81. static _ResourceSaver *get_singleton() { return singleton; }
  82. Error save(const String &p_path, const RES &p_resource, SaverFlags p_flags);
  83. Vector<String> get_recognized_extensions(const RES &p_resource);
  84. _ResourceSaver() { singleton = this; }
  85. };
  86. VARIANT_ENUM_CAST(_ResourceSaver::SaverFlags);
  87. class MainLoop;
  88. class _OS : public Object {
  89. GDCLASS(_OS, Object);
  90. protected:
  91. static void _bind_methods();
  92. static _OS *singleton;
  93. public:
  94. enum VideoDriver {
  95. VIDEO_DRIVER_GLES2,
  96. VIDEO_DRIVER_VULKAN,
  97. };
  98. enum Weekday {
  99. DAY_SUNDAY,
  100. DAY_MONDAY,
  101. DAY_TUESDAY,
  102. DAY_WEDNESDAY,
  103. DAY_THURSDAY,
  104. DAY_FRIDAY,
  105. DAY_SATURDAY
  106. };
  107. enum Month {
  108. // Start at 1 to follow Windows SYSTEMTIME structure
  109. // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
  110. MONTH_JANUARY = 1,
  111. MONTH_FEBRUARY,
  112. MONTH_MARCH,
  113. MONTH_APRIL,
  114. MONTH_MAY,
  115. MONTH_JUNE,
  116. MONTH_JULY,
  117. MONTH_AUGUST,
  118. MONTH_SEPTEMBER,
  119. MONTH_OCTOBER,
  120. MONTH_NOVEMBER,
  121. MONTH_DECEMBER
  122. };
  123. virtual PackedStringArray get_connected_midi_inputs();
  124. virtual void open_midi_inputs();
  125. virtual void close_midi_inputs();
  126. void set_low_processor_usage_mode(bool p_enabled);
  127. bool is_in_low_processor_usage_mode() const;
  128. void set_low_processor_usage_mode_sleep_usec(int p_usec);
  129. int get_low_processor_usage_mode_sleep_usec() const;
  130. String get_executable_path() const;
  131. int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking = true, Array p_output = Array(), bool p_read_stderr = false);
  132. Error kill(int p_pid);
  133. Error shell_open(String p_uri);
  134. int get_process_id() const;
  135. bool has_environment(const String &p_var) const;
  136. String get_environment(const String &p_var) const;
  137. String get_name() const;
  138. Vector<String> get_cmdline_args();
  139. String get_locale() const;
  140. String get_model_name() const;
  141. void dump_memory_to_file(const String &p_file);
  142. void dump_resources_to_file(const String &p_file);
  143. void print_resources_in_use(bool p_short = false);
  144. void print_all_resources(const String &p_to_file);
  145. void print_all_textures_by_size();
  146. void print_resources_by_type(const Vector<String> &p_types);
  147. bool is_debug_build() const;
  148. String get_unique_id() const;
  149. String get_keycode_string(uint32_t p_code) const;
  150. bool is_keycode_unicode(uint32_t p_unicode) const;
  151. int find_keycode_from_string(const String &p_code) const;
  152. void set_use_file_access_save_and_swap(bool p_enable);
  153. int get_exit_code() const;
  154. void set_exit_code(int p_code);
  155. Dictionary get_date(bool utc) const;
  156. Dictionary get_time(bool utc) const;
  157. Dictionary get_datetime(bool utc) const;
  158. Dictionary get_datetime_from_unix_time(int64_t unix_time_val) const;
  159. int64_t get_unix_time_from_datetime(Dictionary datetime) const;
  160. Dictionary get_time_zone_info() const;
  161. double get_unix_time() const;
  162. uint64_t get_static_memory_usage() const;
  163. uint64_t get_static_memory_peak_usage() const;
  164. void delay_usec(uint32_t p_usec) const;
  165. void delay_msec(uint32_t p_msec) const;
  166. uint32_t get_ticks_msec() const;
  167. uint64_t get_ticks_usec() const;
  168. bool can_use_threads() const;
  169. bool is_userfs_persistent() const;
  170. bool is_stdout_verbose() const;
  171. int get_processor_count() const;
  172. enum SystemDir {
  173. SYSTEM_DIR_DESKTOP,
  174. SYSTEM_DIR_DCIM,
  175. SYSTEM_DIR_DOCUMENTS,
  176. SYSTEM_DIR_DOWNLOADS,
  177. SYSTEM_DIR_MOVIES,
  178. SYSTEM_DIR_MUSIC,
  179. SYSTEM_DIR_PICTURES,
  180. SYSTEM_DIR_RINGTONES,
  181. };
  182. String get_system_dir(SystemDir p_dir) const;
  183. String get_user_data_dir() const;
  184. Error set_thread_name(const String &p_name);
  185. bool has_feature(const String &p_feature) const;
  186. bool request_permission(const String &p_name);
  187. bool request_permissions();
  188. Vector<String> get_granted_permissions() const;
  189. int get_tablet_driver_count() const;
  190. String get_tablet_driver_name(int p_driver) const;
  191. String get_current_tablet_driver() const;
  192. void set_current_tablet_driver(const String &p_driver);
  193. static _OS *get_singleton() { return singleton; }
  194. _OS() { singleton = this; }
  195. };
  196. VARIANT_ENUM_CAST(_OS::VideoDriver);
  197. VARIANT_ENUM_CAST(_OS::Weekday);
  198. VARIANT_ENUM_CAST(_OS::Month);
  199. VARIANT_ENUM_CAST(_OS::SystemDir);
  200. class _Geometry2D : public Object {
  201. GDCLASS(_Geometry2D, Object);
  202. static _Geometry2D *singleton;
  203. protected:
  204. static void _bind_methods();
  205. public:
  206. static _Geometry2D *get_singleton();
  207. Variant segment_intersects_segment(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b);
  208. Variant line_intersects_line(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b);
  209. Vector<Vector2> get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2);
  210. Vector2 get_closest_point_to_segment(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  211. Vector2 get_closest_point_to_segment_uncapped(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  212. bool point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const;
  213. bool is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius);
  214. real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius);
  215. bool is_polygon_clockwise(const Vector<Vector2> &p_polygon);
  216. bool is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon);
  217. Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon);
  218. Vector<int> triangulate_delaunay(const Vector<Vector2> &p_points);
  219. Vector<Point2> convex_hull(const Vector<Point2> &p_points);
  220. enum PolyBooleanOperation {
  221. OPERATION_UNION,
  222. OPERATION_DIFFERENCE,
  223. OPERATION_INTERSECTION,
  224. OPERATION_XOR
  225. };
  226. // 2D polygon boolean operations.
  227. Array merge_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Union (add).
  228. Array clip_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Difference (subtract).
  229. Array intersect_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Common area (multiply).
  230. Array exclude_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // All but common area (xor).
  231. // 2D polyline vs polygon operations.
  232. Array clip_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // Cut.
  233. Array intersect_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // Chop.
  234. // 2D offset polygons/polylines.
  235. enum PolyJoinType {
  236. JOIN_SQUARE,
  237. JOIN_ROUND,
  238. JOIN_MITER
  239. };
  240. enum PolyEndType {
  241. END_POLYGON,
  242. END_JOINED,
  243. END_BUTT,
  244. END_SQUARE,
  245. END_ROUND
  246. };
  247. Array offset_polygon(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE);
  248. Array offset_polyline(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE, PolyEndType p_end_type = END_SQUARE);
  249. Dictionary make_atlas(const Vector<Size2> &p_rects);
  250. _Geometry2D() { singleton = this; }
  251. };
  252. VARIANT_ENUM_CAST(_Geometry2D::PolyBooleanOperation);
  253. VARIANT_ENUM_CAST(_Geometry2D::PolyJoinType);
  254. VARIANT_ENUM_CAST(_Geometry2D::PolyEndType);
  255. class _Geometry3D : public Object {
  256. GDCLASS(_Geometry3D, Object);
  257. static _Geometry3D *singleton;
  258. protected:
  259. static void _bind_methods();
  260. public:
  261. static _Geometry3D *get_singleton();
  262. Vector<Plane> build_box_planes(const Vector3 &p_extents);
  263. Vector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z);
  264. Vector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis = Vector3::AXIS_Z);
  265. Vector<Vector3> get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2);
  266. Vector3 get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  267. Vector3 get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  268. Variant ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  269. Variant segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  270. Vector<Vector3> segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius);
  271. Vector<Vector3> segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius);
  272. Vector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes);
  273. Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
  274. _Geometry3D() { singleton = this; }
  275. };
  276. class _File : public Reference {
  277. GDCLASS(_File, Reference);
  278. FileAccess *f = nullptr;
  279. bool eswap = false;
  280. protected:
  281. static void _bind_methods();
  282. public:
  283. enum ModeFlags {
  284. READ = 1,
  285. WRITE = 2,
  286. READ_WRITE = 3,
  287. WRITE_READ = 7,
  288. };
  289. enum CompressionMode {
  290. COMPRESSION_FASTLZ = Compression::MODE_FASTLZ,
  291. COMPRESSION_DEFLATE = Compression::MODE_DEFLATE,
  292. COMPRESSION_ZSTD = Compression::MODE_ZSTD,
  293. COMPRESSION_GZIP = Compression::MODE_GZIP
  294. };
  295. Error open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key);
  296. Error open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass);
  297. Error open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode = COMPRESSION_FASTLZ);
  298. Error open(const String &p_path, ModeFlags p_mode_flags); // open a file.
  299. void close(); // Close a file.
  300. bool is_open() const; // True when file is open.
  301. String get_path() const; // Returns the path for the current open file.
  302. String get_path_absolute() const; // Returns the absolute path for the current open file.
  303. void seek(int64_t p_position); // Seek to a given position.
  304. void seek_end(int64_t p_position = 0); // Seek from the end of file.
  305. int64_t get_position() const; // Get position in the file.
  306. int64_t get_len() const; // Get size of the file.
  307. bool eof_reached() const; // Reading passed EOF.
  308. uint8_t get_8() const; // Get a byte.
  309. uint16_t get_16() const; // Get 16 bits uint.
  310. uint32_t get_32() const; // Get 32 bits uint.
  311. uint64_t get_64() const; // Get 64 bits uint.
  312. float get_float() const;
  313. double get_double() const;
  314. real_t get_real() const;
  315. Variant get_var(bool p_allow_objects = false) const;
  316. Vector<uint8_t> get_buffer(int p_length) const; // Get an array of bytes.
  317. String get_line() const;
  318. Vector<String> get_csv_line(const String &p_delim = ",") const;
  319. String get_as_text() const;
  320. String get_md5(const String &p_path) const;
  321. String get_sha256(const String &p_path) const;
  322. /* Use this for files WRITTEN in _big_ endian machines (ie, amiga/mac).
  323. * It's not about the current CPU type but file formats.
  324. * This flags get reset to false (little endian) on each open.
  325. */
  326. void set_endian_swap(bool p_swap);
  327. bool get_endian_swap();
  328. Error get_error() const; // Get last error.
  329. void store_8(uint8_t p_dest); // Store a byte.
  330. void store_16(uint16_t p_dest); // Store 16 bits uint.
  331. void store_32(uint32_t p_dest); // Store 32 bits uint.
  332. void store_64(uint64_t p_dest); // Store 64 bits uint.
  333. void store_float(float p_dest);
  334. void store_double(double p_dest);
  335. void store_real(real_t p_real);
  336. void store_string(const String &p_string);
  337. void store_line(const String &p_string);
  338. void store_csv_line(const Vector<String> &p_values, const String &p_delim = ",");
  339. virtual void store_pascal_string(const String &p_string);
  340. virtual String get_pascal_string();
  341. void store_buffer(const Vector<uint8_t> &p_buffer); // Store an array of bytes.
  342. void store_var(const Variant &p_var, bool p_full_objects = false);
  343. bool file_exists(const String &p_name) const; // Return true if a file exists.
  344. uint64_t get_modified_time(const String &p_file) const;
  345. _File() {}
  346. virtual ~_File();
  347. };
  348. VARIANT_ENUM_CAST(_File::ModeFlags);
  349. VARIANT_ENUM_CAST(_File::CompressionMode);
  350. class _Directory : public Reference {
  351. GDCLASS(_Directory, Reference);
  352. DirAccess *d;
  353. bool dir_open = false;
  354. protected:
  355. static void _bind_methods();
  356. public:
  357. Error open(const String &p_path);
  358. bool is_open() const;
  359. Error list_dir_begin(bool p_skip_navigational = false, bool p_skip_hidden = false); // This starts dir listing.
  360. String get_next();
  361. bool current_is_dir() const;
  362. void list_dir_end();
  363. int get_drive_count();
  364. String get_drive(int p_drive);
  365. int get_current_drive();
  366. Error change_dir(String p_dir); // Can be relative or absolute, return false on success.
  367. String get_current_dir(); // Return current dir location.
  368. Error make_dir(String p_dir);
  369. Error make_dir_recursive(String p_dir);
  370. bool file_exists(String p_file);
  371. bool dir_exists(String p_dir);
  372. int get_space_left();
  373. Error copy(String p_from, String p_to);
  374. Error rename(String p_from, String p_to);
  375. Error remove(String p_name);
  376. _Directory();
  377. virtual ~_Directory();
  378. private:
  379. bool _list_skip_navigational = false;
  380. bool _list_skip_hidden = false;
  381. };
  382. class _Marshalls : public Object {
  383. GDCLASS(_Marshalls, Object);
  384. static _Marshalls *singleton;
  385. protected:
  386. static void _bind_methods();
  387. public:
  388. static _Marshalls *get_singleton();
  389. String variant_to_base64(const Variant &p_var, bool p_full_objects = false);
  390. Variant base64_to_variant(const String &p_str, bool p_allow_objects = false);
  391. String raw_to_base64(const Vector<uint8_t> &p_arr);
  392. Vector<uint8_t> base64_to_raw(const String &p_str);
  393. String utf8_to_base64(const String &p_str);
  394. String base64_to_utf8(const String &p_str);
  395. _Marshalls() { singleton = this; }
  396. ~_Marshalls() { singleton = nullptr; }
  397. };
  398. class _Mutex : public Reference {
  399. GDCLASS(_Mutex, Reference);
  400. Mutex mutex;
  401. static void _bind_methods();
  402. public:
  403. void lock();
  404. Error try_lock();
  405. void unlock();
  406. };
  407. class _Semaphore : public Reference {
  408. GDCLASS(_Semaphore, Reference);
  409. Semaphore semaphore;
  410. static void _bind_methods();
  411. public:
  412. void wait();
  413. Error try_wait();
  414. void post();
  415. };
  416. class _Thread : public Reference {
  417. GDCLASS(_Thread, Reference);
  418. protected:
  419. Variant ret;
  420. Variant userdata;
  421. volatile bool active = false;
  422. Object *target_instance = nullptr;
  423. StringName target_method;
  424. Thread *thread = nullptr;
  425. static void _bind_methods();
  426. static void _start_func(void *ud);
  427. public:
  428. enum Priority {
  429. PRIORITY_LOW,
  430. PRIORITY_NORMAL,
  431. PRIORITY_HIGH,
  432. PRIORITY_MAX
  433. };
  434. Error start(Object *p_instance, const StringName &p_method, const Variant &p_userdata = Variant(), Priority p_priority = PRIORITY_NORMAL);
  435. String get_id() const;
  436. bool is_active() const;
  437. Variant wait_to_finish();
  438. _Thread() {}
  439. ~_Thread();
  440. };
  441. VARIANT_ENUM_CAST(_Thread::Priority);
  442. class _ClassDB : public Object {
  443. GDCLASS(_ClassDB, Object);
  444. protected:
  445. static void _bind_methods();
  446. public:
  447. PackedStringArray get_class_list() const;
  448. PackedStringArray get_inheriters_from_class(const StringName &p_class) const;
  449. StringName get_parent_class(const StringName &p_class) const;
  450. bool class_exists(const StringName &p_class) const;
  451. bool is_parent_class(const StringName &p_class, const StringName &p_inherits) const;
  452. bool can_instance(const StringName &p_class) const;
  453. Variant instance(const StringName &p_class) const;
  454. bool has_signal(StringName p_class, StringName p_signal) const;
  455. Dictionary get_signal(StringName p_class, StringName p_signal) const;
  456. Array get_signal_list(StringName p_class, bool p_no_inheritance = false) const;
  457. Array get_property_list(StringName p_class, bool p_no_inheritance = false) const;
  458. Variant get_property(Object *p_object, const StringName &p_property) const;
  459. Error set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const;
  460. bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false) const;
  461. Array get_method_list(StringName p_class, bool p_no_inheritance = false) const;
  462. PackedStringArray get_integer_constant_list(const StringName &p_class, bool p_no_inheritance = false) const;
  463. bool has_integer_constant(const StringName &p_class, const StringName &p_name) const;
  464. int get_integer_constant(const StringName &p_class, const StringName &p_name) const;
  465. StringName get_category(const StringName &p_node) const;
  466. bool is_class_enabled(StringName p_class) const;
  467. _ClassDB() {}
  468. ~_ClassDB() {}
  469. };
  470. class _Engine : public Object {
  471. GDCLASS(_Engine, Object);
  472. protected:
  473. static void _bind_methods();
  474. static _Engine *singleton;
  475. public:
  476. static _Engine *get_singleton() { return singleton; }
  477. void set_iterations_per_second(int p_ips);
  478. int get_iterations_per_second() const;
  479. void set_physics_jitter_fix(float p_threshold);
  480. float get_physics_jitter_fix() const;
  481. float get_physics_interpolation_fraction() const;
  482. void set_target_fps(int p_fps);
  483. int get_target_fps() const;
  484. float get_frames_per_second() const;
  485. uint64_t get_physics_frames() const;
  486. uint64_t get_process_frames() const;
  487. int get_frames_drawn();
  488. void set_time_scale(float p_scale);
  489. float get_time_scale();
  490. MainLoop *get_main_loop() const;
  491. Dictionary get_version_info() const;
  492. Dictionary get_author_info() const;
  493. Array get_copyright_info() const;
  494. Dictionary get_donor_info() const;
  495. Dictionary get_license_info() const;
  496. String get_license_text() const;
  497. bool is_in_physics_frame() const;
  498. bool has_singleton(const String &p_name) const;
  499. Object *get_singleton_object(const String &p_name) const;
  500. void set_editor_hint(bool p_enabled);
  501. bool is_editor_hint() const;
  502. _Engine() { singleton = this; }
  503. };
  504. class _JSON;
  505. class JSONParseResult : public Reference {
  506. GDCLASS(JSONParseResult, Reference);
  507. friend class _JSON;
  508. Error error;
  509. String error_string;
  510. int error_line = -1;
  511. Variant result;
  512. protected:
  513. static void _bind_methods();
  514. public:
  515. void set_error(Error p_error);
  516. Error get_error() const;
  517. void set_error_string(const String &p_error_string);
  518. String get_error_string() const;
  519. void set_error_line(int p_error_line);
  520. int get_error_line() const;
  521. void set_result(const Variant &p_result);
  522. Variant get_result() const;
  523. JSONParseResult() {}
  524. };
  525. class _JSON : public Object {
  526. GDCLASS(_JSON, Object);
  527. protected:
  528. static void _bind_methods();
  529. static _JSON *singleton;
  530. public:
  531. static _JSON *get_singleton() { return singleton; }
  532. String print(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false);
  533. Ref<JSONParseResult> parse(const String &p_json);
  534. _JSON() { singleton = this; }
  535. };
  536. class _EngineDebugger : public Object {
  537. GDCLASS(_EngineDebugger, Object);
  538. class ProfilerCallable {
  539. friend class _EngineDebugger;
  540. Callable callable_toggle;
  541. Callable callable_add;
  542. Callable callable_tick;
  543. public:
  544. ProfilerCallable() {}
  545. ProfilerCallable(const Callable &p_toggle, const Callable &p_add, const Callable &p_tick) {
  546. callable_toggle = p_toggle;
  547. callable_add = p_add;
  548. callable_tick = p_tick;
  549. }
  550. };
  551. Map<StringName, Callable> captures;
  552. Map<StringName, ProfilerCallable> profilers;
  553. protected:
  554. static void _bind_methods();
  555. static _EngineDebugger *singleton;
  556. public:
  557. static _EngineDebugger *get_singleton() { return singleton; }
  558. bool is_active();
  559. void register_profiler(const StringName &p_name, const Callable &p_toggle, const Callable &p_add, const Callable &p_tick);
  560. void unregister_profiler(const StringName &p_name);
  561. bool is_profiling(const StringName &p_name);
  562. bool has_profiler(const StringName &p_name);
  563. void profiler_add_frame_data(const StringName &p_name, const Array &p_data);
  564. void profiler_enable(const StringName &p_name, bool p_enabled, const Array &p_opts = Array());
  565. void register_message_capture(const StringName &p_name, const Callable &p_callable);
  566. void unregister_message_capture(const StringName &p_name);
  567. bool has_capture(const StringName &p_name);
  568. void send_message(const String &p_msg, const Array &p_data);
  569. static void call_toggle(void *p_user, bool p_enable, const Array &p_opts);
  570. static void call_add(void *p_user, const Array &p_data);
  571. static void call_tick(void *p_user, float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time);
  572. static Error call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured);
  573. _EngineDebugger() { singleton = this; }
  574. ~_EngineDebugger();
  575. };
  576. #endif // CORE_BIND_H