core_bind.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. #ifndef CORE_BIND_H
  2. #define CORE_BIND_H
  3. #include "io/resource_loader.h"
  4. #include "io/resource_saver.h"
  5. #include "os/file_access.h"
  6. #include "os/dir_access.h"
  7. #include "os/thread.h"
  8. #include "os/semaphore.h"
  9. class _ResourceLoader : public Object {
  10. OBJ_TYPE(_ResourceLoader,Object);
  11. protected:
  12. static void _bind_methods();
  13. static _ResourceLoader *singleton;
  14. public:
  15. static _ResourceLoader *get_singleton() { return singleton; }
  16. Ref<ResourceInteractiveLoader> load_interactive(const String& p_path,const String& p_type_hint="");
  17. RES load(const String &p_path,const String& p_type_hint="", bool p_no_cache = false);
  18. DVector<String> get_recognized_extensions_for_type(const String& p_type);
  19. void set_abort_on_missing_resources(bool p_abort);
  20. StringArray get_dependencies(const String& p_path);
  21. bool has(const String& p_path);
  22. _ResourceLoader();
  23. };
  24. class _ResourceSaver : public Object {
  25. OBJ_TYPE(_ResourceSaver,Object);
  26. protected:
  27. static void _bind_methods();
  28. static _ResourceSaver *singleton;
  29. public:
  30. enum SaverFlags {
  31. FLAG_RELATIVE_PATHS=1,
  32. FLAG_BUNDLE_RESOURCES=2,
  33. FLAG_CHANGE_PATH=4,
  34. FLAG_OMIT_EDITOR_PROPERTIES=8,
  35. FLAG_SAVE_BIG_ENDIAN=16,
  36. FLAG_COMPRESS=32,
  37. };
  38. static _ResourceSaver *get_singleton() { return singleton; }
  39. Error save(const String &p_path,const RES& p_resource, uint32_t p_flags);
  40. DVector<String> get_recognized_extensions(const RES& p_resource);
  41. _ResourceSaver();
  42. };
  43. class MainLoop;
  44. class _OS : public Object {
  45. OBJ_TYPE(_OS,Object);
  46. protected:
  47. static void _bind_methods();
  48. static _OS *singleton;
  49. public:
  50. enum Weekday {
  51. DAY_SUNDAY,
  52. DAY_MONDAY,
  53. DAY_TUESDAY,
  54. DAY_WEDNESDAY,
  55. DAY_THURSDAY,
  56. DAY_FRIDAY,
  57. DAY_SATURDAY
  58. };
  59. enum Month {
  60. MONTH_JANUARY,
  61. MONTH_FEBRUARY,
  62. MONTH_MARCH,
  63. MONTH_APRIL,
  64. MONTH_MAY,
  65. MONTH_JUNE,
  66. MONTH_JULY,
  67. MONTH_AUGUST,
  68. MONTH_SEPTEMBER,
  69. MONTH_OCTOBER,
  70. MONTH_NOVEMBER,
  71. MONTH_DECEMBER
  72. };
  73. Point2 get_mouse_pos() const;
  74. void set_window_title(const String& p_title);
  75. int get_mouse_button_state() const;
  76. void set_clipboard(const String& p_text);
  77. String get_clipboard() const;
  78. void set_video_mode(const Size2& p_size, bool p_fullscreen,bool p_resizeable,int p_screen=0);
  79. Size2 get_video_mode(int p_screen=0) const;
  80. bool is_video_mode_fullscreen(int p_screen=0) const;
  81. bool is_video_mode_resizable(int p_screen=0) const;
  82. Array get_fullscreen_mode_list(int p_screen=0) const;
  83. virtual int get_screen_count() const;
  84. virtual int get_current_screen() const;
  85. virtual void set_current_screen(int p_screen);
  86. virtual Point2 get_screen_position(int p_screen=0) const;
  87. virtual Size2 get_screen_size(int p_screen=0) const;
  88. virtual Point2 get_window_position() const;
  89. virtual void set_window_position(const Point2& p_position);
  90. virtual Size2 get_window_size() const;
  91. virtual void set_window_size(const Size2& p_size);
  92. virtual void set_window_fullscreen(bool p_enabled);
  93. virtual bool is_window_fullscreen() const;
  94. virtual void set_window_resizable(bool p_enabled);
  95. virtual bool is_window_resizable() const;
  96. virtual void set_window_minimized(bool p_enabled);
  97. virtual bool is_window_minimized() const;
  98. virtual void set_window_maximized(bool p_enabled);
  99. virtual bool is_window_maximized() const;
  100. Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  101. bool native_video_is_playing();
  102. void native_video_pause();
  103. void native_video_stop();
  104. void set_iterations_per_second(int p_ips);
  105. int get_iterations_per_second() const;
  106. void set_target_fps(int p_fps);
  107. float get_target_fps() const;
  108. void set_low_processor_usage_mode(bool p_enabled);
  109. bool is_in_low_processor_usage_mode() const;
  110. String get_executable_path() const;
  111. int execute(const String& p_path, const Vector<String> & p_arguments,bool p_blocking,Array p_output=Array());
  112. Error kill(int p_pid);
  113. Error shell_open(String p_uri);
  114. int get_process_ID() const;
  115. bool has_environment(const String& p_var) const;
  116. String get_environment(const String& p_var) const;
  117. String get_name() const;
  118. Vector<String> get_cmdline_args();
  119. String get_locale() const;
  120. String get_model_name() const;
  121. MainLoop *get_main_loop() const;
  122. String get_custom_level() const;
  123. float get_frames_per_second() const;
  124. void dump_memory_to_file(const String& p_file);
  125. void dump_resources_to_file(const String& p_file);
  126. void print_resources_in_use(bool p_short=false);
  127. void print_all_resources(const String& p_to_file);
  128. void print_all_textures_by_size();
  129. void print_resources_by_type(const Vector<String>& p_types);
  130. bool has_touchscreen_ui_hint() const;
  131. bool is_debug_build() const;
  132. String get_unique_ID() const;
  133. String get_scancode_string(uint32_t p_code) const;
  134. bool is_scancode_unicode(uint32_t p_unicode) const;
  135. int find_scancode_from_string(const String& p_code) const;
  136. /*
  137. struct Date {
  138. int year;
  139. Month month;
  140. int day;
  141. Weekday weekday;
  142. bool dst;
  143. };
  144. struct Time {
  145. int hour;
  146. int min;
  147. int sec;
  148. };
  149. */
  150. void set_use_file_access_save_and_swap(bool p_enable);
  151. void set_icon(const Image& p_icon);
  152. Dictionary get_date() const;
  153. Dictionary get_time() const;
  154. uint64_t get_unix_time() const;
  155. int get_static_memory_usage() const;
  156. int get_static_memory_peak_usage() const;
  157. int get_dynamic_memory_usage() const;
  158. void delay_usec(uint32_t p_usec) const;
  159. void delay_msec(uint32_t p_msec) const;
  160. uint32_t get_ticks_msec() const;
  161. uint32_t get_splash_tick_msec() const;
  162. bool can_use_threads() const;
  163. bool can_draw() const;
  164. int get_frames_drawn();
  165. bool is_stdout_verbose() const;
  166. int get_processor_count() const;
  167. enum SystemDir {
  168. SYSTEM_DIR_DESKTOP,
  169. SYSTEM_DIR_DCIM,
  170. SYSTEM_DIR_DOCUMENTS,
  171. SYSTEM_DIR_DOWNLOADS,
  172. SYSTEM_DIR_MOVIES,
  173. SYSTEM_DIR_MUSIC,
  174. SYSTEM_DIR_PICTURES,
  175. SYSTEM_DIR_RINGTONES,
  176. };
  177. String get_system_dir(SystemDir p_dir) const;
  178. String get_data_dir() const;
  179. void set_time_scale(float p_scale);
  180. float get_time_scale();
  181. bool is_ok_left_and_cancel_right() const;
  182. static _OS *get_singleton() { return singleton; }
  183. _OS();
  184. };
  185. VARIANT_ENUM_CAST(_OS::SystemDir);
  186. class _Geometry : public Object {
  187. OBJ_TYPE(_Geometry, Object);
  188. static _Geometry *singleton;
  189. protected:
  190. static void _bind_methods();
  191. public:
  192. static _Geometry *get_singleton();
  193. DVector<Plane> build_box_planes(const Vector3& p_extents);
  194. DVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
  195. DVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
  196. 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);
  197. DVector<Vector2> get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2);
  198. DVector<Vector3> get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2);
  199. Vector3 get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b);
  200. Variant ray_intersects_triangle( const Vector3& p_from, const Vector3& p_dir, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
  201. Variant segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
  202. bool point_is_inside_triangle(const Vector2& s, const Vector2& a, const Vector2& b, const Vector2& c) const;
  203. DVector<Vector3> segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius);
  204. DVector<Vector3> segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius);
  205. DVector<Vector3> segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes);
  206. real_t segment_intersects_circle(const Vector2& p_from, const Vector2& p_to, const Vector2& p_circle_pos, real_t p_circle_radius);
  207. int get_uv84_normal_bit(const Vector3& p_vector);
  208. Vector<int> triangulate_polygon(const Vector<Vector2>& p_polygon);
  209. Dictionary make_atlas(const Vector<Size2>& p_rects);
  210. _Geometry();
  211. };
  212. class _File : public Reference {
  213. OBJ_TYPE(_File,Reference);
  214. FileAccess *f;
  215. bool eswap;
  216. protected:
  217. static void _bind_methods();
  218. public:
  219. enum ModeFlags {
  220. READ=1,
  221. WRITE=2,
  222. READ_WRITE=3,
  223. };
  224. Error open_encrypted(const String& p_path, int p_mode_flags,const Vector<uint8_t>& p_key);
  225. Error open_encrypted_pass(const String& p_path, int p_mode_flags,const String& p_pass);
  226. Error open(const String& p_path, int p_mode_flags); ///< open a file
  227. void close(); ///< close a file
  228. bool is_open() const; ///< true when file is open
  229. void seek(int64_t p_position); ///< seek to a given position
  230. void seek_end(int64_t p_position=0); ///< seek from the end of file
  231. int64_t get_pos() const; ///< get position in the file
  232. int64_t get_len() const; ///< get size of the file
  233. bool eof_reached() const; ///< reading passed EOF
  234. uint8_t get_8() const; ///< get a byte
  235. uint16_t get_16() const; ///< get 16 bits uint
  236. uint32_t get_32() const; ///< get 32 bits uint
  237. uint64_t get_64() const; ///< get 64 bits uint
  238. float get_float() const;
  239. double get_double() const;
  240. real_t get_real() const;
  241. Variant get_var() const;
  242. DVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
  243. String get_line() const;
  244. String get_as_text() const;
  245. /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
  246. * It's not about the current CPU type but file formats.
  247. * this flags get reset to false (little endian) on each open
  248. */
  249. void set_endian_swap(bool p_swap);
  250. bool get_endian_swap();
  251. Error get_error() const; ///< get last error
  252. void store_8(uint8_t p_dest); ///< store a byte
  253. void store_16(uint16_t p_dest); ///< store 16 bits uint
  254. void store_32(uint32_t p_dest); ///< store 32 bits uint
  255. void store_64(uint64_t p_dest); ///< store 64 bits uint
  256. void store_float(float p_dest);
  257. void store_double(double p_dest);
  258. void store_real(real_t p_real);
  259. void store_string(const String& p_string);
  260. void store_line(const String& p_string);
  261. virtual void store_pascal_string(const String& p_string);
  262. virtual String get_pascal_string();
  263. Vector<String> get_csv_line() const;
  264. void store_buffer(const DVector<uint8_t>& p_buffer); ///< store an array of bytes
  265. void store_var(const Variant& p_var);
  266. bool file_exists(const String& p_name) const; ///< return true if a file exists
  267. _File();
  268. virtual ~_File();
  269. };
  270. class _Directory : public Reference {
  271. OBJ_TYPE(_Directory,Reference);
  272. DirAccess *d;
  273. protected:
  274. static void _bind_methods();
  275. public:
  276. Error open(const String& p_path);
  277. bool list_dir_begin(); ///< This starts dir listing
  278. String get_next();
  279. bool current_is_dir() const;
  280. void list_dir_end(); ///<
  281. int get_drive_count();
  282. String get_drive(int p_drive);
  283. Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
  284. String get_current_dir(); ///< return current dir location
  285. Error make_dir(String p_dir);
  286. Error make_dir_recursive(String p_dir);
  287. bool file_exists(String p_file);
  288. bool dir_exists(String p_dir);
  289. int get_space_left();
  290. Error copy(String p_from,String p_to);
  291. Error rename(String p_from, String p_to);
  292. Error remove(String p_name);
  293. _Directory();
  294. virtual ~_Directory();
  295. };
  296. class _Marshalls : public Reference {
  297. OBJ_TYPE(_Marshalls,Reference);
  298. protected:
  299. static void _bind_methods();
  300. public:
  301. String variant_to_base64(const Variant& p_var);
  302. Variant base64_to_variant(const String& p_str);
  303. _Marshalls() {};
  304. };
  305. class _Mutex : public Reference {
  306. OBJ_TYPE(_Mutex,Reference);
  307. Mutex *mutex;
  308. static void _bind_methods();
  309. public:
  310. void lock();
  311. Error try_lock();
  312. void unlock();
  313. _Mutex();
  314. ~_Mutex();
  315. };
  316. class _Semaphore : public Reference {
  317. OBJ_TYPE(_Semaphore,Reference);
  318. Semaphore *semaphore;
  319. static void _bind_methods();
  320. public:
  321. Error wait();
  322. Error post();
  323. _Semaphore();
  324. ~_Semaphore();
  325. };
  326. class _Thread : public Reference {
  327. OBJ_TYPE(_Thread,Reference);
  328. protected:
  329. Variant ret;
  330. Variant userdata;
  331. volatile bool active;
  332. Object *target_instance;
  333. StringName target_method;
  334. Thread *thread;
  335. static void _bind_methods();
  336. static void _start_func(void *ud);
  337. public:
  338. enum Priority {
  339. PRIORITY_LOW,
  340. PRIORITY_NORMAL,
  341. PRIORITY_HIGH
  342. };
  343. Error start(Object *p_instance,const StringName& p_method,const Variant& p_userdata=Variant(),int p_priority=PRIORITY_NORMAL);
  344. String get_id() const;
  345. bool is_active() const;
  346. Variant wait_to_finish();
  347. _Thread();
  348. ~_Thread();
  349. };
  350. #endif // CORE_BIND_H