core_bind.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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_latin_keyboard_variant() const;
  217. int keyboard_get_layout_count() const;
  218. int keyboard_get_current_layout() const;
  219. void keyboard_set_current_layout(int p_index);
  220. String keyboard_get_layout_language(int p_index) const;
  221. String keyboard_get_layout_name(int p_index) const;
  222. String get_model_name() const;
  223. void dump_memory_to_file(const String &p_file);
  224. void dump_resources_to_file(const String &p_file);
  225. bool has_virtual_keyboard() const;
  226. void show_virtual_keyboard(const String &p_existing_text = "", bool p_multiline = false);
  227. void hide_virtual_keyboard();
  228. int get_virtual_keyboard_height();
  229. void print_resources_in_use(bool p_short = false);
  230. void print_all_resources(const String &p_to_file);
  231. void print_all_textures_by_size();
  232. void print_resources_by_type(const Vector<String> &p_types);
  233. bool has_touchscreen_ui_hint() const;
  234. bool is_debug_build() const;
  235. String get_unique_id() const;
  236. String get_scancode_string(uint32_t p_code) const;
  237. bool is_scancode_unicode(uint32_t p_unicode) const;
  238. int find_scancode_from_string(const String &p_code) const;
  239. void set_use_file_access_save_and_swap(bool p_enable);
  240. void set_native_icon(const String &p_filename);
  241. void set_icon(const Ref<Image> &p_icon);
  242. int get_exit_code() const;
  243. void set_exit_code(int p_code);
  244. Dictionary get_date(bool utc) const;
  245. Dictionary get_time(bool utc) const;
  246. Dictionary get_datetime(bool utc) const;
  247. Dictionary get_datetime_from_unix_time(int64_t unix_time_val) const;
  248. int64_t get_unix_time_from_datetime(Dictionary datetime) const;
  249. Dictionary get_time_zone_info() const;
  250. uint64_t get_unix_time() const;
  251. uint64_t get_system_time_secs() const;
  252. uint64_t get_system_time_msecs() const;
  253. uint64_t get_static_memory_usage() const;
  254. uint64_t get_static_memory_peak_usage() const;
  255. uint64_t get_dynamic_memory_usage() const;
  256. void delay_usec(int p_usec) const;
  257. void delay_msec(int p_msec) const;
  258. uint32_t get_ticks_msec() const;
  259. uint64_t get_ticks_usec() const;
  260. uint32_t get_splash_tick_msec() const;
  261. bool can_use_threads() const;
  262. bool can_draw() const;
  263. bool is_userfs_persistent() const;
  264. bool is_stdout_verbose() const;
  265. int get_processor_count() const;
  266. enum SystemDir {
  267. SYSTEM_DIR_DESKTOP,
  268. SYSTEM_DIR_DCIM,
  269. SYSTEM_DIR_DOCUMENTS,
  270. SYSTEM_DIR_DOWNLOADS,
  271. SYSTEM_DIR_MOVIES,
  272. SYSTEM_DIR_MUSIC,
  273. SYSTEM_DIR_PICTURES,
  274. SYSTEM_DIR_RINGTONES,
  275. };
  276. enum ScreenOrientation {
  277. SCREEN_ORIENTATION_LANDSCAPE,
  278. SCREEN_ORIENTATION_PORTRAIT,
  279. SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
  280. SCREEN_ORIENTATION_REVERSE_PORTRAIT,
  281. SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
  282. SCREEN_ORIENTATION_SENSOR_PORTRAIT,
  283. SCREEN_ORIENTATION_SENSOR,
  284. };
  285. String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;
  286. String get_user_data_dir() const;
  287. void alert(const String &p_alert, const String &p_title = "ALERT!");
  288. void set_screen_orientation(ScreenOrientation p_orientation);
  289. ScreenOrientation get_screen_orientation() const;
  290. void set_keep_screen_on(bool p_enabled);
  291. bool is_keep_screen_on() const;
  292. bool is_ok_left_and_cancel_right() const;
  293. Error set_thread_name(const String &p_name);
  294. Thread::ID get_thread_caller_id() const;
  295. void set_use_vsync(bool p_enable);
  296. bool is_vsync_enabled() const;
  297. void set_vsync_via_compositor(bool p_enable);
  298. bool is_vsync_via_compositor_enabled() const;
  299. PowerState get_power_state();
  300. int get_power_seconds_left();
  301. int get_power_percent_left();
  302. bool has_feature(const String &p_feature) const;
  303. bool request_permission(const String &p_name);
  304. bool request_permissions();
  305. Vector<String> get_granted_permissions() const;
  306. int get_tablet_driver_count() const;
  307. String get_tablet_driver_name(int p_driver) const;
  308. String get_current_tablet_driver() const;
  309. void set_current_tablet_driver(const String &p_driver);
  310. static _OS *get_singleton() { return singleton; }
  311. _OS();
  312. };
  313. VARIANT_ENUM_CAST(_OS::VideoDriver);
  314. VARIANT_ENUM_CAST(_OS::PowerState);
  315. VARIANT_ENUM_CAST(_OS::Weekday);
  316. VARIANT_ENUM_CAST(_OS::Month);
  317. VARIANT_ENUM_CAST(_OS::SystemDir);
  318. VARIANT_ENUM_CAST(_OS::ScreenOrientation);
  319. VARIANT_ENUM_CAST(_OS::HandleType);
  320. class _Geometry : public Object {
  321. GDCLASS(_Geometry, Object);
  322. static _Geometry *singleton;
  323. protected:
  324. static void _bind_methods();
  325. public:
  326. static _Geometry *get_singleton();
  327. PoolVector<Plane> build_box_planes(const Vector3 &p_extents);
  328. PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z);
  329. PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis = Vector3::AXIS_Z);
  330. 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);
  331. 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);
  332. PoolVector<Vector2> get_closest_points_between_segments_2d(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2);
  333. PoolVector<Vector3> get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2);
  334. Vector2 get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  335. Vector3 get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  336. Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  337. Vector3 get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  338. Variant ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  339. Variant segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  340. bool point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const;
  341. PoolVector<Vector3> segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius);
  342. PoolVector<Vector3> segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius);
  343. PoolVector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes);
  344. bool is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius);
  345. real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius);
  346. int get_uv84_normal_bit(const Vector3 &p_vector);
  347. bool is_polygon_clockwise(const Vector<Vector2> &p_polygon);
  348. bool is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon);
  349. Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon);
  350. Vector<int> triangulate_delaunay_2d(const Vector<Vector2> &p_points);
  351. Vector<Point2> convex_hull_2d(const Vector<Point2> &p_points);
  352. Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
  353. enum PolyBooleanOperation {
  354. OPERATION_UNION,
  355. OPERATION_DIFFERENCE,
  356. OPERATION_INTERSECTION,
  357. OPERATION_XOR
  358. };
  359. // 2D polygon boolean operations.
  360. Array merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Union (add).
  361. Array clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Difference (subtract).
  362. Array intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Common area (multiply).
  363. Array exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // All but common area (xor).
  364. // 2D polyline vs polygon operations.
  365. Array clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // Cut.
  366. Array intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // Chop.
  367. // 2D offset polygons/polylines.
  368. enum PolyJoinType {
  369. JOIN_SQUARE,
  370. JOIN_ROUND,
  371. JOIN_MITER
  372. };
  373. enum PolyEndType {
  374. END_POLYGON,
  375. END_JOINED,
  376. END_BUTT,
  377. END_SQUARE,
  378. END_ROUND
  379. };
  380. Array offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE);
  381. 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);
  382. Dictionary make_atlas(const Vector<Size2> &p_rects);
  383. _Geometry();
  384. };
  385. VARIANT_ENUM_CAST(_Geometry::PolyBooleanOperation);
  386. VARIANT_ENUM_CAST(_Geometry::PolyJoinType);
  387. VARIANT_ENUM_CAST(_Geometry::PolyEndType);
  388. class _File : public Reference {
  389. GDCLASS(_File, Reference);
  390. FileAccess *f;
  391. bool eswap;
  392. protected:
  393. static void _bind_methods();
  394. public:
  395. enum ModeFlags {
  396. READ = 1,
  397. WRITE = 2,
  398. READ_WRITE = 3,
  399. WRITE_READ = 7,
  400. };
  401. enum CompressionMode {
  402. COMPRESSION_FASTLZ = Compression::MODE_FASTLZ,
  403. COMPRESSION_DEFLATE = Compression::MODE_DEFLATE,
  404. COMPRESSION_ZSTD = Compression::MODE_ZSTD,
  405. COMPRESSION_GZIP = Compression::MODE_GZIP
  406. };
  407. Error open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key);
  408. Error open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass);
  409. Error open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode = COMPRESSION_FASTLZ);
  410. Error open(const String &p_path, ModeFlags p_mode_flags); // open a file.
  411. void flush(); // Flush a file (write its buffer to disk).
  412. void close(); // Close a file.
  413. bool is_open() const; // True when file is open.
  414. String get_path() const; // Returns the path for the current open file.
  415. String get_path_absolute() const; // Returns the absolute path for the current open file.
  416. void seek(int64_t p_position); // Seek to a given position.
  417. void seek_end(int64_t p_position = 0); // Seek from the end of file.
  418. int64_t get_position() const; // Get position in the file.
  419. int64_t get_len() const; // Get size of the file.
  420. bool eof_reached() const; // Reading passed EOF.
  421. uint8_t get_8() const; // Get a byte.
  422. uint16_t get_16() const; // Get 16 bits uint.
  423. uint32_t get_32() const; // Get 32 bits uint.
  424. uint64_t get_64() const; // Get 64 bits uint.
  425. float get_float() const;
  426. double get_double() const;
  427. real_t get_real() const;
  428. Variant get_var(bool p_allow_objects = false) const;
  429. PoolVector<uint8_t> get_buffer(int p_length) const; // Get an array of bytes.
  430. String get_line() const;
  431. Vector<String> get_csv_line(const String &p_delim = ",") const;
  432. String get_as_text() const;
  433. String get_md5(const String &p_path) const;
  434. String get_sha256(const String &p_path) const;
  435. /* Use this for files WRITTEN in _big_ endian machines (ie, amiga/mac).
  436. * It's not about the current CPU type but file formats.
  437. * This flags get reset to false (little endian) on each open.
  438. */
  439. void set_endian_swap(bool p_swap);
  440. bool get_endian_swap();
  441. Error get_error() const; // Get last error.
  442. void store_8(uint8_t p_dest); // Store a byte.
  443. void store_16(uint16_t p_dest); // Store 16 bits uint.
  444. void store_32(uint32_t p_dest); // Store 32 bits uint.
  445. void store_64(uint64_t p_dest); // Store 64 bits uint.
  446. void store_float(float p_dest);
  447. void store_double(double p_dest);
  448. void store_real(real_t p_real);
  449. void store_string(const String &p_string);
  450. void store_line(const String &p_string);
  451. void store_csv_line(const Vector<String> &p_values, const String &p_delim = ",");
  452. virtual void store_pascal_string(const String &p_string);
  453. virtual String get_pascal_string();
  454. void store_buffer(const PoolVector<uint8_t> &p_buffer); // Store an array of bytes.
  455. void store_var(const Variant &p_var, bool p_full_objects = false);
  456. bool file_exists(const String &p_name) const; // Return true if a file exists.
  457. uint64_t get_modified_time(const String &p_file) const;
  458. _File();
  459. virtual ~_File();
  460. };
  461. VARIANT_ENUM_CAST(_File::ModeFlags);
  462. VARIANT_ENUM_CAST(_File::CompressionMode);
  463. class _Directory : public Reference {
  464. GDCLASS(_Directory, Reference);
  465. DirAccess *d;
  466. protected:
  467. static void _bind_methods();
  468. public:
  469. Error open(const String &p_path);
  470. Error list_dir_begin(bool p_skip_navigational = false, bool p_skip_hidden = false); // This starts dir listing.
  471. String get_next();
  472. bool current_is_dir() const;
  473. void list_dir_end();
  474. int get_drive_count();
  475. String get_drive(int p_drive);
  476. int get_current_drive();
  477. Error change_dir(String p_dir); // Can be relative or absolute, return false on success.
  478. String get_current_dir(); // Return current dir location.
  479. Error make_dir(String p_dir);
  480. Error make_dir_recursive(String p_dir);
  481. bool file_exists(String p_file);
  482. bool dir_exists(String p_dir);
  483. int get_space_left();
  484. Error copy(String p_from, String p_to);
  485. Error rename(String p_from, String p_to);
  486. Error remove(String p_name);
  487. _Directory();
  488. virtual ~_Directory();
  489. private:
  490. bool _list_skip_navigational;
  491. bool _list_skip_hidden;
  492. };
  493. class _Marshalls : public Object {
  494. GDCLASS(_Marshalls, Object);
  495. static _Marshalls *singleton;
  496. protected:
  497. static void _bind_methods();
  498. public:
  499. static _Marshalls *get_singleton();
  500. String variant_to_base64(const Variant &p_var, bool p_full_objects = false);
  501. Variant base64_to_variant(const String &p_str, bool p_allow_objects = false);
  502. String raw_to_base64(const PoolVector<uint8_t> &p_arr);
  503. PoolVector<uint8_t> base64_to_raw(const String &p_str);
  504. String utf8_to_base64(const String &p_str);
  505. String base64_to_utf8(const String &p_str);
  506. _Marshalls() { singleton = this; }
  507. ~_Marshalls() { singleton = NULL; }
  508. };
  509. class _Mutex : public Reference {
  510. GDCLASS(_Mutex, Reference);
  511. Mutex mutex;
  512. static void _bind_methods();
  513. public:
  514. void lock();
  515. Error try_lock();
  516. void unlock();
  517. };
  518. class _Semaphore : public Reference {
  519. GDCLASS(_Semaphore, Reference);
  520. Semaphore semaphore;
  521. static void _bind_methods();
  522. public:
  523. Error wait();
  524. Error post();
  525. };
  526. class _Thread : public Reference {
  527. GDCLASS(_Thread, Reference);
  528. protected:
  529. Variant ret;
  530. Variant userdata;
  531. SafeFlag active;
  532. Object *target_instance;
  533. StringName target_method;
  534. Thread thread;
  535. static void _bind_methods();
  536. static void _start_func(void *ud);
  537. public:
  538. enum Priority {
  539. PRIORITY_LOW,
  540. PRIORITY_NORMAL,
  541. PRIORITY_HIGH,
  542. PRIORITY_MAX
  543. };
  544. Error start(Object *p_instance, const StringName &p_method, const Variant &p_userdata = Variant(), Priority p_priority = PRIORITY_NORMAL);
  545. String get_id() const;
  546. bool is_active() const;
  547. Variant wait_to_finish();
  548. _Thread();
  549. ~_Thread();
  550. };
  551. VARIANT_ENUM_CAST(_Thread::Priority);
  552. class _ClassDB : public Object {
  553. GDCLASS(_ClassDB, Object);
  554. protected:
  555. static void _bind_methods();
  556. public:
  557. PoolStringArray get_class_list() const;
  558. PoolStringArray get_inheriters_from_class(const StringName &p_class) const;
  559. StringName get_parent_class(const StringName &p_class) const;
  560. bool class_exists(const StringName &p_class) const;
  561. bool is_parent_class(const StringName &p_class, const StringName &p_inherits) const;
  562. bool can_instance(const StringName &p_class) const;
  563. Variant instance(const StringName &p_class) const;
  564. bool has_signal(StringName p_class, StringName p_signal) const;
  565. Dictionary get_signal(StringName p_class, StringName p_signal) const;
  566. Array get_signal_list(StringName p_class, bool p_no_inheritance = false) const;
  567. Array get_property_list(StringName p_class, bool p_no_inheritance = false) const;
  568. Variant get_property(Object *p_object, const StringName &p_property) const;
  569. Error set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const;
  570. bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false) const;
  571. Array get_method_list(StringName p_class, bool p_no_inheritance = false) const;
  572. PoolStringArray get_integer_constant_list(const StringName &p_class, bool p_no_inheritance = false) const;
  573. bool has_integer_constant(const StringName &p_class, const StringName &p_name) const;
  574. int get_integer_constant(const StringName &p_class, const StringName &p_name) const;
  575. StringName get_category(const StringName &p_node) const;
  576. bool is_class_enabled(StringName p_class) const;
  577. _ClassDB();
  578. ~_ClassDB();
  579. };
  580. class _Engine : public Object {
  581. GDCLASS(_Engine, Object);
  582. protected:
  583. static void _bind_methods();
  584. static _Engine *singleton;
  585. public:
  586. static _Engine *get_singleton() { return singleton; }
  587. void set_iterations_per_second(int p_ips);
  588. int get_iterations_per_second() const;
  589. void set_physics_jitter_fix(float p_threshold);
  590. float get_physics_jitter_fix() const;
  591. float get_physics_interpolation_fraction() const;
  592. void set_target_fps(int p_fps);
  593. int get_target_fps() const;
  594. float get_frames_per_second() const;
  595. uint64_t get_physics_frames() const;
  596. uint64_t get_idle_frames() const;
  597. int get_frames_drawn();
  598. void set_time_scale(float p_scale);
  599. float get_time_scale();
  600. MainLoop *get_main_loop() const;
  601. Dictionary get_version_info() const;
  602. Dictionary get_author_info() const;
  603. Array get_copyright_info() const;
  604. Dictionary get_donor_info() const;
  605. Dictionary get_license_info() const;
  606. String get_license_text() const;
  607. bool is_in_physics_frame() const;
  608. bool has_singleton(const String &p_name) const;
  609. Object *get_singleton_object(const String &p_name) const;
  610. void set_editor_hint(bool p_enabled);
  611. bool is_editor_hint() const;
  612. _Engine();
  613. };
  614. class _JSON;
  615. class JSONParseResult : public Reference {
  616. GDCLASS(JSONParseResult, Reference);
  617. friend class _JSON;
  618. Error error;
  619. String error_string;
  620. int error_line;
  621. Variant result;
  622. protected:
  623. static void _bind_methods();
  624. public:
  625. void set_error(Error p_error);
  626. Error get_error() const;
  627. void set_error_string(const String &p_error_string);
  628. String get_error_string() const;
  629. void set_error_line(int p_error_line);
  630. int get_error_line() const;
  631. void set_result(const Variant &p_result);
  632. Variant get_result() const;
  633. JSONParseResult() :
  634. error_line(-1) {}
  635. };
  636. class _JSON : public Object {
  637. GDCLASS(_JSON, Object);
  638. protected:
  639. static void _bind_methods();
  640. static _JSON *singleton;
  641. public:
  642. static _JSON *get_singleton() { return singleton; }
  643. String print(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false);
  644. Ref<JSONParseResult> parse(const String &p_json);
  645. _JSON();
  646. };
  647. #endif // CORE_BIND_H