core_bind.h 24 KB

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