core_bind.h 24 KB

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