core_bind.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*************************************************************************/
  2. /* core_bind.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef CORE_BIND_H
  30. #define CORE_BIND_H
  31. #include "io/resource_loader.h"
  32. #include "io/resource_saver.h"
  33. #include "os/dir_access.h"
  34. #include "os/file_access.h"
  35. #include "os/power.h"
  36. #include "os/semaphore.h"
  37. #include "os/thread.h"
  38. class _ResourceLoader : public Object {
  39. GDCLASS(_ResourceLoader, Object);
  40. protected:
  41. static void _bind_methods();
  42. static _ResourceLoader *singleton;
  43. public:
  44. static _ResourceLoader *get_singleton() { return singleton; }
  45. Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = "");
  46. RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false);
  47. PoolVector<String> get_recognized_extensions_for_type(const String &p_type);
  48. void set_abort_on_missing_resources(bool p_abort);
  49. PoolStringArray get_dependencies(const String &p_path);
  50. bool has(const String &p_path);
  51. _ResourceLoader();
  52. };
  53. class _ResourceSaver : public Object {
  54. GDCLASS(_ResourceSaver, Object);
  55. protected:
  56. static void _bind_methods();
  57. static _ResourceSaver *singleton;
  58. public:
  59. enum SaverFlags {
  60. FLAG_RELATIVE_PATHS = 1,
  61. FLAG_BUNDLE_RESOURCES = 2,
  62. FLAG_CHANGE_PATH = 4,
  63. FLAG_OMIT_EDITOR_PROPERTIES = 8,
  64. FLAG_SAVE_BIG_ENDIAN = 16,
  65. FLAG_COMPRESS = 32,
  66. };
  67. static _ResourceSaver *get_singleton() { return singleton; }
  68. Error save(const String &p_path, const RES &p_resource, uint32_t p_flags);
  69. PoolVector<String> get_recognized_extensions(const RES &p_resource);
  70. _ResourceSaver();
  71. };
  72. class MainLoop;
  73. class _OS : public Object {
  74. GDCLASS(_OS, Object);
  75. protected:
  76. static void _bind_methods();
  77. static _OS *singleton;
  78. public:
  79. enum Weekday {
  80. DAY_SUNDAY,
  81. DAY_MONDAY,
  82. DAY_TUESDAY,
  83. DAY_WEDNESDAY,
  84. DAY_THURSDAY,
  85. DAY_FRIDAY,
  86. DAY_SATURDAY
  87. };
  88. enum Month {
  89. /// Start at 1 to follow Windows SYSTEMTIME structure
  90. /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
  91. MONTH_JANUARY = 1,
  92. MONTH_FEBRUARY,
  93. MONTH_MARCH,
  94. MONTH_APRIL,
  95. MONTH_MAY,
  96. MONTH_JUNE,
  97. MONTH_JULY,
  98. MONTH_AUGUST,
  99. MONTH_SEPTEMBER,
  100. MONTH_OCTOBER,
  101. MONTH_NOVEMBER,
  102. MONTH_DECEMBER
  103. };
  104. Point2 get_mouse_pos() const;
  105. void set_window_title(const String &p_title);
  106. int get_mouse_button_state() const;
  107. void set_clipboard(const String &p_text);
  108. String get_clipboard() const;
  109. void set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen = 0);
  110. Size2 get_video_mode(int p_screen = 0) const;
  111. bool is_video_mode_fullscreen(int p_screen = 0) const;
  112. bool is_video_mode_resizable(int p_screen = 0) const;
  113. Array get_fullscreen_mode_list(int p_screen = 0) const;
  114. virtual int get_screen_count() const;
  115. virtual int get_current_screen() const;
  116. virtual void set_current_screen(int p_screen);
  117. virtual Point2 get_screen_position(int p_screen = 0) const;
  118. virtual Size2 get_screen_size(int p_screen = 0) const;
  119. virtual int get_screen_dpi(int p_screen = 0) const;
  120. virtual Point2 get_window_position() const;
  121. virtual void set_window_position(const Point2 &p_position);
  122. virtual Size2 get_window_size() const;
  123. virtual void set_window_size(const Size2 &p_size);
  124. virtual void set_window_fullscreen(bool p_enabled);
  125. virtual bool is_window_fullscreen() const;
  126. virtual void set_window_resizable(bool p_enabled);
  127. virtual bool is_window_resizable() const;
  128. virtual void set_window_minimized(bool p_enabled);
  129. virtual bool is_window_minimized() const;
  130. virtual void set_window_maximized(bool p_enabled);
  131. virtual bool is_window_maximized() const;
  132. virtual void request_attention();
  133. virtual void set_borderless_window(bool p_borderless);
  134. virtual bool get_borderless_window() const;
  135. Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  136. bool native_video_is_playing();
  137. void native_video_pause();
  138. void native_video_unpause();
  139. void native_video_stop();
  140. void set_low_processor_usage_mode(bool p_enabled);
  141. bool is_in_low_processor_usage_mode() const;
  142. String get_executable_path() const;
  143. int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output = Array());
  144. Error kill(int p_pid);
  145. Error shell_open(String p_uri);
  146. int get_process_ID() const;
  147. bool has_environment(const String &p_var) const;
  148. String get_environment(const String &p_var) const;
  149. String get_name() const;
  150. Vector<String> get_cmdline_args();
  151. String get_locale() const;
  152. String get_latin_keyboard_variant() const;
  153. String get_model_name() const;
  154. void dump_memory_to_file(const String &p_file);
  155. void dump_resources_to_file(const String &p_file);
  156. bool has_virtual_keyboard() const;
  157. void show_virtual_keyboard(const String &p_existing_text = "");
  158. void hide_virtual_keyboard();
  159. void print_resources_in_use(bool p_short = false);
  160. void print_all_resources(const String &p_to_file);
  161. void print_all_textures_by_size();
  162. void print_resources_by_type(const Vector<String> &p_types);
  163. bool has_touchscreen_ui_hint() const;
  164. bool is_debug_build() const;
  165. String get_unique_ID() const;
  166. String get_scancode_string(uint32_t p_code) const;
  167. bool is_scancode_unicode(uint32_t p_unicode) const;
  168. int find_scancode_from_string(const String &p_code) const;
  169. /*
  170. struct Date {
  171. int year;
  172. Month month;
  173. int day;
  174. Weekday weekday;
  175. bool dst;
  176. };
  177. struct Time {
  178. int hour;
  179. int min;
  180. int sec;
  181. };
  182. */
  183. void set_use_file_access_save_and_swap(bool p_enable);
  184. void set_icon(const Image &p_icon);
  185. int get_exit_code() const;
  186. void set_exit_code(int p_code);
  187. Dictionary get_date(bool utc) const;
  188. Dictionary get_time(bool utc) const;
  189. Dictionary get_datetime(bool utc) const;
  190. Dictionary get_datetime_from_unix_time(uint64_t unix_time_val) const;
  191. uint64_t get_unix_time_from_datetime(Dictionary datetime) const;
  192. Dictionary get_time_zone_info() const;
  193. uint64_t get_unix_time() const;
  194. uint64_t get_system_time_secs() const;
  195. int get_static_memory_usage() const;
  196. int get_static_memory_peak_usage() const;
  197. int get_dynamic_memory_usage() const;
  198. void delay_usec(uint32_t p_usec) const;
  199. void delay_msec(uint32_t p_msec) const;
  200. uint32_t get_ticks_msec() const;
  201. uint32_t get_splash_tick_msec() const;
  202. bool can_use_threads() const;
  203. bool can_draw() const;
  204. bool is_stdout_verbose() const;
  205. int get_processor_count() const;
  206. enum SystemDir {
  207. SYSTEM_DIR_DESKTOP,
  208. SYSTEM_DIR_DCIM,
  209. SYSTEM_DIR_DOCUMENTS,
  210. SYSTEM_DIR_DOWNLOADS,
  211. SYSTEM_DIR_MOVIES,
  212. SYSTEM_DIR_MUSIC,
  213. SYSTEM_DIR_PICTURES,
  214. SYSTEM_DIR_RINGTONES,
  215. };
  216. enum ScreenOrientation {
  217. SCREEN_ORIENTATION_LANDSCAPE,
  218. SCREEN_ORIENTATION_PORTRAIT,
  219. SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
  220. SCREEN_ORIENTATION_REVERSE_PORTRAIT,
  221. SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
  222. SCREEN_ORIENTATION_SENSOR_PORTRAIT,
  223. SCREEN_ORIENTATION_SENSOR,
  224. };
  225. String get_system_dir(SystemDir p_dir) const;
  226. String get_data_dir() const;
  227. void alert(const String &p_alert, const String &p_title = "ALERT!");
  228. void set_screen_orientation(ScreenOrientation p_orientation);
  229. ScreenOrientation get_screen_orientation() const;
  230. void set_keep_screen_on(bool p_enabled);
  231. bool is_keep_screen_on() const;
  232. bool is_ok_left_and_cancel_right() const;
  233. Error set_thread_name(const String &p_name);
  234. void set_use_vsync(bool p_enable);
  235. bool is_vsync_enabled() const;
  236. PowerState get_power_state();
  237. int get_power_seconds_left();
  238. int get_power_percent_left();
  239. static _OS *get_singleton() { return singleton; }
  240. _OS();
  241. };
  242. VARIANT_ENUM_CAST(_OS::SystemDir);
  243. VARIANT_ENUM_CAST(_OS::ScreenOrientation);
  244. class _Geometry : public Object {
  245. GDCLASS(_Geometry, Object);
  246. static _Geometry *singleton;
  247. protected:
  248. static void _bind_methods();
  249. public:
  250. static _Geometry *get_singleton();
  251. PoolVector<Plane> build_box_planes(const Vector3 &p_extents);
  252. PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z);
  253. PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis = Vector3::AXIS_Z);
  254. 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);
  255. PoolVector<Vector2> get_closest_points_between_segments_2d(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2);
  256. PoolVector<Vector3> get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2);
  257. Vector2 get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  258. Vector3 get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  259. Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b);
  260. Vector3 get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b);
  261. Variant ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  262. Variant segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2);
  263. bool point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const;
  264. PoolVector<Vector3> segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius);
  265. PoolVector<Vector3> segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius);
  266. PoolVector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes);
  267. real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius);
  268. int get_uv84_normal_bit(const Vector3 &p_vector);
  269. Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon);
  270. Dictionary make_atlas(const Vector<Size2> &p_rects);
  271. _Geometry();
  272. };
  273. class _File : public Reference {
  274. GDCLASS(_File, Reference);
  275. FileAccess *f;
  276. bool eswap;
  277. protected:
  278. static void _bind_methods();
  279. public:
  280. enum ModeFlags {
  281. READ = 1,
  282. WRITE = 2,
  283. READ_WRITE = 3,
  284. WRITE_READ = 7,
  285. };
  286. Error open_encrypted(const String &p_path, int p_mode_flags, const Vector<uint8_t> &p_key);
  287. Error open_encrypted_pass(const String &p_path, int p_mode_flags, const String &p_pass);
  288. Error open(const String &p_path, int p_mode_flags); ///< open a file
  289. void close(); ///< close a file
  290. bool is_open() const; ///< true when file is open
  291. void seek(int64_t p_position); ///< seek to a given position
  292. void seek_end(int64_t p_position = 0); ///< seek from the end of file
  293. int64_t get_pos() const; ///< get position in the file
  294. int64_t get_len() const; ///< get size of the file
  295. bool eof_reached() const; ///< reading passed EOF
  296. uint8_t get_8() const; ///< get a byte
  297. uint16_t get_16() const; ///< get 16 bits uint
  298. uint32_t get_32() const; ///< get 32 bits uint
  299. uint64_t get_64() const; ///< get 64 bits uint
  300. float get_float() const;
  301. double get_double() const;
  302. real_t get_real() const;
  303. Variant get_var() const;
  304. PoolVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
  305. String get_line() const;
  306. String get_as_text() const;
  307. String get_md5(const String &p_path) const;
  308. String get_sha256(const String &p_path) const;
  309. /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
  310. * It's not about the current CPU type but file formats.
  311. * this flags get reset to false (little endian) on each open
  312. */
  313. void set_endian_swap(bool p_swap);
  314. bool get_endian_swap();
  315. Error get_error() const; ///< get last error
  316. void store_8(uint8_t p_dest); ///< store a byte
  317. void store_16(uint16_t p_dest); ///< store 16 bits uint
  318. void store_32(uint32_t p_dest); ///< store 32 bits uint
  319. void store_64(uint64_t p_dest); ///< store 64 bits uint
  320. void store_float(float p_dest);
  321. void store_double(double p_dest);
  322. void store_real(real_t p_real);
  323. void store_string(const String &p_string);
  324. void store_line(const String &p_string);
  325. virtual void store_pascal_string(const String &p_string);
  326. virtual String get_pascal_string();
  327. Vector<String> get_csv_line(String delim = ",") const;
  328. void store_buffer(const PoolVector<uint8_t> &p_buffer); ///< store an array of bytes
  329. void store_var(const Variant &p_var);
  330. bool file_exists(const String &p_name) const; ///< return true if a file exists
  331. uint64_t get_modified_time(const String &p_file) const;
  332. _File();
  333. virtual ~_File();
  334. };
  335. class _Directory : public Reference {
  336. GDCLASS(_Directory, Reference);
  337. DirAccess *d;
  338. protected:
  339. static void _bind_methods();
  340. public:
  341. Error open(const String &p_path);
  342. Error list_dir_begin(bool p_skip_internal = false, bool p_skip_hidden = false); ///< This starts dir listing
  343. String get_next();
  344. bool current_is_dir() const;
  345. void list_dir_end(); ///<
  346. int get_drive_count();
  347. String get_drive(int p_drive);
  348. int get_current_drive();
  349. Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
  350. String get_current_dir(); ///< return current dir location
  351. Error make_dir(String p_dir);
  352. Error make_dir_recursive(String p_dir);
  353. bool file_exists(String p_file);
  354. bool dir_exists(String p_dir);
  355. int get_space_left();
  356. Error copy(String p_from, String p_to);
  357. Error rename(String p_from, String p_to);
  358. Error remove(String p_name);
  359. _Directory();
  360. virtual ~_Directory();
  361. private:
  362. bool _list_skip_navigational;
  363. bool _list_skip_hidden;
  364. };
  365. class _Marshalls : public Reference {
  366. GDCLASS(_Marshalls, Reference);
  367. static _Marshalls *singleton;
  368. protected:
  369. static void _bind_methods();
  370. public:
  371. static _Marshalls *get_singleton();
  372. String variant_to_base64(const Variant &p_var);
  373. Variant base64_to_variant(const String &p_str);
  374. String raw_to_base64(const PoolVector<uint8_t> &p_arr);
  375. PoolVector<uint8_t> base64_to_raw(const String &p_str);
  376. String utf8_to_base64(const String &p_str);
  377. String base64_to_utf8(const String &p_str);
  378. _Marshalls() { singleton = this; }
  379. ~_Marshalls() { singleton = NULL; }
  380. };
  381. class _Mutex : public Reference {
  382. GDCLASS(_Mutex, Reference);
  383. Mutex *mutex;
  384. static void _bind_methods();
  385. public:
  386. void lock();
  387. Error try_lock();
  388. void unlock();
  389. _Mutex();
  390. ~_Mutex();
  391. };
  392. class _Semaphore : public Reference {
  393. GDCLASS(_Semaphore, Reference);
  394. Semaphore *semaphore;
  395. static void _bind_methods();
  396. public:
  397. Error wait();
  398. Error post();
  399. _Semaphore();
  400. ~_Semaphore();
  401. };
  402. class _Thread : public Reference {
  403. GDCLASS(_Thread, Reference);
  404. protected:
  405. Variant ret;
  406. Variant userdata;
  407. volatile bool active;
  408. Object *target_instance;
  409. StringName target_method;
  410. Thread *thread;
  411. static void _bind_methods();
  412. static void _start_func(void *ud);
  413. public:
  414. enum Priority {
  415. PRIORITY_LOW,
  416. PRIORITY_NORMAL,
  417. PRIORITY_HIGH
  418. };
  419. Error start(Object *p_instance, const StringName &p_method, const Variant &p_userdata = Variant(), int p_priority = PRIORITY_NORMAL);
  420. String get_id() const;
  421. bool is_active() const;
  422. Variant wait_to_finish();
  423. _Thread();
  424. ~_Thread();
  425. };
  426. class _ClassDB : public Object {
  427. GDCLASS(_ClassDB, Object)
  428. protected:
  429. static void _bind_methods();
  430. public:
  431. PoolStringArray get_class_list() const;
  432. PoolStringArray get_inheriters_from_class(const StringName &p_class) const;
  433. StringName get_parent_class(const StringName &p_class) const;
  434. bool class_exists(const StringName &p_class) const;
  435. bool is_parent_class(const StringName &p_class, const StringName &p_inherits) const;
  436. bool can_instance(const StringName &p_class) const;
  437. Variant instance(const StringName &p_class) const;
  438. bool has_signal(StringName p_class, StringName p_signal) const;
  439. Dictionary get_signal(StringName p_class, StringName p_signal) const;
  440. Array get_signal_list(StringName p_class, bool p_no_inheritance = false) const;
  441. Array get_property_list(StringName p_class, bool p_no_inheritance = false) const;
  442. bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false) const;
  443. Array get_method_list(StringName p_class, bool p_no_inheritance = false) const;
  444. PoolStringArray get_integer_constant_list(const StringName &p_class, bool p_no_inheritance = false) const;
  445. bool has_integer_constant(const StringName &p_class, const StringName &p_name) const;
  446. int get_integer_constant(const StringName &p_class, const StringName &p_name) const;
  447. StringName get_category(const StringName &p_node) const;
  448. bool is_class_enabled(StringName p_class) const;
  449. _ClassDB();
  450. ~_ClassDB();
  451. };
  452. class _Engine : public Object {
  453. GDCLASS(_Engine, Object);
  454. protected:
  455. static void _bind_methods();
  456. static _Engine *singleton;
  457. public:
  458. static _Engine *get_singleton() { return singleton; }
  459. void set_iterations_per_second(int p_ips);
  460. int get_iterations_per_second() const;
  461. void set_target_fps(int p_fps);
  462. float get_target_fps() const;
  463. float get_frames_per_second() const;
  464. int get_frames_drawn();
  465. void set_time_scale(float p_scale);
  466. float get_time_scale();
  467. String get_custom_level() const;
  468. MainLoop *get_main_loop() const;
  469. Dictionary get_version_info() const;
  470. _Engine();
  471. };
  472. #endif // CORE_BIND_H