2
0

core_bind.h 24 KB

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