core_bind.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. static _ResourceSaver *get_singleton() { return singleton; }
  31. Error save(const String &p_path,const RES& p_resource, uint32_t p_flags);
  32. DVector<String> get_recognized_extensions(const RES& p_resource);
  33. _ResourceSaver();
  34. };
  35. class MainLoop;
  36. class _OS : public Object {
  37. OBJ_TYPE(_OS,Object);
  38. protected:
  39. static void _bind_methods();
  40. static _OS *singleton;
  41. public:
  42. enum Weekday {
  43. DAY_SUNDAY,
  44. DAY_MONDAY,
  45. DAY_TUESDAY,
  46. DAY_WEDNESDAY,
  47. DAY_THURSDAY,
  48. DAY_FRIDAY,
  49. DAY_SATURDAY
  50. };
  51. enum Month {
  52. MONTH_JANUARY,
  53. MONTH_FEBRUARY,
  54. MONTH_MARCH,
  55. MONTH_APRIL,
  56. MONTH_MAY,
  57. MONTH_JUNE,
  58. MONTH_JULY,
  59. MONTH_AUGUST,
  60. MONTH_SEPTEMBER,
  61. MONTH_OCTOBER,
  62. MONTH_NOVEMBER,
  63. MONTH_DECEMBER
  64. };
  65. Point2 get_mouse_pos() const;
  66. void set_window_title(const String& p_title);
  67. int get_mouse_button_state() const;
  68. void set_clipboard(const String& p_text);
  69. String get_clipboard() const;
  70. void set_video_mode(const Size2& p_size, bool p_fullscreen,bool p_resizeable,int p_screen=0);
  71. Size2 get_video_mode(int p_screen=0) const;
  72. bool is_video_mode_fullscreen(int p_screen=0) const;
  73. bool is_video_mode_resizable(int p_screen=0) const;
  74. Array get_fullscreen_mode_list(int p_screen=0) const;
  75. void set_iterations_per_second(int p_ips);
  76. int get_iterations_per_second() const;
  77. void set_low_processor_usage_mode(bool p_enabled);
  78. bool is_in_low_processor_usage_mode() const;
  79. String get_executable_path() const;
  80. int execute(const String& p_path, const Vector<String> & p_arguments,bool p_blocking);
  81. Error kill(int p_pid);
  82. Error shell_open(String p_uri);
  83. bool has_environment(const String& p_var) const;
  84. String get_environment(const String& p_var) const;
  85. String get_name() const;
  86. Vector<String> get_cmdline_args();
  87. String get_locale() const;
  88. String get_model_name() const;
  89. MainLoop *get_main_loop() const;
  90. String get_custom_level() const;
  91. float get_frames_per_second() const;
  92. void dump_memory_to_file(const String& p_file);
  93. void dump_resources_to_file(const String& p_file);
  94. void print_resources_in_use(bool p_short=false);
  95. void print_all_resources(const String& p_to_file);
  96. bool has_touchscreen_ui_hint() const;
  97. String get_unique_ID() const;
  98. /*
  99. struct Date {
  100. int year;
  101. Month month;
  102. int day;
  103. Weekday weekday;
  104. bool dst;
  105. };
  106. struct Time {
  107. int hour;
  108. int min;
  109. int sec;
  110. };
  111. */
  112. void set_icon(const Image& p_icon);
  113. Dictionary get_date() const;
  114. Dictionary get_time() const;
  115. uint64_t get_unix_time() const;
  116. int get_static_memory_usage() const;
  117. int get_static_memory_peak_usage() const;
  118. int get_dynamic_memory_usage() const;
  119. void delay_usec(uint32_t p_usec) const;
  120. void delay_msec(uint32_t p_msec) const;
  121. uint32_t get_ticks_msec() const;
  122. bool can_draw() const;
  123. int get_frames_drawn();
  124. bool is_stdout_verbose() const;
  125. int get_processor_count() const;
  126. String get_data_dir() const;
  127. static _OS *get_singleton() { return singleton; }
  128. _OS();
  129. };
  130. class _Geometry : public Object {
  131. OBJ_TYPE(_Geometry, Object);
  132. static _Geometry *singleton;
  133. protected:
  134. static void _bind_methods();
  135. public:
  136. static _Geometry *get_singleton();
  137. DVector<Plane> build_box_planes(const Vector3& p_extents);
  138. DVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
  139. DVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
  140. 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);
  141. DVector<Vector2> get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2);
  142. DVector<Vector3> get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2);
  143. Vector3 get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b);
  144. Variant ray_intersects_triangle( const Vector3& p_from, const Vector3& p_dir, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
  145. Variant segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
  146. DVector<Vector3> segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius);
  147. DVector<Vector3> segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius);
  148. DVector<Vector3> segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes);
  149. real_t segment_intersects_circle(const Vector2& p_from, const Vector2& p_to, const Vector2& p_circle_pos, real_t p_circle_radius);
  150. Vector<int> triangulate_polygon(const Vector<Vector2>& p_polygon);
  151. _Geometry();
  152. };
  153. class _File : public Reference {
  154. OBJ_TYPE(_File,Reference);
  155. FileAccess *f;
  156. bool eswap;
  157. protected:
  158. static void _bind_methods();
  159. public:
  160. enum ModeFlags {
  161. READ=1,
  162. WRITE=2,
  163. READ_WRITE=3,
  164. };
  165. Error open(const String& p_path, int p_mode_flags); ///< open a file
  166. void close(); ///< close a file
  167. bool is_open() const; ///< true when file is open
  168. void seek(int64_t p_position); ///< seek to a given position
  169. void seek_end(int64_t p_position=0); ///< seek from the end of file
  170. int64_t get_pos() const; ///< get position in the file
  171. int64_t get_len() const; ///< get size of the file
  172. bool eof_reached() const; ///< reading passed EOF
  173. uint8_t get_8() const; ///< get a byte
  174. uint16_t get_16() const; ///< get 16 bits uint
  175. uint32_t get_32() const; ///< get 32 bits uint
  176. uint64_t get_64() const; ///< get 64 bits uint
  177. float get_float() const;
  178. double get_double() const;
  179. real_t get_real() const;
  180. Variant get_var() const;
  181. DVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
  182. String get_line() const;
  183. String get_as_text() const;
  184. /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
  185. * It's not about the current CPU type but file formats.
  186. * this flags get reset to false (little endian) on each open
  187. */
  188. void set_endian_swap(bool p_swap);
  189. bool get_endian_swap();
  190. Error get_error() const; ///< get last error
  191. void store_8(uint8_t p_dest); ///< store a byte
  192. void store_16(uint16_t p_dest); ///< store 16 bits uint
  193. void store_32(uint32_t p_dest); ///< store 32 bits uint
  194. void store_64(uint64_t p_dest); ///< store 64 bits uint
  195. void store_float(float p_dest);
  196. void store_double(double p_dest);
  197. void store_real(real_t p_real);
  198. void store_string(const String& p_string);
  199. void store_line(const String& p_string);
  200. Vector<String> get_csv_line() const;
  201. void store_buffer(const DVector<uint8_t>& p_buffer); ///< store an array of bytes
  202. void store_var(const Variant& p_var);
  203. bool file_exists(const String& p_name) const; ///< return true if a file exists
  204. _File();
  205. virtual ~_File();
  206. };
  207. class _Directory : public Reference {
  208. OBJ_TYPE(_Directory,Reference);
  209. DirAccess *d;
  210. protected:
  211. static void _bind_methods();
  212. public:
  213. Error open(const String& p_path);
  214. bool list_dir_begin(); ///< This starts dir listing
  215. String get_next();
  216. bool current_is_dir() const;
  217. void list_dir_end(); ///<
  218. int get_drive_count();
  219. String get_drive(int p_drive);
  220. Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
  221. String get_current_dir(); ///< return current dir location
  222. Error make_dir(String p_dir);
  223. Error make_dir_recursive(String p_dir);
  224. bool file_exists(String p_file);
  225. int get_space_left();
  226. Error copy(String p_from,String p_to);
  227. Error rename(String p_from, String p_to);
  228. Error remove(String p_name);
  229. _Directory();
  230. virtual ~_Directory();
  231. };
  232. class _Marshalls : public Reference {
  233. OBJ_TYPE(_Marshalls,Reference);
  234. protected:
  235. static void _bind_methods();
  236. public:
  237. String variant_to_base64(const Variant& p_var);
  238. Variant base64_to_variant(const String& p_str);
  239. _Marshalls() {};
  240. };
  241. class _Mutex : public Reference {
  242. OBJ_TYPE(_Mutex,Reference);
  243. Mutex *mutex;
  244. static void _bind_methods();
  245. public:
  246. void lock();
  247. Error try_lock();
  248. void unlock();
  249. _Mutex();
  250. ~_Mutex();
  251. };
  252. class _Semaphore : public Reference {
  253. OBJ_TYPE(_Semaphore,Reference);
  254. Semaphore *semaphore;
  255. static void _bind_methods();
  256. public:
  257. Error wait();
  258. Error post();
  259. _Semaphore();
  260. ~_Semaphore();
  261. };
  262. class _Thread : public Reference {
  263. OBJ_TYPE(_Thread,Reference);
  264. protected:
  265. Variant ret;
  266. Variant userdata;
  267. volatile bool active;
  268. Object *target_instance;
  269. StringName target_method;
  270. Thread *thread;
  271. static void _bind_methods();
  272. static void _start_func(void *ud);
  273. public:
  274. enum Priority {
  275. PRIORITY_LOW,
  276. PRIORITY_NORMAL,
  277. PRIORITY_HIGH
  278. };
  279. Error start(Object *p_instance,const StringName& p_method,const Variant& p_userdata=Variant(),int p_priority=PRIORITY_NORMAL);
  280. String get_id() const;
  281. bool is_active() const;
  282. Variant wait_to_finish();
  283. _Thread();
  284. ~_Thread();
  285. };
  286. #endif // CORE_BIND_H