2
0

core_bind.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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/file_access.h"
  34. #include "os/dir_access.h"
  35. #include "os/thread.h"
  36. #include "os/semaphore.h"
  37. class _ResourceLoader : public Object {
  38. GDCLASS(_ResourceLoader,Object);
  39. protected:
  40. static void _bind_methods();
  41. static _ResourceLoader *singleton;
  42. public:
  43. static _ResourceLoader *get_singleton() { return singleton; }
  44. Ref<ResourceInteractiveLoader> load_interactive(const String& p_path,const String& p_type_hint="");
  45. RES load(const String &p_path,const String& p_type_hint="", bool p_no_cache = false);
  46. DVector<String> get_recognized_extensions_for_type(const String& p_type);
  47. void set_abort_on_missing_resources(bool p_abort);
  48. StringArray get_dependencies(const String& p_path);
  49. bool has(const String& p_path);
  50. Ref<ResourceImportMetadata> load_import_metadata(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. DVector<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_iterations_per_second(int p_ips);
  141. int get_iterations_per_second() const;
  142. void set_target_fps(int p_fps);
  143. float get_target_fps() const;
  144. void set_low_processor_usage_mode(bool p_enabled);
  145. bool is_in_low_processor_usage_mode() const;
  146. String get_executable_path() const;
  147. int execute(const String& p_path, const Vector<String> & p_arguments,bool p_blocking,Array p_output=Array());
  148. Error kill(int p_pid);
  149. Error shell_open(String p_uri);
  150. int get_process_ID() const;
  151. bool has_environment(const String& p_var) const;
  152. String get_environment(const String& p_var) const;
  153. String get_name() const;
  154. Vector<String> get_cmdline_args();
  155. String get_locale() const;
  156. String get_latin_keyboard_variant() const;
  157. String get_model_name() const;
  158. MainLoop *get_main_loop() const;
  159. String get_custom_level() const;
  160. float get_frames_per_second() const;
  161. void dump_memory_to_file(const String& p_file);
  162. void dump_resources_to_file(const String& p_file);
  163. bool has_virtual_keyboard() const;
  164. void show_virtual_keyboard(const String& p_existing_text="");
  165. void hide_virtual_keyboard();
  166. void print_resources_in_use(bool p_short=false);
  167. void print_all_resources(const String& p_to_file);
  168. void print_all_textures_by_size();
  169. void print_resources_by_type(const Vector<String>& p_types);
  170. bool has_touchscreen_ui_hint() const;
  171. bool is_debug_build() const;
  172. String get_unique_ID() const;
  173. String get_scancode_string(uint32_t p_code) const;
  174. bool is_scancode_unicode(uint32_t p_unicode) const;
  175. int find_scancode_from_string(const String& p_code) const;
  176. /*
  177. struct Date {
  178. int year;
  179. Month month;
  180. int day;
  181. Weekday weekday;
  182. bool dst;
  183. };
  184. struct Time {
  185. int hour;
  186. int min;
  187. int sec;
  188. };
  189. */
  190. void set_use_file_access_save_and_swap(bool p_enable);
  191. void set_icon(const Image& p_icon);
  192. Dictionary get_date(bool utc) const;
  193. Dictionary get_time(bool utc) const;
  194. Dictionary get_datetime(bool utc) const;
  195. Dictionary get_datetime_from_unix_time(uint64_t unix_time_val) const;
  196. uint64_t get_unix_time_from_datetime(Dictionary datetime) const;
  197. Dictionary get_time_zone_info() const;
  198. uint64_t get_unix_time() const;
  199. uint64_t get_system_time_secs() const;
  200. int get_static_memory_usage() const;
  201. int get_static_memory_peak_usage() const;
  202. int get_dynamic_memory_usage() const;
  203. void delay_usec(uint32_t p_usec) const;
  204. void delay_msec(uint32_t p_msec) const;
  205. uint32_t get_ticks_msec() const;
  206. uint32_t get_splash_tick_msec() const;
  207. bool can_use_threads() const;
  208. bool can_draw() const;
  209. int get_frames_drawn();
  210. bool is_stdout_verbose() const;
  211. int get_processor_count() const;
  212. enum SystemDir {
  213. SYSTEM_DIR_DESKTOP,
  214. SYSTEM_DIR_DCIM,
  215. SYSTEM_DIR_DOCUMENTS,
  216. SYSTEM_DIR_DOWNLOADS,
  217. SYSTEM_DIR_MOVIES,
  218. SYSTEM_DIR_MUSIC,
  219. SYSTEM_DIR_PICTURES,
  220. SYSTEM_DIR_RINGTONES,
  221. };
  222. enum ScreenOrientation {
  223. SCREEN_ORIENTATION_LANDSCAPE,
  224. SCREEN_ORIENTATION_PORTRAIT,
  225. SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
  226. SCREEN_ORIENTATION_REVERSE_PORTRAIT,
  227. SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
  228. SCREEN_ORIENTATION_SENSOR_PORTRAIT,
  229. SCREEN_ORIENTATION_SENSOR,
  230. };
  231. String get_system_dir(SystemDir p_dir) const;
  232. String get_data_dir() const;
  233. void alert(const String& p_alert,const String& p_title="ALERT!");
  234. void set_screen_orientation(ScreenOrientation p_orientation);
  235. ScreenOrientation get_screen_orientation() const;
  236. void set_keep_screen_on(bool p_enabled);
  237. bool is_keep_screen_on() const;
  238. void set_time_scale(float p_scale);
  239. float get_time_scale();
  240. bool is_ok_left_and_cancel_right() const;
  241. Error set_thread_name(const String& p_name);
  242. void set_use_vsync(bool p_enable);
  243. bool is_vsync_enabled() const;
  244. Dictionary get_engine_version() const;
  245. static _OS *get_singleton() { return singleton; }
  246. _OS();
  247. };
  248. VARIANT_ENUM_CAST(_OS::SystemDir);
  249. VARIANT_ENUM_CAST(_OS::ScreenOrientation);
  250. class _Geometry : public Object {
  251. GDCLASS(_Geometry, Object);
  252. static _Geometry *singleton;
  253. protected:
  254. static void _bind_methods();
  255. public:
  256. static _Geometry *get_singleton();
  257. DVector<Plane> build_box_planes(const Vector3& p_extents);
  258. DVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
  259. DVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
  260. 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);
  261. DVector<Vector2> get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2);
  262. DVector<Vector3> get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2);
  263. Vector3 get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b);
  264. Variant ray_intersects_triangle( const Vector3& p_from, const Vector3& p_dir, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
  265. Variant segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
  266. bool point_is_inside_triangle(const Vector2& s, const Vector2& a, const Vector2& b, const Vector2& c) const;
  267. DVector<Vector3> segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius);
  268. DVector<Vector3> segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius);
  269. DVector<Vector3> segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes);
  270. real_t segment_intersects_circle(const Vector2& p_from, const Vector2& p_to, const Vector2& p_circle_pos, real_t p_circle_radius);
  271. int get_uv84_normal_bit(const Vector3& p_vector);
  272. Vector<int> triangulate_polygon(const Vector<Vector2>& p_polygon);
  273. Dictionary make_atlas(const Vector<Size2>& p_rects);
  274. _Geometry();
  275. };
  276. class _File : public Reference {
  277. GDCLASS(_File,Reference);
  278. FileAccess *f;
  279. bool eswap;
  280. protected:
  281. static void _bind_methods();
  282. public:
  283. enum ModeFlags {
  284. READ=1,
  285. WRITE=2,
  286. READ_WRITE=3,
  287. WRITE_READ=7,
  288. };
  289. Error open_encrypted(const String& p_path, int p_mode_flags,const Vector<uint8_t>& p_key);
  290. Error open_encrypted_pass(const String& p_path, int p_mode_flags,const String& p_pass);
  291. Error open(const String& p_path, int p_mode_flags); ///< open a file
  292. void close(); ///< close a file
  293. bool is_open() const; ///< true when file is open
  294. void seek(int64_t p_position); ///< seek to a given position
  295. void seek_end(int64_t p_position=0); ///< seek from the end of file
  296. int64_t get_pos() const; ///< get position in the file
  297. int64_t get_len() const; ///< get size of the file
  298. bool eof_reached() const; ///< reading passed EOF
  299. uint8_t get_8() const; ///< get a byte
  300. uint16_t get_16() const; ///< get 16 bits uint
  301. uint32_t get_32() const; ///< get 32 bits uint
  302. uint64_t get_64() const; ///< get 64 bits uint
  303. float get_float() const;
  304. double get_double() const;
  305. real_t get_real() const;
  306. Variant get_var() const;
  307. DVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
  308. String get_line() const;
  309. String get_as_text() const;
  310. String get_md5(const String& p_path) const;
  311. String get_sha256(const String& p_path) const;
  312. /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
  313. * It's not about the current CPU type but file formats.
  314. * this flags get reset to false (little endian) on each open
  315. */
  316. void set_endian_swap(bool p_swap);
  317. bool get_endian_swap();
  318. Error get_error() const; ///< get last error
  319. void store_8(uint8_t p_dest); ///< store a byte
  320. void store_16(uint16_t p_dest); ///< store 16 bits uint
  321. void store_32(uint32_t p_dest); ///< store 32 bits uint
  322. void store_64(uint64_t p_dest); ///< store 64 bits uint
  323. void store_float(float p_dest);
  324. void store_double(double p_dest);
  325. void store_real(real_t p_real);
  326. void store_string(const String& p_string);
  327. void store_line(const String& p_string);
  328. virtual void store_pascal_string(const String& p_string);
  329. virtual String get_pascal_string();
  330. Vector<String> get_csv_line(String delim=",") const;
  331. void store_buffer(const DVector<uint8_t>& p_buffer); ///< store an array of bytes
  332. void store_var(const Variant& p_var);
  333. bool file_exists(const String& p_name) const; ///< return true if a file exists
  334. _File();
  335. virtual ~_File();
  336. };
  337. class _Directory : public Reference {
  338. GDCLASS(_Directory,Reference);
  339. DirAccess *d;
  340. protected:
  341. static void _bind_methods();
  342. public:
  343. Error open(const String& p_path);
  344. bool list_dir_begin(); ///< This starts dir listing
  345. String get_next();
  346. bool current_is_dir() const;
  347. void list_dir_end(); ///<
  348. int get_drive_count();
  349. String get_drive(int p_drive);
  350. Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
  351. String get_current_dir(); ///< return current dir location
  352. Error make_dir(String p_dir);
  353. Error make_dir_recursive(String p_dir);
  354. bool file_exists(String p_file);
  355. bool dir_exists(String p_dir);
  356. int get_space_left();
  357. Error copy(String p_from,String p_to);
  358. Error rename(String p_from, String p_to);
  359. Error remove(String p_name);
  360. _Directory();
  361. virtual ~_Directory();
  362. };
  363. class _Marshalls : public Reference {
  364. GDCLASS(_Marshalls,Reference);
  365. static _Marshalls* singleton;
  366. protected:
  367. static void _bind_methods();
  368. public:
  369. static _Marshalls* get_singleton();
  370. String variant_to_base64(const Variant& p_var);
  371. Variant base64_to_variant(const String& p_str);
  372. String raw_to_base64(const DVector<uint8_t>& p_arr);
  373. DVector<uint8_t> base64_to_raw(const String& p_str);
  374. String utf8_to_base64(const String& p_str);
  375. String base64_to_utf8(const String& p_str);
  376. _Marshalls() { singleton = this; }
  377. ~_Marshalls() { singleton = NULL; }
  378. };
  379. class _Mutex : public Reference {
  380. GDCLASS(_Mutex,Reference);
  381. Mutex *mutex;
  382. static void _bind_methods();
  383. public:
  384. void lock();
  385. Error try_lock();
  386. void unlock();
  387. _Mutex();
  388. ~_Mutex();
  389. };
  390. class _Semaphore : public Reference {
  391. GDCLASS(_Semaphore,Reference);
  392. Semaphore *semaphore;
  393. static void _bind_methods();
  394. public:
  395. Error wait();
  396. Error post();
  397. _Semaphore();
  398. ~_Semaphore();
  399. };
  400. class _Thread : public Reference {
  401. GDCLASS(_Thread,Reference);
  402. protected:
  403. Variant ret;
  404. Variant userdata;
  405. volatile bool active;
  406. Object *target_instance;
  407. StringName target_method;
  408. Thread *thread;
  409. static void _bind_methods();
  410. static void _start_func(void *ud);
  411. public:
  412. enum Priority {
  413. PRIORITY_LOW,
  414. PRIORITY_NORMAL,
  415. PRIORITY_HIGH
  416. };
  417. Error start(Object *p_instance,const StringName& p_method,const Variant& p_userdata=Variant(),int p_priority=PRIORITY_NORMAL);
  418. String get_id() const;
  419. bool is_active() const;
  420. Variant wait_to_finish();
  421. _Thread();
  422. ~_Thread();
  423. };
  424. class _ClassDB : public Object {
  425. GDCLASS(_ClassDB,Object)
  426. protected:
  427. static void _bind_methods();
  428. public:
  429. StringArray get_class_list() const;
  430. StringArray get_inheriters_from_class( const StringName& p_class) const;
  431. StringName get_parent_class(const StringName& p_class) const;
  432. bool class_exists(const StringName &p_class) const;
  433. bool is_parent_class(const StringName &p_class,const StringName& p_inherits) const;
  434. bool can_instance(const StringName &p_class) const;
  435. Variant instance(const StringName &p_class) const;
  436. bool has_signal(StringName p_class,StringName p_signal) const;
  437. Dictionary get_signal(StringName p_class,StringName p_signal) const;
  438. Array get_signal_list(StringName p_class,bool p_no_inheritance=false) const;
  439. Array get_property_list(StringName p_class, bool p_no_inheritance=false) const;
  440. bool has_method(StringName p_class,StringName p_method,bool p_no_inheritance=false) const;
  441. Array get_method_list(StringName p_class,bool p_no_inheritance=false) const;
  442. StringArray get_integer_constant_list(const StringName& p_class, bool p_no_inheritance=false) const;
  443. bool has_integer_constant(const StringName& p_class, const StringName &p_name) const;
  444. int get_integer_constant(const StringName& p_class, const StringName &p_name) const;
  445. StringName get_category(const StringName& p_node) const;
  446. bool is_class_enabled(StringName p_class) const;
  447. _ClassDB();
  448. ~_ClassDB();
  449. };
  450. #endif // CORE_BIND_H