core_bind.h 23 KB

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