core_bind.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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="");
  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. Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  84. bool native_video_is_playing();
  85. void native_video_pause();
  86. void native_video_stop();
  87. void set_iterations_per_second(int p_ips);
  88. int get_iterations_per_second() const;
  89. void set_target_fps(int p_fps);
  90. float get_target_fps() const;
  91. void set_low_processor_usage_mode(bool p_enabled);
  92. bool is_in_low_processor_usage_mode() const;
  93. String get_executable_path() const;
  94. int execute(const String& p_path, const Vector<String> & p_arguments,bool p_blocking,Array p_output=Array());
  95. Error kill(int p_pid);
  96. Error shell_open(String p_uri);
  97. int get_process_ID() const;
  98. bool has_environment(const String& p_var) const;
  99. String get_environment(const String& p_var) const;
  100. String get_name() const;
  101. Vector<String> get_cmdline_args();
  102. String get_locale() const;
  103. String get_model_name() const;
  104. MainLoop *get_main_loop() const;
  105. String get_custom_level() const;
  106. float get_frames_per_second() const;
  107. void dump_memory_to_file(const String& p_file);
  108. void dump_resources_to_file(const String& p_file);
  109. void print_resources_in_use(bool p_short=false);
  110. void print_all_resources(const String& p_to_file);
  111. void print_all_textures_by_size();
  112. void print_resources_by_type(const Vector<String>& p_types);
  113. bool has_touchscreen_ui_hint() const;
  114. bool is_debug_build() const;
  115. String get_unique_ID() const;
  116. /*
  117. struct Date {
  118. int year;
  119. Month month;
  120. int day;
  121. Weekday weekday;
  122. bool dst;
  123. };
  124. struct Time {
  125. int hour;
  126. int min;
  127. int sec;
  128. };
  129. */
  130. void set_use_file_access_save_and_swap(bool p_enable);
  131. void set_icon(const Image& p_icon);
  132. Dictionary get_date() const;
  133. Dictionary get_time() const;
  134. uint64_t get_unix_time() const;
  135. int get_static_memory_usage() const;
  136. int get_static_memory_peak_usage() const;
  137. int get_dynamic_memory_usage() const;
  138. void delay_usec(uint32_t p_usec) const;
  139. void delay_msec(uint32_t p_msec) const;
  140. uint32_t get_ticks_msec() const;
  141. bool can_use_threads() const;
  142. bool can_draw() const;
  143. int get_frames_drawn();
  144. bool is_stdout_verbose() const;
  145. int get_processor_count() const;
  146. String get_data_dir() const;
  147. void set_time_scale(float p_scale);
  148. float get_time_scale();
  149. static _OS *get_singleton() { return singleton; }
  150. _OS();
  151. };
  152. class _Geometry : public Object {
  153. OBJ_TYPE(_Geometry, Object);
  154. static _Geometry *singleton;
  155. protected:
  156. static void _bind_methods();
  157. public:
  158. static _Geometry *get_singleton();
  159. DVector<Plane> build_box_planes(const Vector3& p_extents);
  160. DVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
  161. DVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
  162. 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);
  163. DVector<Vector2> get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2);
  164. DVector<Vector3> get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2);
  165. Vector3 get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b);
  166. Variant ray_intersects_triangle( const Vector3& p_from, const Vector3& p_dir, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
  167. Variant segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
  168. DVector<Vector3> segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius);
  169. DVector<Vector3> segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius);
  170. DVector<Vector3> segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes);
  171. real_t segment_intersects_circle(const Vector2& p_from, const Vector2& p_to, const Vector2& p_circle_pos, real_t p_circle_radius);
  172. int get_uv84_normal_bit(const Vector3& p_vector);
  173. Vector<int> triangulate_polygon(const Vector<Vector2>& p_polygon);
  174. Dictionary make_atlas(const Vector<Size2>& p_rects);
  175. _Geometry();
  176. };
  177. class _File : public Reference {
  178. OBJ_TYPE(_File,Reference);
  179. FileAccess *f;
  180. bool eswap;
  181. protected:
  182. static void _bind_methods();
  183. public:
  184. enum ModeFlags {
  185. READ=1,
  186. WRITE=2,
  187. READ_WRITE=3,
  188. };
  189. Error open_encrypted(const String& p_path, int p_mode_flags,const Vector<uint8_t>& p_key);
  190. Error open_encrypted_pass(const String& p_path, int p_mode_flags,const String& p_pass);
  191. Error open(const String& p_path, int p_mode_flags); ///< open a file
  192. void close(); ///< close a file
  193. bool is_open() const; ///< true when file is open
  194. void seek(int64_t p_position); ///< seek to a given position
  195. void seek_end(int64_t p_position=0); ///< seek from the end of file
  196. int64_t get_pos() const; ///< get position in the file
  197. int64_t get_len() const; ///< get size of the file
  198. bool eof_reached() const; ///< reading passed EOF
  199. uint8_t get_8() const; ///< get a byte
  200. uint16_t get_16() const; ///< get 16 bits uint
  201. uint32_t get_32() const; ///< get 32 bits uint
  202. uint64_t get_64() const; ///< get 64 bits uint
  203. float get_float() const;
  204. double get_double() const;
  205. real_t get_real() const;
  206. Variant get_var() const;
  207. DVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
  208. String get_line() const;
  209. String get_as_text() const;
  210. /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
  211. * It's not about the current CPU type but file formats.
  212. * this flags get reset to false (little endian) on each open
  213. */
  214. void set_endian_swap(bool p_swap);
  215. bool get_endian_swap();
  216. Error get_error() const; ///< get last error
  217. void store_8(uint8_t p_dest); ///< store a byte
  218. void store_16(uint16_t p_dest); ///< store 16 bits uint
  219. void store_32(uint32_t p_dest); ///< store 32 bits uint
  220. void store_64(uint64_t p_dest); ///< store 64 bits uint
  221. void store_float(float p_dest);
  222. void store_double(double p_dest);
  223. void store_real(real_t p_real);
  224. void store_string(const String& p_string);
  225. void store_line(const String& p_string);
  226. virtual void store_pascal_string(const String& p_string);
  227. virtual String get_pascal_string();
  228. Vector<String> get_csv_line() const;
  229. void store_buffer(const DVector<uint8_t>& p_buffer); ///< store an array of bytes
  230. void store_var(const Variant& p_var);
  231. bool file_exists(const String& p_name) const; ///< return true if a file exists
  232. _File();
  233. virtual ~_File();
  234. };
  235. class _Directory : public Reference {
  236. OBJ_TYPE(_Directory,Reference);
  237. DirAccess *d;
  238. protected:
  239. static void _bind_methods();
  240. public:
  241. Error open(const String& p_path);
  242. bool list_dir_begin(); ///< This starts dir listing
  243. String get_next();
  244. bool current_is_dir() const;
  245. void list_dir_end(); ///<
  246. int get_drive_count();
  247. String get_drive(int p_drive);
  248. Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
  249. String get_current_dir(); ///< return current dir location
  250. Error make_dir(String p_dir);
  251. Error make_dir_recursive(String p_dir);
  252. bool file_exists(String p_file);
  253. bool dir_exists(String p_dir);
  254. int get_space_left();
  255. Error copy(String p_from,String p_to);
  256. Error rename(String p_from, String p_to);
  257. Error remove(String p_name);
  258. _Directory();
  259. virtual ~_Directory();
  260. };
  261. class _Marshalls : public Reference {
  262. OBJ_TYPE(_Marshalls,Reference);
  263. protected:
  264. static void _bind_methods();
  265. public:
  266. String variant_to_base64(const Variant& p_var);
  267. Variant base64_to_variant(const String& p_str);
  268. _Marshalls() {};
  269. };
  270. class _Mutex : public Reference {
  271. OBJ_TYPE(_Mutex,Reference);
  272. Mutex *mutex;
  273. static void _bind_methods();
  274. public:
  275. void lock();
  276. Error try_lock();
  277. void unlock();
  278. _Mutex();
  279. ~_Mutex();
  280. };
  281. class _Semaphore : public Reference {
  282. OBJ_TYPE(_Semaphore,Reference);
  283. Semaphore *semaphore;
  284. static void _bind_methods();
  285. public:
  286. Error wait();
  287. Error post();
  288. _Semaphore();
  289. ~_Semaphore();
  290. };
  291. class _Thread : public Reference {
  292. OBJ_TYPE(_Thread,Reference);
  293. protected:
  294. Variant ret;
  295. Variant userdata;
  296. volatile bool active;
  297. Object *target_instance;
  298. StringName target_method;
  299. Thread *thread;
  300. static void _bind_methods();
  301. static void _start_func(void *ud);
  302. public:
  303. enum Priority {
  304. PRIORITY_LOW,
  305. PRIORITY_NORMAL,
  306. PRIORITY_HIGH
  307. };
  308. Error start(Object *p_instance,const StringName& p_method,const Variant& p_userdata=Variant(),int p_priority=PRIORITY_NORMAL);
  309. String get_id() const;
  310. bool is_active() const;
  311. Variant wait_to_finish();
  312. _Thread();
  313. ~_Thread();
  314. };
  315. #endif // CORE_BIND_H