core_bind.h 24 KB

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