os.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /*************************************************************************/
  2. /* os.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 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 OS_H
  30. #define OS_H
  31. #include "ustring.h"
  32. #include "list.h"
  33. #include "vector.h"
  34. #include "os/main_loop.h"
  35. #include <stdarg.h>
  36. /**
  37. @author Juan Linietsky <[email protected]>
  38. */
  39. class OS {
  40. static OS* singleton;
  41. String _execpath;
  42. String _custom_level;
  43. List<String> _cmdline;
  44. int ips;
  45. bool low_processor_usage_mode;
  46. bool _verbose_stdout;
  47. String _local_clipboard;
  48. uint64_t frames_drawn;
  49. uint32_t _frame_delay;
  50. uint64_t _msec_splash;
  51. bool _no_window;
  52. int _exit_code;
  53. int _orientation;
  54. float _fps;
  55. int _target_fps;
  56. float _time_scale;
  57. char *last_error;
  58. public:
  59. enum RenderThreadMode {
  60. RENDER_THREAD_UNSAFE,
  61. RENDER_THREAD_SAFE,
  62. RENDER_SEPARATE_THREAD
  63. };
  64. struct VideoMode {
  65. int width,height;
  66. bool fullscreen;
  67. bool resizable;
  68. float get_aspect() const { return (float)width/(float)height; }
  69. VideoMode(int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) {width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; }
  70. };
  71. protected:
  72. friend class Main;
  73. RenderThreadMode _render_thread_mode;
  74. // functions used by main to initialize/deintialize the OS
  75. virtual int get_video_driver_count() const=0;
  76. virtual const char * get_video_driver_name(int p_driver) const=0;
  77. virtual VideoMode get_default_video_mode() const=0;
  78. virtual int get_audio_driver_count() const=0;
  79. virtual const char * get_audio_driver_name(int p_driver) const=0;
  80. virtual void initialize_core()=0;
  81. virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver)=0;
  82. virtual void set_main_loop( MainLoop * p_main_loop )=0;
  83. virtual void delete_main_loop()=0;
  84. virtual void finalize()=0;
  85. virtual void finalize_core()=0;
  86. virtual void set_cmdline(const char* p_execpath, const List<String>& p_args);
  87. void _ensure_data_dir();
  88. public:
  89. typedef int64_t ProcessID;
  90. static OS* get_singleton();
  91. enum ErrorType {
  92. ERR_ERROR,
  93. ERR_WARNING,
  94. ERR_SCRIPT
  95. };
  96. virtual void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type=ERR_ERROR);
  97. virtual void print(const char *p_format, ... );
  98. virtual void printerr(const char *p_format, ... );
  99. virtual void vprint(const char* p_format, va_list p_list, bool p_stderr=false)=0;
  100. virtual void alert(const String& p_alert,const String& p_title="ALERT!")=0;
  101. virtual String get_stdin_string(bool p_block = true)=0;
  102. virtual void set_last_error(const char* p_error);
  103. virtual const char *get_last_error() const;
  104. virtual void clear_last_error();
  105. enum MouseMode {
  106. MOUSE_MODE_VISIBLE,
  107. MOUSE_MODE_HIDDEN,
  108. MOUSE_MODE_CAPTURED
  109. };
  110. virtual void set_mouse_mode(MouseMode p_mode);
  111. virtual MouseMode get_mouse_mode() const;
  112. virtual void warp_mouse_pos(const Point2& p_to) {}
  113. virtual Point2 get_mouse_pos() const=0;
  114. virtual int get_mouse_button_state() const=0;
  115. virtual void set_window_title(const String& p_title)=0;
  116. virtual void set_clipboard(const String& p_text);
  117. virtual String get_clipboard() const;
  118. virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0)=0;
  119. virtual VideoMode get_video_mode(int p_screen=0) const=0;
  120. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const=0;
  121. virtual int get_screen_count() const{ return 1; }
  122. virtual int get_current_screen() const { return 0; }
  123. virtual void set_current_screen(int p_screen) { }
  124. virtual Point2 get_screen_position(int p_screen=0) { return Point2(); }
  125. virtual Size2 get_screen_size(int p_screen=0) const { return get_window_size(); }
  126. virtual Point2 get_window_position() const { return Vector2(); }
  127. virtual void set_window_position(const Point2& p_position) {}
  128. virtual Size2 get_window_size() const=0;
  129. virtual void set_window_size(const Size2 p_size){}
  130. virtual void set_window_fullscreen(bool p_enabled) {}
  131. virtual bool is_window_fullscreen() const { return true; }
  132. virtual void set_window_resizable(bool p_enabled) {}
  133. virtual bool is_window_resizable() const { return false; }
  134. virtual void set_window_minimized(bool p_enabled) {}
  135. virtual bool is_window_minimized() const { return false; }
  136. virtual void set_window_maximized(bool p_enabled) {}
  137. virtual bool is_window_maximized() const { return true; }
  138. virtual void set_iterations_per_second(int p_ips);
  139. virtual int get_iterations_per_second() const;
  140. virtual void set_target_fps(int p_fps);
  141. virtual float get_target_fps() const;
  142. virtual float get_frames_per_second() const { return _fps; };
  143. virtual void set_low_processor_usage_mode(bool p_enabled);
  144. virtual bool is_in_low_processor_usage_mode() const;
  145. virtual String get_executable_path() const;
  146. virtual Error execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL)=0;
  147. virtual Error kill(const ProcessID& p_pid)=0;
  148. virtual int get_process_ID() const;
  149. virtual Error shell_open(String p_uri);
  150. virtual Error set_cwd(const String& p_cwd);
  151. virtual bool has_environment(const String& p_var) const=0;
  152. virtual String get_environment(const String& p_var) const=0;
  153. virtual String get_name()=0;
  154. virtual List<String> get_cmdline_args() const { return _cmdline; }
  155. virtual String get_model_name() const;
  156. virtual MainLoop *get_main_loop() const=0;
  157. String get_custom_level() const { return _custom_level; }
  158. virtual void yield();
  159. enum Weekday {
  160. DAY_SUNDAY,
  161. DAY_MONDAY,
  162. DAY_TUESDAY,
  163. DAY_WEDNESDAY,
  164. DAY_THURSDAY,
  165. DAY_FRIDAY,
  166. DAY_SATURDAY
  167. };
  168. enum Month {
  169. MONTH_JANUARY,
  170. MONTH_FEBRUARY,
  171. MONTH_MARCH,
  172. MONTH_APRIL,
  173. MONTH_MAY,
  174. MONTH_JUNE,
  175. MONTH_JULY,
  176. MONTH_AUGUST,
  177. MONTH_SEPTEMBER,
  178. MONTH_OCTOBER,
  179. MONTH_NOVEMBER,
  180. MONTH_DECEMBER
  181. };
  182. struct Date {
  183. int year;
  184. Month month;
  185. int day;
  186. Weekday weekday;
  187. bool dst;
  188. };
  189. struct Time {
  190. int hour;
  191. int min;
  192. int sec;
  193. };
  194. virtual Date get_date() const=0;
  195. virtual Time get_time() const=0;
  196. virtual uint64_t get_unix_time() const;
  197. virtual void delay_usec(uint32_t p_usec) const=0;
  198. virtual uint64_t get_ticks_usec() const=0;
  199. uint32_t get_ticks_msec() const;
  200. uint64_t get_splash_tick_msec() const;
  201. void set_frame_delay(uint32_t p_msec);
  202. uint32_t get_frame_delay() const;
  203. virtual bool can_draw() const = 0;
  204. uint64_t get_frames_drawn();
  205. bool is_stdout_verbose() const;
  206. enum CursorShape {
  207. CURSOR_ARROW,
  208. CURSOR_IBEAM,
  209. CURSOR_POINTING_HAND,
  210. CURSOR_CROSS,
  211. CURSOR_WAIT,
  212. CURSOR_BUSY,
  213. CURSOR_DRAG,
  214. CURSOR_CAN_DROP,
  215. CURSOR_FORBIDDEN,
  216. CURSOR_VSIZE,
  217. CURSOR_HSIZE,
  218. CURSOR_BDIAGSIZE,
  219. CURSOR_FDIAGSIZE,
  220. CURSOR_MOVE,
  221. CURSOR_VSPLIT,
  222. CURSOR_HSPLIT,
  223. CURSOR_HELP,
  224. CURSOR_MAX
  225. };
  226. virtual bool has_virtual_keyboard() const;
  227. virtual void show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect=Rect2());
  228. virtual void hide_virtual_keyboard();
  229. virtual void set_cursor_shape(CursorShape p_shape)=0;
  230. virtual bool get_swap_ok_cancel() { return false; }
  231. virtual void dump_memory_to_file(const char* p_file);
  232. virtual void dump_resources_to_file(const char* p_file);
  233. virtual void print_resources_in_use(bool p_short=false);
  234. virtual void print_all_resources(String p_to_file="");
  235. virtual int get_static_memory_usage() const;
  236. virtual int get_static_memory_peak_usage() const;
  237. virtual int get_dynamic_memory_usage() const;
  238. virtual int get_free_static_memory() const;
  239. RenderThreadMode get_render_thread_mode() const { return _render_thread_mode; }
  240. virtual String get_locale() const;
  241. virtual String get_data_dir() const;
  242. virtual String get_resource_dir() const;
  243. enum SystemDir {
  244. SYSTEM_DIR_DESKTOP,
  245. SYSTEM_DIR_DCIM,
  246. SYSTEM_DIR_DOCUMENTS,
  247. SYSTEM_DIR_DOWNLOADS,
  248. SYSTEM_DIR_MOVIES,
  249. SYSTEM_DIR_MUSIC,
  250. SYSTEM_DIR_PICTURES,
  251. SYSTEM_DIR_RINGTONES,
  252. };
  253. virtual String get_system_dir(SystemDir p_dir) const;
  254. virtual void set_no_window_mode(bool p_enable);
  255. virtual bool is_no_window_mode_enabled() const;
  256. virtual bool has_touchscreen_ui_hint() const;
  257. enum ScreenOrientation {
  258. SCREEN_LANDSCAPE,
  259. SCREEN_PORTRAIT,
  260. SCREEN_REVERSE_LANDSCAPE,
  261. SCREEN_REVERSE_PORTRAIT,
  262. SCREEN_SENSOR_LANDSCAPE,
  263. SCREEN_SENSOR_PORTRAIT,
  264. SCREEN_SENSOR,
  265. };
  266. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  267. ScreenOrientation get_screen_orientation() const;
  268. virtual void move_window_to_foreground() {};
  269. virtual void debug_break();
  270. virtual void release_rendering_thread();
  271. virtual void make_rendering_thread();
  272. virtual void swap_buffers();
  273. virtual void set_icon(const Image& p_icon);
  274. virtual int get_exit_code() const;
  275. virtual void set_exit_code(int p_code);
  276. virtual int get_processor_count() const;
  277. virtual String get_unique_ID() const;
  278. virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  279. virtual bool native_video_is_playing() const;
  280. virtual void native_video_pause();
  281. virtual void native_video_stop();
  282. virtual bool can_use_threads() const;
  283. virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object* p_obj, String p_callback);
  284. virtual Error dialog_input_text(String p_title, String p_description, String p_partial, Object* p_obj, String p_callback);
  285. enum LatinKeyboardVariant {
  286. LATIN_KEYBOARD_QWERTY,
  287. LATIN_KEYBOARD_QWERTZ,
  288. LATIN_KEYBOARD_AZERTY,
  289. LATIN_KEYBOARD_QZERTY,
  290. LATIN_KEYBOARD_DVORAK,
  291. LATIN_KEYBOARD_NEO,
  292. };
  293. virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
  294. void set_time_scale(float p_scale);
  295. float get_time_scale() const;
  296. OS();
  297. virtual ~OS();
  298. };
  299. #endif