os.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*************************************************************************/
  2. /* os.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 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. bool _no_window;
  51. int _exit_code;
  52. int _orientation;
  53. float _fps;
  54. char *last_error;
  55. public:
  56. enum RenderThreadMode {
  57. RENDER_THREAD_UNSAFE,
  58. RENDER_THREAD_SAFE,
  59. RENDER_SEPARATE_THREAD
  60. };
  61. struct VideoMode {
  62. int width,height;
  63. bool fullscreen;
  64. bool resizable;
  65. float get_aspect() const { return (float)width/(float)height; }
  66. 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; }
  67. };
  68. protected:
  69. friend class Main;
  70. RenderThreadMode _render_thread_mode;
  71. // functions used by main to initialize/deintialize the OS
  72. virtual int get_video_driver_count() const=0;
  73. virtual const char * get_video_driver_name(int p_driver) const=0;
  74. virtual VideoMode get_default_video_mode() const=0;
  75. virtual int get_audio_driver_count() const=0;
  76. virtual const char * get_audio_driver_name(int p_driver) const=0;
  77. virtual void initialize_core()=0;
  78. virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver)=0;
  79. virtual void set_main_loop( MainLoop * p_main_loop )=0;
  80. virtual void delete_main_loop()=0;
  81. virtual void finalize()=0;
  82. virtual void finalize_core()=0;
  83. virtual void set_cmdline(const char* p_execpath, const List<String>& p_args);
  84. void _ensure_data_dir();
  85. public:
  86. typedef int64_t ProcessID;
  87. static OS* get_singleton();
  88. enum ErrorType {
  89. ERR_ERROR,
  90. ERR_WARNING,
  91. ERR_SCRIPT
  92. };
  93. 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);
  94. virtual void print(const char *p_format, ... );
  95. virtual void printerr(const char *p_format, ... );
  96. virtual void vprint(const char* p_format, va_list p_list, bool p_stderr=false)=0;
  97. virtual void alert(const String& p_alert,const String& p_title="ALERT!")=0;
  98. virtual String get_stdin_string(bool p_block = true)=0;
  99. virtual void set_last_error(const char* p_error);
  100. virtual const char *get_last_error() const;
  101. virtual void clear_last_error();
  102. enum MouseMode {
  103. MOUSE_MODE_VISIBLE,
  104. MOUSE_MODE_HIDDEN,
  105. MOUSE_MODE_CAPTURED
  106. };
  107. virtual void set_mouse_mode(MouseMode p_mode);
  108. virtual MouseMode get_mouse_mode() const;
  109. virtual Point2 get_mouse_pos() const=0;
  110. virtual int get_mouse_button_state() const=0;
  111. virtual void set_window_title(const String& p_title)=0;
  112. virtual void set_clipboard(const String& p_text);
  113. virtual String get_clipboard() const;
  114. virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0)=0;
  115. virtual VideoMode get_video_mode(int p_screen=0) const=0;
  116. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const=0;
  117. virtual void set_iterations_per_second(int p_ips);
  118. virtual int get_iterations_per_second() const;
  119. virtual float get_frames_per_second() const { return _fps; };
  120. virtual void set_low_processor_usage_mode(bool p_enabled);
  121. virtual bool is_in_low_processor_usage_mode() const;
  122. virtual String get_executable_path() const;
  123. 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;
  124. virtual Error kill(const ProcessID& p_pid)=0;
  125. virtual Error shell_open(String p_uri);
  126. virtual Error set_cwd(const String& p_cwd);
  127. virtual bool has_environment(const String& p_var) const=0;
  128. virtual String get_environment(const String& p_var) const=0;
  129. virtual String get_name()=0;
  130. virtual List<String> get_cmdline_args() const { return _cmdline; }
  131. virtual String get_model_name() const;
  132. virtual MainLoop *get_main_loop() const=0;
  133. String get_custom_level() const { return _custom_level; }
  134. virtual void yield();
  135. enum Weekday {
  136. DAY_SUNDAY,
  137. DAY_MONDAY,
  138. DAY_TUESDAY,
  139. DAY_WEDNESDAY,
  140. DAY_THURSDAY,
  141. DAY_FRIDAY,
  142. DAY_SATURDAY
  143. };
  144. enum Month {
  145. MONTH_JANUARY,
  146. MONTH_FEBRUARY,
  147. MONTH_MARCH,
  148. MONTH_APRIL,
  149. MONTH_MAY,
  150. MONTH_JUNE,
  151. MONTH_JULY,
  152. MONTH_AUGUST,
  153. MONTH_SEPTEMBER,
  154. MONTH_OCTOBER,
  155. MONTH_NOVEMBER,
  156. MONTH_DECEMBER
  157. };
  158. struct Date {
  159. int year;
  160. Month month;
  161. int day;
  162. Weekday weekday;
  163. bool dst;
  164. };
  165. struct Time {
  166. int hour;
  167. int min;
  168. int sec;
  169. };
  170. virtual Date get_date() const=0;
  171. virtual Time get_time() const=0;
  172. virtual uint64_t get_unix_time() const;
  173. virtual void delay_usec(uint32_t p_usec) const=0;
  174. virtual uint64_t get_ticks_usec() const=0;
  175. uint32_t get_ticks_msec() const;
  176. void set_frame_delay(uint32_t p_msec);
  177. uint32_t get_frame_delay() const;
  178. virtual bool can_draw() const = 0;
  179. uint64_t get_frames_drawn();
  180. bool is_stdout_verbose() const;
  181. enum CursorShape {
  182. CURSOR_ARROW,
  183. CURSOR_IBEAM,
  184. CURSOR_POINTING_HAND,
  185. CURSOR_CROSS,
  186. CURSOR_WAIT,
  187. CURSOR_BUSY,
  188. CURSOR_DRAG,
  189. CURSOR_CAN_DROP,
  190. CURSOR_FORBIDDEN,
  191. CURSOR_VSIZE,
  192. CURSOR_HSIZE,
  193. CURSOR_BDIAGSIZE,
  194. CURSOR_FDIAGSIZE,
  195. CURSOR_MOVE,
  196. CURSOR_VSPLIT,
  197. CURSOR_HSPLIT,
  198. CURSOR_HELP,
  199. CURSOR_MAX
  200. };
  201. virtual bool has_virtual_keyboard() const;
  202. virtual void show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect=Rect2());
  203. virtual void hide_virtual_keyboard();
  204. virtual void set_cursor_shape(CursorShape p_shape)=0;
  205. virtual bool get_swap_ok_cancel() { return false; }
  206. virtual void dump_memory_to_file(const char* p_file);
  207. virtual void dump_resources_to_file(const char* p_file);
  208. virtual void print_resources_in_use(bool p_short=false);
  209. virtual void print_all_resources(String p_to_file="");
  210. virtual int get_static_memory_usage() const;
  211. virtual int get_static_memory_peak_usage() const;
  212. virtual int get_dynamic_memory_usage() const;
  213. virtual int get_free_static_memory() const;
  214. RenderThreadMode get_render_thread_mode() const { return _render_thread_mode; }
  215. virtual String get_locale() const;
  216. virtual String get_data_dir() const;
  217. virtual String get_resource_dir() const;
  218. virtual void set_no_window_mode(bool p_enable);
  219. virtual bool is_no_window_mode_enabled() const;
  220. virtual bool has_touchscreen_ui_hint() const;
  221. enum ScreenOrientation {
  222. SCREEN_LANDSCAPE,
  223. SCREEN_PORTRAIT,
  224. SCREEN_REVERSE_LANDSCAPE,
  225. SCREEN_REVERSE_PORTRAIT,
  226. SCREEN_SENSOR_LANDSCAPE,
  227. SCREEN_SENSOR_PORTRAIT,
  228. SCREEN_SENSOR,
  229. };
  230. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  231. ScreenOrientation get_screen_orientation() const;
  232. virtual void move_window_to_foreground() {};
  233. virtual void debug_break();
  234. virtual void release_rendering_thread();
  235. virtual void make_rendering_thread();
  236. virtual void swap_buffers();
  237. virtual void set_icon(const Image& p_icon);
  238. virtual int get_exit_code() const;
  239. virtual void set_exit_code(int p_code);
  240. virtual int get_processor_count() const;
  241. virtual String get_unique_ID() const;
  242. virtual Error native_video_play(String p_path);
  243. virtual bool native_video_is_playing();
  244. virtual void native_video_pause();
  245. virtual void native_video_stop();
  246. virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object* p_obj, String p_callback);
  247. virtual Error dialog_input_text(String p_title, String p_description, String p_partial, Object* p_obj, String p_callback);
  248. OS();
  249. virtual ~OS();
  250. };
  251. #endif