core_bind.h
1 #ifndef CORE_BIND_H
2 #define CORE_BIND_H
3 
4 #include "io/resource_loader.h"
5 #include "io/resource_saver.h"
6 #include "os/file_access.h"
7 #include "os/dir_access.h"
8 #include "os/thread.h"
9 #include "os/semaphore.h"
10 
11 
12 class _ResourceLoader : public Object {
13  OBJ_TYPE(_ResourceLoader,Object);
14 
15 protected:
16 
17  static void _bind_methods();
18  static _ResourceLoader *singleton;
19 public:
20 
21 
22  static _ResourceLoader *get_singleton() { return singleton; }
23  Ref<ResourceInteractiveLoader> load_interactive(const String& p_path,const String& p_type_hint="");
24  RES load(const String &p_path,const String& p_type_hint="", bool p_no_cache = false);
25  DVector<String> get_recognized_extensions_for_type(const String& p_type);
26  void set_abort_on_missing_resources(bool p_abort);
27  StringArray get_dependencies(const String& p_path);
28  bool has(const String& p_path);
29 
31 };
32 
33 class _ResourceSaver : public Object {
34  OBJ_TYPE(_ResourceSaver,Object);
35 
36 protected:
37 
38  static void _bind_methods();
39  static _ResourceSaver *singleton;
40 public:
41 
42  enum SaverFlags {
43 
44  FLAG_RELATIVE_PATHS=1,
45  FLAG_BUNDLE_RESOURCES=2,
46  FLAG_CHANGE_PATH=4,
47  FLAG_OMIT_EDITOR_PROPERTIES=8,
48  FLAG_SAVE_BIG_ENDIAN=16,
49  FLAG_COMPRESS=32,
50  };
51 
52  static _ResourceSaver *get_singleton() { return singleton; }
53 
54  Error save(const String &p_path,const RES& p_resource, uint32_t p_flags);
55  DVector<String> get_recognized_extensions(const RES& p_resource);
56 
57 
59 };
60 
61 class MainLoop;
62 
63 class _OS : public Object {
64  OBJ_TYPE(_OS,Object);
65 
66 protected:
67 
68  static void _bind_methods();
69  static _OS *singleton;
70 public:
71 
72  enum Weekday {
73  DAY_SUNDAY,
74  DAY_MONDAY,
75  DAY_TUESDAY,
76  DAY_WEDNESDAY,
77  DAY_THURSDAY,
78  DAY_FRIDAY,
79  DAY_SATURDAY
80  };
81 
82  enum Month {
83  MONTH_JANUARY,
84  MONTH_FEBRUARY,
85  MONTH_MARCH,
86  MONTH_APRIL,
87  MONTH_MAY,
88  MONTH_JUNE,
89  MONTH_JULY,
90  MONTH_AUGUST,
91  MONTH_SEPTEMBER,
92  MONTH_OCTOBER,
93  MONTH_NOVEMBER,
94  MONTH_DECEMBER
95  };
96 
97  Point2 get_mouse_pos() const;
98  void set_window_title(const String& p_title);
99  int get_mouse_button_state() const;
100 
101 
102  void set_clipboard(const String& p_text);
103  String get_clipboard() const;
104 
105  void set_video_mode(const Size2& p_size, bool p_fullscreen,bool p_resizeable,int p_screen=0);
106  Size2 get_video_mode(int p_screen=0) const;
107  bool is_video_mode_fullscreen(int p_screen=0) const;
108  bool is_video_mode_resizable(int p_screen=0) const;
109  Array get_fullscreen_mode_list(int p_screen=0) const;
110 
111 
112  virtual int get_screen_count() const;
113  virtual int get_current_screen() const;
114  virtual void set_current_screen(int p_screen);
115  virtual Point2 get_screen_position(int p_screen=0) const;
116  virtual Size2 get_screen_size(int p_screen=0) const;
117  virtual Point2 get_window_position() const;
118  virtual void set_window_position(const Point2& p_position);
119  virtual Size2 get_window_size() const;
120  virtual void set_window_size(const Size2& p_size);
121  virtual void set_window_fullscreen(bool p_enabled);
122  virtual bool is_window_fullscreen() const;
123  virtual void set_window_resizable(bool p_enabled);
124  virtual bool is_window_resizable() const;
125  virtual void set_window_minimized(bool p_enabled);
126  virtual bool is_window_minimized() const;
127  virtual void set_window_maximized(bool p_enabled);
128  virtual bool is_window_maximized() const;
129 
130 
131  Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
132  bool native_video_is_playing();
133  void native_video_pause();
134  void native_video_unpause();
135  void native_video_stop();
136 
137  void set_iterations_per_second(int p_ips);
138  int get_iterations_per_second() const;
139 
140  void set_target_fps(int p_fps);
141  float get_target_fps() const;
142 
143  void set_low_processor_usage_mode(bool p_enabled);
144  bool is_in_low_processor_usage_mode() const;
145 
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 
149  Error kill(int p_pid);
150  Error shell_open(String p_uri);
151 
152  int get_process_ID() const;
153 
154  bool has_environment(const String& p_var) const;
155  String get_environment(const String& p_var) const;
156 
157  String get_name() const;
158  Vector<String> get_cmdline_args();
159 
160  String get_locale() const;
161  String get_model_name() const;
162  MainLoop *get_main_loop() const;
163 
164  String get_custom_level() const;
165 
166  float get_frames_per_second() const;
167 
168  void dump_memory_to_file(const String& p_file);
169  void dump_resources_to_file(const String& p_file);
170 
171  void print_resources_in_use(bool p_short=false);
172  void print_all_resources(const String& p_to_file);
173  void print_all_textures_by_size();
174  void print_resources_by_type(const Vector<String>& p_types);
175 
176  bool has_touchscreen_ui_hint() const;
177 
178  bool is_debug_build() const;
179 
180  String get_unique_ID() const;
181 
182  String get_scancode_string(uint32_t p_code) const;
183  bool is_scancode_unicode(uint32_t p_unicode) const;
184  int find_scancode_from_string(const String& p_code) const;
185 
186 
187  /*
188  struct Date {
189 
190  int year;
191  Month month;
192  int day;
193  Weekday weekday;
194  bool dst;
195  };
196 
197  struct Time {
198 
199  int hour;
200  int min;
201  int sec;
202  };
203 */
204 
205  void set_use_file_access_save_and_swap(bool p_enable);
206 
207  void set_icon(const Image& p_icon);
208  Dictionary get_date(bool utc) const;
209  Dictionary get_time(bool utc) const;
210  Dictionary get_time_zone_info() const;
211  uint64_t get_unix_time() const;
212  uint64_t get_system_time_secs() const;
213 
214  int get_static_memory_usage() const;
215  int get_static_memory_peak_usage() const;
216  int get_dynamic_memory_usage() const;
217 
218  void delay_usec(uint32_t p_usec) const;
219  void delay_msec(uint32_t p_msec) const;
220  uint32_t get_ticks_msec() const;
221  uint32_t get_splash_tick_msec() const;
222 
223  bool can_use_threads() const;
224 
225  bool can_draw() const;
226 
227  int get_frames_drawn();
228 
229  bool is_stdout_verbose() const;
230 
231  int get_processor_count() const;
232 
233  enum SystemDir {
234  SYSTEM_DIR_DESKTOP,
235  SYSTEM_DIR_DCIM,
236  SYSTEM_DIR_DOCUMENTS,
237  SYSTEM_DIR_DOWNLOADS,
238  SYSTEM_DIR_MOVIES,
239  SYSTEM_DIR_MUSIC,
240  SYSTEM_DIR_PICTURES,
241  SYSTEM_DIR_RINGTONES,
242  };
243 
244  enum ScreenOrientation {
245 
246  SCREEN_ORIENTATION_LANDSCAPE,
247  SCREEN_ORIENTATION_PORTRAIT,
248  SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
249  SCREEN_ORIENTATION_REVERSE_PORTRAIT,
250  SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
251  SCREEN_ORIENTATION_SENSOR_PORTRAIT,
252  SCREEN_ORIENTATION_SENSOR,
253  };
254 
255  String get_system_dir(SystemDir p_dir) const;
256 
257 
258  String get_data_dir() const;
259 
260  void alert(const String& p_alert,const String& p_title="ALERT!");
261 
262 
263  void set_screen_orientation(ScreenOrientation p_orientation);
264  ScreenOrientation get_screen_orientation() const;
265 
266  void set_keep_screen_on(bool p_enabled);
267  bool is_keep_screen_on() const;
268 
269  void set_time_scale(float p_scale);
270  float get_time_scale();
271 
272  bool is_ok_left_and_cancel_right() const;
273 
274  Error set_thread_name(const String& p_name);
275 
276  static _OS *get_singleton() { return singleton; }
277 
278  _OS();
279 };
280 
281 VARIANT_ENUM_CAST(_OS::SystemDir);
282 VARIANT_ENUM_CAST(_OS::ScreenOrientation);
283 
284 
285 class _Geometry : public Object {
286 
287  OBJ_TYPE(_Geometry, Object);
288 
289  static _Geometry *singleton;
290 protected:
291 
292  static void _bind_methods();
293 public:
294 
295  static _Geometry *get_singleton();
296  DVector<Plane> build_box_planes(const Vector3& p_extents);
297  DVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
298  DVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
299  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);
300  DVector<Vector2> get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2);
301  DVector<Vector3> get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2);
302  Vector3 get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b);
303  Variant ray_intersects_triangle( const Vector3& p_from, const Vector3& p_dir, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
304  Variant segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
305  bool point_is_inside_triangle(const Vector2& s, const Vector2& a, const Vector2& b, const Vector2& c) const;
306 
307  DVector<Vector3> segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius);
308  DVector<Vector3> segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius);
309  DVector<Vector3> segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes);
310  real_t segment_intersects_circle(const Vector2& p_from, const Vector2& p_to, const Vector2& p_circle_pos, real_t p_circle_radius);
311  int get_uv84_normal_bit(const Vector3& p_vector);
312 
313  Vector<int> triangulate_polygon(const Vector<Vector2>& p_polygon);
314 
315  Dictionary make_atlas(const Vector<Size2>& p_rects);
316 
317  _Geometry();
318 };
319 
320 
321 
322 
323 class _File : public Reference {
324 
325  OBJ_TYPE(_File,Reference);
326  FileAccess *f;
327  bool eswap;
328 protected:
329 
330  static void _bind_methods();
331 public:
332 
333  enum ModeFlags {
334 
335  READ=1,
336  WRITE=2,
337  READ_WRITE=3,
338  WRITE_READ=7,
339  };
340 
341  Error open_encrypted(const String& p_path, int p_mode_flags,const Vector<uint8_t>& p_key);
342  Error open_encrypted_pass(const String& p_path, int p_mode_flags,const String& p_pass);
343 
344 
345  Error open(const String& p_path, int p_mode_flags);
346  void close();
347  bool is_open() const;
348 
349  void seek(int64_t p_position);
350  void seek_end(int64_t p_position=0);
351  int64_t get_pos() const;
352  int64_t get_len() const;
353 
354  bool eof_reached() const;
355 
356  uint8_t get_8() const;
357  uint16_t get_16() const;
358  uint32_t get_32() const;
359  uint64_t get_64() const;
360 
361  float get_float() const;
362  double get_double() const;
363  real_t get_real() const;
364 
365  Variant get_var() const;
366 
367  DVector<uint8_t> get_buffer(int p_length) const;
368  String get_line() const;
369  String get_as_text() const;
370 
376  void set_endian_swap(bool p_swap);
377  bool get_endian_swap();
378 
379  Error get_error() const;
380 
381  void store_8(uint8_t p_dest);
382  void store_16(uint16_t p_dest);
383  void store_32(uint32_t p_dest);
384  void store_64(uint64_t p_dest);
385 
386  void store_float(float p_dest);
387  void store_double(double p_dest);
388  void store_real(real_t p_real);
389 
390  void store_string(const String& p_string);
391  void store_line(const String& p_string);
392 
393  virtual void store_pascal_string(const String& p_string);
394  virtual String get_pascal_string();
395 
396  Vector<String> get_csv_line(String delim=",") const;
397 
398 
399  void store_buffer(const DVector<uint8_t>& p_buffer);
400 
401  void store_var(const Variant& p_var);
402 
403  bool file_exists(const String& p_name) const;
404 
405  _File();
406  virtual ~_File();
407 
408 };
409 
410 class _Directory : public Reference {
411 
412  OBJ_TYPE(_Directory,Reference);
413  DirAccess *d;
414 protected:
415 
416  static void _bind_methods();
417 public:
418 
419  Error open(const String& p_path);
420 
421  bool list_dir_begin();
422  String get_next();
423  bool current_is_dir() const;
424 
425  void list_dir_end();
426 
427  int get_drive_count();
428  String get_drive(int p_drive);
429 
430  Error change_dir(String p_dir);
431  String get_current_dir();
432 
433  Error make_dir(String p_dir);
434  Error make_dir_recursive(String p_dir);
435 
436  bool file_exists(String p_file);
437  bool dir_exists(String p_dir);
438 
439  int get_space_left();
440 
441  Error copy(String p_from,String p_to);
442  Error rename(String p_from, String p_to);
443  Error remove(String p_name);
444 
445 
446  _Directory();
447  virtual ~_Directory();
448 
449 };
450 
451 class _Marshalls : public Reference {
452 
453  OBJ_TYPE(_Marshalls,Reference);
454 
455 protected:
456 
457  static void _bind_methods();
458 
459 
460 public:
461 
462  String variant_to_base64(const Variant& p_var);
463  Variant base64_to_variant(const String& p_str);
464 
465  String raw_to_base64(const DVector<uint8_t>& p_arr);
466  DVector<uint8_t> base64_to_raw(const String& p_str);
467 
468  String utf8_to_base64(const String& p_str);
469  String base64_to_utf8(const String& p_str);
470 
471  _Marshalls() {};
472 };
473 
474 
475 class _Mutex : public Reference {
476 
477  OBJ_TYPE(_Mutex,Reference);
478  Mutex *mutex;
479 
480  static void _bind_methods();
481 public:
482 
483  void lock();
484  Error try_lock();
485  void unlock();
486 
487  _Mutex();
488  ~_Mutex();
489 };
490 
491 class _Semaphore : public Reference {
492 
493  OBJ_TYPE(_Semaphore,Reference);
494  Semaphore *semaphore;
495 
496  static void _bind_methods();
497 public:
498 
499  Error wait();
500  Error post();
501 
502  _Semaphore();
503  ~_Semaphore();
504 };
505 
506 class _Thread : public Reference {
507 
508  OBJ_TYPE(_Thread,Reference);
509 
510 protected:
511 
512  Variant ret;
513  Variant userdata;
514  volatile bool active;
515  Object *target_instance;
516  StringName target_method;
517  Thread *thread;
518  static void _bind_methods();
519  static void _start_func(void *ud);
520 public:
521 
522  enum Priority {
523 
524  PRIORITY_LOW,
525  PRIORITY_NORMAL,
526  PRIORITY_HIGH
527  };
528 
529  Error start(Object *p_instance,const StringName& p_method,const Variant& p_userdata=Variant(),int p_priority=PRIORITY_NORMAL);
530  String get_id() const;
531  bool is_active() const;
532  Variant wait_to_finish();
533 
534  _Thread();
535  ~_Thread();
536 };
537 
538 #endif // CORE_BIND_H
Definition: core_bind.h:323
Definition: array.h:38
Definition: reference.h:78
Definition: main_loop.h:38
Definition: variant.h:74
Definition: core_bind.h:475
Definition: image.h:47
Definition: mutex.h:45
Definition: string_db.h:48
Definition: reference.h:40
Definition: thread.h:42
Definition: vector3.h:38
Definition: core_bind.h:451
Definition: core_bind.h:491
Definition: core_bind.h:63
Definition: dictionary.h:42
Definition: core_bind.h:410
Definition: core_bind.h:285
Definition: math_2d.h:65
Definition: core_bind.h:506
Definition: semaphore.h:37
Definition: core_bind.h:33
Definition: core_bind.h:12
Definition: dvector.h:43
Definition: ustring.h:64
Definition: object.h:317
Definition: file_access.h:40
Definition: dir_access.h:41