core_bind.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. /*************************************************************************/
  2. /* core_bind.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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, uint32_t 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. Point2 get_mouse_position() const;
  125. void set_window_title(const String &p_title);
  126. int get_mouse_button_state() const;
  127. void set_clipboard(const String &p_text);
  128. String get_clipboard() const;
  129. void set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen = 0);
  130. Size2 get_video_mode(int p_screen = 0) const;
  131. bool is_video_mode_fullscreen(int p_screen = 0) const;
  132. bool is_video_mode_resizable(int p_screen = 0) const;
  133. Array get_fullscreen_mode_list(int p_screen = 0) const;
  134. virtual int get_video_driver_count() const;
  135. virtual String get_video_driver_name(VideoDriver p_driver) const;
  136. virtual VideoDriver get_current_video_driver() const;
  137. virtual int get_audio_driver_count() const;
  138. virtual String get_audio_driver_name(int p_driver) const;
  139. virtual PoolStringArray get_connected_midi_inputs();
  140. virtual void open_midi_inputs();
  141. virtual void close_midi_inputs();
  142. virtual int get_screen_count() const;
  143. virtual int get_current_screen() const;
  144. virtual void set_current_screen(int p_screen);
  145. virtual Point2 get_screen_position(int p_screen = -1) const;
  146. virtual Size2 get_screen_size(int p_screen = -1) const;
  147. virtual int get_screen_dpi(int p_screen = -1) const;
  148. virtual Point2 get_window_position() const;
  149. virtual void set_window_position(const Point2 &p_position);
  150. virtual Size2 get_window_size() const;
  151. virtual Size2 get_real_window_size() const;
  152. virtual Rect2 get_window_safe_area() const;
  153. virtual void set_window_size(const Size2 &p_size);
  154. virtual void set_window_fullscreen(bool p_enabled);
  155. virtual bool is_window_fullscreen() const;
  156. virtual void set_window_resizable(bool p_enabled);
  157. virtual bool is_window_resizable() const;
  158. virtual void set_window_minimized(bool p_enabled);
  159. virtual bool is_window_minimized() const;
  160. virtual void set_window_maximized(bool p_enabled);
  161. virtual bool is_window_maximized() const;
  162. virtual void set_window_always_on_top(bool p_enabled);
  163. virtual bool is_window_always_on_top() const;
  164. virtual void request_attention();
  165. virtual void center_window();
  166. virtual void move_window_to_foreground();
  167. virtual void set_borderless_window(bool p_borderless);
  168. virtual bool get_borderless_window() const;
  169. virtual bool get_window_per_pixel_transparency_enabled() const;
  170. virtual void set_window_per_pixel_transparency_enabled(bool p_enabled);
  171. virtual void set_ime_active(const bool p_active);
  172. virtual void set_ime_position(const Point2 &p_pos);
  173. virtual Point2 get_ime_selection() const;
  174. virtual String get_ime_text() const;
  175. Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  176. bool native_video_is_playing();
  177. void native_video_pause();
  178. void native_video_unpause();
  179. void native_video_stop();
  180. void set_low_processor_usage_mode(bool p_enabled);
  181. bool is_in_low_processor_usage_mode() const;
  182. String get_executable_path() const;
  183. int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output = Array());
  184. Error kill(int p_pid);
  185. Error shell_open(String p_uri);
  186. int get_process_id() const;
  187. bool has_environment(const String &p_var) const;
  188. String get_environment(const String &p_var) const;
  189. String get_name() const;
  190. Vector<String> get_cmdline_args();
  191. String get_locale() const;
  192. String get_latin_keyboard_variant() const;
  193. String get_model_name() const;
  194. void dump_memory_to_file(const String &p_file);
  195. void dump_resources_to_file(const String &p_file);
  196. bool has_virtual_keyboard() const;
  197. void show_virtual_keyboard(const String &p_existing_text = "");
  198. void hide_virtual_keyboard();
  199. int get_virtual_keyboard_height();
  200. void print_resources_in_use(bool p_short = false);
  201. void print_all_resources(const String &p_to_file);
  202. void print_all_textures_by_size();
  203. void print_resources_by_type(const Vector<String> &p_types);
  204. bool has_touchscreen_ui_hint() const;
  205. bool is_debug_build() const;
  206. String get_unique_id() const;
  207. String get_scancode_string(uint32_t p_code) const;
  208. bool is_scancode_unicode(uint32_t p_unicode) const;
  209. int find_scancode_from_string(const String &p_code) const;
  210. /*
  211. struct Date {
  212. int year;
  213. Month month;
  214. int day;
  215. Weekday weekday;
  216. bool dst;
  217. };
  218. struct Time {
  219. int hour;
  220. int min;
  221. int sec;
  222. };
  223. */
  224. void set_use_file_access_save_and_swap(bool p_enable);
  225. void set_icon(const Ref<Image> &p_icon);
  226. int get_exit_code() const;
  227. void set_exit_code(int p_code);
  228. Dictionary get_date(bool utc) const;
  229. Dictionary get_time(bool utc) const;
  230. Dictionary get_datetime(bool utc) const;
  231. Dictionary get_datetime_from_unix_time(int64_t unix_time_val) const;
  232. int64_t get_unix_time_from_datetime(Dictionary datetime) const;
  233. Dictionary get_time_zone_info() const;
  234. uint64_t get_unix_time() const;
  235. uint64_t get_system_time_secs() const;
  236. uint64_t get_system_time_msecs() const;
  237. uint64_t get_static_memory_usage() const;
  238. uint64_t get_static_memory_peak_usage() const;
  239. uint64_t get_dynamic_memory_usage() const;
  240. void delay_usec(uint32_t p_usec) const;
  241. void delay_msec(uint32_t p_msec) const;
  242. uint32_t get_ticks_msec() const;
  243. uint64_t get_ticks_usec() const;
  244. uint32_t get_splash_tick_msec() const;
  245. bool can_use_threads() const;
  246. bool can_draw() const;
  247. bool is_userfs_persistent() const;
  248. bool is_stdout_verbose() const;
  249. int get_processor_count() const;
  250. enum SystemDir {
  251. SYSTEM_DIR_DESKTOP,
  252. SYSTEM_DIR_DCIM,
  253. SYSTEM_DIR_DOCUMENTS,
  254. SYSTEM_DIR_DOWNLOADS,
  255. SYSTEM_DIR_MOVIES,
  256. SYSTEM_DIR_MUSIC,
  257. SYSTEM_DIR_PICTURES,
  258. SYSTEM_DIR_RINGTONES,
  259. };
  260. enum ScreenOrientation {
  261. SCREEN_ORIENTATION_LANDSCAPE,
  262. SCREEN_ORIENTATION_PORTRAIT,
  263. SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
  264. SCREEN_ORIENTATION_REVERSE_PORTRAIT,
  265. SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
  266. SCREEN_ORIENTATION_SENSOR_PORTRAIT,
  267. SCREEN_ORIENTATION_SENSOR,
  268. };
  269. String get_system_dir(SystemDir p_dir) const;
  270. String get_user_data_dir() const;
  271. void alert(const String &p_alert, const String &p_title = "ALERT!");
  272. void set_screen_orientation(ScreenOrientation p_orientation);
  273. ScreenOrientation get_screen_orientation() const;
  274. void set_keep_screen_on(bool p_enabled);
  275. bool is_keep_screen_on() const;
  276. bool is_ok_left_and_cancel_right() const;
  277. Error set_thread_name(const String &p_name);
  278. void set_use_vsync(bool p_enable);
  279. bool is_vsync_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. static _OS *get_singleton() { return singleton; }
  286. _OS();
  287. };
  288. VARIANT_ENUM_CAST(_OS::VideoDriver);
  289. VARIANT_ENUM_CAST(_OS::PowerState);
  290. VARIANT_ENUM_CAST(_OS::Weekday);
  291. VARIANT_ENUM_CAST(_OS::Month);
  292. VARIANT_ENUM_CAST(_OS::SystemDir);
  293. VARIANT_ENUM_CAST(_OS::ScreenOrientation);
  294. class _Geometry : public Object {
  295. GDCLASS(_Geometry, Object);
  296. static _Geometry *singleton;
  297. protected:
  298. static void _bind_methods();
  299. public:
  300. static _Geometry *get_singleton();
  301. PoolVector<Plane> build_box_planes(const Vector3 &p_extents);
  302. PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z);
  303. PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis = Vector3::AXIS_Z);
  304. 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);
  305. 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);
  306. PoolVector<Vector2> get_closest_points_between_segments_2d(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2);
  307. PoolVector<Vector3> get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2);
  308. Vector2 get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  309. Vector3 get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  310. Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  311. Vector3 get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  312. Variant ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  313. Variant segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  314. bool point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const;
  315. PoolVector<Vector3> segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius);
  316. PoolVector<Vector3> segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius);
  317. PoolVector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes);
  318. real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius);
  319. int get_uv84_normal_bit(const Vector3 &p_vector);
  320. Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon);
  321. Vector<Point2> convex_hull_2d(const Vector<Point2> &p_points);
  322. Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
  323. Dictionary make_atlas(const Vector<Size2> &p_rects);
  324. _Geometry();
  325. };
  326. class _File : public Reference {
  327. GDCLASS(_File, Reference);
  328. FileAccess *f;
  329. bool eswap;
  330. protected:
  331. static void _bind_methods();
  332. public:
  333. enum ModeFlags {
  334. READ = 1,
  335. WRITE = 2,
  336. READ_WRITE = 3,
  337. WRITE_READ = 7,
  338. };
  339. enum CompressionMode {
  340. COMPRESSION_FASTLZ = Compression::MODE_FASTLZ,
  341. COMPRESSION_DEFLATE = Compression::MODE_DEFLATE,
  342. COMPRESSION_ZSTD = Compression::MODE_ZSTD,
  343. COMPRESSION_GZIP = Compression::MODE_GZIP
  344. };
  345. Error open_encrypted(const String &p_path, int p_mode_flags, const Vector<uint8_t> &p_key);
  346. Error open_encrypted_pass(const String &p_path, int p_mode_flags, const String &p_pass);
  347. Error open_compressed(const String &p_path, int p_mode_flags, int p_compress_mode = 0);
  348. Error open(const String &p_path, int p_mode_flags); ///< open a file
  349. void close(); ///< close a file
  350. bool is_open() const; ///< true when file is open
  351. String get_path() const; /// returns the path for the current open file
  352. String get_path_absolute() const; /// returns the absolute path for the current open file
  353. void seek(int64_t p_position); ///< seek to a given position
  354. void seek_end(int64_t p_position = 0); ///< seek from the end of file
  355. int64_t get_position() const; ///< get position in the file
  356. int64_t get_len() const; ///< get size of the file
  357. bool eof_reached() const; ///< reading passed EOF
  358. uint8_t get_8() const; ///< get a byte
  359. uint16_t get_16() const; ///< get 16 bits uint
  360. uint32_t get_32() const; ///< get 32 bits uint
  361. uint64_t get_64() const; ///< get 64 bits uint
  362. float get_float() const;
  363. double get_double() const;
  364. real_t get_real() const;
  365. Variant get_var(bool p_allow_objects = false) const;
  366. PoolVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
  367. String get_line() const;
  368. Vector<String> get_csv_line(const String &p_delim = ",") const;
  369. String get_as_text() const;
  370. String get_md5(const String &p_path) const;
  371. String get_sha256(const String &p_path) const;
  372. /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
  373. * It's not about the current CPU type but file formats.
  374. * this flags get reset to false (little endian) on each open
  375. */
  376. void set_endian_swap(bool p_swap);
  377. bool get_endian_swap();
  378. Error get_error() const; ///< get last error
  379. void store_8(uint8_t p_dest); ///< store a byte
  380. void store_16(uint16_t p_dest); ///< store 16 bits uint
  381. void store_32(uint32_t p_dest); ///< store 32 bits uint
  382. void store_64(uint64_t p_dest); ///< store 64 bits uint
  383. void store_float(float p_dest);
  384. void store_double(double p_dest);
  385. void store_real(real_t p_real);
  386. void store_string(const String &p_string);
  387. void store_line(const String &p_string);
  388. void store_csv_line(const Vector<String> &p_values, const String &p_delim = ",");
  389. virtual void store_pascal_string(const String &p_string);
  390. virtual String get_pascal_string();
  391. void store_buffer(const PoolVector<uint8_t> &p_buffer); ///< store an array of bytes
  392. void store_var(const Variant &p_var, bool p_full_objects = false);
  393. bool file_exists(const String &p_name) const; ///< return true if a file exists
  394. uint64_t get_modified_time(const String &p_file) const;
  395. _File();
  396. virtual ~_File();
  397. };
  398. VARIANT_ENUM_CAST(_File::ModeFlags);
  399. VARIANT_ENUM_CAST(_File::CompressionMode);
  400. class _Directory : public Reference {
  401. GDCLASS(_Directory, Reference);
  402. DirAccess *d;
  403. protected:
  404. static void _bind_methods();
  405. public:
  406. Error open(const String &p_path);
  407. Error list_dir_begin(bool p_skip_navigational = false, bool p_skip_hidden = false); ///< This starts dir listing
  408. String get_next();
  409. bool current_is_dir() const;
  410. void list_dir_end(); ///<
  411. int get_drive_count();
  412. String get_drive(int p_drive);
  413. int get_current_drive();
  414. Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
  415. String get_current_dir(); ///< return current dir location
  416. Error make_dir(String p_dir);
  417. Error make_dir_recursive(String p_dir);
  418. bool file_exists(String p_file);
  419. bool dir_exists(String p_dir);
  420. int get_space_left();
  421. Error copy(String p_from, String p_to);
  422. Error rename(String p_from, String p_to);
  423. Error remove(String p_name);
  424. _Directory();
  425. virtual ~_Directory();
  426. private:
  427. bool _list_skip_navigational;
  428. bool _list_skip_hidden;
  429. };
  430. class _Marshalls : public Reference {
  431. GDCLASS(_Marshalls, Reference);
  432. static _Marshalls *singleton;
  433. protected:
  434. static void _bind_methods();
  435. public:
  436. static _Marshalls *get_singleton();
  437. String variant_to_base64(const Variant &p_var, bool p_full_objects = false);
  438. Variant base64_to_variant(const String &p_str, bool p_allow_objects = false);
  439. String raw_to_base64(const PoolVector<uint8_t> &p_arr);
  440. PoolVector<uint8_t> base64_to_raw(const String &p_str);
  441. String utf8_to_base64(const String &p_str);
  442. String base64_to_utf8(const String &p_str);
  443. _Marshalls() { singleton = this; }
  444. ~_Marshalls() { singleton = NULL; }
  445. };
  446. class _Mutex : public Reference {
  447. GDCLASS(_Mutex, Reference);
  448. Mutex *mutex;
  449. static void _bind_methods();
  450. public:
  451. void lock();
  452. Error try_lock();
  453. void unlock();
  454. _Mutex();
  455. ~_Mutex();
  456. };
  457. class _Semaphore : public Reference {
  458. GDCLASS(_Semaphore, Reference);
  459. Semaphore *semaphore;
  460. static void _bind_methods();
  461. public:
  462. Error wait();
  463. Error post();
  464. _Semaphore();
  465. ~_Semaphore();
  466. };
  467. class _Thread : public Reference {
  468. GDCLASS(_Thread, Reference);
  469. protected:
  470. Variant ret;
  471. Variant userdata;
  472. volatile bool active;
  473. Object *target_instance;
  474. StringName target_method;
  475. Thread *thread;
  476. static void _bind_methods();
  477. static void _start_func(void *ud);
  478. public:
  479. enum Priority {
  480. PRIORITY_LOW,
  481. PRIORITY_NORMAL,
  482. PRIORITY_HIGH
  483. };
  484. Error start(Object *p_instance, const StringName &p_method, const Variant &p_userdata = Variant(), int p_priority = PRIORITY_NORMAL);
  485. String get_id() const;
  486. bool is_active() const;
  487. Variant wait_to_finish();
  488. _Thread();
  489. ~_Thread();
  490. };
  491. VARIANT_ENUM_CAST(_Thread::Priority);
  492. class _ClassDB : public Object {
  493. GDCLASS(_ClassDB, Object)
  494. protected:
  495. static void _bind_methods();
  496. public:
  497. PoolStringArray get_class_list() const;
  498. PoolStringArray get_inheriters_from_class(const StringName &p_class) const;
  499. StringName get_parent_class(const StringName &p_class) const;
  500. bool class_exists(const StringName &p_class) const;
  501. bool is_parent_class(const StringName &p_class, const StringName &p_inherits) const;
  502. bool can_instance(const StringName &p_class) const;
  503. Variant instance(const StringName &p_class) const;
  504. bool has_signal(StringName p_class, StringName p_signal) const;
  505. Dictionary get_signal(StringName p_class, StringName p_signal) const;
  506. Array get_signal_list(StringName p_class, bool p_no_inheritance = false) const;
  507. Array get_property_list(StringName p_class, bool p_no_inheritance = false) const;
  508. Variant get_property(Object *p_object, const StringName &p_property) const;
  509. Error set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const;
  510. bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false) const;
  511. Array get_method_list(StringName p_class, bool p_no_inheritance = false) const;
  512. PoolStringArray get_integer_constant_list(const StringName &p_class, bool p_no_inheritance = false) const;
  513. bool has_integer_constant(const StringName &p_class, const StringName &p_name) const;
  514. int get_integer_constant(const StringName &p_class, const StringName &p_name) const;
  515. StringName get_category(const StringName &p_node) const;
  516. bool is_class_enabled(StringName p_class) const;
  517. _ClassDB();
  518. ~_ClassDB();
  519. };
  520. class _Engine : public Object {
  521. GDCLASS(_Engine, Object);
  522. protected:
  523. static void _bind_methods();
  524. static _Engine *singleton;
  525. public:
  526. static _Engine *get_singleton() { return singleton; }
  527. void set_iterations_per_second(int p_ips);
  528. int get_iterations_per_second() const;
  529. void set_physics_jitter_fix(float p_threshold);
  530. float get_physics_jitter_fix() const;
  531. void set_target_fps(int p_fps);
  532. int get_target_fps() const;
  533. float get_frames_per_second() const;
  534. int get_frames_drawn();
  535. void set_time_scale(float p_scale);
  536. float get_time_scale();
  537. MainLoop *get_main_loop() const;
  538. Dictionary get_version_info() const;
  539. Dictionary get_author_info() const;
  540. Array get_copyright_info() const;
  541. Dictionary get_donor_info() const;
  542. Dictionary get_license_info() const;
  543. String get_license_text() const;
  544. bool is_in_physics_frame() const;
  545. bool has_singleton(const String &p_name) const;
  546. Object *get_singleton_object(const String &p_name) const;
  547. void set_editor_hint(bool p_enabled);
  548. bool is_editor_hint() const;
  549. _Engine();
  550. };
  551. class _JSON;
  552. class JSONParseResult : public Reference {
  553. GDCLASS(JSONParseResult, Reference)
  554. friend class _JSON;
  555. Error error;
  556. String error_string;
  557. int error_line;
  558. Variant result;
  559. protected:
  560. static void _bind_methods();
  561. public:
  562. void set_error(Error p_error);
  563. Error get_error() const;
  564. void set_error_string(const String &p_error_string);
  565. String get_error_string() const;
  566. void set_error_line(int p_error_line);
  567. int get_error_line() const;
  568. void set_result(const Variant &p_result);
  569. Variant get_result() const;
  570. };
  571. class _JSON : public Object {
  572. GDCLASS(_JSON, Object)
  573. protected:
  574. static void _bind_methods();
  575. static _JSON *singleton;
  576. public:
  577. static _JSON *get_singleton() { return singleton; }
  578. String print(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false);
  579. Ref<JSONParseResult> parse(const String &p_json);
  580. _JSON();
  581. };
  582. #endif // CORE_BIND_H