core_bind.h 26 KB

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