core_bind.h 25 KB

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