core_bind.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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/image.h"
  33. #include "core/io/compression.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/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. static _ResourceLoader *get_singleton() { return singleton; }
  49. Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = "");
  50. RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false);
  51. PoolVector<String> get_recognized_extensions_for_type(const String &p_type);
  52. void set_abort_on_missing_resources(bool p_abort);
  53. PoolStringArray get_dependencies(const String &p_path);
  54. #ifndef DISABLE_DEPRECATED
  55. bool has(const String &p_path);
  56. #endif // DISABLE_DEPRECATED
  57. bool has_cached(const String &p_path);
  58. bool exists(const String &p_path, const String &p_type_hint = "");
  59. _ResourceLoader();
  60. };
  61. class _ResourceSaver : public Object {
  62. GDCLASS(_ResourceSaver, Object);
  63. protected:
  64. static void _bind_methods();
  65. static _ResourceSaver *singleton;
  66. public:
  67. enum SaverFlags {
  68. FLAG_RELATIVE_PATHS = 1,
  69. FLAG_BUNDLE_RESOURCES = 2,
  70. FLAG_CHANGE_PATH = 4,
  71. FLAG_OMIT_EDITOR_PROPERTIES = 8,
  72. FLAG_SAVE_BIG_ENDIAN = 16,
  73. FLAG_COMPRESS = 32,
  74. FLAG_REPLACE_SUBRESOURCE_PATHS = 64,
  75. };
  76. static _ResourceSaver *get_singleton() { return singleton; }
  77. Error save(const String &p_path, const RES &p_resource, SaverFlags p_flags);
  78. PoolVector<String> get_recognized_extensions(const RES &p_resource);
  79. _ResourceSaver();
  80. };
  81. VARIANT_ENUM_CAST(_ResourceSaver::SaverFlags);
  82. class MainLoop;
  83. class _OS : public Object {
  84. GDCLASS(_OS, Object);
  85. protected:
  86. static void _bind_methods();
  87. static _OS *singleton;
  88. public:
  89. enum VideoDriver {
  90. VIDEO_DRIVER_GLES3,
  91. VIDEO_DRIVER_GLES2,
  92. };
  93. enum PowerState {
  94. POWERSTATE_UNKNOWN, // Cannot determine power status.
  95. POWERSTATE_ON_BATTERY, // Not plugged in, running on the battery.
  96. POWERSTATE_NO_BATTERY, // Plugged in, no battery available.
  97. POWERSTATE_CHARGING, // Plugged in, charging battery.
  98. POWERSTATE_CHARGED // Plugged in, battery charged.
  99. };
  100. enum Weekday {
  101. DAY_SUNDAY,
  102. DAY_MONDAY,
  103. DAY_TUESDAY,
  104. DAY_WEDNESDAY,
  105. DAY_THURSDAY,
  106. DAY_FRIDAY,
  107. DAY_SATURDAY
  108. };
  109. enum Month {
  110. // Start at 1 to follow Windows SYSTEMTIME structure
  111. // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
  112. MONTH_JANUARY = 1,
  113. MONTH_FEBRUARY,
  114. MONTH_MARCH,
  115. MONTH_APRIL,
  116. MONTH_MAY,
  117. MONTH_JUNE,
  118. MONTH_JULY,
  119. MONTH_AUGUST,
  120. MONTH_SEPTEMBER,
  121. MONTH_OCTOBER,
  122. MONTH_NOVEMBER,
  123. MONTH_DECEMBER
  124. };
  125. enum HandleType {
  126. APPLICATION_HANDLE, // HINSTANCE, NSApplication*, UIApplication*, JNIEnv* ...
  127. DISPLAY_HANDLE, // X11::Display* ...
  128. WINDOW_HANDLE, // HWND, X11::Window*, NSWindow*, UIWindow*, Android activity ...
  129. WINDOW_VIEW, // HDC, NSView*, UIView*, Android surface ...
  130. OPENGL_CONTEXT, // HGLRC, X11::GLXContext, NSOpenGLContext*, EGLContext* ...
  131. };
  132. void global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta);
  133. void global_menu_add_separator(const String &p_menu);
  134. void global_menu_remove_item(const String &p_menu, int p_idx);
  135. void global_menu_clear(const String &p_menu);
  136. Point2 get_mouse_position() const;
  137. void set_window_title(const String &p_title);
  138. void set_window_mouse_passthrough(const PoolVector2Array &p_region);
  139. int get_mouse_button_state() const;
  140. void set_clipboard(const String &p_text);
  141. String get_clipboard() const;
  142. void set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen = 0);
  143. Size2 get_video_mode(int p_screen = 0) const;
  144. bool is_video_mode_fullscreen(int p_screen = 0) const;
  145. bool is_video_mode_resizable(int p_screen = 0) const;
  146. Array get_fullscreen_mode_list(int p_screen = 0) const;
  147. virtual int get_video_driver_count() const;
  148. virtual String get_video_driver_name(VideoDriver p_driver) const;
  149. virtual VideoDriver get_current_video_driver() const;
  150. virtual int get_audio_driver_count() const;
  151. virtual String get_audio_driver_name(int p_driver) const;
  152. virtual PoolStringArray get_connected_midi_inputs();
  153. virtual void open_midi_inputs();
  154. virtual void close_midi_inputs();
  155. virtual int get_screen_count() const;
  156. virtual int get_current_screen() const;
  157. virtual void set_current_screen(int p_screen);
  158. virtual Point2 get_screen_position(int p_screen = -1) const;
  159. virtual Size2 get_screen_size(int p_screen = -1) const;
  160. virtual int get_screen_dpi(int p_screen = -1) const;
  161. virtual float get_screen_scale(int p_screen = -1) const;
  162. virtual float get_screen_max_scale() const;
  163. virtual Point2 get_window_position() const;
  164. virtual void set_window_position(const Point2 &p_position);
  165. virtual Size2 get_max_window_size() const;
  166. virtual Size2 get_min_window_size() const;
  167. virtual Size2 get_window_size() const;
  168. virtual Size2 get_real_window_size() const;
  169. virtual Rect2 get_window_safe_area() const;
  170. virtual void set_max_window_size(const Size2 &p_size);
  171. virtual void set_min_window_size(const Size2 &p_size);
  172. virtual void set_window_size(const Size2 &p_size);
  173. virtual void set_window_fullscreen(bool p_enabled);
  174. virtual bool is_window_fullscreen() const;
  175. virtual void set_window_resizable(bool p_enabled);
  176. virtual bool is_window_resizable() const;
  177. virtual void set_window_minimized(bool p_enabled);
  178. virtual bool is_window_minimized() const;
  179. virtual void set_window_maximized(bool p_enabled);
  180. virtual bool is_window_maximized() const;
  181. virtual void set_window_always_on_top(bool p_enabled);
  182. virtual bool is_window_always_on_top() const;
  183. virtual bool is_window_focused() const;
  184. virtual void request_attention();
  185. virtual void center_window();
  186. virtual void move_window_to_foreground();
  187. virtual int64_t get_native_handle(HandleType p_handle_type);
  188. virtual void set_borderless_window(bool p_borderless);
  189. virtual bool get_borderless_window() const;
  190. virtual bool get_window_per_pixel_transparency_enabled() const;
  191. virtual void set_window_per_pixel_transparency_enabled(bool p_enabled);
  192. virtual void set_ime_active(const bool p_active);
  193. virtual void set_ime_position(const Point2 &p_pos);
  194. virtual Point2 get_ime_selection() const;
  195. virtual String get_ime_text() const;
  196. Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  197. bool native_video_is_playing();
  198. void native_video_pause();
  199. void native_video_unpause();
  200. void native_video_stop();
  201. void set_low_processor_usage_mode(bool p_enabled);
  202. bool is_in_low_processor_usage_mode() const;
  203. void set_low_processor_usage_mode_sleep_usec(int p_usec);
  204. int get_low_processor_usage_mode_sleep_usec() const;
  205. String get_executable_path() const;
  206. int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking = true, Array p_output = Array(), bool p_read_stderr = false);
  207. Error kill(int p_pid);
  208. Error shell_open(String p_uri);
  209. int get_process_id() const;
  210. bool has_environment(const String &p_var) const;
  211. String get_environment(const String &p_var) const;
  212. bool set_environment(const String &p_var, const String &p_value) const;
  213. String get_name() const;
  214. Vector<String> get_cmdline_args();
  215. String get_locale() const;
  216. String get_locale_language() const;
  217. String get_latin_keyboard_variant() const;
  218. int keyboard_get_layout_count() const;
  219. int keyboard_get_current_layout() const;
  220. void keyboard_set_current_layout(int p_index);
  221. String keyboard_get_layout_language(int p_index) const;
  222. String keyboard_get_layout_name(int p_index) const;
  223. String get_model_name() const;
  224. void dump_memory_to_file(const String &p_file);
  225. void dump_resources_to_file(const String &p_file);
  226. bool has_virtual_keyboard() const;
  227. void show_virtual_keyboard(const String &p_existing_text = "", bool p_multiline = false);
  228. void hide_virtual_keyboard();
  229. int get_virtual_keyboard_height();
  230. void print_resources_in_use(bool p_short = false);
  231. void print_all_resources(const String &p_to_file);
  232. void print_all_textures_by_size();
  233. void print_resources_by_type(const Vector<String> &p_types);
  234. bool has_touchscreen_ui_hint() const;
  235. bool is_debug_build() const;
  236. String get_unique_id() const;
  237. String get_scancode_string(uint32_t p_code) const;
  238. bool is_scancode_unicode(uint32_t p_unicode) const;
  239. int find_scancode_from_string(const String &p_code) const;
  240. void set_use_file_access_save_and_swap(bool p_enable);
  241. void set_native_icon(const String &p_filename);
  242. void set_icon(const Ref<Image> &p_icon);
  243. int get_exit_code() const;
  244. void set_exit_code(int p_code);
  245. Dictionary get_date(bool utc) const;
  246. Dictionary get_time(bool utc) const;
  247. Dictionary get_datetime(bool utc) const;
  248. Dictionary get_datetime_from_unix_time(int64_t unix_time_val) const;
  249. int64_t get_unix_time_from_datetime(Dictionary datetime) const;
  250. Dictionary get_time_zone_info() const;
  251. uint64_t get_unix_time() const;
  252. uint64_t get_system_time_secs() const;
  253. uint64_t get_system_time_msecs() const;
  254. uint64_t get_static_memory_usage() const;
  255. uint64_t get_static_memory_peak_usage() const;
  256. uint64_t get_dynamic_memory_usage() const;
  257. void delay_usec(int p_usec) const;
  258. void delay_msec(int p_msec) const;
  259. uint64_t get_ticks_msec() const;
  260. uint64_t get_ticks_usec() const;
  261. uint32_t get_splash_tick_msec() const;
  262. bool can_use_threads() const;
  263. bool can_draw() const;
  264. bool is_userfs_persistent() const;
  265. bool is_stdout_verbose() const;
  266. int get_processor_count() const;
  267. enum SystemDir {
  268. SYSTEM_DIR_DESKTOP,
  269. SYSTEM_DIR_DCIM,
  270. SYSTEM_DIR_DOCUMENTS,
  271. SYSTEM_DIR_DOWNLOADS,
  272. SYSTEM_DIR_MOVIES,
  273. SYSTEM_DIR_MUSIC,
  274. SYSTEM_DIR_PICTURES,
  275. SYSTEM_DIR_RINGTONES,
  276. };
  277. enum ScreenOrientation {
  278. SCREEN_ORIENTATION_LANDSCAPE,
  279. SCREEN_ORIENTATION_PORTRAIT,
  280. SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
  281. SCREEN_ORIENTATION_REVERSE_PORTRAIT,
  282. SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
  283. SCREEN_ORIENTATION_SENSOR_PORTRAIT,
  284. SCREEN_ORIENTATION_SENSOR,
  285. };
  286. String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;
  287. String get_user_data_dir() const;
  288. String get_config_dir() const;
  289. String get_data_dir() const;
  290. String get_cache_dir() const;
  291. void alert(const String &p_alert, const String &p_title = "ALERT!");
  292. void set_screen_orientation(ScreenOrientation p_orientation);
  293. ScreenOrientation get_screen_orientation() const;
  294. void set_keep_screen_on(bool p_enabled);
  295. bool is_keep_screen_on() const;
  296. bool is_ok_left_and_cancel_right() const;
  297. Error set_thread_name(const String &p_name);
  298. Thread::ID get_thread_caller_id() const;
  299. void set_use_vsync(bool p_enable);
  300. bool is_vsync_enabled() const;
  301. void set_vsync_via_compositor(bool p_enable);
  302. bool is_vsync_via_compositor_enabled() const;
  303. void set_delta_smoothing(bool p_enabled);
  304. bool is_delta_smoothing_enabled() const;
  305. PowerState get_power_state();
  306. int get_power_seconds_left();
  307. int get_power_percent_left();
  308. bool has_feature(const String &p_feature) const;
  309. bool request_permission(const String &p_name);
  310. bool request_permissions();
  311. Vector<String> get_granted_permissions() const;
  312. int get_tablet_driver_count() const;
  313. String get_tablet_driver_name(int p_driver) const;
  314. String get_current_tablet_driver() const;
  315. void set_current_tablet_driver(const String &p_driver);
  316. static _OS *get_singleton() { return singleton; }
  317. _OS();
  318. };
  319. VARIANT_ENUM_CAST(_OS::VideoDriver);
  320. VARIANT_ENUM_CAST(_OS::PowerState);
  321. VARIANT_ENUM_CAST(_OS::Weekday);
  322. VARIANT_ENUM_CAST(_OS::Month);
  323. VARIANT_ENUM_CAST(_OS::SystemDir);
  324. VARIANT_ENUM_CAST(_OS::ScreenOrientation);
  325. VARIANT_ENUM_CAST(_OS::HandleType);
  326. class _Geometry : public Object {
  327. GDCLASS(_Geometry, Object);
  328. static _Geometry *singleton;
  329. protected:
  330. static void _bind_methods();
  331. public:
  332. static _Geometry *get_singleton();
  333. PoolVector<Plane> build_box_planes(const Vector3 &p_extents);
  334. PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z);
  335. PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis = Vector3::AXIS_Z);
  336. Variant segment_intersects_segment_2d(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b);
  337. Variant line_intersects_line_2d(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b);
  338. PoolVector<Vector2> get_closest_points_between_segments_2d(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2);
  339. PoolVector<Vector3> get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2);
  340. Vector2 get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  341. Vector3 get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  342. Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  343. Vector3 get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  344. Variant ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  345. Variant segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  346. bool point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const;
  347. PoolVector<Vector3> segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius);
  348. PoolVector<Vector3> segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius);
  349. PoolVector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes);
  350. bool is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius);
  351. real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius);
  352. int get_uv84_normal_bit(const Vector3 &p_vector);
  353. bool is_polygon_clockwise(const Vector<Vector2> &p_polygon);
  354. bool is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon);
  355. Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon);
  356. Vector<int> triangulate_delaunay_2d(const Vector<Vector2> &p_points);
  357. Vector<Point2> convex_hull_2d(const Vector<Point2> &p_points);
  358. Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
  359. enum PolyBooleanOperation {
  360. OPERATION_UNION,
  361. OPERATION_DIFFERENCE,
  362. OPERATION_INTERSECTION,
  363. OPERATION_XOR
  364. };
  365. // 2D polygon boolean operations.
  366. Array merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Union (add).
  367. Array clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Difference (subtract).
  368. Array intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Common area (multiply).
  369. Array exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // All but common area (xor).
  370. // 2D polyline vs polygon operations.
  371. Array clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // Cut.
  372. Array intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // Chop.
  373. // 2D offset polygons/polylines.
  374. enum PolyJoinType {
  375. JOIN_SQUARE,
  376. JOIN_ROUND,
  377. JOIN_MITER
  378. };
  379. enum PolyEndType {
  380. END_POLYGON,
  381. END_JOINED,
  382. END_BUTT,
  383. END_SQUARE,
  384. END_ROUND
  385. };
  386. Array offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE);
  387. Array offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE, PolyEndType p_end_type = END_SQUARE);
  388. Dictionary make_atlas(const Vector<Size2> &p_rects);
  389. _Geometry();
  390. };
  391. VARIANT_ENUM_CAST(_Geometry::PolyBooleanOperation);
  392. VARIANT_ENUM_CAST(_Geometry::PolyJoinType);
  393. VARIANT_ENUM_CAST(_Geometry::PolyEndType);
  394. class _File : public Reference {
  395. GDCLASS(_File, Reference);
  396. FileAccess *f;
  397. bool eswap;
  398. protected:
  399. static void _bind_methods();
  400. public:
  401. enum ModeFlags {
  402. READ = 1,
  403. WRITE = 2,
  404. READ_WRITE = 3,
  405. WRITE_READ = 7,
  406. };
  407. enum CompressionMode {
  408. COMPRESSION_FASTLZ = Compression::MODE_FASTLZ,
  409. COMPRESSION_DEFLATE = Compression::MODE_DEFLATE,
  410. COMPRESSION_ZSTD = Compression::MODE_ZSTD,
  411. COMPRESSION_GZIP = Compression::MODE_GZIP
  412. };
  413. Error open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key);
  414. Error open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass);
  415. Error open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode = COMPRESSION_FASTLZ);
  416. Error open(const String &p_path, ModeFlags p_mode_flags); // open a file.
  417. void flush(); // Flush a file (write its buffer to disk).
  418. void close(); // Close a file.
  419. bool is_open() const; // True when file is open.
  420. String get_path() const; // Returns the path for the current open file.
  421. String get_path_absolute() const; // Returns the absolute path for the current open file.
  422. void seek(int64_t p_position); // Seek to a given position.
  423. void seek_end(int64_t p_position = 0); // Seek from the end of file.
  424. uint64_t get_position() const; // Get position in the file.
  425. uint64_t get_len() const; // Get size of the file.
  426. bool eof_reached() const; // Reading passed EOF.
  427. uint8_t get_8() const; // Get a byte.
  428. uint16_t get_16() const; // Get 16 bits uint.
  429. uint32_t get_32() const; // Get 32 bits uint.
  430. uint64_t get_64() const; // Get 64 bits uint.
  431. float get_float() const;
  432. double get_double() const;
  433. real_t get_real() const;
  434. Variant get_var(bool p_allow_objects = false) const;
  435. PoolVector<uint8_t> get_buffer(int64_t p_length) const; // Get an array of bytes.
  436. String get_line() const;
  437. Vector<String> get_csv_line(const String &p_delim = ",") const;
  438. String get_as_text() const;
  439. String get_md5(const String &p_path) const;
  440. String get_sha256(const String &p_path) const;
  441. /* Use this for files WRITTEN in _big_ endian machines (ie, amiga/mac).
  442. * It's not about the current CPU type but file formats.
  443. * This flags get reset to false (little endian) on each open.
  444. */
  445. void set_endian_swap(bool p_swap);
  446. bool get_endian_swap();
  447. Error get_error() const; // Get last error.
  448. void store_8(uint8_t p_dest); // Store a byte.
  449. void store_16(uint16_t p_dest); // Store 16 bits uint.
  450. void store_32(uint32_t p_dest); // Store 32 bits uint.
  451. void store_64(uint64_t p_dest); // Store 64 bits uint.
  452. void store_float(float p_dest);
  453. void store_double(double p_dest);
  454. void store_real(real_t p_real);
  455. void store_string(const String &p_string);
  456. void store_line(const String &p_string);
  457. void store_csv_line(const Vector<String> &p_values, const String &p_delim = ",");
  458. virtual void store_pascal_string(const String &p_string);
  459. virtual String get_pascal_string();
  460. void store_buffer(const PoolVector<uint8_t> &p_buffer); // Store an array of bytes.
  461. void store_var(const Variant &p_var, bool p_full_objects = false);
  462. bool file_exists(const String &p_name) const; // Return true if a file exists.
  463. uint64_t get_modified_time(const String &p_file) const;
  464. _File();
  465. virtual ~_File();
  466. };
  467. VARIANT_ENUM_CAST(_File::ModeFlags);
  468. VARIANT_ENUM_CAST(_File::CompressionMode);
  469. class _Directory : public Reference {
  470. GDCLASS(_Directory, Reference);
  471. DirAccess *d;
  472. protected:
  473. static void _bind_methods();
  474. public:
  475. Error open(const String &p_path);
  476. Error list_dir_begin(bool p_skip_navigational = false, bool p_skip_hidden = false); // This starts dir listing.
  477. String get_next();
  478. bool current_is_dir() const;
  479. void list_dir_end();
  480. int get_drive_count();
  481. String get_drive(int p_drive);
  482. int get_current_drive();
  483. Error change_dir(String p_dir); // Can be relative or absolute, return false on success.
  484. String get_current_dir(); // Return current dir location.
  485. Error make_dir(String p_dir);
  486. Error make_dir_recursive(String p_dir);
  487. bool file_exists(String p_file);
  488. bool dir_exists(String p_dir);
  489. uint64_t get_space_left();
  490. Error copy(String p_from, String p_to);
  491. Error rename(String p_from, String p_to);
  492. Error remove(String p_name);
  493. _Directory();
  494. virtual ~_Directory();
  495. private:
  496. bool _list_skip_navigational;
  497. bool _list_skip_hidden;
  498. };
  499. class _Marshalls : public Object {
  500. GDCLASS(_Marshalls, Object);
  501. static _Marshalls *singleton;
  502. protected:
  503. static void _bind_methods();
  504. public:
  505. static _Marshalls *get_singleton();
  506. String variant_to_base64(const Variant &p_var, bool p_full_objects = false);
  507. Variant base64_to_variant(const String &p_str, bool p_allow_objects = false);
  508. String raw_to_base64(const PoolVector<uint8_t> &p_arr);
  509. PoolVector<uint8_t> base64_to_raw(const String &p_str);
  510. String utf8_to_base64(const String &p_str);
  511. String base64_to_utf8(const String &p_str);
  512. _Marshalls() { singleton = this; }
  513. ~_Marshalls() { singleton = nullptr; }
  514. };
  515. class _Mutex : public Reference {
  516. GDCLASS(_Mutex, Reference);
  517. Mutex mutex;
  518. static void _bind_methods();
  519. public:
  520. void lock();
  521. Error try_lock();
  522. void unlock();
  523. };
  524. class _Semaphore : public Reference {
  525. GDCLASS(_Semaphore, Reference);
  526. Semaphore semaphore;
  527. static void _bind_methods();
  528. public:
  529. Error wait();
  530. Error post();
  531. };
  532. class _Thread : public Reference {
  533. GDCLASS(_Thread, Reference);
  534. protected:
  535. Variant ret;
  536. Variant userdata;
  537. SafeFlag running;
  538. ObjectID target_instance_id;
  539. StringName target_method;
  540. Thread thread;
  541. static void _bind_methods();
  542. static void _start_func(void *ud);
  543. public:
  544. enum Priority {
  545. PRIORITY_LOW,
  546. PRIORITY_NORMAL,
  547. PRIORITY_HIGH,
  548. PRIORITY_MAX
  549. };
  550. Error start(Object *p_instance, const StringName &p_method, const Variant &p_userdata = Variant(), Priority p_priority = PRIORITY_NORMAL);
  551. String get_id() const;
  552. bool is_active() const;
  553. bool is_alive() const;
  554. Variant wait_to_finish();
  555. _Thread();
  556. ~_Thread();
  557. };
  558. VARIANT_ENUM_CAST(_Thread::Priority);
  559. class _ClassDB : public Object {
  560. GDCLASS(_ClassDB, Object);
  561. protected:
  562. static void _bind_methods();
  563. public:
  564. PoolStringArray get_class_list() const;
  565. PoolStringArray get_inheriters_from_class(const StringName &p_class) const;
  566. StringName get_parent_class(const StringName &p_class) const;
  567. bool class_exists(const StringName &p_class) const;
  568. bool is_parent_class(const StringName &p_class, const StringName &p_inherits) const;
  569. bool can_instance(const StringName &p_class) const;
  570. Variant instance(const StringName &p_class) const;
  571. bool has_signal(StringName p_class, StringName p_signal) const;
  572. Dictionary get_signal(StringName p_class, StringName p_signal) const;
  573. Array get_signal_list(StringName p_class, bool p_no_inheritance = false) const;
  574. Array get_property_list(StringName p_class, bool p_no_inheritance = false) const;
  575. Variant get_property(Object *p_object, const StringName &p_property) const;
  576. Error set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const;
  577. bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false) const;
  578. Array get_method_list(StringName p_class, bool p_no_inheritance = false) const;
  579. PoolStringArray get_integer_constant_list(const StringName &p_class, bool p_no_inheritance = false) const;
  580. bool has_integer_constant(const StringName &p_class, const StringName &p_name) const;
  581. int get_integer_constant(const StringName &p_class, const StringName &p_name) const;
  582. StringName get_category(const StringName &p_node) const;
  583. bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false) const;
  584. PoolStringArray get_enum_list(const StringName &p_class, bool p_no_inheritance = false) const;
  585. PoolStringArray get_enum_constants(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance = false) const;
  586. StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false) const;
  587. bool is_class_enabled(StringName p_class) const;
  588. _ClassDB();
  589. ~_ClassDB();
  590. };
  591. class _Engine : public Object {
  592. GDCLASS(_Engine, Object);
  593. protected:
  594. static void _bind_methods();
  595. static _Engine *singleton;
  596. public:
  597. static _Engine *get_singleton() { return singleton; }
  598. void set_iterations_per_second(int p_ips);
  599. int get_iterations_per_second() const;
  600. void set_physics_jitter_fix(float p_threshold);
  601. float get_physics_jitter_fix() const;
  602. float get_physics_interpolation_fraction() const;
  603. void set_target_fps(int p_fps);
  604. int get_target_fps() const;
  605. float get_frames_per_second() const;
  606. uint64_t get_physics_frames() const;
  607. uint64_t get_idle_frames() const;
  608. int get_frames_drawn();
  609. void set_time_scale(float p_scale);
  610. float get_time_scale();
  611. MainLoop *get_main_loop() const;
  612. Dictionary get_version_info() const;
  613. Dictionary get_author_info() const;
  614. Array get_copyright_info() const;
  615. Dictionary get_donor_info() const;
  616. Dictionary get_license_info() const;
  617. String get_license_text() const;
  618. bool is_in_physics_frame() const;
  619. bool has_singleton(const String &p_name) const;
  620. Object *get_singleton_object(const String &p_name) const;
  621. void set_editor_hint(bool p_enabled);
  622. bool is_editor_hint() const;
  623. void set_print_error_messages(bool p_enabled);
  624. bool is_printing_error_messages() const;
  625. _Engine();
  626. };
  627. class _JSON;
  628. class JSONParseResult : public Reference {
  629. GDCLASS(JSONParseResult, Reference);
  630. friend class _JSON;
  631. Error error;
  632. String error_string;
  633. int error_line;
  634. Variant result;
  635. protected:
  636. static void _bind_methods();
  637. public:
  638. void set_error(Error p_error);
  639. Error get_error() const;
  640. void set_error_string(const String &p_error_string);
  641. String get_error_string() const;
  642. void set_error_line(int p_error_line);
  643. int get_error_line() const;
  644. void set_result(const Variant &p_result);
  645. Variant get_result() const;
  646. JSONParseResult() :
  647. error_line(-1) {}
  648. };
  649. class _JSON : public Object {
  650. GDCLASS(_JSON, Object);
  651. protected:
  652. static void _bind_methods();
  653. static _JSON *singleton;
  654. public:
  655. static _JSON *get_singleton() { return singleton; }
  656. String print(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false);
  657. Ref<JSONParseResult> parse(const String &p_json);
  658. _JSON();
  659. };
  660. #endif // CORE_BIND_H