os.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /**************************************************************************/
  2. /* os.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef OS_H
  31. #define OS_H
  32. #include "core/engine.h"
  33. #include "core/image.h"
  34. #include "core/io/logger.h"
  35. #include "core/list.h"
  36. #include "core/os/main_loop.h"
  37. #include "core/ustring.h"
  38. #include "core/vector.h"
  39. #include <stdarg.h>
  40. #include <stdlib.h>
  41. class OS {
  42. static OS *singleton;
  43. static uint64_t target_ticks;
  44. String _execpath;
  45. List<String> _cmdline;
  46. bool _keep_screen_on;
  47. bool low_processor_usage_mode;
  48. int low_processor_usage_mode_sleep_usec;
  49. bool _update_vital_only;
  50. bool _verbose_stdout;
  51. bool _debug_stdout;
  52. String _local_clipboard;
  53. String _primary_clipboard;
  54. uint64_t _msec_splash;
  55. bool _no_window;
  56. int _exit_code = EXIT_FAILURE; // unexpected exit is marked as failure
  57. bool _is_custom_exit_code = false;
  58. int _orientation;
  59. bool _allow_hidpi;
  60. bool _allow_layered;
  61. bool _use_vsync;
  62. bool _vsync_via_compositor;
  63. bool _delta_smoothing_enabled;
  64. char *last_error;
  65. void *_stack_bottom;
  66. CompositeLogger *_logger;
  67. bool restart_on_exit;
  68. List<String> restart_commandline;
  69. // For tracking benchmark data
  70. bool use_benchmark = false;
  71. String benchmark_file;
  72. HashMap<String, uint64_t> start_benchmark_from;
  73. Dictionary startup_benchmark_json;
  74. protected:
  75. bool _update_pending;
  76. void _set_logger(CompositeLogger *p_logger);
  77. public:
  78. typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection);
  79. typedef bool (*HasServerFeatureCallback)(const String &p_feature);
  80. enum PowerState {
  81. POWERSTATE_UNKNOWN, /**< cannot determine power status */
  82. POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */
  83. POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */
  84. POWERSTATE_CHARGING, /**< Plugged in, charging battery */
  85. POWERSTATE_CHARGED /**< Plugged in, battery charged */
  86. };
  87. enum RenderThreadMode {
  88. RENDER_THREAD_UNSAFE,
  89. RENDER_THREAD_SAFE,
  90. RENDER_SEPARATE_THREAD
  91. };
  92. struct VideoMode {
  93. int width, height;
  94. bool fullscreen;
  95. bool resizable;
  96. bool borderless_window;
  97. bool maximized;
  98. bool always_on_top;
  99. bool use_vsync;
  100. bool vsync_via_compositor;
  101. bool layered;
  102. float get_aspect() const { return (float)width / (float)height; }
  103. VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_always_on_top = false, bool p_use_vsync = false, bool p_vsync_via_compositor = false) {
  104. width = p_width;
  105. height = p_height;
  106. fullscreen = p_fullscreen;
  107. resizable = p_resizable;
  108. borderless_window = p_borderless_window;
  109. maximized = p_maximized;
  110. always_on_top = p_always_on_top;
  111. use_vsync = p_use_vsync;
  112. vsync_via_compositor = p_vsync_via_compositor;
  113. layered = false;
  114. }
  115. };
  116. struct TTSUtterance {
  117. String text;
  118. String voice;
  119. int volume = 50;
  120. float pitch = 1.f;
  121. float rate = 1.f;
  122. int id = 0;
  123. };
  124. enum TTSUtteranceEvent {
  125. TTS_UTTERANCE_STARTED,
  126. TTS_UTTERANCE_ENDED,
  127. TTS_UTTERANCE_CANCELED,
  128. TTS_UTTERANCE_BOUNDARY,
  129. TTS_UTTERANCE_MAX,
  130. };
  131. private:
  132. struct Callback {
  133. Object *object = nullptr;
  134. StringName cb_name;
  135. };
  136. Callback utterance_callback[TTS_UTTERANCE_MAX];
  137. protected:
  138. friend class Main;
  139. HasServerFeatureCallback has_server_feature_callback;
  140. RenderThreadMode _render_thread_mode;
  141. // functions used by main to initialize/deinitialize the OS
  142. void add_logger(Logger *p_logger);
  143. virtual void initialize_core() = 0;
  144. virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) = 0;
  145. virtual void set_main_loop(MainLoop *p_main_loop) = 0;
  146. virtual void delete_main_loop() = 0;
  147. virtual void finalize() = 0;
  148. virtual void finalize_core() = 0;
  149. virtual void set_cmdline(const char *p_execpath, const List<String> &p_args);
  150. virtual bool _check_internal_feature_support(const String &p_feature) = 0;
  151. public:
  152. typedef int64_t ProcessID;
  153. static OS *get_singleton();
  154. virtual void global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta){};
  155. virtual void global_menu_add_separator(const String &p_menu){};
  156. virtual void global_menu_remove_item(const String &p_menu, int p_idx){};
  157. virtual void global_menu_clear(const String &p_menu){};
  158. void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type = Logger::ERR_ERROR);
  159. void print(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
  160. void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
  161. virtual void alert(const String &p_alert, const String &p_title = "ALERT!") = 0;
  162. virtual String get_stdin_string() = 0;
  163. enum MouseMode {
  164. MOUSE_MODE_VISIBLE,
  165. MOUSE_MODE_HIDDEN,
  166. MOUSE_MODE_CAPTURED,
  167. MOUSE_MODE_CONFINED,
  168. MOUSE_MODE_CONFINED_HIDDEN,
  169. };
  170. virtual void set_mouse_mode(MouseMode p_mode);
  171. virtual MouseMode get_mouse_mode() const;
  172. virtual bool tts_is_speaking() const;
  173. virtual bool tts_is_paused() const;
  174. virtual Array tts_get_voices() const;
  175. virtual PoolStringArray tts_get_voices_for_language(const String &p_language) const;
  176. virtual void tts_speak(const String &p_text, const String &p_voice, int p_volume = 50, float p_pitch = 1.f, float p_rate = 1.f, int p_utterance_id = 0, bool p_interrupt = false);
  177. virtual void tts_pause();
  178. virtual void tts_resume();
  179. virtual void tts_stop();
  180. virtual void tts_set_utterance_callback(TTSUtteranceEvent p_event, Object *p_object, const StringName &p_callback);
  181. virtual void tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id, int p_pos = 0);
  182. virtual void warp_mouse_position(const Point2 &p_to) {}
  183. virtual Point2 get_mouse_position() const = 0;
  184. virtual int get_mouse_button_state() const = 0;
  185. virtual void set_window_title(const String &p_title) = 0;
  186. virtual void set_window_mouse_passthrough(const PoolVector2Array &p_region){};
  187. virtual void set_clipboard(const String &p_text);
  188. virtual String get_clipboard() const;
  189. virtual bool has_clipboard() const;
  190. virtual void set_clipboard_primary(const String &p_text);
  191. virtual String get_clipboard_primary() const;
  192. virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0) = 0;
  193. virtual VideoMode get_video_mode(int p_screen = 0) const = 0;
  194. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const = 0;
  195. enum VideoDriver {
  196. VIDEO_DRIVER_GLES3,
  197. VIDEO_DRIVER_GLES2,
  198. VIDEO_DRIVER_MAX,
  199. };
  200. virtual int get_video_driver_count() const;
  201. virtual const char *get_video_driver_name(int p_driver) const;
  202. virtual int get_current_video_driver() const = 0;
  203. virtual bool is_offscreen_gl_available() const;
  204. virtual void set_offscreen_gl_current(bool p_current);
  205. virtual int get_audio_driver_count() const;
  206. virtual const char *get_audio_driver_name(int p_driver) const;
  207. virtual int get_tablet_driver_count() const { return 0; };
  208. virtual String get_tablet_driver_name(int p_driver) const { return ""; };
  209. virtual String get_current_tablet_driver() const { return ""; };
  210. virtual void set_current_tablet_driver(const String &p_driver){};
  211. virtual PoolStringArray get_connected_midi_inputs();
  212. virtual void open_midi_inputs();
  213. virtual void close_midi_inputs();
  214. // Returned by get_screen_refresh_rate if the method fails.
  215. const float SCREEN_REFRESH_RATE_FALLBACK = -1.0;
  216. virtual int get_screen_count() const { return 1; }
  217. virtual int get_current_screen() const { return 0; }
  218. virtual void set_current_screen(int p_screen) {}
  219. virtual Point2 get_screen_position(int p_screen = -1) const { return Point2(); }
  220. virtual Size2 get_screen_size(int p_screen = -1) const { return get_window_size(); }
  221. virtual int get_screen_dpi(int p_screen = -1) const { return 72; }
  222. virtual float get_screen_scale(int p_screen = -1) const { return 1.0; }
  223. virtual float get_screen_max_scale() const { return 1.0; };
  224. virtual float get_screen_refresh_rate(int p_screen = -1) const { return SCREEN_REFRESH_RATE_FALLBACK; };
  225. virtual Point2 get_window_position() const { return Vector2(); }
  226. virtual void set_window_position(const Point2 &p_position) {}
  227. virtual Size2 get_max_window_size() const { return Size2(); };
  228. virtual Size2 get_min_window_size() const { return Size2(); };
  229. virtual Size2 get_window_size() const = 0;
  230. virtual Size2 get_real_window_size() const { return get_window_size(); }
  231. virtual void set_min_window_size(const Size2 p_size) {}
  232. virtual void set_max_window_size(const Size2 p_size) {}
  233. virtual void set_window_size(const Size2 p_size) {}
  234. virtual void set_window_fullscreen(bool p_enabled) {}
  235. virtual bool is_window_fullscreen() const { return true; }
  236. virtual void set_window_resizable(bool p_enabled) {}
  237. virtual bool is_window_resizable() const { return false; }
  238. virtual void set_window_minimized(bool p_enabled) {}
  239. virtual bool is_window_minimized() const { return false; }
  240. virtual void set_window_maximized(bool p_enabled) {}
  241. virtual bool is_window_maximized() const { return true; }
  242. virtual void set_window_always_on_top(bool p_enabled) {}
  243. virtual bool is_window_always_on_top() const { return false; }
  244. virtual bool is_window_focused() const { return true; }
  245. virtual void request_attention() {}
  246. virtual void center_window();
  247. // Returns internal pointers and handles.
  248. // While exposed to GDScript this is mostly to give GDNative plugins access to this information.
  249. // Note that whether a valid handle is returned depends on whether it applies to the given
  250. // platform and often to the chosen render driver.
  251. // NULL will be returned if a handle is not available.
  252. enum HandleType {
  253. APPLICATION_HANDLE, // HINSTANCE, NSApplication*, UIApplication*, JNIEnv* ...
  254. DISPLAY_HANDLE, // X11::Display* ...
  255. WINDOW_HANDLE, // HWND, X11::Window*, NSWindow*, UIWindow*, Android activity ...
  256. WINDOW_VIEW, // HDC, NSView*, UIView*, Android surface ...
  257. OPENGL_CONTEXT, // HGLRC, X11::GLXContext, NSOpenGLContext*, EGLContext* ...
  258. };
  259. virtual void *get_native_handle(int p_handle_type) { return nullptr; };
  260. // Returns window area free of hardware controls and other obstacles.
  261. // The application should use this to determine where to place UI elements.
  262. //
  263. // Keep in mind the area returned is in window coordinates rather than
  264. // viewport coordinates - you should perform the conversion on your own.
  265. //
  266. // The maximum size of the area is Rect2(0, 0, window_size.width, window_size.height).
  267. virtual Rect2 get_window_safe_area() const {
  268. Size2 window_size = get_window_size();
  269. return Rect2(0, 0, window_size.width, window_size.height);
  270. }
  271. virtual Array get_display_cutouts() const { return Array(); }
  272. virtual void set_borderless_window(bool p_borderless) {}
  273. virtual bool get_borderless_window() { return false; }
  274. virtual bool get_window_per_pixel_transparency_enabled() const { return false; }
  275. virtual void set_window_per_pixel_transparency_enabled(bool p_enabled) {}
  276. virtual void set_ime_active(const bool p_active) {}
  277. virtual void set_ime_position(const Point2 &p_pos) {}
  278. virtual Point2 get_ime_selection() const { return Point2(); }
  279. virtual String get_ime_text() const { return String(); }
  280. virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false) { return ERR_UNAVAILABLE; }
  281. virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; }
  282. virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) { return ERR_UNAVAILABLE; }
  283. virtual void set_keep_screen_on(bool p_enabled);
  284. virtual bool is_keep_screen_on() const;
  285. virtual void set_low_processor_usage_mode(bool p_enabled);
  286. virtual bool is_in_low_processor_usage_mode() const;
  287. virtual void set_low_processor_usage_mode_sleep_usec(int p_usec);
  288. virtual int get_low_processor_usage_mode_sleep_usec() const;
  289. virtual void set_update_vital_only(bool p_enabled);
  290. virtual void set_update_pending(bool p_pending) { _update_pending = p_pending; }
  291. // Convenience easy switch for turning this off outside tools builds, without littering calling code
  292. // with #ifdefs. It will also hopefully be compiled out in release.
  293. #ifdef TOOLS_ENABLED
  294. // This function is used to throttle back updates of animations and particle systems when using UPDATE_VITAL_ONLY mode.
  295. // CASE 1) We are not in UPDATE_VITAL_ONLY mode - always return true and update.
  296. // CASE 2) We are in UPDATE_VITAL_ONLY mode -
  297. // In most cases this will return false and prevent animations etc updating.
  298. // The exception is that we can also choose to receive a true
  299. // each time a frame is redrawn as a result of moving the mouse, clicking etc.
  300. // This enables us to keep e.g. particle systems processing, but ONLY when other
  301. // events have caused a redraw.
  302. virtual bool is_update_pending(bool p_include_redraws = false) const { return !_update_vital_only || (_update_pending && p_include_redraws); }
  303. #else
  304. // Always update when outside the editor, UPDATE_VITAL_ONLY has no effect outside the editor.
  305. virtual bool is_update_pending(bool p_include_redraws = false) const { return true; }
  306. #endif
  307. virtual String get_executable_path() const;
  308. virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = nullptr, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) = 0;
  309. virtual Error kill(const ProcessID &p_pid) = 0;
  310. virtual int get_process_id() const;
  311. virtual bool is_process_running(const ProcessID &p_pid) const = 0;
  312. virtual void vibrate_handheld(int p_duration_ms = 500) {}
  313. virtual Error shell_open(String p_uri);
  314. virtual Error set_cwd(const String &p_cwd);
  315. virtual bool has_environment(const String &p_var) const = 0;
  316. virtual String get_environment(const String &p_var) const = 0;
  317. virtual bool set_environment(const String &p_var, const String &p_value) const = 0;
  318. virtual String get_name() const = 0;
  319. virtual List<String> get_cmdline_args() const { return _cmdline; }
  320. virtual String get_model_name() const;
  321. void ensure_user_data_dir();
  322. virtual MainLoop *get_main_loop() const = 0;
  323. virtual void yield();
  324. enum Weekday {
  325. DAY_SUNDAY,
  326. DAY_MONDAY,
  327. DAY_TUESDAY,
  328. DAY_WEDNESDAY,
  329. DAY_THURSDAY,
  330. DAY_FRIDAY,
  331. DAY_SATURDAY
  332. };
  333. enum Month {
  334. /// Start at 1 to follow Windows SYSTEMTIME structure
  335. /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
  336. MONTH_JANUARY = 1,
  337. MONTH_FEBRUARY,
  338. MONTH_MARCH,
  339. MONTH_APRIL,
  340. MONTH_MAY,
  341. MONTH_JUNE,
  342. MONTH_JULY,
  343. MONTH_AUGUST,
  344. MONTH_SEPTEMBER,
  345. MONTH_OCTOBER,
  346. MONTH_NOVEMBER,
  347. MONTH_DECEMBER
  348. };
  349. struct Date {
  350. int year;
  351. Month month;
  352. int day;
  353. Weekday weekday;
  354. bool dst;
  355. };
  356. struct Time {
  357. int hour;
  358. int min;
  359. int sec;
  360. };
  361. struct TimeZoneInfo {
  362. int bias;
  363. String name;
  364. };
  365. virtual Date get_date(bool local = false) const = 0;
  366. virtual Time get_time(bool local = false) const = 0;
  367. virtual TimeZoneInfo get_time_zone_info() const = 0;
  368. virtual String get_iso_date_time(bool local = false) const;
  369. virtual uint64_t get_unix_time() const;
  370. virtual uint64_t get_system_time_secs() const;
  371. virtual uint64_t get_system_time_msecs() const;
  372. virtual double get_subsecond_unix_time() const; // For use in Time::get_unix_time().
  373. virtual void delay_usec(uint32_t p_usec) const = 0;
  374. virtual void add_frame_delay(bool p_can_draw);
  375. virtual uint64_t get_ticks_usec() const = 0;
  376. uint32_t get_ticks_msec() const;
  377. uint64_t get_splash_tick_msec() const;
  378. virtual bool can_draw() const = 0;
  379. virtual bool is_userfs_persistent() const { return true; }
  380. bool is_stdout_verbose() const;
  381. bool is_stdout_debug_enabled() const;
  382. virtual void disable_crash_handler() {}
  383. virtual bool is_disable_crash_handler() const { return false; }
  384. virtual void initialize_debugging() {}
  385. enum CursorShape {
  386. CURSOR_ARROW,
  387. CURSOR_IBEAM,
  388. CURSOR_POINTING_HAND,
  389. CURSOR_CROSS,
  390. CURSOR_WAIT,
  391. CURSOR_BUSY,
  392. CURSOR_DRAG,
  393. CURSOR_CAN_DROP,
  394. CURSOR_FORBIDDEN,
  395. CURSOR_VSIZE,
  396. CURSOR_HSIZE,
  397. CURSOR_BDIAGSIZE,
  398. CURSOR_FDIAGSIZE,
  399. CURSOR_MOVE,
  400. CURSOR_VSPLIT,
  401. CURSOR_HSPLIT,
  402. CURSOR_HELP,
  403. CURSOR_MAX
  404. };
  405. enum VirtualKeyboardType {
  406. KEYBOARD_TYPE_DEFAULT,
  407. KEYBOARD_TYPE_MULTILINE,
  408. KEYBOARD_TYPE_NUMBER,
  409. KEYBOARD_TYPE_NUMBER_DECIMAL,
  410. KEYBOARD_TYPE_PHONE,
  411. KEYBOARD_TYPE_EMAIL_ADDRESS,
  412. KEYBOARD_TYPE_PASSWORD,
  413. KEYBOARD_TYPE_URL
  414. };
  415. virtual bool has_virtual_keyboard() const;
  416. virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
  417. virtual void hide_virtual_keyboard();
  418. // returns height of the currently shown virtual keyboard (0 if keyboard is hidden)
  419. virtual int get_virtual_keyboard_height() const;
  420. virtual uint32_t keyboard_get_scancode_from_physical(uint32_t p_scancode) const;
  421. virtual void set_cursor_shape(CursorShape p_shape);
  422. virtual CursorShape get_cursor_shape() const;
  423. virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot);
  424. virtual bool get_swap_ok_cancel() { return false; }
  425. virtual void dump_memory_to_file(const char *p_file);
  426. virtual void dump_resources_to_file(const char *p_file);
  427. virtual void print_resources_in_use(bool p_short = false);
  428. virtual void print_all_resources(String p_to_file = "");
  429. virtual uint64_t get_static_memory_usage() const;
  430. virtual uint64_t get_static_memory_peak_usage() const;
  431. virtual uint64_t get_dynamic_memory_usage() const;
  432. virtual uint64_t get_free_static_memory() const;
  433. RenderThreadMode get_render_thread_mode() const { return _render_thread_mode; }
  434. virtual String get_locale() const;
  435. String get_locale_language() const;
  436. virtual uint64_t get_embedded_pck_offset() const;
  437. String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const;
  438. virtual String get_godot_dir_name() const;
  439. virtual String get_data_path() const;
  440. virtual String get_config_path() const;
  441. virtual String get_cache_path() const;
  442. virtual String get_bundle_resource_dir() const;
  443. virtual String get_bundle_icon_path() const;
  444. virtual String get_user_data_dir() const;
  445. virtual String get_resource_dir() const;
  446. enum SystemDir {
  447. SYSTEM_DIR_DESKTOP,
  448. SYSTEM_DIR_DCIM,
  449. SYSTEM_DIR_DOCUMENTS,
  450. SYSTEM_DIR_DOWNLOADS,
  451. SYSTEM_DIR_MOVIES,
  452. SYSTEM_DIR_MUSIC,
  453. SYSTEM_DIR_PICTURES,
  454. SYSTEM_DIR_RINGTONES,
  455. };
  456. virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;
  457. virtual Error move_to_trash(const String &p_path) { return FAILED; }
  458. virtual void set_no_window_mode(bool p_enable);
  459. virtual bool is_no_window_mode_enabled() const;
  460. virtual bool has_touchscreen_ui_hint() const;
  461. enum ScreenOrientation {
  462. SCREEN_LANDSCAPE,
  463. SCREEN_PORTRAIT,
  464. SCREEN_REVERSE_LANDSCAPE,
  465. SCREEN_REVERSE_PORTRAIT,
  466. SCREEN_SENSOR_LANDSCAPE,
  467. SCREEN_SENSOR_PORTRAIT,
  468. SCREEN_SENSOR,
  469. };
  470. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  471. virtual ScreenOrientation get_screen_orientation() const;
  472. ScreenOrientation get_screen_orientation_from_string(const String &p_orientation) const;
  473. virtual void enable_for_stealing_focus(ProcessID pid) {}
  474. virtual void move_window_to_foreground() {}
  475. virtual void release_rendering_thread();
  476. virtual void make_rendering_thread();
  477. virtual void swap_buffers();
  478. virtual void set_native_icon(const String &p_filename);
  479. virtual void set_icon(const Ref<Image> &p_icon);
  480. virtual int get_exit_code() const;
  481. virtual void set_exit_code(int p_code);
  482. virtual bool is_custom_exit_code();
  483. virtual int get_processor_count() const;
  484. virtual String get_processor_name() const;
  485. virtual int get_default_thread_pool_size() const { return get_processor_count(); }
  486. virtual String get_unique_id() const;
  487. virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
  488. virtual bool native_video_is_playing() const;
  489. virtual void native_video_pause();
  490. virtual void native_video_unpause();
  491. virtual void native_video_stop();
  492. virtual bool can_use_threads() const;
  493. virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object *p_obj, String p_callback);
  494. virtual Error dialog_input_text(String p_title, String p_description, String p_partial, Object *p_obj, String p_callback);
  495. enum LatinKeyboardVariant {
  496. LATIN_KEYBOARD_QWERTY,
  497. LATIN_KEYBOARD_QWERTZ,
  498. LATIN_KEYBOARD_AZERTY,
  499. LATIN_KEYBOARD_QZERTY,
  500. LATIN_KEYBOARD_DVORAK,
  501. LATIN_KEYBOARD_NEO,
  502. LATIN_KEYBOARD_COLEMAK,
  503. };
  504. virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
  505. virtual int keyboard_get_layout_count() const;
  506. virtual int keyboard_get_current_layout() const;
  507. virtual void keyboard_set_current_layout(int p_index);
  508. virtual String keyboard_get_layout_language(int p_index) const;
  509. virtual String keyboard_get_layout_name(int p_index) const;
  510. virtual bool is_joy_known(int p_device);
  511. virtual String get_joy_guid(int p_device) const;
  512. enum EngineContext {
  513. CONTEXT_EDITOR,
  514. CONTEXT_PROJECTMAN,
  515. CONTEXT_ENGINE,
  516. };
  517. virtual void set_context(int p_context);
  518. //amazing hack because OpenGL needs this to be set on a separate thread..
  519. //also core can't access servers, so a callback must be used
  520. typedef void (*SwitchVSyncCallbackInThread)(bool);
  521. static SwitchVSyncCallbackInThread switch_vsync_function;
  522. void set_use_vsync(bool p_enable);
  523. bool is_vsync_enabled() const;
  524. //real, actual overridable function to switch vsync, which needs to be called from graphics thread if needed
  525. virtual void _set_use_vsync(bool p_enable) {}
  526. void set_vsync_via_compositor(bool p_enable);
  527. bool is_vsync_via_compositor_enabled() const;
  528. void set_delta_smoothing(bool p_enabled);
  529. bool is_delta_smoothing_enabled() const;
  530. virtual OS::PowerState get_power_state();
  531. virtual int get_power_seconds_left();
  532. virtual int get_power_percent_left();
  533. virtual void force_process_input(){};
  534. bool has_feature(const String &p_feature);
  535. void set_has_server_feature_callback(HasServerFeatureCallback p_callback);
  536. bool is_layered_allowed() const { return _allow_layered; }
  537. bool is_hidpi_allowed() const { return _allow_hidpi; }
  538. void set_restart_on_exit(bool p_restart, const List<String> &p_restart_arguments);
  539. bool is_restart_on_exit_set() const;
  540. List<String> get_restart_on_exit_arguments() const;
  541. virtual bool request_permission(const String &p_name) { return true; }
  542. virtual bool request_permissions() { return true; }
  543. virtual Vector<String> get_granted_permissions() const { return Vector<String>(); }
  544. // For recording / measuring benchmark data. Only enabled with tools
  545. void set_use_benchmark(bool p_use_benchmark);
  546. bool is_use_benchmark_set();
  547. void set_benchmark_file(const String &p_benchmark_file);
  548. String get_benchmark_file();
  549. virtual void benchmark_begin_measure(const String &p_what);
  550. virtual void benchmark_end_measure(const String &p_what);
  551. virtual void benchmark_dump();
  552. virtual void process_and_drop_events() {}
  553. OS();
  554. virtual ~OS();
  555. };
  556. VARIANT_ENUM_CAST(OS::PowerState);
  557. #endif // OS_H